Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
NetworkManager
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
146
Issues
146
List
Boards
Labels
Service Desk
Milestones
Merge Requests
11
Merge Requests
11
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
NetworkManager
NetworkManager
Commits
b4544182
Commit
b4544182
authored
Jun 09, 2014
by
Jiří Klimeš
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples: fix get-active-connections-dbus-glib.c example
parent
a7eae7a5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
45 deletions
+18
-45
examples/C/glib/get-active-connections-dbus-glib.c
examples/C/glib/get-active-connections-dbus-glib.c
+18
-45
No files found.
examples/C/glib/get-active-connections-dbus-glib.c
View file @
b4544182
...
...
@@ -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.
*
* (C) Copyright 2010 Red Hat, Inc.
* (C) Copyright 2010
-2014
Red Hat, Inc.
*/
/*
...
...
@@ -26,6 +26,7 @@
* 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>
...
...
@@ -41,22 +42,18 @@
#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
)
print_connection
(
DBusGConnection
*
bus
,
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.
*/
/* This function asks NetworkManager for the details of the connection */
/* Create the D-Bus proxy for the Settings Service so we can ask it for the
* connection configuration details.
*/
/* Create the D-Bus proxy so we can ask it for the connection configuration details. */
proxy
=
dbus_g_proxy_new_for_name
(
bus
,
service
,
NM_DBUS_SERVICE
,
path
,
NM_DBUS_IFACE_SETTINGS_CONNECTION
);
g_assert
(
proxy
);
...
...
@@ -72,9 +69,8 @@ print_connection (DBusGConnection *bus, const char *service, const char *path)
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. */
/* 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
);
...
...
@@ -83,7 +79,7 @@ print_connection (DBusGConnection *bus, const char *service, const char *path)
}
/* And finally dump all the configuration to stdout */
g_message
(
"%s => %s"
,
service
,
path
);
printf
(
"%s <=> %s
\n
"
,
nm_connection_get_id
(
connection
)
,
path
);
nm_connection_dump
(
connection
);
out:
...
...
@@ -99,9 +95,8 @@ get_active_connection_details (DBusGConnection *bus, const char *obj_path)
{
DBusGProxy
*
props_proxy
;
GValue
path_value
=
G_VALUE_INIT
;
GValue
serv_value
=
G_VALUE_INIT
;
GError
*
error
=
NULL
;
const
char
*
path
=
NULL
,
*
service
=
NULL
;
const
char
*
path
=
NULL
;
/* This function gets the backing Connection object that describes the
* network configuration that the ActiveConnection object is actually using.
...
...
@@ -141,37 +136,11 @@ get_active_connection_details (DBusGConnection *bus, const char *obj_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
);
print_connection
(
bus
,
path
);
out:
g_value_unset
(
&
path_value
);
g_value_unset
(
&
serv_value
);
g_object_unref
(
props_proxy
);
}
...
...
@@ -181,6 +150,7 @@ 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 */
...
...
@@ -209,9 +179,12 @@ get_active_connections (DBusGConnection *bus, DBusGProxy *proxy)
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
));
/* 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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment