Ejemplo n.º 1
0
DsmeDbusMessage* dsme_dbus_signal_new(const char* path,
                                      const char* interface,
                                      const char* name)
{
  DsmeDbusMessage* s = 0;
  DBusError        error;
  DBusConnection*  connection;

  if (path && interface && name) {
      dbus_error_init(&error);

      // TODO: we only use the system bus
      if ((connection = dsme_dbus_get_connection(&error))) {
          s = g_new(DsmeDbusMessage, 1);

          s->connection = connection;
          s->msg        = dbus_message_new_signal(path, interface, name);

          dbus_message_iter_init_append(s->msg, &s->iter);
      }
      dbus_error_free(&error);
  }

  return s;
}
Ejemplo n.º 2
0
/* Helper function to check if this module is needed */
static void check_loader_needed(void)
{
    DBusError        err  = DBUS_ERROR_INIT;
    DBusPendingCall *pc   = 0;
    DBusConnection  *conn = 0;
    DBusMessage     *req  = NULL;
    const char      *unit = WLAN_SYSTEMD_UNIT;

    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",
                               "GetUnit");
    if (!req)
        goto cleanup;

    if (!dbus_message_append_args(req,
                            DBUS_TYPE_STRING, &unit,
                            DBUS_TYPE_INVALID)) {
        goto cleanup;
    }

    if (!dbus_connection_send_with_reply(conn, req, &pc, -1))
        goto cleanup;

    if (!pc) {
        dsme_log(LOG_WARNING, "wlanloader: null pending call received");
        goto cleanup;
    }

    if (!dbus_pending_call_set_notify(pc, loader_needed_cb, 0, 0))
        goto cleanup;

cleanup:

    if (pc) dbus_pending_call_unref(pc);
    if (req) dbus_message_unref(req);
    if (conn) dbus_connection_unref(conn);
    dbus_error_free(&err);
}
Ejemplo n.º 3
0
DSME_HANDLER(DSM_MSGTYPE_DBUS_CONNECT, client, msg)
{
    dsme_log(LOG_DEBUG, "usbtracker: DBUS_CONNECT");
    dsme_dbus_bind_signals(&bound, signals);

    /* we are connected on dbus, now we can query
     * charger/usb connection details */

    DBusError        err  = DBUS_ERROR_INIT;
    DBusPendingCall *pc   = 0;
    DBusConnection  *conn = 0;
    DBusMessage     *req  = NULL;

    if( !(conn = dsme_dbus_get_connection(&err)) )
    {
	dsme_log(LOG_ERR, "system bus connect: %s: %s",
		 err.name, err.message);
        goto cleanup;
    }

    req = dbus_message_new_method_call("com.meego.usb_moded",
                                       "/com/meego/usb_moded",
                                       "com.meego.usb_moded",
                                       "mode_request");
    if( !req )
        goto cleanup;

    if( !dbus_connection_send_with_reply(conn, req, &pc, -1) )
        goto cleanup;

    if( !dbus_pending_call_set_notify(pc, mode_request_cb, 0, 0) )
        goto cleanup;

    dsme_log(LOG_DEBUG, "usbtracker: mode_request sent");

cleanup:

    if( pc ) dbus_pending_call_unref(pc);
    if( req ) dbus_message_unref(req);
    if( conn ) dbus_connection_unref(conn);
    dbus_error_free(&err);
}
Ejemplo n.º 4
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);
}
Ejemplo n.º 5
0
static Filter* filter_new(void* child, FilterMessageHandler* handler)
{
  DBusError       error;
  DBusConnection* connection;
  Filter*         filter = 0;

  dbus_error_init(&error);

  // TODO: we only use the system bus
  if ((connection = dsme_dbus_get_connection(&error)) == 0) {
    dsme_log(LOG_ERR, "system bus connect failed: %s", error.message);
    dbus_error_free(&error);
  } else {

    dbus_connection_setup_with_g_main(connection, 0);
    filter = g_new(Filter, 1);

    if (!dbus_connection_add_filter(connection,
                                    filter_static_message_handler,
                                    filter,
                                    0))
    {
      dsme_log(LOG_ERR, "dbus_connection_add_filter() failed");
      g_free(filter);
      filter = 0;
    } else {

      filter->connection = connection;
      filter->child      = child;
      filter->handler    = handler;

    }
  }

  return filter;
}