/* * Create client handle for addrconf forwarder */ static dbus_bool_t ni_objectmodel_addrconf_forwarder_call(ni_dbus_addrconf_forwarder_t *forwarder, ni_netdev_t *dev, const char *method_name, const ni_uuid_t *uuid, const ni_dbus_variant_t *dict, DBusError *error) { ni_dbus_object_t *object; char object_path[256]; ni_dbus_variant_t argv[2]; int argc = 0; dbus_bool_t rv; if (forwarder->supplicant.client == NULL) { forwarder->supplicant.client = ni_create_dbus_client(forwarder->supplicant.bus_name); if (forwarder->supplicant.client == NULL) { dbus_set_error(error, "unable to create call forwarder for %s", forwarder->supplicant.bus_name); return FALSE; } ni_dbus_client_add_signal_handler(forwarder->supplicant.client, forwarder->supplicant.bus_name, /* sender must be the supplicant */ NULL, /* any object */ NI_OBJECTMODEL_ADDRCONF_INTERFACE, /* interface */ ni_objectmodel_addrconf_signal_handler, forwarder); } /* Build the path of the object to talk to in the supplicant service */ snprintf(object_path, sizeof(object_path), "%s/%u", forwarder->supplicant.object_path, dev->link.ifindex); object = ni_dbus_client_object_new(forwarder->supplicant.client, &forwarder->class, object_path, forwarder->supplicant.interface, NULL); /* Build the arguments. Note that we don't clone the dict, we just assign it * to argv[1]. Thus, we must make sure we never call ni_dbus_variant_destroy on argv[1] */ memset(argv, 0, sizeof(argv)); ni_dbus_variant_set_uuid(&argv[argc++], uuid); if (dict) argv[argc++] = *dict; /* Call the supplicant's method */ rv = ni_dbus_object_call_variant(object, forwarder->supplicant.interface, method_name, argc, argv, 0, NULL, error); ni_dbus_object_free(object); ni_dbus_variant_destroy(&argv[0]); return rv; }
/* * Create the client and return the handle of the root object */ ni_dbus_object_t * ni_call_create_client(void) { static ni_dbus_object_t *root_object = NULL; if (root_object == NULL) { ni_dbus_client_t *client; ni_objectmodel_init(NULL); /* Use ni_objectmodel_create_client() */ client = ni_create_dbus_client(NI_OBJECTMODEL_DBUS_BUS_NAME); if (!client) ni_fatal("Unable to connect to wicked dbus service"); root_object = ni_dbus_client_object_new(client, &ni_dbus_anonymous_class, NI_OBJECTMODEL_OBJECT_PATH, NI_OBJECTMODEL_INTERFACE, NULL); } return root_object; }