Esempio n. 1
0
static bool mia_activity_action_add(const char *owner,
                                    const char *service,
                                    const char *path,
                                    const char *interface,
                                    const char *method)
{
    bool ack = false;

    /* Add D-Bus name owner monitor */
    if( mce_dbus_owner_monitor_add(owner,
                                   mia_dbus_activity_action_owner_cb,
                                   &activity_action_owners,
                                   ACTIVITY_CB_MAX_MONITORED) == -1) {
        mce_log(LL_ERR, "Failed to add name owner monitoring for `%s'",
                owner);
        goto EXIT;
    }

    /* Add activity callback */
    mia_action_t *cb = mia_action_create(owner, service, path, interface, method);

    activity_action_list = g_slist_prepend(activity_action_list, cb);

    ack = true;

EXIT:
    return ack;
}
Esempio n. 2
0
/**
 * D-Bus callback for the ALS enabling method call
 *
 * @param msg The D-Bus message
 * @return TRUE
 */
static gboolean als_enable_req_dbus_cb(DBusMessage *const msg)
{
	const char *sender;

	gssize retval;

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

	mce_log(LL_DEBUG, "Received ALS enable request from %s", sender);

	retval = mce_dbus_owner_monitor_add(sender, als_owner_monitor_dbus_cb,
					    &ext_als_enablers,
					    ALS_MAX_MONITORED);
	if (retval == -1) {
		mce_log(LL_WARN, "Failed to add name owner monitoring"
			" for `%s'", sender);
		goto EXIT;
	}

	rethink_als_status();

EXIT:
	if( !dbus_message_get_no_reply(msg) ) {
		DBusMessage *reply = dbus_new_method_reply(msg);
		dbus_send_message(reply), reply = 0;
	}

	return TRUE;
}
Esempio n. 3
0
File: alarm.c Progetto: kimmoli/mce
/**
 * Install alarm D-Bus service monitor callback.
 *
 * @param sender sender D-Bus address
 */
static void setup_alarm_dbus_monitor(const gchar* sender)
{
	mce_log(LL_DEBUG, "adding dbus monitor for: '%s'" ,sender);
	/* No need to check return value, if it does not succeed, not much
	 * we can do / fall back to
	 */
	mce_dbus_owner_monitor_add(sender,
							   alarm_owner_monitor_dbus_cb,
							   &alarm_owner_monitor_list,
							   ALARM_MAX_MONITORED);
}
Esempio n. 4
0
/** Install/remove alarm queue D-Bus name owner monitor
 *
 * @param sender   Private D-Bus name to monitor
 * @param monitor  true/false to start/stop monitoring
 */
static void queue_monitor_setup(const char *sender, bool monitor)
{
    if( monitor ) {
        gssize cnt = mce_dbus_owner_monitor_add(sender,
                                                queue_owner_monitor_dbus_cb,
                                                &queue_owner_monitor_list,
                                                ALARM_MAX_MONITORED);
        if( cnt != -1 ) {
            /* A owner monitor was added/renewed */
            mce_log(LL_DEVEL, "monitoring dbus name: %s", sender);
            mce_wakelock_obtain(ALARM_IMMINENT_WAKELOCK_NAME,
                                ALARM_IMMINENT_TIMEOUT_MS);
        }
    }
    else {
        gssize cnt = mce_dbus_owner_monitor_remove(sender,
                                                   &queue_owner_monitor_list);
        if( cnt == 0 ) {
            /* The last monitor was removed */
            mce_log(LL_DEVEL, "all dbus name monitors removed");
            mce_wakelock_release(ALARM_IMMINENT_WAKELOCK_NAME);
        }
    }
}
Esempio n. 5
0
File: inactivity.c Progetto: 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;
}
Esempio n. 6
0
/**
 * D-Bus callback for the call state change request method call
 *
 * @param msg The D-Bus message
 * @return TRUE on success, FALSE on failure
 */
static gboolean
change_call_state_dbus_cb(DBusMessage *const msg)
{
    gboolean     status = FALSE;
    const char  *state  = 0;
    const char  *type   = 0;
    const gchar *sender = dbus_message_get_sender(msg);

    call_state_t call_state = CALL_STATE_NONE;
    call_type_t  call_type = NORMAL_CALL;
    DBusMessage *reply = NULL;
    DBusError    error = DBUS_ERROR_INIT;
    dbus_bool_t changed = false;

    mce_log(LL_DEBUG, "Received set call state request");

    if (dbus_message_get_args(msg, &error,
                              DBUS_TYPE_STRING, &state,
                              DBUS_TYPE_STRING, &type,
                              DBUS_TYPE_INVALID) == FALSE) {
        // XXX: return an error!
        mce_log(LL_CRIT, "Failed to get argument from %s.%s: %s",
                MCE_REQUEST_IF, MCE_CALL_STATE_CHANGE_REQ,
                error.message);
        dbus_error_free(&error);
        goto EXIT;
    }

    /* Convert call state to enum */
    call_state = call_state_parse(state);
    if (call_state == MCE_INVALID_TRANSLATION) {
	mce_log(LL_DEBUG,
                "Invalid call state received; request ignored");
        goto EXIT;
    }

    /* Convert call type to enum */
    call_type = call_type_parse(type);
    if (call_type == MCE_INVALID_TRANSLATION) {
        mce_log(LL_DEBUG,
                "Invalid call type received; request ignored");
        goto EXIT;
    }

    /* reject no-call emergency calls ... */
    if( call_state == CALL_STATE_NONE )
        call_type = NORMAL_CALL;

    /* If call state isn't monitored or if the request comes from
     * the owner of the current state, then some additional changes
     * are ok
     */
    if( call_state_monitor_list &&
        !mce_dbus_is_owner_monitored(sender,
                                     call_state_monitor_list) ) {
        mce_log(LL_DEBUG, "Call state already has owner; ignoring request");
        goto EXIT;
    }

    /* Only transitions to/from "none" are allowed,
     * and from "ringing" to "active",
     * to avoid race conditions; except when new tuple
     * is active:emergency
     */
    if( call_state == CALL_STATE_ACTIVE &&
        simulated.state != CALL_STATE_RINGING &&
        call_type != EMERGENCY_CALL )
    {
        mce_log(LL_INFO,
                "Call state change vetoed.  Requested: %i:%i "
                "(current: %i:%i)",
                call_state, call_type,
                simulated.state, simulated.type);
        goto EXIT;
    }

    if( call_state != CALL_STATE_NONE &&
        mce_dbus_owner_monitor_add(sender, call_state_owner_monitor_dbus_cb,
                                   &call_state_monitor_list, 1) != -1 ) {

        simulated.state = call_state;
        simulated.type  = call_type;
    }
    else {
        mce_dbus_owner_monitor_remove(sender, &call_state_monitor_list);
        simulated.state = CALL_STATE_NONE;
        simulated.type  = NORMAL_CALL;
    }
    changed = call_state_rethink_forced();

EXIT:
    /* Setup the reply */
    reply = dbus_new_method_reply(msg);

    /* Append the result */
    if (dbus_message_append_args(reply,
                                 DBUS_TYPE_BOOLEAN, &changed,
                                 DBUS_TYPE_INVALID) == FALSE) {
        mce_log(LL_CRIT,
                "Failed to append reply arguments to D-Bus "
                "message for %s.%s",
                MCE_REQUEST_IF, MCE_CALL_STATE_CHANGE_REQ);
        dbus_message_unref(reply);
    } else {
        /* Send the message */
        status = dbus_send_message(reply);
    }

    return status;
}