diff options
Diffstat (limited to 'examples')
42 files changed, 1197 insertions, 1313 deletions
diff --git a/examples/C/Makefile.in b/examples/C/Makefile.in index 95754494..c3bdf7e6 100644 --- a/examples/C/Makefile.in +++ b/examples/C/Makefile.in @@ -190,6 +190,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -313,6 +315,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -332,6 +335,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ @@ -358,7 +362,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_BASE_DIR = @UDEV_BASE_DIR@ +UDEV_DIR = @UDEV_DIR@ USE_NLS = @USE_NLS@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ diff --git a/examples/C/glib/Makefile.am b/examples/C/glib/Makefile.am index 1f4785da..d8e5d285 100644 --- a/examples/C/glib/Makefile.am +++ b/examples/C/glib/Makefile.am @@ -1,83 +1,53 @@ AM_CPPFLAGS = \ - -I${top_srcdir}/libnm-util \ - -I${top_builddir}/libnm-util \ - -I${top_srcdir}/libnm-glib \ -I${top_srcdir}/include \ - -I${top_builddir}/include \ - $(DBUS_CFLAGS) \ + -I${top_srcdir}/libnm-core \ + -I${top_builddir}/libnm-core \ + -I${top_srcdir}/libnm \ + -I${top_builddir}/libnm \ $(GLIB_CFLAGS) noinst_PROGRAMS = \ - add-connection-dbus-glib \ - add-connection-libnm-glib \ - get-active-connections-dbus-glib \ - list-connections-dbus-glib \ - list-connections-libnm-glib \ - get-ap-info-libnm-glib \ - monitor-nm-running-dbus-glib \ - monitor-nm-running-GDBus \ - monitor-nm-state-GDBus + add-connection-gdbus \ + add-connection-libnm \ + get-active-connections-gdbus \ + get-ap-info-libnm \ + list-connections-gdbus \ + list-connections-libnm \ + monitor-nm-running-gdbus \ + monitor-nm-state-gdbus -add_connection_dbus_glib_SOURCES = add-connection-dbus-glib.c -add_connection_dbus_glib_LDADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(DBUS_LIBS) \ - $(GLIB_LIBS) - -add_connection_libnm_glib_SOURCES = add-connection-libnm-glib.c -add_connection_libnm_glib_LDADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(top_builddir)/libnm-glib/libnm-glib.la \ - $(DBUS_LIBS) \ - $(GLIB_LIBS) +add_connection_gdbus_SOURCES = add-connection-gdbus.c +add_connection_gdbus_LDADD = \ + $(GLIB_LIBS) \ + $(UUID_LIBS) -get_active_connections_dbus_glib_SOURCES = get-active-connections-dbus-glib.c -get_active_connections_dbus_glib_LDADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(DBUS_LIBS) \ +add_connection_libnm_SOURCES = add-connection-libnm.c +add_connection_libnm_LDADD = \ + $(top_builddir)/libnm/libnm.la \ $(GLIB_LIBS) -list_connections_dbus_glib_SOURCES = list-connections-dbus-glib.c -list_connections_dbus_glib_LDADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(DBUS_LIBS) \ +get_active_connections_gdbus_SOURCES = get-active-connections-gdbus.c +get_active_connections_gdbus_LDADD = \ $(GLIB_LIBS) -list_connections_libnm_glib_SOURCES = list-connections-libnm-glib.c -list_connections_libnm_glib_LDADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(top_builddir)/libnm-glib/libnm-glib.la \ - $(DBUS_LIBS) \ +get_ap_info_libnm_SOURCES = get-ap-info-libnm.c +get_ap_info_libnm_LDADD = \ + $(top_builddir)/libnm/libnm.la \ $(GLIB_LIBS) -get_ap_info_libnm_glib_SOURCES = get-ap-info-libnm-glib.c -get_ap_info_libnm_glib_LDADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(top_builddir)/libnm-glib/libnm-glib.la \ - $(DBUS_LIBS) \ +list_connections_gdbus_SOURCES = list-connections-gdbus.c +list_connections_gdbus_LDADD = \ $(GLIB_LIBS) -monitor_nm_running_dbus_glib_SOURCES = monitor-nm-running-dbus-glib.c -monitor_nm_running_dbus_glib_LDADD = \ - $(DBUS_LIBS) \ +list_connections_libnm_SOURCES = list-connections-libnm.c +list_connections_libnm_LDADD = \ + $(top_builddir)/libnm/libnm.la \ $(GLIB_LIBS) -monitor_nm_running_GDBus_SOURCES = monitor-nm-running-GDBus.c -monitor_nm_running_GDBus_LDADD = \ +monitor_nm_running_gdbus_SOURCES = monitor-nm-running-gdbus.c +monitor_nm_running_gdbus_LDADD = \ $(GLIB_LIBS) -monitor_nm_state_GDBus_SOURCES = monitor-nm-state-GDBus.c -monitor_nm_state_GDBus_LDADD = \ +monitor_nm_state_gdbus_SOURCES = monitor-nm-state-gdbus.c +monitor_nm_state_gdbus_LDADD = \ $(GLIB_LIBS) - -EXTRA_DIST = \ - add-connection-dbus-glib.c \ - add-connection-libnm-glib.c \ - get-active-connections-dbus-glib.c \ - list-connections-dbus-glib.c \ - list-connections-libnm-glib.c \ - get-ap-info-libnm-glib.c \ - monitor-nm-running-dbus-glib.c \ - monitor-nm-running-GDBus.c \ - monitor-nm-state-GDBus.c - diff --git a/examples/C/glib/Makefile.in b/examples/C/glib/Makefile.in index e58e66d0..d2790a7a 100644 --- a/examples/C/glib/Makefile.in +++ b/examples/C/glib/Makefile.in @@ -78,15 +78,13 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -noinst_PROGRAMS = add-connection-dbus-glib$(EXEEXT) \ - add-connection-libnm-glib$(EXEEXT) \ - get-active-connections-dbus-glib$(EXEEXT) \ - list-connections-dbus-glib$(EXEEXT) \ - list-connections-libnm-glib$(EXEEXT) \ - get-ap-info-libnm-glib$(EXEEXT) \ - monitor-nm-running-dbus-glib$(EXEEXT) \ - monitor-nm-running-GDBus$(EXEEXT) \ - monitor-nm-state-GDBus$(EXEEXT) +noinst_PROGRAMS = add-connection-gdbus$(EXEEXT) \ + add-connection-libnm$(EXEEXT) \ + get-active-connections-gdbus$(EXEEXT) \ + get-ap-info-libnm$(EXEEXT) list-connections-gdbus$(EXEEXT) \ + list-connections-libnm$(EXEEXT) \ + monitor-nm-running-gdbus$(EXEEXT) \ + monitor-nm-state-gdbus$(EXEEXT) subdir = examples/C/glib DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ $(top_srcdir)/build-aux/depcomp @@ -111,68 +109,43 @@ CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = PROGRAMS = $(noinst_PROGRAMS) -am_add_connection_dbus_glib_OBJECTS = \ - add-connection-dbus-glib.$(OBJEXT) -add_connection_dbus_glib_OBJECTS = \ - $(am_add_connection_dbus_glib_OBJECTS) +am_add_connection_gdbus_OBJECTS = add-connection-gdbus.$(OBJEXT) +add_connection_gdbus_OBJECTS = $(am_add_connection_gdbus_OBJECTS) am__DEPENDENCIES_1 = -add_connection_dbus_glib_DEPENDENCIES = \ - $(top_builddir)/libnm-util/libnm-util.la $(am__DEPENDENCIES_1) \ +add_connection_gdbus_DEPENDENCIES = $(am__DEPENDENCIES_1) \ $(am__DEPENDENCIES_1) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent am__v_lt_1 = -am_add_connection_libnm_glib_OBJECTS = \ - add-connection-libnm-glib.$(OBJEXT) -add_connection_libnm_glib_OBJECTS = \ - $(am_add_connection_libnm_glib_OBJECTS) -add_connection_libnm_glib_DEPENDENCIES = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(top_builddir)/libnm-glib/libnm-glib.la $(am__DEPENDENCIES_1) \ +am_add_connection_libnm_OBJECTS = add-connection-libnm.$(OBJEXT) +add_connection_libnm_OBJECTS = $(am_add_connection_libnm_OBJECTS) +add_connection_libnm_DEPENDENCIES = $(top_builddir)/libnm/libnm.la \ $(am__DEPENDENCIES_1) -am_get_active_connections_dbus_glib_OBJECTS = \ - get-active-connections-dbus-glib.$(OBJEXT) -get_active_connections_dbus_glib_OBJECTS = \ - $(am_get_active_connections_dbus_glib_OBJECTS) -get_active_connections_dbus_glib_DEPENDENCIES = \ - $(top_builddir)/libnm-util/libnm-util.la $(am__DEPENDENCIES_1) \ +am_get_active_connections_gdbus_OBJECTS = \ + get-active-connections-gdbus.$(OBJEXT) +get_active_connections_gdbus_OBJECTS = \ + $(am_get_active_connections_gdbus_OBJECTS) +get_active_connections_gdbus_DEPENDENCIES = $(am__DEPENDENCIES_1) +am_get_ap_info_libnm_OBJECTS = get-ap-info-libnm.$(OBJEXT) +get_ap_info_libnm_OBJECTS = $(am_get_ap_info_libnm_OBJECTS) +get_ap_info_libnm_DEPENDENCIES = $(top_builddir)/libnm/libnm.la \ $(am__DEPENDENCIES_1) -am_get_ap_info_libnm_glib_OBJECTS = get-ap-info-libnm-glib.$(OBJEXT) -get_ap_info_libnm_glib_OBJECTS = $(am_get_ap_info_libnm_glib_OBJECTS) -get_ap_info_libnm_glib_DEPENDENCIES = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(top_builddir)/libnm-glib/libnm-glib.la $(am__DEPENDENCIES_1) \ +am_list_connections_gdbus_OBJECTS = list-connections-gdbus.$(OBJEXT) +list_connections_gdbus_OBJECTS = $(am_list_connections_gdbus_OBJECTS) +list_connections_gdbus_DEPENDENCIES = $(am__DEPENDENCIES_1) +am_list_connections_libnm_OBJECTS = list-connections-libnm.$(OBJEXT) +list_connections_libnm_OBJECTS = $(am_list_connections_libnm_OBJECTS) +list_connections_libnm_DEPENDENCIES = $(top_builddir)/libnm/libnm.la \ $(am__DEPENDENCIES_1) -am_list_connections_dbus_glib_OBJECTS = \ - list-connections-dbus-glib.$(OBJEXT) -list_connections_dbus_glib_OBJECTS = \ - $(am_list_connections_dbus_glib_OBJECTS) -list_connections_dbus_glib_DEPENDENCIES = \ - $(top_builddir)/libnm-util/libnm-util.la $(am__DEPENDENCIES_1) \ - $(am__DEPENDENCIES_1) -am_list_connections_libnm_glib_OBJECTS = \ - list-connections-libnm-glib.$(OBJEXT) -list_connections_libnm_glib_OBJECTS = \ - $(am_list_connections_libnm_glib_OBJECTS) -list_connections_libnm_glib_DEPENDENCIES = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(top_builddir)/libnm-glib/libnm-glib.la $(am__DEPENDENCIES_1) \ - $(am__DEPENDENCIES_1) -am_monitor_nm_running_GDBus_OBJECTS = \ - monitor-nm-running-GDBus.$(OBJEXT) -monitor_nm_running_GDBus_OBJECTS = \ - $(am_monitor_nm_running_GDBus_OBJECTS) -monitor_nm_running_GDBus_DEPENDENCIES = $(am__DEPENDENCIES_1) -am_monitor_nm_running_dbus_glib_OBJECTS = \ - monitor-nm-running-dbus-glib.$(OBJEXT) -monitor_nm_running_dbus_glib_OBJECTS = \ - $(am_monitor_nm_running_dbus_glib_OBJECTS) -monitor_nm_running_dbus_glib_DEPENDENCIES = $(am__DEPENDENCIES_1) \ - $(am__DEPENDENCIES_1) -am_monitor_nm_state_GDBus_OBJECTS = monitor-nm-state-GDBus.$(OBJEXT) -monitor_nm_state_GDBus_OBJECTS = $(am_monitor_nm_state_GDBus_OBJECTS) -monitor_nm_state_GDBus_DEPENDENCIES = $(am__DEPENDENCIES_1) +am_monitor_nm_running_gdbus_OBJECTS = \ + monitor-nm-running-gdbus.$(OBJEXT) +monitor_nm_running_gdbus_OBJECTS = \ + $(am_monitor_nm_running_gdbus_OBJECTS) +monitor_nm_running_gdbus_DEPENDENCIES = $(am__DEPENDENCIES_1) +am_monitor_nm_state_gdbus_OBJECTS = monitor-nm-state-gdbus.$(OBJEXT) +monitor_nm_state_gdbus_OBJECTS = $(am_monitor_nm_state_gdbus_OBJECTS) +monitor_nm_state_gdbus_DEPENDENCIES = $(am__DEPENDENCIES_1) AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false @@ -207,24 +180,20 @@ AM_V_CCLD = $(am__v_CCLD_@AM_V@) am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = -SOURCES = $(add_connection_dbus_glib_SOURCES) \ - $(add_connection_libnm_glib_SOURCES) \ - $(get_active_connections_dbus_glib_SOURCES) \ - $(get_ap_info_libnm_glib_SOURCES) \ - $(list_connections_dbus_glib_SOURCES) \ - $(list_connections_libnm_glib_SOURCES) \ - $(monitor_nm_running_GDBus_SOURCES) \ - $(monitor_nm_running_dbus_glib_SOURCES) \ - $(monitor_nm_state_GDBus_SOURCES) -DIST_SOURCES = $(add_connection_dbus_glib_SOURCES) \ - $(add_connection_libnm_glib_SOURCES) \ - $(get_active_connections_dbus_glib_SOURCES) \ - $(get_ap_info_libnm_glib_SOURCES) \ - $(list_connections_dbus_glib_SOURCES) \ - $(list_connections_libnm_glib_SOURCES) \ - $(monitor_nm_running_GDBus_SOURCES) \ - $(monitor_nm_running_dbus_glib_SOURCES) \ - $(monitor_nm_state_GDBus_SOURCES) +SOURCES = $(add_connection_gdbus_SOURCES) \ + $(add_connection_libnm_SOURCES) \ + $(get_active_connections_gdbus_SOURCES) \ + $(get_ap_info_libnm_SOURCES) $(list_connections_gdbus_SOURCES) \ + $(list_connections_libnm_SOURCES) \ + $(monitor_nm_running_gdbus_SOURCES) \ + $(monitor_nm_state_gdbus_SOURCES) +DIST_SOURCES = $(add_connection_gdbus_SOURCES) \ + $(add_connection_libnm_SOURCES) \ + $(get_active_connections_gdbus_SOURCES) \ + $(get_ap_info_libnm_SOURCES) $(list_connections_gdbus_SOURCES) \ + $(list_connections_libnm_SOURCES) \ + $(monitor_nm_running_gdbus_SOURCES) \ + $(monitor_nm_state_gdbus_SOURCES) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -259,6 +228,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -382,6 +353,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -401,6 +373,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ @@ -427,7 +400,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_BASE_DIR = @UDEV_BASE_DIR@ +UDEV_DIR = @UDEV_DIR@ USE_NLS = @USE_NLS@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ @@ -507,77 +480,49 @@ with_netconfig = @with_netconfig@ with_resolvconf = @with_resolvconf@ with_valgrind = @with_valgrind@ AM_CPPFLAGS = \ - -I${top_srcdir}/libnm-util \ - -I${top_builddir}/libnm-util \ - -I${top_srcdir}/libnm-glib \ -I${top_srcdir}/include \ - -I${top_builddir}/include \ - $(DBUS_CFLAGS) \ + -I${top_srcdir}/libnm-core \ + -I${top_builddir}/libnm-core \ + -I${top_srcdir}/libnm \ + -I${top_builddir}/libnm \ $(GLIB_CFLAGS) -add_connection_dbus_glib_SOURCES = add-connection-dbus-glib.c -add_connection_dbus_glib_LDADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(DBUS_LIBS) \ - $(GLIB_LIBS) - -add_connection_libnm_glib_SOURCES = add-connection-libnm-glib.c -add_connection_libnm_glib_LDADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(top_builddir)/libnm-glib/libnm-glib.la \ - $(DBUS_LIBS) \ - $(GLIB_LIBS) +add_connection_gdbus_SOURCES = add-connection-gdbus.c +add_connection_gdbus_LDADD = \ + $(GLIB_LIBS) \ + $(UUID_LIBS) -get_active_connections_dbus_glib_SOURCES = get-active-connections-dbus-glib.c -get_active_connections_dbus_glib_LDADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(DBUS_LIBS) \ +add_connection_libnm_SOURCES = add-connection-libnm.c +add_connection_libnm_LDADD = \ + $(top_builddir)/libnm/libnm.la \ $(GLIB_LIBS) -list_connections_dbus_glib_SOURCES = list-connections-dbus-glib.c -list_connections_dbus_glib_LDADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(DBUS_LIBS) \ +get_active_connections_gdbus_SOURCES = get-active-connections-gdbus.c +get_active_connections_gdbus_LDADD = \ $(GLIB_LIBS) -list_connections_libnm_glib_SOURCES = list-connections-libnm-glib.c -list_connections_libnm_glib_LDADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(top_builddir)/libnm-glib/libnm-glib.la \ - $(DBUS_LIBS) \ +get_ap_info_libnm_SOURCES = get-ap-info-libnm.c +get_ap_info_libnm_LDADD = \ + $(top_builddir)/libnm/libnm.la \ $(GLIB_LIBS) -get_ap_info_libnm_glib_SOURCES = get-ap-info-libnm-glib.c -get_ap_info_libnm_glib_LDADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(top_builddir)/libnm-glib/libnm-glib.la \ - $(DBUS_LIBS) \ +list_connections_gdbus_SOURCES = list-connections-gdbus.c +list_connections_gdbus_LDADD = \ $(GLIB_LIBS) -monitor_nm_running_dbus_glib_SOURCES = monitor-nm-running-dbus-glib.c -monitor_nm_running_dbus_glib_LDADD = \ - $(DBUS_LIBS) \ +list_connections_libnm_SOURCES = list-connections-libnm.c +list_connections_libnm_LDADD = \ + $(top_builddir)/libnm/libnm.la \ $(GLIB_LIBS) -monitor_nm_running_GDBus_SOURCES = monitor-nm-running-GDBus.c -monitor_nm_running_GDBus_LDADD = \ +monitor_nm_running_gdbus_SOURCES = monitor-nm-running-gdbus.c +monitor_nm_running_gdbus_LDADD = \ $(GLIB_LIBS) -monitor_nm_state_GDBus_SOURCES = monitor-nm-state-GDBus.c -monitor_nm_state_GDBus_LDADD = \ +monitor_nm_state_gdbus_SOURCES = monitor-nm-state-gdbus.c +monitor_nm_state_gdbus_LDADD = \ $(GLIB_LIBS) -EXTRA_DIST = \ - add-connection-dbus-glib.c \ - add-connection-libnm-glib.c \ - get-active-connections-dbus-glib.c \ - list-connections-dbus-glib.c \ - list-connections-libnm-glib.c \ - get-ap-info-libnm-glib.c \ - monitor-nm-running-dbus-glib.c \ - monitor-nm-running-GDBus.c \ - monitor-nm-state-GDBus.c - all: all-am .SUFFIXES: @@ -622,41 +567,37 @@ clean-noinstPROGRAMS: echo " rm -f" $$list; \ rm -f $$list -add-connection-dbus-glib$(EXEEXT): $(add_connection_dbus_glib_OBJECTS) $(add_connection_dbus_glib_DEPENDENCIES) $(EXTRA_add_connection_dbus_glib_DEPENDENCIES) - @rm -f add-connection-dbus-glib$(EXEEXT) - $(AM_V_CCLD)$(LINK) $(add_connection_dbus_glib_OBJECTS) $(add_connection_dbus_glib_LDADD) $(LIBS) - -add-connection-libnm-glib$(EXEEXT): $(add_connection_libnm_glib_OBJECTS) $(add_connection_libnm_glib_DEPENDENCIES) $(EXTRA_add_connection_libnm_glib_DEPENDENCIES) - @rm -f add-connection-libnm-glib$(EXEEXT) - $(AM_V_CCLD)$(LINK) $(add_connection_libnm_glib_OBJECTS) $(add_connection_libnm_glib_LDADD) $(LIBS) +add-connection-gdbus$(EXEEXT): $(add_connection_gdbus_OBJECTS) $(add_connection_gdbus_DEPENDENCIES) $(EXTRA_add_connection_gdbus_DEPENDENCIES) + @rm -f add-connection-gdbus$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(add_connection_gdbus_OBJECTS) $(add_connection_gdbus_LDADD) $(LIBS) -get-active-connections-dbus-glib$(EXEEXT): $(get_active_connections_dbus_glib_OBJECTS) $(get_active_connections_dbus_glib_DEPENDENCIES) $(EXTRA_get_active_connections_dbus_glib_DEPENDENCIES) - @rm -f get-active-connections-dbus-glib$(EXEEXT) - $(AM_V_CCLD)$(LINK) $(get_active_connections_dbus_glib_OBJECTS) $(get_active_connections_dbus_glib_LDADD) $(LIBS) +add-connection-libnm$(EXEEXT): $(add_connection_libnm_OBJECTS) $(add_connection_libnm_DEPENDENCIES) $(EXTRA_add_connection_libnm_DEPENDENCIES) + @rm -f add-connection-libnm$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(add_connection_libnm_OBJECTS) $(add_connection_libnm_LDADD) $(LIBS) -get-ap-info-libnm-glib$(EXEEXT): $(get_ap_info_libnm_glib_OBJECTS) $(get_ap_info_libnm_glib_DEPENDENCIES) $(EXTRA_get_ap_info_libnm_glib_DEPENDENCIES) - @rm -f get-ap-info-libnm-glib$(EXEEXT) - $(AM_V_CCLD)$(LINK) $(get_ap_info_libnm_glib_OBJECTS) $(get_ap_info_libnm_glib_LDADD) $(LIBS) +get-active-connections-gdbus$(EXEEXT): $(get_active_connections_gdbus_OBJECTS) $(get_active_connections_gdbus_DEPENDENCIES) $(EXTRA_get_active_connections_gdbus_DEPENDENCIES) + @rm -f get-active-connections-gdbus$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(get_active_connections_gdbus_OBJECTS) $(get_active_connections_gdbus_LDADD) $(LIBS) -list-connections-dbus-glib$(EXEEXT): $(list_connections_dbus_glib_OBJECTS) $(list_connections_dbus_glib_DEPENDENCIES) $(EXTRA_list_connections_dbus_glib_DEPENDENCIES) - @rm -f list-connections-dbus-glib$(EXEEXT) - $(AM_V_CCLD)$(LINK) $(list_connections_dbus_glib_OBJECTS) $(list_connections_dbus_glib_LDADD) $(LIBS) +get-ap-info-libnm$(EXEEXT): $(get_ap_info_libnm_OBJECTS) $(get_ap_info_libnm_DEPENDENCIES) $(EXTRA_get_ap_info_libnm_DEPENDENCIES) + @rm -f get-ap-info-libnm$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(get_ap_info_libnm_OBJECTS) $(get_ap_info_libnm_LDADD) $(LIBS) -list-connections-libnm-glib$(EXEEXT): $(list_connections_libnm_glib_OBJECTS) $(list_connections_libnm_glib_DEPENDENCIES) $(EXTRA_list_connections_libnm_glib_DEPENDENCIES) - @rm -f list-connections-libnm-glib$(EXEEXT) - $(AM_V_CCLD)$(LINK) $(list_connections_libnm_glib_OBJECTS) $(list_connections_libnm_glib_LDADD) $(LIBS) +list-connections-gdbus$(EXEEXT): $(list_connections_gdbus_OBJECTS) $(list_connections_gdbus_DEPENDENCIES) $(EXTRA_list_connections_gdbus_DEPENDENCIES) + @rm -f list-connections-gdbus$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(list_connections_gdbus_OBJECTS) $(list_connections_gdbus_LDADD) $(LIBS) -monitor-nm-running-GDBus$(EXEEXT): $(monitor_nm_running_GDBus_OBJECTS) $(monitor_nm_running_GDBus_DEPENDENCIES) $(EXTRA_monitor_nm_running_GDBus_DEPENDENCIES) - @rm -f monitor-nm-running-GDBus$(EXEEXT) - $(AM_V_CCLD)$(LINK) $(monitor_nm_running_GDBus_OBJECTS) $(monitor_nm_running_GDBus_LDADD) $(LIBS) +list-connections-libnm$(EXEEXT): $(list_connections_libnm_OBJECTS) $(list_connections_libnm_DEPENDENCIES) $(EXTRA_list_connections_libnm_DEPENDENCIES) + @rm -f list-connections-libnm$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(list_connections_libnm_OBJECTS) $(list_connections_libnm_LDADD) $(LIBS) -monitor-nm-running-dbus-glib$(EXEEXT): $(monitor_nm_running_dbus_glib_OBJECTS) $(monitor_nm_running_dbus_glib_DEPENDENCIES) $(EXTRA_monitor_nm_running_dbus_glib_DEPENDENCIES) - @rm -f monitor-nm-running-dbus-glib$(EXEEXT) - $(AM_V_CCLD)$(LINK) $(monitor_nm_running_dbus_glib_OBJECTS) $(monitor_nm_running_dbus_glib_LDADD) $(LIBS) +monitor-nm-running-gdbus$(EXEEXT): $(monitor_nm_running_gdbus_OBJECTS) $(monitor_nm_running_gdbus_DEPENDENCIES) $(EXTRA_monitor_nm_running_gdbus_DEPENDENCIES) + @rm -f monitor-nm-running-gdbus$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(monitor_nm_running_gdbus_OBJECTS) $(monitor_nm_running_gdbus_LDADD) $(LIBS) -monitor-nm-state-GDBus$(EXEEXT): $(monitor_nm_state_GDBus_OBJECTS) $(monitor_nm_state_GDBus_DEPENDENCIES) $(EXTRA_monitor_nm_state_GDBus_DEPENDENCIES) - @rm -f monitor-nm-state-GDBus$(EXEEXT) - $(AM_V_CCLD)$(LINK) $(monitor_nm_state_GDBus_OBJECTS) $(monitor_nm_state_GDBus_LDADD) $(LIBS) +monitor-nm-state-gdbus$(EXEEXT): $(monitor_nm_state_gdbus_OBJECTS) $(monitor_nm_state_gdbus_DEPENDENCIES) $(EXTRA_monitor_nm_state_gdbus_DEPENDENCIES) + @rm -f monitor-nm-state-gdbus$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(monitor_nm_state_gdbus_OBJECTS) $(monitor_nm_state_gdbus_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -664,15 +605,14 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/add-connection-dbus-glib.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/add-connection-libnm-glib.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/get-active-connections-dbus-glib.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/get-ap-info-libnm-glib.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/list-connections-dbus-glib.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/list-connections-libnm-glib.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/monitor-nm-running-GDBus.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/monitor-nm-running-dbus-glib.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/monitor-nm-state-GDBus.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/add-connection-gdbus.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/add-connection-libnm.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/get-active-connections-gdbus.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/get-ap-info-libnm.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/list-connections-gdbus.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/list-connections-libnm.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/monitor-nm-running-gdbus.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/monitor-nm-state-gdbus.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< diff --git a/examples/C/glib/add-connection-dbus-glib.c b/examples/C/glib/add-connection-dbus-glib.c deleted file mode 100644 index 354dcb75..00000000 --- a/examples/C/glib/add-connection-dbus-glib.c +++ /dev/null @@ -1,126 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * (C) Copyright 2011 Red Hat, Inc. - */ - -/* - * The example shows how to call AddConnection() D-Bus method to add - * a connection to system settings service. It uses dbus-glib and libnm-util - * libraries. - * - * Compile with: - * gcc -Wall `pkg-config --libs --cflags glib-2.0 dbus-glib-1 libnm-util` add-connection-glib.c -o add-connection-glib - */ - -#include <glib.h> -#include <dbus/dbus-glib.h> - -#include <nm-connection.h> -#include <nm-setting-connection.h> -#include <nm-setting-wired.h> -#include <nm-setting-ip4-config.h> -#include <NetworkManager.h> -#include <nm-utils.h> - -#define DBUS_TYPE_G_MAP_OF_VARIANT (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE)) -#define DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, DBUS_TYPE_G_MAP_OF_VARIANT)) - -static void -add_connection (DBusGProxy *proxy, const char *con_name) -{ - NMConnection *connection; - NMSettingConnection *s_con; - NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - char *uuid, *new_con_path = NULL; - GHashTable *hash; - GError *error = NULL; - - /* Create a new connection object */ - connection = (NMConnection *) nm_connection_new (); - - /* Build up the 'connection' Setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new (); - uuid = nm_utils_uuid_generate (); - g_object_set (G_OBJECT (s_con), - NM_SETTING_CONNECTION_UUID, uuid, - NM_SETTING_CONNECTION_ID, con_name, - NM_SETTING_CONNECTION_TYPE, "802-3-ethernet", - NULL); - g_free (uuid); - nm_connection_add_setting (connection, NM_SETTING (s_con)); - - /* Build up the 'wired' Setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new (); - nm_connection_add_setting (connection, NM_SETTING (s_wired)); - - /* Build up the 'ipv4' Setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); - g_object_set (G_OBJECT (s_ip4), - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, - NULL); - nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - - hash = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL); - - /* Call AddConnection with the hash as argument */ - if (!dbus_g_proxy_call (proxy, "AddConnection", &error, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, hash, - G_TYPE_INVALID, - DBUS_TYPE_G_OBJECT_PATH, &new_con_path, - G_TYPE_INVALID)) { - g_print ("Error adding connection: %s %s", - dbus_g_error_get_name (error), - error->message); - g_clear_error (&error); - } else { - g_print ("Added: %s\n", new_con_path); - g_free (new_con_path); - } - - g_hash_table_destroy (hash); - g_object_unref (connection); -} - - -int main (int argc, char *argv[]) -{ - DBusGConnection *bus; - DBusGProxy *proxy; - -#if !GLIB_CHECK_VERSION (2, 35, 0) - /* Initialize GType system */ - g_type_init (); -#endif - - /* Get system bus */ - bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL); - - /* Create a D-Bus proxy; NM_DBUS_* defined in NetworkManager.h */ - proxy = dbus_g_proxy_new_for_name (bus, - NM_DBUS_SERVICE, - NM_DBUS_PATH_SETTINGS, - NM_DBUS_IFACE_SETTINGS); - - /* Add a connection */ - add_connection (proxy, "__Test connection__"); - - g_object_unref (proxy); - dbus_g_connection_unref (bus); - - return 0; -} diff --git a/examples/C/glib/add-connection-gdbus.c b/examples/C/glib/add-connection-gdbus.c new file mode 100644 index 00000000..d3903273 --- /dev/null +++ b/examples/C/glib/add-connection-gdbus.c @@ -0,0 +1,150 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2011, 2014 Red Hat, Inc. + */ + +/* + * The example shows how to call the AddConnection() D-Bus method to add a + * connection to the system settings service. It uses GDBus, plus a few defines + * from the NetworkManager headers. Contrast add-connection-libnm, which is + * higher level because it uses libnm. + * + * Compile with: + * gcc -Wall `pkg-config --cflags libnm` `pkg-config --cflags --libs gio-2.0` -luuid add-connection-gdbus.c -o add-connection-gdbus + */ + +#include "config.h" + +#include <gio/gio.h> +#include <uuid/uuid.h> +#include <NetworkManager.h> + +/* copied from libnm-core/nm-utils.c */ +char * +nm_utils_uuid_generate (void) +{ + uuid_t uuid; + char *buf; + + buf = g_malloc0 (37); + uuid_generate_random (uuid); + uuid_unparse_lower (uuid, &buf[0]); + return buf; +} + +static void +add_connection (GDBusProxy *proxy, const char *con_name) +{ + GVariantBuilder connection_builder; + GVariantBuilder setting_builder; + char *uuid; + const char *new_con_path; + GVariant *ret; + GError *error = NULL; + + /* Initialize connection GVariantBuilder */ + g_variant_builder_init (&connection_builder, G_VARIANT_TYPE ("a{sa{sv}}")); + + /* Build up the 'connection' Setting */ + g_variant_builder_init (&setting_builder, G_VARIANT_TYPE ("a{sv}")); + + uuid = nm_utils_uuid_generate (); + g_variant_builder_add (&setting_builder, "{sv}", + NM_SETTING_CONNECTION_UUID, + g_variant_new_string (uuid)); + g_free (uuid); + + g_variant_builder_add (&setting_builder, "{sv}", + NM_SETTING_CONNECTION_ID, + g_variant_new_string (con_name)); + g_variant_builder_add (&setting_builder, "{sv}", + NM_SETTING_CONNECTION_TYPE, + g_variant_new_string (NM_SETTING_WIRED_SETTING_NAME)); + + g_variant_builder_add (&connection_builder, "{sa{sv}}", + NM_SETTING_CONNECTION_SETTING_NAME, + &setting_builder); + + /* Add the (empty) 'wired' Setting */ + g_variant_builder_init (&setting_builder, G_VARIANT_TYPE ("a{sv}")); + g_variant_builder_add (&connection_builder, "{sa{sv}}", + NM_SETTING_WIRED_SETTING_NAME, + &setting_builder); + + /* Build up the 'ipv4' Setting */ + g_variant_builder_init (&setting_builder, G_VARIANT_TYPE ("a{sv}")); + g_variant_builder_add (&setting_builder, "{sv}", + NM_SETTING_IP_CONFIG_METHOD, + g_variant_new_string (NM_SETTING_IP4_CONFIG_METHOD_AUTO)); + g_variant_builder_add (&connection_builder, "{sa{sv}}", + NM_SETTING_IP4_CONFIG_SETTING_NAME, + &setting_builder); + + /* Call AddConnection with the connection dictionary as argument. + * (g_variant_new() will consume the floating GVariant returned from + * &connection_builder, and g_dbus_proxy_call_sync() will consume the + * floating variant returned from g_variant_new(), so no cleanup is needed. + */ + ret = g_dbus_proxy_call_sync (proxy, + "AddConnection", + g_variant_new ("(a{sa{sv}})", &connection_builder), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, &error); + if (ret) { + g_variant_get (ret, "(&o)", &new_con_path); + g_print ("Added: %s\n", new_con_path); + g_variant_unref (ret); + } else { + g_dbus_error_strip_remote_error (error); + g_print ("Error adding connection: %s\n", error->message); + g_clear_error (&error); + } +} + +int +main (int argc, char *argv[]) +{ + GDBusProxy *proxy; + GError *error = NULL; + +#if !GLIB_CHECK_VERSION (2, 35, 0) + /* Initialize GType system */ + g_type_init (); +#endif + + /* Create a D-Bus proxy; NM_DBUS_* defined in nm-dbus-interface.h */ + proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + NM_DBUS_SERVICE, + NM_DBUS_PATH_SETTINGS, + NM_DBUS_INTERFACE_SETTINGS, + NULL, &error); + if (!proxy) { + g_dbus_error_strip_remote_error (error); + g_print ("Could not create NetworkManager D-Bus proxy: %s\n", error->message); + g_error_free (error); + return 1; + } + + /* Add a connection */ + add_connection (proxy, "__Test connection__"); + + g_object_unref (proxy); + + return 0; +} diff --git a/examples/C/glib/add-connection-libnm-glib.c b/examples/C/glib/add-connection-libnm.c index 28eadf8d..75048bd8 100644 --- a/examples/C/glib/add-connection-libnm-glib.c +++ b/examples/C/glib/add-connection-libnm.c @@ -14,61 +14,61 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * (C) Copyright 2011 Red Hat, Inc. + * Copyright 2011 Red Hat, Inc. */ /* - * The example shows how to add a new connection using libnm-glib and libnm-util. - * Contrast this example with add-connection-dbus-glib.c, which is a bit lower - * level and talks directly to NM using dbus-glib. This example is simpler - * because libnm-glib handles much of the low-level stuff for you. + * The example shows how to add a new connection using libnm. Contrast this + * example with add-connection-gdbus.c, which is a bit lower level and talks + * directly to NM using GDBus. This example is simpler because libnm handles + * much of the low-level stuff for you. * * Compile with: - * gcc -Wall `pkg-config --libs --cflags glib-2.0 dbus-glib-1 libnm-util` add-connection-libnm-glib.c -o add-connection-libnm-glib + * gcc -Wall `pkg-config --libs --cflags glib-2.0 libnm` add-connection-libnm.c -o add-connection-libnm */ -#include <glib.h> -#include <nm-remote-settings.h> +#include "config.h" -#include <nm-connection.h> -#include <nm-setting-connection.h> -#include <nm-setting-wired.h> -#include <nm-setting-ip4-config.h> -#include <nm-utils.h> +#include <glib.h> +#include <NetworkManager.h> static void -added_cb (NMRemoteSettings *settings, - NMRemoteConnection *remote, - GError *error, +added_cb (GObject *client, + GAsyncResult *result, gpointer user_data) { GMainLoop *loop = user_data; + NMRemoteConnection *remote; + GError *error; /* NM responded to our request; either handle the resulting error or * print out the object path of the connection we just added. */ + remote = nm_client_add_connection_finish (NM_CLIENT (client), result, &error); - if (error) + if (error) { g_print ("Error adding connection: %s", error->message); - else + g_error_free (error); + } else { g_print ("Added: %s\n", nm_connection_get_path (NM_CONNECTION (remote))); + g_object_unref (remote); + } /* Tell the mainloop we're done and we can quit now */ g_main_loop_quit (loop); } -static gboolean -add_connection (NMRemoteSettings *settings, GMainLoop *loop, const char *con_name) +static void +add_connection (NMClient *client, GMainLoop *loop, const char *con_name) { NMConnection *connection; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIP4Config *s_ip4; char *uuid; - gboolean success; /* Create a new connection object */ - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Build up the 'connection' Setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -88,27 +88,24 @@ add_connection (NMRemoteSettings *settings, GMainLoop *loop, const char *con_nam /* Build up the 'ipv4' Setting */ s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); g_object_set (G_OBJECT (s_ip4), - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); /* Ask the settings service to add the new connection; we'll quit the * mainloop and exit when the callback is called. */ - success = nm_remote_settings_add_connection (settings, connection, added_cb, loop); - if (!success) - g_print ("Error adding connection\n"); - + nm_client_add_connection_async (client, connection, TRUE, NULL, added_cb, loop); g_object_unref (connection); - return success; } -int main (int argc, char *argv[]) +int +main (int argc, char *argv[]) { - DBusGConnection *bus; - NMRemoteSettings *settings; + NMClient *client; GMainLoop *loop; + GError *error = NULL; #if !GLIB_CHECK_VERSION (2, 35, 0) /* Initialize GType system */ @@ -117,22 +114,21 @@ int main (int argc, char *argv[]) loop = g_main_loop_new (NULL, FALSE); - /* Get system bus */ - bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL); - - /* Create our proxy for NetworkManager's settings service */ - settings = nm_remote_settings_new (bus); + /* Connect to NetworkManager */ + client = nm_client_new (NULL, &error); + if (!client) { + g_message ("Error: Could not connect to NetworkManager: %s.", error->message); + g_error_free (error); + return 1; + } - /* Ask the settings service to add the new connection */ - if (add_connection (settings, loop, "__Test connection__")) { - /* Wait for the connection to be added */ - g_main_loop_run (loop); - } else - g_print ("Error adding connection to NetworkManager\n"); + /* Ask NM to add the new connection */ + add_connection (client, loop, "__Test connection__"); + /* Wait for the connection to be added */ + g_main_loop_run (loop); /* Clean up */ - g_object_unref (settings); - dbus_g_connection_unref (bus); + g_object_unref (client); return 0; } diff --git a/examples/C/glib/get-active-connections-dbus-glib.c b/examples/C/glib/get-active-connections-dbus-glib.c deleted file mode 100644 index 186feae2..00000000 --- a/examples/C/glib/get-active-connections-dbus-glib.c +++ /dev/null @@ -1,223 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * (C) Copyright 2010 -2014 Red Hat, Inc. - */ - -/* - * The example shows how to call the D-Bus properties interface to get the - * list of currently active connections known to NetworkManager. It uses - * dbus-glib and libnm-util libraries. - * - * Compile with: - * gcc -Wall `pkg-config --libs --cflags glib-2.0 dbus-glib-1 libnm-util` get-active-connections-dbus-glib.c -o get-active-connections-dbus-glib - */ - -#include <stdio.h> -#include <glib.h> -#include <dbus/dbus-glib.h> - -#include <nm-connection.h> -#include <nm-setting-connection.h> -#include <nm-setting-wired.h> -#include <nm-setting-ip4-config.h> -#include <NetworkManager.h> -#include <nm-utils.h> - -#define DBUS_TYPE_G_MAP_OF_VARIANT (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE)) -#define DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, DBUS_TYPE_G_MAP_OF_VARIANT)) -#define DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH (dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH)) - -static void -print_connection (DBusGConnection *bus, const char *path) -{ - DBusGProxy *proxy; - GError *error = NULL; - GHashTable *hash = NULL; - NMConnection *connection = NULL; - - /* This function asks NetworkManager for the details of the connection */ - - /* Create the D-Bus proxy so we can ask it for the connection configuration details. */ - proxy = dbus_g_proxy_new_for_name (bus, - NM_DBUS_SERVICE, - path, - NM_DBUS_IFACE_SETTINGS_CONNECTION); - g_assert (proxy); - - /* Request the all the configuration of the Connection */ - if (!dbus_g_proxy_call (proxy, "GetSettings", &error, - G_TYPE_INVALID, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &hash, - G_TYPE_INVALID)) { - g_warning ("Failed to get active connection Connection property: %s", - error->message); - g_error_free (error); - goto out; - } - - /* Using the raw configuration, create an NMConnection object for it. This - * step also verifies that the data we got from NetworkManager are valid. */ - connection = nm_connection_new_from_hash (hash, &error); - if (!connection) { - g_warning ("Received invalid connection data: %s", error->message); - g_error_free (error); - goto out; - } - - /* And finally dump all the configuration to stdout */ - printf ("%s <=> %s\n", nm_connection_get_id (connection), path); - nm_connection_dump (connection); - -out: - if (connection) - g_object_unref (connection); - if (hash) - g_hash_table_destroy (hash); - g_object_unref (proxy); -} - -static void -get_active_connection_details (DBusGConnection *bus, const char *obj_path) -{ - DBusGProxy *props_proxy; - GValue path_value = G_VALUE_INIT; - GError *error = NULL; - const char *path = NULL; - - /* This function gets the backing Connection object that describes the - * network configuration that the ActiveConnection object is actually using. - * The ActiveConnection object contains the mapping between the configuration - * and the actual network interfaces that are using that configuration. - */ - - /* Create a D-Bus object proxy for the active connection object's properties */ - props_proxy = dbus_g_proxy_new_for_name (bus, - NM_DBUS_SERVICE, - obj_path, - DBUS_INTERFACE_PROPERTIES); - g_assert (props_proxy); - - /* Get the object path of the Connection details */ - if (!dbus_g_proxy_call (props_proxy, "Get", &error, - G_TYPE_STRING, NM_DBUS_INTERFACE_ACTIVE_CONNECTION, - G_TYPE_STRING, "Connection", - G_TYPE_INVALID, - G_TYPE_VALUE, &path_value, - G_TYPE_INVALID)) { - g_warning ("Failed to get active connection Connection property: %s", - error->message); - g_error_free (error); - goto out; - } - - if (!G_VALUE_HOLDS (&path_value, DBUS_TYPE_G_OBJECT_PATH)) { - g_warning ("Unexpected type returned getting Connection property: %s", - G_VALUE_TYPE_NAME (&path_value)); - goto out; - } - - path = g_value_get_boxed (&path_value); - if (!path) { - g_warning ("Missing connection path!"); - goto out; - } - - /* Print out the actual connection details */ - print_connection (bus, path); - -out: - g_value_unset (&path_value); - g_object_unref (props_proxy); -} - -static void -get_active_connections (DBusGConnection *bus, DBusGProxy *proxy) -{ - GError *error = NULL; - GValue value = G_VALUE_INIT; - GPtrArray *paths = NULL; - const char *a_path; - int i; - - /* Get the ActiveConnections property from the NM Manager object */ - if (!dbus_g_proxy_call (proxy, "Get", &error, - G_TYPE_STRING, NM_DBUS_INTERFACE, - G_TYPE_STRING, "ActiveConnections", - G_TYPE_INVALID, - G_TYPE_VALUE, &value, - G_TYPE_INVALID)) { - g_warning ("Failed to get ActiveConnections property: %s", error->message); - g_error_free (error); - return; - } - - /* Make sure the ActiveConnections property is the type we expect it to be */ - if (!G_VALUE_HOLDS (&value, DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH)) { - g_warning ("Unexpected type returned getting ActiveConnections: %s", - G_VALUE_TYPE_NAME (&value)); - goto out; - } - - /* Extract the active connections array from the GValue */ - paths = g_value_get_boxed (&value); - if (!paths) { - g_warning ("Could not retrieve active connections property"); - goto out; - } - - /* And print out the details for each active connection */ - for (i = 0; i < paths->len; i++) { - a_path = g_ptr_array_index (paths, i); - printf ("Active connection path: %s\n", a_path); - get_active_connection_details (bus, a_path); - } - -out: - g_value_unset (&value); -} - - -int main (int argc, char *argv[]) -{ - DBusGConnection *bus; - DBusGProxy *props_proxy; - -#if !GLIB_CHECK_VERSION (2, 35, 0) - /* Initialize GType system */ - g_type_init (); -#endif - - /* Get system bus */ - bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL); - - /* Create a D-Bus proxy to get the object properties from the NM Manager - * object. NM_DBUS_* defines are from NetworkManager.h. - */ - props_proxy = dbus_g_proxy_new_for_name (bus, - NM_DBUS_SERVICE, - NM_DBUS_PATH, - DBUS_INTERFACE_PROPERTIES); - g_assert (props_proxy); - - /* Get active connections */ - get_active_connections (bus, props_proxy); - - g_object_unref (props_proxy); - dbus_g_connection_unref (bus); - - return 0; -} diff --git a/examples/C/glib/get-active-connections-gdbus.c b/examples/C/glib/get-active-connections-gdbus.c new file mode 100644 index 00000000..9b34f6b2 --- /dev/null +++ b/examples/C/glib/get-active-connections-gdbus.c @@ -0,0 +1,274 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (C) Copyright 2010 -2014 Red Hat, Inc. + */ + +/* + * The example shows how to call the D-Bus properties interface to get the list + * of currently active connections known to NetworkManager. It uses GDBus, plus + * a few defines from the NetworkManager headers. + * + * Compile with: + * gcc -Wall `pkg-config --cflags libnm` `pkg-config --cflags --libs gio-2.0` get-active-connections-gdbus.c -o get-active-connections-gdbus + */ + +#include "config.h" + +#include <string.h> +#include <gio/gio.h> +#include <NetworkManager.h> + +static void +print_setting (const char *setting_name, GVariant *setting) +{ + GVariantIter iter; + const char *property_name; + GVariant *value; + char *printed_value; + + g_print (" %s:\n", setting_name); + g_variant_iter_init (&iter, setting); + while (g_variant_iter_next (&iter, "{&sv}", &property_name, &value)) { + printed_value = g_variant_print (value, FALSE); + if (strcmp (printed_value, "[]") != 0) + g_print (" %s: %s\n", property_name, printed_value); + g_free (printed_value); + g_variant_unref (value); + } +} + +static void +print_connection (const char *path) +{ + GDBusProxy *proxy; + GError *error = NULL; + GVariant *ret, *connection = NULL, *s_con = NULL; + const char *id, *type; + gboolean found; + GVariantIter iter; + const char *setting_name; + GVariant *setting; + + /* This function asks NetworkManager for the details of the connection */ + + /* Create the D-Bus proxy so we can ask it for the connection configuration details. */ + proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + NM_DBUS_SERVICE, + path, + NM_DBUS_INTERFACE_SETTINGS_CONNECTION, + NULL, NULL); + g_assert (proxy); + + /* Request the all the configuration of the Connection */ + ret = g_dbus_proxy_call_sync (proxy, + "GetSettings", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, &error); + if (!ret) { + g_dbus_error_strip_remote_error (error); + g_warning ("Failed to get connection settings: %s\n", error->message); + g_error_free (error); + goto out; + } + + g_variant_get (ret, "(@a{sa{sv}})", &connection); + + s_con = g_variant_lookup_value (connection, NM_SETTING_CONNECTION_SETTING_NAME, NULL); + g_assert (s_con != NULL); + found = g_variant_lookup (s_con, NM_SETTING_CONNECTION_ID, "&s", &id); + g_assert (found); + found = g_variant_lookup (s_con, NM_SETTING_CONNECTION_TYPE, "&s", &type); + g_assert (found); + + /* Dump the configuration to stdout */ + g_print ("%s <=> %s\n", id, path); + + /* Connection setting first */ + print_setting (NM_SETTING_CONNECTION_SETTING_NAME, s_con); + + /* Then the type-specific setting */ + setting = g_variant_lookup_value (connection, type, NULL); + if (setting) { + print_setting (type, setting); + g_variant_unref (setting); + } + + g_variant_iter_init (&iter, connection); + while (g_variant_iter_next (&iter, "{&s@a{sv}}", &setting_name, &setting)) { + if ( strcmp (setting_name, NM_SETTING_CONNECTION_SETTING_NAME) != 0 + && strcmp (setting_name, type) != 0) + print_setting (setting_name, setting); + g_variant_unref (setting); + } + g_print ("\n"); + +out: + if (s_con) + g_variant_unref (s_con); + if (connection) + g_variant_unref (connection); + if (ret) + g_variant_unref (ret); + g_object_unref (proxy); +} + +static void +get_active_connection_details (const char *obj_path) +{ + GDBusProxy *props_proxy; + GVariant *ret = NULL, *path_value = NULL; + const char *path = NULL; + GError *error = NULL; + + /* This function gets the backing Connection object that describes the + * network configuration that the ActiveConnection object is actually using. + * The ActiveConnection object contains the mapping between the configuration + * and the actual network interfaces that are using that configuration. + */ + + /* Create a D-Bus object proxy for the active connection object's properties */ + props_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + NM_DBUS_SERVICE, + obj_path, + "org.freedesktop.DBus.Properties", + NULL, NULL); + g_assert (props_proxy); + + /* Get the object path of the Connection details */ + ret = g_dbus_proxy_call_sync (props_proxy, + "Get", + g_variant_new ("(ss)", + NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + "Connection"), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, &error); + if (!ret) { + g_dbus_error_strip_remote_error (error); + g_warning ("Failed to get active connection Connection property: %s\n", + error->message); + g_error_free (error); + goto out; + } + + g_variant_get (ret, "(v)", &path_value); + if (!g_variant_is_of_type (path_value, G_VARIANT_TYPE_OBJECT_PATH)) { + g_warning ("Unexpected type returned getting Connection property: %s", + g_variant_get_type_string (path_value)); + goto out; + } + + path = g_variant_get_string (path_value, NULL); + + /* Print out the actual connection details */ + print_connection (path); + +out: + if (path_value) + g_variant_unref (path_value); + if (ret) + g_variant_unref (ret); + g_object_unref (props_proxy); +} + +static void +get_active_connections (GDBusProxy *proxy) +{ + GError *error = NULL; + GVariant *ret = NULL, *value = NULL; + char **paths; + int i; + + /* Get the ActiveConnections property from the NM Manager object */ + ret = g_dbus_proxy_call_sync (proxy, + "Get", + g_variant_new ("(ss)", + NM_DBUS_INTERFACE, + "ActiveConnections"), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, &error); + if (!ret) { + g_dbus_error_strip_remote_error (error); + g_warning ("Failed to get ActiveConnections property: %s\n", error->message); + g_error_free (error); + return; + } + + g_variant_get (ret, "(v)", &value); + + /* Make sure the ActiveConnections property is the type we expect it to be */ + if (!g_variant_is_of_type (value, G_VARIANT_TYPE ("ao"))) { + g_warning ("Unexpected type returned getting ActiveConnections: %s", + g_variant_get_type_string (value)); + goto out; + } + + /* Extract the active connections array from the GValue */ + paths = g_variant_dup_objv (value, NULL); + if (!paths) { + g_warning ("Could not retrieve active connections property"); + goto out; + } + + /* And print out the details for each active connection */ + for (i = 0; paths[i]; i++) { + g_print ("Active connection path: %s\n", paths[i]); + get_active_connection_details (paths[i]); + } + g_strfreev (paths); + +out: + if (value) + g_variant_unref (value); + if (ret) + g_variant_unref (ret); +} + + +int +main (int argc, char *argv[]) +{ + GDBusProxy *props_proxy; + +#if !GLIB_CHECK_VERSION (2, 35, 0) + /* Initialize GType system */ + g_type_init (); +#endif + + /* Create a D-Bus proxy to get the object properties from the NM Manager + * object. NM_DBUS_* defines are from nm-dbus-interface.h. + */ + props_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + NM_DBUS_SERVICE, + NM_DBUS_PATH, + "org.freedesktop.DBus.Properties", + NULL, NULL); + g_assert (props_proxy); + + /* Get active connections */ + get_active_connections (props_proxy); + + g_object_unref (props_proxy); + + return 0; +} diff --git a/examples/C/glib/get-ap-info-libnm-glib.c b/examples/C/glib/get-ap-info-libnm.c index 1ad58124..90bc2d5e 100644 --- a/examples/C/glib/get-ap-info-libnm-glib.c +++ b/examples/C/glib/get-ap-info-libnm.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -13,29 +14,24 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * (C) Copyright 2010 Red Hat, Inc. + * Copyright 2010 Red Hat, Inc. */ /* - * The example shows how to get info about APs visible by Wi-Fi devices - * using libnm-glib (that wraps direct D-Bus calls). - * The example uses dbus-glib, libnm-util and libnm-glib libraries. + * The example shows how to get info about APs visible by Wi-Fi devices using + * libnm. * * Compile with: - * gcc -Wall `pkg-config --libs --cflags glib-2.0 dbus-glib-1 libnm-util libnm-glib` get-ap-info-libnm-glib.c -o get-ap-info-libnm-glib + * gcc -Wall `pkg-config --libs --cflags glib-2.0 libnm` get-ap-info-libnm.c -o get-ap-info-libnm */ +#include "config.h" + #include <glib.h> -#include <dbus/dbus-glib.h> #include <stdio.h> #include <stdlib.h> -#include <nm-client.h> -#include <nm-device.h> -#include <nm-device-wifi.h> -#include <nm-access-point.h> #include <NetworkManager.h> -#include <nm-utils.h> /* Convert flags to string */ static char * @@ -85,7 +81,7 @@ show_access_point_info (NMAccessPoint *ap) { guint32 flags, wpa_flags, rsn_flags, freq, bitrate; guint8 strength; - const GByteArray *ssid; + GBytes *ssid; const char *hwaddr; NM80211Mode mode; char *freq_str, *ssid_str, *bitrate_str, *strength_str, *wpa_flags_str, *rsn_flags_str; @@ -103,7 +99,10 @@ show_access_point_info (NMAccessPoint *ap) strength = nm_access_point_get_strength (ap); /* Convert to strings */ - ssid_str = nm_utils_ssid_to_utf8 (ssid); + if (ssid) + ssid_str = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid)); + else + ssid_str = g_strdup ("--"); freq_str = g_strdup_printf ("%u MHz", freq); bitrate_str = g_strdup_printf ("%u Mbit/s", bitrate/1000); strength_str = g_strdup_printf ("%u", strength); @@ -161,7 +160,7 @@ show_wifi_device_info (NMDevice *device) const char *iface; const char *driver; guint32 speed; - const GByteArray *active_ssid; + GBytes *active_ssid; char *active_ssid_str = NULL; int i; @@ -169,7 +168,11 @@ show_wifi_device_info (NMDevice *device) if (nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED) { if ((active_ap = nm_device_wifi_get_active_access_point (NM_DEVICE_WIFI (device)))) { active_ssid = nm_access_point_get_ssid (active_ap); - active_ssid_str = nm_utils_ssid_to_utf8 (active_ssid); + if (active_ssid) + active_ssid_str = nm_utils_ssid_to_utf8 (g_bytes_get_data (active_ssid, NULL), + g_bytes_get_size (active_ssid)); + else + active_ssid_str = g_strdup ("--"); } } @@ -187,32 +190,30 @@ show_wifi_device_info (NMDevice *device) aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device)); /* Print AP details */ - for (i = 0; aps && (i < aps->len); i++) { + for (i = 0; i < aps->len; i++) { NMAccessPoint *ap = g_ptr_array_index (aps, i); show_access_point_info (ap); } } -int main (int argc, char *argv[]) +int +main (int argc, char *argv[]) { - DBusGConnection *bus; NMClient *client; const GPtrArray *devices; int i; + GError *error = NULL; #if !GLIB_CHECK_VERSION (2, 35, 0) /* Initialize GType system */ g_type_init (); #endif - /* Get system bus */ - bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL); - /* Get NMClient object */ - client = nm_client_new (); + client = nm_client_new (NULL, &error); if (!client) { - dbus_g_connection_unref (bus); - g_message ("Error: Could not create NMClient."); + g_message ("Error: Could not create NMClient: %s.", error->message); + g_error_free (error); return EXIT_FAILURE; } @@ -220,14 +221,13 @@ int main (int argc, char *argv[]) devices = nm_client_get_devices (client); /* Go through the array and process Wi-Fi devices */ - for (i = 0; devices && (i < devices->len); i++) { + for (i = 0; i < devices->len; i++) { NMDevice *device = g_ptr_array_index (devices, i); if (NM_IS_DEVICE_WIFI (device)) show_wifi_device_info (device); } g_object_unref (client); - dbus_g_connection_unref (bus); return EXIT_SUCCESS; } diff --git a/examples/C/glib/list-connections-dbus-glib.c b/examples/C/glib/list-connections-dbus-glib.c deleted file mode 100644 index e17b8dc7..00000000 --- a/examples/C/glib/list-connections-dbus-glib.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * (C) Copyright 2011 Red Hat, Inc. - */ - -/* - * The example shows how to list connections from System Settings service using direct - * D-Bus call of ListConnections method. - * The example uses dbus-glib, libnm-util libraries. - * - * Compile with: - * gcc -Wall `pkg-config --libs --cflags glib-2.0 dbus-glib-1 libnm-util` list-connections-dbus.c -o list-connections-dbus - */ - -#include <glib.h> -#include <dbus/dbus-glib.h> -#include <stdio.h> - -#include <NetworkManager.h> -#include <nm-utils.h> - -#define DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH (dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH)) - -static void -list_connections (DBusGProxy *proxy) -{ - int i; - GError *error = NULL; - GPtrArray *con_array; - gboolean success; - - /* Call ListConnections D-Bus method */ - success = dbus_g_proxy_call (proxy, "ListConnections", &error, - /* No input arguments */ - G_TYPE_INVALID, - DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, &con_array, /* Return values */ - G_TYPE_INVALID); - if (!success) { - printf ("ListConnections failed: %s", error->message); - g_error_free (error); - return; - } - - for (i = 0; con_array && i < con_array->len; i++) { - char *connection_path = g_ptr_array_index (con_array, i); - printf ("%s\n", connection_path); - g_free (connection_path); - } - g_ptr_array_free (con_array, TRUE); -} - -int main (int argc, char *argv[]) -{ - DBusGConnection *bus; - DBusGProxy *proxy; - -#if !GLIB_CHECK_VERSION (2, 35, 0) - /* Initialize GType system */ - g_type_init (); -#endif - - /* Get system bus */ - bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL); - - /* Create a D-Bus proxy; NM_DBUS_* defined in NetworkManager.h */ - proxy = dbus_g_proxy_new_for_name (bus, - NM_DBUS_SERVICE, - NM_DBUS_PATH_SETTINGS, - NM_DBUS_IFACE_SETTINGS); - - /* List connections of system settings service */ - list_connections (proxy); - - g_object_unref (proxy); - dbus_g_connection_unref (bus); - - return 0; -} diff --git a/examples/C/glib/list-connections-gdbus.c b/examples/C/glib/list-connections-gdbus.c new file mode 100644 index 00000000..634bd90c --- /dev/null +++ b/examples/C/glib/list-connections-gdbus.c @@ -0,0 +1,90 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2011, 2014 Red Hat, Inc. + */ + +/* + * The example shows how to list connections from the System Settings service + * using direct D-Bus calls. The example uses GDBus, plus a few defines from + * the NetworkManager headers. Contrast list-connections-libnm, which is higher + * level because it uses libnm. + * + * Compile with: + * gcc -Wall `pkg-config --cflags libnm` `pkg-config --cflags --libs gio-2.0` list-connections-gdbus.c -o list-connections-gdbus + */ + +#include "config.h" + +#include <gio/gio.h> +#include <NetworkManager.h> + +static void +list_connections (GDBusProxy *proxy) +{ + int i; + GError *error = NULL; + GVariant *ret; + char **paths; + + /* Call ListConnections D-Bus method */ + ret = g_dbus_proxy_call_sync (proxy, + "ListConnections", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, &error); + if (!ret) { + g_dbus_error_strip_remote_error (error); + g_print ("ListConnections failed: %s\n", error->message); + g_error_free (error); + return; + } + + g_variant_get (ret, "(^ao)", &paths); + g_variant_unref (ret); + + for (i = 0; paths[i]; i++) + g_print ("%s\n", paths[i]); + g_strfreev (paths); +} + +int +main (int argc, char *argv[]) +{ + GDBusProxy *proxy; + +#if !GLIB_CHECK_VERSION (2, 35, 0) + /* Initialize GType system */ + g_type_init (); +#endif + + /* Create a D-Bus proxy; NM_DBUS_* defined in nm-dbus-interface.h */ + proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + NM_DBUS_SERVICE, + NM_DBUS_PATH_SETTINGS, + NM_DBUS_INTERFACE_SETTINGS, + NULL, NULL); + g_assert (proxy != NULL); + + /* List connections of system settings service */ + list_connections (proxy); + + g_object_unref (proxy); + + return 0; +} diff --git a/examples/C/glib/list-connections-libnm-glib.c b/examples/C/glib/list-connections-libnm-glib.c deleted file mode 100644 index 29f105c6..00000000 --- a/examples/C/glib/list-connections-libnm-glib.c +++ /dev/null @@ -1,178 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * (C) Copyright 2011 Red Hat, Inc. - */ - -/* - * The example shows how to list connections from System Settings service using libnm-glib - * (that wraps direct D-Bus calls). - * The example uses dbus-glib, libnm-util and libnm-glib libraries. - * - * Compile with: - * gcc -Wall `pkg-config --libs --cflags glib-2.0 dbus-glib-1 libnm-util libnm-glib` list-connections-libnm-glib.c -o list-connections-libnm-glib - */ - -#include <glib.h> -#include <dbus/dbus-glib.h> -#include <stdio.h> -#include <stdlib.h> -#include <signal.h> - -#include <nm-connection.h> -#include <nm-setting-connection.h> -#include <NetworkManager.h> -#include <nm-utils.h> -#include <nm-remote-settings.h> - - -/* Global variables */ -GMainLoop *loop = NULL; /* Main loop variable - needed for waiting for signal */ -int result = EXIT_SUCCESS; - -static void -signal_handler (int signo) -{ - if (signo == SIGINT || signo == SIGTERM) { - g_message ("Caught signal %d, shutting down...", signo); - g_main_loop_quit (loop); - } -} - -static void -setup_signals (void) -{ - struct sigaction action; - sigset_t mask; - - sigemptyset (&mask); - action.sa_handler = signal_handler; - action.sa_mask = mask; - action.sa_flags = 0; - sigaction (SIGTERM, &action, NULL); - sigaction (SIGINT, &action, NULL); -} - -/* Print details of connection */ -static void -show_connection (gpointer data, gpointer user_data) -{ - NMConnection *connection = (NMConnection *) data; - NMSettingConnection *s_con; - guint64 timestamp; - char *timestamp_str; - char timestamp_real_str[64]; - const char *val1, *val2, *val3, *val4, *val5; - - s_con = nm_connection_get_setting_connection (connection); - if (s_con) { - /* Get various info from NMSettingConnection and show it */ - timestamp = nm_setting_connection_get_timestamp (s_con); - timestamp_str = g_strdup_printf ("%" G_GUINT64_FORMAT, timestamp); - strftime (timestamp_real_str, sizeof (timestamp_real_str), "%c", localtime ((time_t *) ×tamp)); - - val1 = nm_setting_connection_get_id (s_con); - val2 = nm_setting_connection_get_uuid (s_con); - val3 = nm_setting_connection_get_connection_type (s_con); - val4 = nm_connection_get_path (connection); - val5 = timestamp ? timestamp_real_str : "never"; - - printf ("%-25s | %s | %-15s | %-43s | %s\n", val1, val2, val3, val4, val5); - - g_free (timestamp_str); - } -} - -/* This callback is called when connections from the settings service are ready. - * Now the connections can be listed. - */ -static void -get_connections_cb (NMRemoteSettings *settings, gpointer user_data) -{ - GSList *connections; - - connections = nm_remote_settings_list_connections (settings); - - printf ("Connections:\n===================\n"); - - g_slist_foreach (connections, show_connection, NULL); - - g_slist_free (connections); - g_object_unref (settings); - - /* We are done, exit main loop */ - g_main_loop_quit (loop); -} - -/* Get system settings and then connect to connections-read signal */ -static gboolean -list_connections (gpointer data) -{ - DBusGConnection *bus = (DBusGConnection *) data; - NMRemoteSettings *settings; - gboolean settings_running; - - /* Get system settings */ - if (!(settings = nm_remote_settings_new (bus))) { - g_message ("Error: Could not get system settings."); - result = EXIT_FAILURE; - g_main_loop_quit (loop); - return FALSE; - } - - /* Find out whether setting service is running */ - g_object_get (settings, NM_REMOTE_SETTINGS_SERVICE_RUNNING, &settings_running, NULL); - - if (!settings_running) { - g_message ("Error: Can't obtain connections: settings service is not running."); - result = EXIT_FAILURE; - g_main_loop_quit (loop); - return FALSE; - } - - /* Connect to signal "connections-read" - emitted when connections are fetched and ready */ - g_signal_connect (settings, NM_REMOTE_SETTINGS_CONNECTIONS_READ, - G_CALLBACK (get_connections_cb), NULL); - - return FALSE; -} - -int main (int argc, char *argv[]) -{ - DBusGConnection *bus; - -#if !GLIB_CHECK_VERSION (2, 35, 0) - /* Initialize GType system */ - g_type_init (); -#endif - - /* Get system bus */ - bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL); - - /* Run list_connections from main loop, because we need to wait for "connections-read" - * signal to have connections ready. The execution will be finished in get_connections_cb() - * callback on the signal. - */ - g_idle_add (list_connections, bus); - - loop = g_main_loop_new (NULL, FALSE); /* Create main loop */ - setup_signals (); /* Setup UNIX signals */ - g_main_loop_run (loop); /* Run main loop */ - - g_main_loop_unref (loop); - dbus_g_connection_unref (bus); - - return result; -} diff --git a/examples/C/glib/list-connections-libnm.c b/examples/C/glib/list-connections-libnm.c new file mode 100644 index 00000000..d5cdf361 --- /dev/null +++ b/examples/C/glib/list-connections-libnm.c @@ -0,0 +1,101 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2011 Red Hat, Inc. + */ + +/* + * The example shows how to list connections. Contrast this example with + * list-connections-gdbus.c, which is a bit lower level and talks directly to NM + * using GDBus. + * + * Compile with: + * gcc -Wall `pkg-config --libs --cflags glib-2.0 libnm` list-connections-libnm.c -o list-connections-libnm + */ + +#include "config.h" + +#include <glib.h> +#include <stdio.h> +#include <stdlib.h> + +#include <NetworkManager.h> + +/* Print details of connection */ +static void +show_connection (NMConnection *connection) +{ + NMSettingConnection *s_con; + guint64 timestamp; + char *timestamp_str; + char timestamp_real_str[64]; + const char *val1, *val2, *val3, *val4, *val5; + + s_con = nm_connection_get_setting_connection (connection); + if (s_con) { + /* Get various info from NMSettingConnection and show it */ + timestamp = nm_setting_connection_get_timestamp (s_con); + timestamp_str = g_strdup_printf ("%" G_GUINT64_FORMAT, timestamp); + strftime (timestamp_real_str, sizeof (timestamp_real_str), "%c", localtime ((time_t *) ×tamp)); + + val1 = nm_setting_connection_get_id (s_con); + val2 = nm_setting_connection_get_uuid (s_con); + val3 = nm_setting_connection_get_connection_type (s_con); + val4 = nm_connection_get_path (connection); + val5 = timestamp ? timestamp_real_str : "never"; + + printf ("%-25s | %s | %-15s | %-43s | %s\n", val1, val2, val3, val4, val5); + + g_free (timestamp_str); + } +} + +int +main (int argc, char *argv[]) +{ + NMClient *client; + GError *error = NULL; + const GPtrArray *connections; + int i; + +#if !GLIB_CHECK_VERSION (2, 35, 0) + /* Initialize GType system */ + g_type_init (); +#endif + + if (!(client = nm_client_new (NULL, &error))) { + g_message ("Error: Could not connect to NetworkManager: %s.", error->message); + g_error_free (error); + return EXIT_FAILURE; + } + + if (!nm_client_get_nm_running (client)) { + g_message ("Error: Can't obtain connections: NetworkManager is not running."); + return EXIT_FAILURE; + } + + /* Now the connections can be listed. */ + connections = nm_client_get_connections (client); + + printf ("Connections:\n===================\n"); + + for (i = 0; i < connections->len; i++) + show_connection (connections->pdata[i]); + + g_object_unref (client); + + return EXIT_SUCCESS; +} diff --git a/examples/C/glib/monitor-nm-running-dbus-glib.c b/examples/C/glib/monitor-nm-running-dbus-glib.c deleted file mode 100644 index 0b01a57f..00000000 --- a/examples/C/glib/monitor-nm-running-dbus-glib.c +++ /dev/null @@ -1,127 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* vim: set ft=c ts=4 sts=4 sw=4 noexpandtab smartindent: */ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * (C) Copyright 2012 Red Hat, Inc. - */ - -/* - * This example monitors whether NM is running by checking D-Bus - * NameOwnerChanged signal. - * It uses dbus-glib library. - * - * Standalone compilation: - * gcc -Wall `pkg-config --libs --cflags glib-2.0 dbus-glib-1` monitor-nm-running.c -o monitor-nm-running - */ - -#include <glib.h> -#include <dbus/dbus-glib.h> -#include <dbus/dbus-glib-bindings.h> -#include <string.h> - -#define NM_DBUS_SERVICE "org.freedesktop.NetworkManager" - -static void -proxy_name_owner_changed (DBusGProxy *proxy, - const char *name, - const char *old_owner, - const char *new_owner, - gpointer user_data) -{ - gboolean *nm_running = (gboolean *) user_data; - gboolean old_good = (old_owner && strlen (old_owner)); - gboolean new_good = (new_owner && strlen (new_owner)); - gboolean new_running = FALSE; - - /* We are only interested in NetworkManager */ - if (!name || strcmp (name, NM_DBUS_SERVICE) != 0) - return; - - if (!old_good && new_good) - new_running = TRUE; - else if (old_good && !new_good) - new_running = FALSE; - - *nm_running = new_running; - - g_print ("name: '%s', old_owner: '%s', new_owner: '%s'", name, old_owner, new_owner); - g_print (" => NM is %s\n", *nm_running ? "running" : "not running"); -} - - -int -main (int argc, char *argv[]) -{ - DBusGConnection *bus; - DBusGProxy *bus_proxy; - GMainLoop *loop = NULL; - GError *err = NULL; - gboolean nm_running; - -#if !GLIB_CHECK_VERSION (2, 35, 0) - /* Initialize GType system */ - g_type_init (); -#endif - - g_print ("Monitor 'org.freedesktop.NetworkManager' D-Bus name\n"); - g_print ("===================================================\n"); - - /* Get system bus */ - bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL); - - /* Create a D-Bus proxy to D-Bus daemon */ - bus_proxy = dbus_g_proxy_new_for_name (bus, - "org.freedesktop.DBus", - "/org/freedesktop/DBus", - "org.freedesktop.DBus"); - - if (!bus_proxy) { - g_message ("Error: Couldn't create D-Bus object proxy for org.freedesktop.DBus."); - dbus_g_connection_unref (bus); - return -1; - } - - /* Call NameHasOwner method to find out if NM is running. When NM runs it claims - * 'org.freedesktop.NetworkManager' service name on D-Bus */ - if (!org_freedesktop_DBus_name_has_owner (bus_proxy, NM_DBUS_SERVICE, &nm_running, &err)) { - g_message ("Error: NameHasOwner request failed: %s", - (err && err->message) ? err->message : "(unknown)"); - g_clear_error (&err); - g_object_unref (bus_proxy); - dbus_g_connection_unref (bus); - return -1; - } - g_print ("NM is %s\n", nm_running ? "running" : "not running"); - - - /* Connect to NameOwnerChanged signal to monitor NM running state */ - dbus_g_proxy_add_signal (bus_proxy, "NameOwnerChanged", - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_INVALID); - dbus_g_proxy_connect_signal (bus_proxy, - "NameOwnerChanged", - G_CALLBACK (proxy_name_owner_changed), - &nm_running, NULL); - - loop = g_main_loop_new (NULL, FALSE); /* Create main loop */ - g_main_loop_run (loop); /* Run main loop */ - - g_object_unref (bus_proxy); - dbus_g_connection_unref (bus); - - return 0; -} - diff --git a/examples/C/glib/monitor-nm-running-GDBus.c b/examples/C/glib/monitor-nm-running-gdbus.c index 9e38d4c7..e4b3bbbf 100644 --- a/examples/C/glib/monitor-nm-running-GDBus.c +++ b/examples/C/glib/monitor-nm-running-gdbus.c @@ -1,5 +1,4 @@ /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* vim: set ft=c ts=4 sts=4 sw=4 noexpandtab smartindent: */ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,7 +14,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * (C) Copyright 2012 Red Hat, Inc. + * Copyright 2012 Red Hat, Inc. */ /* @@ -26,9 +25,11 @@ * See also http://developer.gnome.org/gio/stable/gio-Watching-Bus-Names.html * * Standalone compilation: - * gcc -Wall `pkg-config --libs --cflags glib-2.0 gio-2.0` monitor-nm-running-GDBus.c -o monitor-nm-running-GDBus + * gcc -Wall `pkg-config --libs --cflags glib-2.0 gio-2.0` monitor-nm-running-gdbus.c -o monitor-nm-running-gdbus */ +#include "config.h" + #include <gio/gio.h> static void diff --git a/examples/C/glib/monitor-nm-state-GDBus.c b/examples/C/glib/monitor-nm-state-gdbus.c index f4019725..aeabcfe1 100644 --- a/examples/C/glib/monitor-nm-state-GDBus.c +++ b/examples/C/glib/monitor-nm-state-gdbus.c @@ -1,5 +1,4 @@ /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* vim: set ft=c ts=4 sts=4 sw=4 noexpandtab smartindent: */ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,24 +14,26 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * (C) Copyright 2012 Red Hat, Inc. + * Copyright 2012 Red Hat, Inc. */ /* * This example monitors NM state via D-Bus "StateChanged" signal on * "org.freedesktop.NetworkManager" object. - * It uses GDBus. + * It uses GDBus and the libnm headers. - * You don't need to have NetworkManager devel package installed. You can just - * grab NetworkManager.h and put it in the path. + * You don't need to have the NetworkManager devel packages installed. You can just + * grab nm-dbus-interface.h and put it in the path. * * Standalone compilation: - * gcc -Wall `pkg-config --libs --cflags glib-2.0 gio-2.0 NetworkManager` monitor-nm-state-GDBus.c -o monitor-nm-state-GDBus + * gcc -Wall `pkg-config --libs --cflags glib-2.0 gio-2.0` `pkg-config --cflags libnm` monitor-nm-state-gdbus.c -o monitor-nm-state-gdbus */ +#include "config.h" + #include <gio/gio.h> #include <string.h> -#include <NetworkManager.h> +#include <nm-dbus-interface.h> static const char * nm_state_to_string (NMState state) @@ -112,6 +113,7 @@ main (int argc, char *argv[]) if (proxy == NULL) { + g_dbus_error_strip_remote_error (error); g_printerr ("Error creating D-Bus proxy: %s\n", error->message); g_error_free (error); return -1; diff --git a/examples/C/qt/Makefile.am b/examples/C/qt/Makefile.am index 15b6bf45..aff4c48e 100644 --- a/examples/C/qt/Makefile.am +++ b/examples/C/qt/Makefile.am @@ -1,6 +1,6 @@ AM_CPPFLAGS = \ - -I${top_srcdir}/include \ - -I${top_builddir}/include \ + -I${top_srcdir}/libnm-core \ + -I${top_builddir}/libnm-core \ $(DBUS_CFLAGS) \ $(QT_CFLAGS) diff --git a/examples/C/qt/Makefile.in b/examples/C/qt/Makefile.in index 6cce9883..f6bb151c 100644 --- a/examples/C/qt/Makefile.in +++ b/examples/C/qt/Makefile.in @@ -200,6 +200,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -323,6 +325,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -342,6 +345,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ @@ -368,7 +372,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_BASE_DIR = @UDEV_BASE_DIR@ +UDEV_DIR = @UDEV_DIR@ USE_NLS = @USE_NLS@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ @@ -448,8 +452,8 @@ with_netconfig = @with_netconfig@ with_resolvconf = @with_resolvconf@ with_valgrind = @with_valgrind@ AM_CPPFLAGS = \ - -I${top_srcdir}/include \ - -I${top_builddir}/include \ + -I${top_srcdir}/libnm-core \ + -I${top_builddir}/libnm-core \ $(DBUS_CFLAGS) \ $(QT_CFLAGS) diff --git a/examples/C/qt/add-connection-wired.cpp b/examples/C/qt/add-connection-wired.cpp index 475eafff..fe790ecd 100644 --- a/examples/C/qt/add-connection-wired.cpp +++ b/examples/C/qt/add-connection-wired.cpp @@ -31,7 +31,7 @@ #include <QtCore/QDebug> -#include "NetworkManager.h" +#include "nm-dbus-interface.h" typedef QMap<QString, QMap<QString, QVariant> > Connection; Q_DECLARE_METATYPE(Connection) @@ -68,7 +68,7 @@ int main() { QDBusInterface interface( NM_DBUS_SERVICE, NM_DBUS_PATH_SETTINGS, - NM_DBUS_IFACE_SETTINGS, + NM_DBUS_INTERFACE_SETTINGS, QDBusConnection::systemBus()); addConnection(interface, "__Test connection__"); diff --git a/examples/C/qt/change-ipv4-addresses.cpp b/examples/C/qt/change-ipv4-addresses.cpp index ca340f7f..8ca3dde2 100644 --- a/examples/C/qt/change-ipv4-addresses.cpp +++ b/examples/C/qt/change-ipv4-addresses.cpp @@ -22,10 +22,10 @@ * It uses Qt and D-Bus libraries to do that. * * Standalone compilation: - * g++ -Wall `pkg-config --libs --cflags NetworkManager QtCore QtDBus QtNetwork` change-ipv4-addresses.cpp -o change-ipv4-addresses + * g++ -Wall `pkg-config --libs --cflags QtCore QtDBus QtNetwork` `pkg-config --cflags libnm` change-ipv4-addresses.cpp -o change-ipv4-addresses * * You don't need to have NetworkManager devel package installed; you can just - * grab NetworkManager.h and put it in the path + * grab nm-dbus-interface.h and put it in the path */ #include <QtDBus/QDBusConnection> @@ -40,7 +40,7 @@ #include "arpa/inet.h" -#include "NetworkManager.h" +#include "nm-dbus-interface.h" typedef QMap<QString, QMap<QString, QVariant> > Connection; Q_DECLARE_METATYPE(Connection) @@ -61,7 +61,7 @@ const QString getConnection(const QString& connectionUuid, Connection *found_con QDBusInterface interface( NM_DBUS_SERVICE, NM_DBUS_PATH_SETTINGS, - NM_DBUS_IFACE_SETTINGS, + NM_DBUS_INTERFACE_SETTINGS, QDBusConnection::systemBus()); // Get connection list and find the connection with 'connectionUuid' @@ -71,7 +71,7 @@ const QString getConnection(const QString& connectionUuid, Connection *found_con ifaceForSettings = new QDBusInterface( NM_DBUS_SERVICE, connection.path(), - NM_DBUS_IFACE_SETTINGS_CONNECTION, + NM_DBUS_INTERFACE_SETTINGS_CONNECTION, QDBusConnection::systemBus()); QDBusReply<Connection> result2 = ifaceForSettings->call("GetSettings"); delete ifaceForSettings; @@ -120,7 +120,7 @@ void changeConnection(const QString& uuid) QDBusInterface interface( NM_DBUS_SERVICE, conPath, - NM_DBUS_IFACE_SETTINGS_CONNECTION, + NM_DBUS_INTERFACE_SETTINGS_CONNECTION, QDBusConnection::systemBus()); // Call Update() D-Bus method to update connection diff --git a/examples/C/qt/list-connections.cpp b/examples/C/qt/list-connections.cpp index fb981664..66f309c8 100644 --- a/examples/C/qt/list-connections.cpp +++ b/examples/C/qt/list-connections.cpp @@ -28,7 +28,7 @@ #include <QtCore/QDebug> -#include "NetworkManager.h" +#include "nm-dbus-interface.h" void listConnections(QDBusInterface& interface) { @@ -44,7 +44,7 @@ int main() { QDBusInterface interface( NM_DBUS_SERVICE, NM_DBUS_PATH_SETTINGS, - NM_DBUS_IFACE_SETTINGS, + NM_DBUS_INTERFACE_SETTINGS, QDBusConnection::systemBus()); listConnections(interface); diff --git a/examples/Makefile.in b/examples/Makefile.in index 8a27af4f..6754f4e6 100644 --- a/examples/Makefile.in +++ b/examples/Makefile.in @@ -189,6 +189,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -312,6 +314,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -331,6 +334,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ @@ -357,7 +361,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_BASE_DIR = @UDEV_BASE_DIR@ +UDEV_DIR = @UDEV_DIR@ USE_NLS = @USE_NLS@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ diff --git a/examples/dispatcher/Makefile.in b/examples/dispatcher/Makefile.in index d577fde1..7e1686ad 100644 --- a/examples/dispatcher/Makefile.in +++ b/examples/dispatcher/Makefile.in @@ -129,6 +129,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -252,6 +254,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -271,6 +274,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ @@ -297,7 +301,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_BASE_DIR = @UDEV_BASE_DIR@ +UDEV_DIR = @UDEV_DIR@ USE_NLS = @USE_NLS@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ diff --git a/examples/python/Makefile.in b/examples/python/Makefile.in index 33893595..fd0edd1c 100644 --- a/examples/python/Makefile.in +++ b/examples/python/Makefile.in @@ -189,6 +189,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -312,6 +314,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -331,6 +334,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ @@ -357,7 +361,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_BASE_DIR = @UDEV_BASE_DIR@ +UDEV_DIR = @UDEV_DIR@ USE_NLS = @USE_NLS@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ diff --git a/examples/python/dbus/Makefile.am b/examples/python/dbus/Makefile.am index 0e884884..dd77f1e9 100644 --- a/examples/python/dbus/Makefile.am +++ b/examples/python/dbus/Makefile.am @@ -1,6 +1,7 @@ EXTRA_DIST = \ nm-state.py \ add-connection.py \ + add-connection-compat.py \ add-system-wifi-connection.py \ vpn.py \ update-secrets.py \ diff --git a/examples/python/dbus/Makefile.in b/examples/python/dbus/Makefile.in index 7b543fa7..a505993c 100644 --- a/examples/python/dbus/Makefile.in +++ b/examples/python/dbus/Makefile.in @@ -129,6 +129,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -252,6 +254,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -271,6 +274,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ @@ -297,7 +301,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_BASE_DIR = @UDEV_BASE_DIR@ +UDEV_DIR = @UDEV_DIR@ USE_NLS = @USE_NLS@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ @@ -379,6 +383,7 @@ with_valgrind = @with_valgrind@ EXTRA_DIST = \ nm-state.py \ add-connection.py \ + add-connection-compat.py \ add-system-wifi-connection.py \ vpn.py \ update-secrets.py \ diff --git a/examples/python/dbus/add-connection-compat.py b/examples/python/dbus/add-connection-compat.py new file mode 100755 index 00000000..4792ac5e --- /dev/null +++ b/examples/python/dbus/add-connection-compat.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Copyright (C) 2010 - 2012 Red Hat, Inc. +# + +# +# This example adds a new ethernet connection via the AddConnection() +# D-Bus call, using backward-compatible settings, so it will work with +# both old and new versions of NetworkManager. Compare +# add-connection.py, which only supports NM 1.0 and later. +# +# Configuration settings are described at +# https://developer.gnome.org/NetworkManager/1.0/ref-settings.html +# + +import socket, struct, dbus, uuid + +# Helper functions +def ip_to_int(ip_string): + return struct.unpack("=I", socket.inet_aton(ip_string))[0] + +def int_to_ip(ip_int): + return socket.inet_ntoa(struct.pack("=I", ip_int)) + +s_wired = dbus.Dictionary({'duplex': 'full'}) +s_con = dbus.Dictionary({ + 'type': '802-3-ethernet', + 'uuid': str(uuid.uuid4()), + 'id': 'MyConnectionExample'}) + +addr1 = dbus.Array([ip_to_int("10.1.2.3"), dbus.UInt32(8L), ip_to_int("10.1.2.1")], signature=dbus.Signature('u')) +s_ip4 = dbus.Dictionary({ + 'addresses': dbus.Array([addr1], signature=dbus.Signature('au')), + 'method': 'manual'}) + +s_ip6 = dbus.Dictionary({'method': 'ignore'}) + +con = dbus.Dictionary({ + '802-3-ethernet': s_wired, + 'connection': s_con, + 'ipv4': s_ip4, + 'ipv6': s_ip6}) + + +print "Creating connection:", s_con['id'], "-", s_con['uuid'] + +bus = dbus.SystemBus() +proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/Settings") +settings = dbus.Interface(proxy, "org.freedesktop.NetworkManager.Settings") + +settings.AddConnection(con) + diff --git a/examples/python/dbus/add-connection.py b/examples/python/dbus/add-connection.py index 6df14c10..5ebb82a3 100755 --- a/examples/python/dbus/add-connection.py +++ b/examples/python/dbus/add-connection.py @@ -18,20 +18,17 @@ # # -# This example adds a new ethernet connection via AddConnection() D-Bus call. +# This example adds a new ethernet connection via the AddConnection() +# D-Bus call, using the new 'ipv4.address-data' and 'ipv4.gateway' +# settings introduced in NetworkManager 1.0. Compare +# add-connection-compat.py, which will work against older versions of +# NetworkManager as well. # # Configuration settings are described at -# https://developer.gnome.org/NetworkManager/0.9/ref-settings.html +# https://developer.gnome.org/NetworkManager/1.0/ref-settings.html # -import socket, struct, dbus, uuid - -# Helper functions -def ip_to_int(ip_string): - return struct.unpack("=I", socket.inet_aton(ip_string))[0] - -def int_to_ip(ip_int): - return socket.inet_ntoa(struct.pack("=I", ip_int)) +import dbus, uuid s_wired = dbus.Dictionary({'duplex': 'full'}) s_con = dbus.Dictionary({ @@ -39,9 +36,12 @@ s_con = dbus.Dictionary({ 'uuid': str(uuid.uuid4()), 'id': 'MyConnectionExample'}) -addr1 = dbus.Array([ip_to_int("10.1.2.3"), dbus.UInt32(8L), ip_to_int("10.1.2.1")], signature=dbus.Signature('u')) +addr1 = dbus.Dictionary({ + 'address': '10.1.2.3', + 'prefix': dbus.UInt32(8L)}) s_ip4 = dbus.Dictionary({ - 'addresses': dbus.Array([addr1], signature=dbus.Signature('au')), + 'address-data': dbus.Array([addr1], signature=dbus.Signature('a{sv}')), + 'gateway': '10.1.2.1', 'method': 'manual'}) s_ip6 = dbus.Dictionary({'method': 'ignore'}) diff --git a/examples/python/dbus/is-wwan-default.py b/examples/python/dbus/is-wwan-default.py index 6131cda1..a4a3ff8e 100755 --- a/examples/python/dbus/is-wwan-default.py +++ b/examples/python/dbus/is-wwan-default.py @@ -28,6 +28,8 @@ NM_SERVICE_NAME = "org.freedesktop.NetworkManager" NM_MANAGER_IFACE = "org.freedesktop.NetworkManager" DBUS_PROPS_IFACE = "org.freedesktop.DBus.Properties" +NM_ACTIVE_CONNECTION_INTERFACE = "org.freedesktop.NetworkManager.Connection.Active" + bus = dbus.SystemBus() # Exit early if NetworkManager is not running @@ -42,34 +44,54 @@ proxy = bus.get_object(NM_SERVICE_NAME, "/org/freedesktop/NetworkManager") manager = dbus.Interface(proxy, NM_MANAGER_IFACE) props = dbus.Interface(proxy, DBUS_PROPS_IFACE) -default_is_wwan = False +def found_connection_type(ctype): + if ctype == '': + print "No active connection" + elif ctype in ["gsm", "cdma", "bluetooth"]: + print "WWAN is default" + else: + print "WWAN is not default" + sys.exit(0) + +# Shortcut #1, for NM 1.0 +try: + ctype = props.Get(NM_MANAGER_IFACE, "PrimaryConnectionType") + found_connection_type(ctype) +except KeyError: + pass -# Look through all active network connections for the default one +# Shortcut #2, for NM 0.9.10 +try: + primary = props.Get(NM_MANAGER_IFACE, "PrimaryConnection") + if not primary: + found_connection_type('') + primary_proxy = bus.get_object(NM_SERVICE_NAME, primary) + primary_props = dbus.Interface(primary_proxy, DBUS_PROPS_IFACE) + ctype = primary_props.Get(NM_ACTIVE_CONNECTION_INTERFACE, "Type") + found_connection_type(ctype) +except KeyError: + pass + +# Fallback for NM 0.9.8 and earlier; look through all active network +# connections for the default one +default_is_wwan = False active = props.Get(NM_MANAGER_IFACE, "ActiveConnections") for a in active: a_proxy = bus.get_object(NM_SERVICE_NAME, a) a_props = dbus.Interface(a_proxy, DBUS_PROPS_IFACE) - all_props = a_props.GetAll("org.freedesktop.NetworkManager.Connection.Active") + all_props = a_props.GetAll(NM_ACTIVE_CONNECTION_INTERFACE) # Ignore this network connection if it's not default for IPv4 or IPv6 if all_props["Default"] == False and all_props["Default6"] == False: continue - # Shortcut: check for Type property (only present in NM 0.9.9+) - try: - ctype = all_props["Type"] - if ctype in ["gsm", "cdma", "bluetooth"]: - default_is_wwan = True - break - except KeyError: - # Fall back to checking the type of the network connection's device - dev_path = all_props["Devices"][0] - dev_proxy = bus.get_object(NM_SERVICE_NAME, dev_path) - dev_props = dbus.Interface(dev_proxy, DBUS_PROPS_IFACE) - devtype = dev_props.Get("org.freedesktop.NetworkManager.Device", "DeviceType") - if devtype == NM_DEVICE_TYPE_MODEM or devtype == NM_DEVICE_TYPE_BLUETOOTH: - default_is_wwan = True - break + dev_path = all_props["Devices"][0] + dev_proxy = bus.get_object(NM_SERVICE_NAME, dev_path) + dev_props = dbus.Interface(dev_proxy, DBUS_PROPS_IFACE) + devtype = dev_props.Get("org.freedesktop.NetworkManager.Device", "DeviceType") + if devtype == NM_DEVICE_TYPE_MODEM or devtype == NM_DEVICE_TYPE_BLUETOOTH: + default_is_wwan = True + break if default_is_wwan: print "WWAN is default" diff --git a/examples/python/dbus/update-ip4-method.py b/examples/python/dbus/update-ip4-method.py index 243738c5..28a22289 100755 --- a/examples/python/dbus/update-ip4-method.py +++ b/examples/python/dbus/update-ip4-method.py @@ -21,15 +21,14 @@ # # This example updates a connection's IPv4 method with the Update() method. # +# This uses the new NM 1.0 setting properties. See add-connection-compat.py +# for a similar example using the backward-compatible properties +# # Configuration settings are described at -# https://developer.gnome.org/NetworkManager/0.9/ref-settings.html +# https://developer.gnome.org/NetworkManager/1.0/ref-settings.html # -import socket, struct, dbus, sys - -def ip_to_int(ip_string): - return struct.unpack("=I", socket.inet_aton(ip_string))[0] - +import dbus, sys if len(sys.argv) < 3: print "Usage: %s <uuid> <auto|static> [address prefix gateway]" % sys.argv[0] @@ -58,21 +57,25 @@ for c_path in settings.ListConnections(): continue # add IPv4 setting if it doesn't yet exist - if not c_settings.has_key('ipv4'): + if 'ipv4' not in c_settings: c_settings['ipv4'] = {} + # clear existing address info + if c_settings['ipv4'].has_key('addresses'): + del c_settings['ipv4']['addresses'] + if c_settings['ipv4'].has_key('address-data'): + del c_settings['ipv4']['address-data'] + if c_settings['ipv4'].has_key('gateway'): + del c_settings['ipv4']['gateway'] + # set the method and change properties c_settings['ipv4']['method'] = method - if method == "auto": - # remove addresses - c_settings['ipv4']['addresses'] = dbus.Array([], signature=dbus.Signature('au')) - elif method == "manual": + if method == "manual": # Add the static IP address, prefix, and (optional) gateway - gw = 0 + addr = dbus.Dictionary({'address': sys.argv[3], 'prefix': dbus.UInt32(int(sys.argv[4]))}) + c_settings['ipv4']['address-data'] = dbus.Array([addr], signature=dbus.Signature('a{sv}')) if len(sys.argv) == 6: - gw = ip_to_int(sys.argv[5]) - addr = dbus.Array([ip_to_int(sys.argv[3]), dbus.UInt32(int(sys.argv[4])), gw], signature=dbus.Signature('u')) - c_settings['ipv4']['addresses'] = dbus.Array([addr], signature=dbus.Signature('au')) + c_settings['ipv4']['gateway'] = sys.argv[5] # Save all the updated settings back to NetworkManager c_obj.Update(c_settings) diff --git a/examples/python/gi/Makefile.in b/examples/python/gi/Makefile.in index 8ea13b18..0f8e3e58 100644 --- a/examples/python/gi/Makefile.in +++ b/examples/python/gi/Makefile.in @@ -129,6 +129,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -252,6 +254,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -271,6 +274,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ @@ -297,7 +301,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_BASE_DIR = @UDEV_BASE_DIR@ +UDEV_DIR = @UDEV_DIR@ USE_NLS = @USE_NLS@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ diff --git a/examples/python/gi/add_connection.py b/examples/python/gi/add_connection.py index 76c2e94e..bb1163db 100755 --- a/examples/python/gi/add_connection.py +++ b/examples/python/gi/add_connection.py @@ -1,5 +1,7 @@ #!/usr/bin/env python # -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +# vim: ft=python ts=4 sts=4 sw=4 et ai + # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -15,21 +17,19 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# Copyright (C) 2014 Red Hat, Inc. +# Copyright 2014 Red Hat, Inc. # # # This example shows how to add a new NM connection profile. -# The code uses libnm-util (NetworkManager) and libnm-glib (NMClient) -# via GObject Introspection. +# The code uses libnm (NM) via GObject Introspection. # # Documentation links: -# https://developer.gnome.org/libnm-glib/0.9/ -# https://developer.gnome.org/libnm-util/0.9/ -# https://developer.gnome.org/NetworkManager/0.9/ref-settings.html +# https://developer.gnome.org/libnm/1.0/ +# https://developer.gnome.org/NetworkManager/1.0/ref-settings.html # -from gi.repository import GLib, NetworkManager, NMClient +from gi.repository import GLib, NM import sys, uuid main_loop = None @@ -39,19 +39,19 @@ def print_values(setting, key, value, flags, data): # create an Ethernet connection and return it def create_profile(name): - profile = NetworkManager.Connection.new() - s_con = NetworkManager.SettingConnection.new() - s_con.set_property(NetworkManager.SETTING_CONNECTION_ID, name) - s_con.set_property(NetworkManager.SETTING_CONNECTION_UUID, str(uuid.uuid4())) - s_con.set_property(NetworkManager.SETTING_CONNECTION_TYPE, "802-3-ethernet") + profile = NM.SimpleConnection.new() + s_con = NM.SettingConnection.new() + s_con.set_property(NM.SETTING_CONNECTION_ID, name) + s_con.set_property(NM.SETTING_CONNECTION_UUID, str(uuid.uuid4())) + s_con.set_property(NM.SETTING_CONNECTION_TYPE, "802-3-ethernet") - s_wired = NetworkManager.SettingWired.new() + s_wired = NM.SettingWired.new() - s_ip4 = NetworkManager.SettingIP4Config.new() - s_ip4.set_property(NetworkManager.SETTING_IP4_CONFIG_METHOD, "auto") + s_ip4 = NM.SettingIP4Config.new() + s_ip4.set_property(NM.SETTING_IP_CONFIG_METHOD, "auto") - s_ip6 = NetworkManager.SettingIP6Config.new() - s_ip6.set_property(NetworkManager.SETTING_IP6_CONFIG_METHOD, "auto") + s_ip6 = NM.SettingIP6Config.new() + s_ip6.set_property(NM.SETTING_IP_CONFIG_METHOD, "auto") profile.add_setting(s_con) profile.add_setting(s_ip4) @@ -64,11 +64,12 @@ def create_profile(name): return profile # callback function -def added_cb(settings, con, error, data): - if error is (None): +def added_cb(client, result, data): + try: + client.add_connection_finish(result) print("The connection profile has been succesfully added to NetworkManager.") - else: - print(error) + except Exception, e: + print("Error: %s" % e) main_loop.quit() if __name__ == "__main__": @@ -85,17 +86,14 @@ if __name__ == "__main__": main_loop = GLib.MainLoop() - # create RemoteSettings object - settings = NMClient.RemoteSettings.new(None); + # create Client object + client = NM.Client.new(None) # create a connection profile for NM con = create_profile(profile_name) # send the connection to NM - if persistent: - settings.add_connection(con, added_cb, None) - else: - settings.add_connection_unsaved(con, added_cb, None) + client.add_connection_async(con, persistent, None, added_cb, None) main_loop.run() diff --git a/examples/python/gi/device-state-ip4config.py b/examples/python/gi/device-state-ip4config.py index be19b996..1a6f7dec 100755 --- a/examples/python/gi/device-state-ip4config.py +++ b/examples/python/gi/device-state-ip4config.py @@ -21,7 +21,7 @@ # import sys -from gi.repository import GLib, NetworkManager, NMClient +from gi.repository import GLib, NM # # This example shows how to get NMIP4Config from NMDevice after it is activated. @@ -51,7 +51,7 @@ if __name__ == "__main__": sys.exit('Usage: %s <interface>' % sys.argv[0]) dev_iface = sys.argv[1] - c = NMClient.Client.new() + c = NM.Client.new(None) dev = c.get_device_by_iface(dev_iface) if dev is None: sys.exit('Device \'%s\' not found' % dev_iface) diff --git a/examples/python/gi/firewall-zone.py b/examples/python/gi/firewall-zone.py index 5e5eea91..ed9e5910 100755 --- a/examples/python/gi/firewall-zone.py +++ b/examples/python/gi/firewall-zone.py @@ -16,11 +16,11 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# Copyright (C) 2013 Red Hat, Inc. +# Copyright 2013 - 2014 Red Hat, Inc. # import sys -from gi.repository import GLib, NetworkManager, NMClient +from gi.repository import GLib, NM # # This example demonstrates how to get and change firewall zone in a @@ -32,7 +32,7 @@ from gi.repository import GLib, NetworkManager, NMClient # If you used D-Bus calls, you would call GetSettings() and then Update(). # # Links: -# https://developer.gnome.org/libnm-glib/0.9/ +# https://developer.gnome.org/libnm/1.0/ # https://wiki.gnome.org/GObjectIntrospection # https://wiki.gnome.org/PyGObject # @@ -43,7 +43,14 @@ def connection_saved(connection, error, data): print ("Connection '%s' saved.") % (connection.get_id()) main_loop.quit() -def connections_read(settings, data): +if __name__ == "__main__": + if len(sys.argv) != 2 and len(sys.argv) != 3: + sys.exit('Usage: %s <connection name or UUID> [new zone]' % sys.argv[0]) + + main_loop = GLib.MainLoop() + client = NM.Client.new(None) + connections = client.get_connections() + con_name = sys.argv[1] if len(sys.argv) == 3: new_zone = sys.argv[2] @@ -51,7 +58,6 @@ def connections_read(settings, data): new_zone = None found = False - connections = settings.list_connections() for c in connections: if c.get_id() == con_name or c.get_uuid() == con_name: found = True @@ -71,17 +77,3 @@ def connections_read(settings, data): if not found: print ("Error: connection '%s' not found.") % (con_name) main_loop.quit() - - -if __name__ == "__main__": - if len(sys.argv) != 2 and len(sys.argv) != 3: - sys.exit('Usage: %s <connection name or UUID> [new zone]' % sys.argv[0]) - - main_loop = GLib.MainLoop() - settings = NMClient.RemoteSettings.new(None); - - # Connections are read asynchronously, so we have to wait for the - # 'settings' object to tell us that all connections have been read. - settings.connect("connections-read", connections_read, None) - main_loop.run() - diff --git a/examples/python/gi/get-active-connections.py b/examples/python/gi/get-active-connections.py index 13f0b031..55ba2d81 100755 --- a/examples/python/gi/get-active-connections.py +++ b/examples/python/gi/get-active-connections.py @@ -21,10 +21,10 @@ # This example lists currently active connections -from gi.repository import GLib, NMClient +from gi.repository import GLib, NM if __name__ == "__main__": - client = NMClient.Client.new() + client = NM.Client.new(None) acons = client.get_active_connections() for ac in acons: print "%s (%s) - %s" % (ac.get_id(), ac.get_uuid(), ac.get_connection_type()) diff --git a/examples/python/gi/get_ips.py b/examples/python/gi/get_ips.py index 6903b6de..690bd6ef 100755 --- a/examples/python/gi/get_ips.py +++ b/examples/python/gi/get_ips.py @@ -17,22 +17,22 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# Copyright (C) 2014 Red Hat, Inc. +# Copyright 2014 Red Hat, Inc. # -import sys, socket, struct -from gi.repository import GLib, NetworkManager, NMClient +import sys, socket +from gi.repository import GLib, NM # # This example shows how to get addresses, routes and DNS information # from NMIP4Config and NMIP6Config (got out of NMDevice) # -def show_addresses(self, family): +def show_addresses(dev, family): if (family == socket.AF_INET): - ip_cfg = self.get_ip4_config() + ip_cfg = dev.get_ip4_config() else: - ip_cfg = self.get_ip6_config() + ip_cfg = dev.get_ip6_config() if ip_cfg is None: print("None") @@ -46,24 +46,29 @@ def show_addresses(self, family): for nm_address in nm_addresses: addr = nm_address.get_address() prefix = nm_address.get_prefix() - gateway = nm_address.get_gateway() - if (family == socket.AF_INET): - addr_struct = struct.pack("=I", addr) - gateway_struct = struct.pack("=I", gateway) - else: - addr_struct = addr - gateway_struct = gateway - print("%s/%d %s") % (socket.inet_ntop(family, addr_struct), - prefix, - socket.inet_ntop(family, gateway_struct)) + print("%s/%d") % (addr, prefix) +def show_gateway(dev, family): + if (family == socket.AF_INET): + ip_cfg = dev.get_ip4_config() + else: + ip_cfg = dev.get_ip6_config() + + if ip_cfg is None: + gw = "None" + else: + gw = ip_cfg.get_gateway() + if gw == '': + gw = "None" + + print(gw) -def show_routes(self, family): +def show_routes(dev, family): if (family == socket.AF_INET): - ip_cfg = self.get_ip4_config() + ip_cfg = dev.get_ip4_config() else: - ip_cfg = self.get_ip6_config() + ip_cfg = dev.get_ip6_config() if ip_cfg is None: print("None") @@ -80,43 +85,24 @@ def show_routes(self, family): next_hop = nm_route.get_next_hop() metric = nm_route.get_metric() - if (family == socket.AF_INET): - dest_struct = struct.pack("=I", dest) - next_hop_struct = struct.pack("=I", next_hop) - else: - dest_struct = dest - next_hop_struct = next_hop - print("%s/%d %s %d") % (socket.inet_ntop(family, dest_struct), - prefix, - socket.inet_ntop(family, next_hop_struct), - metric) + print("%s/%d %s %d") % (dest, prefix, next_hop, metric) -def show_dns(self, family): +def show_dns(dev, family): if (family == socket.AF_INET): - ip_cfg = self.get_ip4_config() + ip_cfg = dev.get_ip4_config() else: - ip_cfg = self.get_ip6_config() + ip_cfg = dev.get_ip6_config() if ip_cfg is None: print("None") return + print ("Nameservers: %s") % (ip_cfg.get_nameservers()) + print ("Domains: %s") % (ip_cfg.get_domains()) + print ("Searches: %s") % (ip_cfg.get_searches()) if (family == socket.AF_INET): - print ("Domains: %s") % (ip_cfg.get_domains()) - print ("Searches: %s") % (ip_cfg.get_searches()) - print("Nameservers:") - nameservers = ip_cfg.get_nameservers() - for dns in nameservers: - print socket.inet_ntop(family, struct.pack("=I", dns)) - else: - print ("Domains: %s") % (ip_cfg.get_domains()) - print ("Searches: %s") % (ip_cfg.get_searches()) - print("Nameservers:") - num = ip_cfg.get_num_nameservers() - for i in range(0,num): - dns = ip_cfg.get_nameserver(i) - print socket.inet_ntop(family, dns) + print ("WINS: %s") % (ip_cfg.get_wins_servers()) if __name__ == "__main__": @@ -124,7 +110,7 @@ if __name__ == "__main__": sys.exit('Usage: %s <interface>' % sys.argv[0]) dev_iface = sys.argv[1] - c = NMClient.Client.new() + c = NM.Client.new(None) dev = c.get_device_by_iface(dev_iface) if dev is None: sys.exit('Device \'%s\' not found' % dev_iface) @@ -136,6 +122,11 @@ if __name__ == "__main__": show_addresses(dev, socket.AF_INET) print + print("IPv4 gateway:") + print("-------------") + show_gateway(dev, socket.AF_INET) + print + print("IPv4 routes:") print("------------") show_routes(dev, socket.AF_INET) @@ -146,6 +137,11 @@ if __name__ == "__main__": show_addresses(dev, socket.AF_INET6) print + print("IPv6 gateway:") + print("-------------") + show_gateway(dev, socket.AF_INET6) + print + print "IPv6 routes:" print("------------") show_routes(dev, socket.AF_INET6) diff --git a/examples/python/gi/list-connections.py b/examples/python/gi/list-connections.py index b6452d35..34b559fc 100755 --- a/examples/python/gi/list-connections.py +++ b/examples/python/gi/list-connections.py @@ -1,5 +1,7 @@ #!/usr/bin/env python # -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +# vim: ft=python ts=4 sts=4 sw=4 et ai + # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -15,36 +17,26 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# Copyright (C) 2012 Red Hat, Inc. +# Copyright 2012 - 2014 Red Hat, Inc. # -from gi.repository import GLib, NetworkManager, NMClient +from gi.repository import NM # This example asks settings service for all configured connections. -# Unfortunately, at this time since libnm-glib still makes heavy use of -# GValue and GHashTable (rather than GVariant), libnm-glib isn't fully -# usable from GObject Introspection-ready languages. Most functions will -# work fine, but e. g. nm_connection_to_hash() causes assertion failures. - -main_loop = None def print_values(setting, key, value, flags, data): print " %s.%s: %s" % (setting.get_name(), key, value) -def connections_read(settings): - connections = settings.list_connections() +if __name__ == "__main__": + # create Client object + client = NM.Client.new(None) + + # get all connections + connections = client.get_connections() + + # print the connections' details for c in connections: - print "--- %s : %s" % (c.get_id(), c.get_path()) + print "=== %s : %s ===" % (c.get_id(), c.get_path()) c.for_each_setting_value(print_values, None) print "\n" - main_loop.quit() - -if __name__ == "__main__": - main_loop = GLib.MainLoop() - settings = NMClient.RemoteSettings.new(None); - - # connections are read asynchronously, so we need to wait for the - # settings object to tell us that it's read all connections - settings.connect("connections-read", connections_read) - main_loop.run() diff --git a/examples/python/gi/show-wifi-networks.py b/examples/python/gi/show-wifi-networks.py index 9d9e3471..7f3bd2db 100755 --- a/examples/python/gi/show-wifi-networks.py +++ b/examples/python/gi/show-wifi-networks.py @@ -20,33 +20,32 @@ # Copyright (C) 2013 Red Hat, Inc. # -from gi.repository import NetworkManager, NMClient +import locale +from gi.repository import NM # # This example lists Wi-Fi access points NetworkManager scanned on Wi-Fi devices. -# It calls libnm-glib functions using GObject introspection. +# It calls libnm functions using GObject introspection. # # Note the second line of the file: coding=utf-8 # It is necessary because we use unicode characters and python would produce # an error without it: http://www.python.org/dev/peps/pep-0263/ # -signal_bars = { - 0 : "____", - 1 : "▂___", - 2 : "▂▄__", - 3 : "▂▄▆_", - 4 : "▂▄▆█" -} - def clamp(value, minvalue, maxvalue): return max(minvalue, min(value, maxvalue)) +def ssid_to_utf8(ap): + ssid = ap.get_ssid() + if not ssid: + return "" + return NM.utils_ssid_to_utf8(ap.get_ssid().get_data()) + def print_device_info(device): active_ap = dev.get_active_access_point() ssid = None if active_ap is not None: - ssid = active_ap.get_ssid() + ssid = ssid_to_utf8(active_ap) info = "Device: %s | Driver: %s | Active AP: %s" % (dev.get_iface(), dev.get_driver(), ssid) print info print '=' * len(info) @@ -54,19 +53,24 @@ def print_device_info(device): def print_ap_info(ap): strength = ap.get_strength() frequency = ap.get_frequency() - print "SSID: %s" % (ap.get_ssid()) + print "SSID: %s" % (ssid_to_utf8(ap)) print "BSSID: %s" % (ap.get_bssid()) print "Frequency: %s" % (frequency) - print "Channel: %s" % (NetworkManager.utils_wifi_freq_to_channel(frequency)) - print "Strength: %s %s%%" % (signal_bars[(clamp(strength-5, 0, 99)+24)/25], strength) + print "Channel: %s" % (NM.utils_wifi_freq_to_channel(frequency)) + print "Strength: %s %s%%" % (NM.utils_wifi_strength_bars(strength), strength) print if __name__ == "__main__": - nmc = NMClient.Client.new() + # Python apparently doesn't call setlocale() on its own? We have to call this or else + # NM.utils_wifi_strength_bars() will think the locale is ASCII-only, and return the + # fallback characters rather than the unicode bars + locale.setlocale(locale.LC_ALL, '') + + nmc = NM.Client.new(None) devs = nmc.get_devices() for dev in devs: - if dev.get_device_type() == NetworkManager.DeviceType.WIFI: + if dev.get_device_type() == NM.DeviceType.WIFI: print_device_info(dev) for ap in dev.get_access_points(): print_ap_info(ap) diff --git a/examples/python/gi/update-ip4-method.py b/examples/python/gi/update-ip4-method.py index 2fe12693..983578cf 100755 --- a/examples/python/gi/update-ip4-method.py +++ b/examples/python/gi/update-ip4-method.py @@ -1,5 +1,6 @@ #!/usr/bin/env python # -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +# vim: ft=python ts=4 sts=4 sw=4 et ai # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -15,35 +16,43 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# Copyright (C) 2014 Red Hat, Inc. +# Copyright 2014 Red Hat, Inc. # # # This example updates a connection's IPv4 method with the Update() method -# using the libnm-glib GObject-based convenience APIs. +# using the libnm GObject-based convenience APIs. # # Configuration settings are described at -# https://developer.gnome.org/NetworkManager/0.9/ref-settings.html +# https://developer.gnome.org/NetworkManager/1.0/ref-settings.html # -from gi.repository import GLib, NetworkManager, NMClient -import sys, struct, socket +from gi.repository import GLib, NM +import sys, socket -def ip_to_int(ip_string): - return struct.unpack("=I", socket.inet_aton(ip_string))[0] +if __name__ == "__main__": + # parse and validate arguments + if len(sys.argv) < 3: + print "Usage: %s <uuid> <auto|static> [address prefix gateway]" % sys.argv[0] + sys.exit(1) + + method = sys.argv[2] + if (method == "static" or method == "manual") and len(sys.argv) < 5: + print "Usage: %s %s static address prefix [gateway]" % (sys.argv[0], sys.argv[1]) + sys.exit(1) -# callback function -def commit_cb(connection, error, data): - if error is (None): - print("The connection profile has been updated.") - else: - print(error) - main_loop.quit() + uuid = sys.argv[1] -def connections_read_cb(settings, data): - uuid, method, args = data + # Convert method to NM method + if method == "static": + method = "manual" + + main_loop = GLib.MainLoop() - all_connections = settings.list_connections() + # create Client object + client = NM.Client.new(None) + + all_connections = client.get_connections() for c in all_connections: if c.get_uuid() != uuid: continue @@ -51,46 +60,26 @@ def connections_read_cb(settings, data): # add IPv4 setting if it doesn't yet exist s_ip4 = c.get_setting_ip4_config() if not s_ip4: - s_ip4 = NetworkManager.SettingIP4Config.new() + s_ip4 = NM.SettingIP4Config.new() c.add_setting(s_ip4) # set the method and change properties - s_ip4.set_property(NetworkManager.SETTING_IP4_CONFIG_METHOD, method) + s_ip4.set_property(NM.SETTING_IP_CONFIG_METHOD, method) if method == "auto": - # remove addresses + # remove addresses and gateway s_ip4.clear_addresses() + s_ip4.props.gateway = None elif method == "manual": # Add the static IP address, prefix, and (optional) gateway - addr = NetworkManager.IP4Address.new() - addr.set_address(ip_to_int(sys.argv[3])) - addr.set_prefix(int(sys.argv[4])) - if len(sys.argv) == 6: - addr.set_gateway(ip_to_int(sys.argv[5])) + addr = NM.IPAddress.new(socket.AF_INET, sys.argv[3], int(sys.argv[4])) s_ip4.add_address(addr) - - c.commit_changes(commit_cb, None) - -if __name__ == "__main__": - # parse and validate arguments - if len(sys.argv) < 3: - print "Usage: %s <uuid> <auto|static> [address prefix gateway]" % sys.argv[0] - sys.exit(1) - - method = sys.argv[2] - if method == "static" and len(sys.argv) < 5: - print "Usage: %s %s static address prefix [gateway]" % (sys.argv[0], sys.argv[1]) - sys.exit(1) - - # Convert method to NM method - if method == "static": - method = "manual" - - main_loop = GLib.MainLoop() - - # create RemoteSettings object and attach to the "connections-read" signal - # to wait for connections to be loaded asynchronously - settings = NMClient.RemoteSettings.new(None) - settings.connect('connections-read', connections_read_cb, (sys.argv[1], method, sys.argv)) - - main_loop.run() + if len(sys.argv) == 6: + s_ip4.props.gateway = sys.argv[5] + + try: + c.commit_changes(True, None) + print("The connection profile has been updated.") + except Exception, e: + print("Error: %s" % e) + break diff --git a/examples/ruby/Makefile.in b/examples/ruby/Makefile.in index e9bff785..fa8d7c73 100644 --- a/examples/ruby/Makefile.in +++ b/examples/ruby/Makefile.in @@ -129,6 +129,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -252,6 +254,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -271,6 +274,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ @@ -297,7 +301,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_BASE_DIR = @UDEV_BASE_DIR@ +UDEV_DIR = @UDEV_DIR@ USE_NLS = @USE_NLS@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ diff --git a/examples/ruby/add-connection.rb b/examples/ruby/add-connection.rb index 6af723bf..645ad348 100755 --- a/examples/ruby/add-connection.rb +++ b/examples/ruby/add-connection.rb @@ -27,8 +27,13 @@ require 'ipaddr' # It also shows how to specify D-Bus signature for properties like "addresses" # and "clone-mac-address". # +# This uses the old, backwards-compatible settings properties. The new 1.0 +# properties (eg, 'address-data' rather than 'addresses') would make this simpler; +# see the python add-connection.py and add-connection-compat.py examples for +# details +# # Configuration settings are described here: -# https://developer.gnome.org/NetworkManager/0.9/ref-settings.html +# https://developer.gnome.org/NetworkManager/1.0/ref-settings.html # # Helper functions diff --git a/examples/shell/Makefile.in b/examples/shell/Makefile.in index d3a6bdfa..327b4949 100644 --- a/examples/shell/Makefile.in +++ b/examples/shell/Makefile.in @@ -129,6 +129,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -252,6 +254,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -271,6 +274,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ @@ -297,7 +301,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_BASE_DIR = @UDEV_BASE_DIR@ +UDEV_DIR = @UDEV_DIR@ USE_NLS = @USE_NLS@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ |