• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ dbus_error_free函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: _dbus_server_test

EXPORT_C
dbus_bool_t
_dbus_server_test (void)
{
  const char *valid_addresses[] = {
    "tcp:port=1234",
   // #ifndef __SYMBIAN32__
    "unix:path=./boogie",
 //   #endif
    "tcp:host=localhost,port=1234",
    "tcp:host=localhost,port=1234;tcp:port=5678",
    "tcp:port=1234;unix:path=./boogie",
  };

  DBusServer *server;
  int i;
  
  for (i = 0; i < _DBUS_N_ELEMENTS (valid_addresses); i++)
    {
      DBusError error;

      /* FIXME um, how are the two tests here different? */
      
      dbus_error_init (&error);
      server = dbus_server_listen (valid_addresses[i], &error);
      if (server == NULL)
        {
          _dbus_warn ("server listen error: %s: %s\n", error.name, error.message);
          dbus_error_free (&error);
          _dbus_assert_not_reached ("Failed to listen for valid address.");
        }
	 #ifdef __SYMBIAN32__	
	  if(server!=NULL)	
	  {
	  dbus_server_disconnect (server);
      dbus_server_unref (server);
	  }
	 #else
	 dbus_server_disconnect (server);
     dbus_server_unref (server); 
	 #endif 
      /* Try disconnecting before unreffing */
      server = dbus_server_listen (valid_addresses[i], &error);
      if (server == NULL)
        {
          _dbus_warn ("server listen error: %s: %s\n", error.name, error.message);
          dbus_error_free (&error);          
          _dbus_assert_not_reached ("Failed to listen for valid address.");
        }
      #ifdef __SYMBIAN32__  
      if(server!=NULL)   
      {
      dbus_server_disconnect (server);
      dbus_server_unref (server);
      }
      #else
      dbus_server_disconnect (server);
      dbus_server_unref (server);
      #endif
    }

  return TRUE;
}
开发者ID:cdaffara,项目名称:symbiandump-os2,代码行数:63,代码来源:dbus-server.c


示例2: method_AddService

