######################################################################
# Source files and Targets
######################################################################
-tgm_src = env.Glob('sdk/src/*.cpp', '../../extlibs/timer/timer.c')
-tgmsdk_static = things_manager_env.StaticLibrary('TGMSDKLibrary', tgm_src)
-tgmsdk_shared = things_manager_env.SharedLibrary('TGMSDKLibrary', tgm_src)
-things_manager_env.InstallTarget([tgmsdk_static,tgmsdk_shared], 'libTGMSDK')
-things_manager_env.UserInstallTargetLib([tgmsdk_static,tgmsdk_shared], 'libTGMSDK')
-things_manager_env.UserInstallTargetHeader('sdk/inc/ActionSet.h', 'service/things-manager', 'ActionSet.h')
-things_manager_env.UserInstallTargetHeader('sdk/inc/ThingsManager.h', 'service/things-manager', 'ThingsManager.h')
-# Build JNI layer
-#if target_os == 'android':
-# SConscript(os.path.join('sdk', 'java', 'jni', 'SConscript'))
+# Remove it if the conversion for Android and Tizen platform is done
+if target_os == 'linux':
+ tgm_src = env.Glob('sdk/src/*.cpp', '../../extlibs/timer/timer.c')
+ tgmsdk_static = things_manager_env.StaticLibrary('TGMSDKLibrary', tgm_src)
+ tgmsdk_shared = things_manager_env.SharedLibrary('TGMSDKLibrary', tgm_src)
-#Go to build sample apps
-SConscript('sampleapp/SConscript')
+ things_manager_env.InstallTarget([tgmsdk_static,tgmsdk_shared], 'libTGMSDK')
+ things_manager_env.UserInstallTargetLib([tgmsdk_static,tgmsdk_shared], 'libTGMSDK')
+
+ # Build JNI layer
+ #if target_os == 'android':
+ # SConscript(os.path.join('sdk', 'java', 'jni', 'SConscript'))
+
+ #Go to build sample apps
+ SConscript('sampleapp/SConscript')
#include <functional>
#include <thread>
+#include <string.h>
#include "OCPlatform.h"
#include "OCApi.h"
-#include "ThingsManager.h"
#include "ConfigurationCollection.h"
using namespace OC;
+using namespace std;
/// This function internally calls registerResource API.
void ConfigurationResource::createResources(ResourceEntityHandler callback)
#include "OCPlatform.h"
#include "OCApi.h"
-#include "ThingsManager.h"
#pragma once
typedef std::function<
OCEntityHandlerResult(std::shared_ptr< OCResourceRequest > request) > ResourceEntityHandler;
-static std::string defaultURIPrefix = "/oic/con";
-static std::string defaultResourceTypePrefix = "oic.con";
+static std::string defaultConURI = "/oic/con";
+static std::string defaultConResourceType = "oic.wk.con";
extern std::string defaultLocation;
extern std::string defaultSystemTime;
m_location(defaultLocation), m_systemTime(defaultSystemTime), m_currency(
defaultCurrency), m_region(defaultRegion)
{
- m_configurationUri = "/oic/con"; // URI of the resource
- m_configurationTypes.push_back("oic.con"); // resource type name.
+ m_configurationUri = defaultConURI; // URI of the resource
+ m_configurationTypes.push_back(defaultConResourceType); // resource type name.
m_configurationInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
- //m_configurationInterfaces.push_back(BATCH_INTERFACE); // resource interface.
- //m_configurationInterfaces.push_back(LINK_INTERFACE); // resource interface.
m_configurationRep.setValue("loc", m_location);
m_configurationRep.setValue("st", m_systemTime);
m_configurationRep.setValue("c", m_currency);
#include <functional>
#include <thread>
+#include <string.h>
#include "OCPlatform.h"
#include "OCApi.h"
-#include "ThingsManager.h"
#include "DiagnosticsCollection.h"
using namespace OC;
+using namespace std;
/// This function internally calls registerResource API.
-void DiagnosticsResource::createResources(ResourceEntityHandler callback)
+void MaintenanceResource::createResources(ResourceEntityHandler callback)
{
using namespace OC::OCPlatform;
}
// This will internally create and register the resource.
- OCStackResult result = registerResource(m_diagnosticsHandle, m_diagnosticsUri,
- m_diagnosticsTypes[0], m_diagnosticsInterfaces[0], callback,
+ OCStackResult result = registerResource(m_maintenanceHandle, m_maintenanceUri,
+ m_maintenanceTypes[0], m_maintenanceInterfaces[0], callback,
OC_DISCOVERABLE | OC_OBSERVABLE);
if (OC_STACK_OK != result)
{
- std::cout << "Resource creation (diagnostics) was unsuccessful\n";
+ std::cout << "Resource creation (maintenance) was unsuccessful\n";
}
thread exec(
std::function< void(int second) >(
- std::bind(&DiagnosticsResource::diagnosticsMonitor, this,
+ std::bind(&MaintenanceResource::maintenanceMonitor, this,
std::placeholders::_1)), 10); // every 10 seconds
exec.detach();
- std::cout << "Diagnostics Resource is Created!\n";
+ std::cout << "maintenance Resource is Created!\n";
}
-void DiagnosticsResource::setDiagnosticsRepresentation(OCRepresentation& rep)
+void MaintenanceResource::setMaintenanceRepresentation(OCRepresentation& rep)
{
string value;
}
}
-OCRepresentation DiagnosticsResource::getDiagnosticsRepresentation()
+OCRepresentation MaintenanceResource::getMaintenanceRepresentation()
{
- m_diagnosticsRep.setValue("fr", m_factoryReset);
- m_diagnosticsRep.setValue("rb", m_reboot);
- m_diagnosticsRep.setValue("ssc", m_startStatCollection);
+ m_maintenanceRep.setValue("fr", m_factoryReset);
+ m_maintenanceRep.setValue("rb", m_reboot);
+ m_maintenanceRep.setValue("ssc", m_startStatCollection);
- return m_diagnosticsRep;
+ return m_maintenanceRep;
}
-std::string DiagnosticsResource::getUri()
+std::string MaintenanceResource::getUri()
{
- return m_diagnosticsUri;
+ return m_maintenanceUri;
}
-void DiagnosticsResource::diagnosticsMonitor(int second)
+void MaintenanceResource::maintenanceMonitor(int second)
{
while (1)
{
#include "OCPlatform.h"
#include "OCApi.h"
-#include "ThingsManager.h"
#pragma once
typedef std::function<
OCEntityHandlerResult(std::shared_ptr< OCResourceRequest > request) > ResourceEntityHandler;
+static std::string defaultMntURI = "/oic/mnt";
+static std::string defaultMntResourceType = "oic.wk.mnt";
+
static std::string defaultFactoryReset = "false";
static std::string defaultReboot = "false";
static std::string defaultStartStatCollection = "false";
-class DiagnosticsResource
+class MaintenanceResource
{
public:
// diagnostics members
- std::string m_diagnosticsUri;
+ std::string m_maintenanceUri;
std::string m_factoryReset;
std::string m_reboot;
std::string m_startStatCollection;
- std::vector< std::string > m_diagnosticsTypes;
- std::vector< std::string > m_diagnosticsInterfaces;
- OCResourceHandle m_diagnosticsHandle;
- OCRepresentation m_diagnosticsRep;
+ std::vector< std::string > m_maintenanceTypes;
+ std::vector< std::string > m_maintenanceInterfaces;
+ OCResourceHandle m_maintenanceHandle;
+ OCRepresentation m_maintenanceRep;
public:
/// Constructor
- DiagnosticsResource() :
+ MaintenanceResource() :
m_factoryReset(defaultFactoryReset), m_reboot(defaultReboot),
m_startStatCollection(defaultStartStatCollection)
{
- m_diagnosticsUri = "/oic/diag"; // URI of the resource
- m_diagnosticsTypes.push_back("oic.diag"); // resource type name.
- m_diagnosticsInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
- m_diagnosticsRep.setValue("fr", m_factoryReset);
- m_diagnosticsRep.setValue("rb", m_reboot);
- m_diagnosticsRep.setValue("ssc", m_startStatCollection);
- m_diagnosticsRep.setUri(m_diagnosticsUri);
- m_diagnosticsRep.setResourceTypes(m_diagnosticsTypes);
- m_diagnosticsRep.setResourceInterfaces(m_diagnosticsInterfaces);
- m_diagnosticsHandle = NULL;
+ m_maintenanceUri = defaultMntURI; // URI of the resource
+ m_maintenanceTypes.push_back(defaultMntResourceType); // resource type name.
+ m_maintenanceInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
+ m_maintenanceRep.setValue("fr", m_factoryReset);
+ m_maintenanceRep.setValue("rb", m_reboot);
+ m_maintenanceRep.setValue("ssc", m_startStatCollection);
+ m_maintenanceRep.setUri(m_maintenanceUri);
+ m_maintenanceRep.setResourceTypes(m_maintenanceTypes);
+ m_maintenanceRep.setResourceInterfaces(m_maintenanceInterfaces);
+ m_maintenanceHandle = NULL;
}
;
/// This function internally calls registerResource API.
void createResources(ResourceEntityHandler callback);
- void setDiagnosticsRepresentation(OCRepresentation& rep);
+ void setMaintenanceRepresentation(OCRepresentation& rep);
- OCRepresentation getDiagnosticsRepresentation();
+ OCRepresentation getMaintenanceRepresentation();
std::string getUri();
- void diagnosticsMonitor(int second);
+ void maintenanceMonitor(int second);
std::function< void() > factoryReset;
};
#include <functional>
#include <thread>
+#include <string.h>
#include "OCPlatform.h"
#include "OCApi.h"
-#include "ThingsManager.h"
#include "FactorySetCollection.h"
using namespace OC;
+using namespace std;
FactorySetResource::FactorySetResource()
{
#include "OCPlatform.h"
#include "OCApi.h"
-#include "ThingsManager.h"
+//#include "ThingsManager.h"
#include "ConfigurationCollection.h"
#pragma once
#include <vector>
#include "OCPlatform.h"
#include "OCApi.h"
-#include "ThingsManager.h"
+//#include "ThingsManager.h"
+#include "ThingsConfiguration.h"
+#include "ThingsDiagnostics.h"
+#include "GroupManager.h"
using namespace OC;
using namespace OIC;
const int SUCCESS_RESPONSE = 0;
-static ThingsManager* g_thingsmanager;
+//static ThingsManager* g_thingsmanager;
+static GroupManager* g_groupmanager;
+static ThingsConfiguration* g_thingsConf;
+static ThingsMaintenance* g_thingsMnt;
OCResourceHandle configurationCollectionHandle;
std::shared_ptr< OCResource > g_configurationCollection; // for a group of multiple resources
std::shared_ptr< OCResource > g_configurationResource; // For a single resource
-OCResourceHandle diagnosticsCollectionHandle;
-std::shared_ptr< OCResource > g_diagnosticsCollection; // for a group of multiple resources
-std::shared_ptr< OCResource > g_diagnosticsResource; // For a single resource
+OCResourceHandle maintenanceCollectionHandle;
+std::shared_ptr< OCResource > g_maintenanceCollection; // for a group of multiple resources
+std::shared_ptr< OCResource > g_maintenanceResource; // For a single resource
OCResourceHandle setCollectionHandle;
std::shared_ptr< OCResource > g_setCollection; // for a group of multiple resources
std::map< std::string, std::shared_ptr< OCResource > > resourceTable;
std::vector< OCResourceHandle > resourceHandleVector;
-typedef std::function<
- void(const HeaderOptions& headerOptions,
- const OCRepresentation& rep, const int eCode) > ConfigurationCallback;
-typedef std::function<
- void(const HeaderOptions& headerOptions,
- const OCRepresentation& rep, const int eCode) > DiagnosticsCallback;
-
typedef std::string ConfigurationName;
typedef std::string ConfigurationValue;
{
if (resource->uri() == "/core/a/configuration/resourceset")
g_configurationCollection = resource;
- else if (resource->uri() == "/core/a/diagnostics/resourceset")
- g_diagnosticsCollection = resource;
+ else if (resource->uri() == "/core/a/maintenance/resourceset")
+ g_maintenanceCollection = resource;
else if (resource->uri() == "/core/a/factoryset/resourceset")
g_setCollection = resource;
else
if (g_configurationResource == NULL)
g_configurationResource = resource;
}
- else if (resource->uri() == "/oic/diag")
+ else if (resource->uri() == "/oic/mnt")
{
- OCPlatform::bindResource(diagnosticsCollectionHandle,
+ OCPlatform::bindResource(maintenanceCollectionHandle,
foundResourceHandle);
- if (g_diagnosticsResource == NULL)
- g_diagnosticsResource = resource;
+ if (g_maintenanceResource == NULL)
+ g_maintenanceResource = resource;
}
else if (resource->uri() == "/factorySet")
{
{ OC::ServiceType::InProc, OC::ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos };
OCPlatform::Configure(cfg);
- g_thingsmanager = new ThingsManager();
+ //g_thingsmanager = new ThingsManager();
+ g_thingsConf = new ThingsConfiguration();
+ g_thingsMnt = new ThingsMaintenance();
+ g_groupmanager = new GroupManager();
//**************************************************************
pthread_mutex_unlock(&mutex_lock);
cout << endl << endl << "(0) Quit" << std::endl;
- cout << "(1) Find all resources(URI: /oic/con, /oic/diag, /factoryset)" << std::endl;
+ cout << "(1) Find all resources(URI: /oic/con, /oic/mnt, /factoryset)" << std::endl;
cout << "(2) Find all groups" << std::endl;
cout << "(3) Get a Configuration resource" << std::endl;
cout << "(4) Update a region attribute value" << std::endl;
DEFAULT_INTERFACE);
}
- // For Registering a collection resource for diagnostics resources
- if (diagnosticsCollectionHandle == NULL)
+ // For Registering a collection resource for maintenance resources
+ if (maintenanceCollectionHandle == NULL)
{
- string resourceURI = "/core/a/diagnostics/resourceset";
- string resourceTypeName = "core.diagnostics.resourceset";
+ string resourceURI = "/core/a/maintenance/resourceset";
+ string resourceTypeName = "core.maintenance.resourceset";
string resourceInterface = BATCH_INTERFACE;
- OCPlatform::registerResource(diagnosticsCollectionHandle, resourceURI,
+ OCPlatform::registerResource(maintenanceCollectionHandle, resourceURI,
resourceTypeName, resourceInterface, NULL,
//&entityHandler, // entityHandler
OC_DISCOVERABLE);
- OCPlatform::bindInterfaceToResource(diagnosticsCollectionHandle, GROUP_INTERFACE);
- OCPlatform::bindInterfaceToResource(diagnosticsCollectionHandle, DEFAULT_INTERFACE);
+ OCPlatform::bindInterfaceToResource(maintenanceCollectionHandle, GROUP_INTERFACE);
+ OCPlatform::bindInterfaceToResource(maintenanceCollectionHandle, DEFAULT_INTERFACE);
}
// For Registering a collection resource for set resources
OCPlatform::bindInterfaceToResource(setCollectionHandle, DEFAULT_INTERFACE);
}
- types.push_back("oic.con");
- types.push_back("oic.diag");
+ types.push_back("oic.wk.con");
+ types.push_back("oic.wk.mnt");
types.push_back("factorySet");
std::cout << "Finding Configuration Resource... " << std::endl;
- std::cout << "Finding Diagnostics Resource... " << std::endl;
+ std::cout << "Finding Maintenance Resource... " << std::endl;
std::cout << "Finding Set Resource... " << std::endl;
- g_thingsmanager->findCandidateResources(types, &onFoundCandidateResource, 5);
+ g_groupmanager->findCandidateResources(types, &onFoundCandidateResource, 5);
pthread_mutex_lock(&mutex_lock);
isWaiting = 1;
{
std::vector< std::string > types;
types.push_back("core.configuration.resourceset");
- types.push_back("core.diagnostics.resourceset");
+ types.push_back("core.maintenance.resourceset");
types.push_back("core.factoryset.resourceset");
- g_thingsmanager->findCandidateResources(types, &onFoundCollectionResource, 5);
+ g_groupmanager->findCandidateResources(types, &onFoundCollectionResource, 5);
std::cout << "Finding Collection resource... " << std::endl;
configurations.push_back(name);
- if (g_thingsmanager->getConfigurations(g_configurationCollection, configurations, &onGet)
+ if (g_thingsConf->getConfigurations(g_configurationCollection, configurations, &onGet)
!= OC_STACK_ERROR)
{
pthread_mutex_lock(&mutex_lock);
configurations.insert(std::make_pair(name, value));
- if (g_thingsmanager->updateConfigurations(g_configurationCollection, configurations,
+ if (g_thingsConf->updateConfigurations(g_configurationCollection, configurations,
&onUpdate) != OC_STACK_ERROR)
{
pthread_mutex_lock(&mutex_lock);
else if (g_Steps == 5)
{
// factory reset
- if(g_diagnosticsCollection == NULL)
+ if(g_maintenanceCollection == NULL)
{
std::cout<<"Note that you first create a group to use this command." << std::endl;
continue;
}
- if (g_thingsmanager->factoryReset(g_diagnosticsCollection, &onFactoryReset)
+ if (g_thingsMnt->factoryReset(g_maintenanceCollection, &onFactoryReset)
!= OC_STACK_ERROR)
{
pthread_mutex_lock(&mutex_lock);
else if (g_Steps == 6)
{
// reboot
- if(g_diagnosticsCollection == NULL)
+ if(g_maintenanceCollection == NULL)
{
std::cout<<"Note that you first create a group to use this command." << std::endl;
continue;
}
- if (g_thingsmanager->reboot(g_diagnosticsCollection, &onReboot) != OC_STACK_ERROR)
+ if (g_thingsMnt->reboot(g_maintenanceCollection, &onReboot) != OC_STACK_ERROR)
{
pthread_mutex_lock(&mutex_lock);
isWaiting = 0;
}
else if (g_Steps == 10)
{
- std::cout << g_thingsmanager->getListOfSupportedConfigurationUnits() << std::endl;
+ std::cout << g_thingsConf->getListOfSupportedConfigurationUnits() << std::endl;
}
}
#include "OCPlatform.h"
#include "OCApi.h"
-#include "ThingsManager.h"
+#include "ThingsConfiguration.h"
+#include "ThingsDiagnostics.h"
#include "ConfigurationCollection.h"
#include "DiagnosticsCollection.h"
#include "FactorySetCollection.h"
std::string defaultSystemTime;
std::string defaultCurrency;
-static ThingsManager* g_thingsmanager;
+//static ThingsManager* g_thingsmanager;
+static ThingsConfiguration* g_thingsConf;
// Forward declaring the entityHandler (Configuration)
bool prepareResponseForResource(std::shared_ptr< OCResourceRequest > request);
OCEntityHandlerResult entityHandlerForResource(std::shared_ptr< OCResourceRequest > request);
ConfigurationResource *myConfigurationResource;
-DiagnosticsResource *myDiagnosticsResource;
+MaintenanceResource *myMaintenanceResource;
FactorySetResource *myFactorySetResource;
typedef std::function< void(OCRepresentation&) > putFunc;
res = std::bind(&ConfigurationResource::getConfigurationRepresentation,
myConfigurationResource);
}
- else if (uri == myDiagnosticsResource->getUri())
+ else if (uri == myMaintenanceResource->getUri())
{
- res = std::bind(&DiagnosticsResource::getDiagnosticsRepresentation,
- myDiagnosticsResource);
+ res = std::bind(&MaintenanceResource::getMaintenanceRepresentation,
+ myMaintenanceResource);
}
return res;
res = std::bind(&ConfigurationResource::setConfigurationRepresentation,
myConfigurationResource, std::placeholders::_1);
}
- else if (uri == myDiagnosticsResource->getUri())
+ else if (uri == myMaintenanceResource->getUri())
{
- res = std::bind(&DiagnosticsResource::setDiagnosticsRepresentation,
- myDiagnosticsResource, std::placeholders::_1);
+ res = std::bind(&MaintenanceResource::setMaintenanceRepresentation,
+ myMaintenanceResource, std::placeholders::_1);
}
return res;
{ OC::ServiceType::InProc, OC::ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos };
OCPlatform::Configure(cfg);
- g_thingsmanager = new ThingsManager();
+ g_thingsConf = new ThingsConfiguration();
+ //g_thingsDiag = new ThingsDiagnostics();
//**************************************************************
if (getuid() != 0)
}
else if (g_Steps == 1)
{
- if( g_thingsmanager->doBootstrap(&onBootstrap) == OC_STACK_OK)
+ if( g_thingsConf->doBootstrap(&onBootstrap) == OC_STACK_OK)
{
pthread_mutex_lock(&mutex_lock);
isWaiting = 1;
myConfigurationResource = new ConfigurationResource();
myConfigurationResource->createResources(&entityHandlerForResource);
- myDiagnosticsResource = new DiagnosticsResource();
- myDiagnosticsResource->createResources(&entityHandlerForResource);
-
+ myMaintenanceResource = new MaintenanceResource();
+ myMaintenanceResource->createResources(&entityHandlerForResource);
myFactorySetResource = new FactorySetResource();
myFactorySetResource->createResources(&entityHandlerForResource);
- myDiagnosticsResource->factoryReset = std::function < void()
+ myMaintenanceResource->factoryReset = std::function < void()
> (std::bind(&ConfigurationResource::factoryReset,
myConfigurationResource));
#include "timer.h"
-#include <ThingsManager.h>
+#include <GroupManager.h>
using namespace std;
using namespace OC;
shared_ptr<OCResource> g_resource;
vector<string> lights;
-ThingsManager *thingsMgr = new ThingsManager();
+GroupManager *groupMgr = new GroupManager();
void onGet(const HeaderOptions& opt, const OCRepresentation &rep,
const int eCode);
if (rep.getValue("ActionSet", plainText))
{
- ActionSet *actionset = thingsMgr->getActionSetfromString(plainText);
+ ActionSet *actionset = groupMgr->getActionSetfromString(plainText);
if (actionset != NULL)
{
cout << endl << "\tACTIONSET NAME :: "
void Scheduled_AllbulbOff()
{
- thingsMgr->executeActionSet(g_resource, "AllBulbOffScheduledCall", &onPost);
+ groupMgr->executeActionSet(g_resource, "AllBulbOffScheduledCall", &onPost);
}
void Scheduled_AllbulbOffEx()
{
- thingsMgr->executeActionSet(g_resource, "AllBulbOffScheduledCall", 10, &onPost);
+ groupMgr->executeActionSet(g_resource, "AllBulbOffScheduledCall", 10, &onPost);
}
void CancelScheduled_AllBulbOff()
{
- thingsMgr->cancelActionSet(g_resource, "AllBulbOffScheduledCall", &onPost);
+ groupMgr->cancelActionSet(g_resource, "AllBulbOffScheduledCall", &onPost);
}
void Recursive_allBulbOn()
{
- thingsMgr->executeActionSet(g_resource, "AllBulbOnRecursiveCall", &onPost);
+ groupMgr->executeActionSet(g_resource, "AllBulbOnRecursiveCall", &onPost);
}
void Recursive_allBulbOnEx()
{
- thingsMgr->executeActionSet(g_resource, "AllBulbOnRecursiveCall", 10, &onPost);
+ groupMgr->executeActionSet(g_resource, "AllBulbOnRecursiveCall", 10, &onPost);
}
void CancelRecursive_allBulbOn()
{
- thingsMgr->cancelActionSet(g_resource, "AllBulbOnRecursiveCall", &onPost);
+ groupMgr->cancelActionSet(g_resource, "AllBulbOnRecursiveCall", &onPost);
}
void onObserve(const HeaderOptions headerOptions, const OCRepresentation& rep,
}
if (g_resource)
{
- thingsMgr->addActionSet(g_resource, allBulbOff, onPut);
+ groupMgr->addActionSet(g_resource, allBulbOff, onPut);
}
delete allBulbOff;
}
if (g_resource)
{
- thingsMgr->addActionSet(g_resource, allBulbOff, onPut);
+ groupMgr->addActionSet(g_resource, allBulbOff, onPut);
}
delete allBulbOff;
}
if (g_resource)
{
- thingsMgr->addActionSet(g_resource, allBulbOff, onPut);
+ groupMgr->addActionSet(g_resource, allBulbOff, onPut);
}
delete allBulbOff;
}
if (g_resource)
{
- thingsMgr->addActionSet(g_resource, allBulbOn, onPut);
+ groupMgr->addActionSet(g_resource, allBulbOn, onPut);
}
delete allBulbOn;
// Find lights for group creation.
vector<string> types;
types.push_back("core.light");
- thingsMgr->findCandidateResources(types, &foundResources, 5);
+ groupMgr->findCandidateResources(types, &foundResources, 5);
OCStackResult res = OCPlatform::registerResource(resourceHandle, resourceURI,
resourceTypeName, resourceInterface, NULL, OC_DISCOVERABLE);
}
else if (n == 6)
{
- thingsMgr->getActionSet(g_resource, "AllBulbOff", onPost);
+ groupMgr->getActionSet(g_resource, "AllBulbOff", onPost);
}
else if (n == 7)
{
- thingsMgr->deleteActionSet(g_resource, "AllBulbOff", onPut);
+ groupMgr->deleteActionSet(g_resource, "AllBulbOff", onPut);
}
else if (n == 8)
{
#include <string>
#include <cstdlib>
#include <pthread.h>
+#include <string.h>
#include "OCPlatform.h"
#include "OCApi.h"
-#include "ThingsManager.h"
+#include "GroupSynchronization.h"
using namespace OC;
using namespace OIC;
+using namespace std;
-static ThingsManager* gThingManager = NULL;
+static GroupSynchronization* gGroupSynchronization = NULL;
static std::vector< OCResourceHandle > gResourceHandleList;
return;
}
- result = gThingManager->joinGroup(collectionResourceType, resourceHandle);
+ result = gGroupSynchronization->joinGroup(collectionResourceType, resourceHandle);
if (OC_STACK_OK == result)
{
cout << "onFindResource : Joining group was successful\n";
OC::QualityOfService::LowQos };
OCPlatform::Configure(cfg);
- gThingManager = new ThingsManager();
+ gGroupSynchronization = new GroupSynchronization();
int selectedMenu;
OCStackResult result;
if (selectedMenu == 1)
{
- result = gThingManager->createGroup(collectionResourceType);
+ result = gGroupSynchronization->createGroup(collectionResourceType);
if (OC_STACK_OK == result)
{
cout << "Group creation was successful\n";
std::string type = OCGetResourceTypeName(resourceHandle, 0);
if (0 == mpType.compare(type))
{
- result = gThingManager->leaveGroup(collectionResourceType, resourceHandle);
+ result = gGroupSynchronization->leaveGroup(collectionResourceType, resourceHandle);
if (OC_STACK_OK == result)
{
cout << "Leaving group of music player was successful\n";
std::string type = OCGetResourceTypeName(resourceHandle, 0);
if (0 == mpType.compare(type))
{
- result = gThingManager->leaveGroup(collectionResourceType, resourceHandle);
+ result = gGroupSynchronization->leaveGroup(collectionResourceType, resourceHandle);
if (OC_STACK_OK == result)
{
cout << "Leaving group of speaker was successful\n";
}
else if (selectedMenu == 31)
{
- gThingManager->deleteGroup(collectionResourceType);
+ gGroupSynchronization->deleteGroup(collectionResourceType);
}
}
}
#include <string>
#include <cstdlib>
#include <pthread.h>
+#include <string.h>
#include "OCPlatform.h"
#include "OCApi.h"
-#include "ThingsManager.h"
using namespace OC;
+using namespace std;
OCEntityHandlerResult mpEntityHandler(const std::shared_ptr< OCResourceRequest > request)
{
#include <pthread.h>
#include "OCPlatform.h"
#include "OCApi.h"
-#include "ThingsManager.h"
+#include "GroupManager.h"
+#include "GroupSynchronization.h"
using namespace OC;
using namespace OIC;
+using namespace std;
-static ThingsManager* gThingManager = NULL;
+static GroupManager* gGroupManager = NULL;
+static GroupSynchronization* gGroupSynchronization = NULL;
static OCResourceHandle gPhoneResourceHandle = NULL;
gFindGroup = resource;
{
OCStackResult res;
- res = gThingManager->subscribeCollectionPresence( resource, &presenceCallback);
+ res = gGroupManager->subscribeCollectionPresence( resource, &presenceCallback);
std::cout << "Return Value: " << res << std::endl;
}
}
- gThingManager->joinGroup(gFindGroup, gPhoneResourceHandle);
+ gGroupSynchronization->joinGroup(gFindGroup, gPhoneResourceHandle);
}
else
{
if (0 == gPlayStart->listOfAction.empty())
{
- result = gThingManager->addActionSet(gFindGroup, gPlayStart, onAction);
+ result = gGroupManager->addActionSet(gFindGroup, gPlayStart, onAction);
if (OC_STACK_OK == result)
{
cout << "addActionSet(gPlayStart) was successful\n";
if (0 == gPlayStop->listOfAction.empty())
{
- result = gThingManager->addActionSet(gFindGroup, gPlayStop, onAction);
+ result = gGroupManager->addActionSet(gFindGroup, gPlayStop, onAction);
if (OC_STACK_OK == result)
{
cout << "addActionSet(gPlayStop) was successful\n";
{ OC::ServiceType::InProc, OC::ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos };
OCPlatform::Configure(cfg);
- gThingManager = new ThingsManager();
+ gGroupManager = new GroupManager();
+ gGroupSynchronization = new GroupSynchronization();
int selectedMenu;
OCStackResult result;
types.clear();
types.push_back(collectionResourceType);
- result = gThingManager->findGroup(types, &onFindGroup);
+ result = gGroupSynchronization->findGroup(types, &onFindGroup);
if (OC_STACK_OK == result)
{
cout << "Finding group was successful\n";
continue;
}
- result = gThingManager->executeActionSet(gFindGroup, "playstart", onAction);
+ result = gGroupManager->executeActionSet(gFindGroup, "playstart", onAction);
if (OC_STACK_OK == result)
{
cout << "DoAction(playstart) was successful\n";
continue;
}
- result = gThingManager->executeActionSet(gFindGroup, "playstop", onAction);
+ result = gGroupManager->executeActionSet(gFindGroup, "playstop", onAction);
if (OC_STACK_OK == result)
{
cout << "DoAction(playstop) was successful\n";
continue;
}
- result = gThingManager->deleteActionSet(gFindGroup, "playstart", onAction);
+ result = gGroupManager->deleteActionSet(gFindGroup, "playstart", onAction);
if (OC_STACK_OK == result)
{
cout << "Delete Action(playstart) was successful\n";
<< endl;
}
- result = gThingManager->deleteActionSet(gFindGroup, "playstop", onAction);
+ result = gGroupManager->deleteActionSet(gFindGroup, "playstop", onAction);
if (OC_STACK_OK == result)
{
cout << "Delete Action(playstop) was successful\n";
continue;
}
- result = gThingManager->leaveGroup(gFindGroup, collectionResourceType, gPhoneResourceHandle);
+ result = gGroupSynchronization->leaveGroup(gFindGroup, collectionResourceType, gPhoneResourceHandle);
if (OC_STACK_OK == result)
{
cout << "Leaving group was successful\n";
#include <string>
#include <cstdlib>
#include <pthread.h>
+#include <string.h>
#include "OCPlatform.h"
#include "OCApi.h"
-#include "ThingsManager.h"
using namespace OC;
+using namespace std;
OCEntityHandlerResult speakerEntityHandler(const std::shared_ptr< OCResourceRequest > request)
{
*/
public:
+ /**
+ * API for extracting an action set string from the ActionSet class instance
+ *
+ * @param newActionSet pointer of ActionSet class instance
+ *
+ * @return std::string return value of this API.
+ * It returns an action set String.
+ * @note OCStackResult is defined in ocstack.h.
+ */
std::string getStringFromActionSet(const ActionSet *newActionSet);
+
+ /**
+ * API for extrracting ActionSet class instance from an action set string.
+ *
+ * @param desc description of an action set string
+ *
+ * @return ActionSet* return value of this API.
+ * It returns pointer of ActionSet.
+ */
ActionSet* getActionSetfromString(std::string desc);
+ /**
+ * API for adding an action set.
+ * Callback is called when the response of PUT operation arrives.
+ *
+ * @param resource resource pointer of the group resource
+ * @param newActionSet pointer of ActionSet class instance
+ * @param callback callback for PUT operation.
+ *
+ * @return Returns ::OC_STACK_OK if success.
+ *
+ * @note OCStackResult is defined in ocstack.h.
+ */
OCStackResult addActionSet(std::shared_ptr< OCResource > resource,
const ActionSet* newActionSet, PutCallback cb);
+
+ /**
+ * API for executing an existing action set.
+ * Callback is called when the response of POST operation arrives.
+ *
+ * @param resource resource pointer of the group resource
+ * @param actionsetName the action set name for executing the action set
+ * @param callback callback for POST operation.
+ *
+ * @return Returns ::OC_STACK_OK if success.
+ * @note OCStackResult is defined in ocstack.h.
+ */
OCStackResult executeActionSet(std::shared_ptr< OCResource > resource,
std::string actionsetName, PostCallback cb);
+
+ /**
+ * API for executing an existing action set.
+ * Callback is called when the response of POST operation arrives.
+ *
+ * @param resource resource pointer of the group resource
+ * @param actionsetName the action set name for executing the action set
+ * @param delay waiting time for until the action set run.
+ * @param callback callback for POST operation.
+ *
+ * @return Returns ::OC_STACK_OK if success.
+ * @note OCStackResult is defined in ocstack.h.
+ */
OCStackResult executeActionSet(std::shared_ptr< OCResource > resource,
std::string actionsetName, long int delay, PostCallback cb);
+
+ /**
+ * API for canceling an existing action set.
+ * Callback is called when the response of POST operation arrives.
+ *
+ * @param resource resource pointer of the group resource
+ * @param actionsetName the action set name for executing the action set
+ * @param callback callback for POST operation.
+ *
+ * @return Returns ::OC_STACK_OK if success.
+ * @note OCStackResult is defined in ocstack.h.
+ */
OCStackResult cancelActionSet(std::shared_ptr< OCResource > resource,
std::string actionsetName, PostCallback cb);
+
+ /**
+ * API for reading an existing action set.
+ * Callback is called when the response of GET operation arrives.
+ *
+ * @param resource resource pointer of the group resource
+ * @param actionsetName the action set name for reading the action set
+ * @param callback callback for GET operation.
+ *
+ * @return Returns ::OC_STACK_OK if success.
+ * @note OCStackResult is defined in ocstack.h.
+ */
OCStackResult getActionSet(std::shared_ptr< OCResource > resource, std::string actionsetName,
PostCallback cb);
+
+ /**
+ * API for removing an existing action set.
+ * Callback is called when the response of POST operation arrives.
+ *
+ * @param resource resource pointer of the group resource
+ * @param actionsetName the action set name for removing the action set
+ * @param callback callback for POST operation.
+ *
+ * @return Returns ::OC_STACK_OK if success.
+ * @note OCStackResult is defined in ocstack.h.
+ */
OCStackResult deleteActionSet(std::shared_ptr< OCResource > resource, std::string actionsetName,
PostCallback);
};
--- /dev/null
+//******************************************************************
+//
+// Copyright 2014 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/**
+ * @file
+ *
+ * This file contains the declaration of classes and its members related to
+ * GroupSynchronization.
+ */
+
+#ifndef __OC_GROUPSYNCHRONIZATION__
+#define __OC_GROUPSYNCHRONIZATION__
+
+#include <string>
+#include <vector>
+#include <map>
+#include <cstdlib>
+#include "OCPlatform.h"
+#include "OCApi.h"
+
+using namespace OC;
+
+namespace OIC
+{
+ class GroupSynchronization
+ {
+ private:
+
+ std::map< std::string, OCResourceHandle > collectionResourceHandleList;
+ // collection resource handle list
+ std::map< OCResourceHandle, std::vector< OCResourceHandle > > childResourceHandleList;
+
+ std::map< std::string, OCResourceHandle > groupSyncResourceHandleList;
+ // group sync resource handle list
+ std::map< std::string, std::shared_ptr< OCResource > > groupSyncResourceList;
+ // remote group sync resource list
+
+ std::vector< OCResourceHandle > deviceResourceHandleList; // these cannot be removed.
+ OCResourceHandle deviceResourceHandle;
+
+ OCResourceHandle collectionResourceHandle; // collection handle
+ std::shared_ptr< OCResource > remoteCollectionResource;
+
+ FindCallback findCallback;
+
+ std::vector< std::shared_ptr< OCResource > > foundGroupResourceList;
+
+ std::mutex foundGroupMutex;
+ // std::mutex groupSyncMutex;
+
+ std::shared_ptr< OCResourceRequest > resourceRequest; // this is used for slow response
+
+ static GroupSynchronization* groupSyncnstance;
+ static bool bIsFinding;
+
+ public:
+
+ GroupSynchronization()
+ {
+ collectionResourceHandleList.clear();
+ childResourceHandleList.clear();
+ groupSyncResourceHandleList.clear();
+ groupSyncResourceList.clear();
+ deviceResourceHandleList.clear();
+
+ deviceResourceHandle = NULL;
+ collectionResourceHandle = NULL;
+ remoteCollectionResource = NULL;
+ findCallback = NULL;
+ }
+ ;
+
+ ~GroupSynchronization()
+ {
+ std::map< std::string, OCResourceHandle >::iterator handleIt;
+ for (handleIt = collectionResourceHandleList.begin();
+ handleIt != collectionResourceHandleList.end(); ++handleIt)
+ {
+ deleteGroup(handleIt->first);
+ }
+ }
+ ;
+
+ // TODO: deprecated
+ static GroupSynchronization* getInstance();
+ void deleteInstance();
+
+ /**
+ * API for finding a specific remote group when a resource tries to join a group.
+ * Callback is called when a group is found or not.
+ *
+ * @param collectionResourceTypes resource types of a group to find and join
+ * @param callback callback. It has OCResource param.
+ * If a group is found, OCResource has the group resource.
+ * Otherwise, OCResource is NULL.
+ *
+ * @return Returns ::OC_STACK_OK if success.
+ * @note It returns OC_STACK ERROR when it is already finding a group.
+ * You should call this api after the group finding process has stopped.
+ * OCStackResult is defined in ocstack.h.
+ */
+ OCStackResult findGroup(std::vector< std::string > collectionResourceTypes,
+ FindCallback callback);
+
+ /**
+ * API for creating a new group.
+ *
+ * @param collectionResourceType resource type of a group to create
+ *
+ * @return Returns ::OC_STACK_OK if success.
+ * @note OCStackResult is defined in ocstack.h.
+ */
+ OCStackResult createGroup(std::string collectionResourceType);
+
+ /**
+ * API for joining a group. This API is used when a resource that has a group tries
+ * to find a specific remote resource and makes it join a group
+ *
+ * @param collectionResourceType resource type of a group to join.
+ * @param resourceHandle resource handle to join a group.
+ *
+ * @return Returns ::OC_STACK_OK if success.
+ *
+ * @note If you want to join the resource in the remote(other) process,
+ * use joinGroup(const std::shared_ptr< OCResource >, OCResourceHandle)
+ * instead of this.
+ * OCStackResult is defined in ocstack.h.
+ */
+ OCStackResult joinGroup(std::string collectionResourceTyps,
+ OCResourceHandle resourceHandle);
+
+ /**
+ * API for joining a group. This API is used when a resource that
+ * doesn't have a group tries to find and join a specific remote group.
+ *
+ * @param resource group resource pointer to join.
+ * It can be the callback result of findGroup().
+ * @param resourceHandle resource handle to join a group.
+ *
+ * @return Returns ::OC_STACK_OK if success.
+ * @note If you want to join the resource in the same process,
+ * use joinGroup(std::string, OCResourceHandle)
+ * instead of this.
+ * OCStackResult is defined in ocstack.h.
+ */
+ OCStackResult joinGroup(const std::shared_ptr< OCResource > resource,
+ OCResourceHandle resourceHandle);
+
+ /**
+ * API for leaving a joined group.
+ *
+ * @param collectionResourceType resource type of a group to leave.
+ * @param resourceHandle resource handle to leave a group.
+ *
+ * @return Returns ::OC_STACK_OK if success.
+ * @note OCStackResult is defined in ocstack.h.
+ */
+ OCStackResult leaveGroup(std::string collectionResourceType,
+ OCResourceHandle resourceHandle);
+
+ /**
+ * API for leaving a joined group.
+ *
+ * @param resource group resource pointer to join.
+ * It can be the callback result of findGroup().
+ *
+ * @param collectionResourceType resource type of a group to leave.
+ * @param resourceHandle resource handle to leave a group.
+ *
+ * @return Returns ::OC_STACK_OK if success.
+ *
+ * @note OCStackResult is defined in ocstack.h.
+ */
+ OCStackResult leaveGroup(const std::shared_ptr< OCResource > resource,
+ std::string collectionResourceType,
+ OCResourceHandle resourceHandle);
+
+ /**
+ * API for deleting a group.
+ *
+ * @param collectionResourceType resource type of a group to delete.
+ *
+ * @return void
+ */
+ void deleteGroup(std::string collectionResourceType);
+
+ /**
+ * API for getting a list of joined groups.
+ *
+ * @return std::map return value of this API.
+ * It returns group resource type and group resource handle as a map type.
+ */
+ std::map< std::string, OCResourceHandle > getGroupList();
+
+ private:
+
+ OCEntityHandlerResult groupEntityHandler(
+ const std::shared_ptr< OCResourceRequest > request);
+
+ void onFindGroup(std::shared_ptr< OCResource > resource);
+ void onJoinGroup(const HeaderOptions& headerOptions, const OCRepresentation& rep,
+ const int eCode);
+ void onFindResource(std::shared_ptr< OCResource > resource);
+ void onGetJoinedRemoteChild(const HeaderOptions& headerOptions, const OCRepresentation& rep,
+ const int eCode);
+ void onLeaveGroup(const HeaderOptions& headerOptions, const OCRepresentation& rep,
+ const int eCode);
+ void checkFindGroup(void);
+ bool IsSameGroup(std::shared_ptr< OCResource > resource);
+ void saveGroup(std::shared_ptr< OCResource > resource);
+
+ void debugGroupSync(void);
+
+ };
+}
+#endif // __OC_GROUPSYNCHRONIZATION__
static ThingsConfiguration *thingsConfigurationInstance;
static ThingsConfiguration* getInstance();
- void deleteInstance();
+ // TODO: deprecated
+ void deleteInstance();
void setGroupManager(GroupManager *groupmanager);
/**
* @file
*
* This file contains the declaration of classes and its members related to
- * ThingsDiagnostics.
+ * ThingsMaintenance.
*/
-#ifndef __OC_THINGSDIAGNOSTICS__
-#define __OC_THINGSDIAGNOSTICS__
+#ifndef __OC_THINGSMAINTENANCE__
+#define __OC_THINGSMAINTENANCE__
#include <string>
#include <vector>
using namespace OC;
namespace OIC
{
- /// Declearation of Diagnostics Callback funtion type
+ /// Declearation of Maintenance Callback funtion type
typedef std::function<
void(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
- > DiagnosticsCallback;
+ > MaintenanceCallback;
/**
* @brief
* The following class is used as a item stacking in request queue. The class stores a request
- * and referential information (e.g., a diagnostics name, a target resource object, a callback
+ * and referential information (e.g., a maintenance name, a target resource object, a callback
* function passed from the applications, and a update value). When the function for updating/
- * getting diagnostics value is called from applications, this class instance is created and
+ * getting maintenance value is called from applications, this class instance is created and
* stored in the request queue. The queue is maintained in a std::map structure so if desiring
- * to find a specific request, you can find it by querying a diagnostics name.
+ * to find a specific request, you can find it by querying a maintenance name.
*/
- class DiagnosticsRequestEntry
+ class MaintenanceRequestEntry
{
public:
- DiagnosticsRequestEntry(std::string ID, DiagnosticsCallback callback,
+ MaintenanceRequestEntry(std::string ID, MaintenanceCallback callback,
std::shared_ptr< OCResource > resource, std::string updateVal);
- // Diagnostics Name (used in key value in std::map structure)
+ // Maintenance Name (used in key value in std::map structure)
// e.g., reboot and factoryset
std::string m_ID;
// Reference callback pointer
- DiagnosticsCallback m_callback;
+ MaintenanceCallback m_callback;
// Reference resource object
std::shared_ptr< OCResource > m_resource;
- // Update value only used for diagnostics update (always "true")
+ // Update value only used for maintenance update (always "true")
std::string m_updateVal;
};
/**
* @brief
- * The following class is used to store providing diagnostics name and its relevant information
+ * The following class is used to store providing maintenance name and its relevant information
* The relevant information includes a brief description, uri, and attribute key.
- * Note that a developer only specifies a diagnostics name, not URI nor attribute key, to
- * update a value to a remote. Thus, using diagnostics name, we convert it to more specific
+ * Note that a developer only specifies a maintenance name, not URI nor attribute key, to
+ * update a value to a remote. Thus, using maintenance name, we convert it to more specific
* information (i.e. uri and attribute key) to send a request. This class is reponsible to
* storing these information.
*/
- class DiagnosticsUnitInfo
+ class MaintenanceUnitInfo
{
public:
std::string m_name;
std::string m_attribute;
std::string m_uri;
- DiagnosticsUnitInfo(std::string name, std::string attribute, std::string uri);
+ MaintenanceUnitInfo(std::string name, std::string attribute, std::string uri);
// If a developer wants to know a list of configuration names, gives it in JSON format.
std::string getJSON();
};
#define NUMDIAGUNIT 3
- typedef std::string DiagnosticsName;
- typedef std::string DiagnosticsValue;
+ typedef std::string MaintenanceName;
+ typedef std::string MaintenanceValue;
- class ThingsDiagnostics
+ class ThingsMaintenance
{
public:
/**
- * Constructor for ThingsDiagnostics. Constructs a new ThingsDiagnostics
+ * Constructor for ThingsMaintenance. Constructs a new ThingsMaintenance
*/
- ThingsDiagnostics(void);
+ ThingsMaintenance(void);
/**
* Virtual destructor
*/
- ~ThingsDiagnostics(void);
+ ~ThingsMaintenance(void);
- static ThingsDiagnostics *thingsDiagnosticsInstance;
- static ThingsDiagnostics* getInstance();
- void deleteInstance();
+ static ThingsMaintenance *thingsMaintenanceInstance;
+ static ThingsMaintenance* getInstance();
+ // TODO: deprecated
+ void deleteInstance();
void setGroupManager(GroupManager *groupmanager);
/**
*
* NOTE: OCStackResult is defined in ocstack.h.
*/
- OCStackResult reboot(std::shared_ptr< OCResource > resource, DiagnosticsCallback callback);
+ OCStackResult reboot(std::shared_ptr< OCResource > resource, MaintenanceCallback callback);
/**
* API for factory reset on device
*/
OCStackResult factoryReset(std::shared_ptr< OCResource > resource,
- DiagnosticsCallback callback);
+ MaintenanceCallback callback);
/**
- * API to show a list of supported diagnostics units
+ * API to show a list of supported maintenance units
* Callback call when a response arrives.
*
* @return the list in JSON format
*/
- std::string getListOfSupportedDiagnosticsUnits();
+ std::string getListOfSupportedMaintenanceUnits();
private:
GroupManager *g_groupmanager;
- std::vector< DiagnosticsUnitInfo > DiagnosticsUnitTable;
+ std::vector< MaintenanceUnitInfo > MaintenanceUnitTable;
void onExecuteForGroupAction(const HeaderOptions& headerOptions,
const OCRepresentation& rep, const int eCode, std::string conf);
std::string conf);
std::shared_ptr< OCResource > getResource(std::string conf);
- DiagnosticsCallback getCallback(std::string conf);
+ MaintenanceCallback getCallback(std::string conf);
std::string getUpdateVal(std::string conf);
- std::string getAttributeByDiagnosticsName(DiagnosticsName name);
- std::string getUriByDiagnosticsName(DiagnosticsName name);
+ std::string getAttributeByMaintenanceName(MaintenanceName name);
+ std::string getUriByMaintenanceName(MaintenanceName name);
std::string getHostFromURI(std::string oldUri);
+++ /dev/null
-//******************************************************************
-//
-// Copyright 2014 Samsung Electronics All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-/**
- * @file
- *
- * This file contains the declaration of ThingsManager class and its
- * members related to ThingsManager.
- */
-
-#ifndef __OC_THINGSMANAGER__
-#define __OC_THINGSMANAGER__
-
-#include <string>
-#include <vector>
-#include <map>
-#include <cstdlib>
-#include <ActionSet.h>
-#include "OCPlatform.h"
-#include "OCApi.h"
-
-using namespace OC;
-
-namespace OIC
-{
- /**
- * @class ThingsManager
- * @brief This class provides a set of functions regarding group management,
- * synchronization of group, configuration of things, and diagnostics about things.
- *
- */
- class ThingsManager
- {
- public:
- /**
- * Constructor for ThingsManager
- */
- ThingsManager(void);
-
- /**
- * Virtual destructor for ThingsManager
- */
- ~ThingsManager(void);
-
- /**
- * API for discoverying candidate resources.
- * Callback is called when all resource types are found.
- *
- * @param resourceTypes required resource types(called "candidate")
- * @param candidateCallback callback. Returns OCResource vector.
- *
- * @return Returns ::OC_STACK_OK if success.
- * @note OCStackResult is defined in ocstack.h.
- */
- OCStackResult findCandidateResources(std::vector< std::string > resourceTypes,
- std::function< void(std::vector< std::shared_ptr< OCResource > >) > callback,
- int waitsec);
-
- /**
- * API for subscribing child's state.
- *
- * @param resource collection resource for subscribing presence of all child resources.
- * @param callback callback funcion for result of child's presence.
- *
- * @return Returns ::OC_STACK_OK if success.
- * @note OCStackResult is defined in ocstack.h.
- */
- OCStackResult subscribeCollectionPresence(std::shared_ptr< OCResource > resource,
- std::function< void(std::string, OCStackResult) > callback);
-
- /**
- * API for registering and binding resource to group.
- *
- * @param childHandle child resource handle. It will be filled from resource param.
- * @param resource resource for registering and binding to group. It has all data.
- * @param collectionHandle collection resource handle. It will be added child resource.
- *
- * @return Returns ::OC_STACK_OK if success.
- * @note OCStackResult is defined in ocstack.h.
- */
- OCStackResult bindResourceToGroup(OCResourceHandle& childHandle,
- std::shared_ptr< OCResource > resource, OCResourceHandle& collectionHandle);
-
- // Group Synchronization
-
- /**
- * API for finding a specific remote group when a resource tries to join a group.
- * Callback is called when a group is found or not.
- *
- * @param collectionResourceTypes resource types of a group to find and join
- * @param callback callback. It has OCResource param.
- * If a group is found, OCResource has the group resource.
- * Otherwise, OCResource is NULL.
- *
- * @return Returns ::OC_STACK_OK if success.
- * @note It returns OC_STACK ERROR when it is already finding a group.
- * You should call this api after the group finding process has stopped.
- * OCStackResult is defined in ocstack.h.
- */
- OCStackResult findGroup(std::vector< std::string > collectionResourceTypes,
- FindCallback callback);
-
- /**
- * API for creating a new group.
- *
- * @param collectionResourceType resource type of a group to create
- *
- * @return Returns ::OC_STACK_OK if success.
- * @note OCStackResult is defined in ocstack.h.
- */
- OCStackResult createGroup(std::string collectionResourceType);
-
- /**
- * API for joining a group. This API is used when a resource that has a group tries
- * to find a specific remote resource and makes it join a group
- *
- * @param collectionResourceType resource type of a group to join.
- * @param resourceHandle resource handle to join a group.
- *
- * @return Returns ::OC_STACK_OK if success.
- *
- * @note If you want to join the resource in the remote(other) process,
- * use joinGroup(const std::shared_ptr< OCResource >, OCResourceHandle)
- * instead of this.
- * OCStackResult is defined in ocstack.h.
- */
- OCStackResult joinGroup(std::string collectionResourceType,
- OCResourceHandle resourceHandle);
-
- /**
- * API for joining a group. This API is used when a resource that
- * doesn't have a group tries to find and join a specific remote group.
- *
- * @param resource group resource pointer to join.
- * It can be the callback result of findGroup().
- * @param resourceHandle resource handle to join a group.
- *
- * @return Returns ::OC_STACK_OK if success.
- * @note If you want to join the resource in the same process,
- * use joinGroup(std::string, OCResourceHandle)
- * instead of this.
- * OCStackResult is defined in ocstack.h.
- */
- OCStackResult joinGroup(const std::shared_ptr< OCResource > resource,
- OCResourceHandle resourceHandle);
-
- /**
- * API for leaving a joined group.
- *
- * @param collectionResourceType resource type of a group to leave.
- * @param resourceHandle resource handle to leave a group.
- *
- * @return Returns ::OC_STACK_OK if success.
- * @note OCStackResult is defined in ocstack.h.
- */
- OCStackResult leaveGroup(std::string collectionResourceType,
- OCResourceHandle resourceHandle);
-
- /**
- * API for leaving a joined group.
- *
- * @param resource group resource pointer to join.
- * It can be the callback result of findGroup().
- *
- * @param collectionResourceType resource type of a group to leave.
- * @param resourceHandle resource handle to leave a group.
- *
- * @return Returns ::OC_STACK_OK if success.
- *
- * @note OCStackResult is defined in ocstack.h.
- */
- OCStackResult leaveGroup(const std::shared_ptr< OCResource > resource,
- std::string collectionResourceType,
- OCResourceHandle resourceHandle);
-
- /**
- * API for deleting a group.
- *
- * @param collectionResourceType resource type of a group to delete.
- *
- * @return void
- */
- void deleteGroup(std::string collectionResourceType);
-
- /**
- * API for getting a list of joined groups.
- *
- * @return std::map return value of this API.
- * It returns group resource type and group resource handle as a map type.
- */
- std::map< std::string, OCResourceHandle > getGroupList();
-
- // Things Configuration
-
- /**
- * API for updating configuration value of multiple things of a target group
- * or a single thing.
- * Callback is called when a response arrives.
- * Before using the below function, a developer should acquire a resource pointer of
- * (collection) resource that he wants to send a request by calling findResource() function
- * provided in OCPlatform. And he should also notice a "Configuration Name" term which
- * represents a nickname of a target attribute of a resource that he wants to update.
- * The base motivation to introduce the term is to avoid a usage of URI to access a resource
- * from a developer. Thus, a developer should know which configuration names are supported
- * by Things Configuration class and what the configuration name means.
- * To get a list of supported configuration names,
- * use getListOfSupportedConfigurationUnits()
- * function, which provides the list in JSON format.
- *
- * @param resource resource pointer representing the target group or the single thing.
- * @param configurations ConfigurationUnit: an attribute key of target resource.
- * (e.g., loc, st, c, r)
- * Value : a value to be updated
- * @param callback callback for updateConfigurations.
- *
- * @return Returns ::OC_STACK_OK if success.
- * @note OCStackResult is defined in ocstack.h.
- */
- OCStackResult updateConfigurations(std::shared_ptr< OCResource > resource,
- std::map< std::string, std::string > configurations,
- std::function<
- void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
- const int eCode) > callback);
-
- /**
- * API for getting configuration value of multiple things of a target group
- * or a single thing.
- * Callback is called when a response arrives.
- *
- * @param resource resource pointer representing the target group or the single thing.
- * @param configurations ConfigurationUnit: an attribute key of target resource.
- * @param callback callback for getConfigurations.
- *
- * @return Returns ::OC_STACK_OK if success.
- * @note OCStackResult is defined in ocstack.h.
- */
- OCStackResult getConfigurations(std::shared_ptr< OCResource > resource,
- std::vector< std::string > configurations,
- std::function<
- void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
- const int eCode) > callback);
-
- /**
- * API for showing the list of supported configuration units (attribute keys)
- * Callback is called when a response arrives.
- *
- * @param void
- * @return std::string return value of this API.
- * It returns the list in JSON format
- */
- std::string getListOfSupportedConfigurationUnits();
-
- /**
- * API for boostrapping system configuration parameters from a bootstrap server.
- * Callback is called when a response from the bootstrap server arrives.
- *
- * @param callback callback for doBootstrap.
- *
- * @return Returns ::OC_STACK_OK if success.
- * @note OCStackResult is defined in ocstack.h.
- */
- OCStackResult doBootstrap(
- std::function<
- void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
- const int eCode) > callback);
-
- // Things Diagnostics
-
- /**
- * API to let thing(device) reboot.
- * The target thing could be a group of multiple things or a single thing.
- * Callback is called when a response arrives.
- *
- * @param resource resource pointer representing the target group
- * @param callback callback for reboot.
- *
- * @return Returns ::OC_STACK_OK if success.
- * @note OCStackResult is defined in ocstack.h.
- */
- OCStackResult reboot(std::shared_ptr< OCResource > resource,
- std::function<
- void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
- const int eCode) > callback);
-
- /**
- * API for factory reset on thing(device).
- * The target thing could be a group of multiple things or a single thing.
- * Callback is called when a response arrives.
- *
- * @param resource resource pointer representing the target group
- * @param callback callback for factoryReset.
- *
- * @return Returns ::OC_STACK_OK if success.
- * @note OCStackResult is defined in ocstack.h.
- */
- OCStackResult factoryReset(std::shared_ptr< OCResource > resource,
- std::function<
- void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
- const int eCode) > callback);
-
- // Group Action.
-
- /**
- * API for extracting an action set string from the ActionSet class instance
- *
- * @param newActionSet pointer of ActionSet class instance
- *
- * @return std::string return value of this API.
- * It returns an action set String.
- * @note OCStackResult is defined in ocstack.h.
- */
- std::string getStringFromActionSet(const ActionSet *newActionSet);
-
- /**
- * API for extrracting ActionSet class instance from an action set string.
- *
- * @param desc description of an action set string
- *
- * @return ActionSet* return value of this API.
- * It returns pointer of ActionSet.
- */
- ActionSet* getActionSetfromString(std::string desc);
-
- /**
- * API for adding an action set.
- * Callback is called when the response of PUT operation arrives.
- *
- * @param resource resource pointer of the group resource
- * @param newActionSet pointer of ActionSet class instance
- * @param callback callback for PUT operation.
- *
- * @return Returns ::OC_STACK_OK if success.
- *
- * @note OCStackResult is defined in ocstack.h.
- */
- OCStackResult addActionSet(std::shared_ptr< OCResource > resource,
- const ActionSet* newActionSet, PutCallback cb);
-
- /**
- * API for executing an existing action set.
- * Callback is called when the response of POST operation arrives.
- *
- * @param resource resource pointer of the group resource
- * @param actionsetName the action set name for executing the action set
- * @param callback callback for POST operation.
- *
- * @return Returns ::OC_STACK_OK if success.
- * @note OCStackResult is defined in ocstack.h.
- */
- OCStackResult executeActionSet(std::shared_ptr< OCResource > resource,
- std::string actionsetName, PostCallback cb);
-
- /**
- * API for executing an existing action set.
- * Callback is called when the response of POST operation arrives.
- *
- * @param resource resource pointer of the group resource
- * @param actionsetName the action set name for executing the action set
- * @param delay waiting time for until the action set run.
- * @param callback callback for POST operation.
- *
- * @return Returns ::OC_STACK_OK if success.
- * @note OCStackResult is defined in ocstack.h.
- */
- OCStackResult executeActionSet(std::shared_ptr< OCResource > resource,
- std::string actionsetName, long int delay, PostCallback cb);
-
- /**
- * API for canceling an existing action set.
- * Callback is called when the response of POST operation arrives.
- *
- * @param resource resource pointer of the group resource
- * @param actionsetName the action set name for executing the action set
- * @param callback callback for POST operation.
- *
- * @return Returns ::OC_STACK_OK if success.
- * @note OCStackResult is defined in ocstack.h.
- */
- OCStackResult cancelActionSet(std::shared_ptr< OCResource > resource,
- std::string actionsetName, PostCallback cb);
- /**
- * API for reading an existing action set.
- * Callback is called when the response of GET operation arrives.
- *
- * @param resource resource pointer of the group resource
- * @param actionsetName the action set name for reading the action set
- * @param callback callback for GET operation.
- *
- * @return Returns ::OC_STACK_OK if success.
- * @note OCStackResult is defined in ocstack.h.
- */
- OCStackResult getActionSet(std::shared_ptr< OCResource > resource,
- std::string actionsetName, GetCallback cb);
-
- /**
- * API for removing an existing action set.
- * Callback is called when the response of POST operation arrives.
- *
- * @param resource resource pointer of the group resource
- * @param actionsetName the action set name for removing the action set
- * @param callback callback for POST operation.
- *
- * @return Returns ::OC_STACK_OK if success.
- * @note OCStackResult is defined in ocstack.h.
- */
- OCStackResult deleteActionSet(std::shared_ptr< OCResource > resource,
- std::string actionsetName, PostCallback);
-
- };
-}
-#endif /* __OC_THINGSMANAGER__*/
+++ /dev/null
-//******************************************************************
-//
-// Copyright 2014 Samsung Electronics All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-/**
- * @file
- *
- * This file contains the declaration of classes and its members related to
- * GroupSynchronization.
- */
-
-#ifndef __OC_GROUPSYNCHRONIZATION__
-#define __OC_GROUPSYNCHRONIZATION__
-
-#include <string>
-#include <vector>
-#include <map>
-#include <cstdlib>
-#include "OCPlatform.h"
-#include "OCApi.h"
-
-using namespace OC;
-
-namespace OIC
-{
-class GroupSynchronization
-{
-private:
-
- std::map< std::string, OCResourceHandle > collectionResourceHandleList;
- // collection resource handle list
- std::map< OCResourceHandle, std::vector< OCResourceHandle > > childResourceHandleList;
-
- std::map< std::string, OCResourceHandle > groupSyncResourceHandleList;
- // group sync resource handle list
- std::map< std::string, std::shared_ptr< OCResource > > groupSyncResourceList;
- // remote group sync resource list
-
- std::vector< OCResourceHandle > deviceResourceHandleList; // these cannot be removed.
- OCResourceHandle deviceResourceHandle;
-
- OCResourceHandle collectionResourceHandle; // collection handle
- std::shared_ptr< OCResource > remoteCollectionResource;
-
- FindCallback findCallback;
-
- std::vector< std::shared_ptr< OCResource > > foundGroupResourceList;
-
- std::mutex foundGroupMutex;
-// std::mutex groupSyncMutex;
-
- std::shared_ptr< OCResourceRequest > resourceRequest; // this is used for slow response
-
- static GroupSynchronization* groupSyncnstance;
- static bool bIsFinding;
-
- GroupSynchronization()
- {
- collectionResourceHandleList.clear();
- childResourceHandleList.clear();
- groupSyncResourceHandleList.clear();
- groupSyncResourceList.clear();
- deviceResourceHandleList.clear();
-
- deviceResourceHandle = NULL;
- collectionResourceHandle = NULL;
- remoteCollectionResource = NULL;
- findCallback = NULL;
- }
- ;
-
- ~GroupSynchronization()
- {
- std::map< std::string, OCResourceHandle >::iterator handleIt;
- for (handleIt = collectionResourceHandleList.begin();
- handleIt != collectionResourceHandleList.end(); ++handleIt)
- {
- deleteGroup(handleIt->first);
- }
- }
- ;
-
-public:
-
- static GroupSynchronization* getInstance();
- void deleteInstance();
-
- OCStackResult findGroup(std::vector< std::string > collectionResourceTypes,
- FindCallback callback);
- OCStackResult createGroup(std::string collectionResourceType);
- OCStackResult joinGroup(std::string collectionResourceTyps,
- OCResourceHandle resourceHandle);
- OCStackResult joinGroup(const std::shared_ptr< OCResource > resource,
- OCResourceHandle resourceHandle);
- OCStackResult leaveGroup(std::string collectionResourceType,
- OCResourceHandle resourceHandle);
- OCStackResult leaveGroup(const std::shared_ptr< OCResource > resource,
- std::string collectionResourceType,
- OCResourceHandle resourceHandle);
- void deleteGroup(std::string collectionResourceType);
-
- std::map< std::string, OCResourceHandle > getGroupList();
-
-private:
-
- OCEntityHandlerResult groupEntityHandler(
- const std::shared_ptr< OCResourceRequest > request);
-
- void onFindGroup(std::shared_ptr< OCResource > resource);
- void onJoinGroup(const HeaderOptions& headerOptions, const OCRepresentation& rep,
- const int eCode);
- void onFindResource(std::shared_ptr< OCResource > resource);
- void onGetJoinedRemoteChild(const HeaderOptions& headerOptions, const OCRepresentation& rep,
- const int eCode);
- void onLeaveGroup(const HeaderOptions& headerOptions, const OCRepresentation& rep,
- const int eCode);
-// void onSubscribePresence (OCStackResult result,
-// const unsigned int nonce/*, std::string resourceType, std::string host*/);
-
- void checkFindGroup(void);
- bool IsSameGroup(std::shared_ptr< OCResource > resource);
- void saveGroup(std::shared_ptr< OCResource > resource);
-
- void debugGroupSync(void);
-
-};
-}
-#endif // __OC_GROUPSYNCHRONIZATION__
namespace OIC
{
- std::map< std::string, DiagnosticsRequestEntry > diagnosticsRequestTable;
- ThingsDiagnostics* ThingsDiagnostics::thingsDiagnosticsInstance = NULL;
+ std::map< std::string, MaintenanceRequestEntry > maintenanceRequestTable;
+ ThingsMaintenance* ThingsMaintenance::thingsMaintenanceInstance = NULL;
- DiagnosticsRequestEntry::DiagnosticsRequestEntry(std::string ID, DiagnosticsCallback callback,
+ MaintenanceRequestEntry::MaintenanceRequestEntry(std::string ID, MaintenanceCallback callback,
std::shared_ptr< OCResource > resource, std::string updateVal)
{
m_ID = ID;
m_updateVal = updateVal;
}
- DiagnosticsUnitInfo::DiagnosticsUnitInfo(std::string name,
+ MaintenanceUnitInfo::MaintenanceUnitInfo(std::string name,
std::string attribute,
std::string uri)
{
m_uri = uri;
}
- std::string DiagnosticsUnitInfo::getJSON()
+ std::string MaintenanceUnitInfo::getJSON()
{
std::string res;
return res;
}
- ThingsDiagnostics::ThingsDiagnostics()
+ ThingsMaintenance::ThingsMaintenance()
{
- DiagnosticsUnitInfo unit[] =
+ MaintenanceUnitInfo unit[] =
{
- { "rb", "Reboot", "/oic/diag"},
- { "ssc", "StartStatCollection", "/oic/diag"},
- { "fr", "Factory Reset", "/oic/diag" } };
+ { "rb", "Reboot", "/oic/mnt"},
+ { "ssc", "StartStatCollection", "/oic/mnt"},
+ { "fr", "Factory Reset", "/oic/mnt" } };
for (int i = 0; i < NUMDIAGUNIT; i++)
- DiagnosticsUnitTable.push_back(unit[i]);
+ MaintenanceUnitTable.push_back(unit[i]);
}
- ThingsDiagnostics::~ThingsDiagnostics()
+ ThingsMaintenance::~ThingsMaintenance()
{
}
- void ThingsDiagnostics::setGroupManager(GroupManager *groupmanager)
+ void ThingsMaintenance::setGroupManager(GroupManager *groupmanager)
{
g_groupmanager = groupmanager;
}
- ThingsDiagnostics* ThingsDiagnostics::getInstance()
+ ThingsMaintenance* ThingsMaintenance::getInstance()
{
- if (thingsDiagnosticsInstance == NULL)
+ if (thingsMaintenanceInstance == NULL)
{
- thingsDiagnosticsInstance = new ThingsDiagnostics();
+ thingsMaintenanceInstance = new ThingsMaintenance();
}
- return thingsDiagnosticsInstance;
+ return thingsMaintenanceInstance;
}
- void ThingsDiagnostics::deleteInstance()
+ void ThingsMaintenance::deleteInstance()
{
- if (thingsDiagnosticsInstance)
+ if (thingsMaintenanceInstance)
{
- delete thingsDiagnosticsInstance;
- thingsDiagnosticsInstance = NULL;
+ delete thingsMaintenanceInstance;
+ thingsMaintenanceInstance = NULL;
}
}
- std::string ThingsDiagnostics::getAttributeByDiagnosticsName(DiagnosticsName name)
+ std::string ThingsMaintenance::getAttributeByMaintenanceName(MaintenanceName name)
{
- for (auto it = DiagnosticsUnitTable.begin(); DiagnosticsUnitTable.end() != it; it++)
+ for (auto it = MaintenanceUnitTable.begin(); MaintenanceUnitTable.end() != it; it++)
{
if ((*it).m_name == name)
return (*it).m_attribute;
return "";
}
- std::string ThingsDiagnostics::getUriByDiagnosticsName(DiagnosticsName name)
+ std::string ThingsMaintenance::getUriByMaintenanceName(MaintenanceName name)
{
- for (auto it = DiagnosticsUnitTable.begin(); DiagnosticsUnitTable.end() != it; it++)
+ for (auto it = MaintenanceUnitTable.begin(); MaintenanceUnitTable.end() != it; it++)
{
if ((*it).m_name == name)
return (*it).m_uri;
return "";
}
- std::string ThingsDiagnostics::getUpdateVal(std::string diag)
+ std::string ThingsMaintenance::getUpdateVal(std::string mnt)
{
- std::map< std::string, DiagnosticsRequestEntry >::iterator it =
- diagnosticsRequestTable.find(diag);
+ std::map< std::string, MaintenanceRequestEntry >::iterator it =
+ maintenanceRequestTable.find(mnt);
- if (it == diagnosticsRequestTable.end())
+ if (it == maintenanceRequestTable.end())
return NULL;
else
return it->second.m_updateVal;
}
- std::shared_ptr< OCResource > ThingsDiagnostics::getResource(std::string diag)
+ std::shared_ptr< OCResource > ThingsMaintenance::getResource(std::string mnt)
{
- std::map< std::string, DiagnosticsRequestEntry >::iterator it =
- diagnosticsRequestTable.find(diag);
+ std::map< std::string, MaintenanceRequestEntry >::iterator it =
+ maintenanceRequestTable.find(mnt);
- if (it == diagnosticsRequestTable.end())
+ if (it == maintenanceRequestTable.end())
return NULL;
else
return it->second.m_resource;
}
- DiagnosticsCallback ThingsDiagnostics::getCallback(std::string diag)
+ MaintenanceCallback ThingsMaintenance::getCallback(std::string mnt)
{
- std::map< std::string, DiagnosticsRequestEntry >::iterator it =
- diagnosticsRequestTable.find(diag);
+ std::map< std::string, MaintenanceRequestEntry >::iterator it =
+ maintenanceRequestTable.find(mnt);
- if (it == diagnosticsRequestTable.end())
+ if (it == maintenanceRequestTable.end())
return NULL;
else
return it->second.m_callback;
}
- std::string ThingsDiagnostics::getHostFromURI(std::string oldUri)
+ std::string ThingsMaintenance::getHostFromURI(std::string oldUri)
{
size_t f;
std::string newUri;
return newUri;
}
- std::string ThingsDiagnostics::getListOfSupportedDiagnosticsUnits()
+ std::string ThingsMaintenance::getListOfSupportedMaintenanceUnits()
{
std::string res;
- res = "{\"Diagnostics Units\":[";
+ res = "{\"Maintenance Units\":[";
- auto it = DiagnosticsUnitTable.begin();
+ auto it = MaintenanceUnitTable.begin();
while (1)
{
res = res + (*it).getJSON();
it++;
- if (it == DiagnosticsUnitTable.end())
+ if (it == MaintenanceUnitTable.end())
break;
else
res += ",";
return res;
}
- void ThingsDiagnostics::onGetChildInfoForUpdate(const HeaderOptions& headerOptions,
- const OCRepresentation& rep, const int eCode, std::string diag)
+ void ThingsMaintenance::onGetChildInfoForUpdate(const HeaderOptions& headerOptions,
+ const OCRepresentation& rep, const int eCode, std::string mnt)
{
if (eCode != OC_STACK_OK)
{
std::cout << "onGet Response error: " << eCode << std::endl;
- getCallback(diag)(headerOptions, rep, eCode);
+ getCallback(mnt)(headerOptions, rep, eCode);
return ;
}
std::cout << "\t\tChild Resource URI: " << oit->getUri() << std::endl;
}
- // Get information by using diagnostics name(diag)
- std::shared_ptr < OCResource > resource = getResource(diag);
- std::string actionstring = diag;
- std::string uri = getUriByDiagnosticsName(diag);
- std::string attrKey = diag;
+ // Get information by using maintenance name(mnt)
+ std::shared_ptr < OCResource > resource = getResource(mnt);
+ std::string actionstring = mnt;
+ std::string uri = getUriByMaintenanceName(mnt);
+ std::string attrKey = mnt;
if (uri == "")
return;
// Required information consists of a host address, URI, attribute key, and
// attribute value.
ActionSet *newActionSet = new ActionSet();
- newActionSet->actionsetName = diag;
+ newActionSet->actionsetName = mnt;
for (auto oit = children.begin(); oit != children.end(); ++oit)
{
Capability *newCapability = new Capability();
newCapability->capability = attrKey;
- newCapability->status = getUpdateVal(diag);
+ newCapability->status = getUpdateVal(mnt);
newAction->listOfCapability.push_back(newCapability);
newActionSet->listOfAction.push_back(newAction);
std::function<
void(const HeaderOptions& headerOptions,
const OCRepresentation& rep, const int eCode) >(
- std::bind(&ThingsDiagnostics::onCreateActionSet, this,
+ std::bind(&ThingsMaintenance::onCreateActionSet, this,
std::placeholders::_1, std::placeholders::_2,
- std::placeholders::_3, diag)));
+ std::placeholders::_3, mnt)));
delete(newActionSet);
}
}
- void ThingsDiagnostics::onCreateActionSet(const HeaderOptions& headerOptions,
- const OCRepresentation& rep, const int eCode, std::string diag)
+ void ThingsMaintenance::onCreateActionSet(const HeaderOptions& headerOptions,
+ const OCRepresentation& rep, const int eCode, std::string mnt)
{
if (eCode != OC_STACK_OK)
{
std::cout << "onPut Response error: " << eCode << std::endl;
- getCallback(diag)(headerOptions, rep, eCode);
+ getCallback(mnt)(headerOptions, rep, eCode);
return ;
}
std::cout << "PUT request was successful" << std::endl;
- std::shared_ptr < OCResource > resource = getResource(diag);
+ std::shared_ptr < OCResource > resource = getResource(mnt);
if (resource)
{
// Now, it is time to execute the action set.
- g_groupmanager->executeActionSet(resource, diag,
+ g_groupmanager->executeActionSet(resource, mnt,
std::function<
void(const HeaderOptions& headerOptions,
const OCRepresentation& rep, const int eCode) >(
- std::bind(&ThingsDiagnostics::onExecuteForGroupAction, this,
+ std::bind(&ThingsMaintenance::onExecuteForGroupAction, this,
std::placeholders::_1, std::placeholders::_2,
- std::placeholders::_3, diag)));
+ std::placeholders::_3, mnt)));
}
}
- void ThingsDiagnostics::onExecuteForGroupAction(const HeaderOptions& headerOptions,
- const OCRepresentation& rep, const int eCode, std::string diag)
+ void ThingsMaintenance::onExecuteForGroupAction(const HeaderOptions& headerOptions,
+ const OCRepresentation& rep, const int eCode, std::string mnt)
{
if (eCode != OC_STACK_OK)
{
std::cout << "onPut Response error: " << eCode << std::endl;
- getCallback(diag)(headerOptions, rep, eCode);
+ getCallback(mnt)(headerOptions, rep, eCode);
return ;
}
std::cout << "PUT request was successful" << std::endl;
- getCallback(diag)(headerOptions, rep, eCode);
+ getCallback(mnt)(headerOptions, rep, eCode);
// Delete the created actionset
- std::shared_ptr < OCResource > resource = getResource(diag);
+ std::shared_ptr < OCResource > resource = getResource(mnt);
if (resource)
{
- g_groupmanager->deleteActionSet(resource, diag,
+ g_groupmanager->deleteActionSet(resource, mnt,
std::function<
void(const HeaderOptions& headerOptions,
const OCRepresentation& rep, const int eCode) >(
- std::bind(&ThingsDiagnostics::onDeleteGroupAction, this,
+ std::bind(&ThingsMaintenance::onDeleteGroupAction, this,
std::placeholders::_1, std::placeholders::_2,
- std::placeholders::_3, diag)));
+ std::placeholders::_3, mnt)));
}
}
- void ThingsDiagnostics::onDeleteGroupAction(const HeaderOptions& headerOptions,
- const OCRepresentation& rep, const int eCode, std::string diag)
+ void ThingsMaintenance::onDeleteGroupAction(const HeaderOptions& headerOptions,
+ const OCRepresentation& rep, const int eCode, std::string mnt)
{
if (eCode != OC_STACK_OK)
{
- std::cout << "Delete actionset returned with error: " << eCode << diag << std::endl;
+ std::cout << "Delete actionset returned with error: " << eCode << mnt << std::endl;
return;
}
- std::cout << "Deleted the actionset created!" << diag<< std::endl;
+ std::cout << "Deleted the actionset created!" << mnt<< std::endl;
}
- void ThingsDiagnostics::onPut(const HeaderOptions& headerOptions, const OCRepresentation& rep,
- const int eCode, std::string diag)
+ void ThingsMaintenance::onPut(const HeaderOptions& headerOptions, const OCRepresentation& rep,
+ const int eCode, std::string mnt)
{
if (eCode != OC_STACK_OK)
{
std::cout << "onPut Response error: " << eCode << std::endl;
- getCallback(diag)(headerOptions, rep, eCode);
+ getCallback(mnt)(headerOptions, rep, eCode);
return ;
}
std::cout << "PUT request was successful" << std::endl;
- getCallback(diag)(headerOptions, rep, eCode);
+ getCallback(mnt)(headerOptions, rep, eCode);
}
- bool ThingsDiagnostics::isSimpleResource(std::shared_ptr< OCResource > resource)
+ bool ThingsMaintenance::isSimpleResource(std::shared_ptr< OCResource > resource)
{
for (unsigned int i = 0; i < resource->getResourceTypes().size(); ++i)
{
return true;
}
- OCStackResult ThingsDiagnostics::reboot(std::shared_ptr< OCResource > resource,
- DiagnosticsCallback callback)
+ OCStackResult ThingsMaintenance::reboot(std::shared_ptr< OCResource > resource,
+ MaintenanceCallback callback)
{
if (!resource)
{
return OC_STACK_ERROR;
}
- std::string diag = "rb";
+ std::string mnt = "rb";
// Check the request queue if a previous request is still left. If so, remove it.
- std::map< std::string, DiagnosticsRequestEntry >::iterator iter =
- diagnosticsRequestTable.find(diag);
- if (iter != diagnosticsRequestTable.end())
- diagnosticsRequestTable.erase(iter);
+ std::map< std::string, MaintenanceRequestEntry >::iterator iter =
+ maintenanceRequestTable.find(mnt);
+ if (iter != maintenanceRequestTable.end())
+ maintenanceRequestTable.erase(iter);
// Create new request entry stored in the queue
- DiagnosticsRequestEntry newCallback(diag, callback, resource, "true");
- diagnosticsRequestTable.insert(std::make_pair(diag, newCallback));
+ MaintenanceRequestEntry newCallback(mnt, callback, resource, "true");
+ maintenanceRequestTable.insert(std::make_pair(mnt, newCallback));
QueryParamsMap query;
OCRepresentation rep;
{
// This resource is a simple resource. Just send a PUT message
OCRepresentation rep;
- rep.setValue < std::string > (diag, "true");
+ rep.setValue < std::string > (mnt, "true");
return resource->put(resource->getResourceTypes().at(0), DEFAULT_INTERFACE, rep, query,
std::function<
void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
const int eCode) >(
- std::bind(&ThingsDiagnostics::onPut, this, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3, diag)));
+ std::bind(&ThingsMaintenance::onPut, this, std::placeholders::_1,
+ std::placeholders::_2, std::placeholders::_3, mnt)));
}
else
{
std::function<
void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
const int eCode) >(
- std::bind(&ThingsDiagnostics::onGetChildInfoForUpdate, this,
+ std::bind(&ThingsMaintenance::onGetChildInfoForUpdate, this,
std::placeholders::_1, std::placeholders::_2,
- std::placeholders::_3, diag)));
+ std::placeholders::_3, mnt)));
}
}
- OCStackResult ThingsDiagnostics::factoryReset(std::shared_ptr< OCResource > resource,
- DiagnosticsCallback callback)
+ OCStackResult ThingsMaintenance::factoryReset(std::shared_ptr< OCResource > resource,
+ MaintenanceCallback callback)
{
if (!resource)
{
return OC_STACK_ERROR;
}
- std::string diag = "fr";
+ std::string mnt = "fr";
// Check the request queue if a previous request is still left. If so, remove it.
- std::map< std::string, DiagnosticsRequestEntry >::iterator iter =
- diagnosticsRequestTable.find(diag);
- if (iter != diagnosticsRequestTable.end())
- diagnosticsRequestTable.erase(iter);
+ std::map< std::string, MaintenanceRequestEntry >::iterator iter =
+ maintenanceRequestTable.find(mnt);
+ if (iter != maintenanceRequestTable.end())
+ maintenanceRequestTable.erase(iter);
// Create new request entry stored in the queue
- DiagnosticsRequestEntry newCallback(diag, callback, resource, "true");
- diagnosticsRequestTable.insert(std::make_pair(diag, newCallback));
+ MaintenanceRequestEntry newCallback(mnt, callback, resource, "true");
+ maintenanceRequestTable.insert(std::make_pair(mnt, newCallback));
QueryParamsMap query;
OCRepresentation rep;
std::function<
void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
const int eCode) >(
- std::bind(&ThingsDiagnostics::onPut, this, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3, diag)));
+ std::bind(&ThingsMaintenance::onPut, this, std::placeholders::_1,
+ std::placeholders::_2, std::placeholders::_3, mnt)));
}
else
{
std::function<
void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
const int eCode) >(
- std::bind(&ThingsDiagnostics::onGetChildInfoForUpdate, this,
+ std::bind(&ThingsMaintenance::onGetChildInfoForUpdate, this,
std::placeholders::_1, std::placeholders::_2,
- std::placeholders::_3, diag)));
+ std::placeholders::_3, mnt)));
}
}
}
+++ /dev/null
-//******************************************************************
-//
-// Copyright 2014 Samsung Electronics All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-/**
- * @file
- *
- */
-
-#include "ThingsManager.h"
-#include "GroupManager.h"
-#include "GroupSynchronization.h"
-#include "ThingsConfiguration.h"
-#include "ThingsDiagnostics.h"
-#include <algorithm>
-#include <thread>
-
-using namespace OC;
-namespace OIC
-{
-
- GroupManager *g_groupManager;
- GroupSynchronization *g_groupSync = NULL;
- ThingsConfiguration *g_thingsConf = NULL;
- ThingsDiagnostics *g_thingsDiag = NULL;
-
- ThingsManager::ThingsManager(void)
- {
- g_groupManager = new GroupManager();
- g_groupSync = GroupSynchronization::getInstance();
- g_thingsConf = ThingsConfiguration::getInstance();
- g_thingsDiag = ThingsDiagnostics::getInstance();
- g_thingsConf->setGroupManager(g_groupManager);
- g_thingsDiag->setGroupManager(g_groupManager);
- }
-
- /**
- * Virtual destructor
- */
- ThingsManager::~ThingsManager(void)
- {
- delete g_groupManager;
- g_groupSync->deleteInstance();
- g_thingsConf->deleteInstance();
- g_thingsDiag->deleteInstance();
- }
-
- OCStackResult ThingsManager::findCandidateResources(std::vector< std::string > resourceTypes,
- std::function< void(std::vector< std::shared_ptr< OCResource > >) > callback,
- int waitsec)
- {
- OCStackResult result = g_groupManager->findCandidateResources(resourceTypes, callback,
- waitsec);
-
- return result;
- }
-
- OCStackResult ThingsManager::subscribeCollectionPresence(std::shared_ptr< OCResource > resource,
- std::function< void(std::string, OCStackResult) > callback)
- {
- OCStackResult result = g_groupManager->subscribeCollectionPresence(resource, callback);
-
- return result;
- }
-
- OCStackResult ThingsManager::bindResourceToGroup(OCResourceHandle& childHandle, std::shared_ptr< OCResource > resource, OCResourceHandle& collectionHandle)
- {
- OCStackResult result = g_groupManager->bindResourceToGroup(childHandle,resource,collectionHandle);
-
- return result;
- }
-
- OCStackResult ThingsManager::findGroup(std::vector< std::string > collectionResourceTypes,
- FindCallback callback)
- {
- OCStackResult result = g_groupSync->findGroup(collectionResourceTypes, callback);
-
- return result;
- }
-
- OCStackResult ThingsManager::createGroup(std::string collectionResourceType)
- {
- OCStackResult result = g_groupSync->createGroup(collectionResourceType);
-
- return result;
- }
-
- OCStackResult ThingsManager::joinGroup(std::string collectionResourceType,
- OCResourceHandle resourceHandle)
- {
- OCStackResult result = g_groupSync->joinGroup(collectionResourceType, resourceHandle);
-
- return result;
- }
-
- OCStackResult ThingsManager::joinGroup(const std::shared_ptr< OCResource > resource,
- OCResourceHandle resourceHandle)
- {
- OCStackResult result = g_groupSync->joinGroup(resource, resourceHandle);
-
- return result;
- }
-
- OCStackResult ThingsManager::leaveGroup(std::string collectionResourceType,
- OCResourceHandle resourceHandle)
- {
- OCStackResult result = g_groupSync->leaveGroup(collectionResourceType, resourceHandle);
-
- return result;
- }
-
- OCStackResult ThingsManager::leaveGroup(const std::shared_ptr< OCResource > resource,
- std::string collectionResourceType,
- OCResourceHandle resourceHandle)
- {
- return g_groupSync->leaveGroup(resource, collectionResourceType, resourceHandle);
- }
-
- void ThingsManager::deleteGroup(std::string collectionResourceType)
- {
- g_groupSync->deleteGroup(collectionResourceType);
- }
-
- std::map< std::string, OCResourceHandle > ThingsManager::getGroupList()
- {
- return g_groupSync->getGroupList();
- }
-
- OCStackResult ThingsManager::updateConfigurations(std::shared_ptr< OCResource > resource,
- std::map< ConfigurationName, ConfigurationValue > configurations,
- ConfigurationCallback callback)
- {
- return g_thingsConf->updateConfigurations(resource, configurations, callback);
- }
- OCStackResult ThingsManager::getConfigurations(std::shared_ptr< OCResource > resource,
- std::vector< ConfigurationName > configurations, ConfigurationCallback callback)
- {
- return g_thingsConf->getConfigurations(resource, configurations, callback);
- }
- std::string ThingsManager::getListOfSupportedConfigurationUnits()
- {
- return g_thingsConf->getListOfSupportedConfigurationUnits();
- }
-
- OCStackResult ThingsManager::doBootstrap(ConfigurationCallback callback)
- {
- return g_thingsConf->doBootstrap(callback);
- }
-
- OCStackResult ThingsManager::reboot(std::shared_ptr< OCResource > resource,
- ConfigurationCallback callback)
- {
- return g_thingsDiag->reboot(resource, callback);
- }
- OCStackResult ThingsManager::factoryReset(std::shared_ptr< OCResource > resource,
- ConfigurationCallback callback)
- {
- return g_thingsDiag->factoryReset(resource, callback);
- }
-
- std::string ThingsManager::getStringFromActionSet(const ActionSet *newActionSet)
- {
- return g_groupManager->getStringFromActionSet(newActionSet);
- }
- ActionSet* ThingsManager::getActionSetfromString(std::string desc)
- {
- return g_groupManager->getActionSetfromString(desc);
- }
- OCStackResult ThingsManager::addActionSet(std::shared_ptr< OCResource > resource,
- const ActionSet* newActionSet, PutCallback cb)
- {
- return g_groupManager->addActionSet(resource, newActionSet, cb);
- }
- OCStackResult ThingsManager::executeActionSet(std::shared_ptr< OCResource > resource,
- std::string actionsetName, PostCallback cb)
- {
- return g_groupManager->executeActionSet(resource, actionsetName, cb);
- }
- OCStackResult ThingsManager::executeActionSet(std::shared_ptr< OCResource > resource,
- std::string actionsetName, long int delay, PostCallback cb)
- {
- return g_groupManager->executeActionSet(resource, actionsetName, delay, cb);
- }
- OCStackResult ThingsManager::cancelActionSet(std::shared_ptr< OCResource > resource,
- std::string actionsetName, PostCallback cb)
- {
- return g_groupManager->cancelActionSet(resource, actionsetName, cb);
- }
- OCStackResult ThingsManager::getActionSet(std::shared_ptr< OCResource > resource,
- std::string actionsetName, GetCallback cb)
- {
- return g_groupManager->getActionSet(resource, actionsetName, cb);
- }
- OCStackResult ThingsManager::deleteActionSet(std::shared_ptr< OCResource > resource,
- std::string actionsetName, PostCallback cb)
- {
- return g_groupManager->deleteActionSet(resource, actionsetName, cb);
- }
-}