Пример #1
0
static bool
shutdownServicesRegister(LSHandle *sh, LSMessage *message,
                             void *user_data)
{
    struct json_object *object =
        json_tokener_parse(LSMessageGetPayload(message));
    if (is_error(object)) goto end;

    const char *clientId = LSMessageGetUniqueToken(message);
    const char *clientName = json_object_get_string(json_object_object_get(
        object, "clientName"));

    client_new_service(clientId, clientName);

    bool retVal;
    LSError lserror;
    LSErrorInit(&lserror);

    retVal = LSSubscriptionAdd(sh, "shutdownClient",
                             message, &lserror);
    if (!retVal)
    {
        g_critical("LSSubscriptionAdd failed.");
        LSErrorPrint(&lserror, stderr);
        LSErrorFree(&lserror);
    }

    send_reply(sh, message, "{\"clientId\":\"%s\"}", clientId);

    json_object_put(object);
end:
    return true;
}
Пример #2
0
static bool
_CatalogAdd(_Catalog *catalog, const char *key,
            LSMessage *message, LSError *lserror)
{
    bool retVal = false;
    const char *token = LSMessageGetUniqueToken(message);
    if (!token)
    {
        _LSErrorSet(lserror, MSGID_LS_TOKEN_ERR, -1, "Could not get unique token");
        return false;
    }

    _CatalogLock(catalog);

    _SubList *list =
        g_hash_table_lookup(catalog->subscription_lists, key);
    if (!list)
    {
        list = _SubListNew();
        g_hash_table_replace(catalog->subscription_lists,
                             g_strdup(key), list);
    }

    const char* client_name = LSMessageGetSender(message);
    if (!client_name)
    {
        _LSErrorSet(lserror, MSGID_LS_UNAME_ERR, -1, "Could not get service unique name");
        return false;
    }

    _SubList *client_list =
        g_hash_table_lookup(catalog->client_subscriptions, client_name);
    if (!client_list)
    {
        client_list = _SubListNew();
        g_hash_table_replace(catalog->client_subscriptions,
                             g_strdup(client_name), client_list);
    }

    _Subscription *subs = g_hash_table_lookup(catalog->token_map, token);
    if (!subs)
    {
        subs = _SubscriptionNew(catalog->sh, message);
        if (subs)
        {
            g_hash_table_replace(catalog->token_map, g_strdup(token), subs);
        }
        else
        {
            goto cleanup;
        }
    }
    LS_ASSERT(subs->message == message);

    if (!_SubListContains(list, token))
    {
        _SubListAdd(list, g_strdup(token));
    }

    if (!_SubListContains(client_list, token))
    {
        _SubListAdd(client_list, g_strdup(token));
    }

    if (!g_char_ptr_array_contains(subs->keys, key))
    {
        g_ptr_array_add(subs->keys, g_strdup(key));
    }

    retVal = true;

cleanup:
    _CatalogUnlock(catalog);
    return retVal;
}