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


C++ dbus_message_append_args函数代码示例

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


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

示例1: keyzen_dbus_get_pid_of_name

int keyzen_dbus_get_pid_of_name(DBusConnection *connection, const char *name, pid_t *pid)
{
	int result;
	DBusError error;
	DBusMessage *message, *reply;
	dbus_bool_t b;
    dbus_uint32_t u32;

	assert(connection);
	assert(name);
	assert(pid);

	/* look at cache */
	if (read_cache(name, pid))
		return 0;

	/* create the message */
	message = dbus_message_new_method_call(
				DBUS_SERVICE_DBUS, 
				DBUS_PATH_DBUS, 
				DBUS_INTERFACE_DBUS, 
				get_pid_method);

	if (message == NULL) {
		result = -ENOMEM; /* can't create the message */
	} else {
		/* fulfill the message with the name */
		b = dbus_message_append_args(
				message, 
				DBUS_TYPE_STRING, 
				&name, 
				DBUS_TYPE_INVALID);
		if (b != TRUE) {
			result = -ENOMEM; /* can't fullfill the message */
		} else {
			dbus_error_init(&error);
			reply = dbus_connection_send_with_reply_and_block(
							connection, 
							message, 
							timeout, 
							&error);
			if (!reply) {
				result = -ENOTSUP; /* got no reply */
			} else {
				if (dbus_message_get_type(reply)
						!= DBUS_MESSAGE_TYPE_METHOD_RETURN) {
					result = -ENOTSUP; /* unexpected answer kind */
				} else {
					dbus_error_init(&error);
					b = dbus_message_get_args(
								reply, 
								&error, 
								DBUS_TYPE_UINT32, 
								&u32, 
								DBUS_TYPE_INVALID);
					if (b != TRUE) {
						result = -ENOTSUP; /* unexpected argument types */
					} else {
						*pid = (pid_t)u32;
						result = 0;
						add_cache(name, (pid_t)u32);
					}
				}
				dbus_message_unref(reply);
			}
		}
		dbus_message_unref(message);
	}
	return result;
}
开发者ID:jobol,项目名称:keyzen,代码行数:70,代码来源:keyzen-dbus.c

示例2: ccgi_dbus_eag_conf_vlanmaping

int ccgi_dbus_eag_conf_vlanmaping(DBusConnection *conn, dbus_vlan_conf vlan_conf)
{
	DBusMessage *query, *reply;
    DBusError err;
    int ret_vlan = -1;

    query = dbus_message_new_method_call(
                                    EAG_AURO_SERVER,
                                    EAG_AURO_CONF_OBJECT,
						            INTERFACE_AURO_VLANMAPING, 
						            METHOD_VLANMAPING );
	if (NULL == query) {
      fprintf(stderr, "dbus_eag_conf_vlanmaping:dbus_message_new_method_call==Null\n");
    }

    dbus_error_init(&err);

	//fprintf(stderr,"eag_auto_conf v_wlan_begin_id=%d,v_wlan_end_id=%d,v_wtp_begin_id=%u,v_wtp_end_id=%u",\
	//			vlan_conf.v_wlan_begin_id,vlan_conf.v_wlan_end_id,vlan_conf.v_wtp_begin_id,vlan_conf.v_wtp_end_id);
	
	const char * tmp_wlan_begin_id = vlan_conf.v_wlan_begin_id;
	const char * tmp_wlan_end_id = vlan_conf.v_wlan_end_id;
	const char * tmp_wtp_begin_id = vlan_conf.v_wtp_begin_id;
	const char * tmp_wtp_end_id = vlan_conf.v_wtp_end_id;
	const char * nasportid = vlan_conf.nasportid;
	const char * tmp_attz = vlan_conf.v_attz;
	
	dbus_message_append_args(   query,
								DBUS_TYPE_INT32,  &vlan_conf.v_flag,
								DBUS_TYPE_INT32,  &vlan_conf.v_strategy_id,
								DBUS_TYPE_STRING, &tmp_wlan_begin_id,
								DBUS_TYPE_STRING, &tmp_wlan_end_id,
								DBUS_TYPE_STRING, &tmp_wtp_begin_id,
								DBUS_TYPE_STRING, &tmp_wtp_end_id,
								DBUS_TYPE_STRING, &nasportid,
								DBUS_TYPE_STRING, &tmp_attz,
					            DBUS_TYPE_INVALID );
	
    reply = dbus_connection_send_with_reply_and_block ( conn, query, -1, &err );
    dbus_message_unref(query);
    
    if ( NULL == reply )
    {
        if (dbus_error_is_set(&err))
        {
        	//fprintf(stderr, "dbus_message_new_method_call Error:%s\n", err.message);
            dbus_error_free(&err);
        }
        ret_vlan = ERR_DBUS_REPLY_NULL;
    }
    else
    {
        dbus_message_get_args( reply,
                                &err,
                                DBUS_TYPE_INT32, &ret_vlan,
                                DBUS_TYPE_INVALID );
		dbus_message_unref(reply);
    }       
    
	return ret_vlan;
}
开发者ID:inibir,项目名称:daemongroup,代码行数:61,代码来源:ws_eag_auto_conf.c

示例3: create_ac_ip_list_cmd

/*ifname的长度要小于16 */
int create_ac_ip_list_cmd(int instance_id,char *ID,char *ifname)/*返回0表示失败,返回1表示成功,返回-1表示unknown id format*/
																   /*返回-2表示id should be 1 to ACIPLIST_NUM-1,返回-3表示ifname is too long,out of the limit of 16*/
																   /*返回-4表示id exist,返回-5表示error,返回-6表示interface has be binded in other hansi*/
{
	if((NULL == ID)||(NULL == ifname))
		return 0;
	
	int ret,len;
	unsigned char isAdd;	
	unsigned char id;
	char *name;
	DBusMessage *query, *reply;	
	DBusMessageIter	 iter;
	DBusError err;
	isAdd = 1;
	int retu;
	
	ret = parse_char_ID((char*)ID, &id);
	if(ret != WID_DBUS_SUCCESS){
		return -1;
	}	
	if(id >= ACIPLIST_NUM || id == 0){
		return -2;
	}
	len = strlen(ifname);
	if(len > 16){		
		return -3;
	}
	name = (char*)malloc(strlen(ifname)+1);
	if(NULL == name)
		return 0;
	memset(name, 0, strlen(ifname)+1);
	memcpy(name, ifname, strlen(ifname));		
	
	int index;
	char BUSNAME[PATH_LEN];
	char OBJPATH[PATH_LEN];
	char INTERFACE[PATH_LEN];
	/*if(vty->node == CONFIG_NODE){
		index = 0;
	}else if(vty->node == HANSI_NODE){
		index = vty->index;
	}*/
	index = instance_id;
	
	ReInitDbusPath(index,WID_DBUS_BUSNAME,BUSNAME);
	ReInitDbusPath(index,WID_DBUS_ACIPLIST_OBJPATH,OBJPATH);
	ReInitDbusPath(index,WID_DBUS_ACIPLIST_INTERFACE,INTERFACE);
	query = dbus_message_new_method_call(BUSNAME,OBJPATH,INTERFACE,WID_DBUS_ACIPLIST_METHOD_ADD_AC_IP_LIST_GROUP);

/*	query = dbus_message_new_method_call(WID_DBUS_BUSNAME,WID_DBUS_ACIPLIST_OBJPATH,\
						WID_DBUS_ACIPLIST_INTERFACE,WID_DBUS_ACIPLIST_METHOD_ADD_AC_IP_LIST_GROUP);*/
	dbus_error_init(&err);

	dbus_message_append_args(query,
						DBUS_TYPE_BYTE,&id,
						DBUS_TYPE_STRING,&name,
						DBUS_TYPE_INVALID);

	reply = dbus_connection_send_with_reply_and_block (ccgi_dbus_connection,query,-1, &err);
	
	dbus_message_unref(query);
	
	if (NULL == reply) {
		if (dbus_error_is_set(&err)) {
			dbus_error_free(&err);
		}
		if(name)
		{
			free(name);
			name = NULL;
		}
		return 0;
	}
	dbus_message_iter_init(reply,&iter);
	dbus_message_iter_get_basic(&iter,&ret);

	if(ret == 0)
		retu = 1;
	else if(ret == WLAN_ID_BE_USED)
		retu = -4;
	else if(ret == IF_BINDING_FLAG)
		retu = -6;
	else
		retu = -5;

	dbus_message_unref(reply);
	FREE_OBJECT(name);
	return retu;	
}
开发者ID:inibir,项目名称:daemongroup,代码行数:91,代码来源:ws_dcli_ac_ip_list.c

示例4: dbus_bus_get_unix_process_id

static dbus_bool_t dbus_bus_get_unix_process_id(DBusConnection* conn,
                                                const char*     name,
                                                pid_t*          pid)
{
  DBusMessage*  msg;
  DBusMessage*  reply;
  DBusError     err;
  dbus_uint32_t pid_arg;

  msg = dbus_message_new_method_call("org.freedesktop.DBus",
                                     "/org/freedesktop/DBus",
                                     "org.freedesktop.DBus",
                                     "GetConnectionUnixProcessID");
  if (!msg) {
      dsme_log(LOG_DEBUG, "Unable to allocate new message");
      return FALSE;
  }

  if (!dbus_message_append_args(msg,
                                DBUS_TYPE_STRING,
                                &name,
                                DBUS_TYPE_INVALID))
  {
      dsme_log(LOG_DEBUG, "Unable to append arguments to message");
      dbus_message_unref(msg);
      return FALSE;
  }

  // TODO: it is risky that we are blocking
  dbus_error_init(&err);
  reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err);
  if (dbus_error_is_set(&err)) {
      dsme_log(LOG_DEBUG,
               "Sending GetConnectionUnixProcessID failed: %s",
               err.message);
      dbus_error_free(&err);
      dbus_message_unref(msg);
      return FALSE;
  }

  dbus_error_init(&err);
  dbus_message_get_args(reply,
                        &err,
                        DBUS_TYPE_UINT32,
                        &pid_arg,
                        DBUS_TYPE_INVALID);
  if (dbus_error_is_set(&err)) {
      dsme_log(LOG_DEBUG,
               "Getting GetConnectionUnixProcessID args failed: %s",
               err.message);
      dbus_error_free(&err);
      dbus_message_unref(msg);
      dbus_message_unref(reply);
      return FALSE;
  }

  *pid = pid_arg;

  dbus_message_unref(msg);
  dbus_message_unref(reply);

  return TRUE;
}
开发者ID:plundstr,项目名称:dsme,代码行数:63,代码来源:dsme_dbus.c

示例5: nds_filter_function

static DBusHandlerResult
nds_filter_function(DBusConnection *connection, DBusMessage *message,
		void *user_data)
{
	LibHalContext *ctx = user_data;
	DBusMessage *reply;
	DBusError error;
	const char *member = dbus_message_get_member(message);
	const char *path = dbus_message_get_path(message);
	int rc = -1;

	dbus_error_init(&error);

	HAL_DEBUG(("DBus message: %s, %s ", member, path));

	if (dbus_message_is_method_call(message,
				DBUS_INTERFACE, "EnablePrinterScanningViaSNMP")) {
		int interval = -1;
		char *udi = getenv("UDI");
		char *community = "public";
		char *network = "0.0.0.0";

		dbus_message_get_args(message, &error,
				DBUS_TYPE_INT32, &interval,
				DBUS_TYPE_STRING, &community,
				DBUS_TYPE_STRING, &network,
				DBUS_TYPE_INVALID);

		if (strcmp(network, "0.0.0.0") == 0)
			network = NULL;

		rc = nds_EnablePrinterScanningViaSNMP(ctx, udi, interval,
				community, network);
	} else if (dbus_message_is_method_call(message,
				DBUS_INTERFACE, "ScanForPrintersViaSNMP")) {
		int interval = -1;
		char *udi = getenv("UDI");
		char *community = "public";
		char *network = "0.0.0.0";

		dbus_message_get_args(message, &error,
				DBUS_TYPE_STRING, &community,
				DBUS_TYPE_STRING, &network,
				DBUS_TYPE_INVALID);

		if (strcmp(network, "0.0.0.0") == 0)
			network = NULL;

		rc = nds_ScanForPrintersViaSNMP(ctx, udi, community, network);
	} else if (dbus_message_is_method_call(message,
				DBUS_INTERFACE, "DisablePrinterScanningViaSNMP")) {
		rc = nds_DisablePrinterScanningViaSNMP(ctx);
	} else {
		/* bypass not-handled messages */
		HAL_WARNING(("Unknown DBus message: %s, %s ", member, path));
		return (DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
	}

	if (dbus_error_is_set(&error))
		dbus_error_free(&error);

	if ((reply = dbus_message_new_method_return(message)) == NULL) {
		HAL_WARNING(("Could not allocate memory for the DBus reply"));
		return (FALSE);
	}

	dbus_message_append_args(reply, DBUS_TYPE_INT32, &rc,
			DBUS_TYPE_INVALID);

	if (!dbus_connection_send(connection, reply, NULL)) {
		HAL_WARNING(("Could not sent reply"));
	}
	dbus_connection_flush(connection);
	dbus_message_unref(reply);

	return (DBUS_HANDLER_RESULT_HANDLED);
}
开发者ID:AlainODea,项目名称:illumos-gate,代码行数:77,代码来源:addon-network-discovery.c

示例6: force_unmount

static void 
force_unmount (LibHalContext *ctx, const char *udi)
{
	DBusError error;
	DBusMessage *msg = NULL;
	DBusMessage *reply = NULL;
	char **options = NULL;
	unsigned int num_options = 0;
	DBusConnection *dbus_connection;
	char *device_file;

	dbus_connection = libhal_ctx_get_dbus_connection (ctx);

	msg = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
					    "org.freedesktop.Hal.Device.Volume",
					    "Unmount");
	if (msg == NULL) {
		HAL_ERROR (("Could not create dbus message for %s", udi));
		goto out;
	}


	options = calloc (1, sizeof (char *));
	if (options == NULL) {
		HAL_ERROR (("Could not allocate options array"));
		goto out;
	}

	options[0] = "lazy";
	num_options = 1;

	device_file = libhal_device_get_property_string (ctx, udi, "block.device", NULL);
	if (device_file != NULL) {
		HAL_INFO(("forcibly attempting to lazy unmount %s as media was removed", device_file));
		libhal_free_string (device_file);
	}

	if (!dbus_message_append_args (msg, 
				       DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &options, num_options,
				       DBUS_TYPE_INVALID)) {
		HAL_ERROR (("Could not append args to dbus message for %s", udi));
		goto out;
	}
	
	dbus_error_init (&error);
	if (!(reply = dbus_connection_send_with_reply_and_block (dbus_connection, msg, -1, &error))) {
		HAL_ERROR (("Unmount failed for %s: %s : %s\n", udi, error.name, error.message));
		dbus_error_free (&error);
		goto out;
	}

	if (dbus_error_is_set (&error)) {
		HAL_ERROR (("Unmount failed for %s\n%s : %s\n", udi, error.name, error.message));
		dbus_error_free (&error);
		goto out;
	}

	HAL_DEBUG (("Succesfully unmounted udi '%s'", udi));

out:
	if (options != NULL)
		free (options);
	if (msg != NULL)
		dbus_message_unref (msg);
	if (reply != NULL)
		dbus_message_unref (reply);
}
开发者ID:bbidulock,项目名称:hal,代码行数:67,代码来源:addon-storage.c

示例7: check_hello_from_self_reply

static void
check_hello_from_self_reply (DBusPendingCall *pcall, 
                             void *user_data)
{
  DBusMessage *reply;
  DBusMessage *echo_message, *echo_reply = NULL;
  DBusError error;
  DBusConnection *connection;
  
  int type;
  
  dbus_error_init (&error);
 
  connection = dbus_bus_get (DBUS_BUS_STARTER, &error);
  if (connection == NULL)
    {
      fprintf (stderr, "*** Failed to open connection to activating message bus: %s\n",
               error.message);
      dbus_error_free (&error);
      die("no memory");
    }

  
  echo_message = (DBusMessage *)user_data;
    
  reply = dbus_pending_call_steal_reply (pcall);
    
  type = dbus_message_get_type (reply);
    
  if (type == DBUS_MESSAGE_TYPE_METHOD_RETURN)
    {
      const char *s;
      printf ("Reply from HelloFromSelf received\n");
     
      if (!dbus_message_get_args (echo_message,
                              &error,
                              DBUS_TYPE_STRING, &s,
                              DBUS_TYPE_INVALID))
        {
            echo_reply = dbus_message_new_error (echo_message,
                                      error.name,
                                      error.message);

            if (echo_reply == NULL)
              die ("No memory\n");

        } 
      else
        {  
          echo_reply = dbus_message_new_method_return (echo_message);
          if (echo_reply == NULL)
            die ("No memory\n");
  
          if (!dbus_message_append_args (echo_reply,
                                 DBUS_TYPE_STRING, &s,
                                 DBUS_TYPE_INVALID))
            die ("No memory");
        }
        
      if (!dbus_connection_send (connection, echo_reply, NULL))
        die ("No memory\n");
      
      dbus_message_unref (echo_reply);
    }
  else if (type == DBUS_MESSAGE_TYPE_ERROR)
    {
      dbus_set_error_from_message (&error, reply);
      printf ("Error type in reply: %s\n", error.message);

      if (strcmp (error.name, DBUS_ERROR_NO_MEMORY) != 0)
        {
            echo_reply = dbus_message_new_error (echo_reply,
                                      error.name,
                                      error.message);

            if (echo_reply == NULL)
              die ("No memory\n");

            if (!dbus_connection_send (connection, echo_reply, NULL))
              die ("No memory\n");

            dbus_message_unref (echo_reply);
        }
      dbus_error_free (&error);
    }
  else
     _dbus_assert_not_reached ("Unexpected message received\n");

  hello_from_self_reply_received = TRUE;
  
  dbus_message_unref (reply);
  dbus_message_unref (echo_message);
  dbus_pending_call_unref (pcall);
  dbus_connection_unref (connection);
}
开发者ID:psunkari,项目名称:spicebird,代码行数:95,代码来源:test-service.c

示例8: tool_cmd_joiner

int tool_cmd_joiner(int argc, char* argv[])
{
	int ret = 0;
	int c;
	int timeout = DEFAULT_TIMEOUT_IN_SECONDS * 1000;
	DBusConnection* connection = NULL;
	DBusMessage *message = NULL;
	DBusMessage *reply = NULL;
	DBusMessageIter iter;
	DBusMessageIter dict_iter;
	DBusError error;
	const char *empty_string = "";
	const char *psk = NULL;
	const char *provisioning_url = NULL;
	const char *vendor_name = NULL;
	const char *vendor_model = NULL;
	const char *vendor_sw_version = NULL;
	const char *vendor_data = NULL;
	const char *property_joiner_state = kWPANTUNDProperty_ThreadJoinerState;
	dbus_bool_t action = false;

	dbus_error_init(&error);

	if (argc == 1) {
		fprintf(stderr, "%s: error: Missing command.\n", argv[0]);
		print_arg_list_help(joiner_option_list,
				argv[0], joiner_cmd_syntax);
		goto bail;
	}

	while (1) {
		static struct option long_options[] = {
			{"help", no_argument, 0, 'h'},
			{"timeout", required_argument, 0, 't'},
			{"start", no_argument, 0, 'e'},
			{"stop", no_argument, 0, 'd'},
			{"attach", no_argument, 0, 'a'},
			{"state", no_argument, 0, 's'},
			{0, 0, 0, 0}
		};

		int option_index = 0;
		c = getopt_long(argc, argv, "hst:eda", long_options,
						&option_index);
		if (c == -1) {
			break;
		}

		switch (c) {
		case 'h':
			print_arg_list_help(joiner_option_list,
								argv[0], joiner_cmd_syntax);
			ret = ERRORCODE_HELP;
			goto bail;

		case 't':
			//timeout
			timeout = strtol(optarg, NULL, 0);
			break;

		case 's':
			// state
			if (optind < argc) {
				fprintf(stderr,
						"%s: error: Unexpected extra argument: \"%s\"\n",
						argv[0], argv[optind]);
				ret = ERRORCODE_BADARG;
				goto bail;
			}

			connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);

			ret = create_new_wpan_dbus_message(&message, WPANTUND_IF_CMD_PROP_GET);
			require_action(ret == 0, bail, print_error_diagnosis(ret));

			dbus_message_append_args(
				message,
				DBUS_TYPE_STRING, &property_joiner_state,
				DBUS_TYPE_INVALID
			);

			reply = dbus_connection_send_with_reply_and_block(
				connection,
				message,
				timeout,
				&error
			);

			if (!reply) {
				fprintf(stderr, "%s: error: %s\n", argv[0], error.message);
				ret = ERRORCODE_TIMEOUT;
				goto bail;
			}

			dbus_message_iter_init(reply, &iter);

			// Get return code
			dbus_message_iter_get_basic(&iter, &ret);

			if (ret) {
//.........这里部分代码省略.........
开发者ID:abtink,项目名称:wpantund,代码行数:101,代码来源:tool-cmd-joiner.c

示例9: message_handler

DBusHandlerResult message_handler(DBusConnection *connection, 
				  DBusMessage *message, 
				  void *user_data)
{
  char *method = (char *)dbus_message_get_member(message);
  DBusMessage *reply = NULL;
  int clear_cache = 0, new_servers = 0;
    
  if (dbus_message_is_method_call(message, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
    {
      /* string length: "%s" provides space for termination zero */
      if (!introspection_xml && 
	  (introspection_xml = whine_malloc(strlen(introspection_xml_template) + strlen(daemon->dbus_name))))
	sprintf(introspection_xml, introspection_xml_template, daemon->dbus_name);
    
      if (introspection_xml)
	{
	  reply = dbus_message_new_method_return(message);
	  dbus_message_append_args(reply, DBUS_TYPE_STRING, &introspection_xml, DBUS_TYPE_INVALID);
	}
    }
  else if (strcmp(method, "GetVersion") == 0)
    {
      char *v = VERSION;
      reply = dbus_message_new_method_return(message);
      
      dbus_message_append_args(reply, DBUS_TYPE_STRING, &v, DBUS_TYPE_INVALID);
    }
#ifdef HAVE_LOOP
  else if (strcmp(method, "GetLoopServers") == 0)
    {
      reply = dbus_reply_server_loop(message);
    }
#endif
  else if (strcmp(method, "SetServers") == 0)
    {
      dbus_read_servers(message);
      new_servers = 1;
    }
  else if (strcmp(method, "SetServersEx") == 0)
    {
      reply = dbus_read_servers_ex(message, 0);
      new_servers = 1;
    }
  else if (strcmp(method, "SetDomainServers") == 0)
    {
      reply = dbus_read_servers_ex(message, 1);
      new_servers = 1;
    }
  else if (strcmp(method, "SetFilterWin2KOption") == 0)
    {
      reply = dbus_set_bool(message, OPT_FILTER, "filterwin2k");
    }
  else if (strcmp(method, "SetBogusPrivOption") == 0)
    {
      reply = dbus_set_bool(message, OPT_BOGUSPRIV, "bogus-priv");
    }
  else if (strcmp(method, "ClearCache") == 0)
    clear_cache = 1;
  else
    return (DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
   
  if (new_servers)
    {
      my_syslog(LOG_INFO, _("setting upstream servers from DBus"));
      check_servers();
      if (option_bool(OPT_RELOAD))
	clear_cache = 1;
    }

  if (clear_cache)
    clear_cache_and_reload(dnsmasq_time());
  
  method = user_data; /* no warning */

  /* If no reply or no error, return nothing */
  if (!reply)
    reply = dbus_message_new_method_return(message);

  if (reply)
    {
      dbus_connection_send (connection, reply, NULL);
      dbus_message_unref (reply);
    }

  return (DBUS_HANDLER_RESULT_HANDLED);
}
开发者ID:RsrchBoy,项目名称:dpkg-dnsmasq,代码行数:87,代码来源:dbus.c

示例10: major

Device* DeviceHandler::takeDeviceDBus(const std::string& path, int flags)
{
	int fd = 0;
	struct stat st;
    if(stat(path.c_str(), &st) < 0 || !S_ISCHR(st.st_mode))
    {
		ny::sendWarning("DeviceHandler::takeDeviceDBus: failed to get stat struct for path");
        return nullptr;
    }

    unsigned int majr = major(st.st_rdev);
    unsigned int minr = minor(st.st_rdev);

    DBusMessage* msg;
	DBusError error;
	dbus_error_init(&error);
	std::string errStr = "no dbus error available";

    if(!(msg = dbus_message_new_method_call("org.freedesktop.login1", sessionPath().c_str(), 
		"org.freedesktop.login1.Session", "TakeDevice")))
    {
		ny::sendWarning("DeviceHandler::takeDeviceDBus: dbus_message_new_method_call failed");
        dbus_message_unref(msg);
        return nullptr;
    }

    if(!dbus_message_append_args(msg, DBUS_TYPE_UINT32, &majr, DBUS_TYPE_UINT32, &minr, 
		DBUS_TYPE_INVALID))
    {
		ny::sendWarning("DH::takeDeviceDBus: dbus_message_append_args failed");
        dbus_message_unref(msg);
        return nullptr;
    }

    DBusMessage *reply;
    if(!(reply = dbus_connection_send_with_reply_and_block(&dbusHandler()->dbusConnection(), msg, 
		-1, &error)))
    {
		DBusHandler::checkError(error, errStr);
		ny::sendWarning("DH::takeDevDBus: dbus_connection_send_with_reply_and_block: ", errStr);
        dbus_message_unref(msg);
        return nullptr;
    }

    dbus_bool_t paused;
    if(!dbus_message_get_args(reply, nullptr, DBUS_TYPE_UNIX_FD, &fd, DBUS_TYPE_BOOLEAN, 
		&paused, DBUS_TYPE_INVALID))
    {
		ny::sendWarning("DH::takeDeviceDBus: dbus_message_get_args failed");
        dbus_message_unref(reply);
        dbus_message_unref(msg);
        return nullptr;
    }

    int fl;
    if((fl = fcntl(fd, F_GETFL)) < 0 || fcntl(fd, F_SETFD, fl | FD_CLOEXEC) < 0)
    {
		ny::sendWarning("DH::takeDeviceDBus: invalid fd");
        close(fd);
        dbus_message_unref(reply);
        dbus_message_unref(msg);
        return nullptr;
    }

    dbus_message_unref(reply);
    dbus_message_unref(msg);

	auto dev = std::make_unique<Device>();
	dev->fd_ = fd;
	dev->active_ = !paused;
	dev->handler_ = this;
	dev->path_ = path;

	auto* ret = dev.get();
	devices_.push_back(std::move(dev));

	return ret;
}
开发者ID:nyorain,项目名称:iro,代码行数:78,代码来源:devices.cpp

示例11: filter_function

/* DBus filter function */
static DBusHandlerResult
filter_function (DBusConnection *connection, DBusMessage *message, void *userdata)
{
	DBusError err;
	DBusMessage *reply;

	if (!check_priv (halctx, connection, message, dbus_message_get_path (message),
	                 "org.freedesktop.hal.power-management.lcd-panel")) {
		return DBUS_HANDLER_RESULT_HANDLED;
	}

#ifdef DEBUG_OMAP_BL
	dbg ("filter_function: sender=%s destination=%s obj_path=%s interface=%s method=%s",
	     dbus_message_get_sender (message),
	     dbus_message_get_destination (message),
	     dbus_message_get_path (message),
	     dbus_message_get_interface (message),
	     dbus_message_get_member (message));
#endif
	reply = NULL;
	dbus_error_init (&err);

	if (dbus_message_is_method_call (message,
					 "org.freedesktop.Hal.Device.LaptopPanel",
					 "SetBrightness")) {
		int brightness;

		if (dbus_message_get_args (message,
					   &err,
					   DBUS_TYPE_INT32, &brightness,
					   DBUS_TYPE_INVALID)) {
			if (brightness < 0 || brightness > 228) {
				reply = dbus_message_new_error (message,
								"org.freedesktop.Hal.Device.LaptopPanel.Invalid",
								"Brightness has to be between 0 and 228!");
			} else {
				int return_code;

				bl_data.set_backlight_level (&bl_data, brightness);

				reply = dbus_message_new_method_return (message);
				if (reply == NULL)
					goto error;

				return_code = 0;
				dbus_message_append_args (reply,
							  DBUS_TYPE_INT32, &return_code,
							  DBUS_TYPE_INVALID);
			}

			dbus_connection_send (connection, reply, NULL);
		}
	} else if (dbus_message_is_method_call (message,
						"org.freedesktop.Hal.Device.LaptopPanel",
						"GetBrightness")) {
		int brightness;

		if (dbus_message_get_args (message,
					   &err,
					   DBUS_TYPE_INVALID)) {

			brightness = bl_data.get_backlight_level (&bl_data);
			if (brightness < bl_data.bl_min)
				brightness = bl_data.bl_min;
			if (brightness > bl_data.bl_max)
				brightness = bl_data.bl_max;

			/* dbg ("getting brightness, it's %d", brightness); */

			reply = dbus_message_new_method_return (message);
			if (reply == NULL)
				goto error;

			dbus_message_append_args (reply,
						  DBUS_TYPE_INT32, &brightness,
						  DBUS_TYPE_INVALID);
			dbus_connection_send (connection, reply, NULL);
		}
	}

error:
	if (reply != NULL)
		dbus_message_unref (reply);

	LIBHAL_FREE_DBUS_ERROR (&err);

	return DBUS_HANDLER_RESULT_HANDLED;
}
开发者ID:bbidulock,项目名称:hal,代码行数:89,代码来源:addon-omap-backlight.c

示例12: generate_special

static dbus_bool_t
generate_special (DBusMessageDataIter   *iter,
                  DBusString            *data,
                  DBusValidity          *expected_validity)
{
  int item_seq;
  DBusMessage *message;
  int pos;
  dbus_int32_t v_INT32;

  _dbus_assert (_dbus_string_get_length (data) == 0);
  
  message = NULL;
  pos = -1;
  v_INT32 = 42;
  item_seq = iter_get_sequence (iter);

  if (item_seq == 0)
    {
      message = simple_method_call ();
      if (!dbus_message_append_args (message,
                                     DBUS_TYPE_INT32, &v_INT32,
                                     DBUS_TYPE_INT32, &v_INT32,
                                     DBUS_TYPE_INT32, &v_INT32,
                                     DBUS_TYPE_INVALID))
        _dbus_assert_not_reached ("oom");
                                     
      _dbus_header_get_field_raw (&message->header,
                                  DBUS_HEADER_FIELD_SIGNATURE,
                                  NULL, &pos);
      generate_from_message (data, expected_validity, message);
      
      /* set an invalid typecode */
      _dbus_string_set_byte (data, pos + 1, '$');

      *expected_validity = DBUS_INVALID_UNKNOWN_TYPECODE;
    }
  else if (item_seq == 1)
    {
      char long_sig[DBUS_MAXIMUM_TYPE_RECURSION_DEPTH+2];
      const char *v_STRING;
      int i;
      
      message = simple_method_call ();
      if (!dbus_message_append_args (message,
                                     DBUS_TYPE_INT32, &v_INT32,
                                     DBUS_TYPE_INT32, &v_INT32,
                                     DBUS_TYPE_INT32, &v_INT32,
                                     DBUS_TYPE_INVALID))
        _dbus_assert_not_reached ("oom");

      i = 0;
      while (i < (DBUS_MAXIMUM_TYPE_RECURSION_DEPTH + 1))
        {
          long_sig[i] = DBUS_TYPE_ARRAY;
          ++i;
        }
      long_sig[i] = DBUS_TYPE_INVALID;

      v_STRING = long_sig;
      if (!_dbus_header_set_field_basic (&message->header,
                                         DBUS_HEADER_FIELD_SIGNATURE,
                                         DBUS_TYPE_SIGNATURE,
                                         &v_STRING))
        _dbus_assert_not_reached ("oom");
      
      _dbus_header_get_field_raw (&message->header,
                                  DBUS_HEADER_FIELD_SIGNATURE,
                                  NULL, &pos);
      generate_from_message (data, expected_validity, message);
      
      *expected_validity = DBUS_INVALID_EXCEEDED_MAXIMUM_ARRAY_RECURSION;
    }
  else if (item_seq == 2)
    {
      char long_sig[DBUS_MAXIMUM_TYPE_RECURSION_DEPTH*2+4];
      const char *v_STRING;
      int i;
      
      message = simple_method_call ();
      if (!dbus_message_append_args (message,
                                     DBUS_TYPE_INT32, &v_INT32,
                                     DBUS_TYPE_INT32, &v_INT32,
                                     DBUS_TYPE_INT32, &v_INT32,
                                     DBUS_TYPE_INVALID))
        _dbus_assert_not_reached ("oom");

      i = 0;
      while (i <= (DBUS_MAXIMUM_TYPE_RECURSION_DEPTH + 1))
        {
          long_sig[i] = DBUS_STRUCT_BEGIN_CHAR;
          ++i;
        }

      long_sig[i] = DBUS_TYPE_INT32;
      ++i;

      while (i < (DBUS_MAXIMUM_TYPE_RECURSION_DEPTH*2 + 3))
        {
          long_sig[i] = DBUS_STRUCT_END_CHAR;
//.........这里部分代码省略.........
开发者ID:jameshilliard,项目名称:WECB-BH-GPL,代码行数:101,代码来源:dbus-message-factory.c

示例13: start_target

static void start_target(const char *target, bool isolate) {
        DBusMessage *m = NULL, *reply = NULL;
        DBusError error;
        const char *mode, *basic_target = "basic.target";
        DBusConnection *bus = NULL;

        assert(target);

        dbus_error_init(&error);

        if (bus_connect(DBUS_BUS_SYSTEM, &bus, NULL, &error) < 0) {
                log_error("Failed to get D-Bus connection: %s", bus_error_message(&error));
                goto finish;
        }

        if (isolate)
                mode = "isolate";
        else
                mode = "replace";

        log_info("Running request %s/start/%s", target, mode);

        if (!(m = dbus_message_new_method_call("org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartUnitReplace"))) {
                log_error("Could not allocate message.");
                goto finish;
        }

        /* Start these units only if we can replace base.target with it */

        if (!dbus_message_append_args(m,
                                      DBUS_TYPE_STRING, &basic_target,
                                      DBUS_TYPE_STRING, &target,
                                      DBUS_TYPE_STRING, &mode,
                                      DBUS_TYPE_INVALID)) {
                log_error("Could not attach target and flag information to message.");
                goto finish;
        }

        if (!(reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error))) {

                /* Don't print a warning if we aren't called during
                 * startup */
                if (!dbus_error_has_name(&error, BUS_ERROR_NO_SUCH_JOB))
                        log_error("Failed to start unit: %s", bus_error_message(&error));

                goto finish;
        }

finish:
        if (m)
                dbus_message_unref(m);

        if (reply)
                dbus_message_unref(reply);

        if (bus) {
                dbus_connection_flush(bus);
                dbus_connection_close(bus);
                dbus_connection_unref(bus);
        }

        dbus_error_free(&error);
}
开发者ID:adsr,项目名称:systemd,代码行数:63,代码来源:fsck.c

示例14: openConnection

void PulseAudioControl::update()
{
    openConnection();

    if (dbusConnection == NULL) {
        return;
    }

    DBusError error;
    dbus_error_init(&error);

    DBusMessage *reply = NULL;
    DBusMessage *msg = dbus_message_new_method_call(VOLUME_SERVICE, VOLUME_PATH, "org.freedesktop.DBus.Properties", "GetAll");
    if (msg != NULL) {
        dbus_message_append_args(msg, DBUS_TYPE_STRING, &VOLUME_INTERFACE, DBUS_TYPE_INVALID);

        reply = dbus_connection_send_with_reply_and_block(dbusConnection, msg, -1, &error);

        DBUS_ERR_CHECK (error);

        dbus_message_unref(msg);
    }

    int currentStep = -1, stepCount = -1;
    if (reply != NULL) {
        if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN) {
            DBusMessageIter iter;
            dbus_message_iter_init(reply, &iter);
            // Recurse into the array [array of dicts]
            while (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INVALID) {
                DBusMessageIter dict_entry;
                dbus_message_iter_recurse(&iter, &dict_entry);

                // Recurse into the dict [ dict_entry (string, variant(int)) ]
                while (dbus_message_iter_get_arg_type(&dict_entry) != DBUS_TYPE_INVALID) {
                    DBusMessageIter in_dict;
                    // Recurse into the dict_entry [ string, variant(int) ]
                    dbus_message_iter_recurse(&dict_entry, &in_dict);
                    {
                        char *prop_name = NULL;
                        // Get the string value, "property name"
                        dbus_message_iter_get_basic(&in_dict, &prop_name);

                        dbus_message_iter_next(&in_dict);

                        DBusMessageIter variant;
                        // Recurse into the variant [ variant(int) ]
                        dbus_message_iter_recurse(&in_dict, &variant);

                        quint32 value;
                        // Get the variant value which is uint32
                        dbus_message_iter_get_basic(&variant, &value);

                        if (prop_name && strcmp(prop_name, "StepCount") == 0) {
                            stepCount = value;
                        } else if (prop_name && strcmp(prop_name, "CurrentStep") == 0) {
                            currentStep = value;
                        }
                    }

                    dbus_message_iter_next(&dict_entry);
                }
                dbus_message_iter_next(&iter);
            }
        }
        dbus_message_unref(reply);
    }

    if (currentStep != -1 && stepCount != -1) {
        setSteps(currentStep, stepCount);
    }
}
开发者ID:SamuelNevala,项目名称:lipstick,代码行数:72,代码来源:pulseaudiocontrol.cpp

示例15: wpa_supplicant_dbus_notify_state_change

/**
 * wpa_supplicant_dbus_notify_state_change - Send a state change signal
 * @wpa_s: %wpa_supplicant network interface data
 * @new_state: new state wpa_supplicant is entering
 * @old_state: old state wpa_supplicant is leaving
 * Returns: 0 on success, -1 on failure
 *
 * Notify listeners that wpa_supplicant has changed state
 */
void wpa_supplicant_dbus_notify_state_change(struct wpa_supplicant *wpa_s,
					     wpa_states new_state,
					     wpa_states old_state)
{
	struct ctrl_iface_dbus_priv *iface;
	DBusMessage *signal = NULL;
	const char *path;
	const char *new_state_str, *old_state_str;

	/* Do nothing if the control interface is not turned on */
	if (wpa_s->global == NULL)
		return;
	iface = wpa_s->global->dbus_ctrl_iface;
	if (iface == NULL)
		return;

	/* Only send signal if state really changed */
	if (new_state == old_state)
		return;

	path = wpa_supplicant_get_dbus_path(wpa_s);
	if (path == NULL) {
		perror("wpa_supplicant_dbus_notify_state_change[dbus]: "
		       "interface didn't have a dbus path");
		wpa_printf(MSG_ERROR,
		           "wpa_supplicant_dbus_notify_state_change[dbus]: "
		           "interface didn't have a dbus path; can't send "
		           "signal.");
		return;
	}
	signal = dbus_message_new_signal(path, WPAS_DBUS_IFACE_INTERFACE,
					 "StateChange");
	if (signal == NULL) {
		perror("wpa_supplicant_dbus_notify_state_change[dbus]: "
		       "couldn't create dbus signal; likely out of memory");
		wpa_printf(MSG_ERROR,
		           "wpa_supplicant_dbus_notify_state_change[dbus]: "
		           "couldn't create dbus signal; likely out of "
		           "memory.");
		return;
	}

	new_state_str = wpa_supplicant_state_txt(new_state);
	old_state_str = wpa_supplicant_state_txt(old_state);
	if (new_state_str == NULL || old_state_str == NULL) {
		perror("wpa_supplicant_dbus_notify_state_change[dbus]: "
		       "couldn't convert state strings");
		wpa_printf(MSG_ERROR,
		           "wpa_supplicant_dbus_notify_state_change[dbus]: "
		           "couldn't convert state strings.");
		goto out;
	}

	if (!dbus_message_append_args(signal,
	                              DBUS_TYPE_STRING, &new_state_str,
	                              DBUS_TYPE_STRING, &old_state_str,
	                              DBUS_TYPE_INVALID)) {
		perror("wpa_supplicant_dbus_notify_state_change[dbus]: "
		       "not enough memory to construct state change signal.");
		wpa_printf(MSG_ERROR,
		           "wpa_supplicant_dbus_notify_state_change[dbus]: "
		           "not enough memory to construct state change "
		           "signal.");
		goto out;
	}
	dbus_connection_send(iface->con, signal, NULL);

out:
	dbus_message_unref(signal);
}
开发者ID:Katarzynasrom,项目名称:patch-hosting-for-android-x86-support,代码行数:79,代码来源:ctrl_iface_dbus.c


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