当前位置: 首页>>代码示例>>C++>>正文


C++ dbus_message_iter_append_basic函数代码示例

本文整理汇总了C++中dbus_message_iter_append_basic函数的典型用法代码示例。如果您正苦于以下问题:C++ dbus_message_iter_append_basic函数的具体用法?C++ dbus_message_iter_append_basic怎么用?C++ dbus_message_iter_append_basic使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了dbus_message_iter_append_basic函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: get_all_properties_by_unit_path

static int get_all_properties_by_unit_path(DBusConnection *conn, const char *unit_path, int(*callback)(const char *name, const char *value, void *arg), void *cbarg)
{
	int ret = 1;
	DBusMessage *msg = NULL;
	DBusPendingCall *pending = NULL;

	msg = dbus_message_new_method_call(
		"org.freedesktop.systemd1",
		unit_path,
		"org.freedesktop.DBus.Properties",
		"GetAll"
	);
	if (msg == NULL) {
		dI("Failed to create dbus_message via dbus_message_new_method_call!\n");
		goto cleanup;
	}

	DBusMessageIter args, property_iter;

	const char *interface = "org.freedesktop.systemd1.Unit";

	dbus_message_iter_init_append(msg, &args);
	if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &interface)) {
		dI("Failed to append interface '%s' string parameter to dbus message!\n", interface);
		goto cleanup;
	}

	if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) {
		dI("Failed to send message via dbus!\n");
		goto cleanup;
	}
	if (pending == NULL) {
		dI("Invalid dbus pending call!\n");
		goto cleanup;
	}

	dbus_connection_flush(conn);
	dbus_message_unref(msg); msg = NULL;

	dbus_pending_call_block(pending);
	msg = dbus_pending_call_steal_reply(pending);
	if (msg == NULL) {
		dI("Failed to steal dbus pending call reply.\n");
		goto cleanup;
	}
	dbus_pending_call_unref(pending); pending = NULL;

	if (!dbus_message_iter_init(msg, &args)) {
		dI("Failed to initialize iterator over received dbus message.\n");
		goto cleanup;
	}

	if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_ARRAY && dbus_message_iter_get_element_type(&args) != DBUS_TYPE_DICT_ENTRY) {
		dI("Expected array of dict_entry argument in reply. Instead received: %s.\n", dbus_message_type_to_string(dbus_message_iter_get_arg_type(&args)));
		goto cleanup;
	}

	dbus_message_iter_recurse(&args, &property_iter);
	do {
		DBusMessageIter dict_entry, value_variant;
		dbus_message_iter_recurse(&property_iter, &dict_entry);

		if (dbus_message_iter_get_arg_type(&dict_entry) != DBUS_TYPE_STRING) {
			dI("Expected string as key in dict_entry. Instead received: %s.\n", dbus_message_type_to_string(dbus_message_iter_get_arg_type(&dict_entry)));
			goto cleanup;
		}

		_DBusBasicValue value;
		dbus_message_iter_get_basic(&dict_entry, &value);
		char *property_name = oscap_strdup(value.str);

		if (dbus_message_iter_next(&dict_entry) == false) {
			dW("Expected another field in dict_entry.");
			oscap_free(property_name);
			goto cleanup;
		}

		if (dbus_message_iter_get_arg_type(&dict_entry) != DBUS_TYPE_VARIANT) {
			dI("Expected variant as value in dict_entry. Instead received: %s.\n", dbus_message_type_to_string(dbus_message_iter_get_arg_type(&dict_entry)));
			oscap_free(property_name);
			goto cleanup;
		}

		dbus_message_iter_recurse(&dict_entry, &value_variant);

		int cbret = 0;
		const int arg_type = dbus_message_iter_get_arg_type(&value_variant);
		// DBUS_TYPE_ARRAY is a special case, we report each element as one value entry
		if (arg_type == DBUS_TYPE_ARRAY) {
			DBusMessageIter array;
			dbus_message_iter_recurse(&value_variant, &array);

			do {
				char *element = dbus_value_to_string(&array);
				if (element == NULL)
					continue;

				const int elementcbret = callback(property_name, element, cbarg);
				if (elementcbret > cbret)
					cbret = elementcbret;
//.........这里部分代码省略.........
开发者ID:bushong1,项目名称:openscap,代码行数:101,代码来源:systemdunitproperty.c

示例2: notify


//.........这里部分代码省略.........
        char *hint_name;

        int i;
        int id;
        const char *appname = NULL;
        const char *summary = NULL;
        const char *body = NULL;
        const char *icon = NULL;
        const char *fgcolor = NULL;
        const char *bgcolor = NULL;
        int urgency = 1;
        int progress = -1;
        notification *n = malloc(sizeof(notification));
        dbus_uint32_t replaces_id = 0;
        dbus_int32_t expires = -1;

        dbus_serial++;
        dbus_message_iter_init(dmsg, &args);

        _extract_basic(DBUS_TYPE_STRING, &args, &appname);

        dbus_message_iter_next(&args);
        _extract_basic(DBUS_TYPE_UINT32, &args, &replaces_id);

        dbus_message_iter_next(&args);
        _extract_basic(DBUS_TYPE_STRING, &args, &icon);

        dbus_message_iter_next(&args);
        _extract_basic(DBUS_TYPE_STRING, &args, &summary);

        dbus_message_iter_next(&args);
        _extract_basic(DBUS_TYPE_STRING, &args, &body);

        dbus_message_iter_next(&args);
        dbus_message_iter_next(&args);

        dbus_message_iter_recurse(&args, &hints);
        dbus_message_iter_next(&args);

        _extract_basic(DBUS_TYPE_INT32, &args, &expires);

        while (dbus_message_iter_get_arg_type(&hints) != DBUS_TYPE_INVALID) {
                dbus_message_iter_recurse(&hints, &hint);
                while (dbus_message_iter_get_arg_type(&hint) !=
                       DBUS_TYPE_INVALID) {
                        if (dbus_message_iter_get_arg_type(&hint) !=
                            DBUS_TYPE_STRING) {
                                dbus_message_iter_next(&hint);
                                continue;
                        }
                        dbus_message_iter_get_basic(&hint, &hint_name);
                        _extract_hint(DBUS_TYPE_BYTE, "urgency", hint_name,
                                      &hint, &urgency);
                        _extract_hint(DBUS_TYPE_STRING, "fgcolor", hint_name,
                                      &hint, &fgcolor);
                        _extract_hint(DBUS_TYPE_STRING, "bgcolor", hint_name,
                                      &hint, &bgcolor);
                        _extract_hint(DBUS_TYPE_INT32, "value", hint_name,
                                      &hint, &progress);
                        if (!progress)
                                _extract_hint(DBUS_TYPE_UINT32, "value",
                                              hint_name, &hint, &progress);
                        dbus_message_iter_next(&hint);
                }
                dbus_message_iter_next(&hints);
        }

        if (expires > 0) {
                /* do some rounding */
                expires = (expires + 500) / 1000;
                if (expires < 1) {
                        expires = 1;
                }
        }
        n->appname = appname != NULL ? strdup(appname) : "";
        n->summary = summary != NULL ? strdup(summary) : "";
        n->body = body != NULL ? strdup(body) : "";
        n->icon = icon != NULL ? strdup(icon) : "";
        n->timeout = expires;
        n->progress = (progress < 0 || progress > 100) ? 0 : progress + 1;
        n->urgency = urgency;
        n->dbus_client = strdup(dbus_message_get_sender(dmsg));
        for (i = 0; i < ColLast; i++) {
                n->color_strings[i] = NULL;
        }
        n->color_strings[ColFG] = fgcolor == NULL ? NULL : strdup(fgcolor);
        n->color_strings[ColBG] = bgcolor == NULL ? NULL : strdup(bgcolor);

        id = init_notification(n, replaces_id);
        if (id > 0)
                map_win();

        reply = dbus_message_new_method_return(dmsg);

        dbus_message_iter_init_append(reply, &args);
        dbus_message_iter_append_basic(&args, DBUS_TYPE_UINT32, &id);
        dbus_connection_send(dbus_conn, reply, &dbus_serial);

        dbus_message_unref(reply);
}
开发者ID:losciamano,项目名称:dunst,代码行数:101,代码来源:dunst_dbus.c

示例3: man_portal_sta_get_by_ip

int man_portal_sta_get_by_ip(portal_user_info_s *station, unsigned int *next_addr)
{
	int ret;

	DBusMessage *query, *reply; 
	DBusMessageIter  iter;
	DBusMessageIter  iter_array;
	DBusError err;
	int index = 0;
	char BUSNAME[PATH_LEN];
	char OBJPATH[PATH_LEN];
	char INTERFACE[PATH_LEN];
	char *ch;

	index = 0;
	ReInitDbusPath(index,ASD_DBUS_BUSNAME,BUSNAME);
	ReInitDbusPath(index,ASD_DBUS_SECURITY_OBJPATH,OBJPATH);
	ReInitDbusPath(index,ASD_DBUS_SECURITY_INTERFACE,INTERFACE);
	
	dbus_error_init(&err);
	query = dbus_message_new_method_call(BUSNAME,OBJPATH,INTERFACE,ASD_DBUS_SECURITY_METHOD_GET_PORTAL_STA);
	
	dbus_message_iter_init_append (query, &iter);

	dbus_message_iter_append_basic (	&iter,
										DBUS_TYPE_UINT32,
										&station->ipaddr);
		
	reply = dbus_connection_send_with_reply_and_block (dcli_dbus_connection,query,-1, &err);

	dbus_message_unref(query);
	
	if (NULL == reply) {
		if (dbus_error_is_set(&err)) {
			dbus_error_free(&err);
		}
		return CMD_FAILURE;
	}
	
	dbus_message_iter_init(reply,&iter);
	dbus_message_iter_get_basic(&iter,&ret);
	if(ret != CMD_SUCCESS){
		return ret;
	}

	if(ASD_DBUS_SUCCESS == ret)
	{
		dbus_message_iter_next(&iter);	
		dbus_message_iter_get_basic(&iter,&station->state); 
	
		dbus_message_iter_next(&iter);	
		dbus_message_iter_get_basic(&iter,&ch); 
		memset(station->id, 0, NAME_LEN+1);
		strncpy(station->id, ch, NAME_LEN);

		dbus_message_iter_next(&iter);	
		dbus_message_iter_get_basic(&iter,&(station->ipaddr));	

		dbus_message_iter_next(&iter);	
		dbus_message_iter_get_basic(&iter,&(station->netif_index));	

		dbus_message_iter_next(&iter);	
		dbus_message_iter_get_basic(&iter,next_addr);			
	}
	
	return ret;
}
开发者ID:ECYBTech,项目名称:chanos,代码行数:67,代码来源:man_portal.c

示例4: show_notification

static void show_notification (DB_playItem_t *track) {
    char title[1024];
    char content[1024];

    char format[200];
    char format_content[200];
    deadbeef->conf_get_str ("notify.format", NOTIFY_DEFAULT_TITLE, format, sizeof (format));
    deadbeef->conf_get_str ("notify.format_content", NOTIFY_DEFAULT_CONTENT, format_content, sizeof (format_content));
    deadbeef->pl_format_title (track, -1, title, sizeof (title), -1, format);
    deadbeef->pl_format_title (track, -1, content, sizeof (content), -1, format_content);

    // escape &
//    char esc_title[1024];
    char esc_content[1024];
//    esc_xml (title, esc_title, sizeof (esc_title));
    esc_xml (content, esc_content, sizeof (esc_content));
    DBusMessage *msg = dbus_message_new_method_call (E_NOTIFICATION_BUS_NAME, E_NOTIFICATION_PATH, E_NOTIFICATION_INTERFACE, "Notify");

    deadbeef->pl_lock ();
    if (last_track) {
        deadbeef->pl_item_unref (last_track);
        last_track = 0;
    }
    last_track = track;
    deadbeef->pl_item_ref (last_track);
    request_timer = time (NULL);
    deadbeef->pl_unlock ();

    const char *v_appname = "DeaDBeeF";
    dbus_uint32_t v_id = 0;
    char *v_iconname = NULL;
    if (deadbeef->conf_get_int("notify.albumart", 0) && artwork_plugin) {
        deadbeef->pl_lock ();
        const char *album = deadbeef->pl_find_meta (track, "album");
        const char *artist = deadbeef->pl_find_meta (track, "artist");
        const char *fname = deadbeef->pl_find_meta (track, ":URI");
        if (!album || !*album) {
            album = deadbeef->pl_find_meta (track, "title");
        }
        v_iconname = artwork_plugin->get_album_art (fname, artist, album, deadbeef->conf_get_int ("notify.albumart_size", 64), cover_avail_callback, NULL);
        deadbeef->pl_unlock ();
    }
    if (!v_iconname) {
        v_iconname = strdup ("deadbeef");
    }
    const char *v_summary = title;
    const char *v_body = esc_content;
    dbus_int32_t v_timeout = -1;

    dbus_message_append_args (msg
            , DBUS_TYPE_STRING, &v_appname
            , DBUS_TYPE_UINT32, &replaces_id
            , DBUS_TYPE_STRING, &v_iconname
            , DBUS_TYPE_STRING, &v_summary
            , DBUS_TYPE_STRING, &v_body
            , DBUS_TYPE_INVALID
            );

    DBusMessageIter iter, sub;
    // actions
    dbus_message_iter_init_append(msg, &iter);
    dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "s", &sub);
    dbus_message_iter_close_container(&iter, &sub);
    // hints
    dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sv}", &sub);
    dbus_message_iter_close_container(&iter, &sub);

    dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &v_timeout);

    intptr_t tid = 0;
    if ((tid=deadbeef->thread_start(notify_thread, msg)) != 0) {
        dbus_message_ref (msg);
        deadbeef->thread_detach (tid);  
    }
    dbus_message_unref (msg);
    if (v_iconname) {
        free (v_iconname);
    }
}
开发者ID:fishman,项目名称:deadbeef,代码行数:79,代码来源:notify.c

示例5: ofono_ussd_notify

void ofono_ussd_notify(struct ofono_ussd *ussd, int status, int dcs,
			const unsigned char *data, int data_len)
{
	DBusConnection *conn = ofono_dbus_get_connection();
	const char *ussdstr = "USSD";
	char *utf8_str = NULL;
	const char *str;
	const char sig[] = { DBUS_TYPE_STRING, 0 };
	DBusMessage *reply;
	DBusMessageIter iter;
	DBusMessageIter variant;

	DBG("status: %d %s, state: %d %s",
		status, ussd_status_name(status),
		ussd->state, ussd_state_name(ussd->state));

	if (ussd->req &&
			(status == OFONO_USSD_STATUS_NOTIFY ||
			status == OFONO_USSD_STATUS_TERMINATED ||
			status == OFONO_USSD_STATUS_TIMED_OUT ||
			status == OFONO_USSD_STATUS_NOT_SUPPORTED)) {
		ussd_request_finish(ussd, ussd_status_to_failure_code(status),
					dcs, data, data_len);

		ussd_change_state(ussd, USSD_STATE_IDLE);
		return;
	}

	if (status == OFONO_USSD_STATUS_TERMINATED) {
		ussd_change_state(ussd, USSD_STATE_IDLE);

		if (ussd->pending == NULL)
			return;

		reply = __ofono_error_network_terminated(ussd->pending);
		goto out;
	}

	if (status == OFONO_USSD_STATUS_NOT_SUPPORTED) {
		ussd_change_state(ussd, USSD_STATE_IDLE);

		if (ussd->pending == NULL)
			return;

		reply = __ofono_error_not_supported(ussd->pending);
		goto out;
	}

	if (status == OFONO_USSD_STATUS_TIMED_OUT) {
		ussd_change_state(ussd, USSD_STATE_IDLE);

		if (ussd->pending == NULL)
			return;

		reply = __ofono_error_timed_out(ussd->pending);
		goto out;
	}

	if (data && data_len > 0)
		utf8_str = ussd_decode(dcs, data_len, data);

	str = utf8_str;

	/* TODO: Rework this in the Agent framework */
	if (ussd->state == USSD_STATE_ACTIVE) {

		reply = dbus_message_new_method_return(ussd->pending);

		if (str == NULL)
			str = "";

		dbus_message_iter_init_append(reply, &iter);

		dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING,
						&ussdstr);

		dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, sig,
							&variant);

		dbus_message_iter_append_basic(&variant, DBUS_TYPE_STRING,
						&str);

		dbus_message_iter_close_container(&iter, &variant);

		if (status == OFONO_USSD_STATUS_ACTION_REQUIRED)
			ussd_change_state(ussd, USSD_STATE_USER_ACTION);
		else
			ussd_change_state(ussd, USSD_STATE_IDLE);

	} else if (ussd->state == USSD_STATE_RESPONSE_SENT) {
		reply = dbus_message_new_method_return(ussd->pending);

		if (str == NULL)
			str = "";

		dbus_message_append_args(reply, DBUS_TYPE_STRING, &str,
						DBUS_TYPE_INVALID);

		if (status == OFONO_USSD_STATUS_ACTION_REQUIRED)
			ussd_change_state(ussd, USSD_STATE_USER_ACTION);
//.........这里部分代码省略.........
开发者ID:endocode,项目名称:ofono,代码行数:101,代码来源:ussd.c

示例6: main

int main(int argc, char** args)
{
    DBusMessage* msg;
    DBusMessageIter dmargs;
    DBusPendingCall *pending;
    DBusError err;
    DBusConnection* conn;
    int ret;
    char* param = "Hello";

    /* Init the dbus_error */
    dbus_error_init(&err);

    /* Connect to the bus */
    conn = dbus_bus_get(DBUS_BUS_SESSION, &err);
    if (dbus_error_is_set(&err)) {
        LOGE("Connection error: %s\n", err.message);
        dbus_error_free(&err);
    }
    if (conn == NULL) {
        return -1;
    }

    /* Request a name on the bus */
    ret = dbus_bus_request_name(conn, TEST_DBUS_CLIENT_NAME,
            DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
    if (dbus_error_is_set(&err)) {
        LOGE("Name error: %s\n", err.message);
        dbus_error_free(&err);
    }
    if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
        return -1;
    }

    /* call server */
    msg = dbus_message_new_method_call(TEST_DBUS_SERVER_NAME,
            TEST_DBUS_SERVER_OBJ,
            TEST_METHOD_TYPE,
            TEST_METHOD);

    if (msg == NULL) {
        LOGE("Message null\n");
        return -1;
    }

    dbus_message_iter_init_append(msg, &dmargs);
    if (!dbus_message_iter_append_basic(&dmargs, DBUS_TYPE_STRING, &param)) {
        LOGE("OOM\n");
        return -1;
    }

    if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) {
        LOGE("OOM\n");
        return -1;
    }
    if (pending == NULL) {
        LOGE("Pending call null\n");
        return -1;
    }

    dbus_connection_flush(conn);
    LOGE("Message sent\n");

    dbus_message_unref(msg);

    /* Close the dbus connection */
    dbus_connection_close(conn);
    return 0;
}
开发者ID:chiel99,项目名称:Temp,代码行数:69,代码来源:client.c