void method_AddService(char *path)
{
    DBusMessage* msg;
    DBusMessageIter args;
    DBusConnection* conn;
    DBusError err;
    dbus_error_init(&err);
    DBusPendingCall* pending;
    dbus_int32_t interface = -1;
    dbus_int32_t protocol = -1;
    dbus_uint32_t flags = 0;
    char *name = "xifei";
    char *type = "_http._tcp";
    char *domain = "local";
    char *host = "192.168.160.3";
    dbus_uint16_t port = 500;
    char *txt1 = "xifei";
    char *txt2 = "password of xifei";
 /*
    <arg name="interface" type="i" direction="in"/>
    <arg name="protocol" type="i" direction="in"/>
    <arg name="flags" type="u" direction="in"/>
    <arg name="name" type="s" direction="in"/>
    <arg name="type" type="s" direction="in"/>
    <arg name="domain" type="s" direction="in"/>
    <arg name="host" type="s" direction="in"/>
    <arg name="port" type="q" direction="in"/>
    <arg name="txt" type="aay" direction="in"/>
 */
   // initialiset the errors
    printf("Calling remote method: %s\n", "org.freedesktop.Avahi.EntryGroup");

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

    msg = dbus_message_new_method_call("org.freedesktop.Avahi",// target for the method call
                                        path, 							// object to call on
                                        "org.freedesktop.Avahi.EntryGroup",    // interface to call on
                                        "AddService");             // method nameResolveHostName
    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_INT32, &interface))
    {
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &protocol))
    {
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_UINT32, &flags))
    {
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &name))
    {
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &type))
    {
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &domain))
    {
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &host))
    {
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_UINT16, &port))
    {
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
    /*
	DBusMessageIter iter_ay, iter_y;
	// Open dict entry container
	if (!dbus_message_iter_open_container(&args, DBUS_TYPE_ARRAY, "ay", &iter_ay)) {
			printf("Can't open container for iter_ay\n");
			exit(1);
	}
//.........这里部分代码省略.........
开发者ID:IbpTeam,项目名称:webde_dbus_example,代码行数:101,代码来源:call-avahi.c


示例3: ck_connector_open_session

/**
 * Connects to the D-Bus system bus daemon and issues the method call
 * OpenSession on the ConsoleKit manager interface. The
 * connection to the bus is private.
 *
 * Returns FALSE on OOM, if the system bus daemon is not running, if
 * the ConsoleKit daemon is not running or if the caller doesn't have
 * sufficient privileges.
 *
 * @returns #TRUE if the operation succeeds
 */
dbus_bool_t
ck_connector_open_session (CkConnector *connector,
                           DBusError   *error)
{
        DBusError    local_error;
        DBusMessage *message;
        DBusMessage *reply;
        dbus_bool_t  ret;
        char        *cookie;

        _ck_return_val_if_fail (connector != NULL, FALSE);
        _ck_return_val_if_fail ((error) == NULL || !dbus_error_is_set ((error)), FALSE);

        reply = NULL;
        message = NULL;
        ret = FALSE;

        dbus_error_init (&local_error);
        connector->connection = dbus_bus_get_private (DBUS_BUS_SYSTEM, &local_error);
        if (connector->connection == NULL) {
                if (dbus_error_is_set (&local_error)) {
                        dbus_set_error (error,
                                        CK_CONNECTOR_ERROR,
                                        "Unable to open session: %s",
                                        local_error.message);
                        dbus_error_free (&local_error);
                }

                goto out;
        }

        dbus_connection_set_exit_on_disconnect (connector->connection, FALSE);

        message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit",
                                                "/org/freedesktop/ConsoleKit/Manager",
                                                "org.freedesktop.ConsoleKit.Manager",
                                                "OpenSession");
        if (message == NULL) {
                goto out;
        }

        dbus_error_init (&local_error);
        reply = dbus_connection_send_with_reply_and_block (connector->connection,
                                                           message,
                                                           -1,
                                                           &local_error);
        if (reply == NULL) {
                if (dbus_error_is_set (&local_error)) {
                        dbus_set_error (error,
                                        CK_CONNECTOR_ERROR,
                                        "Unable to open session: %s",
                                        local_error.message);
                        dbus_error_free (&local_error);
                        goto out;
                }
        }

        dbus_error_init (&local_error);
        if (! dbus_message_get_args (reply,
                                     &local_error,
                                     DBUS_TYPE_STRING, &cookie,
                                     DBUS_TYPE_INVALID)) {
                if (dbus_error_is_set (&local_error)) {
                        dbus_set_error (error,
                                        CK_CONNECTOR_ERROR,
                                        "Unable to open session: %s",
                                        local_error.message);
                        dbus_error_free (&local_error);
                        goto out;
                }
        }

        connector->cookie = strdup (cookie);
        if (connector->cookie == NULL) {
                goto out;
        }

        connector->session_created = TRUE;
        ret = TRUE;

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

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

//.........这里部分代码省略.........
开发者ID:ConsoleKit2,项目名称:ConsoleKit2,代码行数:101,代码来源:ck-connector.c


示例4: get_service_browser_path

char* get_service_browser_path()
{
    DBusMessage* msg;
    DBusMessageIter args;
    DBusConnection* conn;
    DBusError err;
    dbus_error_init(&err);
    DBusPendingCall* pending;
    dbus_int32_t interface = -1;
    dbus_int32_t protocol = -1;
    char *type = "_http._tcp";
    char *domain = "local";
    dbus_uint32_t flags = 0;
    char *service_browser_path;

   // initialiset the errors
    printf("Calling remote method: %s\n", "org.freedesktop.Avahi");

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

    msg = dbus_message_new_method_call("org.freedesktop.Avahi",// target for the method call
                                        "/", 							// object to call on
                                        "org.freedesktop.Avahi.Server",    // interface to call on
                                        "ServiceBrowserNew");             // method nameResolveHostName
    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_INT32, &interface))
    {
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &protocol))
    {
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &type))
    {
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &domain))
    {
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_UINT32, &flags))
    {
        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_OBJECT_PATH != dbus_message_iter_get_arg_type(&args)) 
        fprintf(stderr, "Argument is not boolean!\n"); 
    else
        dbus_message_iter_get_basic(&args, &service_browser_path);
//.........这里部分代码省略.........
开发者ID:IbpTeam,项目名称:webde_dbus_example,代码行数:101,代码来源:call-avahi.c


示例5: signal_ServiceBrowser_item

