示例#1
0
//--------------------------------------------------------------------------------------------------
le_result_t supCtrl_StartApp
(
    const char* appNamePtr  ///< [IN] The name of the app to start.
)
//--------------------------------------------------------------------------------------------------
{
    // Read the application's info from the config, and check if the app is marked as auto start.
    // If not, there's not much else to do here.
    appCfg_Iter_t appIterRef = appCfg_FindApp(appNamePtr);

    if (appIterRef == NULL)
    {
        // The app was not found, so is basically not startable.
        LE_CRIT("Can't find app '%s' to start it.", appNamePtr);
        return false;
    }

    appCfg_StartMode_t startMode = appCfg_GetStartMode(appIterRef);
    appCfg_DeleteIter(appIterRef);

    if (startMode != APPCFG_START_MODE_AUTO)
    {
        LE_INFO("App '%s' is not marked for auto-start.", appNamePtr);

        return true;
    }

    // Connect to the supervisor and start the application.
    if (!ConnectedToSupervisor)
    {
        le_sup_ctrl_ConnectService();
        ConnectedToSupervisor = true;
    }

    LE_INFO("Starting app '%s'.", appNamePtr);

    le_result_t result = le_sup_ctrl_StartApp(appNamePtr);

    // The app is auto start, so attempt to start it now.
    if (result == LE_DUPLICATE)
    {
        // This means the app was previously installed and running, so we need to stop and start it
        // again to get the new version.
        le_sup_ctrl_StopApp(appNamePtr);
        result = le_sup_ctrl_StartApp(appNamePtr);
    }
    else if (result == LE_NOT_FOUND)
    {
        LE_CRIT("Attempt to start '%s' failed because its config could not be found.",
                appNamePtr);
        return LE_FAULT;
    }

    return result;
}
示例#2
0
//--------------------------------------------------------------------------------------------------
LE_SHARED appCfg_Iter_t appCfg_FindApp
(
    const char* appName         ///< [IN] Name of the app to find.
)
{
    AppsIter_t* iterPtr = appCfg_CreateAppsIter();

    le_cfg_GoToNode(iterPtr->cfgIter, appName);

    if (le_cfg_NodeExists(iterPtr->cfgIter, "") == false)
    {
        appCfg_DeleteIter(iterPtr);
        return NULL;
    }

    return iterPtr;
}
示例#3
0
//--------------------------------------------------------------------------------------------------
static void PopulateAppInfoObjects
(
    void
)
//--------------------------------------------------------------------------------------------------
{
    appCfg_Iter_t appIterRef = appCfg_CreateAppsIter();
    char appName[MAX_APP_NAME_BYTES] = "";
    char versionBuffer[MAX_VERSION_STR_BYTES] = "";
    le_result_t result;

    int foundAppCount = 0;

    result = appCfg_GetNextItem(appIterRef);

    while (result == LE_OK)
    {
        result = appCfg_GetAppName(appIterRef, appName, sizeof(appName));

        if ((result == LE_OK) &&
            (false == IsHiddenApp(appName)))
        {
            LE_DEBUG("Loading object instance for app, '%s'.", appName);

            assetData_InstanceDataRef_t instanceRef = GetObject9InstanceForApp(appName, false);

            if (appCfg_GetVersion(appIterRef, versionBuffer, sizeof(versionBuffer)) == LE_OVERFLOW)
            {
                LE_WARN("Warning, app, '%s' version string truncated to '%s'.",
                        appName,
                        versionBuffer);
            }

            if (0 == strlen(versionBuffer))
            {
                // Use the application hash if the version is empty
                le_appInfo_GetHash(appName, versionBuffer, sizeof(versionBuffer));
            }

            assetData_client_SetString(instanceRef, O9F_PKG_VERSION, versionBuffer);

            assetData_client_SetBool(instanceRef,   O9F_UPDATE_SUPPORTED_OBJECTS, false);

            // No need to save the status in config tree, while populating object9
            SetObj9State(instanceRef, US_INSTALLED, UR_INSTALLED, false);

            foundAppCount++;
        }
        else
        {
            LE_WARN("Application name too large or is hidden, '%s.'", appName);
        }

        result = appCfg_GetNextItem(appIterRef);
    }

    appCfg_DeleteIter(appIterRef);
    LE_FATAL_IF(result != LE_NOT_FOUND,
                "Application cache initialization, unexpected error returned, (%d): \"%s\"",
                result,
                LE_RESULT_TXT(result));

    int index = 0;

    LE_DEBUG("Found app count %d.", foundAppCount);

    while (foundAppCount > 0)
    {
        assetData_InstanceDataRef_t instanceRef = NULL;
        le_result_t result = assetData_GetInstanceRefById(LWM2M_NAME, 9, index, &instanceRef);

        LE_DEBUG("Index %d.", index);

        if (result == LE_OK)
        {
            assetData_client_GetString(instanceRef, O9F_PKG_NAME, appName, sizeof(appName));

            LE_DEBUG("Mapping app '%s'.", appName);

            SetObject9InstanceForApp(appName, instanceRef);
            foundAppCount--;
        }

        index++;
    }
}