示例7: dbus_proc_property

bool dbus_proc_property(const char *method, DBusMessage *msg,
			DBusMessage *reply, DBusError *error,
			struct gsh_dbus_interface **interfaces)
{
	const char *interface;
	const char *prop_name;
	bool retval = false;
	struct gsh_dbus_interface **iface;
	struct gsh_dbus_prop **prop;
	DBusMessageIter reply_iter;

	dbus_message_iter_init_append(reply, &reply_iter);

	if (strcmp(method, "GetAll") == 0) {
		DBusMessageIter getall_dict, dict_entry, val_iter;

		if (!dbus_message_get_args
		    (msg, error, DBUS_TYPE_STRING, &interface,
		     DBUS_TYPE_INVALID))
			goto err_out;
		iface = lookup_interface(interface, interfaces, error);
		if (*iface == NULL)
			goto err_out;
		if (!dbus_message_iter_open_container
		    (&reply_iter, DBUS_TYPE_ARRAY,
		     DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
		     DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
		     DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &getall_dict))
			goto getall_err;
		for (prop = (*iface)->props; prop && *prop; prop++) {
			prop_name = (*prop)->name;
			if ((*prop)->access == DBUS_PROP_READ
			    || (*prop)->access == DBUS_PROP_READWRITE) {
				if (!dbus_message_iter_open_container
				    (&getall_dict, DBUS_TYPE_DICT_ENTRY, NULL,
				     &dict_entry))
					goto getall_err;
				if (!dbus_message_iter_append_basic
				    (&dict_entry, DBUS_TYPE_STRING, &prop_name))
					goto getall_err;
				if (!dbus_message_iter_open_container
				    (&dict_entry, DBUS_TYPE_VARIANT,
				     (*prop)->type, &val_iter))
					goto getall_err;
				if (!(*prop)->get(&val_iter))
					goto getall_err;
				if (!dbus_message_iter_close_container
				    (&dict_entry, &val_iter))
					goto getall_err;
				if (!dbus_message_iter_close_container
				    (&getall_dict, &dict_entry))
					goto getall_err;
			} else {
				dbus_set_error(error,
					       DBUS_ERROR_PROPERTY_READ_ONLY,
					       "%s of %s from %s (write only?)",
					       method, prop_name, interface);
				/** @[email protected] check does write only make sense?? */
				goto err_out;
			}
		}
		if (!dbus_message_iter_close_container
		    (&reply_iter, &getall_dict))
			goto getall_err;

		return true;	/* DONE! */

	} else if (strcmp(method, "Get") == 0) {
		if (!dbus_message_get_args
		    (msg, error, DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING,
		     &prop_name, DBUS_TYPE_INVALID))
			goto err_out;
		iface = lookup_interface(interface, interfaces, error);
		if (*iface == NULL)
			goto err_out;
		prop = lookup_property(prop_name, iface, error);
		if (*prop == NULL)
			goto err_out;
		if ((*prop)->access == DBUS_PROP_READ
		    || (*prop)->access == DBUS_PROP_READWRITE) {
			DBusMessageIter variant_iter;

			if (!dbus_message_iter_open_container
			    (&reply_iter, DBUS_TYPE_VARIANT, (*prop)->type,
			     &variant_iter)) {
				dbus_set_error_const(error, DBUS_ERROR_FAILED,
						     "Couldn't open Get container");
				goto err_out;
			}
			retval = (*prop)->get(&variant_iter);
			if (retval == false ||
			    !dbus_message_iter_close_container(&reply_iter,
							       &variant_iter)) {
				dbus_set_error_const(error, DBUS_ERROR_FAILED,
						     "Couldn't close Get container");
				goto err_out;
			}
		} else {
			dbus_set_error(error, DBUS_ERROR_PROPERTY_READ_ONLY,
				       "%s of %s from %s (write only?)", method,
//.........这里部分代码省略.........
开发者ID:Anuradha-Talur,项目名称:nfs-ganesha,代码行数:101,代码来源:properties_handler.c

示例8: mediaplayer_register

static void mediaplayer_register(const char *id) {
	DBusMessage* msg;
	DBusMessageIter args, element;
	DBusPendingCall* pending;
	char *name=NULL;
	static const char *prop="Identity";
	struct MEDIAPLAYER **mp;
	char player[256];
	
	for(mp=&mediaplayer; *mp; mp=&((*mp)->next)) {
		if(!strcmp(id, (*mp)->id))
			return;
	}
	sprintf(player, "%s.%s", mpris.interface, id);
	if(!(msg=dbus_message_new_method_call(player, mpris.object, dbus.interface_prop, "Get")))
		goto do_register;
	dbus_message_iter_init_append(msg, &args);
	if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &mpris.interface)) {
		dbus_message_unref(msg);
		goto do_register;
	}
	if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &prop)) {
		dbus_message_unref(msg);
		goto do_register;
	}
	if(!dbus_connection_send_with_reply(dbus.session.connection, msg, &pending, -1)) {
		dbus_message_unref(msg);
		goto do_register;
	}
	if(!pending) {
		dbus_message_unref(msg);
		goto do_register;
	}
	dbus_connection_flush(dbus.session.connection);
	dbus_message_unref(msg);
	dbus_pending_call_block(pending);
	if (!(msg=dbus_pending_call_steal_reply(pending))) {
		dbus_pending_call_unref(pending);
		goto do_register;
	}
	dbus_pending_call_unref(pending);
	if(!dbus_message_iter_init(msg, &args)) {
		dbus_message_unref(msg);
		goto do_register;
	} else if(dbus_message_iter_get_arg_type(&args)!=DBUS_TYPE_VARIANT) {
		dbus_message_unref(msg);
		goto do_register;
	}
	
