Exemplo n.º 1
0
/** D-Bus callback for the MCE_CPU_KEEPALIVE_WAKEUP_REQ method call
 *
 * @param msg  The D-Bus message
 *
 * @return TRUE on success, FALSE on failure
 */
static
gboolean
cka_dbus_handle_wakeup_cb(DBusMessage *const msg)
{
  gboolean success = FALSE;

  const char *sender =  0;

  if( !(sender = dbus_message_get_sender(msg)) )
  {
    goto EXIT;
  }

  mce_log(LL_NOTICE, "got keepalive wakeup from %s",
          mce_dbus_get_name_owner_ident(sender));

  cka_clients_handle_wakeup(sender);

  success = TRUE;

EXIT:
  cka_dbusutil_reply_bool(msg, success);

  return success;
}
Exemplo n.º 2
0
/** Find existing / create new client data by dbus name
 *
 * @param dbus_name  dbus name of the client
 *
 * @return client data
 */
static
cka_client_t *
cka_clients_add_client(const gchar *dbus_name)
{
  cka_client_t *client = g_hash_table_lookup(cka_clients_lut, dbus_name);

  if( !client )
  {
    /* Make a dummy peer identification request, so we have it already
     * cached in case we actually need it later on */
    mce_dbus_get_name_owner_ident(dbus_name);

    /* The cka_client_create() adds NameOwnerChanged signal match
     * so that we know when/if the client exits, crashes or
     * otherwise loses dbus connection. */

    client = cka_client_create(dbus_name);
    g_hash_table_insert(cka_clients_lut, g_strdup(dbus_name), client);

    /* Then make an explicit GetNameOwner request to verify that
     * the client is still running when we have the signal
     * listening in the place. */
    cka_clients_verify_name(dbus_name);
  }

  return client;
}
Exemplo n.º 3
0
Arquivo: inactivity.c Projeto: g7/mce
/**
 * D-Bus callback for the remove activity callback method call
 *
 * @param msg The D-Bus message
 * @return TRUE on success, FALSE on failure
 */
static gboolean remove_activity_callback_dbus_cb(DBusMessage *const msg)
{
	dbus_bool_t no_reply = dbus_message_get_no_reply(msg);
	const gchar *sender = dbus_message_get_sender(msg);
	gboolean status = FALSE;

	if (sender == NULL) {
		mce_log(LL_ERR,
			"Received invalid remove activity callback request "
			"(sender == NULL)");
		goto EXIT;
	}

	mce_log(LL_DEVEL, "Received remove activity callback request from %s",
		mce_dbus_get_name_owner_ident(sender));

	status = TRUE;

	remove_activity_cb(sender);

EXIT:
	if (no_reply == FALSE) {
		DBusMessage *reply = dbus_new_method_reply(msg);

		status = dbus_send_message(reply);
	} else {
		status = TRUE;
	}

	return status;
}
Exemplo n.º 4
0
/** D-Bus callback for the alarm queue status signal
 *
 * @param sig  The D-Bus signal message
 *
 * @return TRUE
 */
static gboolean alarm_queue_status_dbus_cb(DBusMessage *const sig)
{
        dbus_int32_t  bootup = 0;
        dbus_int32_t  normal = 0;
        DBusError     error  = DBUS_ERROR_INIT;
        const gchar  *sender = dbus_message_get_sender(sig);

        mce_log(LL_DEVEL, "Received alarm queue status signal from %s",
                mce_dbus_get_name_owner_ident(sender));

        if( !dbus_message_get_args(sig, &error,
                                   DBUS_TYPE_INT32, &bootup,
                                   DBUS_TYPE_INT32, &normal,
                                   DBUS_TYPE_INVALID) ) {
                mce_log(LL_ERR, "Failed to parse arguments: %s: %s",
                        error.name, error.message);
                goto EXIT;
        }

        /* DSME makes sure the device wakes up from suspend at
         * the time when timed needs to trigger an alarm. MCE
         * needs to make sure device does not get back to suspend
         * before alarm ui has had sufficient time to start up
         * and signal alarm dialog state.
         *
         * Timeds sends alarm queue status signal where the "next
         * alarm time" has value of one when alarm has been triggered
         * and alarm ui will be started up.
         */
        queue_monitor_setup(sender, bootup == 1 || normal == 1);

EXIT:
        dbus_error_free(&error);
        return TRUE;
}
Exemplo n.º 5
0
Arquivo: alarm.c Projeto: kimmoli/mce
/**
 * D-Bus callback for the alarm dialog status signal
 *
 * @param msg The D-Bus message
 * @return TRUE on success, FALSE on failure
 */
static gboolean alarm_dialog_status_dbus_cb(DBusMessage *const msg)
{
	alarm_ui_state_t alarm_ui_state = MCE_ALARM_UI_INVALID_INT32;
	gboolean status = FALSE;
	const gchar *sender = dbus_message_get_sender(msg);
	DBusError error;
	dbus_int32_t dialog_status;

	/* Register error channel */
	dbus_error_init(&error);

	mce_log(LL_DEVEL, "Received alarm dialog status signal from %s",
		mce_dbus_get_name_owner_ident(sender));

	if (dbus_message_get_args(msg, &error,
				  DBUS_TYPE_INT32, &dialog_status,
				  DBUS_TYPE_INVALID) == FALSE) {
		// XXX: should we return an error instead?
		mce_log(LL_CRIT,
			"Failed to get argument from %s.%s: %s",
			VISUAL_REMINDERS_SIGNAL_IF,
			VISUAL_REMINDER_STATUS_SIG,
			error.message);
		dbus_error_free(&error);
		goto EXIT;
	}

	/* Convert alarm dialog status to to MCE alarm ui enum */
	switch (dialog_status) {
	case VISUAL_REMINDER_ON_SCREEN:
		setup_alarm_dbus_monitor(sender);
		alarm_ui_state = MCE_ALARM_UI_RINGING_INT32;
		break;

	case VISUAL_REMINDER_ON_SCREEN_NO_SOUND:
		setup_alarm_dbus_monitor(sender);
		alarm_ui_state = MCE_ALARM_UI_VISIBLE_INT32;
		break;

	case VISUAL_REMINDER_NOT_ON_SCREEN:
		mce_dbus_owner_monitor_remove(sender, &alarm_owner_monitor_list);
		alarm_ui_state = MCE_ALARM_UI_OFF_INT32;
		break;

	default:
		mce_log(LL_ERR,
			"Received invalid alarm dialog status; "
			"defaulting to OFF");
		alarm_ui_state = MCE_ALARM_UI_OFF_INT32;
		break;
	}

	alarm_sync_state_to_datapipe(alarm_ui_state);

	status = TRUE;

EXIT:
	return status;
}
Exemplo n.º 6
0
/** D-Bus callback for the add activity callback method call
 *
 * @param req The D-Bus message
 *
 * @return TRUE
 */
static gboolean mia_dbus_add_activity_action_cb(DBusMessage *const req)
{
    const char *sender    = dbus_message_get_sender(req);
    DBusError   err       = DBUS_ERROR_INIT;
    const char *service   = 0;
    const char *path      = 0;
    const char *interface = 0;
    const char *method    = 0;
    dbus_bool_t res       = false;

    if( !sender )
        goto EXIT;

    mce_log(LL_DEVEL, "Add activity callback request from %s",
            mce_dbus_get_name_owner_ident(sender));

    if( !dbus_message_get_args(req, &err,
                               DBUS_TYPE_STRING, &service,
                               DBUS_TYPE_STRING, &path,
                               DBUS_TYPE_STRING, &interface,
                               DBUS_TYPE_STRING, &method,
                               DBUS_TYPE_INVALID) ) {
        mce_log(LL_ERR, "Failed to get arguments: %s: %s",
                err.name, err.message);
        goto EXIT;
    }

    res = mia_activity_action_add(sender, service, path, interface, method);

EXIT:
    if( !dbus_message_get_no_reply(req) ) {
        DBusMessage *rsp = dbus_new_method_reply(req);

        if( !dbus_message_append_args(rsp,
                                      DBUS_TYPE_BOOLEAN, &res,
                                      DBUS_TYPE_INVALID) ) {
            mce_log(LL_ERR, "Failed to append reply argument");
            dbus_message_unref(rsp);
        }
        else {
            dbus_send_message(rsp);
        }
    }

    dbus_error_free(&err);

    return TRUE;
}
Exemplo n.º 7
0
/** D-Bus callback for the MCE_CPU_KEEPALIVE_STOP_REQ method call
 *
 * @param msg  The D-Bus message
 *
 * @return TRUE on success, FALSE on failure
 */
static
gboolean
cka_dbus_handle_stop_cb(DBusMessage *const msg)
{
  gboolean success = FALSE;

  DBusError  err      = DBUS_ERROR_INIT;
  const char *sender  =  0;
  const char *session_id = 0;

  if( !(sender = dbus_message_get_sender(msg)) )
  {
    goto EXIT;
  }

  mce_log(LL_NOTICE, "got keepalive stop from %s",
          mce_dbus_get_name_owner_ident(sender));

  if( !dbus_message_get_args(msg, &err,
                             DBUS_TYPE_STRING, &session_id,
                             DBUS_TYPE_INVALID) )
  {
    // initial dbus interface did not include session_id string
    if( strcmp(err.name, DBUS_ERROR_INVALID_ARGS) )
    {
      mce_log(LL_WARN, "%s: %s", err.name, err.message);
      goto EXIT;
    }

    session_id = SESSION_ID_DEFAULT;
    mce_log(LL_DEBUG, "sender did not supply session_id string; using '%s'",
            session_id);
  }

  cka_clients_stop_session(sender, session_id);

  success = TRUE;

EXIT:
  cka_dbusutil_reply_bool(msg, success);

  dbus_error_free(&err);
  return success;
}
Exemplo n.º 8
0
/** D-Bus callback for the MCE_CPU_KEEPALIVE_PERIOD_REQ method call
 *
 * @param msg  The D-Bus message
 *
 * @return TRUE on success, FALSE on failure
 */
static
gboolean
cka_dbus_handle_period_cb(DBusMessage *const msg)
{
  gboolean success = FALSE;

  DBusError   err     = DBUS_ERROR_INIT;
  const char *sender  = 0;
  const char *session_id = 0;

  if( !(sender = dbus_message_get_sender(msg)) )
  {
    goto EXIT;
  }

  mce_log(LL_NOTICE, "got keepalive period query from %s",
          mce_dbus_get_name_owner_ident(sender));

  if( !dbus_message_get_args(msg, &err,
                             DBUS_TYPE_STRING, &session_id,
                             DBUS_TYPE_INVALID) )
  {
    // initial dbus interface did not include session_id string
    if( strcmp(err.name, DBUS_ERROR_INVALID_ARGS) )
    {
      mce_log(LL_WARN, "%s: %s", err.name, err.message);
      goto EXIT;
    }

    session_id = SESSION_ID_INITIAL;
    mce_log(LL_DEBUG, "sender did not supply session_id string; using '%s'",
            session_id);
  }

  cka_clients_add_session(sender, session_id);

  success = cka_dbusutil_reply_int(msg, MCE_CPU_KEEPALIVE_SUGGESTED_PERIOD_S);

EXIT:
  dbus_error_free(&err);
  return success;
}
Exemplo n.º 9
0
/** D-Bus callback for the remove activity callback method call
 *
 * @param req The D-Bus message
 *
 * @return TRUE
 */
static gboolean mia_dbus_remove_activity_action_cb(DBusMessage *const req)
{
    const char *sender = dbus_message_get_sender(req);

    if( !sender )
        goto EXIT;

    mce_log(LL_DEVEL, "Remove activity callback request from %s",
            mce_dbus_get_name_owner_ident(sender));

    mia_activity_action_remove(sender);

EXIT:

    if( !dbus_message_get_no_reply(req) ) {
        DBusMessage *reply = dbus_new_method_reply(req);
        dbus_send_message(reply);
    }

    return TRUE;
}
Exemplo n.º 10
0
/** Get client identification information
 *
 * @param self  pointer to cka_client_t structure
 *
 * @return human readable string identifying the client process
 */
static
const char *
cka_client_identify(cka_client_t *self)
{
  return mce_dbus_get_name_owner_ident(self->cli_dbus_name);
}
Exemplo n.º 11
0
Arquivo: inactivity.c Projeto: g7/mce
/**
 * D-Bus callback for the add activity callback method call
 *
 * @param msg The D-Bus message
 * @return TRUE on success, FALSE on failure
 */
static gboolean add_activity_callback_dbus_cb(DBusMessage *const msg)
{
	dbus_bool_t no_reply = dbus_message_get_no_reply(msg);
	const gchar *sender = dbus_message_get_sender(msg);
	const gchar *service = NULL;
	const gchar *path = NULL;
	const gchar *interface = NULL;
	const gchar *method_name = NULL;
	activity_cb_t *tmp = NULL;
	gboolean result = FALSE;
	gboolean status = FALSE;
	DBusError error;

	/* Register error channel */
	dbus_error_init(&error);

	if (sender == NULL) {
		mce_log(LL_ERR,
			"Received invalid add activity callback request "
			"(sender == NULL)");
		goto EXIT;
	}

	mce_log(LL_DEVEL, "Received add activity callback request from %s",
		mce_dbus_get_name_owner_ident(sender));

	/* Extract result */
	if (dbus_message_get_args(msg, &error,
				  DBUS_TYPE_STRING, &service,
				  DBUS_TYPE_STRING, &path,
				  DBUS_TYPE_STRING, &interface,
				  DBUS_TYPE_STRING, &method_name,
				  DBUS_TYPE_INVALID) == FALSE) {
		// XXX: should we return an error instead?
		mce_log(LL_CRIT,
			"Failed to get argument from %s.%s; %s",
			MCE_REQUEST_IF, MCE_ADD_ACTIVITY_CALLBACK_REQ,
			error.message);
		dbus_error_free(&error);
		goto EXIT;
	}

	if (mce_dbus_owner_monitor_add(sender,
				       activity_cb_monitor_dbus_cb,
				       &activity_cb_monitor_list,
				       ACTIVITY_CB_MAX_MONITORED) == -1) {
		mce_log(LL_ERR,
			"Failed to add name owner monitoring for `%s'",
			sender);
		goto EXIT2;
	}

	tmp = g_malloc(sizeof (activity_cb_t));

	tmp->owner = g_strdup(sender);
	tmp->service = g_strdup(service);
	tmp->path = g_strdup(path);
	tmp->interface = g_strdup(interface);
	tmp->method_name = g_strdup(method_name);

	activity_callbacks = g_slist_prepend(activity_callbacks, tmp);

	result = TRUE;

EXIT2:
	if (no_reply == FALSE) {
		DBusMessage *reply = dbus_new_method_reply(msg);

		if (dbus_message_append_args(reply,
					     DBUS_TYPE_BOOLEAN, &result,
					     DBUS_TYPE_INVALID) == FALSE) {
			mce_log(LL_CRIT,
				"Failed to append reply argument to "
				"D-Bus message for %s.%s",
				MCE_REQUEST_IF,
				MCE_ADD_ACTIVITY_CALLBACK_REQ);
			dbus_message_unref(reply);
			goto EXIT;
		}

		status = dbus_send_message(reply);
	} else {
		status = TRUE;
	}

EXIT:
	return status;
}