本文整理汇总了C++中dbus_error_is_set函数的典型用法代码示例。如果您正苦于以下问题:C++ dbus_error_is_set函数的具体用法?C++ dbus_error_is_set怎么用?C++ dbus_error_is_set使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dbus_error_is_set函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: conf_drp_show_domain_ip
int
conf_drp_show_domain_ip(DBusConnection *connection,
domain_cst *domain_configs_ret)
{
DBusMessage *query, *reply;
DBusError err;
DBusMessageIter iter;
DBusMessageIter iter_array;
int iRet=0;
int i = 0, ip_num = 0;
char *domain_name = NULL;
int index = 0;
unsigned long ipaddr = 0;
query = dbus_message_new_method_call(
DRP_DBUS_BUSNAME,
DRP_DBUS_OBJPATH,
DRP_DBUS_INTERFACE,
DRP_DBUS_METHOD_SHOW_DOMAIN_IP );
dbus_error_init(&err);
dbus_message_append_args( query,
DBUS_TYPE_INVALID );
reply = dbus_connection_send_with_reply_and_block (
connection, query, -1, &err );
dbus_message_unref(query);
if ( NULL == reply ){
if (dbus_error_is_set(&err)){
dbus_error_free(&err);
}
return DRP_ERR_DBUS_FAILED;
}else{
dbus_message_iter_init(reply,&iter);
//dbus_message_iter_next(&iter);
dbus_message_iter_get_basic(&iter, &iRet);
if( DRP_RETURN_OK == iRet ){
memset (domain_configs_ret, 0, sizeof(domain_configs_ret));
dbus_message_iter_next(&iter);
dbus_message_iter_get_basic(&iter, &ip_num);
if( ip_num > MAX_DOMAIN_CONFIG_NUM*MAX_DOMAIN_IPADDR ){
ip_num = MAX_DOMAIN_CONFIG_NUM*MAX_DOMAIN_IPADDR;
}
domain_configs_ret->num = ip_num;
if( ip_num > 0 ){
dbus_message_iter_next(&iter);
dbus_message_iter_recurse(&iter,&iter_array);
for( i=0; i<ip_num; i++ ){
DBusMessageIter iter_struct;
dbus_message_iter_recurse(&iter_array,&iter_struct);
dbus_message_iter_get_basic(&iter_struct, &domain_name);
strncpy((domain_configs_ret->domain[i].domain_name), domain_name,\
sizeof(domain_configs_ret->domain[i].domain_name));
dbus_message_iter_next(&iter_struct);
dbus_message_iter_get_basic(&iter_struct, \
&(index));
domain_configs_ret->domain[i].index = index;
dbus_message_iter_next(&iter_struct);
dbus_message_iter_get_basic(&iter_struct, \
&(ipaddr));
domain_configs_ret->domain[i].ipaddr = ipaddr;
dbus_message_iter_next(&iter_array);
#ifdef drp_test_interface
printf("domain %s ip index %d ipaddr %lu\n",\
(domain_configs_ret->domain[i].domain_name),\
(domain_configs_ret->domain[i].index),\
(domain_configs_ret->domain[i].ipaddr));
#endif
}
}
}
}
dbus_message_unref(reply);
return iRet;
}
示例2: main
int main(int argc, char *argv[])
{
GOptionContext *context;
GError *error = NULL;
DBusConnection *conn;
DBusError err;
guint signal;
#ifdef NEED_THREADS
if (g_thread_supported() == FALSE)
g_thread_init(NULL);
#endif
context = g_option_context_new(NULL);
g_option_context_add_main_entries(context, options, NULL);
if (g_option_context_parse(context, &argc, &argv, &error) == FALSE) {
if (error != NULL) {
g_printerr("%s\n", error->message);
g_error_free(error);
} else
g_printerr("An unknown error occurred\n");
exit(1);
}
g_option_context_free(context);
if (option_version == TRUE) {
printf("%s\n", VERSION);
exit(0);
}
if (option_detach == TRUE) {
if (daemon(0, 0)) {
perror("Can't start daemon");
exit(1);
}
}
if (mkdir(STATEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
if (errno != EEXIST)
perror("Failed to create state directory");
}
if (mkdir(STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
if (errno != EEXIST)
perror("Failed to create storage directory");
}
umask(0077);
main_loop = g_main_loop_new(NULL, FALSE);
#ifdef NEED_THREADS
if (dbus_threads_init_default() == FALSE) {
fprintf(stderr, "Can't init usage of threads\n");
exit(1);
}
#endif
signal = setup_signalfd();
dbus_error_init(&err);
conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, CONNMAN_SERVICE, &err);
if (conn == NULL) {
if (dbus_error_is_set(&err) == TRUE) {
fprintf(stderr, "%s\n", err.message);
dbus_error_free(&err);
} else
fprintf(stderr, "Can't register with system bus\n");
exit(1);
}
g_dbus_set_disconnect_function(conn, disconnect_callback, NULL, NULL);
__connman_log_init(argv[0], option_debug, option_detach,
option_backtrace, "Connection Manager", VERSION);
__connman_dbus_init(conn);
if (option_config == NULL)
config_init(CONFIGMAINFILE);
else
config_init(option_config);
__connman_inotify_init();
__connman_technology_init();
__connman_notifier_init();
__connman_agent_init();
__connman_service_init();
__connman_provider_init();
__connman_network_init();
__connman_device_init(option_device, option_nodevice);
__connman_ippool_init();
__connman_iptables_init();
__connman_firewall_init();
//.........这里部分代码省略.........
示例3: _dbus_message_test
//.........这里部分代码省略.........
_dbus_assert_not_reached ("received a NULL message");
if (dbus_message_get_reply_serial (message) != 5678)
_dbus_assert_not_reached ("reply serial fields differ");
dbus_message_unref (message);
/* ovveride the serial, since it was reset by dbus_message_copy() */
dbus_message_set_serial(message_without_unix_fds, 8901);
dbus_message_lock (message_without_unix_fds);
verify_test_message (message_without_unix_fds);
{
/* Marshal and demarshal the message. */
DBusMessage *message2;
DBusError error = DBUS_ERROR_INIT;
char *marshalled = NULL;
int len = 0;
char garbage_header[DBUS_MINIMUM_HEADER_SIZE] = "xxx";
if (!dbus_message_marshal (message_without_unix_fds, &marshalled, &len))
_dbus_assert_not_reached ("failed to marshal message");
_dbus_assert (len != 0);
_dbus_assert (marshalled != NULL);
_dbus_assert (dbus_message_demarshal_bytes_needed (marshalled, len) == len);
message2 = dbus_message_demarshal (marshalled, len, &error);
_dbus_assert (message2 != NULL);
_dbus_assert (!dbus_error_is_set (&error));
verify_test_message (message2);
dbus_message_unref (message2);
dbus_free (marshalled);
/* Demarshal invalid message. */
message2 = dbus_message_demarshal ("invalid", 7, &error);
_dbus_assert (message2 == NULL);
_dbus_assert (dbus_error_is_set (&error));
dbus_error_free (&error);
/* Demarshal invalid (empty) message. */
message2 = dbus_message_demarshal ("", 0, &error);
_dbus_assert (message2 == NULL);
_dbus_assert (dbus_error_is_set (&error));
dbus_error_free (&error);
/* Bytes needed to demarshal empty message: 0 (more) */
_dbus_assert (dbus_message_demarshal_bytes_needed ("", 0) == 0);
/* Bytes needed to demarshal invalid message: -1 (error). */
_dbus_assert (dbus_message_demarshal_bytes_needed (garbage_header, DBUS_MINIMUM_HEADER_SIZE) == -1);
}
dbus_message_unref (message_without_unix_fds);
_dbus_message_loader_unref (loader);
check_memleaks ();
示例4: cdbus_init
/**
* Initialize D-Bus connection.
*/
bool
cdbus_init(session_t *ps) {
DBusError err = { };
// Initialize
dbus_error_init(&err);
// Connect to D-Bus
// Use dbus_bus_get_private() so we can fully recycle it ourselves
ps->dbus_conn = dbus_bus_get_private(DBUS_BUS_SESSION, &err);
if (dbus_error_is_set(&err)) {
printf_errf("(): D-Bus connection failed (%s).", err.message);
dbus_error_free(&err);
return false;
}
if (!ps->dbus_conn) {
printf_errf("(): D-Bus connection failed for unknown reason.");
return false;
}
// Avoid exiting on disconnect
dbus_connection_set_exit_on_disconnect(ps->dbus_conn, false);
// Request service name
{
// Build service name
char *service = mstrjoin3(CDBUS_SERVICE_NAME, ".", ps->o.display_repr);
ps->dbus_service = service;
// Request for the name
int ret = dbus_bus_request_name(ps->dbus_conn, service,
DBUS_NAME_FLAG_DO_NOT_QUEUE, &err);
if (dbus_error_is_set(&err)) {
printf_errf("(): Failed to obtain D-Bus name (%s).", err.message);
dbus_error_free(&err);
}
if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret
&& DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER != ret) {
printf_errf("(): Failed to become the primary owner of requested "
"D-Bus name (%d).", ret);
}
}
// Add watch handlers
if (!dbus_connection_set_watch_functions(ps->dbus_conn,
cdbus_callback_add_watch, cdbus_callback_remove_watch,
cdbus_callback_watch_toggled, ps, NULL)) {
printf_errf("(): Failed to add D-Bus watch functions.");
return false;
}
// Add timeout handlers
if (!dbus_connection_set_timeout_functions(ps->dbus_conn,
cdbus_callback_add_timeout, cdbus_callback_remove_timeout,
cdbus_callback_timeout_toggled, ps, NULL)) {
printf_errf("(): Failed to add D-Bus timeout functions.");
return false;
}
// Add match
dbus_bus_add_match(ps->dbus_conn,
"type='method_call',interface='" CDBUS_INTERFACE_NAME "'", &err);
if (dbus_error_is_set(&err)) {
printf_errf("(): Failed to add D-Bus match.");
dbus_error_free(&err);
return false;
}
return true;
}
示例5: match_name_owner_changed_signal
static dbus_bool_t
match_name_owner_changed_signal (DBusConnection *conn, const char *bus_name, const char *lost_name, const char *acquired_name)
{
int tries;
DBusMessage *msg;
for (tries = 0; tries < NUM_TRIES_TIL_FAIL; tries++)
{
_dbus_connection_lock (conn);
_dbus_connection_do_iteration_unlocked (conn,
DBUS_ITERATION_DO_READING |
DBUS_ITERATION_DO_WRITING |
DBUS_ITERATION_BLOCK,
0);
_dbus_connection_unlock (conn);
msg = dbus_connection_pop_message (conn);
if (msg != NULL)
{
if (dbus_message_is_signal (msg,
"org.freedesktop.DBus",
"NameOwnerChanged"))
{
const char *n;
const char *ln;
const char *an;
DBusError error;
dbus_error_init (&error);
dbus_message_get_args (msg, &error, DBUS_TYPE_STRING, &n, DBUS_TYPE_STRING, &ln, DBUS_TYPE_STRING, &an, DBUS_TYPE_INVALID);
if (dbus_error_is_set (&error))
{
fprintf (stderr, "Error getting args: %s\n", error.message);
dbus_error_free (&error);
dbus_message_unref (msg);
return FALSE;
}
if (strcmp (n, bus_name) == 0)
{
if ((lost_name == NULL && strcmp (ln, "") == 0)
|| strcmp (lost_name, ln) == 0)
{
if ((acquired_name == NULL && strcmp (an, "") == 0)
|| strcmp (acquired_name, an) == 0)
{
dbus_message_unref (msg);
break;
}
else
{
fprintf (stderr, "Error: name %s was expected to be acquired but we got %s instead\n", acquired_name, an);
dbus_message_unref (msg);
return FALSE;
}
}
else
{
fprintf (stderr, "Error: name %s was expected to be lost but we got %s instead\n", lost_name, ln);
dbus_message_unref (msg);
return FALSE;
}
}
}
dbus_message_unref (msg);
}
}
if (tries == NUM_TRIES_TIL_FAIL)
{
fprintf (stderr, "Did not recive the expected NameOwnerChanged signal!!!\n");
return FALSE;
}
return TRUE;
}
示例6: _dbus_transport_open
/**
* Try to open a new transport for the given address entry. (This
* opens a client-side-of-the-connection transport.)
*
* @param entry the address entry
* @param error location to store reason for failure.
* @returns new transport of #NULL on failure.
*/
DBusTransport*
_dbus_transport_open (DBusAddressEntry *entry,
DBusError *error)
{
DBusTransport *transport;
const char *expected_guid_orig;
char *expected_guid;
int i;
DBusError tmp_error = DBUS_ERROR_INIT;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
transport = NULL;
expected_guid_orig = dbus_address_entry_get_value (entry, "guid");
expected_guid = _dbus_strdup (expected_guid_orig);
if (expected_guid_orig != NULL && expected_guid == NULL)
{
_DBUS_SET_OOM (error);
return NULL;
}
for (i = 0; i < (int) _DBUS_N_ELEMENTS (open_funcs); ++i)
{
DBusTransportOpenResult result;
_DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
result = (* open_funcs[i].func) (entry, &transport, &tmp_error);
switch (result)
{
case DBUS_TRANSPORT_OPEN_OK:
_DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
goto out;
break;
case DBUS_TRANSPORT_OPEN_NOT_HANDLED:
_DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
/* keep going through the loop of open funcs */
break;
case DBUS_TRANSPORT_OPEN_BAD_ADDRESS:
_DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
goto out;
break;
case DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT:
_DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
goto out;
break;
}
}
out:
if (transport == NULL)
{
if (!dbus_error_is_set (&tmp_error))
_dbus_set_bad_address (&tmp_error,
NULL, NULL,
"Unknown address type (examples of valid types are \"tcp\" and on UNIX \"unix\")");
_DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
dbus_move_error(&tmp_error, error);
dbus_free (expected_guid);
}
else
{
_DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
/* In the case of autostart the initial guid is NULL
* and the autostart transport recursively calls
* _dbus_open_transport wich returns a transport
* with a guid. That guid is the definitive one.
*
* FIXME: if more transports are added they may have
* an effect on the expected_guid semantics (i.e.
* expected_guid and transport->expected_guid may
* both have values). This is very unlikely though
* we should either throw asserts here for those
* corner cases or refactor the code so it is
* clearer on what is expected and what is not
*/
if(expected_guid)
transport->expected_guid = expected_guid;
}
return transport;
}
示例7: main
int main(int argc, char *argv[])
{
GOptionContext *context;
GError *error = NULL;
DBusConnection *conn;
DBusError err;
guint signal;
context = g_option_context_new(NULL);
g_option_context_add_main_entries(context, options, NULL);
if (!g_option_context_parse(context, &argc, &argv, &error)) {
if (error) {
g_printerr("%s\n", error->message);
g_error_free(error);
} else
g_printerr("An unknown error occurred\n");
exit(1);
}
g_option_context_free(context);
if (option_version) {
printf("%s\n", VERSION);
exit(0);
}
if (option_detach) {
if (daemon(0, 0)) {
perror("Can't start daemon");
exit(1);
}
}
if (mkdir(STATEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
if (errno != EEXIST)
perror("Failed to create state directory");
}
/*
* At some point the VPN stuff is migrated into VPN_STORAGEDIR
* and this mkdir() call can be removed.
*/
if (mkdir(STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
if (errno != EEXIST)
perror("Failed to create storage directory");
}
if (mkdir(VPN_STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
if (errno != EEXIST)
perror("Failed to create VPN storage directory");
}
umask(0077);
main_loop = g_main_loop_new(NULL, FALSE);
signal = setup_signalfd();
dbus_error_init(&err);
conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, VPN_SERVICE, &err);
if (!conn) {
if (dbus_error_is_set(&err)) {
fprintf(stderr, "%s\n", err.message);
dbus_error_free(&err);
} else
fprintf(stderr, "Can't register with system bus\n");
exit(1);
}
g_dbus_set_disconnect_function(conn, disconnect_callback, NULL, NULL);
__connman_log_init(argv[0], option_debug, option_detach, false,
"Connection Manager VPN daemon", VERSION);
__connman_dbus_init(conn);
if (!option_config)
config_init(CONFIGMAINFILE);
else
config_init(option_config);
__connman_inotify_init();
__connman_agent_init();
__vpn_provider_init(option_routes);
__vpn_manager_init();
__vpn_ipconfig_init();
__vpn_rtnl_init();
__connman_task_init();
__connman_plugin_init(option_plugin, option_noplugin);
__vpn_config_init();
__vpn_rtnl_start();
g_free(option_plugin);
g_free(option_noplugin);
//.........这里部分代码省略.........
示例8: showNotify
virtual int showNotify(const char *pcHeader, const char *pcBody)
{
int rc;
# ifdef VBOX_WITH_DBUS
DBusConnection *conn;
DBusMessage* msg = NULL;
conn = dbus_bus_get (DBUS_BUS_SESSON, NULL);
if (conn == NULL)
{
LogRelFlowFunc(("Could not retrieve D-BUS session bus!\n"));
rc = VERR_INVALID_HANDLE;
}
else
{
msg = dbus_message_new_method_call("org.freedesktop.Notifications",
"/org/freedesktop/Notifications",
"org.freedesktop.Notifications",
"Notify");
if (msg == NULL)
{
LogRel(("Could not create D-BUS message!\n"));
rc = VERR_INVALID_HANDLE;
}
else
rc = VINF_SUCCESS;
}
if (RT_SUCCESS(rc))
{
uint32_t msg_replace_id = 0;
const char *msg_app = "VBoxClient";
const char *msg_icon = "";
const char *msg_summary = pcHeader;
const char *msg_body = pcBody;
int32_t msg_timeout = -1; /* Let the notification server decide */
DBusMessageIter iter;
DBusMessageIter array;
DBusMessageIter dict;
DBusMessageIter value;
DBusMessageIter variant;
DBusMessageIter data;
/* Format: UINT32 org.freedesktop.Notifications.Notify
* (STRING app_name, UINT32 replaces_id, STRING app_icon, STRING summary, STRING body,
* ARRAY actions, DICT hints, INT32 expire_timeout)
*/
dbus_message_iter_init_append(msg,&iter);
dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&msg_app);
dbus_message_iter_append_basic(&iter,DBUS_TYPE_UINT32,&msg_replace_id);
dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&msg_icon);
dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&msg_summary);
dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&msg_body);
dbus_message_iter_open_container(&iter,DBUS_TYPE_ARRAY,DBUS_TYPE_STRING_AS_STRING,&array);
dbus_message_iter_close_container(&iter,&array);
dbus_message_iter_open_container(&iter,DBUS_TYPE_ARRAY,"{sv}",&array);
dbus_message_iter_close_container(&iter,&array);
dbus_message_iter_append_basic(&iter,DBUS_TYPE_INT32,&msg_timeout);
DBusError err;
dbus_error_init(&err);
DBusMessage *reply;
reply = dbus_connection_send_with_reply_and_block(conn, msg,
30 * 1000 /* 30 seconds timeout */, &err);
if (dbus_error_is_set(&err))
{
LogRel(("D-BUS returned an error while sending the notification: %s", err.message));
}
else if (reply)
{
dbus_connection_flush(conn);
dbus_message_unref(reply);
}
if (dbus_error_is_set(&err))
dbus_error_free(&err);
}
if (msg != NULL)
dbus_message_unref(msg);
# else
/* TODO: Implement me */
rc = VINF_SUCCESS;
# endif /* VBOX_WITH_DBUS */
return rc;
}
示例9: g_return_val_if_fail
static DBusGProxy *dbus_connect (MoonshotError **error)
{
DBusConnection *dbconnection;
DBusError dbus_error;
DBusGConnection *connection;
DBusGProxy *g_proxy;
GError *g_error = NULL;
dbus_bool_t name_has_owner;
g_return_val_if_fail (*error == NULL, NULL);
dbus_error_init (&dbus_error);
/* Check for moonshot server and start the service if possible. We use
* libdbus here because dbus-glib doesn't handle autostarting the service.
* If/when we move to GDBus this code can become a one-liner.
*/
if (is_setid()) {
*error = moonshot_error_new (MOONSHOT_ERROR_IPC_ERROR,
"Cannot use IPC while setid");
return NULL;
}
#ifdef IPC_DBUS_GLIB
if (getenv("DISPLAY")==NULL) {
connection = dbus_launch_moonshot();
if (connection == NULL) {
*error = moonshot_error_new (MOONSHOT_ERROR_IPC_ERROR,
"Headless dbus launch failed");
return NULL;
}
} else
#endif
{
connection = dbus_g_bus_get (DBUS_BUS_SESSION, &g_error);
if (g_error_matches(g_error, DBUS_GERROR, DBUS_GERROR_NOT_SUPPORTED)) {
/*Generally this means autolaunch failed because probably DISPLAY is unset*/
connection = dbus_launch_moonshot();
if (connection != NULL) {
g_error_free(g_error);
g_error = NULL;
}
}
if (g_error != NULL) {
*error = moonshot_error_new (MOONSHOT_ERROR_IPC_ERROR,
"DBus error: %s",
g_error->message);
g_error_free (g_error);
return NULL;
}
}
dbconnection = dbus_g_connection_get_connection(connection);
name_has_owner = dbus_bus_name_has_owner (dbconnection,
MOONSHOT_DBUS_NAME,
&dbus_error);
if (dbus_error_is_set (&dbus_error)) {
*error = moonshot_error_new (MOONSHOT_ERROR_IPC_ERROR,
"DBus error: %s",
dbus_error.message);
dbus_error_free (&dbus_error);
return NULL;
}
if (! name_has_owner) {
dbus_bus_start_service_by_name (dbconnection,
MOONSHOT_DBUS_NAME,
0,
NULL,
&dbus_error);
if (dbus_error_is_set (&dbus_error)) {
if (strcmp (dbus_error.name + 27, "ServiceUnknown") == 0) {
/* Missing .service file; the moonshot-ui install is broken */
*error = moonshot_error_new (MOONSHOT_ERROR_UNABLE_TO_START_SERVICE,
"The Moonshot service was not found. "
"Please make sure that moonshot-ui is "
"correctly installed.");
} else {
*error = moonshot_error_new (MOONSHOT_ERROR_IPC_ERROR,
"DBus error: %s",
dbus_error.message);
}
dbus_error_free (&dbus_error);
return NULL;
}
}
/* Now the service should be running */
g_error = NULL;
g_proxy = dbus_g_proxy_new_for_name_owner (connection,
MOONSHOT_DBUS_NAME,
MOONSHOT_DBUS_PATH,
MOONSHOT_DBUS_NAME,
&g_error);
//.........这里部分代码省略.........
示例10: message_filter
static DBusHandlerResult
message_filter(DBusConnection * connection, DBusMessage * message, void *data)
{
struct systemd_logind_info *info = data;
struct xf86_platform_device *pdev = NULL;
InputInfoPtr pInfo = NULL;
int ack = 0, pause = 0, fd = -1;
DBusError error;
dbus_int32_t major, minor;
char *pause_str;
dbus_error_init(&error);
if (dbus_message_is_signal(message,
"org.freedesktop.DBus", "NameOwnerChanged")) {
char *name, *old_owner, *new_owner;
dbus_message_get_args(message, &error,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_STRING, &old_owner,
DBUS_TYPE_STRING, &new_owner, DBUS_TYPE_INVALID);
if (dbus_error_is_set(&error)) {
LogMessage(X_ERROR, "systemd-logind: NameOwnerChanged: %s\n",
error.message);
dbus_error_free(&error);
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
if (name && strcmp(name, "org.freedesktop.login1") == 0)
FatalError("systemd-logind disappeared (stopped/restarted?)\n");
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
if (strcmp(dbus_message_get_path(message), info->session) != 0)
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
if (dbus_message_is_signal(message, "org.freedesktop.login1.Session",
"PauseDevice")) {
if (!dbus_message_get_args(message, &error,
DBUS_TYPE_UINT32, &major,
DBUS_TYPE_UINT32, &minor,
DBUS_TYPE_STRING, &pause_str,
DBUS_TYPE_INVALID)) {
LogMessage(X_ERROR, "systemd-logind: PauseDevice: %s\n",
error.message);
dbus_error_free(&error);
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
if (strcmp(pause_str, "pause") == 0) {
pause = 1;
ack = 1;
}
else if (strcmp(pause_str, "force") == 0) {
pause = 1;
}
else if (strcmp(pause_str, "gone") == 0) {
/* Device removal is handled through udev */
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
else {
LogMessage(X_WARNING, "systemd-logind: unknown pause type: %s\n",
pause_str);
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
}
else if (dbus_message_is_signal(message, "org.freedesktop.login1.Session",
"ResumeDevice")) {
if (!dbus_message_get_args(message, &error,
DBUS_TYPE_UINT32, &major,
DBUS_TYPE_UINT32, &minor,
DBUS_TYPE_UNIX_FD, &fd,
DBUS_TYPE_INVALID)) {
LogMessage(X_ERROR, "systemd-logind: ResumeDevice: %s\n",
error.message);
dbus_error_free(&error);
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
} else
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
LogMessage(X_INFO, "systemd-logind: got %s for %u:%u\n",
pause ? "pause" : "resume", major, minor);
pdev = xf86_find_platform_device_by_devnum(major, minor);
if (!pdev)
pInfo = systemd_logind_find_info_ptr_by_devnum(xf86InputDevs,
major, minor);
if (!pdev && !pInfo) {
LogMessage(X_WARNING, "systemd-logind: could not find dev %u:%u\n",
major, minor);
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
if (pause) {
/* Our VT_PROCESS usage guarantees we've already given up the vt */
info->active = info->vt_active = FALSE;
/* Note the actual vtleave has already been handled by xf86Events.c */
if (pdev)
//.........这里部分代码省略.........
示例11: connect_hook
static void
connect_hook(DBusConnection *connection, void *data)
{
struct systemd_logind_info *info = data;
DBusError error;
DBusMessage *msg = NULL;
DBusMessage *reply = NULL;
dbus_int32_t arg;
char *session = NULL;
dbus_error_init(&error);
msg = dbus_message_new_method_call("org.freedesktop.login1",
"/org/freedesktop/login1", "org.freedesktop.login1.Manager",
"GetSessionByPID");
if (!msg) {
LogMessage(X_ERROR, "systemd-logind: out of memory\n");
goto cleanup;
}
arg = getpid();
if (!dbus_message_append_args(msg, DBUS_TYPE_UINT32, &arg,
DBUS_TYPE_INVALID)) {
LogMessage(X_ERROR, "systemd-logind: out of memory\n");
goto cleanup;
}
reply = dbus_connection_send_with_reply_and_block(connection, msg,
DBUS_TIMEOUT, &error);
if (!reply) {
LogMessage(X_ERROR, "systemd-logind: failed to get session: %s\n",
error.message);
goto cleanup;
}
dbus_message_unref(msg);
if (!dbus_message_get_args(reply, &error, DBUS_TYPE_OBJECT_PATH, &session,
DBUS_TYPE_INVALID)) {
LogMessage(X_ERROR, "systemd-logind: GetSessionByPID: %s\n",
error.message);
goto cleanup;
}
session = XNFstrdup(session);
dbus_message_unref(reply);
reply = NULL;
msg = dbus_message_new_method_call("org.freedesktop.login1",
session, "org.freedesktop.login1.Session", "TakeControl");
if (!msg) {
LogMessage(X_ERROR, "systemd-logind: out of memory\n");
goto cleanup;
}
arg = FALSE; /* Don't forcibly take over over the session */
if (!dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &arg,
DBUS_TYPE_INVALID)) {
LogMessage(X_ERROR, "systemd-logind: out of memory\n");
goto cleanup;
}
reply = dbus_connection_send_with_reply_and_block(connection, msg,
DBUS_TIMEOUT, &error);
if (!reply) {
LogMessage(X_ERROR, "systemd-logind: TakeControl failed: %s\n",
error.message);
goto cleanup;
}
dbus_bus_add_match(connection,
"type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',path='/org/freedesktop/DBus'",
&error);
if (dbus_error_is_set(&error)) {
LogMessage(X_ERROR, "systemd-logind: could not add match: %s\n",
error.message);
goto cleanup;
}
/*
* HdG: This is not useful with systemd <= 208 since the signal only
* contains invalidated property names there, rather than property, val
* pairs as it should. Instead we just use the first resume / pause now.
*/
#if 0
snprintf(match, sizeof(match),
"type='signal',sender='org.freedesktop.login1',interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',path='%s'",
session);
dbus_bus_add_match(connection, match, &error);
if (dbus_error_is_set(&error)) {
LogMessage(X_ERROR, "systemd-logind: could not add match: %s\n",
error.message);
goto cleanup;
}
#endif
if (!dbus_connection_add_filter(connection, message_filter, info, NULL)) {
LogMessage(X_ERROR, "systemd-logind: could not add filter: %s\n",
error.message);
goto cleanup;
//.........这里部分代码省略.........
示例12: DBusCreate
void* DBusCreate(FcitxInstance* instance)
{
FcitxDBus *dbusmodule = (FcitxDBus*) fcitx_utils_malloc0(sizeof(FcitxDBus));
FcitxAddon* dbusaddon = FcitxAddonsGetAddonByName(FcitxInstanceGetAddons(instance), FCITX_DBUS_NAME);
dbusmodule->owner = instance;
DBusError err;
if (FcitxInstanceIsTryReplace(instance)) {
fcitx_utils_launch_tool("fcitx-remote", "-e");
sleep(1);
}
dbus_threads_init_default();
// first init dbus
dbus_error_init(&err);
int retry = 0;
DBusConnection* conn = NULL;
char* servicename = NULL;
asprintf(&servicename, "%s-%d", FCITX_DBUS_SERVICE,
fcitx_utils_get_display_number());
/* do session dbus initialize */
do {
if (!getenv("DISPLAY") && !getenv("DBUS_SESSION_BUS_ADDRESS")) {
FcitxLog(WARNING, "Without DISPLAY or DBUS_SESSION_BUS_ADDRESS session bus will not work");
break;
}
/* try to get session dbus */
while (1) {
conn = dbus_bus_get(DBUS_BUS_SESSION, &err);
if (dbus_error_is_set(&err)) {
FcitxLog(WARNING, "Connection Error (%s)", err.message);
dbus_error_free(&err);
dbus_error_init(&err);
}
if (NULL == conn && retry < MAX_RETRY_TIMES) {
retry ++;
sleep(RETRY_INTERVAL * retry);
} else {
break;
}
}
if (NULL == conn) {
break;
}
if (!dbus_connection_add_filter(conn, DBusModuleFilter, dbusmodule, NULL))
break;
if (!dbus_connection_set_watch_functions(conn, DBusAddWatch, DBusRemoveWatch,
NULL, &dbusmodule->watches, NULL)) {
FcitxLog(WARNING, "Add Watch Function Error");
dbus_error_free(&err);
dbus_error_init(&err);
dbus_connection_unref(conn);
conn = NULL;
break;
}
/* from here we know dbus connection is successful, now we need to register the service */
dbus_connection_set_exit_on_disconnect(conn, FALSE);
dbusmodule->conn = conn;
boolean request_retry = false;
int replaceCountdown = FcitxInstanceIsTryReplace(instance) ? 3 : 0;
FcitxInstanceResetTryReplace(instance);
do {
request_retry = false;
// request a name on the bus
int ret = dbus_bus_request_name(conn, servicename,
DBUS_NAME_FLAG_DO_NOT_QUEUE,
&err);
if (dbus_error_is_set(&err)) {
FcitxLog(WARNING, "Name Error (%s)", err.message);
goto dbus_init_failed;
}
if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
FcitxLog(WARNING, "DBus Service Already Exists");
if (replaceCountdown > 0) {
replaceCountdown --;
fcitx_utils_launch_tool("fcitx-remote", "-e");
/* sleep for a while and retry */
sleep(1);
request_retry = true;
continue;
}
/* if we know fcitx exists, we should exit. */
dbus_error_free(&err);
free(servicename);
//.........这里部分代码省略.........
示例13: listen_signal
void listen_signal()
{
DBusMessage *msg;
DBusMessageIter arg;
DBusConnection *connection;
DBusError err;
int ret;
char *sigvalue;
//step 1. connect DBus
dbus_error_init(&err);
connection = dbus_bus_get(DBUS_BUS_SESSION, &err);
if (dbus_error_is_set(&err)) {
fprintf(stderr, "Connection Error %s\n", err.message);
dbus_error_free(&err);
}
if (connection == NULL) {
return;
}
//step 2. [OPTION] Assign a known name for connection
ret = dbus_bus_request_name(connection, "test.singal.dest", 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 (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
return ;
}
//step 3. Notify DBus daemon, listen test.signal.Type signal
dbus_bus_add_match(connection, "type='signal', interface='test.signal.Type'", &err);
dbus_connection_flush(connection);
if (dbus_error_is_set(&err)) {
fprintf(stderr, "Match Error %s\n", err.message);
dbus_error_free(&err);
}
//step 4. listen in loop per 1s.
while (1) {
dbus_connection_read_write(connection, 0);
msg = dbus_connection_pop_message(connection);
if (msg == NULL) {
sleep(1);
continue;
}
if (dbus_message_is_signal(msg, "test.signal.Type", "Test")) {
if (!dbus_message_iter_init(msg, &arg)) {
fprintf(stderr, "Message Has no Param");
} else if (dbus_message_iter_get_arg_type(&arg) != DBUS_TYPE_STRING) {
g_printerr("Param is not string");
} else {
dbus_message_iter_get_basic(&arg, &sigvalue);
printf("Got singal with value: %s\n", sigvalue);
}
}
dbus_message_unref(msg);
}//End of while
}
示例14: add_network_printer
int
add_network_printer(LibHalContext *ctx, char *base, char *hostaddr,
char *device, char *community)
{
DBusError error;
int rc = -1;
char udi[128];
char *tmp_udi = NULL;
static char *parent = NULL;
char *manufacturer = NULL, *model = NULL, *description = NULL,
*uri = NULL, *sn, *serial;
sn = serial = pseudo_serialno_from_addr(hostaddr);
if (parent == NULL)
parent = getenv("UDI");
dbus_error_init(&error);
network_device_name_to_udi(udi, sizeof (udi), base, serial, NULL);
if (libhal_device_exists(ctx, udi, &error) == TRUE)
goto out;
if ((tmp_udi = libhal_new_device(ctx, &error)) == NULL)
goto out;
snmp_printer_info(hostaddr, community, &manufacturer, &model,
&description, &serial, NULL, &uri);
libhal_device_set_property_string(ctx, tmp_udi,
"info.parent", parent, &error);
libhal_device_set_property_string(ctx, tmp_udi,
"info.category", "printer", &error);
libhal_device_property_strlist_append(ctx, tmp_udi,
"info.capabilities", "printer", &error);
libhal_device_property_strlist_append(ctx, tmp_udi,
"info.capabilities", "network_device", &error);
libhal_device_set_property_string(ctx, tmp_udi,
"network_device.address", hostaddr, &error);
if ((community != NULL) && (strcasecmp(community, "public") != 0))
libhal_device_set_property_string(ctx, tmp_udi,
"network_device.snmp_community", community, &error);
if ((uri != NULL) || (device != NULL))
libhal_device_set_property_string(ctx, tmp_udi,
"printer.device", (uri ? uri : device), &error);
if (serial != NULL)
libhal_device_set_property_string(ctx, tmp_udi,
"printer.serial", serial, &error);
if (manufacturer != NULL)
libhal_device_set_property_string(ctx, tmp_udi,
"printer.vendor", manufacturer, &error);
if (model != NULL)
libhal_device_set_property_string(ctx, tmp_udi,
"printer.product", model, &error);
if (description != NULL)
libhal_device_set_property_string(ctx, tmp_udi,
"printer.description", description, &error);
/* commit the changes to the new UDI */
rc = libhal_device_commit_to_gdl(ctx, tmp_udi, udi, &error);
out:
HAL_DEBUG(("result: %s (%s): %s, %s, %s, %s, %s", hostaddr, udi,
NP(manufacturer), NP(model), NP(description), NP(serial),
NP(uri)));
if (tmp_udi != NULL)
free(tmp_udi);
if (manufacturer != NULL)
free(manufacturer);
if (model != NULL)
free(model);
if (description != NULL)
free(description);
if (uri != NULL)
free(uri);
if (sn != NULL)
free(sn);
if (dbus_error_is_set(&error)) {
HAL_WARNING(("%s: %s", error.name, error.message));
dbus_error_free(&error);
}
HAL_DEBUG(("add: %s (%s)", hostaddr, udi));
return (rc);
}
示例15: track_pulseaudio_on_dbus
static void track_pulseaudio_on_dbus(pa_context *c, DBusBusType type, pa_dbus_wrap_connection **conn) {
DBusError error;
pa_assert(c);
pa_assert(conn);
dbus_error_init(&error);
if (!(*conn = pa_dbus_wrap_connection_new(c->mainloop, c->use_rtclock, type, &error)) || dbus_error_is_set(&error)) {
pa_log_warn("Unable to contact DBUS: %s: %s", error.name, error.message);
goto fail;
}
if (!dbus_connection_add_filter(pa_dbus_wrap_connection_get(*conn), filter_cb, c, NULL)) {
pa_log_warn("Failed to add filter function");
goto fail;
}
c->filter_added = TRUE;
if (pa_dbus_add_matches(
pa_dbus_wrap_connection_get(*conn), &error,
"type='signal',sender='" DBUS_SERVICE_DBUS "',interface='" DBUS_INTERFACE_DBUS "',member='NameOwnerChanged',arg0='org.pulseaudio.Server',arg1=''", NULL) < 0) {
pa_log_warn("Unable to track org.pulseaudio.Server: %s: %s", error.name, error.message);
goto fail;
}
return;
fail:
if (*conn) {
pa_dbus_wrap_connection_free(*conn);
*conn = NULL;
}
dbus_error_free(&error);
}