void signal_ServiceBrowser_item(char *path){
    DBusMessage* msg;
    DBusMessageIter args;
    DBusConnection* conn;
    DBusError err;
    dbus_error_init(&err);

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

    gchar* filter_itemnew = g_new(gchar, strlen("type='signal',interface='org.freedesktop.Avahi.ServiceBrowser',member='ItemNew', path=''") + strlen(path) + 2);
    sprintf(filter_itemnew, "type='signal',interface='org.freedesktop.Avahi.ServiceBrowser',member='ItemNew', path='%s'", path);
    gchar* filter_itemremove = g_new(gchar, strlen("type='signal',interface='org.freedesktop.Avahi.ServiceBrowser',member='ItemRemove', path=''") + strlen(path) + 2);
    sprintf(filter_itemremove, "type='signal',interface='org.freedesktop.Avahi.ServiceBrowser',member='ItemRemove', path='%s'", path);
    //printf("signal_filter:%s", signal_filter);
    // add a rule for which messages we want to see
    dbus_bus_add_match(conn, filter_itemnew, &err);
    dbus_bus_add_match(conn, filter_itemremove, &err);

    dbus_connection_flush(conn);
    if (dbus_error_is_set(&err)) { 
        fprintf(stderr, "Match Error (%s)\n", err.message);
        exit(1); 
   }
    printf("Match rule sent\n");

    int interface;
    int protocol;
    char *name;
    char *stype;
    char *domain;
    unsigned int flags;
//int cnt = 0;
   // loop listening for signals being emmitted
    while (true) {
        // non blocking read of the next available message
        dbus_connection_read_write(conn, 0);
        msg = dbus_connection_pop_message(conn);
        // loop again if we haven't read a message
        if (NULL == msg) { 
//g_message("cnt: %d", cnt++);
           sleep(1);
           continue;
    }
    // check if the message is a signal from the correct interface and with the correct name
    if (dbus_message_is_signal(msg, "org.freedesktop.Avahi.ServiceBrowser", "ItemNew")) {
        // read the parameters
//g_message("is the message we need.%d", cnt++);
//g_message("Message Has No Parameters\n");

        if (!dbus_message_iter_init(msg, &args))
            g_message("dbus_message_iter_init fail\n");
        else
        { 
            if (DBUS_TYPE_INT32 != dbus_message_iter_get_arg_type(&args)) 
               g_message( "Argument is not error!\n"); 
            else
               dbus_message_iter_get_basic(&args, &interface);

            if (!dbus_message_iter_next(&args))
                g_message( "Message has too few arguments!\n"); 
            else if (DBUS_TYPE_INT32 != dbus_message_iter_get_arg_type(&args)) 
                g_message("Argument is not error!\n"); 
            else
                dbus_message_iter_get_basic(&args, &protocol);

            if (!dbus_message_iter_next(&args))
                g_message("Message has too few arguments!\n"); 
            else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) 
                g_message("Argument is not error!\n"); 
            else
               dbus_message_iter_get_basic(&args, &name);

            if (!dbus_message_iter_next(&args))
                g_message("Message has too few arguments!\n"); 
            else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) 
                g_message("Argument is not error!\n"); 
            else
               dbus_message_iter_get_basic(&args, &stype);

            if (!dbus_message_iter_next(&args))
                g_message("Message has too few arguments!\n"); 
            else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) 
                g_message("Argument is not error!\n"); 
            else
               dbus_message_iter_get_basic(&args, &domain);

            if (!dbus_message_iter_next(&args))
                g_message("Message has too few arguments!\n"); 
            else if (DBUS_TYPE_UINT32 != dbus_message_iter_get_arg_type(&args)) 
                g_message("Argument is not error!\n"); 
            else
                dbus_message_iter_get_basic(&args, &flags);
            printf("\n");
//.........这里部分代码省略.........
开发者ID:IbpTeam,项目名称:webde_dbus_example,代码行数:101,代码来源:call-avahi.c


示例6: read_data

static ReadStatus
read_data (DBusBabysitter *sitter,
           int             fd)
{
    int what;
    int got;
    DBusError error = DBUS_ERROR_INIT;
    ReadStatus r;

    r = read_ints (fd, &what, 1, &got, &error);

    switch (r)
    {
    case READ_STATUS_ERROR:
        _dbus_warn ("Failed to read data from fd %d: %s\n", fd, error.message);
        dbus_error_free (&error);
        return r;

    case READ_STATUS_EOF:
        return r;

    case READ_STATUS_OK:
        break;
    }

    if (got == 1)
    {
        switch (what)
        {
        case CHILD_EXITED:
        case CHILD_FORK_FAILED:
        case CHILD_EXEC_FAILED:
        {
            int arg;

            r = read_ints (fd, &arg, 1, &got, &error);

            switch (r)
            {
            case READ_STATUS_ERROR:
                _dbus_warn ("Failed to read arg from fd %d: %s\n", fd, error.message);
                dbus_error_free (&error);
                return r;
            case READ_STATUS_EOF:
                return r;
            case READ_STATUS_OK:
                break;
            }

            if (got == 1)
            {
                if (what == CHILD_EXITED)
                {
                    sitter->have_child_status = TRUE;
                    sitter->status = arg;
                    sitter->errnum = 0;
                    _dbus_verbose ("recorded child status exited = %d signaled = %d exitstatus = %d termsig = %d\n",
                                   WIFEXITED (sitter->status), WIFSIGNALED (sitter->status),
                                   WEXITSTATUS (sitter->status), WTERMSIG (sitter->status));
                }
                else if (what == CHILD_FORK_FAILED)
                {
                    sitter->have_fork_errnum = TRUE;
                    sitter->errnum = arg;
                    _dbus_verbose ("recorded fork errnum %d\n", sitter->errnum);
                }
                else if (what == CHILD_EXEC_FAILED)
                {
                    sitter->have_exec_errnum = TRUE;
                    sitter->errnum = arg;
                    _dbus_verbose ("recorded exec errnum %d\n", sitter->errnum);
                }
            }
        }
        break;
        case CHILD_PID:
        {
            pid_t pid = -1;

            r = read_pid (fd, &pid, &error);

            switch (r)
            {
            case READ_STATUS_ERROR:
                _dbus_warn ("Failed to read PID from fd %d: %s\n", fd, error.message);
                dbus_error_free (&error);
                return r;
            case READ_STATUS_EOF:
                return r;
            case READ_STATUS_OK:
                break;
            }

            sitter->grandchild_pid = pid;

            _dbus_verbose ("recorded grandchild pid %d\n", sitter->grandchild_pid);
        }
        break;
        default:
            _dbus_warn ("Unknown message received from babysitter process\n");
//.........这里部分代码省略.........
开发者ID:mirsal,项目名称:dbus,代码行数:101,代码来源:dbus-spawn.c


示例7: 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:freedesktop-unofficial-mirror,项目名称:hal,代码行数:67,代码来源:addon-storage.c


示例8: main


//.........这里部分代码省略.........
			} else if (strcmp (opt, "direct") == 0) {
				direct = TRUE;
			} else if (strcmp (opt, "udi") == 0) {
				udi = strdup (optarg);
			} else if (strcmp (opt, "version") == 0) {
				is_version = TRUE;
			}
			break;

		default:
			usage (argc, argv);
			return 1;
			break;
		}
	}

	if (is_version) {
		printf ("hal-set-property " PACKAGE_VERSION "\n");
		return 0;
	}

	/* must have at least one, but not neither or both */
	if ((remove && type != PROP_INVALID) || ((!remove) && type == PROP_INVALID)) {
		usage (argc, argv);
		return 1;
	}
	
	fprintf (stderr, "\n");
	
	dbus_error_init (&error);
	if (direct) {
		if ((hal_ctx = libhal_ctx_init_direct (&error)) == NULL) {
			fprintf (stderr, "error: libhal_ctx_init_direct\n");
			LIBHAL_FREE_DBUS_ERROR (&error);
			return 1;
		}
	} else {
		if ((hal_ctx = libhal_ctx_new ()) == NULL) {
			fprintf (stderr, "error: libhal_ctx_new\n");
			return 1;
		}
		if (!libhal_ctx_set_dbus_connection (hal_ctx, dbus_bus_get (DBUS_BUS_SYSTEM, &error))) {
			fprintf (stderr, "error: libhal_ctx_set_dbus_connection: %s: %s\n", error.name, error.message);
			LIBHAL_FREE_DBUS_ERROR (&error);
			return 1;
		}
		if (!libhal_ctx_init (hal_ctx, &error)) {
			if (dbus_error_is_set(&error)) {
				fprintf (stderr, "error: libhal_ctx_init: %s: %s\n", error.name, error.message);
				dbus_error_free (&error);
			}
			fprintf (stderr, "Could not initialise connection to hald.\n"
					"Normally this means the HAL daemon (hald) is not running or not ready.\n");
			return 1;
		}
	}

	if (remove) {
		rc = libhal_device_remove_property (hal_ctx, udi, key, &error);
		if (!rc) {
			fprintf (stderr, "error: libhal_device_remove_property: %s: %s\n", error.name, error.message);
			LIBHAL_FREE_DBUS_ERROR (&error);
			return 1;
		}
	} else {
		switch (type) {
		case PROP_STRING:
			rc = libhal_device_set_property_string (hal_ctx, udi, key, str_value, &error);
			break;
		case PROP_INT:
			rc = libhal_device_set_property_int (hal_ctx, udi, key, int_value, &error);
			break;
		case PROP_UINT64:
			rc = libhal_device_set_property_uint64 (hal_ctx, udi, key, uint64_value, &error);
			break;
		case PROP_DOUBLE:
			rc = libhal_device_set_property_double (hal_ctx, udi, key, double_value, &error);
			break;
		case PROP_BOOL:
			rc = libhal_device_set_property_bool (hal_ctx, udi, key, bool_value, &error);
			break;
		case PROP_STRLIST_PRE:
			rc = libhal_device_property_strlist_prepend (hal_ctx, udi, key, str_value, &error);
			break;
		case PROP_STRLIST_POST:
			rc = libhal_device_property_strlist_append (hal_ctx, udi, key, str_value, &error);
			break;
		case PROP_STRLIST_REM:
			rc = libhal_device_property_strlist_remove (hal_ctx, udi, key, str_value, &error);
			break;
		}
		if (!rc) {
			fprintf (stderr, "error: libhal_device_set_property: %s: %s\n", error.name, error.message);
			dbus_error_free (&error);
			return 1;
		}
	}
	    
	return rc ? 0 : 1;
}
开发者ID:bbidulock,项目名称:hal,代码行数:101,代码来源:hal_set_property.c


示例9: session_ck_open_session

static char *
session_ck_open_session (DBusConnection *connection,
			 const char     *username,
			 int            display)
{
    DBusError       error;
    DBusMessage     *message;
    DBusMessage     *reply;
    DBusMessageIter iter;
    DBusMessageIter iter_array;
    dbus_bool_t     res;
    char            *ret;
    char            *cookie;
    dbus_bool_t     is_local = FALSE;
    dbus_bool_t     active = TRUE;
    int             uid;
    char            display_str[256];
    const char      *x11_display = display_str;
    const char      *session_type = "rdp";

    reply = NULL;
    message = NULL;
    ret = NULL;

    g_sprintf(display_str, ":%d", display);

    if (g_getuser_info(username, 0, &uid, 0, 0, 0))
	goto out;

    message =
	dbus_message_new_method_call ("org.freedesktop.ConsoleKit",
				      "/org/freedesktop/ConsoleKit/Manager",
				      "org.freedesktop.ConsoleKit.Manager",
				      "OpenSessionWithParameters");
    if (message == NULL) {
	goto out;
    }

    dbus_message_iter_init_append (message, &iter);
    if (! dbus_message_iter_open_container (&iter,
					    DBUS_TYPE_ARRAY,
					    "(sv)",
					    &iter_array)) {
	goto out;
    }

    if (!add_param_basic (&iter_array,
			  "unix-user",
			  DBUS_TYPE_INT32,
			  &uid) ||
	!add_param_basic (&iter_array,
			  "x11-display",
			  DBUS_TYPE_STRING,
			  &x11_display) ||
	!add_param_basic (&iter_array,
			  "is-local",
			  DBUS_TYPE_BOOLEAN,
			  &is_local) ||
	!add_param_basic (&iter_array,
			  "active",
			  DBUS_TYPE_BOOLEAN,
			  &active) ||
	!add_param_basic (&iter_array,
			  "session-type",
			  DBUS_TYPE_STRING,
			  &session_type)) {
	log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS,
		    "Error adding ck session parameter");
	goto out;
    }

    if (! dbus_message_iter_close_container (&iter, &iter_array)) {
	goto out;
    }

    dbus_error_init (&error);
    reply = dbus_connection_send_with_reply_and_block (connection,
						       message,
						       -1,
						       &error);
    if (reply == NULL) {
	if (dbus_error_is_set (&error)) {
	    log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS,
			"Unable to open session: %s",
			error.message);
	    dbus_error_free (&error);
	    goto out;
	}
    }

    dbus_error_init (&error);
    if (! dbus_message_get_args (reply,
				 &error,
				 DBUS_TYPE_STRING, &cookie,
				 DBUS_TYPE_INVALID)) {
	if (dbus_error_is_set (&error)) {
	    log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS,
			"Unable to open session: %s",
			error.message);
	    dbus_error_free (&error);
//.........这里部分代码省略.........
开发者ID:zeha,项目名称:xrdp-suse-fork,代码行数:101,代码来源:session.c


示例10: wpa_supplicant_dbus_ctrl_iface_init

/**
 * wpa_supplicant_dbus_ctrl_iface_init - Initialize dbus control interface
 * @global: Pointer to global data from wpa_supplicant_init()
 * Returns: Pointer to dbus_ctrl_iface date or %NULL on failure
 *
 * Initialize the dbus control interface and start receiving commands from
 * external programs over the bus.
 */
struct ctrl_iface_dbus_priv *
wpa_supplicant_dbus_ctrl_iface_init(struct wpa_global *global)
{
	struct ctrl_iface_dbus_priv *iface;
	DBusError error;
	int ret = -1;
	DBusObjectPathVTable wpas_vtable = {
		NULL, &wpas_message_handler, NULL, NULL, NULL, NULL
	};

	iface = wpa_zalloc(sizeof(struct ctrl_iface_dbus_priv));
	if (iface == NULL)
		return NULL;

	iface->global = global;

	/* Get a reference to the system bus */
	dbus_error_init(&error);
	iface->con = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
	dbus_error_free(&error);
	if (!iface->con) {
		perror("dbus_bus_get[ctrl_iface_dbus]");
		wpa_printf(MSG_ERROR, "Could not acquire the system bus.");
		goto fail;
	}

	/* Tell dbus about our mainloop integration functions */
	if (integrate_with_eloop(iface->con, iface))
		goto fail;

	/* Register the message handler for the global dbus interface */
	if (!dbus_connection_register_object_path(iface->con,
						  WPAS_DBUS_PATH, &wpas_vtable,
						  iface)) {
		perror("dbus_connection_register_object_path[dbus]");
		wpa_printf(MSG_ERROR, "Could not set up DBus message "
			   "handler.");
		goto fail;
	}

	/* Register our service with the message bus */
	dbus_error_init(&error);
	switch (dbus_bus_request_name(iface->con, WPAS_DBUS_SERVICE,
				      0, &error)) {
	case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER:
		ret = 0;
		break;
	case DBUS_REQUEST_NAME_REPLY_EXISTS:
	case DBUS_REQUEST_NAME_REPLY_IN_QUEUE:
	case DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER:
		perror("dbus_bus_request_name[dbus]");
		wpa_printf(MSG_ERROR, "Could not request DBus service name: "
			   "already registered.");
		break;
	default:
		perror("dbus_bus_request_name[dbus]");
		wpa_printf(MSG_ERROR, "Could not request DBus service name: "
			   "%s %s.", error.name, error.message);
		break;
	}
	dbus_error_free(&error);

	if (ret != 0)
		goto fail;

	wpa_printf(MSG_DEBUG, "Providing DBus service '" WPAS_DBUS_SERVICE
		   "'.");

	/*
	 * Dispatch initial DBus messages that may have come in since the bus
	 * name was claimed above. Happens when clients are quick to notice the
	 * wpa_supplicant service.
	 *
	 * FIXME: is there a better solution to this problem?
	 */
	eloop_register_timeout(0, 50, dispatch_initial_dbus_messages,
	                       iface->con, NULL);

	return iface;

fail:
	wpa_supplicant_dbus_ctrl_iface_deinit(iface);
	return NULL;
}
开发者ID:Dopi,项目名称:JetPlatform_delta,代码行数:92,代码来源:ctrl_iface_dbus.c


示例11: verify_polkit

int verify_polkit(
                DBusConnection *c,
                DBusMessage *request,
                const char *action,
                bool interactive,
                bool *_challenge,
                DBusError *error) {


#ifdef ENABLE_POLKIT
        DBusMessage *m = NULL, *reply = NULL;
        const char *unix_process = "unix-process", *pid = "pid", *starttime = "start-time", *cancel_id = "";
        uint32_t flags = interactive ? 1 : 0;
        pid_t pid_raw;
        uint32_t pid_u32;
        unsigned long long starttime_raw;
        uint64_t starttime_u64;
        DBusMessageIter iter_msg, iter_struct, iter_array, iter_dict, iter_variant;
        int r;
        dbus_bool_t authorized = FALSE, challenge = FALSE;
#endif
        const char *sender;
        unsigned long ul;

        assert(c);
        assert(request);

        sender = dbus_message_get_sender(request);
        if (!sender)
                return -EINVAL;

        ul = dbus_bus_get_unix_user(c, sender, error);
        if (ul == (unsigned long) -1)
                return -EINVAL;

        /* Shortcut things for root, to avoid the PK roundtrip and dependency */
        if (ul == 0)
                return 1;

#ifdef ENABLE_POLKIT

        pid_raw = bus_get_unix_process_id(c, sender, error);
        if (pid_raw == 0)
                return -EINVAL;

        r = get_starttime_of_pid(pid_raw, &starttime_raw);
        if (r < 0)
                return r;

        m = dbus_message_new_method_call(
                        "org.freedesktop.PolicyKit1",
                        "/org/freedesktop/PolicyKit1/Authority",
                        "org.freedesktop.PolicyKit1.Authority",
                        "CheckAuthorization");
        if (!m)
                return -ENOMEM;

        dbus_message_iter_init_append(m, &iter_msg);

        pid_u32 = (uint32_t) pid_raw;
        starttime_u64 = (uint64_t) starttime_raw;

        if (!dbus_message_iter_open_container(&iter_msg, DBUS_TYPE_STRUCT, NULL, &iter_struct) ||
            !dbus_message_iter_append_basic(&iter_struct, DBUS_TYPE_STRING, &unix_process) ||
            !dbus_message_iter_open_container(&iter_struct, DBUS_TYPE_ARRAY, "{sv}", &iter_array) ||
            !dbus_message_iter_open_container(&iter_array, DBUS_TYPE_DICT_ENTRY, NULL, &iter_dict) ||
            !dbus_message_iter_append_basic(&iter_dict, DBUS_TYPE_STRING, &pid) ||
            !dbus_message_iter_open_container(&iter_dict, DBUS_TYPE_VARIANT, "u", &iter_variant) ||
            !dbus_message_iter_append_basic(&iter_variant, DBUS_TYPE_UINT32, &pid_u32) ||
            !dbus_message_iter_close_container(&iter_dict, &iter_variant) ||
            !dbus_message_iter_close_container(&iter_array, &iter_dict) ||
            !dbus_message_iter_open_container(&iter_array, DBUS_TYPE_DICT_ENTRY, NULL, &iter_dict) ||
            !dbus_message_iter_append_basic(&iter_dict, DBUS_TYPE_STRING, &starttime) ||
            !dbus_message_iter_open_container(&iter_dict, DBUS_TYPE_VARIANT, "t", &iter_variant) ||
            !dbus_message_iter_append_basic(&iter_variant, DBUS_TYPE_UINT64, &starttime_u64) ||
            !dbus_message_iter_close_container(&iter_dict, &iter_variant) ||
            !dbus_message_iter_close_container(&iter_array, &iter_dict) ||
            !dbus_message_iter_close_container(&iter_struct, &iter_array) ||
            !dbus_message_iter_close_container(&iter_msg, &iter_struct) ||
            !dbus_message_iter_append_basic(&iter_msg, DBUS_TYPE_STRING, &action) ||
            !dbus_message_iter_open_container(&iter_msg, DBUS_TYPE_ARRAY, "{ss}", &iter_array) ||
            !dbus_message_iter_close_container(&iter_msg, &iter_array) ||
            !dbus_message_iter_append_basic(&iter_msg, DBUS_TYPE_UINT32, &flags) ||
            !dbus_message_iter_append_basic(&iter_msg, DBUS_TYPE_STRING, &cancel_id)) {
                r = -ENOMEM;
                goto finish;
        }

        reply = dbus_connection_send_with_reply_and_block(c, m, -1, error);
        if (!reply) {

                /* Treat no PK available as access denied */
                if (dbus_error_has_name(error, DBUS_ERROR_SERVICE_UNKNOWN)) {
                        r = -EACCES;
                        dbus_error_free(error);
                        goto finish;
                }

                r = -EIO;
                goto finish;
//.........这里部分代码省略.........
开发者ID:Miss6yka,项目名称:systemd,代码行数:101,代码来源:polkit.c


示例12: list_controllers_main

int list_controllers_main (void *parent, char ***output)
{
	DBusMessage *message = NULL, *reply = NULL;
	char **         output_local = NULL;
	DBusError       error;
	DBusMessageIter iter;
	int		ret = -1;
	DBusMessageIter output_local_iter;
	size_t          output_local_size;

	*output = NULL;
	message = dbus_message_new_method_call(dbus_bus_get_unique_name(server_conn),
			"/org/linuxcontainers/cgmanager",
			"org.linuxcontainers.cgmanager0_0", "ListControllers");

	dbus_error_init (&error);

	reply = dbus_connection_send_with_reply_and_block (server_conn, message, -1, &error);
	if (! reply) {
		dbus_message_unref (message);

		nih_error("%s: error completing dbus request: %s %s", __func__,
			error.name, error.message);

		dbus_error_free (&error);
		return -1;
	}
	dbus_message_unref (message);

	dbus_message_iter_init (reply, &iter);

	if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY)
		goto out;

	dbus_message_iter_recurse (&iter, &output_local_iter);

	output_local_size = 0;
	output_local = NULL;

	output_local = NIH_MUST( nih_alloc (parent, sizeof (char *)) );

	output_local[output_local_size] = NULL;

	while (dbus_message_iter_get_arg_type (&output_local_iter) != DBUS_TYPE_INVALID) {
		const char *output_local_element_dbus;
		char **     output_local_tmp;
		char *      output_local_element;

		if (dbus_message_iter_get_arg_type (&output_local_iter) != DBUS_TYPE_STRING)
			goto out;

		dbus_message_iter_get_basic (&output_local_iter, &output_local_element_dbus);

		output_local_element = NIH_MUST( nih_strdup (output_local, output_local_element_dbus) );

		dbus_message_iter_next (&output_local_iter);

		output_local_tmp = NIH_MUST( nih_realloc (output_local, parent, sizeof (char *) * (output_local_size + 2)) );

		output_local = output_local_tmp;
		output_local[output_local_size] = output_local_element;
		output_local[output_local_size + 1] = NULL;

		output_local_size++;
	}

	dbus_message_iter_next (&iter);

	if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID)
		goto out;

	*output = output_local;

	ret = 0;

out:
	if (reply)
		dbus_message_unref (reply);
	if (ret)
		nih_free (output_local);
	return ret;
}
开发者ID:smemsh,项目名称:cgmanager,代码行数:82,代码来源:cgmanager-proxy.c


示例13: get_properties


//.........这里部分代码省略.........
        {
            dbus_message_iter_next(&dict_key);
            dbus_message_iter_recurse(&dict_key, &dict_value);
            dbus_message_iter_get_basic(&dict_value, &cValue);
            strcpy(value, cValue);
            printf("%s:  %s\n", key, value);
        }
        //Discoverable
        else if(!strcmp(key, "Discoverable"))
        {
            dbus_message_iter_next(&dict_key);
            dbus_message_iter_recurse(&dict_key, &dict_value);
            dbus_message_iter_get_basic(&dict_value, &bValue);
            printf("%s:  %d\n", key, bValue);
        }
        //DiscoverableTimeout
        else if(!strcmp(key, "DiscoverableTimeout"))
        {
            dbus_message_iter_next(&dict_key);
            dbus_message_iter_recurse(&dict_key, &dict_value);
            dbus_message_iter_get_basic(&dict_value, &iValue);
            printf("%s:  %d\n", key, iValue);
        }
        //Discovering
        else if(!strcmp(key, "Discovering"))
        {
            dbus_message_iter_next(&dict_key);
            dbus_message_iter_recurse(&dict_key, &dict_value);
            dbus_message_iter_get_basic(&dict_value, &bValue);
            printf("%s:  %d\n", key, bValue);
        }
        //Pairable
        else if(!strcmp(key, "Pairable"))
        {
            dbus_message_iter_next(&dict_key);
            dbus_message_iter_recurse(&dict_key, &dict_value);
            dbus_message_iter_get_basic(&dict_value, &bValue);
            printf("%s:  %d\n", key, bValue);
        }
        //PairableTimeout
        else if(!strcmp(key, "PairableTimeout"))
        {
            dbus_message_iter_next(&dict_key);
            dbus_message_iter_recurse(&dict_key, &dict_value);
            dbus_message_iter_get_basic(&dict_value, &iValue);
            printf("%s:  %d\n", key, iValue);
        }
        //Powerd
        else if(!strcmp(key, "Powered"))
        {
            dbus_message_iter_next(&dict_key);
            dbus_message_iter_recurse(&dict_key, &dict_value);
            dbus_message_iter_get_basic(&dict_value, &bValue);
            printf("%s:  %d\n", key, bValue);
        }
        //Devices
        else if(!strcmp(key, "Devices"))
        {
            DBusMessageIter device_array;
            dbus_message_iter_next(&dict_key);
            dbus_message_iter_recurse(&dict_key, &dict_value);
            dbus_message_iter_recurse(&dict_value, &device_array);

            if (dbus_message_iter_get_arg_type(&device_array) != DBUS_TYPE_OBJECT_PATH)
            {
                printf("%s:  0\n", key);
                continue;
            }

            // i = 0;
            do
            {
                dbus_message_iter_get_basic(&device_array, &cValue);
                strcpy(value, cValue);
                // printf("%s %d %s %d: %s\n", __func__, __LINE__, key, ++i, value);
            } while (dbus_message_iter_next(&device_array));

        }
        //UUIDs
        else if(!strcmp(key, "UUIDs"))
        {
            DBusMessageIter device_array;
            dbus_message_iter_next(&dict_key);
            dbus_message_iter_recurse(&dict_key, &dict_value);
            dbus_message_iter_recurse(&dict_value, &device_array);

            do
            {
                dbus_message_iter_get_basic(&device_array, &cValue);
            } while(dbus_message_iter_next(&device_array));
        }
        else
        {
            printf("%s: Not to supported \n",key);
        }

    } while (dbus_message_iter_next(&dict));

    dbus_error_free(&err);
}
开发者ID:jolin90,项目名称:dbus,代码行数:101,代码来源:scan.c


示例14: set_property

static void set_property(DBusConnection *conn, const char *name, struct ADAPTER_PROPERTIES *p)
{
    DBusError err;
    DBusMessage *msg;
    DBusMessageIter iter;
    char s[255];

    memset(&s, 0, 255);
    dbus_error_init(&err);

    msg = dbus_message_new_method_call(DBUS_NAME,DBUS_PATH, DBUS_INTERFACE_APAPTER,
                                       "SetProperty");
    if (msg == NULL)
    {
        printf("%s %d msg is null\n", __func__, __LINE__);
        exit(1);
    }

    /* append data */
    dbus_message_iter_init_append(msg, &iter);
    dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &name);

    // printf("%s %d\n", __func__, __LINE__);

    if (!strcmp(name, "Name"))
    {
        // printf("SynergyDBusAdapter::SetProperty('%s', %s)\n", name, p->Name);
        strcpy(s, p->Name);
        append_variant(&iter, DBUS_TYPE_STRING, &s);
    }
    else if (!strcmp(name, "Powered"))
    {
        // printf("SynergyDBusAdapter::SetProperty('%s', %d)\n", name, p->Powered);
        append_variant(&iter, DBUS_TYPE_BOOLEAN, &p->Powered);
    }
    else if (!strcmp(name, "DiscoverableTimeout"))
    {
        // printf("SynergyDBusAdapter::SetProperty('%s', %d)\n", name, p->DiscoverableTimeout);
        append_variant(&iter, DBUS_TYPE_UINT32, &p->DiscoverableTimeout);
    }
    else if (!strcmp(name, "Discoverable"))
    {
        // printf("SynergyDBusAdapter::SetProperty('%s', %d)\n", name, p->Discoverable);
        append_variant(&iter, DBUS_TYPE_BOOLEAN, &p->Discoverable);
    }
    else if (!strcmp(name, "PairableTimeout"))
    {
        // printf("SynergyDBusAdapter::SetProperty('%s', %d)\n", name, p->PairableTimeout);
        append_variant(&iter, DBUS_TYPE_UINT32, &p->PairableTimeout);
    }
    else if (!strcmp(name, "Pairable"))
    {
        // printf( 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ dbus_error_has_name函数代码示例发布时间:2022-05-30
下一篇:
C++ dbus_connection_unref函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap