Beispiel #1
0
/**
 * Initialize pstat resource by loading data from persistent storage.
 *
 * @retval  OC_STACK_OK for Success, otherwise some error value
 */
OCStackResult InitPstatResource()
{
    OCStackResult ret = OC_STACK_ERROR;

    // Read Pstat resource from PS
    char* jsonSVRDatabase = GetSVRDatabase();
    if (jsonSVRDatabase)
    {
        // Convert JSON Pstat into binary format
        gPstat = JSONToPstatBin(jsonSVRDatabase, true);
    }
    /*
     * If SVR database in persistent storage got corrupted or
     * is not available for some reason, a default pstat is created
     * which allows user to initiate pstat provisioning again.
     */
    if(!jsonSVRDatabase || !gPstat)
    {
        gPstat = GetPstatDefault();
    }
    // Instantiate 'oic.sec.pstat'
    ret = CreatePstatResource();

    OICFree(jsonSVRDatabase);
    return ret;
}
Beispiel #2
0
        gPstat = GetPstatDefault();
    }
    VERIFY_NON_NULL(TAG, gPstat, FATAL);

    //In case of Pstat's device id is empty, fill the device id as doxm's device id.
    if(0 == memcmp(&gPstat->deviceID, &emptyUuid, sizeof(OicUuid_t)))
    {
        OicUuid_t doxmUuid = {.id={0}};
        if(OC_STACK_OK == GetDoxmDeviceID(&doxmUuid))
        {
            memcpy(&gPstat->deviceID, &doxmUuid, sizeof(OicUuid_t));
        }
    }

    // Instantiate 'oic.sec.pstat'
    ret = CreatePstatResource();

exit:
    if (OC_STACK_OK != ret)
    {
        DeInitPstatResource();
    }
    return ret;
}

OCStackResult DeInitPstatResource()
{
    if (gPstat != &gDefaultPstat)
    {
        DeletePstatBinData(gPstat);
        gPstat = NULL;
Beispiel #3
0
//CreatePstatResource Tests
TEST(CreatePstatResourceTest, CreatePstatResource)
{
    EXPECT_EQ(OC_STACK_INVALID_PARAM,  CreatePstatResource());
}