EAPI Eina_Bool
eldbus_signal_handler_match_extra_vset(Eldbus_Signal_Handler *sh, va_list ap)
{
   const char *key = NULL, *read;
   DBusError err;

   ELDBUS_SIGNAL_HANDLER_CHECK_RETVAL(sh, EINA_FALSE);

   dbus_error_init(&err);
   dbus_bus_remove_match(sh->conn->dbus_conn,
                         eina_strbuf_string_get(sh->match), &err);
   EINA_SAFETY_ON_TRUE_RETURN_VAL(dbus_error_is_set(&err), EINA_FALSE);

   for (read = va_arg(ap, char *); read; read = va_arg(ap, char *))
     {
        Signal_Argument *arg;

        if (!key)
          {
             key = read;
             continue;
          }
        arg = calloc(1, sizeof(Signal_Argument));
        EINA_SAFETY_ON_NULL_GOTO(arg, error);
        if (!strncmp(key, ARGX, strlen(ARGX)))
          {
             int id = atoi(key + strlen(ARGX));
             arg->index = (unsigned short) id;
             arg->value = eina_stringshare_add(read);
             sh->args = eina_inlist_sorted_state_insert(sh->args,
                                                        EINA_INLIST_GET(arg),
                                                        _sort_arg,
                                                        sh->state_args);
             _match_append(sh->match, key, read);
          }
        else
          {
             ERR("%s not supported", key);
             free(arg);
          }
        key = NULL;
     }

   dbus_error_init(&err);
   dbus_bus_add_match(sh->conn->dbus_conn,
                      eina_strbuf_string_get(sh->match), &err);
   if (!dbus_error_is_set(&err))
     return EINA_TRUE;

   ERR("Error setting new match.");
   return EINA_FALSE;

error:
   dbus_error_init(&err);
   dbus_bus_add_match(sh->conn->dbus_conn,
                      eina_strbuf_string_get(sh->match), &err);
   if (dbus_error_is_set(&err))
     ERR("Error setting partial extra arguments.");
   return EINA_FALSE;
}
void
HippoDBusIpcProviderImpl::setBusUniqueName(const char *uniqueName)
{
    g_debug("unique name of client: %s", uniqueName ? uniqueName : "NULL");

    if (uniqueName == NULL && busUniqueName_ == NULL)
        return;
    if (uniqueName && busUniqueName_ && strcmp(uniqueName, busUniqueName_) == 0)
        return;
    
    if (busUniqueName_ != NULL && connection_) {
        char *connectedRule = connected_rule(busUniqueName_);
        char *disconnectedRule = disconnected_rule(busUniqueName_);

        // both of these will fail if the matched busUniqueName_ is disconnected,
        // since the bus garbage collects the match rules for nonexistent unique
        // names. we just want to ignore the failure.
        
        g_debug("removing rule %s", connectedRule);
        dbus_bus_remove_match(connection_, connectedRule, NULL);
        g_debug("removing rule %s", disconnectedRule);
        dbus_bus_remove_match(connection_, disconnectedRule, NULL);

        g_free(connectedRule);
        g_free(disconnectedRule);
    }
    
    /* note the new unique name can be NULL */
    busUniqueName_ = g_strdup(uniqueName);

    if (busUniqueName_ != NULL && connection_) {
        char *connectedRule = connected_rule(busUniqueName_);
        char *disconnectedRule = disconnected_rule(busUniqueName_);

        g_debug("adding rule %s", connectedRule);
        dbus_bus_add_match(connection_, connectedRule, NULL);
        g_debug("adding rule %s", disconnectedRule);
        dbus_bus_add_match(connection_, disconnectedRule, NULL);

        g_free(connectedRule);
        g_free(disconnectedRule);
    }
    
    if (busUniqueName_ != NULL)
        notifyRegisterEndpointOpportunity();
    else
        notifyEndpointsInvalidated();
}
static DBusConnection*
connect_to_service (void)
{
	DBusError derr = DBUS_ERROR_INIT;
	DBusConnection *conn;
	const gchar *rule;

	/*
	 * TODO: We currently really have no way to close this connection or do
	 * cleanup, and it's unclear how and whether we need to.
	 */

	if (!dbus_connection) {
		if (!g_getenv ("DBUS_SESSION_BUS_ADDRESS"))
			return NULL;

		conn = dbus_bus_get_private (DBUS_BUS_SESSION, &derr);
		if (conn == NULL) {
			g_message ("couldn't connect to dbus session bus: %s", derr.message);
			dbus_error_free (&derr);
			return NULL;
		}

		dbus_connection_set_exit_on_disconnect (conn, FALSE);

		/* Listen for the completed signal */
		rule = "type='signal',interface='org.mate.secrets.Prompt',member='Completed'";
		dbus_bus_add_match (conn, rule, NULL);

		/* Listen for name owner changed signals */
		rule = "type='signal',member='NameOwnerChanged',interface='org.freedesktop.DBus'";
		dbus_bus_add_match (conn, rule, NULL);
		dbus_connection_add_filter (conn, on_name_changed_filter, NULL, NULL);

		G_LOCK (dbus_connection);
		{
			if (dbus_connection) {
				dbus_connection_unref (conn);
			} else {
				egg_dbus_connect_with_mainloop (conn, NULL);
				dbus_connection = conn;
			}
		}
		G_UNLOCK (dbus_connection);
	}

	return dbus_connection_ref (dbus_connection);
}
CLogindUPowerSyscall::CLogindUPowerSyscall()
{
  m_delayLockFd = -1;
  m_lowBattery = false;

  CLog::Log(LOGINFO, "Selected Logind/UPower as PowerSyscall");

  // Check if we have UPower. If not, we avoid any battery related operations.
  CDBusMessage message("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.UPower", "EnumerateDevices");
  m_hasUPower = message.SendSystem() != NULL;

  if (!m_hasUPower)
    CLog::Log(LOGINFO, "LogindUPowerSyscall - UPower not found, battery information will not be available");

  m_canPowerdown = LogindCheckCapability("CanPowerOff");
  m_canReboot    = LogindCheckCapability("CanReboot");
  m_canHibernate = LogindCheckCapability("CanHibernate");
  m_canSuspend   = LogindCheckCapability("CanSuspend");

  InhibitDelayLock();

  m_batteryLevel = 0;
  if (m_hasUPower)
    UpdateBatteryLevel();

  DBusError error;
  dbus_error_init(&error);
  m_connection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);

  if (dbus_error_is_set(&error))
  {
    CLog::Log(LOGERROR, "LogindUPowerSyscall: Failed to get dbus connection: %s", error.message);
    dbus_connection_close(m_connection);
    dbus_connection_unref(m_connection);
    m_connection = NULL;
    dbus_error_free(&error);
    return;
  }

  dbus_connection_set_exit_on_disconnect(m_connection, false);
  dbus_bus_add_match(m_connection, "type='signal',interface='org.freedesktop.login1.Manager',member='PrepareForSleep'", NULL);

  if (m_hasUPower)
    dbus_bus_add_match(m_connection, "type='signal',interface='org.freedesktop.UPower',member='DeviceChanged'", NULL);

  dbus_connection_flush(m_connection);
  dbus_error_free(&error);
}
Beispiel #5
0
gboolean rtdbus_add_signal_rule_and_filter(
        const char *path, const char *interface,
        DBusHandleMessageFunction filter_fn)
{
    DBusError derror;
    char *match_rule;

    dbus_error_init(&derror);
    match_rule = g_strdup_printf(
            "type='signal',path='%s',interface='%s'",
            path, interface);
    dbus_bus_add_match(rtdbus_connection, match_rule, &derror);
    if (dbus_error_is_set(&derror))
    {
        rtdbus_whinge(&derror, _("Unable to add D-BUS signal match rule"));
        return FALSE;
    }
    if (!dbus_connection_add_filter(rtdbus_connection,
            filter_fn, NULL, NULL))
    {
        rtdbus_whinge(&derror, _("Unable to install D-BUS message filter"));
        return FALSE;
    }
    return TRUE;
}
Beispiel #6
0
void
initdbus(void) {
    int ret;
    dbus_error_init(&dbus_err);
    dbus_conn = dbus_bus_get(DBUS_BUS_SESSION, &dbus_err);
    if(dbus_error_is_set(&dbus_err)) {
        fprintf(stderr, "Connection Error (%s)\n", dbus_err.message);
        dbus_error_free(&dbus_err);
    }
    if(dbus_conn == NULL) {
        fprintf(stderr, "dbus_con == NULL\n");
        exit(EXIT_FAILURE);
    }

    ret = dbus_bus_request_name(dbus_conn, "org.freedesktop.Notifications",
            DBUS_NAME_FLAG_REPLACE_EXISTING, &dbus_err);
    if(dbus_error_is_set(&dbus_err)) {
        fprintf(stderr, "Name Error (%s)\n", dbus_err.message);
    }
    if(DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
        fprintf(stderr, "There's already another notification-daemon running\n");
        exit(EXIT_FAILURE);
    }

    dbus_bus_add_match(dbus_conn,
            "type='signal',interface='org.freedesktop.Notifications'",
            &dbus_err);
    if(dbus_error_is_set(&dbus_err)) {
        fprintf(stderr, "Match error (%s)\n", dbus_err.message);
        exit(EXIT_FAILURE);
    }
}
void
nsNetworkManagerListener::RegisterWithConnection(DBusConnection* connection) {
  DBusError error;
  dbus_error_init(&error);
  
  dbus_bus_add_match(connection,
                     "type='signal',"
                     "interface='" NM_DBUS_INTERFACE "',"
                     "sender='" NM_DBUS_SERVICE "',"
                     "path='" NM_DBUS_PATH "'", &error);
  mOK = !dbus_error_is_set(&error);
  dbus_error_free(&error);
  if (!mOK)
    return;
  
  DBusMessage* msg =
    dbus_message_new_method_call(NM_DBUS_SERVICE, NM_DBUS_PATH,
                                 NM_DBUS_INTERFACE, "state");
  if (!msg) {
    mOK = PR_FALSE;
    return;
  }
  
  DBusPendingCall* reply = mDBUS->SendWithReply(this, msg);
  if (!reply) {
    mOK = PR_FALSE;
    return;
  }

  dbus_pending_call_set_notify(reply, NetworkStatusNotify, this, NULL);
  dbus_pending_call_unref(reply);
}
Beispiel #8
0
int elektraDbusReceiveMessage (DBusBusType type, DBusHandleMessageFunction filter_func)
{
    DBusConnection *connection;
    DBusError error;

    dbus_error_init (&error);
    connection = dbus_bus_get (type, &error);
    if (connection == NULL)
    {
        fprintf (stderr, "Failed to open connection to %s message bus: %s\n",
                 (type == DBUS_BUS_SYSTEM) ? "system" : "session",
                 error.message);
        goto error;
    }

    dbus_bus_add_match (connection, "type='signal',interface='org.libelektra',path='/org/libelektra/configuration'", &error);
    if (dbus_error_is_set (&error)) goto error;

    if (!dbus_connection_add_filter (connection, filter_func, NULL, NULL))
    {
        goto error;
    }

    while (dbus_connection_read_write_dispatch(connection, -1));
    return 0;
error:
    printf ("Error occurred\n");
    dbus_error_free (&error);
    return -1;
}
static void
setup_network_monitor (MateWeatherApplet *gw_applet)
{
    GError *error;
    static DBusGConnection *bus = NULL;
    DBusConnection *dbus;

    if (bus == NULL) {
        error = NULL;
        bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
        if (bus == NULL) {
            g_warning ("Couldn't connect to system bus: %s",
                       error->message);
            g_error_free (error);

            return;
        }

        dbus = dbus_g_connection_get_connection (bus);	
        dbus_connection_add_filter (dbus, filter_func, gw_applet, NULL);
        dbus_bus_add_match (dbus,
                            "type='signal',"
                            "interface='" NM_DBUS_INTERFACE "'",
                            NULL);
    }
}	
Beispiel #10
0
int dbusrecv_addrules(dbusrecv_hdl_st *p_dbusrecv_hdl, char *interface, char *method)
{
    char rules[256] = {0};

    if (NULL == p_dbusrecv_hdl)
    {
        printf("dbusrecv_addrules: invalid parameter, p_dbusrecv_hdl!");
        return -1;
    }
    if (NULL == interface)
    {
        printf("dbusrecv_addrules: invalid parameters, interface couldn't be NULL!\n");
        return -1;
    }
    memset(rules, 0x0, sizeof(rules));
    sprintf(rules, "type='signal', interface='%s'", interface);
    /*
        match options:
                type
                interface;
                member;
                sender;
                destination;
                path;
    */
    dbus_bus_add_match (p_dbusrecv_hdl->connection, rules, &p_dbusrecv_hdl->error);
    if (dbus_error_is_set (&p_dbusrecv_hdl->error))
    {
        printf("%s: add match(%s) failed\n", __FILE__, rules);
        return -1;
    }
    return 0;
}
Beispiel #11
0
void pm_upower_init()
{
    DBusError error;

    dbus_error_init(&error);
    DBusConnection *conn = dbus_bus_get(DBUS_BUS_SYSTEM, &error);

    if (dbus_error_is_set(&error)) {
        g_error("Cannot get System BUS connection: %s", error.message);
        dbus_error_free(&error);
        return;
    }

    dbus_connection_setup_with_g_main(conn, NULL);

    dbus_bus_add_match(conn, RULE, &error);

    if (dbus_error_is_set(&error)) {
        g_error("Cannot add D-BUS match rule, cause: %s", error.message);
        dbus_error_free(&error);
        return;
    }

    dbus_connection_add_filter(conn, signal_filter, NULL, NULL);

}
Beispiel #12
0
int pa_dbus_add_matches(DBusConnection *c, DBusError *error, ...) {
    const char *t;
    va_list ap;
    unsigned k = 0;

    pa_assert(c);
    pa_assert(error);

    va_start(ap, error);
    while ((t = va_arg(ap, const char*))) {
        dbus_bus_add_match(c, t, error);

        if (dbus_error_is_set(error))
            goto fail;

        k++;
    }
    va_end(ap);
    return 0;

fail:

    va_end(ap);
    va_start(ap, error);
    for (; k > 0; k--) {
        pa_assert_se(t = va_arg(ap, const char*));
        dbus_bus_remove_match(c, t, NULL);
    }
    va_end(ap);

    return -1;
}
Beispiel #13
0
static bool client_bind(Client*          client,
                        DsmeDbusHandler* handler,
                        const char*      interface,
                        const char*      name)
{
  bool        bound        = false;
  const char* match_format = "type='signal', interface='%s', member='%s'";
  char*       match;
  DBusError   error;

  dispatcher_list_add(client->handlers,
                      handler_dispatcher_new(handler, interface, name));

  match = malloc(strlen(match_format) +
                 strlen(interface)    +
                 strlen(name) - 3);
  sprintf(match, match_format, interface, name);

  dbus_error_init(&error);
  dbus_bus_add_match(client->filter->connection, match, &error);
  free(match);

  if (dbus_error_is_set(&error)) {
      dsme_log(LOG_DEBUG, "dbus_bus_add_match(): %s", error.message);
      dbus_error_free(&error);
  } else {
      dsme_log(LOG_DEBUG, "bound handler for: %s, %s", interface, name);
      bound = true;
  }

  return bound;
}
Beispiel #14
0
void* dbus_listen_for_signals(void* user_data)
{
	DBusError error;
	dbus_error_init(&error);

	GMainContext* mainContext=g_main_context_new();
	GMainLoop* loop = g_main_loop_new (mainContext, 0);

	dbus_g_thread_init();

	bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
	if (bus == NULL) {
		g_printerr("Failed to open connection to bus: %s", error.message);
		dbus_error_free(&error);
		return NULL;
	}

	dbus_connection_setup_with_g_main (bus, mainContext);

	dbus_bus_add_match(bus, "interface='" SERVICE_NAME "'", &error);
	if(dbus_connection_add_filter(bus, signal_filter, user_data, NULL)==FALSE)
		qDebug("dbus_connection_add_filter returned false !\n");

	g_main_loop_run(loop);

	return NULL;
}
bool
DBusThread::SetUpEventLoop()
{
  // If we already have a connection, exit
  if (mConnection) {
    return false;
  }

  dbus_threads_init_default();
  DBusError err;
  dbus_error_init(&err);

  // If we can't establish a connection to dbus, nothing else will work
  nsresult rv = EstablishDBusConnection();
  if (NS_FAILED(rv)) {
    NS_WARNING("Cannot create DBus Connection for DBus Thread!");
    return false;
  }

  // Set which messages will be processed by this dbus connection.
  // Since we are maintaining a single thread for all the DBus bluez
  // signals we want, register all of them in this thread at startup.
  // The event handler will sort the destinations out as needed.
  for (uint32_t i = 0; i < ArrayLength(DBUS_SIGNALS); ++i) {
    dbus_bus_add_match(mConnection,
                       DBUS_SIGNALS[i],
                       &err);
    if (dbus_error_is_set(&err)) {
      LOG_AND_FREE_DBUS_ERROR(&err);
      return false;
    }
  }
  return true;
}
int
main (int argc, char **argv)
{
  GMainLoop *loop;
  DBusConnection *bus;
  DBusError error;

  loop = g_main_loop_new (NULL, FALSE);

  dbus_error_init (&error);
  bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
  if (!bus) {
    g_warning ("Failed to connect to the D-BUS daemon: %s", error.message);
    dbus_error_free (&error);
    return 1;
  }
  dbus_connection_setup_with_g_main (bus, NULL);

  /* listening to messages from all objects as no path is specified */
  dbus_bus_add_match (bus, "type='signal',interface='com.burtonini.dbus.Signal'", &error);
  dbus_connection_add_filter (bus, signal_filter, loop, NULL);

  g_main_loop_run (loop);
  return 0;
}
Beispiel #17
0
void plugin_init(void)
{
	DBusError error;

    object_hash=g_hash_table_new(g_str_hash, g_str_equal);
	object_count=g_hash_table_new(g_str_hash, g_str_equal);
	dbg(0,"enter 1\n");
	dbus_error_init(&error);
	connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
	if (!connection) {
		dbg(0,"Failed to open connection to session message bus: %s\n", error.message);
		dbus_error_free(&error);
		return;
	}
	dbus_connection_setup_with_g_main(connection, NULL);
#if 0
	dbus_connection_add_filter(connection, filter, NULL, NULL);
	dbus_bus_add_match(connection, "type='signal',""interface='" DBUS_INTERFACE_DBUS  "'", &error);
#endif
	dbus_connection_register_fallback(connection, object_path, &dbus_navit_vtable, NULL);
	dbus_bus_request_name(connection, service_name, 0, &error);
	if (dbus_error_is_set(&error)) {
		dbg(0,"Failed to request name: %s", error.message);
		dbus_error_free (&error);
	}
}
Beispiel #18
0
static gboolean
init_dbus ()
{
	DBusError error;

	dbus_error_init (&error);
	bus = dbus_bus_get (DBUS_BUS_SYSTEM, &error);

	dbus_connection_setup_with_g_main (bus, NULL);

	if (dbus_error_is_set (&error)) {
		g_error ("Net Monitor: Couldn't connect to system bus : %s: %s\n", error.name, error.message);
		return FALSE;
	}

	dbus_connection_add_filter (bus, filter_func, NULL, NULL);
	dbus_bus_add_match (bus, "type='signal',interface='" NM_INTERFACE "'", &error);

	if (dbus_error_is_set (&error)) {
		g_error ("Net Monitor: Could not register signal handler: %s: %s\n", error.name, error.message);
		return FALSE;
	}

	return TRUE;
}
Beispiel #19
0
static int dbus_mainloop(void)
{
    GMainLoop *mainloop;
    DBusError error;

    mainloop = g_main_loop_new(NULL, FALSE);

    dbus_error_init(&error);
    connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
    if (dbus_error_is_set(&error)) {
	syslog(LOG_CRIT, "%s: %s", error.name, error.message);
	return 3;
    }

    dbus_bus_add_match(connection, "type='signal'", &error);
    if (dbus_error_is_set(&error)) {
	syslog(LOG_CRIT, "unable to add match for signals %s: %s", error.name,
	       error.message);
	return 4;
    }

    if (!dbus_connection_add_filter
	(connection, (DBusHandleMessageFunction) signal_handler, NULL,
	 NULL)) {
	syslog(LOG_CRIT, "unable to register filter with the connection");
	return 5;
    }

    dbus_connection_setup_with_g_main(connection, NULL);

    print_gpx_header();
    g_main_loop_run(mainloop);
    return 0;
}
Beispiel #20
0
CUPowerSyscall::CUPowerSyscall()
{
  CLog::Log(LOGINFO, "Selected UPower as PowerSyscall");

  m_lowBattery = false;

  //! @todo do not use dbus_connection_pop_message() that requires the use of a
  //! private connection
  if (m_connection.Connect(DBUS_BUS_SYSTEM, true))
  {
    dbus_connection_set_exit_on_disconnect(m_connection, false);

    CDBusError error;
    dbus_bus_add_match(m_connection, "type='signal',interface='org.freedesktop.UPower'", error);
    dbus_connection_flush(m_connection);

    if (error)
    {
      error.Log("UPower: Failed to attach to signal");
      m_connection.Destroy();
    }
  }

  m_CanPowerdown = false;
  m_CanReboot    = false;

  UpdateCapabilities();

  EnumeratePowerSources();
}
Beispiel #21
0
static int
mce_sink_initialize (NSinkInterface *iface)
{
    (void) iface;
    DBusError       error;

    dbus_error_init (&error);
    bus = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
    if (bus == NULL) {
        N_WARNING ("%s >> failed to get system bus: %s", __FUNCTION__, error.message);
        dbus_error_free (&error);
        return FALSE;
    }

    char *rule = "type='signal',interface='" MCE_SIGNAL_IF "'";
    dbus_bus_add_match(bus, rule, &error);
    if (dbus_error_is_set(&error)) {
        N_WARNING ("%s >> failed to add D-BUS match rule, cause: %s", __FUNCTION__, error.message);
        dbus_error_free (&error);
        return FALSE;
    }

    dbus_connection_add_filter(bus, mce_signal_filter, NULL, NULL);

    return TRUE;
}
int start_devicelock_listener(void)
{
  DBusError       err = DBUS_ERROR_INIT;
  DBusConnection *dbus_conn_devicelock = NULL;

  if( (dbus_conn_devicelock = dbus_bus_get(DBUS_BUS_SYSTEM, &err)) == 0 )
  {
	 log_err("Could not connect to dbus for devicelock\n"); 
	 goto cleanup;
  }

  dbus_bus_add_match(dbus_conn_devicelock, MATCH_DEVICELOCK_SIGNALS, &err);
  if( dbus_error_is_set(&err) )
  {
    goto cleanup;
  }
  if( !dbus_connection_add_filter(dbus_conn_devicelock, devicelock_unlocked_cb , 0, 0) )
  {
        log_err("adding system dbus filter for devicelock failed");
    goto cleanup;
  }
  dbus_connection_setup_with_g_main(dbus_conn_devicelock, NULL);

cleanup:
  dbus_error_free(&err);
  return(1);
}
gboolean _init_dbus_signal(void)
{
	DBG("+\n");
	DBusGConnection *conn;
	GError *err = NULL;
	DBusError dbus_error;

	conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &err);
	if(!conn) {
		ERR(" DBUS get failed\n");
		g_error_free(err);
		return FALSE;
	}
	dbus_connection = dbus_g_connection_get_connection(conn);

	/* Add the filter for network client functions */
	dbus_error_init(&dbus_error);
	dbus_connection_add_filter(dbus_connection, __dbus_event_filter, NULL, NULL);
	dbus_bus_add_match(dbus_connection,
			   "type=signal,interface=" NETWORK_SERIAL_INTERFACE
			   ",member=ready_for_serial", &dbus_error);
	if (dbus_error_is_set(&dbus_error)) {
		ERR("Fail to add dbus filter signal\n");
		dbus_error_free(&dbus_error);
	}

	DBG("-\n");
	return TRUE;
}
void addSignalWatch(
		Signals* signals,
		char* busname,
		char* objectpath,
		char* interface,
		char* signalname)
{
	DBusError dbusError;
	dbus_error_init(&dbusError);
	bstring rule = createRule(busname, objectpath, interface, signalname);

	char* cstr_rule = bstr2cstr(rule,'\0');
	printf("Rule         : %s\n",cstr_rule);

	pthread_mutex_lock(&signals->dbus_mutex);
	dbus_bus_add_match(signals->con,cstr_rule,&dbusError);
	pthread_mutex_unlock(&signals->dbus_mutex);
	if (dbus_error_is_set(&dbusError)) {
		fprintf(stderr, "%s %d: Error occurred: %s\n",__FILE__,__LINE__, dbusError.message);
		dbus_error_free(&dbusError);
	}

	bcstrfree(cstr_rule);
	bdestroy(rule);
}
Beispiel #25
0
static int
vehicle_gpsd_dbus_open(struct vehicle_priv *priv)
{
	DBusError error;

	dbus_error_init(&error);
	if (priv->address) {
		priv->connection = dbus_connection_open(priv->address, &error);
	} else {
		priv->connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
	}
	if (!priv->connection) {
		dbg(0,"Failed to open connection to %s message bus: %s\n", priv->address?priv->address:"session",error.message);
		dbus_error_free(&error);
		return 0;
	}
	dbus_connection_setup_with_g_main(priv->connection, NULL);
	dbus_bus_add_match(priv->connection,"type='signal',interface='org.gpsd'",&error);
	dbus_connection_flush(priv->connection);
	if (dbus_error_is_set(&error)) {
		dbg(0,"Failed to add match to connection: %s\n", error.message);
		vehicle_gpsd_dbus_close(priv);
		return 0;
	}
	if (!dbus_connection_add_filter(priv->connection, vehicle_gpsd_dbus_filter, priv, NULL)) {
		dbg(0,"Failed to add filter to connection\n");
		vehicle_gpsd_dbus_close(priv);
		return 0;
	}
	return 1;
}
Beispiel #26
0
static int supplicant_create(void)
{
	if (g_slist_length(driver_list) > 0)
		return 0;

	connection = connman_dbus_get_connection();
	if (connection == NULL)
		return -EIO;

	_DBG_SUPPLICANT("connection %p", connection);

	if (dbus_connection_add_filter(connection,
				supplicant_filter, NULL, NULL) == FALSE) {
		connection = connman_dbus_get_connection();
		return -EIO;
	}

	dbus_bus_add_match(connection, supplicant_rule, NULL);
	dbus_connection_flush(connection);

	watch = g_dbus_add_service_watch(connection, SUPPLICANT_NAME,
			supplicant_probe, supplicant_remove, NULL, NULL);

	return 0;
}
Beispiel #27
0
CConsoleUPowerSyscall::CConsoleUPowerSyscall()
{
  CLog::Log(LOGINFO, "Selected UPower and ConsoleKit as PowerSyscall");

  m_lowBattery = false;

  dbus_error_init (&m_error);
  // TODO: do not use dbus_connection_pop_message() that requires the use of a
  // private connection
  m_connection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &m_error);

  if (m_connection)
  {
    dbus_connection_set_exit_on_disconnect(m_connection, false);

    dbus_bus_add_match(m_connection, "type='signal',interface='org.freedesktop.UPower'", &m_error);
    dbus_connection_flush(m_connection);
  }

  if (dbus_error_is_set(&m_error))
  {
    CLog::Log(LOGERROR, "UPower: Failed to attach to signal %s", m_error.message);
    dbus_connection_close(m_connection);
    dbus_connection_unref(m_connection);
    m_connection = NULL;
  }

  m_CanPowerdown = ConsoleKitMethodCall("CanStop");
  m_CanReboot    = ConsoleKitMethodCall("CanRestart");

  UpdateUPower();

  EnumeratePowerSources();
}
Beispiel #28
0
    CRJinkeWindowManager( int dx, int dy )
    : CRGUIWindowManager(NULL)
    {
        int bus_fd;
        
        if ( CRJinkeScreen::instance==NULL )
            _screen = new CRJinkeScreen( dx, dy );
        else
            _screen = CRJinkeScreen::instance;
        if ( _screen ) {
            _wid = ((CRJinkeScreen*)_screen)->getWID();
            _ownScreen = true;
            instance = this;

#if ENABLE_DBUS_VIEWER_EVENTS==1
            //dbus, nanox
            m_bus = dbus_bus_get (DBUS_BUS_SESSION, NULL);
            if (!m_bus)
            {
                printf ("Failed to connect to the D-BUS daemon");
                //return 0;
            } else {
                dbus_bus_add_match (m_bus, "type='signal',interface='com.burtonini.dbus.Signal'", NULL);
                dbus_connection_get_unix_fd(m_bus, &bus_fd);
                GrRegisterInput(bus_fd);
            }
#endif
        
        }
    }
Beispiel #29
0
void listen_signal()
{
    DBusMessage * msg;
    DBusMessageIter arg;
    DBusConnection * connection;
    DBusError err;
    int ret;
    char * sigvalue;

     //步骤1:建立与D-Bus后台的连接
    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;

   //步骤2:给连接名分配一个可记忆名字test.singal.dest作为Bus name,这个步骤不是必须的,但推荐这样处理
    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;

    //步骤3:通知D-Bus daemon,希望监听来行接口test.signal.Type的信号
    dbus_bus_add_match(connection,"type='signal',interface='test.signal.Type'",&err);
    //实际需要发送东西给daemon来通知希望监听的内容,所以需要flush
    dbus_connection_flush(connection);
    if(dbus_error_is_set(&err)){
        fprintf(stderr,"Match Error %s/n",err.message);
        dbus_error_free(&err);
    }
   
    //步骤4:在循环中监听,每隔开1秒,就去试图自己的连接中获取这个信号。这里给出的是中连接中获取任何消息的方式,所以获取后去检查一下这个消息是否我们期望的信号,并获取内容。我们也可以通过这个方式来获取method call消息。
    while(1){
        dbus_connection_read_write(connection,0);
        msg = dbus_connection_pop_message (connection);
        if(msg == NULL)
  	{   printf("Sleeping\n");
            sleep(10);
            continue;
        }
	printf("received something\n");
        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)
                fprintf(stderr,"Param is not string");
            else
                dbus_message_iter_get_basic(&arg,&sigvalue);
            printf("Got Singal with value : %s\n\n",sigvalue);
        }
        dbus_message_unref(msg);
    }//End of while
       
}
static DBusConnection *
xdbus_init(void)
{
    DBusError err = DBUS_ERROR_INIT;
    DBusBusType bus_type = DBUS_BUS_SYSTEM;

    if( xdbus_con )
        goto EXIT;

    if( !(xdbus_con = dbus_bus_get(bus_type, &err)) ) {
        log_error("Failed to open connection to message bus"
                  "; %s: %s", err.name, err.message);
        goto EXIT;
    }

    dbus_connection_setup_with_g_main(xdbus_con, 0);

    dbus_connection_add_filter(xdbus_con, xdbus_filter_cb, 0, 0);

    dbus_bus_add_match(xdbus_con, mce_display_ind_rule, 0);

    log_debug("connected to system bus");

EXIT:
    dbus_error_free(&err);
    return xdbus_con;
}