	dbus_message_iter_recurse(&args, &element);
	dbus_message_iter_get_basic(&element, &name);
	dbus_message_unref(msg);
	
	do_register:
	*mp=malloc(sizeof(struct MEDIAPLAYER));
	(*mp)->id=malloc(strlen(id)+1);
	if(name) {
		(*mp)->name=malloc(strlen(name)+1);
		strcpy((void *) (*mp)->name, name);
	} else
		(*mp)->name=NULL;
	(*mp)->next=NULL;
	strcpy((void *) (*mp)->id, id);
}
开发者ID:h4xxel,项目名称:desktop-stuff,代码行数:64,代码来源:indicator-music.c

示例9: unregister_profile_setup

static void unregister_profile_setup(DBusMessageIter *iter, void *user_data)
{
	const char *path = PROFILE_PATH;

	dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
}
开发者ID:Hibati,项目名称:gatt,代码行数:6,代码来源:gatt.c

示例10: append_arg

static void
append_arg (DBusMessageIter *iter, int type, const char *value)
{
  dbus_uint16_t uint16;
  dbus_int16_t int16;
  dbus_uint32_t uint32;
  dbus_int32_t int32;
  dbus_uint64_t uint64;
  dbus_int64_t int64;
  double d;
  unsigned char byte;
  dbus_bool_t v_BOOLEAN;
  
  /* FIXME - we are ignoring OOM returns on all these functions */
  switch (type)
    {
    case DBUS_TYPE_BYTE:
      byte = strtoul (value, NULL, 0);
      dbus_message_iter_append_basic (iter, DBUS_TYPE_BYTE, &byte);
      break;

    case DBUS_TYPE_DOUBLE:
      d = strtod (value, NULL);
      dbus_message_iter_append_basic (iter, DBUS_TYPE_DOUBLE, &d);
      break;

    case DBUS_TYPE_INT16:
      int16 = strtol (value, NULL, 0);
      dbus_message_iter_append_basic (iter, DBUS_TYPE_INT16, &int16);
      break;

    case DBUS_TYPE_UINT16:
      uint16 = strtoul (value, NULL, 0);
      dbus_message_iter_append_basic (iter, DBUS_TYPE_UINT16, &uint16);
      break;

    case DBUS_TYPE_INT32:
      int32 = strtol (value, NULL, 0);
      dbus_message_iter_append_basic (iter, DBUS_TYPE_INT32, &int32);
      break;

    case DBUS_TYPE_UINT32:
      uint32 = strtoul (value, NULL, 0);
      dbus_message_iter_append_basic (iter, DBUS_TYPE_UINT32, &uint32);
      break;

    case DBUS_TYPE_INT64:
      int64 = strtoll (value, NULL, 0);
      dbus_message_iter_append_basic (iter, DBUS_TYPE_INT64, &int64);
      break;

    case DBUS_TYPE_UINT64:
      uint64 = strtoull (value, NULL, 0);
      dbus_message_iter_append_basic (iter, DBUS_TYPE_UINT64, &uint64);
      break;

    case DBUS_TYPE_STRING:
      dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &value);
      break;

    case DBUS_TYPE_OBJECT_PATH:
      dbus_message_iter_append_basic (iter, DBUS_TYPE_OBJECT_PATH, &value);
      break;

    case DBUS_TYPE_BOOLEAN:
      if (strcmp (value, "true") == 0)
	{
	  v_BOOLEAN = TRUE;
	  dbus_message_iter_append_basic (iter, DBUS_TYPE_BOOLEAN, &v_BOOLEAN);
	}
      else if (strcmp (value, "false") == 0)
	{
	  v_BOOLEAN = FALSE;
	  dbus_message_iter_append_basic (iter, DBUS_TYPE_BOOLEAN, &v_BOOLEAN);
	}
      else
	{
	  fprintf (stderr, "%s: Expected \"true\" or \"false\" instead of \"%s\"\n", appname, value);
	  exit (1);
	}
      break;

    default:
      fprintf (stderr, "%s: Unsupported data type %c\n", appname, (char) type);
      exit (1);
    }
}
开发者ID:13824125580,项目名称:hello-world,代码行数:87,代码来源:dbus-send.c

示例11: mediaplayer_get_track

static struct TRACK mediaplayer_get_track(const char *id) {
	int current_type;
	DBusMessage* msg;
	DBusMessageIter args, array, dict, element, var, artist;
	DBusPendingCall* pending;
	static const char *prop="Metadata";
	char player[256];
	struct TRACK track={
		"Unknown",
		"Unknown",
		"Unknown",
	};
	
	sprintf(player, "%s%s", mpris.base, id);
	if(!(msg=dbus_message_new_method_call(player, mpris.object, dbus.interface_prop, "Get")))
		return track;
	dbus_message_iter_init_append(msg, &args);
	if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &mpris.interface_player)) {
		dbus_message_unref(msg);
		return track;
	}
	if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &prop)) {
		dbus_message_unref(msg);
		return track;
	}
	if(!dbus_connection_send_with_reply(dbus.session.connection, msg, &pending, -1)) {
		dbus_message_unref(msg);
		return track;
	}
	if(!pending) {
		dbus_message_unref(msg);
		return track;
	}
	dbus_connection_flush(dbus.session.connection);
	dbus_message_unref(msg);
	dbus_pending_call_block(pending);
	if(!(msg=dbus_pending_call_steal_reply(pending))) {
		dbus_pending_call_unref(pending);
		return track;
	}
	dbus_pending_call_unref(pending);
	if(!dbus_message_iter_init(msg, &args)) {
		dbus_message_unref(msg);
		return track;
	}
	
	if(dbus_message_iter_get_arg_type(&args)!=DBUS_TYPE_VARIANT) {
		dbus_message_unref(msg);
		return track;
	}
	dbus_message_iter_recurse(&args, &array);
	if(dbus_message_iter_get_arg_type(&array)!=DBUS_TYPE_ARRAY) {
		dbus_message_unref(msg);
		return track;
	}
	
	for(dbus_message_iter_recurse(&array, &dict); (current_type=dbus_message_iter_get_arg_type(&dict))!=DBUS_TYPE_INVALID; dbus_message_iter_next(&dict)) {
		char *element_key, *element_value;
		int element_type;
		dbus_message_iter_recurse(&dict, &element);
		if(dbus_message_iter_get_arg_type(&element)!=DBUS_TYPE_STRING)
			continue;
		
		dbus_message_iter_get_basic(&element, &element_key);
		dbus_message_iter_next(&element);
		if(dbus_message_iter_get_arg_type(&element)!=DBUS_TYPE_VARIANT)
			continue;
		
		dbus_message_iter_recurse(&element, &var);
		element_type=dbus_message_iter_get_arg_type(&var);
		if(element_type==DBUS_TYPE_STRING) {
			dbus_message_iter_get_basic(&var, &element_value);
			if(!strcmp(element_key, "xesam:album"))
				snprintf(track.album, TRACK_ELEMENT_LENGTH, "%s", element_value);
			else if(!strcmp(element_key, "xesam:title"))
				snprintf(track.title, TRACK_ELEMENT_LENGTH, "%s", element_value);
		} else if(element_type==DBUS_TYPE_ARRAY) {
			/*just handle one artist for now*/
			dbus_message_iter_recurse(&var, &artist);
			if(dbus_message_iter_get_arg_type(&artist)!=DBUS_TYPE_STRING)
				continue;
			dbus_message_iter_get_basic(&artist, &element_value);
			if(!strcmp(element_key, "xesam:artist"))
				snprintf(track.artist, TRACK_ELEMENT_LENGTH, "%s", element_value);
		}
	}
	dbus_message_unref(msg);
	return track;
}
开发者ID:h4xxel,项目名称:desktop-stuff,代码行数:89,代码来源:indicator-music.c

示例12: g_dbus_proxy_set_property_basic

gboolean g_dbus_proxy_set_property_basic(GDBusProxy *proxy,
				const char *name, int type, const void *value,
				GDBusResultFunction function, void *user_data,
				GDBusDestroyFunction destroy)
{
	struct set_property_data *data;
	GDBusClient *client;
	DBusMessage *msg;
	DBusMessageIter iter, variant;
	DBusPendingCall *call;
	char type_as_str[2];

	if (proxy == NULL || name == NULL || value == NULL)
		return FALSE;

	if (dbus_type_is_basic(type) == FALSE)
		return FALSE;

	client = proxy->client;
	if (client == NULL)
		return FALSE;

	data = g_try_new0(struct set_property_data, 1);
	if (data == NULL)
		return FALSE;

	data->function = function;
	data->user_data = user_data;
	data->destroy = destroy;

	msg = dbus_message_new_method_call(client->service_name,
			proxy->obj_path, DBUS_INTERFACE_PROPERTIES, "Set");
	if (msg == NULL) {
		g_free(data);
		return FALSE;
	}

	type_as_str[0] = (char) type;
	type_as_str[1] = '\0';

	dbus_message_iter_init_append(msg, &iter);
	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING,
							&proxy->interface);
	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &name);

	dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
						type_as_str, &variant);
	dbus_message_iter_append_basic(&variant, type, value);
	dbus_message_iter_close_container(&iter, &variant);

	if (g_dbus_send_message_with_reply(client->dbus_conn, msg,
							&call, -1) == FALSE) {
		dbus_message_unref(msg);
		g_free(data);
		return FALSE;
	}

	dbus_pending_call_set_notify(call, set_property_reply, data, g_free);
	dbus_pending_call_unref(call);

	dbus_message_unref(msg);

	return TRUE;
}
开发者ID:Andrewas,项目名称:android_hardware_semc,代码行数:64,代码来源:client.c

