diff options
| author | Michael Biebl <biebl@debian.org> | 2011-04-08 07:30:59 +0200 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2011-04-08 07:30:59 +0200 |
| commit | f75dd6fd1975146623052b843b182dc32c3fbe46 (patch) | |
| tree | 05ba60b772670f038c9a1fbff940ec5d3e28d870 /examples | |
| parent | c980bdf58dc973dd5617aaa6f9466f9e44fcbf58 (diff) | |
Imported Upstream version 0.8.998 upstream/0.8.998
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/C/Makefile.am | 63 | ||||
| -rw-r--r-- | examples/C/Makefile.in | 709 | ||||
| -rw-r--r-- | examples/C/add-connection-dbus-glib.c | 124 | ||||
| -rw-r--r-- | examples/C/add-connection-libnm-glib.c | 136 | ||||
| -rw-r--r-- | examples/C/get-active-connections.c | 248 | ||||
| -rw-r--r-- | examples/C/get-ap-info-libnm-glib.c | 229 | ||||
| -rw-r--r-- | examples/C/list-connections-dbus.c | 83 | ||||
| -rw-r--r-- | examples/C/list-connections-libnm-glib.c | 176 | ||||
| -rw-r--r-- | examples/Makefile.am | 4 | ||||
| -rw-r--r-- | examples/Makefile.in | 53 | ||||
| -rw-r--r-- | examples/python/Makefile.in | 48 | ||||
| -rwxr-xr-x | examples/python/add-system-connection.py | 4 | ||||
| -rwxr-xr-x | examples/python/add-system-wifi-connection.py | 7 | ||||
| -rw-r--r-- | examples/python/nm-state.py | 7 |
14 files changed, 1848 insertions, 43 deletions
diff --git a/examples/C/Makefile.am b/examples/C/Makefile.am new file mode 100644 index 00000000..684a1fa1 --- /dev/null +++ b/examples/C/Makefile.am @@ -0,0 +1,63 @@ +INCLUDES = -I${top_srcdir}/libnm-util \ + -I${top_srcdir}/libnm-glib \ + -I${top_srcdir}/include + +AM_CPPFLAGS = \ + $(DBUS_CFLAGS) \ + $(GLIB_CFLAGS) + +noinst_PROGRAMS = \ + add-connection-dbus-glib \ + add-connection-libnm-glib \ + get-active-connections \ + list-connections-dbus \ + list-connections-libnm-glib \ + get-ap-info-libnm-glib + +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) + +get_active_connections_SOURCES = get-active-connections.c +get_active_connections_LDADD = \ + $(top_builddir)/libnm-util/libnm-util.la \ + $(DBUS_LIBS) \ + $(GLIB_LIBS) + +list_connections_dbus_SOURCES = list-connections-dbus.c +list_connections_dbus_LDADD = \ + $(top_builddir)/libnm-util/libnm-util.la \ + $(DBUS_LIBS) \ + $(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) \ + $(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) \ + $(GLIB_LIBS) + +EXTRA_DIST = \ + add-connection-dbus-glib.c \ + add-connection-libnm-glib.c \ + get-active-connections.c \ + list-connections-dbus.c \ + list-connections-libnm-glib.c \ + get-ap-info-libnm-glib.c + diff --git a/examples/C/Makefile.in b/examples/C/Makefile.in new file mode 100644 index 00000000..7236a28e --- /dev/null +++ b/examples/C/Makefile.in @@ -0,0 +1,709 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +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$(EXEEXT) list-connections-dbus$(EXEEXT) \ + list-connections-libnm-glib$(EXEEXT) \ + get-ap-info-libnm-glib$(EXEEXT) +subdir = examples/C +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/compiler_warnings.m4 \ + $(top_srcdir)/m4/gettext.m4 $(top_srcdir)/m4/gtk-doc.m4 \ + $(top_srcdir)/m4/iconv.m4 $(top_srcdir)/m4/intlmacosx.m4 \ + $(top_srcdir)/m4/intltool.m4 $(top_srcdir)/m4/introspection.m4 \ + $(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \ + $(top_srcdir)/m4/lib-prefix.m4 $(top_srcdir)/m4/libnl-check.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/nls.m4 \ + $(top_srcdir)/m4/po.m4 $(top_srcdir)/m4/progtest.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +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__DEPENDENCIES_1 = +add_connection_dbus_glib_DEPENDENCIES = \ + $(top_builddir)/libnm-util/libnm-util.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) +AM_V_lt = $(am__v_lt_$(V)) +am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) +am__v_lt_0 = --silent +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__DEPENDENCIES_1) +am_get_active_connections_OBJECTS = get-active-connections.$(OBJEXT) +get_active_connections_OBJECTS = $(am_get_active_connections_OBJECTS) +get_active_connections_DEPENDENCIES = \ + $(top_builddir)/libnm-util/libnm-util.la $(am__DEPENDENCIES_1) \ + $(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__DEPENDENCIES_1) +am_list_connections_dbus_OBJECTS = list-connections-dbus.$(OBJEXT) +list_connections_dbus_OBJECTS = $(am_list_connections_dbus_OBJECTS) +list_connections_dbus_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) +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/build-aux/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_$(V)) +am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) +am__v_CC_0 = @echo " CC " $@; +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +am__v_at_0 = @ +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_$(V)) +am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) +am__v_CCLD_0 = @echo " CCLD " $@; +AM_V_GEN = $(am__v_GEN_$(V)) +am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) +am__v_GEN_0 = @echo " GEN " $@; +SOURCES = $(add_connection_dbus_glib_SOURCES) \ + $(add_connection_libnm_glib_SOURCES) \ + $(get_active_connections_SOURCES) \ + $(get_ap_info_libnm_glib_SOURCES) \ + $(list_connections_dbus_SOURCES) \ + $(list_connections_libnm_glib_SOURCES) +DIST_SOURCES = $(add_connection_dbus_glib_SOURCES) \ + $(add_connection_libnm_glib_SOURCES) \ + $(get_active_connections_SOURCES) \ + $(get_ap_info_libnm_glib_SOURCES) \ + $(list_connections_dbus_SOURCES) \ + $(list_connections_libnm_glib_SOURCES) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +ALL_LINGUAS = @ALL_LINGUAS@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATADIRNAME = @DATADIRNAME@ +DBUS_CFLAGS = @DBUS_CFLAGS@ +DBUS_LIBS = @DBUS_LIBS@ +DBUS_SYS_DIR = @DBUS_SYS_DIR@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DHCLIENT_PATH = @DHCLIENT_PATH@ +DHCLIENT_VERSION = @DHCLIENT_VERSION@ +DHCPCD_PATH = @DHCPCD_PATH@ +DISABLE_DEPRECATED = @DISABLE_DEPRECATED@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ +GETTEXT_PACKAGE = @GETTEXT_PACKAGE@ +GIO_CFLAGS = @GIO_CFLAGS@ +GIO_LIBS = @GIO_LIBS@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_GENMARSHAL = @GLIB_GENMARSHAL@ +GLIB_LIBS = @GLIB_LIBS@ +GMODULE_CFLAGS = @GMODULE_CFLAGS@ +GMODULE_LIBS = @GMODULE_LIBS@ +GMSGFMT = @GMSGFMT@ +GMSGFMT_015 = @GMSGFMT_015@ +GNUTLS_CFLAGS = @GNUTLS_CFLAGS@ +GNUTLS_LIBS = @GNUTLS_LIBS@ +GREP = @GREP@ +GTKDOC_CHECK = @GTKDOC_CHECK@ +GTKDOC_MKPDF = @GTKDOC_MKPDF@ +GTKDOC_REBASE = @GTKDOC_REBASE@ +GUDEV_CFLAGS = @GUDEV_CFLAGS@ +GUDEV_LIBS = @GUDEV_LIBS@ +HTML_DIR = @HTML_DIR@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +INTLLIBS = @INTLLIBS@ +INTLTOOL_EXTRACT = @INTLTOOL_EXTRACT@ +INTLTOOL_MERGE = @INTLTOOL_MERGE@ +INTLTOOL_PERL = @INTLTOOL_PERL@ +INTLTOOL_UPDATE = @INTLTOOL_UPDATE@ +INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@ +INTROSPECTION_CFLAGS = @INTROSPECTION_CFLAGS@ +INTROSPECTION_COMPILER = @INTROSPECTION_COMPILER@ +INTROSPECTION_GENERATE = @INTROSPECTION_GENERATE@ +INTROSPECTION_GIRDIR = @INTROSPECTION_GIRDIR@ +INTROSPECTION_LIBS = @INTROSPECTION_LIBS@ +INTROSPECTION_MAKEFILE = @INTROSPECTION_MAKEFILE@ +INTROSPECTION_SCANNER = @INTROSPECTION_SCANNER@ +INTROSPECTION_TYPELIBDIR = @INTROSPECTION_TYPELIBDIR@ +IPTABLES_PATH = @IPTABLES_PATH@ +IWMX_SDK_CFLAGS = @IWMX_SDK_CFLAGS@ +IWMX_SDK_LIBS = @IWMX_SDK_LIBS@ +KERNEL_FIRMWARE_DIR = @KERNEL_FIRMWARE_DIR@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDL = @LIBDL@ +LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ +LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ +LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ +LIBICONV = @LIBICONV@ +LIBINTL = @LIBINTL@ +LIBM = @LIBM@ +LIBNL_CFLAGS = @LIBNL_CFLAGS@ +LIBNL_LIBS = @LIBNL_LIBS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBINTL = @LTLIBINTL@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +MSGFMT = @MSGFMT@ +MSGFMT_015 = @MSGFMT_015@ +MSGMERGE = @MSGMERGE@ +NM = @NM@ +NMEDIT = @NMEDIT@ +NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ +NM_MICRO_VERSION = @NM_MICRO_VERSION@ +NM_MINOR_VERSION = @NM_MINOR_VERSION@ +NM_VERSION = @NM_VERSION@ +NSS_CFLAGS = @NSS_CFLAGS@ +NSS_LIBS = @NSS_LIBS@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PKGCONFIG_PATH = @PKGCONFIG_PATH@ +PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ +POLKIT_CFLAGS = @POLKIT_CFLAGS@ +POLKIT_LIBS = @POLKIT_LIBS@ +POSUB = @POSUB@ +PPPD_PLUGIN_DIR = @PPPD_PLUGIN_DIR@ +RANLIB = @RANLIB@ +RESOLVCONF_PATH = @RESOLVCONF_PATH@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ +UDEV_BASE_DIR = @UDEV_BASE_DIR@ +USE_NLS = @USE_NLS@ +UUID_CFLAGS = @UUID_CFLAGS@ +UUID_LIBS = @UUID_LIBS@ +VERSION = @VERSION@ +XGETTEXT = @XGETTEXT@ +XGETTEXT_015 = @XGETTEXT_015@ +XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +systemdsystemunitdir = @systemdsystemunitdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +INCLUDES = -I${top_srcdir}/libnm-util \ + -I${top_srcdir}/libnm-glib \ + -I${top_srcdir}/include + +AM_CPPFLAGS = \ + $(DBUS_CFLAGS) \ + $(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) + +get_active_connections_SOURCES = get-active-connections.c +get_active_connections_LDADD = \ + $(top_builddir)/libnm-util/libnm-util.la \ + $(DBUS_LIBS) \ + $(GLIB_LIBS) + +list_connections_dbus_SOURCES = list-connections-dbus.c +list_connections_dbus_LDADD = \ + $(top_builddir)/libnm-util/libnm-util.la \ + $(DBUS_LIBS) \ + $(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) \ + $(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) \ + $(GLIB_LIBS) + +EXTRA_DIST = \ + add-connection-dbus-glib.c \ + add-connection-libnm-glib.c \ + get-active-connections.c \ + list-connections-dbus.c \ + list-connections-libnm-glib.c \ + get-ap-info-libnm-glib.c + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu examples/C/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu examples/C/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-noinstPROGRAMS: + @list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list +add-connection-dbus-glib$(EXEEXT): $(add_connection_dbus_glib_OBJECTS) $(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) + @rm -f add-connection-libnm-glib$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(add_connection_libnm_glib_OBJECTS) $(add_connection_libnm_glib_LDADD) $(LIBS) +get-active-connections$(EXEEXT): $(get_active_connections_OBJECTS) $(get_active_connections_DEPENDENCIES) + @rm -f get-active-connections$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(get_active_connections_OBJECTS) $(get_active_connections_LDADD) $(LIBS) +get-ap-info-libnm-glib$(EXEEXT): $(get_ap_info_libnm_glib_OBJECTS) $(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) +list-connections-dbus$(EXEEXT): $(list_connections_dbus_OBJECTS) $(list_connections_dbus_DEPENDENCIES) + @rm -f list-connections-dbus$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(list_connections_dbus_OBJECTS) $(list_connections_dbus_LDADD) $(LIBS) +list-connections-libnm-glib$(EXEEXT): $(list_connections_libnm_glib_OBJECTS) $(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) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +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.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.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/list-connections-libnm-glib.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ +@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c -o $@ $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\ +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\ +@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\ +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ +@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Plo +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(PROGRAMS) +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-noinstPROGRAMS \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-noinstPROGRAMS ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags uninstall uninstall-am + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/examples/C/add-connection-dbus-glib.c b/examples/C/add-connection-dbus-glib.c new file mode 100644 index 00000000..c7c1a3f1 --- /dev/null +++ b/examples/C/add-connection-dbus-glib.c @@ -0,0 +1,124 @@ +/* -*- 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; + + /* Initialize GType system */ + g_type_init (); + + /* 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/add-connection-libnm-glib.c b/examples/C/add-connection-libnm-glib.c new file mode 100644 index 00000000..510e06ee --- /dev/null +++ b/examples/C/add-connection-libnm-glib.c @@ -0,0 +1,136 @@ +/* -*- 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 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. + * + * 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 + */ + +#include <glib.h> +#include <nm-remote-settings.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> + +static void +added_cb (NMRemoteSettings *settings, + NMRemoteConnection *remote, + GError *error, + gpointer user_data) +{ + GMainLoop *loop = user_data; + + /* NM responded to our request; either handle the resulting error or + * print out the object path of the connection we just added. + */ + + if (error) + g_print ("Error adding connection: %s", error->message); + else + g_print ("Added: %s\n", nm_connection_get_path (NM_CONNECTION (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) +{ + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIP4Config *s_ip4; + char *uuid; + gboolean success; + + /* Create a new connection object */ + connection = 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)); + + /* 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"); + + g_object_unref (connection); + return success; +} + + +int main (int argc, char *argv[]) +{ + DBusGConnection *bus; + NMRemoteSettings *settings; + GMainLoop *loop; + + /* Initialize GType system */ + g_type_init (); + + 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); + + /* 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"); + + /* Clean up */ + g_object_unref (settings); + dbus_g_connection_unref (bus); + + return 0; +} diff --git a/examples/C/get-active-connections.c b/examples/C/get-active-connections.c new file mode 100644 index 00000000..36224d29 --- /dev/null +++ b/examples/C/get-active-connections.c @@ -0,0 +1,248 @@ +/* -*- 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 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.c -o get-active-connections + */ + +#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 *service, const char *path) +{ + DBusGProxy *proxy; + GError *error = NULL; + GHashTable *hash = NULL; + NMConnection *connection = NULL; + + /* This function asks the Settings Service that provides this network + * configuration for the details of that configuration. + */ + + /* Create the D-Bus proxy for the Settings Service so we can ask it for the + * connection configuration details. + */ + proxy = dbus_g_proxy_new_for_name (bus, + 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 the settings service is + * 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 */ + g_message ("%s => %s", service, 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 = { 0 }; + GValue serv_value = { 0 }; + GError *error = NULL; + const char *path = NULL, *service = 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; + } + + /* Get the service name of the D-Bus service that provides the Connection */ + if (!dbus_g_proxy_call (props_proxy, "Get", &error, + G_TYPE_STRING, NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + G_TYPE_STRING, "ServiceName", + G_TYPE_INVALID, + G_TYPE_VALUE, &serv_value, + G_TYPE_INVALID)) { + g_warning ("Failed to get active connection ServiceName property: %s", + error->message); + g_error_free (error); + goto out; + } + + if (!G_VALUE_HOLDS (&serv_value, G_TYPE_STRING)) { + g_warning ("Unexpected type returned getting Connection property: %s", + G_VALUE_TYPE_NAME (&serv_value)); + goto out; + } + + service = g_value_get_string (&serv_value); + if (!service) { + g_warning ("Missing connection service name!"); + goto out; + } + + /* Print out the actual connection details */ + print_connection (bus, service, path); + +out: + g_value_unset (&path_value); + g_value_unset (&serv_value); + g_object_unref (props_proxy); +} + +static void +get_active_connections (DBusGConnection *bus, DBusGProxy *proxy) +{ + GError *error = NULL; + GValue value = { 0 }; + GPtrArray *paths = NULL; + 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 of each active connection */ + for (i = 0; i < paths->len; i++) + get_active_connection_details (bus, g_ptr_array_index (paths, i)); + +out: + g_value_unset (&value); +} + + +int main (int argc, char *argv[]) +{ + DBusGConnection *bus; + DBusGProxy *props_proxy; + + /* Initialize GType system */ + g_type_init (); + + /* 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/get-ap-info-libnm-glib.c b/examples/C/get-ap-info-libnm-glib.c new file mode 100644 index 00000000..316bce0e --- /dev/null +++ b/examples/C/get-ap-info-libnm-glib.c @@ -0,0 +1,229 @@ +/* + * 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 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. + * + * 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 + */ + +#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 * +ap_wpa_rsn_flags_to_string (guint32 flags) +{ + char *flags_str[16]; /* Enough space for flags and terminating NULL */ + char *ret_str; + int i = 0; + + if (flags & NM_802_11_AP_SEC_PAIR_WEP40) + flags_str[i++] = g_strdup ("pair_wpe40"); + if (flags & NM_802_11_AP_SEC_PAIR_WEP104) + flags_str[i++] = g_strdup ("pair_wpe104"); + if (flags & NM_802_11_AP_SEC_PAIR_TKIP) + flags_str[i++] = g_strdup ("pair_tkip"); + if (flags & NM_802_11_AP_SEC_PAIR_CCMP) + flags_str[i++] = g_strdup ("pair_ccmp"); + if (flags & NM_802_11_AP_SEC_GROUP_WEP40) + flags_str[i++] = g_strdup ("group_wpe40"); + if (flags & NM_802_11_AP_SEC_GROUP_WEP104) + flags_str[i++] = g_strdup ("group_wpe104"); + if (flags & NM_802_11_AP_SEC_GROUP_TKIP) + flags_str[i++] = g_strdup ("group_tkip"); + if (flags & NM_802_11_AP_SEC_GROUP_CCMP) + flags_str[i++] = g_strdup ("group_ccmp"); + if (flags & NM_802_11_AP_SEC_KEY_MGMT_PSK) + flags_str[i++] = g_strdup ("psk"); + if (flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X) + flags_str[i++] = g_strdup ("802.1X"); + + if (i == 0) + flags_str[i++] = g_strdup ("none"); + + flags_str[i] = NULL; + + ret_str = g_strjoinv (" ", flags_str); + + i = 0; + while (flags_str[i]) + g_free (flags_str[i++]); + + return ret_str; +} + +static void +show_access_point_info (NMAccessPoint *ap) +{ + guint32 flags, wpa_flags, rsn_flags, freq, bitrate; + guint8 strength; + const GByteArray *ssid; + const char *hwaddr; + NM80211Mode mode; + char *freq_str, *ssid_str, *bitrate_str, *strength_str, *wpa_flags_str, *rsn_flags_str; + GString *security_str; + + /* Get AP properties */ + flags = nm_access_point_get_flags (ap); + wpa_flags = nm_access_point_get_wpa_flags (ap); + rsn_flags = nm_access_point_get_rsn_flags (ap); + ssid = nm_access_point_get_ssid (ap); + hwaddr = nm_access_point_get_hw_address (ap); + freq = nm_access_point_get_frequency (ap); + mode = nm_access_point_get_mode (ap); + bitrate = nm_access_point_get_max_bitrate (ap); + strength = nm_access_point_get_strength (ap); + + /* Convert to strings */ + ssid_str = nm_utils_ssid_to_utf8 (ssid); + freq_str = g_strdup_printf ("%u MHz", freq); + bitrate_str = g_strdup_printf ("%u MB/s", bitrate/1000); + strength_str = g_strdup_printf ("%u", strength); + wpa_flags_str = ap_wpa_rsn_flags_to_string (wpa_flags); + rsn_flags_str = ap_wpa_rsn_flags_to_string (rsn_flags); + + security_str = g_string_new (NULL); + if ( !(flags & NM_802_11_AP_FLAGS_PRIVACY) + && (wpa_flags != NM_802_11_AP_SEC_NONE) + && (rsn_flags != NM_802_11_AP_SEC_NONE)) + g_string_append (security_str, "Encrypted: "); + + if ( (flags & NM_802_11_AP_FLAGS_PRIVACY) + && (wpa_flags == NM_802_11_AP_SEC_NONE) + && (rsn_flags == NM_802_11_AP_SEC_NONE)) + g_string_append (security_str, "WEP "); + if (wpa_flags != NM_802_11_AP_SEC_NONE) + g_string_append (security_str, "WPA "); + if (rsn_flags != NM_802_11_AP_SEC_NONE) + g_string_append (security_str, "WPA2 "); + if ( (wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X) + || (rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) + g_string_append (security_str, "Enterprise "); + + if (security_str->len > 0) + g_string_truncate (security_str, security_str->len-1); /* Chop off last space */ + + printf ("SSID: %s\n", ssid_str); + printf ("BSSID: %s\n", hwaddr); + printf ("Mode: %s\n", mode == NM_802_11_MODE_ADHOC ? "Ad-Hoc" : mode == NM_802_11_MODE_INFRA ? "Infrastructure" : "Unknown"); + printf ("Freq: %s\n", freq_str); + printf ("Bitrate: %s\n", bitrate_str); + printf ("Strength: %s\n", strength_str); + printf ("Security: %s\n", security_str->str); + printf ("WPA flags: %s\n", wpa_flags_str); + printf ("RSN flags: %s\n", rsn_flags_str); + printf ("D-Bus path: %s\n\n", nm_object_get_path (NM_OBJECT (ap))); + + g_free (ssid_str); + g_free (freq_str); + g_free (bitrate_str); + g_free (strength_str); + g_free (wpa_flags_str); + g_free (rsn_flags_str); + g_string_free (security_str, TRUE); +} + +static void +show_wifi_device_info (NMDevice *device) +{ + NMAccessPoint *active_ap = NULL; + const GPtrArray *aps; + const char *iface; + const char *driver; + guint32 speed; + const GByteArray *active_ssid; + char *active_ssid_str = NULL; + int i; + + /* Get active AP */ + 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); + } + } + + iface = nm_device_get_iface (device); + driver = nm_device_get_driver (device); + speed = nm_device_wifi_get_bitrate (NM_DEVICE_WIFI (device)); + speed /= 1000; + + printf ("Device: %s ---- Driver: %s ---- Speed: %d MB/s ---- Active AP: %s\n", + iface, driver, speed, active_ssid_str ? active_ssid_str : "none"); + printf ("=================================================================================\n"); + g_free (active_ssid_str); + + /* Get all APs of the Wi-Fi device */ + aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device)); + + /* Print AP details */ + for (i = 0; aps && (i < aps->len); i++) { + NMAccessPoint *ap = g_ptr_array_index (aps, i); + show_access_point_info (ap); + } +} + +int main (int argc, char *argv[]) +{ + DBusGConnection *bus; + NMClient *client; + const GPtrArray *devices; + int i; + + /* Initialize GType system */ + g_type_init (); + + /* Get system bus */ + bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL); + + /* Get NMClient object */ + client = nm_client_new (); + if (!client) { + dbus_g_connection_unref (bus); + g_message ("Error: Could not create NMClient."); + return EXIT_FAILURE; + } + + /* Get all devices managed by NetworkManager */ + devices = nm_client_get_devices (client); + + /* Go through the array and process Wi-Fi devices */ + for (i = 0; devices && (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/list-connections-dbus.c b/examples/C/list-connections-dbus.c new file mode 100644 index 00000000..2cb584b5 --- /dev/null +++ b/examples/C/list-connections-dbus.c @@ -0,0 +1,83 @@ +/* + * 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; + + /* Call ListConnections D-Bus method */ + 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); + + 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; + + /* Initialize GType system */ + g_type_init (); + + /* 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/list-connections-libnm-glib.c b/examples/C/list-connections-libnm-glib.c new file mode 100644 index 00000000..edb5ccc3 --- /dev/null +++ b/examples/C/list-connections-libnm-glib.c @@ -0,0 +1,176 @@ +/* + * 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 (NMConnection *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 = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_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, (GFunc) 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; + + /* Initialize GType system */ + g_type_init (); + + /* 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/Makefile.am b/examples/Makefile.am index c2ddf781..643959b1 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1 +1,3 @@ -SUBDIRS=python +SUBDIRS= \ + python \ + C diff --git a/examples/Makefile.in b/examples/Makefile.in index 4ab96315..3ecbee95 100644 --- a/examples/Makefile.in +++ b/examples/Makefile.in @@ -37,11 +37,16 @@ subdir = examples DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/compiler_warnings.m4 \ - $(top_srcdir)/m4/gtk-doc.m4 $(top_srcdir)/m4/intltool.m4 \ - $(top_srcdir)/m4/libnl-check.m4 $(top_srcdir)/m4/libtool.m4 \ - $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ - $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ - $(top_srcdir)/m4/nls.m4 $(top_srcdir)/configure.ac + $(top_srcdir)/m4/gettext.m4 $(top_srcdir)/m4/gtk-doc.m4 \ + $(top_srcdir)/m4/iconv.m4 $(top_srcdir)/m4/intlmacosx.m4 \ + $(top_srcdir)/m4/intltool.m4 $(top_srcdir)/m4/introspection.m4 \ + $(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \ + $(top_srcdir)/m4/lib-prefix.m4 $(top_srcdir)/m4/libnl-check.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/nls.m4 \ + $(top_srcdir)/m4/po.m4 $(top_srcdir)/m4/progtest.m4 \ + $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d @@ -98,7 +103,6 @@ am__relativize = \ done; \ reldir="$$dir2" ACLOCAL = @ACLOCAL@ -ACLOCAL_AMFLAGS = @ACLOCAL_AMFLAGS@ ALL_LINGUAS = @ALL_LINGUAS@ AMTAR = @AMTAR@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ @@ -107,8 +111,6 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ -CATALOGS = @CATALOGS@ -CATOBJEXT = @CATOBJEXT@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -125,6 +127,7 @@ DHCLIENT_PATH = @DHCLIENT_PATH@ DHCLIENT_VERSION = @DHCLIENT_VERSION@ DHCPCD_PATH = @DHCPCD_PATH@ DISABLE_DEPRECATED = @DISABLE_DEPRECATED@ +DLLTOOL = @DLLTOOL@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ @@ -133,6 +136,7 @@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ +GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ GETTEXT_PACKAGE = @GETTEXT_PACKAGE@ GIO_CFLAGS = @GIO_CFLAGS@ GIO_LIBS = @GIO_LIBS@ @@ -141,8 +145,8 @@ GLIB_GENMARSHAL = @GLIB_GENMARSHAL@ GLIB_LIBS = @GLIB_LIBS@ GMODULE_CFLAGS = @GMODULE_CFLAGS@ GMODULE_LIBS = @GMODULE_LIBS@ -GMOFILES = @GMOFILES@ GMSGFMT = @GMSGFMT@ +GMSGFMT_015 = @GMSGFMT_015@ GNUTLS_CFLAGS = @GNUTLS_CFLAGS@ GNUTLS_LIBS = @GNUTLS_LIBS@ GREP = @GREP@ @@ -157,13 +161,23 @@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ -INSTOBJEXT = @INSTOBJEXT@ INTLLIBS = @INTLLIBS@ INTLTOOL_EXTRACT = @INTLTOOL_EXTRACT@ INTLTOOL_MERGE = @INTLTOOL_MERGE@ INTLTOOL_PERL = @INTLTOOL_PERL@ INTLTOOL_UPDATE = @INTLTOOL_UPDATE@ +INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@ +INTROSPECTION_CFLAGS = @INTROSPECTION_CFLAGS@ +INTROSPECTION_COMPILER = @INTROSPECTION_COMPILER@ +INTROSPECTION_GENERATE = @INTROSPECTION_GENERATE@ +INTROSPECTION_GIRDIR = @INTROSPECTION_GIRDIR@ +INTROSPECTION_LIBS = @INTROSPECTION_LIBS@ +INTROSPECTION_MAKEFILE = @INTROSPECTION_MAKEFILE@ +INTROSPECTION_SCANNER = @INTROSPECTION_SCANNER@ +INTROSPECTION_TYPELIBDIR = @INTROSPECTION_TYPELIBDIR@ IPTABLES_PATH = @IPTABLES_PATH@ +IWMX_SDK_CFLAGS = @IWMX_SDK_CFLAGS@ +IWMX_SDK_LIBS = @IWMX_SDK_LIBS@ KERNEL_FIRMWARE_DIR = @KERNEL_FIRMWARE_DIR@ LD = @LD@ LDFLAGS = @LDFLAGS@ @@ -171,6 +185,8 @@ LIBDL = @LIBDL@ LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ +LIBICONV = @LIBICONV@ +LIBINTL = @LIBINTL@ LIBM = @LIBM@ LIBNL_CFLAGS = @LIBNL_CFLAGS@ LIBNL_LIBS = @LIBNL_LIBS@ @@ -179,13 +195,15 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBINTL = @LTLIBINTL@ LTLIBOBJS = @LTLIBOBJS@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ -MKINSTALLDIRS = @MKINSTALLDIRS@ MSGFMT = @MSGFMT@ -MSGFMT_OPTS = @MSGFMT_OPTS@ +MSGFMT_015 = @MSGFMT_015@ MSGMERGE = @MSGMERGE@ NM = @NM@ NMEDIT = @NMEDIT@ @@ -211,12 +229,9 @@ PKGCONFIG_PATH = @PKGCONFIG_PATH@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ -POFILES = @POFILES@ POLKIT_CFLAGS = @POLKIT_CFLAGS@ POLKIT_LIBS = @POLKIT_LIBS@ POSUB = @POSUB@ -PO_IN_DATADIR_FALSE = @PO_IN_DATADIR_FALSE@ -PO_IN_DATADIR_TRUE = @PO_IN_DATADIR_TRUE@ PPPD_PLUGIN_DIR = @PPPD_PLUGIN_DIR@ RANLIB = @RANLIB@ RESOLVCONF_PATH = @RESOLVCONF_PATH@ @@ -231,10 +246,13 @@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ VERSION = @VERSION@ XGETTEXT = @XGETTEXT@ +XGETTEXT_015 = @XGETTEXT_015@ +XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ @@ -283,7 +301,10 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -SUBDIRS = python +SUBDIRS = \ + python \ + C + all: all-recursive .SUFFIXES: diff --git a/examples/python/Makefile.in b/examples/python/Makefile.in index fe29d8ae..ba7d7e0e 100644 --- a/examples/python/Makefile.in +++ b/examples/python/Makefile.in @@ -37,11 +37,16 @@ subdir = examples/python DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/compiler_warnings.m4 \ - $(top_srcdir)/m4/gtk-doc.m4 $(top_srcdir)/m4/intltool.m4 \ - $(top_srcdir)/m4/libnl-check.m4 $(top_srcdir)/m4/libtool.m4 \ - $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ - $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ - $(top_srcdir)/m4/nls.m4 $(top_srcdir)/configure.ac + $(top_srcdir)/m4/gettext.m4 $(top_srcdir)/m4/gtk-doc.m4 \ + $(top_srcdir)/m4/iconv.m4 $(top_srcdir)/m4/intlmacosx.m4 \ + $(top_srcdir)/m4/intltool.m4 $(top_srcdir)/m4/introspection.m4 \ + $(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \ + $(top_srcdir)/m4/lib-prefix.m4 $(top_srcdir)/m4/libnl-check.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/nls.m4 \ + $(top_srcdir)/m4/po.m4 $(top_srcdir)/m4/progtest.m4 \ + $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d @@ -58,7 +63,6 @@ SOURCES = DIST_SOURCES = DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ -ACLOCAL_AMFLAGS = @ACLOCAL_AMFLAGS@ ALL_LINGUAS = @ALL_LINGUAS@ AMTAR = @AMTAR@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ @@ -67,8 +71,6 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ -CATALOGS = @CATALOGS@ -CATOBJEXT = @CATOBJEXT@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -85,6 +87,7 @@ DHCLIENT_PATH = @DHCLIENT_PATH@ DHCLIENT_VERSION = @DHCLIENT_VERSION@ DHCPCD_PATH = @DHCPCD_PATH@ DISABLE_DEPRECATED = @DISABLE_DEPRECATED@ +DLLTOOL = @DLLTOOL@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ @@ -93,6 +96,7 @@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ +GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ GETTEXT_PACKAGE = @GETTEXT_PACKAGE@ GIO_CFLAGS = @GIO_CFLAGS@ GIO_LIBS = @GIO_LIBS@ @@ -101,8 +105,8 @@ GLIB_GENMARSHAL = @GLIB_GENMARSHAL@ GLIB_LIBS = @GLIB_LIBS@ GMODULE_CFLAGS = @GMODULE_CFLAGS@ GMODULE_LIBS = @GMODULE_LIBS@ -GMOFILES = @GMOFILES@ GMSGFMT = @GMSGFMT@ +GMSGFMT_015 = @GMSGFMT_015@ GNUTLS_CFLAGS = @GNUTLS_CFLAGS@ GNUTLS_LIBS = @GNUTLS_LIBS@ GREP = @GREP@ @@ -117,13 +121,23 @@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ -INSTOBJEXT = @INSTOBJEXT@ INTLLIBS = @INTLLIBS@ INTLTOOL_EXTRACT = @INTLTOOL_EXTRACT@ INTLTOOL_MERGE = @INTLTOOL_MERGE@ INTLTOOL_PERL = @INTLTOOL_PERL@ INTLTOOL_UPDATE = @INTLTOOL_UPDATE@ +INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@ +INTROSPECTION_CFLAGS = @INTROSPECTION_CFLAGS@ +INTROSPECTION_COMPILER = @INTROSPECTION_COMPILER@ +INTROSPECTION_GENERATE = @INTROSPECTION_GENERATE@ +INTROSPECTION_GIRDIR = @INTROSPECTION_GIRDIR@ +INTROSPECTION_LIBS = @INTROSPECTION_LIBS@ +INTROSPECTION_MAKEFILE = @INTROSPECTION_MAKEFILE@ +INTROSPECTION_SCANNER = @INTROSPECTION_SCANNER@ +INTROSPECTION_TYPELIBDIR = @INTROSPECTION_TYPELIBDIR@ IPTABLES_PATH = @IPTABLES_PATH@ +IWMX_SDK_CFLAGS = @IWMX_SDK_CFLAGS@ +IWMX_SDK_LIBS = @IWMX_SDK_LIBS@ KERNEL_FIRMWARE_DIR = @KERNEL_FIRMWARE_DIR@ LD = @LD@ LDFLAGS = @LDFLAGS@ @@ -131,6 +145,8 @@ LIBDL = @LIBDL@ LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ +LIBICONV = @LIBICONV@ +LIBINTL = @LIBINTL@ LIBM = @LIBM@ LIBNL_CFLAGS = @LIBNL_CFLAGS@ LIBNL_LIBS = @LIBNL_LIBS@ @@ -139,13 +155,15 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBINTL = @LTLIBINTL@ LTLIBOBJS = @LTLIBOBJS@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ -MKINSTALLDIRS = @MKINSTALLDIRS@ MSGFMT = @MSGFMT@ -MSGFMT_OPTS = @MSGFMT_OPTS@ +MSGFMT_015 = @MSGFMT_015@ MSGMERGE = @MSGMERGE@ NM = @NM@ NMEDIT = @NMEDIT@ @@ -171,12 +189,9 @@ PKGCONFIG_PATH = @PKGCONFIG_PATH@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ -POFILES = @POFILES@ POLKIT_CFLAGS = @POLKIT_CFLAGS@ POLKIT_LIBS = @POLKIT_LIBS@ POSUB = @POSUB@ -PO_IN_DATADIR_FALSE = @PO_IN_DATADIR_FALSE@ -PO_IN_DATADIR_TRUE = @PO_IN_DATADIR_TRUE@ PPPD_PLUGIN_DIR = @PPPD_PLUGIN_DIR@ RANLIB = @RANLIB@ RESOLVCONF_PATH = @RESOLVCONF_PATH@ @@ -191,10 +206,13 @@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ VERSION = @VERSION@ XGETTEXT = @XGETTEXT@ +XGETTEXT_015 = @XGETTEXT_015@ +XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ diff --git a/examples/python/add-system-connection.py b/examples/python/add-system-connection.py index d8902a13..f55d0df0 100755 --- a/examples/python/add-system-connection.py +++ b/examples/python/add-system-connection.py @@ -41,8 +41,8 @@ con = dbus.Dictionary({ bus = dbus.SystemBus() -proxy = bus.get_object("org.freedesktop.NetworkManagerSystemSettings", "/org/freedesktop/NetworkManagerSettings") -settings = dbus.Interface(proxy, "org.freedesktop.NetworkManagerSettings") +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/add-system-wifi-connection.py b/examples/python/add-system-wifi-connection.py index ab0b6020..ff390821 100755 --- a/examples/python/add-system-wifi-connection.py +++ b/examples/python/add-system-wifi-connection.py @@ -14,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. # -# Copyright (C) 2010 Red Hat, Inc. +# Copyright (C) 2011 Red Hat, Inc. # import dbus @@ -56,9 +56,8 @@ con = dbus.Dictionary({ bus = dbus.SystemBus() -print con -proxy = bus.get_object("org.freedesktop.NetworkManagerSystemSettings", "/org/freedesktop/NetworkManagerSettings") -settings = dbus.Interface(proxy, "org.freedesktop.NetworkManagerSettings") +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/nm-state.py b/examples/python/nm-state.py index e7bb55f1..a79b3405 100644 --- a/examples/python/nm-state.py +++ b/examples/python/nm-state.py @@ -53,11 +53,8 @@ for a in active: # needed to connect to a specific network. Lets get those details so we # can find the user-readable name of the connection. con_path = prop_iface.Get("org.freedesktop.NetworkManager.Connection.Active", "Connection") - con_service = prop_iface.Get("org.freedesktop.NetworkManager.Connection.Active", "ServiceName") - - # ask the provider of the connection for its details - service_proxy = bus.get_object(con_service, con_path) - con_iface = dbus.Interface(service_proxy, "org.freedesktop.NetworkManagerSettings.Connection") + service_proxy = bus.get_object("org.freedesktop.NetworkManager", con_path) + con_iface = dbus.Interface(service_proxy, "org.freedesktop.NetworkManager.Settings.Connection") con_details = con_iface.GetSettings() con_name = con_details['connection']['id'] |