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


C++ dbus_message_iter_init_append函数代码示例

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


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

示例1: UE_LOG

bool FCodeLiteSourceCodeAccessor::OpenSourceFiles(const TArray<FString>& AbsoluteSourcePaths)
{
	FString CodeLitePath;
	if(!CanRunCodeLite(CodeLitePath))
	{
		UE_LOG(LogCodeLiteAccessor, Warning, TEXT("FCodeLiteSourceCodeAccessor::OpenSourceFiles: Cannot find CodeLite binary"));
		return false;
	}

#ifdef USE_DBUS	

	for(const auto& SourcePath : AbsoluteSourcePaths)
	{
		
		DBusMessage* message = nullptr;
		DBusMessageIter args;
		
		// Create new message.
		message = dbus_message_new_signal ("/org/codelite/command", "org.codelite.command", "OpenFile");

		char* fileName = TCHAR_TO_ANSI(*SourcePath);

		// Add parameters to the message.
		dbus_message_iter_init_append(message, &args);
		if(!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &fileName)) {
			UE_LOG(LogCodeLiteAccessor, Warning, TEXT("Sdbus_message_iter_append_basic failed."));
			return false;
		}
		
		// Send the message.
		dbus_connection_send(DBusConnection, message, nullptr);
		if(dbus_error_is_set(&DBusError))
		{
			UE_LOG(LogCodeLiteAccessor, Warning, TEXT("dbus_connection_send failed: %s"), DBusError.message);
			return false;
		}

		// Free the message resources.
		dbus_message_unref(message);

	}

	dbus_connection_flush(DBusConnection);

	return true;

#else

	for(const auto& SourcePath : AbsoluteSourcePaths)
	{
		const FString Path = FString::Printf(TEXT("\"%s\""), *SourcePath);

		FProcHandle Proc = FPlatformProcess::CreateProc(*CodeLitePath, *Path, true, false, false, nullptr, 0, nullptr, nullptr);
		if(Proc.IsValid())
		{
			UE_LOG(LogCodeLiteAccessor, Warning, TEXT("CodeLiteSourceCodeAccessor::OpenSourceFiles: %s"), *Path);
			FPlatformProcess::CloseProc(Proc);
			return true;
		}
	}

#endif

	return false;
}
开发者ID:Slasher006,项目名称:CodeLiteSourceCodeAccess,代码行数:65,代码来源:CodeLiteSourceCodeAccessor.cpp

示例2: GalagoNotification_notifyAppendArgs

static dbus_bool_t
GalagoNotification_notifyAppendArgs(
    JNIEnv *env, DBusMessage *message, jstring appName, jlong replacesId,
    jobject icon, jstring summary, jstring body, jint expireTimeout)
{
    DBusMessageIter iter;
    dbus_uint32_t _replacesId;
    DBusMessageIter subIter;
    dbus_int32_t _expireTimeout;

    dbus_message_iter_init_append(message, &iter);

    if (!GalagoNotification_messageAppendString(env, &iter, appName))
        return FALSE;

    _replacesId = replacesId;
    if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT32, &_replacesId))
        return FALSE;

    if (!GalagoNotification_messageAppendString(env, &iter, NULL))
        return FALSE;

    if (!GalagoNotification_messageAppendString(env, &iter, summary))
        return FALSE;

    if (!GalagoNotification_messageAppendString(env, &iter, body))
        return FALSE;

    if (!dbus_message_iter_open_container(
            &iter,
            DBUS_TYPE_ARRAY,
            DBUS_TYPE_STRING_AS_STRING,
            &subIter))
        return FALSE;
    if (!dbus_message_iter_close_container(&iter, &subIter))
        return FALSE;

    if (!dbus_message_iter_open_container(
            &iter,
            DBUS_TYPE_ARRAY,
            "{sv}",
            &subIter))
        return FALSE;
    if (icon)
    {
        Image _icon;

        _icon.jdata = NULL;
        _icon.data = NULL;
        if (GalagoNotification_jobject2Image(env, icon, &_icon))
        {
            dbus_bool_t success;

            success
                = GalagoNotification_messageAppendIconHint(&subIter, &_icon);
            if (_icon.jdata && _icon.data)
                (*env)
                    ->ReleaseIntArrayElements(
                        env,
                        _icon.jdata,
                        _icon.data,
                        JNI_ABORT);
            if (!success)
                return FALSE;
        }
    }
    if (!dbus_message_iter_close_container(&iter, &subIter))
        return FALSE;

    _expireTimeout = expireTimeout;
    if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &_expireTimeout))
        return FALSE;

    return TRUE;
}
开发者ID:Darkeye9,项目名称:jitsi,代码行数:75,代码来源:net_java_sip_communicator_impl_galagonotification_GalagoNotification.c

示例3: wbmd_dbus_interface_show_wbridge_mint_info

DBusMessage * wbmd_dbus_interface_show_wbridge_mint_info(DBusConnection *conn, DBusMessage *msg, void *user_data){
	
	DBusMessage* reply;	
	DBusMessageIter	 iter;
	DBusMessageIter	 iter_array;
	DBusMessageIter iter_sub_array;
	DBusMessageIter iter_sub_struct;
	unsigned int num=0;
	DBusError err;
	int ret = WBMD_DBUS_SUCCESS;
	dbus_error_init(&err);
	int i=0;
	int j = 0;
	int WBID;
	char *name = NULL;
	struct wbridge_info *wb[WBRIDGE_NUM];
	dbus_error_init(&err);
	if (!(dbus_message_get_args ( msg, &err,
								DBUS_TYPE_UINT32,&WBID,
								DBUS_TYPE_INVALID))){

		printf("Unable to get input args\n");
				
		if (dbus_error_is_set(&err)) {
			printf("%s raised: %s",err.name,err.message);
			dbus_error_free(&err);
		}
		return NULL;
	}
	if(WBID == 0){
		while(i<WBRIDGE_NUM){
			if(wBridge[i] != NULL)
			{
				wb[num] = wBridge[i];
				num++;
			}
			i++;
		}
	}else{
		if(wBridge[WBID] != NULL){
			wb[num] = wBridge[WBID];
			num++;
		}
	}
	if(num == 0)
		ret = WBMD_DBUS_ID_NO_EXIST;
	
	reply = dbus_message_new_method_return(msg);
		
	dbus_message_iter_init_append (reply, &iter);
		
	dbus_message_iter_append_basic (&iter,
										 DBUS_TYPE_UINT32,
										 &ret);
	if(ret == WBMD_DBUS_SUCCESS){
		name = (char *)malloc(DEFAULT_LEN);
		memset(name, 0, DEFAULT_LEN);
		dbus_message_iter_append_basic (&iter,
											 DBUS_TYPE_UINT32,
											 &num);
			
		dbus_message_iter_open_container (&iter,
										DBUS_TYPE_ARRAY,
										DBUS_STRUCT_BEGIN_CHAR_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING					
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_ARRAY_AS_STRING
												DBUS_STRUCT_BEGIN_CHAR_AS_STRING
													DBUS_TYPE_BYTE_AS_STRING
													DBUS_TYPE_BYTE_AS_STRING
													DBUS_TYPE_BYTE_AS_STRING
													DBUS_TYPE_BYTE_AS_STRING
													DBUS_TYPE_BYTE_AS_STRING
													DBUS_TYPE_BYTE_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_STRING_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
//.........这里部分代码省略.........
开发者ID:kkcloudy,项目名称:daemongroup,代码行数:101,代码来源:wbmd_dbus.c

示例4: request_input

static int request_input(struct vpn_provider *provider,
			request_cb_t callback, const char *dbus_sender,
			void *user_data)
{
	DBusMessage *message;
	const char *path, *agent_sender, *agent_path;
	DBusMessageIter iter;
	DBusMessageIter dict;
	struct request_input_reply *l2tp_reply;
	int err;
	void *agent;

	agent = connman_agent_get_info(dbus_sender, &agent_sender,
							&agent_path);
	if (!provider || !agent || !agent_path || !callback)
		return -ESRCH;

	message = dbus_message_new_method_call(agent_sender, agent_path,
					VPN_AGENT_INTERFACE,
					"RequestInput");
	if (!message)
		return -ENOMEM;

	dbus_message_iter_init_append(message, &iter);

	path = vpn_provider_get_path(provider);
	dbus_message_iter_append_basic(&iter,
				DBUS_TYPE_OBJECT_PATH, &path);

	connman_dbus_dict_open(&iter, &dict);

	vpn_agent_append_user_info(&dict, provider, "L2TP.User");

	vpn_agent_append_host_and_name(&dict, provider);

	connman_dbus_dict_close(&iter, &dict);

	l2tp_reply = g_try_new0(struct request_input_reply, 1);
	if (!l2tp_reply) {
		dbus_message_unref(message);
		return -ENOMEM;
	}

	l2tp_reply->provider = provider;
	l2tp_reply->callback = callback;
	l2tp_reply->user_data = user_data;

	err = connman_agent_queue_message(provider, message,
			connman_timeout_input_request(),
			request_input_reply, l2tp_reply, agent);
	if (err < 0 && err != -EBUSY) {
		DBG("error %d sending agent request", err);
		dbus_message_unref(message);
		g_free(l2tp_reply);
		return err;
	}

	dbus_message_unref(message);

	return -EINPROGRESS;
}
开发者ID:Drakey83,项目名称:steamlink-sdk,代码行数:61,代码来源:l2tp.c

示例5: libvlc_InternalInit


//.........这里部分代码省略.........

                for( i_input = vlc_optind; i_input < i_argc;i_input++ )
                {
                    /* Skip input options, we can't pass them through D-Bus */
                    if( ppsz_argv[i_input][0] == ':' )
                    {
                        msg_Warn( p_libvlc, "Ignoring option %s",
                                  ppsz_argv[i_input] );
                        continue;
                    }

                    /* We need to resolve relative paths in this instance */
                    char *psz_mrl = make_URI( ppsz_argv[i_input], NULL );
                    const char *psz_after_track = "/";

                    if( psz_mrl == NULL )
                        continue;
                    msg_Dbg( p_libvlc, "Adds %s to the running Media Player",
                             psz_mrl );

                    p_dbus_msg = dbus_message_new_method_call(
                        "org.mpris.MediaPlayer2.vlc", "/org/mpris/MediaPlayer2",
                        "org.mpris.MediaPlayer2.TrackList", "AddTrack" );

                    if ( NULL == p_dbus_msg )
                    {
                        msg_Err( p_libvlc, "D-Bus problem" );
                        free( psz_mrl );
                        system_End( );
                        exit( 1 );
                    }

                    /* append MRLs */
                    dbus_message_iter_init_append( p_dbus_msg, &dbus_args );
                    if ( !dbus_message_iter_append_basic( &dbus_args,
                                DBUS_TYPE_STRING, &psz_mrl ) )
                    {
                        dbus_message_unref( p_dbus_msg );
                        free( psz_mrl );
                        system_End( );
                        exit( 1 );
                    }
                    free( psz_mrl );

                    if( !dbus_message_iter_append_basic( &dbus_args,
                                DBUS_TYPE_OBJECT_PATH, &psz_after_track ) )
                    {
                        dbus_message_unref( p_dbus_msg );
                        system_End( );
                        exit( 1 );
                    }

                    b_play = TRUE;
                    if( var_InheritBool( p_libvlc, "playlist-enqueue" ) )
                        b_play = FALSE;

                    if ( !dbus_message_iter_append_basic( &dbus_args,
                                DBUS_TYPE_BOOLEAN, &b_play ) )
                    {
                        dbus_message_unref( p_dbus_msg );
                        system_End( );
                        exit( 1 );
                    }

                    /* send message and get a handle for a reply */
                    if ( !dbus_connection_send_with_reply ( p_conn,
开发者ID:vlcchina,项目名称:vlc-player-experimental,代码行数:67,代码来源:libvlc.c

示例6: colord_find_device

static char *				/* O - Device path or NULL */
colord_find_device(
    const char *device_id)		/* I - Device ID string */
{
  DBusMessage	*message = NULL;	/* D-Bus request */
  DBusMessage	*reply = NULL;		/* D-Bus reply */
  DBusMessageIter args;			/* D-Bus method arguments */
  DBusError	error;			/* D-Bus error */
  const char	*device_path_tmp;	/* Device object path */
  char		*device_path = NULL;	/* Device object path */


  message = dbus_message_new_method_call(COLORD_DBUS_SERVICE,
                                         COLORD_DBUS_PATH,
                                         COLORD_DBUS_INTERFACE,
                                         "FindDeviceById");

  dbus_message_iter_init_append(message, &args);
  dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &device_id);

 /*
  * Send the FindDeviceById request synchronously...
  */

  dbus_error_init(&error);
  cupsdLogMessage(CUPSD_LOG_DEBUG, "Calling FindDeviceById(%s)", device_id);
  reply = dbus_connection_send_with_reply_and_block(colord_con, message,
                                                    COLORD_DBUS_TIMEOUT,
                                                    &error);
  if (!reply)
  {
    cupsdLogMessage(CUPSD_LOG_DEBUG, "FindDeviceById failed: %s:%s",
		    error.name, error.message);
    dbus_error_free(&error);
    goto out;
  }

 /*
  * Get reply data...
  */

  dbus_message_iter_init(reply, &args);
  if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_OBJECT_PATH)
  {
    cupsdLogMessage(CUPSD_LOG_WARN,
                    "FindDeviceById failed: Incorrect reply type.");
    goto out;
  }

  dbus_message_iter_get_basic(&args, &device_path_tmp);
  if (device_path_tmp)
    device_path = strdup(device_path_tmp);

out:

  if (message)
    dbus_message_unref(message);

  if (reply)
    dbus_message_unref(reply);

  return (device_path);
}
开发者ID:josephgbr,项目名称:cups-pt_BR,代码行数:63,代码来源:colorman.c

示例7: sss_sudo_make_request

int sss_sudo_make_request(struct sudo_result_contents ** sudo_result_out)
{


    char ** command_array,**ui;
    int err_status,count;
    dbus_uint32_t header,command_array_out_size;
    struct sudo_result_contents * sudo_result = NULL;

    DBusConnection* conn;
    DBusError err;

    DBusMessage* dbus_msg;
    DBusMessage* dbus_reply;
    DBusMessageIter msg_iter;

    dbus_bool_t ret = -1;

    fprintf(stdout,"Sending message\n");

    if(validate_message_content() !=  SSS_SUDO_VALIDATION_SUCCESS) {
        return SSS_SUDO_VALIDATION_ERR;
    }


    err_status = create_env_hash_table(msg.user_env,&msg.env_table);
    if(err_status != HASH_SUCCESS) {
        fprintf(stderr, "ccouldn't create table: %s\n", hash_error_string(err_status));
        return SSS_SUDO_MESSAGE_ERR;
    }


    err_status = create_settings_hash_table(&msg.settings_table);
    if(err_status != HASH_SUCCESS) {
        fprintf(stderr, "ccouldn't create table: %s\n", hash_error_string(err_status));
        return SSS_SUDO_MESSAGE_ERR;
    }

    /* initialise the errors */
    dbus_error_init(&err);

    /* connect to the system bus and check for errors */
    conn = dbus_connection_open_private(SSS_SUDO_SERVICE_PIPE, &err);

    if (dbus_error_is_set(&err)) {
        fprintf(stderr, "Connection Error (%s)\n", err.message);
        dbus_error_free(&err);
        return SSS_SUDO_CONNECTION_ERR;
    }
    if (NULL == conn) {
        return SSS_SUDO_CONNECTION_ERR;
    }


    /* create a new method call and check for errors */
    dbus_msg = dbus_message_new_method_call( NULL, 		               /*    target    */
                                             SUDO_SERVER_PATH,        /*    object    */
                                             SUDO_SERVER_INTERFACE,  /*   interface  */
                                             SUDO_METHOD_QUERY);    /*  method name */
    if (NULL == dbus_msg) {
        fprintf(stderr, "Message Null\n");
        free_connection(conn,&err,msg.settings_table,(DBusMessage *)NULL,(DBusMessage *)NULL);
        return SSS_SUDO_MESSAGE_ERR;
    }

    /* append arguments */


    dbus_message_iter_init_append(dbus_msg, &msg_iter);
    if(dbus_error_is_set(&err)){
        fprintf(stderr, "Failed to initialize the iterator.\n");
        free_connection(conn,&err,msg.settings_table,dbus_msg,(DBusMessage *)NULL);
        return SSS_SUDO_MESSAGE_ERR;
    }

    ret = frame_sudo_message(conn,
                             &err,
                             dbus_msg,
                             &msg,
                             &msg_iter);
    if( ret != SSS_SUDO_MESSAGE_OK){
        sudo_log(SUDO_CONV_ERROR_MSG,"Failed to frame the message to sssd -  Fatal (Access denied)\n");
        free_connection(conn,&err,(hash_table_t *)NULL,dbus_msg,(DBusMessage *)NULL);
        return SSS_SUDO_MESSAGE_ERR;
    }

    /* send message and get a handle for a reply */
    dbus_reply = dbus_connection_send_with_reply_and_block (conn,dbus_msg,
                                                            SUDO_CLIENT_TIMEOUT,
                                                            &err);
    fprintf(stdout,"Request Sent\n");
    if (dbus_error_is_set(&err)) {
        fprintf(stderr, "Connection send-reply Error (%s)\n", err.message);
        free_connection(conn,&err,(hash_table_t *)NULL,dbus_msg,(DBusMessage *)NULL);
        return SSS_SUDO_REPLY_ERR;
    }
    if (NULL == dbus_reply) {
        fprintf(stderr, "reply failed\n");
        free_connection(conn,&err,(hash_table_t *)NULL,dbus_msg,(DBusMessage *)NULL);
        return SSS_SUDO_REPLY_ERR;
//.........这里部分代码省略.........
开发者ID:scaria,项目名称:sssd,代码行数:101,代码来源:sss_sudoplugin.c

示例8: dbus_client_query_end_session

static gboolean
dbus_client_query_end_session (GsmClient                *client,
                               GsmClientEndSessionFlag   flags,
                               GError                  **error)
{
        GsmDBusClient  *dbus_client = (GsmDBusClient *) client;
        DBusMessage    *message;
        DBusMessageIter iter;
        gboolean        ret;

        ret = FALSE;

        if (dbus_client->priv->bus_name == NULL) {
                g_set_error (error,
                             GSM_CLIENT_ERROR,
                             GSM_CLIENT_ERROR_NOT_REGISTERED,
                             "Client is not registered");
                return FALSE;
        }

        g_debug ("GsmDBusClient: sending QueryEndSession signal to %s", dbus_client->priv->bus_name);

        /* unicast the signal to only the registered bus name */
        message = dbus_message_new_signal (gsm_client_peek_id (client),
                                           SM_DBUS_CLIENT_PRIVATE_INTERFACE,
                                           "QueryEndSession");
        if (message == NULL) {
                g_set_error (error,
                             GSM_CLIENT_ERROR,
                             GSM_CLIENT_ERROR_NOT_REGISTERED,
                             "Unable to send QueryEndSession message");
                goto out;
        }
        if (!dbus_message_set_destination (message, dbus_client->priv->bus_name)) {
                g_set_error (error,
                             GSM_CLIENT_ERROR,
                             GSM_CLIENT_ERROR_NOT_REGISTERED,
                             "Unable to send QueryEndSession message");
                goto out;
        }

        dbus_message_iter_init_append (message, &iter);
        dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &flags);

        if (!dbus_connection_send (dbus_client->priv->connection, message, NULL)) {
                g_set_error (error,
                             GSM_CLIENT_ERROR,
                             GSM_CLIENT_ERROR_NOT_REGISTERED,
                             "Unable to send QueryEndSession message");
                goto out;
        }

        ret = TRUE;

 out:
        if (message != NULL) {
                dbus_message_unref (message);
        }

        return ret;
}
开发者ID:tapiralec,项目名称:gnome-session,代码行数:61,代码来源:gsm-dbus-client.c

示例9: c_call

//! CSL method: call(app, model, method, (arg0, arg1, ...))
static PyObject *
c_call(PyObject *self, PyObject *args)
{
    /*!
     * This method can be used in CSL scripts to call Comar methods
     * internally.
     *
     * @return Called method's reply
     */

    PyObject *ret, *tuple = NULL;
    char *app, *model, *method, *interface, *path;
    int size, i;

    if (!PyArg_ParseTuple(args, "sss|O", &app, &model, &method, &tuple))
        return NULL;


    if (!tuple) {
        tuple = PyTuple_New(0);
    }

    DBusConnection *conn;
    DBusError err;
    DBusMessage *msg, *reply;
    DBusMessageIter iter;

    dbus_error_init(&err);
    conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
    if (dbus_error_is_set(&err)) {
        PyErr_SetString(PyExc_Exception, "Unable to open connection for call() method.");
        dbus_error_free(&err);
        return NULL;
    }

    size = strlen(cfg_bus_interface) + 1 + strlen(model) + 1;
    interface = malloc(size);
    snprintf(interface, size, "%s.%s", cfg_bus_interface, model);
    interface[size - 1] = '\0';

    size = strlen("/package/") + strlen(app) + 1;
    path = malloc(size);
    snprintf(path, size, "/package/%s", app);
    path[size - 1] = '\0';

    msg = dbus_message_new_method_call(cfg_bus_name, path, interface, method);
    free(interface);
    free(path);

    dbus_message_iter_init_append(msg, &iter);

    if (PyTuple_Check(tuple)) {
        if (PyTuple_Size(tuple) > 0) {
            for (i = 0; i < PyTuple_Size(tuple); i++) {
                if (dbus_py_export(&iter, PyTuple_GetItem(tuple, i)) != 0) {
                    return NULL;
                }
            }
        }
    }
    else {
        if (dbus_py_export(&iter, tuple) != 0) {
            return NULL;
        }
    }

    reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err);
    dbus_message_unref(msg);
    dbus_connection_close(conn);
    dbus_connection_unref(conn);
    if (dbus_error_is_set(&err)) {
        PyErr_Format(PyExc_Exception, "Unable to call method: %s", err.message);
        dbus_error_free(&err);
        return NULL;
    }

    switch (dbus_message_get_type(reply)) {
        case DBUS_MESSAGE_TYPE_METHOD_RETURN:
            ret = PyList_AsTuple(dbus_py_import(reply));
            if (PyTuple_Size(ret) == 1) {
                ret = PyTuple_GetItem(ret, 0);
            }
            dbus_message_unref(reply);
            return ret;
        case DBUS_MESSAGE_TYPE_ERROR:
            PyErr_SetString(PyExc_Exception, dbus_message_get_error_name(reply));
            dbus_message_unref(reply);
            return NULL;
    }

    Py_INCREF(Py_None);
    return Py_None;
}
开发者ID:Tayyib,项目名称:uludag,代码行数:94,代码来源:csl.c

示例10: broadcast_and_wait_response

void broadcast_and_wait_response(char* server_name) {
	DBusMessage* msg;
	DBusMessageIter args;
	DBusConnection* conn;
	DBusError err;
	DBusPendingCall* pending;
	int ret;
	char *stat;
	dbus_uint32_t level;

//	printf("broadcast_and_wait_response-----Calling remote method\n");
	// initialiset the errors

	dbus_error_init(&err);

	// connect to the system bus and check for errors
	conn = dbus_bus_get(DBUS_BUS_SYSTEM, &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);
	}

	char name_[50];
	sprintf(name_,"test.method.%s",server_name);
	// create a new method call and check for errors
	msg = dbus_message_new_method_call(name_, // 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);
	}

	char *param = "hello hanmeimei..";
	// 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);

	// free message
	dbus_message_unref(msg);

//	printf("broadcast_and_wait_response-----...............wait........\n");

	// block until we recieve a reply
	dbus_pending_call_block(pending);

//	printf("broadcast_and_wait_response-----now reply........come in..\n");

	// 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);

	stat = (char*)malloc(128);
	// 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 string!\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);
//.........这里部分代码省略.........
开发者ID:zekezang,项目名称:mantis-application,代码行数:101,代码来源:loop-syn.c

示例11: VIR_MOCK_IMPL_RET_ARGS

VIR_MOCK_IMPL_RET_ARGS(dbus_connection_send_with_reply_and_block,
                       DBusMessage *,
                       DBusConnection *, connection,
                       DBusMessage *, message,
                       int, timeout_milliseconds,
                       DBusError *, error)
{
    DBusMessage *reply = NULL;
    const char *service = dbus_message_get_destination(message);
    const char *member = dbus_message_get_member(message);

    VIR_MOCK_IMPL_INIT_REAL(dbus_connection_send_with_reply_and_block);

    if (STREQ(service, "org.freedesktop.machine1")) {
        if (getenv("FAIL_BAD_SERVICE")) {
            dbus_set_error_const(error,
                                 "org.freedesktop.systemd.badthing",
                                 "Something went wrong creating the machine");
        } else {
            reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
        }
    } else if (STREQ(service, "org.freedesktop.login1")) {
        char *supported = getenv("RESULT_SUPPORT");
        DBusMessageIter iter;
        reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
        dbus_message_iter_init_append(reply, &iter);

        if (!dbus_message_iter_append_basic(&iter,
                                            DBUS_TYPE_STRING,
                                            &supported))
            goto error;
    } else if (STREQ(service, "org.freedesktop.DBus") &&
               STREQ(member, "ListActivatableNames")) {
        const char *svc1 = "org.foo.bar.wizz";
        const char *svc2 = "org.freedesktop.machine1";
        const char *svc3 = "org.freedesktop.login1";
        DBusMessageIter iter;
        DBusMessageIter sub;
        reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
        dbus_message_iter_init_append(reply, &iter);
        dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
                                         "s", &sub);

        if (!dbus_message_iter_append_basic(&sub,
                                            DBUS_TYPE_STRING,
                                            &svc1))
            goto error;
        if (!getenv("FAIL_NO_SERVICE") &&
            !dbus_message_iter_append_basic(&sub,
                                            DBUS_TYPE_STRING,
                                            &svc2))
            goto error;
        if (!getenv("FAIL_NO_SERVICE") &&
            !dbus_message_iter_append_basic(&sub,
                                            DBUS_TYPE_STRING,
                                            &svc3))
            goto error;
        dbus_message_iter_close_container(&iter, &sub);
    } else if (STREQ(service, "org.freedesktop.DBus") &&
               STREQ(member, "ListNames")) {
        const char *svc1 = "org.foo.bar.wizz";
        const char *svc2 = "org.freedesktop.systemd1";
        const char *svc3 = "org.freedesktop.login1";
        DBusMessageIter iter;
        DBusMessageIter sub;
        reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
        dbus_message_iter_init_append(reply, &iter);
        dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
                                         "s", &sub);

        if (!dbus_message_iter_append_basic(&sub,
                                            DBUS_TYPE_STRING,
                                            &svc1))
            goto error;
        if ((!getenv("FAIL_NO_SERVICE") && !getenv("FAIL_NOT_REGISTERED")) &&
            !dbus_message_iter_append_basic(&sub,
                                            DBUS_TYPE_STRING,
                                            &svc2))
            goto error;
        if ((!getenv("FAIL_NO_SERVICE") && !getenv("FAIL_NOT_REGISTERED")) &&
            !dbus_message_iter_append_basic(&sub,
                                            DBUS_TYPE_STRING,
                                            &svc3))
            goto error;
        dbus_message_iter_close_container(&iter, &sub);
    } else {
        reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
    }

    return reply;

 error:
    dbus_message_unref(reply);
    return NULL;
}
开发者ID:Thingee,项目名称:libvirt,代码行数:95,代码来源:virsystemdtest.c

示例12: upstart_job_exec

gboolean
upstart_job_exec(svc_action_t * op, gboolean synchronous)
{
    char *job = NULL;
    int arg_wait = TRUE;
    const char *arg_env = "pacemaker=1";
    const char *action = op->action;

    DBusError error;
    DBusMessage *msg = NULL;
    DBusMessage *reply = NULL;
    DBusMessageIter iter, array_iter;

    op->rc = PCMK_OCF_UNKNOWN_ERROR;
    CRM_ASSERT(upstart_init());

    if (safe_str_eq(op->action, "meta-data")) {
        op->stdout_data = upstart_job_metadata(op->agent);
        op->rc = PCMK_OCF_OK;
        goto cleanup;
    }

    if(!upstart_job_by_name(op->agent, &job, op->timeout)) {
        crm_debug("Could not obtain job named '%s' to %s", op->agent, action);
        if (!g_strcmp0(action, "stop")) {
            op->rc = PCMK_OCF_OK;

        } else {
            op->rc = PCMK_OCF_NOT_INSTALLED;
            op->status = PCMK_LRM_OP_NOT_INSTALLED;
        }
        goto cleanup;
    }

    if (safe_str_eq(op->action, "monitor") || safe_str_eq(action, "status")) {

        char *path = get_first_instance(job, op->timeout);

        op->rc = PCMK_OCF_NOT_RUNNING;
        if(path) {
            DBusPendingCall *pending = NULL;
            char *state = pcmk_dbus_get_property(
                upstart_proxy, BUS_NAME, path, UPSTART_06_API ".Instance", "state",
                op->synchronous?NULL:upstart_job_check, op,
                op->synchronous?NULL:&pending, op->timeout);

            free(job);
            free(path);

            if(op->synchronous) {
                upstart_job_check("state", state, op);
                free(state);
                return op->rc == PCMK_OCF_OK;
            } else if (pending) {
                services_set_op_pending(op, pending);
                return TRUE;
            }
            return FALSE;
        }
        goto cleanup;

    } else if (!g_strcmp0(action, "start")) {
        action = "Start";
    } else if (!g_strcmp0(action, "stop")) {
        action = "Stop";
    } else if (!g_strcmp0(action, "restart")) {
        action = "Restart";
    } else {
        op->rc = PCMK_OCF_UNIMPLEMENT_FEATURE;
        goto cleanup;
    }

    crm_debug("Calling %s for %s on %s", action, op->rsc, job);

    msg = dbus_message_new_method_call(BUS_NAME, // target for the method call
                                       job, // object to call on
                                       UPSTART_JOB_IFACE, // interface to call on
                                       action); // method name
    CRM_ASSERT(msg != NULL);

    dbus_message_iter_init_append (msg, &iter);

    CRM_LOG_ASSERT(dbus_message_iter_open_container (&iter,
                                                     DBUS_TYPE_ARRAY,
                                                     DBUS_TYPE_STRING_AS_STRING,
                                                     &array_iter));

    CRM_LOG_ASSERT(dbus_message_iter_append_basic (&array_iter, DBUS_TYPE_STRING, &arg_env));
    CRM_LOG_ASSERT(dbus_message_iter_close_container (&iter, &array_iter));

    CRM_LOG_ASSERT(dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &arg_wait, DBUS_TYPE_INVALID));

    if (op->synchronous == FALSE) {
        DBusPendingCall* pending = pcmk_dbus_send(msg, upstart_proxy, upstart_async_dispatch, op, op->timeout);
        free(job);

        if(pending) {
            services_set_op_pending(op, pending);
            return TRUE;
        }
//.........这里部分代码省略.........
开发者ID:tradej,项目名称:pacemaker,代码行数:101,代码来源:upstart.c

示例13: umask

bool CHALManager::Mount(CStorageDevice *volume, CStdString mountpath)
{
  CLog::Log(LOGNOTICE, "HAL: Mounting %s (%s) at %s with umask=%u", volume->UDI.c_str(), volume->toString().c_str(), mountpath.c_str(), umask (0));
  DBusMessage* msg;
  DBusMessageIter args;
  DBusError error;
  dbus_error_init (&error);
  DBusConnection *connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
  const char *s;
  if (connection)
  {
    msg = dbus_message_new_method_call("org.freedesktop.Hal", volume->UDI.c_str(), "org.freedesktop.Hal.Device.Volume", "Mount");
    dbus_message_iter_init_append(msg, &args);
    s = mountpath.c_str();
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &s))
      CLog::Log(LOGERROR, "DBus: Failed to append arguments");
    s = ""; //FileSystem
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &s))
      CLog::Log(LOGERROR, "DBus: Failed to append arguments");
    DBusMessageIter sub;
    dbus_message_iter_open_container(&args, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &sub);

    CStdString temporaryString;

    if (volume->FileSystem.Equals("vfat"))
    {
      int mask = umask (0);
      temporaryString.Format("umask=%#o", mask);
      s = temporaryString.c_str();
      dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &s);
      temporaryString.Format("uid=%u", getuid());
      s = temporaryString.c_str();
      dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &s);
      s = "shortname=mixed";
      dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &s);
      s = "utf8";
      dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &s);
      // 'sync' option will slow down transfer speed significantly for FAT filesystems. We prefer 'flush' instead.
      s = "flush";
      dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &s);
    }
    else
    {
      s = "sync";
      dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &s);
    }

    dbus_message_iter_close_container(&args, &sub);

    if (msg == NULL)
        CLog::Log(LOGERROR, "DBus: Create Mount Message failed");
    else
    {
      DBusMessage *reply;
      reply = dbus_connection_send_with_reply_and_block(connection, msg, -1, &error); //The reply timout might be bad to have as -1
      if (dbus_error_is_set(&error))
      {
        CLog::Log(LOGERROR, "DBus: %s - %s", error.name, error.message);
        dbus_error_free(&error);
        return false;
      }
      // Need to create a reader for the Message
      dbus_message_unref (reply);
      dbus_message_unref(msg);
      msg = NULL;
    }

    volume->Mounted = true;
    volume->MountedByXBMC = true;
    volume->MountPoint = mountpath;
    dbus_connection_unref(connection);
    connection = NULL;
    return true;
  }
  else
  {
    CLog::Log(LOGERROR, "DBus: Failed to connect to Systembus");
    dbus_error_free(&error);
    return false;
  }
}
开发者ID:Ayu222,项目名称:android,代码行数:81,代码来源:HALManager.cpp

示例14: create_health_application

/**
 * Creates the HealthApplication's by calling BlueZ
 *
 * @param is_sink TRUE if data type is Sink role
 * @param data_type Specialization or data type 
 */
gboolean create_health_application(gboolean is_sink, guint16 data_type)
{
	/* Create HealthApplication */

	// Need to use non-GLib code here because GLib still does not have
	// the G_TYPE_UINT16 type.

	DBusMessage *msg, *reply;
	DBusError err;
	DBusMessageIter iter, array, entry, variant;
	guint16 value;
	const char *svalue;
	const char *key;
	char *app_path;
	app_object *app;

	msg = dbus_message_new_method_call("org.bluez", "/org/bluez",
					   "org.bluez.HealthManager", "CreateApplication");

	if (!msg) {
		DEBUG(" network:dbus Can't allocate new method call");
		return FALSE;
	}

	dbus_message_iter_init_append(msg, &iter);
	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sv}", &array);

	key = "DataType";
	value = data_type;
	dbus_message_iter_open_container(&array, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
	dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
	dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, "q", &variant);
	dbus_message_iter_append_basic(&variant, DBUS_TYPE_UINT16, &value);
	dbus_message_iter_close_container(&entry, &variant);
	dbus_message_iter_close_container(&array, &entry);

	key = "Role";
	svalue = (is_sink ? "Sink" : "Source");
	dbus_message_iter_open_container(&array, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
	dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
	dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, "s", &variant);
	dbus_message_iter_append_basic(&variant, DBUS_TYPE_STRING, &svalue);
	dbus_message_iter_close_container(&entry, &variant);
	dbus_message_iter_close_container(&array, &entry);

	key = "Description";
	svalue = "healthd";
	dbus_message_iter_open_container(&array, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
	dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
	dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, "s", &variant);
	dbus_message_iter_append_basic(&variant, DBUS_TYPE_STRING, &svalue);
	dbus_message_iter_close_container(&entry, &variant);
	dbus_message_iter_close_container(&array, &entry);

	dbus_message_iter_close_container(&iter, &array);

	dbus_error_init(&err);

	reply = dbus_connection_send_with_reply_and_block(
			dbus_g_connection_get_connection(conn),
			msg, -1, &err);

	dbus_message_unref(msg);

	if (!reply) {
		DEBUG(" network:dbus Can't create application");

		if (dbus_error_is_set(&err)) {
			ERROR("%s", err.message);
			dbus_error_free(&err);
		}

		return FALSE;
	}

	if (!dbus_message_get_args(reply, &err,
				   DBUS_TYPE_OBJECT_PATH, &app_path,
				   DBUS_TYPE_INVALID)) {
		DEBUG(" network:dbus Can't get reply arguments");

		if (dbus_error_is_set(&err)) {
			ERROR("%s", err.message);
			dbus_error_free(&err);
		}

		return FALSE;
	}

	app = g_new0(app_object, 1);
	app->path = g_strdup(app_path);
	app->data_type = data_type;
	app->is_sink = is_sink;

	llist_add(apps(), app);
//.........这里部分代码省略.........
开发者ID:DBattisti,项目名称:antidote,代码行数:101,代码来源:plugin_bluez.c

示例15: gconf_database_dbus_notify_listeners

void
gconf_database_dbus_notify_listeners (GConfDatabase    *db,
				      GConfSources     *modified_sources,
				      const gchar      *key,
				      const GConfValue *value,
				      gboolean          is_default,
				      gboolean          is_writable,
				      gboolean          notify_others)
{
  char             *dir, *sep;
  GList            *l;
  NotificationData *notification;
  DBusMessage      *message;
  gboolean          last;
  
  dir = g_strdup (key);

  /* Lookup the key in the namespace hierarchy, start with the full key and then
   * remove the leaf, lookup again, remove the leaf, and so on until a match is
   * found. Notify the clients (identified by their base service) that
   * correspond to the found namespace.
   */
  last = FALSE;
  while (1)
    {
      notification = g_hash_table_lookup (db->notifications, dir);

      if (notification)
	{
	  for (l = notification->clients; l; l = l->next)
	    {
	      const char *base_service = l->data;
	      DBusMessageIter iter;
	      
	      message = dbus_message_new_method_call (base_service,
						      GCONF_DBUS_CLIENT_OBJECT,
						      GCONF_DBUS_CLIENT_INTERFACE,
						      "Notify");

	      dbus_message_append_args (message,
					DBUS_TYPE_STRING, &db->object_path,
					DBUS_TYPE_STRING, &dir,
					DBUS_TYPE_INVALID);

	      dbus_message_iter_init_append (message, &iter);
	      
	      gconf_dbus_utils_append_entry_values (&iter,
						    key,
						    value,
						    is_default,
						    is_writable,
						    NULL);
	      
	      dbus_message_set_no_reply (message, TRUE);
	      
	      dbus_connection_send (gconfd_dbus_get_connection (), message, NULL);
	      dbus_message_unref (message);
	    }
	}

      if (last)
	break;
      
      sep = strrchr (dir, '/');

      /* Special case to catch notifications on the root. */
      if (sep == dir)
	{
	  last = TRUE;
	  sep[1] = '\0';
	}
      else
	*sep = '\0';
    }

    
  g_free (dir);

  if (modified_sources)
    {
      if (notify_others)
        gconfd_notify_other_listeners (db, modified_sources, key);

      g_list_free (modified_sources->sources);
      g_free (modified_sources);
    }
}
开发者ID:SpOlErOk38,项目名称:gconf-dbus,代码行数:87,代码来源:gconf-database-dbus.c


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