Example #1
0
//--------------------------------------------------------------------------------------------------
static Service_t* GetService
(
    le_msg_ProtocolRef_t    protocolRef,
    const char*             serviceName
)
//--------------------------------------------------------------------------------------------------
{
    ServiceId_t id;

    id.protocolRef = protocolRef;
    LE_FATAL_IF(le_utf8_Copy(id.name, serviceName, sizeof(id.name), NULL) == LE_OVERFLOW,
                "Service ID '%s' too long (should only be %zu bytes total).",
                serviceName,
                sizeof(id.name));

    Service_t* servicePtr = le_hashmap_Get(ServiceMapRef, &id);
    if (servicePtr == NULL)
    {
        servicePtr = CreateService(protocolRef, serviceName);
    }
    else
    {
        le_mem_AddRef(servicePtr);
    }

    return servicePtr;
}
Example #2
0
//--------------------------------------------------------------------------------------------------
void le_pm_Relax(le_pm_WakeupSourceRef_t w)
{
    WakeupSource_t *ws, *entry;

    // Validate the reference, check if it exists
    ws = ToWakeupSource(w);
    // If the wakeup source is NULL then the client will have
    // been killed and we can just return
    if (NULL == ws)
        return;

    entry = (WakeupSource_t*)le_hashmap_Get(PowerManager.locks, ws->name);
    if (!entry)
        LE_FATAL("Wakeup source '%s' not created.\n", ws->name);

    if (!entry->taken) {
        LE_ERROR("Wakeup source '%s' already released.", entry->name);
        return;
    }

    // write to /sys/power/wake_unlock
    if (0 > write(PowerManager.wu, entry->name, strlen(entry->name)))
        LE_FATAL("Error releasing wakeup soruce '%s', errno = %d.",
            entry->name, errno);

    entry->taken = LE_OFF;

    return;
}
Example #3
0
//--------------------------------------------------------------------------------------------------
static WatchdogObj_t* LookupClientWatchdogPtrById
(
    pid_t clientPid  ///< Client we want the watchdog for
)
{
    return le_hashmap_Get(WatchdogRefsContainer, &clientPid);
}
Example #4
0
static int mangoh_bridge_air_vantage_pushString(void* param, const unsigned char* data, uint32_t size)
{
    mangoh_bridge_air_vantage_t* airVantage = (mangoh_bridge_air_vantage_t*)param;
    int32_t res = LE_OK;

    LE_ASSERT(airVantage);
    LE_ASSERT(data);

    LE_DEBUG("---> PUSH STRING");
    uint8_t* ptr = (uint8_t*)data;

    uint8_t len = 0;
    memcpy(&len, ptr, sizeof(len));
    LE_DEBUG("len(%u)", len);
    ptr += sizeof(len);

    char fieldName[MANGOH_BRIDGE_AIR_VANTAGE_FIELD_NAME_MAX_LEN] = {0};
    memcpy(fieldName, ptr, len);
    LE_DEBUG("field('%s')", fieldName);
    ptr += len;

    char val[MANGOH_BRIDGE_AIR_VANTAGE_VALUE_MAX_LEN] = {0};
    memcpy(val, ptr, size - len - sizeof(len));
    LE_DEBUG("value('%s')", val);

    dataRouter_WriteString(fieldName, val, time(NULL));

    dataRouter_DataUpdateHandlerRef_t dataUpdateHandlerRef = le_hashmap_Get(airVantage->dataUpdateHandlers, fieldName);
    if (!dataUpdateHandlerRef)
    {
        LE_DEBUG("add data update handler('%s')", fieldName);
        dataUpdateHandlerRef = dataRouter_AddDataUpdateHandler(fieldName, mangoh_bridge_air_vantage_dataUpdateHdlr, airVantage);
        if (!dataUpdateHandlerRef)
        {
            LE_ERROR("ERROR dataRouter_AddDataUpdateHandler() failed");
            res = LE_FAULT;
            goto cleanup;
        }

        if (le_hashmap_Put(airVantage->dataUpdateHandlers, fieldName, dataUpdateHandlerRef))
        {
            LE_ERROR("ERROR le_hashmap_Put() failed");
            res = LE_FAULT;
            goto cleanup;
        }
    }

    res = mangoh_bridge_sendResult(airVantage->bridge, 0);
    if (res != LE_OK)
    {
        LE_ERROR("ERROR mangoh_bridge_sendResult() failed(%d)", res);
        goto cleanup;
    }

cleanup:
    return res;
}
Example #5
0
//--------------------------------------------------------------------------------------------------
le_pm_WakeupSourceRef_t le_pm_NewWakeupSource(uint32_t opts, const char *tag)
{
    WakeupSource_t *ws;
    Client_t *cl;
    char name[LEGATO_WS_NAME_LEN];

    if (!tag || *tag == '\0' || strlen(tag) > LE_PM_TAG_LEN) {
        LE_KILL_CLIENT("Error: Tag value is invalid or NULL.");
        return NULL;
    }

    // Find and validate client record
    cl = to_Client_t(le_hashmap_Get(PowerManager.clients,
                                    le_pm_GetClientSessionRef()));

    // Check if identical wakeup source already exists for this client
    sprintf(name, LEGATO_WS_NAME_FORMAT, tag, cl->pid);

    // Lookup wakeup source by name
    ws = (WakeupSource_t*)le_hashmap_Get(PowerManager.locks, name);
    if (ws) {
        LE_KILL_CLIENT("Error: Tag '%s' already exists.", tag);
        return NULL;
    }

    // Allocate and populate wakeup source record (exits on error)
    ws = (WakeupSource_t*)le_mem_ForceAlloc(PowerManager.lpool);
    ws->cookie = PM_WAKEUP_SOURCE_COOKIE;
    strcpy(ws->name, name);
    ws->taken = LE_OFF;
    ws->pid = cl->pid;
    ws->wsref = le_ref_CreateRef(PowerManager.refs, ws);

    // Store record in table of wakeup sources
    if (le_hashmap_Put(PowerManager.locks, ws->name, ws))
        LE_FATAL("Error adding wakeup source '%s'.", ws->name);

    LE_INFO("Created new wakeup source '%s' for pid %d.", ws->name, ws->pid);

    return (le_pm_WakeupSourceRef_t)ws->wsref;
}
Example #6
0
//--------------------------------------------------------------------------------------------------
static void AsyncRecvHandler(void* handle, short events)
{
    // Retrieve the Handle record, using the FD
    HandleRecord_t* connectionRecordPtr = le_hashmap_Get(HandleRecordByFileDescriptor, handle);
    if (connectionRecordPtr == NULL)
    {
        LE_ERROR("Unable to find matching Handle Record, fd [%" PRIiPTR "]", (intptr_t) handle);
        return;
    }

    // Notify the RPC Proxy
    AsyncReceiveHandlerFuncPtr(connectionRecordPtr, events);
}
Example #7
0
//--------------------------------------------------------------------------------------------------
static tu_UserRef_t GetUser
(
    uid_t userId,     ///< [IN]  The user id to look up.
    bool* wasCreated  ///< [OUT] Was the user info created for this request?  Pass NULL if you don't
                      ///<       need this.
)
//--------------------------------------------------------------------------------------------------
{
    // If the connected user has the same uid we're running under, treat the user as if they're
    // root.
    if (userId == geteuid())
    {
        userId = 0;
    }

    if (wasCreated)
    {
        *wasCreated = false;
    }

    // Now try to look up this user in our hash table.  If not found, create it now.
    tu_UserRef_t userRef = le_hashmap_Get(UserCollectionRef, &userId);

    if (userRef == NULL)
    {
        // At this point, grab the user's app name, which will succeed if it is an app, otherwise we get
        // the standard user name.

        char userName[LIMIT_MAX_USER_NAME_BYTES] = "";

        if (user_GetAppName(userId, userName, sizeof(userName)) != LE_OK)
        {
            LE_ASSERT(user_GetName(userId, userName, sizeof(userName)) == LE_OK);
        }

        userRef = CreateUserInfo(userId, userName, userName);

        if (wasCreated)
        {
            *wasCreated = true;
        }
    }

    return userRef;
}
Example #8
0
//--------------------------------------------------------------------------------------------------
static void ListeningRecvHandler(void* handle, short events)
{
    int clientFd = -1;

    if (events != POLLIN)
    {
        LE_ERROR("Unexpected fd event(s): 0x%hX", events);
        return;
    }

    // Retrieve the Handle record, using the FD
    HandleRecord_t* parentRecordPtr = le_hashmap_Get(HandleRecordByFileDescriptor, handle);
    if (parentRecordPtr == NULL)
    {
        LE_ERROR("Unable to find matching Handle Record, fd [%" PRIiPTR "]", (intptr_t) handle);
        return;
    }

    // Accept the connection, setting the connection to be non-blocking.
    clientFd = accept((int)(size_t)handle, NULL, NULL);
    if (clientFd < 0)
    {
        LE_ERROR("Failed to accept client connection. Errno %d", errno);
    }

    LE_INFO("Accepting Client socket connection, fd [%d]", clientFd);
    HandleRecord_t *connectionRecordPtr = le_mem_AssertAlloc(HandleRecordPoolRef);

    // Initialize the connection record
    connectionRecordPtr->fd = clientFd;
    connectionRecordPtr->isListeningFd = false;
    connectionRecordPtr->parentRecordPtr = parentRecordPtr;

    le_hashmap_Put(HandleRecordByFileDescriptor, (void*)(intptr_t) connectionRecordPtr->fd, connectionRecordPtr);

    LE_INFO("Notifying RPC Proxy Client socket connected, fd [%d]", clientFd);

    // Notify the RPC Proxy of the Client connection
    AsyncConnectionHandlerFuncPtr(connectionRecordPtr, events);
}
Example #9
0
static int mangoh_bridge_air_vantage_pushFloat(void* param, const unsigned char* data, uint32_t size)
{
    mangoh_bridge_air_vantage_t* airVantage = (mangoh_bridge_air_vantage_t*)param;
    double fVal = 0;
    int32_t res = LE_OK;

    LE_ASSERT(airVantage);
    LE_ASSERT(data);

    LE_DEBUG("---> PUSH FLOAT");
    uint8_t* ptr = (uint8_t*)data;

    uint8_t len = 0;
    memcpy(&len, ptr, sizeof(len));
    LE_DEBUG("len(%u)", len);
    ptr += sizeof(len);

    char fieldName[MANGOH_BRIDGE_AIR_VANTAGE_FIELD_NAME_MAX_LEN] = {0};
    memcpy(fieldName, ptr, len);
    LE_DEBUG("field('%s')", fieldName);
    ptr += len;

    int8_t precision = 0;
    memcpy(&precision, ptr, sizeof(precision));
    LE_DEBUG("precision(%u)", precision);
    ptr += sizeof(precision);

    int32_t val = 0;
    memcpy(&val, ptr, sizeof(val));
    LE_DEBUG("value(%d)", val);
    fVal = val;
    while (precision-- > 0) fVal /= 10.0;

    LE_DEBUG("write(%f)", fVal);
    dataRouter_WriteFloat(fieldName, fVal, time(NULL));

    dataRouter_DataUpdateHandlerRef_t dataUpdateHandlerRef = le_hashmap_Get(airVantage->dataUpdateHandlers, fieldName);
    if (!dataUpdateHandlerRef)
    {
        LE_DEBUG("add data update handler('%s')", fieldName);
        dataUpdateHandlerRef = dataRouter_AddDataUpdateHandler(fieldName, mangoh_bridge_air_vantage_dataUpdateHdlr, airVantage);
        if (!dataUpdateHandlerRef)
        {
            LE_ERROR("ERROR dataRouter_AddDataUpdateHandler() failed");
            res = LE_FAULT;
            goto cleanup;
        }

        if (le_hashmap_Put(airVantage->dataUpdateHandlers, fieldName, dataUpdateHandlerRef))
        {
            LE_ERROR("ERROR le_hashmap_Put() failed");
            res = LE_FAULT;
            goto cleanup;
        }
    }

    res = mangoh_bridge_sendResult(airVantage->bridge, 0);
    if (res != LE_OK)
    {
        LE_ERROR("ERROR mangoh_bridge_sendResult() failed(%d)", res);
        goto cleanup;
    }

cleanup:
    return res;
}