Hi Wicked Developers,
We are working on a new feature in our product with SELS15 OS, where we want to programmatically leverage Wicked and dbus integration. We have process A for which we want to get it notified of any change in the state of the ethernet interfaces such as linkdown, linkup, MTU change etc. We came across the gdbus API where there seemed to be a solution for what we want. We have written some sample programs using gdbus API. Here are few code snippets:
static void
on_signal (GDBusProxy *proxy,
char *sender_name,
char *signal_name,
GVariant *parameters,
gpointer user_data)
{
guint32 new_state;
/* Print all signals */
char *parameters_str;
parameters_str = g_variant_print (parameters, TRUE);
g_print (" *** Received Signal: %s: %s\n", signal_name, parameters_str);
g_free (parameters_str);
printf("in on_signal \n");
g_print ("Interface Name %s \n", g_dbus_proxy_get_interface_name(proxy));
g_print ("Object Path %s \n", g_dbus_proxy_get_object_path (proxy));
/* We are only interested in "StateChanged" signal */
if (strcmp (signal_name, "StateChanged") == 0) {
GVariant *tmp = g_variant_get_child_value (parameters, 0);
new_state = g_variant_get_uint32 (tmp);
g_variant_unref (tmp);
g_print ("NetworkManager state is: (%d) %s\n", new_state, nm_state_to_string ((NMState) new_state));
}
}
main()
{
.
.
proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
flags,
NULL, /* GDBusInterfaceInfo */
"org.opensuse.Network",
"/org/opensuse/Network",
"org.opensuse.Network",
NULL, /* GCancellable */
&error);
/* Connect to g-signal to receive signals from proxy (remote object) */
g_signal_connect (proxy,
"g-signal",
G_CALLBACK (on_signal),
NULL);
/* Run main loop */
loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (loop);
g_object_unref (proxy);
return 0;
}
Now, when the interfaces are brought down using wicked ifdown/ifup commands, the program is able to catch the signals.
Additionally, we also want to have the ability to bring down the interfaces in the program. So we tried something like using g_dbus_proxy_new_for_bus_sync()
main()
{
GError *error = NULL;
GDBusProxyFlags flags;
GDBusProxy *proxy;
g_print ("Running Proxy Command \n");
g_print ("==============================\n");
flags = G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START;
proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
flags,
NULL, /* GDBusInterfaceInfo */
"org.opensuse.Network",
"/org/opensuse/Network/Interface/4",
"org.opensuse.Network.Interface",
NULL, /* GCancellable */
&error);
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;
}
g_dbus_proxy_call_sync (proxy, "linkUp", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
g_object_unref (proxy);
return 0;
}
Does Suse recommend using the gdbus APIs to programmatically achieve dbus and wicked communication for third party programs/applications? We need this info as we need to freeze on the architecture and design for our new feature. If Suse does not recommend gdbus APIs, please let us know if there are robust alternatives to what we are trying to achieve. How do we know the APIs that are exposed by Wicked for dbus?
Thank You,
Koundinya
--
To unsubscribe, e-mail: wicked-devel+unsubscribe(a)opensuse.org
To contact the owner, e-mail: wicked-devel+owner(a)opensuse.org