int set_service_property(DBusConnection *connection, DBusMessage *message, char *name, char *property, char **keys, void *data, int num_args) { DBusMessage *message_send; DBusMessageIter iter; struct service_data service; char *path; const char *path_name; path_name = find_service(connection, message, name, &service); if (path_name == NULL) return -ENXIO; path = g_strdup_printf("/net/connman/service/%s", path_name); message_send = dbus_message_new_method_call("net.connman", path, "net.connman.Service", "SetProperty"); if (message_send == NULL) return -ENOMEM; dbus_message_iter_init_append(message_send, &iter); if (strcmp(property, "AutoConnect") == 0) connman_dbus_property_append_basic(&iter, (const char *) property, DBUS_TYPE_BOOLEAN, data); else if ((strcmp(property, "Domains.Configuration") == 0) || (strcmp(property, "Timeservers.Configuration") == 0) || (strcmp(property, "Nameservers.Configuration") == 0)) append_property_array(&iter, property, data, num_args); else if ((strcmp(property, "IPv4.Configuration") == 0) || (strcmp(property, "IPv6.Configuration") == 0) || (strcmp(property, "Proxy.Configuration") == 0)) append_property_dict(&iter, property, keys, data, num_args); dbus_connection_send(connection, message_send, NULL); dbus_connection_flush(connection); dbus_message_unref(message_send); g_free(path); return 0; }
static int change_powered(DBusConnection *conn, const char *path, dbus_bool_t powered) { DBusMessage *message; DBusMessageIter iter; DBusPendingCall *call; DBG(""); if (path == NULL) return -EINVAL; message = dbus_message_new_method_call(BLUEZ_SERVICE, path, BLUEZ_ADAPTER_INTERFACE, SET_PROPERTY); if (message == NULL) return -ENOMEM; dbus_message_set_auto_start(message, FALSE); dbus_message_iter_init_append(message, &iter); connman_dbus_property_append_basic(&iter, "Powered", DBUS_TYPE_BOOLEAN, &powered); if (dbus_connection_send_with_reply(conn, message, &call, TIMEOUT) == FALSE) { connman_error("Failed to change Powered property"); dbus_message_unref(message); return -EINVAL; } if (call == NULL) { connman_error("D-Bus connection not available"); dbus_message_unref(message); return -EINVAL; } dbus_pending_call_set_notify(call, powered_reply, g_strdup(path), g_free); dbus_message_unref(message); return -EINPROGRESS; }
dbus_bool_t connman_dbus_property_changed_basic(const char *path, const char *interface, const char *key, int type, void *val) { DBusMessage *signal; DBusMessageIter iter; if (!path) return FALSE; signal = dbus_message_new_signal(path, interface, "PropertyChanged"); if (!signal) return FALSE; dbus_message_iter_init_append(signal, &iter); connman_dbus_property_append_basic(&iter, key, type, val); g_dbus_send_message(connection, signal); return TRUE; }
static DBusMessage *set_property(DBusConnection *connection, const char *property, int type, void *value) { DBusMessage *message, *reply; DBusError error; DBusMessageIter iter; message = dbus_message_new_method_call(CONNMAN_SERVICE, CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, "SetProperty"); if (!message) return NULL; dbus_message_iter_init_append(message, &iter); connman_dbus_property_append_basic(&iter, property, type, value); dbus_error_init(&error); reply = dbus_connection_send_with_reply_and_block(connection, message, -1, &error); if (!reply) { if (dbus_error_is_set(&error)) { LOG("%s", error.message); dbus_error_free(&error); } else { LOG("Failed to get properties"); } dbus_message_unref(message); return NULL; } dbus_message_unref(message); return reply; }