Ejemplo n.º 1
1
static bool
alarms_timeout_subscribe_cb(LSHandle *sh, LSMessage *message, void *ctx)
{
	bool retVal;
	bool fired = false;
	struct context *alrm_ctx = (struct context *)ctx;

	const char *payload = LSMessageGetPayload(message);
	struct json_object *object = json_tokener_parse(payload);
	if (is_error(object))
	{
		POWERDLOG(LOG_CRIT,"%s: invalid json from sleep daemon",__func__);
	}
	else
	{
		fired = json_object_get_boolean(json_object_object_get(object, "fired"));
	}

	POWERDLOG(LOG_INFO,"%s: response with payload %s, count : %d", __FUNCTION__, payload, alrm_ctx->count);

	if(alrm_ctx->replyMessage)
	{
		if(fired)
		{
			retVal = LSMessageReply(GetLunaServiceHandle(), alrm_ctx->replyMessage, payload, NULL);
			if (!retVal)
			{
				POWERDLOG(LOG_WARNING, "%s could not send reply.", __FUNCTION__);
			}
		}
		else if(LSMessageGetConnection(alrm_ctx->replyMessage))
		{
			retVal = LSMessageReply(LSMessageGetConnection(alrm_ctx->replyMessage), alrm_ctx->replyMessage, payload, NULL);
			if (!retVal)
			{
				POWERDLOG(LOG_WARNING, "%s could not send reply.", __FUNCTION__);
			}
		}
		alrm_ctx->count++;
	}
	else
		POWERDLOG(LOG_CRIT,"%s: replyMessage is NULL",__func__);

	if(alrm_ctx->count == 2) {
		if(!LSCallCancel(sh, alrm_ctx->call_token, NULL))
		{
			POWERDLOG(LOG_WARNING, "%s could not cancel luna-service alarm call.", __FUNCTION__);
		}
		LSMessageUnref(alrm_ctx->replyMessage);
		free(alrm_ctx);
	}

	if (!is_error(object)) json_object_put(object);

    return true;
}
Ejemplo n.º 2
0
void ls2_thread_cleanup(void *arg) {
  THREAD_DATA *data = (THREAD_DATA *)arg;

  syslog(LOG_DEBUG, "Ls2 thread cleanup, closing pipe %p, unref message %p\n", 
      data->fp, data->message);

  if (data->fp) pclose(data->fp);
  if (data->message) LSMessageUnref(data->message);
}
Ejemplo n.º 3
0
static bool play_feedback_cb(LSHandle *handle, LSMessage *message, void *user_data)
{
	struct audio_service *service = user_data;
	struct play_feedback_data *pfd;
	const char *payload;
	jvalue_ref parsed_obj;
	char *name, *sink;
	bool play;

	if (!service->context_initialized) {
		luna_service_message_reply_custom_error(handle, message, "Not yet initialized");
		return true;
	}

	payload = LSMessageGetPayload(message);
	parsed_obj = luna_service_message_parse_and_validate(payload);
	if (jis_null(parsed_obj)) {
		luna_service_message_reply_error_bad_json(handle, message);
		goto cleanup;
	}

	name = luna_service_message_get_string(parsed_obj, "name", NULL);
	if (!name) {
		luna_service_message_reply_custom_error(handle, message, "Invalid parameters: name parameter is required");
		goto cleanup;
	}

	play = luna_service_message_get_boolean(parsed_obj, "play", true);

	sink = luna_service_message_get_string(parsed_obj, "sink", NULL);

	pfd = g_new0(struct play_feedback_data, 1);
	pfd->service = service;
	pfd->handle = handle;
	pfd->message = message;
	pfd->name = name;
	pfd->sink = sink;
	pfd->play = play;

	LSMessageRef(message);

	if (!preload_sample(service, pfd)) {
		luna_service_message_reply_custom_error(handle, message, "Could not preload sample");
		LSMessageUnref(message);
		g_free(pfd);
		g_free(name);
		g_free(sink);
		goto cleanup;
	}

cleanup:
	if (!jis_null(parsed_obj))
		j_release(&parsed_obj);

	return true;
}
Ejemplo n.º 4
0
static void
alarm_free(_Alarm *a)
{
    g_debug("Freeing alarm with id %d", a->id);

    g_free(a->serviceName);
    g_free(a->applicationName);
    if (a->message) LSMessageUnref(a->message);
    g_free(a);
}
Ejemplo n.º 5
0
static void play_feedback_data_free(struct play_feedback_data *pfd)
{
	if (pfd->fd > 0)
		close(pfd->fd);

	LSMessageUnref(pfd->message);

	g_free(pfd->name);
	g_free(pfd);
}
Ejemplo n.º 6
0
//
// Handler for the listApps service.
//
bool listApps_handler(LSHandle* lshandle, LSMessage *reply, void *ctx) {
  bool retVal;
  LSError lserror;
  LSErrorInit(&lserror);
  LSMessage* message = (LSMessage*)ctx;
  retVal = LSMessageRespond(message, LSMessageGetPayload(reply), &lserror);
  LSMessageUnref(message);
  if (!retVal) {
    LSErrorPrint(&lserror, stderr);
    LSErrorFree(&lserror);
  }
  return retVal;
}
Ejemplo n.º 7
0
static void
alarm_free(_Alarm *a)
{
	SLEEPDLOG_DEBUG("Freeing alarm with id %d", a->id);

	g_free(a->serviceName);
	g_free(a->applicationName);

	if (a->message)
	{
		LSMessageUnref(a->message);
	}

	g_free(a);
}
Ejemplo n.º 8
0
//
// Handler for the impersonate service.
//
bool impersonate_handler(LSHandle* lshandle, LSMessage *reply, void *ctx) {
  bool retVal;
  LSError lserror;
  LSErrorInit(&lserror);
  LSMessage* message = (LSMessage*)ctx;
  retVal = LSMessageRespond(message, LSMessageGetPayload(reply), &lserror);
  if (!LSMessageIsSubscription(message)) {
    LSMessageUnref(message);
  }
  if (!retVal) {
    LSErrorPrint(&lserror, stderr);
    LSErrorFree(&lserror);
  }
  return retVal;
}
Ejemplo n.º 9
0
/**
* @brief Frees up resources for LSSubscriptionIter.
*
* @param  iter
*/
void
LSSubscriptionRelease(LSSubscriptionIter *iter)
{
    GSList *seen_iter = iter->seen_messages;
    while (seen_iter)
    {
        LSMessage *msg = (LSMessage*)seen_iter->data;
        LSMessageUnref(msg);

        seen_iter = seen_iter->next;
    }

    _SubListFree(iter->tokens);
    g_slist_free(iter->seen_messages);
    g_free(iter);
}
Ejemplo n.º 10
0
static bool
suspend_ipc_method_cb(LSHandle *sh, LSMessage *message, void *ctx)
{
	bool retVal;
	LSMessage *replyMessage = (LSMessage *)ctx;

	POWERDLOG(LOG_INFO,"%s: response with payload %s", __FUNCTION__, LSMessageGetPayload(message));
	if(replyMessage && LSMessageGetConnection(replyMessage))
	{
		retVal = LSMessageReply(LSMessageGetConnection(replyMessage), replyMessage, LSMessageGetPayload(message), NULL);
		if (!retVal)
		{
			POWERDLOG(LOG_WARNING, "%s could not send reply.", __FUNCTION__);
		}
		LSMessageUnref(replyMessage);
	}
	else
		POWERDLOG(LOG_CRIT,"%s: replyMessage is NULL",__func__);
    return true;
}
Ejemplo n.º 11
0
static void
_PrintSubscriptionResultsList(GSList *sub_list)
{
    for (; sub_list != NULL; sub_list = g_slist_next(sub_list))
    {
        LSMessage *msg = sub_list->data;

        /* We may get error messages if the service goes down between the
         * time we find out about it and send the subscription info request */
        if (!LSMessageIsHubErrorMessage(msg))
        {
            const char *sub_text = LSMessageGetPayload(msg);
            const char *service = LSMessageGetSenderServiceName(msg);
            fprintf(stdout, "%s: %s\n", service, sub_text);
        }

        LSMessageUnref(msg);
    }
    fprintf(stdout, "\n");
}
Ejemplo n.º 12
0
static void
_SubscriptionFree(_Catalog *catalog, _Subscription *subs)
{
    if (subs)
    {
        LSMessageUnref(subs->message);

        if (subs->keys)
        {
            g_ptr_array_foreach(subs->keys, (GFunc)g_free, NULL);
            g_ptr_array_free(subs->keys, TRUE);
        }

#ifdef MEMCHECK
        memset(subs, 0xFF, sizeof(_Subscription));
#endif

        g_free(subs);
    }
}
Ejemplo n.º 13
0
static bool
state_shutdown_action(ShutdownEvent *event, ShutdownState *next)
{
    bool retVal =
        LSMessageReply(GetLunaServiceHandle(), shutdown_message,
            "{\"success\":true}", NULL);
    if (!retVal)
    {
        g_critical("%s: Could not send shutdown success message",
                __FUNCTION__);
    }

    if (shutdown_message)
    {
        LSMessageUnref(shutdown_message);
        shutdown_message = NULL;
    }

    nyx_system_set_alarm(GetNyxSystemDevice(),0,NULL,NULL);

    return false;  
}
Ejemplo n.º 14
0
LunaServiceMessage::~LunaServiceMessage()
{
    LSMessageUnref(mMessage);
}