static void server_broadcast(LassiServer *ls, DBusMessage *m, LassiConnection *except) { GList *i; g_assert(ls); g_assert(m); for (i = ls->connections; i; i = i->next) { dbus_bool_t b; LassiConnection *lc = i->data; DBusMessage *n; if (lc == except || !lc->id) continue; n = dbus_message_copy(m); g_assert(n); b = dbus_connection_send(lc->dbus_connection, n, NULL); g_assert(b); dbus_message_unref(n); } }
void gkd_secret_service_emit_collection_deleted (GkdSecretService *self, const gchar *collection_path) { DBusMessage *message; g_return_if_fail (GKD_SECRET_IS_SERVICE (self)); g_return_if_fail (collection_path != NULL); message = dbus_message_new_signal (SECRET_SERVICE_PATH, SECRET_SERVICE_INTERFACE, "CollectionDeleted"); dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &collection_path, DBUS_TYPE_INVALID); if (!dbus_connection_send (self->connection, message, NULL)) g_return_if_reached (); dbus_message_unref (message); emit_collections_properties_changed (self); }
/** * @internal * Send Elektra's D-Bus message. * * @param signalName signal name * @param keyName key name */ static void dbusSendMessage (const char * signalName, const char * keyName) { DBusMessage * message; const char * interface = "org.libelektra"; const char * path = "/org/libelektra/configuration"; DBusConnection * connection = getDbusConnection (testBusType); exit_if_fail (connection != NULL, "could not get bus connection"); message = dbus_message_new_signal (path, interface, signalName); exit_if_fail (message, "could not allocate dbus message"); exit_if_fail (dbus_message_append_args (message, DBUS_TYPE_STRING, &keyName, DBUS_TYPE_INVALID), "could not add message arguments"); dbus_connection_send (connection, message, NULL); dbus_message_unref (message); dbus_connection_unref (connection); return; }
void reply_to_suspend(DBusMessage* msg, DBusConnection* conn) { DBusMessage* reply; char path[128]; FILE* f = fopen(SUSPEND_FILE, "w"); reply = dbus_message_new_method_return(msg); if (!f) { fprintf(stderr, "Unable to open path for writing\n"); return; } snprintf(path, sizeof(path), "mem\n"); fprintf(f, path); fclose(f); dbus_connection_send(conn, reply, NULL); }
int NotificationServer::notifySettingChanged(const std::string pkgId, const std::string privacyId) { if (!m_initialized) return PRIV_FLTR_ERROR_INVALID_STATE; char* pPkgId = const_cast <char*> (pkgId.c_str()); char* pPrivacyId = const_cast <char*> (privacyId.c_str()); DBusMessage* pMessage = dbus_message_new_signal(DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str(), DBUS_SIGNAL_SETTING_CHANGED.c_str()); TryReturn(pMessage != NULL, PRIV_FLTR_ERROR_IPC_ERROR, , "dbus_message_new_signal"); dbus_bool_t r; r = dbus_message_append_args(pMessage, DBUS_TYPE_STRING, &pPkgId, DBUS_TYPE_STRING, &pPrivacyId, DBUS_TYPE_INVALID); TryReturn(r, PRIV_FLTR_ERROR_IPC_ERROR, , "dbus_message_append_args"); r = dbus_connection_send(m_pDBusConnection, pMessage, NULL); TryReturn(r, PRIV_FLTR_ERROR_IPC_ERROR, dbus_message_unref(pMessage);, "dbus_connection_send");
static void launcher_logind_pause_device_complete(struct launcher_logind *wl, uint32_t major, uint32_t minor) { DBusMessage *m; bool b; m = dbus_message_new_method_call("org.freedesktop.login1", wl->spath, "org.freedesktop.login1.Session", "PauseDeviceComplete"); if (m) { b = dbus_message_append_args(m, DBUS_TYPE_UINT32, &major, DBUS_TYPE_UINT32, &minor, DBUS_TYPE_INVALID); if (b) dbus_connection_send(wl->dbus, m, NULL); dbus_message_unref(m); } }
static gboolean stream_setup_retry(gpointer user_data) { struct sink *sink = user_data; struct pending_request *pending = sink->connect; if (sink->state >= AVDTP_STATE_OPEN) { DBusMessage *reply; debug("Stream successfully created, after XCASE connect:connect"); reply = dbus_message_new_method_return(pending->msg); dbus_connection_send(pending->conn, reply, NULL); dbus_message_unref(reply); } else { debug("Stream setup failed, after XCASE connect:connect"); error_failed(pending->conn, pending->msg, "Stream setup failed"); } sink->connect = NULL; pending_request_free(pending); return FALSE; }
/* This test outputs TAP syntax: http://testanything.org/ */ int main (int argc, char *argv[]) { long start_tv_sec, start_tv_usec; long end_tv_sec, end_tv_usec; int i; DBusMessage *method; DBusConnection *conn; DBusError error; printf ("# Testing pending call timeouts\n"); dbus_error_init (&error); conn = dbus_bus_get (DBUS_BUS_SESSION, &error); /* run 100 times to make sure */ for (i = 0; i < 100; i++) { long delta; _dbus_get_monotonic_time (&start_tv_sec, &start_tv_usec); _run_iteration (conn); _dbus_get_monotonic_time (&end_tv_sec, &end_tv_usec); /* we just care about seconds */ delta = end_tv_sec - start_tv_sec; printf ("ok %d - %lis\n", i + 1, delta); } method = dbus_message_new_method_call ("org.freedesktop.TestSuiteEchoService", "/org/freedesktop/TestSuite", "org.freedesktop.TestSuite", "Exit"); dbus_connection_send (conn, method, NULL); dbus_message_unref (method); printf ("# Testing completed\n1..%d\n", i); exit (0); }
static void reset_wlan_module(void) { DBusError err = DBUS_ERROR_INIT; DBusConnection *conn = 0; DBusMessage *req = NULL; const char *unit = WLAN_SYSTEMD_UNIT; const char *mode = "ignore-requirements"; dsme_log(LOG_DEBUG, "wlanloader: Resetting WLAN"); if (!(conn = dsme_dbus_get_connection(&err))) { dsme_log(LOG_ERR, "wlanloader: system bus connect: %s: %s", err.name, err.message); goto cleanup; } req = dbus_message_new_method_call("org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "RestartUnit"); if (!req) goto cleanup; if (!dbus_message_append_args(req, DBUS_TYPE_STRING, &unit, DBUS_TYPE_STRING, &mode, DBUS_TYPE_INVALID)) { goto cleanup; } if (!dbus_connection_send(conn, req, NULL)) goto cleanup; cleanup: if (req) dbus_message_unref(req); if (conn) dbus_connection_unref(conn); dbus_error_free(&err); }
static void database_handle_remove_notify (DBusConnection *conn, DBusMessage *message, GConfDatabase *db) { gchar *namespace_section; DBusMessage *reply; const char *sender; NotificationData *notification; ListeningClientData *client; if (!gconfd_dbus_get_message_args (conn, message, DBUS_TYPE_STRING, &namespace_section, DBUS_TYPE_INVALID)) return; sender = dbus_message_get_sender (message); notification = g_hash_table_lookup (db->notifications, namespace_section); client = g_hash_table_lookup (db->listening_clients, sender); if (client) { client->nr_of_notifications--; if (client->nr_of_notifications == 0) { database_remove_listening_client (db, client); } } /* Notification can be NULL if the client and server get out of sync. */ if (notification == NULL || !database_remove_notification_data (db, notification, sender)) { gconf_log (GCL_DEBUG, _("Notification on %s doesn't exist"), namespace_section); } reply = dbus_message_new_method_return (message); dbus_connection_send (conn, reply, NULL); dbus_message_unref (reply); }
static bool complete_dbus_request(DBusMessage *message, int *sv, struct ucred *rcred, struct ucred *vcred) { char buf[1]; if (!dbus_connection_send(server_conn, message, NULL)) { nih_error("%s: failed to send dbus message", __func__); dbus_message_unref(message); return false; } dbus_connection_flush(server_conn); dbus_message_unref(message); if (proxyrecv(sv[0], buf, 1) != 1) { nih_error("%s: Error getting reply from server over socketpair", __func__); return false; } if (send_creds(sv[0], rcred)) { nih_error("%s: Error sending pid over SCM_CREDENTIAL", __func__); return false; } if (!vcred) // this request only requires one scm_credential return true; if (proxyrecv(sv[0], buf, 1) != 1) { nih_error("%s: Error getting reply from server over socketpair", __func__); return false; } if (send_creds(sv[0], vcred)) { nih_error("%s: Error sending pid over SCM_CREDENTIAL", __func__); return false; } return true; }
static DBusHandlerResult profile_handler(DBusConnection *c, DBusMessage *m, void *userdata) { pa_bluetooth_backend *b = userdata; DBusMessage *r = NULL; const char *path, *interface, *member; pa_assert(b); path = dbus_message_get_path(m); interface = dbus_message_get_interface(m); member = dbus_message_get_member(m); pa_log_debug("dbus: path=%s, interface=%s, member=%s", path, interface, member); if (!pa_streq(path, HSP_AG_PROFILE) && !pa_streq(path, HSP_HS_PROFILE)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (dbus_message_is_method_call(m, "org.freedesktop.DBus.Introspectable", "Introspect")) { const char *xml = PROFILE_INTROSPECT_XML; pa_assert_se(r = dbus_message_new_method_return(m)); pa_assert_se(dbus_message_append_args(r, DBUS_TYPE_STRING, &xml, DBUS_TYPE_INVALID)); } else if (dbus_message_is_method_call(m, BLUEZ_PROFILE_INTERFACE, "Release")) { pa_log_debug("Release not handled"); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } else if (dbus_message_is_method_call(m, BLUEZ_PROFILE_INTERFACE, "RequestDisconnection")) { r = profile_request_disconnection(c, m, userdata); } else if (dbus_message_is_method_call(m, BLUEZ_PROFILE_INTERFACE, "NewConnection")) r = profile_new_connection(c, m, userdata); else return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (r) { pa_assert_se(dbus_connection_send(pa_dbus_connection_get(b->connection), r, NULL)); dbus_message_unref(r); } return DBUS_HANDLER_RESULT_HANDLED; }
int lassi_server_key_event(LassiServer *ls, unsigned key, gboolean is_press) { DBusMessage *n; dbus_bool_t b; if (!ls->active_connection) return -1; n = dbus_message_new_signal("/", LASSI_INTERFACE, "KeyEvent"); g_assert(n); b = dbus_message_append_args(n, DBUS_TYPE_UINT32, &key, DBUS_TYPE_BOOLEAN, &is_press, DBUS_TYPE_INVALID); g_assert(b); b = dbus_connection_send(ls->active_connection->dbus_connection, n, NULL); g_assert(b); dbus_message_unref(n); dbus_connection_flush(ls->active_connection->dbus_connection); return 0; }
static void emit_collections_properties_changed (GkdSecretService *self) { const gchar *iface = SECRET_SERVICE_INTERFACE; DBusMessage *message; DBusMessageIter array; DBusMessageIter iter; message = dbus_message_new_signal (SECRET_SERVICE_PATH, DBUS_INTERFACE_PROPERTIES, "PropertiesChanged"); dbus_message_iter_init_append (message, &iter); dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &iface); service_append_all_properties (self, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "s", &array); dbus_message_iter_close_container (&iter, &array); if (!dbus_connection_send (self->connection, message, NULL)) g_return_if_reached (); dbus_message_unref (message); }
void device_finish_sdp_transaction(struct audio_device *dev) { char address[18], *addr_ptr = address; DBusMessage *msg; ba2str(&dev->dst, address); msg = dbus_message_new_method_call("org.bluez", dev->adapter_path, "org.bluez.Adapter", "FinishRemoteServiceTransaction"); if (!msg) { error("Unable to allocate new method call"); return; } dbus_message_append_args(msg, DBUS_TYPE_STRING, &addr_ptr, DBUS_TYPE_INVALID); dbus_connection_send(dev->conn, msg, NULL); dbus_message_unref(msg); }
gboolean ibus_connection_send (IBusConnection *connection, IBusMessage *message) { g_assert (IBUS_IS_CONNECTION (connection)); g_assert (message != NULL); gboolean retval; IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); retval = dbus_connection_send (priv->connection, message, NULL); if (retval) { g_signal_emit (connection, connection_signals[IBUS_MESSAGE_SENT], 0, message); } return retval; }
int my_test_peek_reply (NihDBusMessage *message, const char * value) { DBusMessage * reply; DBusMessageIter iter; nih_assert (message != NULL); nih_assert (value != NULL); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return 0; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) return -1; dbus_message_iter_init_append (reply, &iter); /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &value)) { dbus_message_unref (reply); return -1; } /* Send the reply, appending it to the outgoing queue. */ if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return -1; } dbus_message_unref (reply); return 0; }
static void listen_for_signal (const char *signal, const char **objects) { DBusMessage *msg = NULL; const char *empty[1] = { NULL }; int count; g_assert (volume_bus); g_assert (signal); msg = dbus_message_new_method_call (NULL, PULSE_CORE_PATH, PULSE_CORE_IF, LISTEN_FOR_METHOD); if (!msg) goto done; if (!objects) objects = empty; for (count = 0; objects[count]; count++); dbus_message_append_args (msg, DBUS_TYPE_STRING, &signal, DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &objects, count, DBUS_TYPE_INVALID); if (dbus_connection_send (volume_bus, msg, NULL)) { int i; N_DEBUG (LOG_CAT "listen for signal %s", signal); for (i = 0; i < count; i++) N_DEBUG (LOG_CAT "- object path: %s", objects[i]); } done: if (msg) dbus_message_unref (msg); }
static DBusHandlerResult request_passkey_message(DBusConnection *conn, DBusMessage *msg) { DBusMessage *reply; DBusError derr; const char *device; char passkey[17]; const char *psk = passkey; reply = dbus_message_new_method_return(msg); if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; dbus_error_init(&derr); if (!dbus_message_get_args(msg, &derr, DBUS_TYPE_OBJECT_PATH, &device, DBUS_TYPE_INVALID)) { fprintf(stderr, "%s", derr.message); dbus_error_free(&derr); return error_message(conn, msg, "org.bluez.Error.Rejected", "Wrong signature"); } if (device) printf("Device: %s\n", device); memset(passkey, 0, sizeof(passkey)); printf("Insert passkey >> "); scanf("%16s", passkey); dbus_message_append_args(reply, DBUS_TYPE_STRING, &psk, DBUS_TYPE_INVALID); dbus_connection_send(conn, reply, NULL); dbus_message_unref(reply); return DBUS_HANDLER_RESULT_HANDLED; }
bool EdbusConnection::send(const EdbusMessage& content) { if(!dc || !dc->conn) return false; bool ret; dbus_uint32_t serial; DBusMessage* msg = content.to_dbus_message(); if(!msg) { E_WARNING(E_STRLOC ": Can't convert to DBusMessage\n"); return false; } if(!dbus_connection_send(dc->conn, msg, &serial)) { E_WARNING(E_STRLOC ": Message sending failed\n"); ret = false; } else ret = true; dbus_connection_flush(dc->conn); return ret; }
static gboolean send_dbus_signal(const char *name, int first_arg_type, ...) { DBusMessage * msg; gboolean result = FALSE; va_list va; va_start(va, first_arg_type); msg = dbus_message_new_signal("/com/nokia/bme/signal", "com.nokia.bme.signal", name); if (msg && dbus_message_append_args_valist(msg, first_arg_type, va) && dbus_connection_send(system_dbus, msg, 0)) { dbus_connection_flush(system_dbus); result = TRUE; } if (msg) dbus_message_unref(msg); return result; }
static dbus_bool_t emit_signal_valist(DBusConnection *conn, const char *path, const char *interface, const char *name, int first, va_list var_args) { DBusMessage *signal; dbus_bool_t ret; const char *signature, *args; if (!check_signal(conn, path, interface, name, &args)) return FALSE; signal = dbus_message_new_signal(path, interface, name); if (signal == NULL) { error("Unable to allocate new %s.%s signal", interface, name); return FALSE; } ret = dbus_message_append_args_valist(signal, first, var_args); if (!ret) goto fail; signature = dbus_message_get_signature(signal); if (strcmp(args, signature) != 0) { error("%s.%s: expected signature'%s' but got '%s'", interface, name, args, signature); ret = FALSE; goto fail; } ret = dbus_connection_send(conn, signal, NULL); fail: dbus_message_unref(signal); return ret; }
DBusHandlerResult FcitxDBusMenuEventHandler(DBusConnection* connection, DBusMessage* message, void* user_data) { FcitxNotificationItem* notificationitem = user_data; DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED; DBusMessage *reply = NULL; boolean flush = false; if (dbus_message_is_method_call(message, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) { reply = dbus_message_new_method_return(message); dbus_message_append_args(reply, DBUS_TYPE_STRING, &dbus_menu_interface, DBUS_TYPE_INVALID); } else if (dbus_message_is_method_call(message, DBUS_MENU_IFACE, "Event")) { /* this is no reply */ FcitxDBusMenuEvent(notificationitem, message); return DBUS_HANDLER_RESULT_HANDLED; } else if (dbus_message_is_method_call(message, DBUS_MENU_IFACE, "GetProperty")) { reply = FcitxDBusMenuGetProperty(notificationitem, message); } else if (dbus_message_is_method_call(message, DBUS_MENU_IFACE, "GetLayout")) { reply = FcitxDBusMenuGetLayout(notificationitem, message); } else if (dbus_message_is_method_call(message, DBUS_MENU_IFACE, "GetGroupProperties")) { reply = FcitxDBusMenuGetGroupProperties(notificationitem, message); } else if (dbus_message_is_method_call(message, DBUS_MENU_IFACE, "AboutToShow")) { reply = FcitxDBusMenuAboutToShow(notificationitem, message); } else if (dbus_message_is_method_call(message, DBUS_INTERFACE_PROPERTIES, "Get")) { reply = FcitxDBusPropertyGet(notificationitem, dbusMenuPropertyTable, message); } else if (dbus_message_is_method_call(message, DBUS_INTERFACE_PROPERTIES, "Set")) { reply = FcitxDBusPropertySet(notificationitem, dbusMenuPropertyTable, message); } else if (dbus_message_is_method_call(message, DBUS_INTERFACE_PROPERTIES, "GetAll")) { reply = FcitxDBusPropertyGetAll(notificationitem, dbusMenuPropertyTable, message); } if (reply) { dbus_connection_send(connection, reply, NULL); dbus_message_unref(reply); if (flush) { dbus_connection_flush(connection); } result = DBUS_HANDLER_RESULT_HANDLED; } return result; }
void wpa_supplicant_dbus_notify_wps_cred(struct wpa_supplicant *wpa_s, const struct wps_credential *cred) { struct wpas_dbus_priv *iface; DBusMessage *_signal = NULL; /* Do nothing if the control interface is not turned on */ if (wpa_s->global == NULL) return; iface = wpa_s->global->dbus; if (iface == NULL) return; _signal = dbus_message_new_signal(wpa_s->dbus_path, WPAS_DBUS_IFACE_INTERFACE, "WpsCred"); if (_signal == NULL) { wpa_printf(MSG_ERROR, "dbus: wpa_supplicant_dbus_notify_wps_cred: " "Could not create dbus signal; likely out of " "memory"); return; } if (!dbus_message_append_args(_signal, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &cred->cred_attr, cred->cred_attr_len, DBUS_TYPE_INVALID)) { wpa_printf(MSG_ERROR, "dbus: wpa_supplicant_dbus_notify_wps_cred: " "Not enough memory to construct signal"); goto out; } dbus_connection_send(iface->con, _signal, NULL); out: dbus_message_unref(_signal); }
int dbusif_send_signal(struct tonegend *tonegend, char *intf, char *name, int first_arg_type, ...) { struct dbusif *dbusif = tonegend->dbus_ctx; DBusMessage *msg; va_list ap; int success; do { /* not a loop */ success = FALSE; if (name == NULL) { LOG_ERROR("%s(): Called with invalid argument", __FUNCTION__); errno = EINVAL; break; } if (intf == NULL) intf = service; if ((msg = dbus_message_new_signal(path, intf, name)) == NULL) { errno = ENOMEM; break; } va_start(ap, first_arg_type); if (dbus_message_append_args_valist(msg, first_arg_type, ap)) { success = dbus_connection_send(dbusif->conn, msg, NULL); } va_end(ap); dbus_message_unref(msg); } while(FALSE); return success ? 0 : -1; }
gboolean g_dbus_send_message(DBusConnection *connection, DBusMessage *message) { dbus_bool_t result; if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_METHOD_CALL) dbus_message_set_no_reply(message, TRUE); else if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_SIGNAL) { const char *path = dbus_message_get_path(message); const char *interface = dbus_message_get_interface(message); const char *name = dbus_message_get_member(message); const GDBusArgInfo *args; if (!check_signal(connection, path, interface, name, &args)) return FALSE; } result = dbus_connection_send(connection, message, NULL); dbus_message_unref(message); return result; }
static void emit_interfaces_added(struct generic_data *data) { DBusMessage *signal; DBusMessageIter iter, array; if (root == NULL || data == root) return; signal = dbus_message_new_signal(root->path, DBUS_INTERFACE_OBJECT_MANAGER, "InterfacesAdded"); if (signal == NULL) return; dbus_message_iter_init_append(signal, &iter); dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, &data->path); dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &array); g_slist_foreach(data->added, append_interface, &array); g_slist_free(data->added); data->added = NULL; dbus_message_iter_close_container(&iter, &array); /* Use dbus_connection_send to avoid recursive calls to g_dbus_flush */ dbus_connection_send(data->conn, signal, NULL); dbus_message_unref(signal); }
void getServerInformation(DBusMessage *dmsg) { DBusMessage *reply; DBusMessageIter args; char *param = ""; const char *info[4] = {"dunst", "dunst", "2011", "2011"}; if (!dbus_message_iter_init(dmsg, &args)) { } else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) { } else { dbus_message_iter_get_basic(&args, ¶m); } reply = dbus_message_new_method_return(dmsg); dbus_message_iter_init_append(reply, &args); if(!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &info[0]) || !dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &info[1]) || !dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &info[2]) || !dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &info[3])) { fprintf(stderr, "Unable to fill arguments"); return; } dbus_serial++; if (!dbus_connection_send(dbus_conn, reply, &dbus_serial)) { fprintf(stderr, "Out Of Memory!\n"); exit(EXIT_FAILURE); } dbus_connection_flush(dbus_conn); dbus_message_unref(reply); }
int mp_dbus_send_signal(const char *path, const char *interface, const char *name, const char *str, int state) { dbus_uint32_t serial = 0; // Create signal DBusMessage *msg = dbus_message_new_signal(path, interface, name); if (msg == NULL) { fprintf(stderr, "DBus: error creating signal\n"); return 0; } // Append arguments if (str != NULL) { DBusMessageIter args; dbus_message_iter_init_append(msg, &args); if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &str)) { fprintf(stderr, "DBus: error building signal\n"); return 0; } if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_UINT32, &state)) { fprintf(stderr, "DBus: error building signal\n"); return 0; } } // Send signal if (!dbus_connection_send(connection, msg, &serial)) { fprintf(stderr, "DBus: error sending signal\n"); return 0; } dbus_connection_flush(connection); // Delete signal dbus_message_unref(msg); return 1; }
static DBusHandlerResult filter_session_message (DBusConnection *connection, DBusMessage *message, void *user_data) { TestServiceData *testdata = user_data; if (dbus_message_is_method_call (message, "org.freedesktop.DBus.TestSuite.PrivServer", "GetPrivateAddress")) { DBusMessage *reply; reply = dbus_message_new_method_return (message); if (reply == NULL) die ("OOM"); if (!dbus_message_append_args (reply, DBUS_TYPE_STRING, &(testdata->private_addr), DBUS_TYPE_INVALID)) die ("OOM"); if (!dbus_connection_send (connection, reply, NULL)) die ("Error sending message"); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else if (dbus_message_is_method_call (message, "org.freedesktop.DBus.TestSuite.PrivServer", "Quit")) { fprintf (stderr, "server exiting loop\n"); _dbus_loop_quit (testdata->loop); return DBUS_HANDLER_RESULT_HANDLED; } return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; }