示例13: sedbus_send_avc

/**
 * Listens for signals on the bus
 */
int sedbus_send_avc(DBusConnection* conn, char *avc) {

	DBusMessage* msg;
	DBusMessageIter args;
	DBusPendingCall* pending;
	char* reply = NULL;

	msg = dbus_message_new_method_call(BUSNAME, 
					   PATH, 
					   INTERFACE,
					   "avc"); // method name
	if (NULL == msg) { 
		fprintf(stderr, "Can't communicate with setroubleshootd\n");
		return -1;
	}
	// append arguments
	dbus_message_iter_init_append(msg, &args);
	if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &avc)) { 
		fprintf(stderr, "Out Of Memory!\n"); 
		return -1;
	}

	// send message and get a handle for a reply
	if ( ! dbus_connection_send_with_reply (conn, msg, &pending, -1)) { 
		// -1 is default timeout
		fprintf(stderr, "Out Of Memory!\n"); 
		return -1;
	}
	if (NULL == pending) { 
		fprintf(stderr, "Pending Call Null\n"); 
		return -1;
	}
	dbus_connection_flush(conn);
	
	// free message
	dbus_message_unref(msg);

	// block until we receive a reply
	dbus_pending_call_block(pending);
   
	// get the reply message
	msg = dbus_pending_call_steal_reply(pending);
	if (NULL == msg) {
		fprintf(stderr, "Reply Null\n"); 
		exit(1); 
	}
	// free the pending message handle
	dbus_pending_call_unref(pending);

	// read the parameters
	if (!dbus_message_iter_init(msg, &args))
		fprintf(stderr, "Message has no arguments!\n"); 
	else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) 
		fprintf(stderr, "Argument is not boolean!\n"); 
	else
		dbus_message_iter_get_basic(&args, &reply);

	printf("Send: %s\n", avc);
	printf("Got Reply: %s\n", reply);

	// free reply and close connection
	dbus_message_unref(msg);   

	return 0;
}
开发者ID:OndrejSlamecka,项目名称:setroubleshoot,代码行数:68,代码来源:sedbus.c

示例14: query

/**
 * Call a method on a remote object
 */
void query(char* param) 
{
   DBusMessage* msg;
   DBusMessageIter args;
   DBusConnection* conn;
   DBusError err;
   DBusPendingCall* pending;
   int ret;
   dbus_bool_t stat;
   dbus_uint32_t level;

   printf("Calling remote method with %s\n", param);

   // initialiset the errors
   dbus_error_init(&err);

   // connect to the system bus and check for errors
   conn = dbus_bus_get(DBUS_BUS_SESSION, &err);
   if (dbus_error_is_set(&err)) { 
      fprintf(stderr, "Connection Error (%s)\n", err.message); 
      dbus_error_free(&err);
   }
   if (NULL == conn) { 
      exit(1); 
   }

   // request our name on the bus
   ret = dbus_bus_request_name(conn, "test.method.caller", DBUS_NAME_FLAG_REPLACE_EXISTING , &err);
   if (dbus_error_is_set(&err)) { 
      fprintf(stderr, "Name Error (%s)\n", err.message); 
      dbus_error_free(&err);
   }
   if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) { 
      exit(1);
   }

   // create a new method call and check for errors
   msg = dbus_message_new_method_call("test.method.server", // target for the method call
                                      "/test/method/Object", // object to call on
                                      "test.method.Type", // interface to call on
                                      "Method"); // method name
   if (NULL == msg) { 
      fprintf(stderr, "Message Null\n");
      exit(1);
   }

   // append arguments
   dbus_message_iter_init_append(msg, &args);
   if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &param)) {
      fprintf(stderr, "Out Of Memory!\n"); 
      exit(1);
   }
   
   // send message and get a handle for a reply
   if (!dbus_connection_send_with_reply (conn, msg, &pending, -1)) { // -1 is default timeout
      fprintf(stderr, "Out Of Memory!\n"); 
      exit(1);
   }
   if (NULL == pending) { 
      fprintf(stderr, "Pending Call Null\n"); 
      exit(1); 
   }
   dbus_connection_flush(conn);
   
   printf("Request Sent\n");
   
   // free message
   dbus_message_unref(msg);
   
   // block until we recieve a reply
   dbus_pending_call_block(pending);

   // get the reply message
   msg = dbus_pending_call_steal_reply(pending);
   if (NULL == msg) {
      fprintf(stderr, "Reply Null\n"); 
      exit(1); 
   }
   // free the pending message handle
   dbus_pending_call_unref(pending);

   // read the parameters
   if (!dbus_message_iter_init(msg, &args))
      fprintf(stderr, "Message has no arguments!\n"); 
   else if (DBUS_TYPE_BOOLEAN != dbus_message_iter_get_arg_type(&args)) 
      fprintf(stderr, "Argument is not boolean!\n"); 
   else
      dbus_message_iter_get_basic(&args, &stat);

   if (!dbus_message_iter_next(&args))
      fprintf(stderr, "Message has too few arguments!\n"); 
   else if (DBUS_TYPE_UINT32 != dbus_message_iter_get_arg_type(&args)) 
      fprintf(stderr, "Argument is not int!\n"); 
   else
      dbus_message_iter_get_basic(&args, &level);

   printf("Got Reply: %d, %d\n", stat, level);
//.........这里部分代码省略.........
开发者ID:minghuadev,项目名称:minecraft-tests,代码行数:101,代码来源:dbus-example.c

示例15: EINA_LIST_FOREACH

   EINA_LIST_FOREACH(e_intl_language_list(), l, str)
     {
	DBG("language: %s", str);
	dbus_message_iter_append_basic(&arr, DBUS_TYPE_STRING, &str);
     }
开发者ID:Deepspeed,项目名称:moksha,代码行数:5,代码来源:msgbus_lang.c


注:本文中的dbus_message_iter_append_basic函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。