/**
* Constructor for BundleActivator
*/
- BundleActivator() { };
+ BundleActivator()
+ {
+
+ };
/**
* Virtual destructor for BundleActivator
*/
- virtual ~BundleActivator() { };
+ virtual ~BundleActivator()
+ {
+
+ };
/**
* Activate the Bundle to make bundle work and create bundle resources
/**
* Constructor for NotificationReceiver
*/
- NotificationReceiver() {};
+ NotificationReceiver()
+ {
+
+ };
/**
* destructor for NotificationReceiver
*/
- ~NotificationReceiver() {};
+ ~NotificationReceiver()
+ {
+
+ };
/**
* Callback method for getting notification from bundle resources
/**
* Constructor for ProtocolBridgeConnector
*/
- ProtocolBridgeConnector() { };
+ ProtocolBridgeConnector()
+ {
+
+ };
/**
* Virtual destructor for ProtocolBridgeConnector
*/
- virtual ~ProtocolBridgeConnector() { };
+ virtual ~ProtocolBridgeConnector()
+ {
+
+ };
/**
* Execute the logic needed for connection with different protocol from IoTivity
/**
* Constructor for ProtocolBridgeResource
*/
- ProtocolBridgeResource() { };
+ ProtocolBridgeResource()
+ {
+
+ };
/**
* Virtual destructor for ProtocolBridgeResource
*/
- virtual ~ProtocolBridgeResource() { };
+ virtual ~ProtocolBridgeResource()
+ {
+
+ };
/**
* Initialize attributes of the resource
std::string strBMIResult;
if (m_pBMISensor->executeBMISensorLogic(&m_mapInputData, &strBMIResult) != -1)
+ {
setAttribute("BMIresult", RCSResourceAttributes::Value(strBMIResult.c_str()));
+ }
}
void BMISensorResource::onUpdatedInputResource(const std::string attributeName,
m_mapInputData.clear();
if (!attributeName.compare("weight"))
+ {
m_mapInputData.insert(std::make_pair("weight", values.back().get< std::string >()));
+ }
if (!attributeName.compare("height"))
+ {
m_mapInputData.insert(std::make_pair("height", values.back().get< std::string >()));
+ }
executeLogic();
}
EXIT = 11
} APPMenu;
- struct CloseApp {};
+ struct CloseApp
+ {
+ };
const int MAX_PATH = 2048;
char buffer[MAX_PATH];
if (!pPath->empty())
+ {
pPath->clear();
+ }
#if defined(__linux__)
char *strPath = NULL;
strPath = strrchr(buffer, '/');
if (strPath != NULL)
+ {
*strPath = '\0';
+ }
}
#endif
pPath->append(buffer);
std::cin >> input;
if (!std::cin.fail() && min <= input && input <= max)
+ {
return input;
+ }
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
for (auto &bundle : bundleList)
{
if (bundle->getID().compare(bundleId) == 0)
+ {
return true;
+ }
}
}
for (auto &resource : resourceList)
{
if (resource.compare(resourceUri) == 0)
+ {
return true;
+ }
}
}
g_bSampleBundleStarted = false;
}
else
+ {
std::cout << "Sample Bundle is not started." << std::endl;
+ }
}
else
{
if (g_pResourceContainer && g_bContainerStarted)
{
if (checkBundleRegistered(EXAMPLE_BUNDLE_ID))
+ {
g_pResourceContainer->removeBundle(EXAMPLE_BUNDLE_ID);
+ }
}
else
{
resourceParams);
}
else
+ {
std::cout << "Sample Bundle is not started." << std::endl;
+ }
}
else
{
{
if (checkResourceRegistered(EXAMPLE_BUNDLE_ID, EXAMPLE_RESOURCE_URI)
&& g_bSampleBundleStarted)
+ {
g_pResourceContainer->removeResourceConfig(EXAMPLE_BUNDLE_ID, EXAMPLE_RESOURCE_URI);
+ }
else
+ {
std::cout << "Sample Bundle is not started." << std::endl;
+ }
}
else
{
}
if (g_bContainerStarted)
+ {
g_pResourceContainer->stopContainer();
+ }
g_pResourceContainer = nullptr;
}
if (OBSERVE_TYPE_TO_USE == ObserveType::Observe)
+ {
std::cout << std::endl << "Observe is used." << std::endl << std::endl;
+ }
else if (OBSERVE_TYPE_TO_USE == ObserveType::ObserveAll)
+ {
std::cout << std::endl << "ObserveAll is used." << std::endl << std::endl;
+ }
curResource->observe(OBSERVE_TYPE_TO_USE, QueryParamsMap(), &onObserve);
res = curl_easy_perform(curl);
/* Check for errors */
if (res != CURLE_OK)
+ {
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
+ }
/* always cleanup */
curl_easy_cleanup(curl);
*/
virtual bool isActivated() = 0;
- RCSBundleInfo(){};
- virtual ~RCSBundleInfo(){};
+ RCSBundleInfo()
+ {
+ };
+ virtual ~RCSBundleInfo()
+ {
+ };
protected:
std::string m_ID, m_path, m_version;
{
std::list< std::string > ret;
- for (auto &it : m_resourceAttributes){
+ for (auto &it : m_resourceAttributes)
+ {
ret.push_back(it.key());
}
m_resourceAttributes[it.key()] = it.value();
}
- if(notify){
+ if(notify)
+ {
// asynchronous notification
auto notifyFunc = [](NotificationReceiver *notificationReceiver,
std::string uri)
{
- if (notificationReceiver){
+ if (notificationReceiver)
+ {
notificationReceiver->onNotificationReceived(uri);
}
};
std::lock_guard<std::mutex> lock(m_resourceAttributes_mutex);
m_resourceAttributes[key] = std::move(value);
- if(notify){
+ if(notify)
+ {
// asynchronous notification
auto notifyFunc = [](NotificationReceiver *notificationReceiver,
std::string uri)
{
- if (notificationReceiver){
+ if (notificationReceiver)
+ {
notificationReceiver->onNotificationReceived(uri);
}
};
{
strBundleId = bundle->first_node(BUNDLE_ID)->value();
}
- else{
+ else
+ {
strBundleId = "";
}
bundleConfigMap.insert(std::make_pair(BUNDLE_ID, trim_both(strBundleId)));
// <path>
- if (bundle->first_node(BUNDLE_PATH)){
+ if (bundle->first_node(BUNDLE_PATH))
+ {
strPath = bundle->first_node(BUNDLE_PATH)->value();
}
- else{
+ else
+ {
strPath = "";
}
bundleConfigMap.insert(std::make_pair(BUNDLE_PATH, trim_both(strPath)));
// <version>
- if (bundle->first_node(BUNDLE_VERSION)){
+ if (bundle->first_node(BUNDLE_VERSION))
+ {
strVersion = bundle->first_node(BUNDLE_VERSION)->value();
}
- else{
+ else
+ {
strVersion = "";
}
bundleConfigMap.insert(
}
void Configuration::getResourceConfiguration(std::string bundleId, std::string resourceUri,
- resourceInfo *resourceInfoOut){
+ resourceInfo *resourceInfoOut)
+ {
rapidxml::xml_node< char > *bundle;
rapidxml::xml_node< char > *resource;
rapidxml::xml_node< char > *item, *subItem, *subItem2;
OIC_LOG_V(INFO, CONTAINER_TAG, "Inspecting");
// <resourceInfo>
bundle = bundle->first_node(OUTPUT_RESOURCES_TAG);
- if (bundle){
+ if (bundle)
+ {
for (resource = bundle->first_node(OUTPUT_RESOURCE_INFO);
resource; resource = resource->next_sibling())
{
}
else if (!strKey.compare(OUTPUT_RESOURCE_ADDR))
+ {
resourceInfoOut->address = trim_both(strValue);
+ }
else if (!strKey.compare(OUTPUT_RESOURCE_TYPE))
+ {
resourceInfoOut->resourceType = trim_both(strValue);
+ }
else
{
OIC_LOG_V(ERROR, CONTAINER_TAG, "Exception (%s)", e.what());
}
}
- else{
+ else
+ {
OIC_LOG(INFO, CONTAINER_TAG, "config is not loaded yet !!");
}
}
strValue = item->value();
if (!strKey.compare(OUTPUT_RESOURCE_NAME))
+ {
tempResourceInfo.name = trim_both(strValue);
+ }
else if (!strKey.compare(OUTPUT_RESOURCE_URI))
+ {
tempResourceInfo.uri = trim_both(strValue);
+ }
else if (!strKey.compare(OUTPUT_RESOURCE_ADDR))
+ {
tempResourceInfo.address = trim_both(strValue);
+ }
else if (!strKey.compare(OUTPUT_RESOURCE_TYPE))
+ {
tempResourceInfo.resourceType = trim_both(strValue);
+ }
else
{
OIC_LOG_V(ERROR, CONTAINER_TAG, "Exception (%s)", e.what());
}
}
- else{
+ else
+ {
OIC_LOG(INFO, CONTAINER_TAG, "config is not loaded yet !!");
}
}
if (remoteObject && !isAlreadyDiscoveredResource(remoteObject))
{
OIC_LOG_V(DEBUG, DISCOVER_TAG, "Discovered - uri: %s", uri.c_str());
- if (uri.empty() || uri.compare(remoteObject->getUri()) == 0){
+ if (uri.empty() || uri.compare(remoteObject->getUri()) == 0)
+ {
RemoteResourceUnit::Ptr newDiscoveredResource =
RemoteResourceUnit::createRemoteResourceInfo(remoteObject,
pUpdatedCBFromServer);
OIC_LOG_V(DEBUG, DISCOVER_TAG, "Created remote resource unit");
}
- else{
+ else
+ {
OIC_LOG_V(DEBUG, DISCOVER_TAG, "URI is not matching - uri: %s", uri.c_str());
}
}
struct DiscoverResourceInfo
{
DiscoverResourceInfo()
- : resourceUri(), resourceType(), attributeName() {}
+ : resourceUri(), resourceType(), attributeName()
+ {
+
+ }
DiscoverResourceInfo(std::string uri, std::string type, std::string name)
- : resourceUri(uri), resourceType(type), attributeName(name) {}
+ : resourceUri(uri), resourceType(type), attributeName(name)
+ {
+
+ }
std::string resourceUri;
std::string resourceType;
std::string attributeName;
{
if(remoteObject->isCaching())
{
- try{
+ try
+ {
remoteObject->stopCaching();
}
- catch(std::exception &e){
+ catch(std::exception &e)
+ {
OIC_LOG_V(ERROR, CONTAINER_TAG, "%s", e.what());
}
}
if(remoteObject->isMonitoring())
{
- try{
+ try
+ {
remoteObject->stopMonitoring();
}
- catch(std::exception &e){
+ catch(std::exception &e)
+ {
OIC_LOG_V(ERROR, CONTAINER_TAG, "%s", e.what());
}
}
activationLock.lock();
- try{
+ try
+ {
if (!configFile.empty())
{
m_config = new Configuration(configFile);
}
OIC_LOG(INFO, CONTAINER_TAG, "Resource container started.");
- }catch(...){
+ }
+ catch (...)
+ {
OIC_LOG(INFO, CONTAINER_TAG, "Resource container failed starting.");
}
activationLock.unlock();
}
if (m_config)
+ {
delete m_config;
+ }
}
void ResourceContainerImpl::activateBundle(shared_ptr<RCSBundleInfo> bundleInfo)
std::string(m_bundles[id]->getID()).c_str());
activationLock.lock();
- try{
+ try
+ {
activateBundleThread(id);
}
- catch(...){
+ catch (...)
+ {
OIC_LOG_V(INFO, CONTAINER_TAG, "Activating bundle: (%s) failed",
std::string(m_bundles[id]->getID()).c_str());
}
registerExtBundle(bundleInfo);
#endif
}
- else if(has_suffix(bundleInfo->getPath(), ".so"))
+ else if (has_suffix(bundleInfo->getPath(), ".so"))
{
bundleInfoInternal->setSoBundle(true);
bundleInfoInternal->setJavaBundle(false);
registerSoBundle(bundleInfo);
}
// other cases might be for example .apk for android, which are loaded in the wrapper
- else{
+ else
+ {
bundleInfoInternal->setSoBundle(false);
bundleInfoInternal->setJavaBundle(false);
registerExtBundle(bundleInfo);
{
unregisterBundleSo(bundleInfo->getID());
}
- else if(bundleInfoInternal->getJavaBundle())
+ else if (bundleInfoInternal->getJavaBundle())
{
#if(JAVA_SUPPORT)
unregisterBundleJava(bundleInfo->getID());
registrationLock.lock();
if (m_mapResources.find(strUri) == m_mapResources.end())
{
- if (strInterface.empty()) {
+ if (strInterface.empty())
+ {
strInterface = "oic.if.baseline";
}
strResourceType).c_str());
discoverInputResource(strUri);
}
- else{
+ else
+ {
OIC_LOG_V(INFO, CONTAINER_TAG, "Resource has no input (%s)",
std::string(strUri + ", " +
strResourceType).c_str());
{
m_config->getResourceConfiguration(bundleId, configOutput);
}
- else{
+ else
+ {
OIC_LOG_V(DEBUG, CONTAINER_TAG, "no config present ");
}
}
if (m_bundles.find(bundleId) != m_bundles.end())
{
if (!m_bundles[bundleId]->isActivated())
+ {
activateBundle(m_bundles[bundleId]);
+ }
else
{
OIC_LOG(ERROR, CONTAINER_TAG, "Bundle already started");
if (m_bundles.find(bundleId) != m_bundles.end())
{
if (m_bundles[bundleId]->isActivated())
+ {
deactivateBundle(m_bundles[bundleId]);
+ }
else
{
OIC_LOG(ERROR, CONTAINER_TAG, "Bundle not activated");
(void) bundleUri;
if (m_bundles.find(bundleId) != m_bundles.end())
+ {
OIC_LOG(ERROR, CONTAINER_TAG, "BundleId already exist");
+ }
else
{
{
shared_ptr<BundleInfoInternal> bundleInfo = m_bundles[bundleId];
if (bundleInfo->isActivated())
+ {
deactivateBundle(bundleInfo);
+ }
if (bundleInfo->isLoaded())
+ {
unregisterBundle(bundleInfo);
+ }
}
else
{
newResourceInfo.uri = resourceUri;
if (params.find(OUTPUT_RESOURCE_NAME) != params.end())
+ {
newResourceInfo.name = params[OUTPUT_RESOURCE_NAME];
+ }
if (params.find(OUTPUT_RESOURCE_TYPE) != params.end())
+ {
newResourceInfo.resourceType = params[OUTPUT_RESOURCE_TYPE];
+ }
if (params.find(OUTPUT_RESOURCE_ADDR) != params.end())
+ {
newResourceInfo.address = params[OUTPUT_RESOURCE_ADDR];
+ }
addSoBundleResource(bundleId, newResourceInfo);
}
{
OIC_LOG_V(ERROR, CONTAINER_TAG, "Error while loading .so bundle: (%s)", error);
}
- else{
+ else
+ {
OIC_LOG_V(DEBUG, CONTAINER_TAG, "Looked up %s", ("" +
bundleInfoInternal->getActivatorName()
+ "_externalActivateBundle").c_str());
{
OIC_LOG_V(ERROR, CONTAINER_TAG, "Error while loading .so bundle: (%s)", error);
}
- else{
+ else
+ {
OIC_LOG_V(DEBUG, CONTAINER_TAG, "Looked up %s", ("" +
bundleInfoInternal->getActivatorName()
+ "_externalDeactivateBundle").c_str());
{
OIC_LOG_V(ERROR, CONTAINER_TAG, "Error while loading .so bundle: (%s)", error);
}
- else{
+ else
+ {
OIC_LOG_V(DEBUG, CONTAINER_TAG, "Looked up %s", ("" +
bundleInfoInternal->getActivatorName()
+ "_externalCreateResource").c_str());
{
OIC_LOG_V(ERROR, CONTAINER_TAG, "Error while loading .so bundle: (%s)", error);
}
- else{
+ else
+ {
OIC_LOG_V(DEBUG, CONTAINER_TAG, "Looked up %s", ("" +
bundleInfoInternal->getActivatorName()
+ "_externalDestroyResource").c_str());
OIC_LOG_V(DEBUG, CONTAINER_TAG, "Register SO bundle finished");
}
- void ResourceContainerImpl::registerExtBundle(shared_ptr<RCSBundleInfo> bundleInfo){
+ void ResourceContainerImpl::registerExtBundle(shared_ptr<RCSBundleInfo> bundleInfo)
+ {
OIC_LOG_V(INFO, CONTAINER_TAG, "Registering ext bundle (%s)",
std::string(bundleInfo->getID()).c_str());
OIC_LOG_V(INFO, CONTAINER_TAG, "Activator name (%s)",
activateJavaBundle(id);
#endif
}
- else if(m_bundles[id]->getSoBundle())
+ else if (m_bundles[id]->getSoBundle())
{
activateSoBundle (id);
}
// initialize output attributes
for (itor = m_mapResourceProperty[SS_RESOURCE_OUTPUT].begin();
itor != m_mapResourceProperty[SS_RESOURCE_OUTPUT].end(); itor++)
+ {
BundleResource::setAttribute((*itor)[SS_RESOURCE_OUTPUTNAME], nullptr);
+ }
}
}
}
strPath = strrchr(buffer, '/');
if (strPath != NULL)
+ {
*strPath = '\0';
+ }
}
#endif
pPath->append(buffer);
class TestBundleResource: public BundleResource
{
public:
- virtual void initAttributes() { }
+ virtual void initAttributes()
+ {
+ }
virtual void handleSetAttributesRequest(const RCSResourceAttributes &attr,
const std::map< std::string, std::string > &queryParams)
class TestBundleResourceWithAttrs: public BundleResource
{
public:
- virtual void initAttributes() {
+ virtual void initAttributes()
+ {
setAttribute("attrib1", RCSResourceAttributes::Value("test"));
setAttribute("attrib2", RCSResourceAttributes::Value(1));
setAttribute("attrib3", RCSResourceAttributes::Value(true));
class TestSoftSensorResource: public SoftSensorResource
{
public:
- virtual void initAttributes() {
+ virtual void initAttributes()
+ {
SoftSensorResource::initAttributes();
}
return BundleResource::getAttributes();
}
- virtual void executeLogic(){
-
+ virtual void executeLogic()
+ {
}
virtual void onUpdatedInputResource(
- std::string, std::vector<OIC::Service::RCSResourceAttributes::Value>){
-
+ std::string, std::vector<OIC::Service::RCSResourceAttributes::Value>)
+ {
}
};
{
mocks.OnCallFunc(ResourceContainerImpl::buildResourceObject).Return(
RCSResourceObject::Ptr(m_pResourceObject, [](RCSResourceObject *)
- {}));
+ {
+ }));
mocks.ExpectCall(m_pResourceObject, RCSResourceObject::setGetRequestHandler);
mocks.ExpectCall(m_pResourceObject, RCSResourceObject::setSetRequestHandler);
{
mocks.OnCallFunc(ResourceContainerImpl::buildResourceObject).Return(
RCSResourceObject::Ptr(m_pResourceObject, [](RCSResourceObject *)
- {}));
+ {
+ }));
mocks.ExpectCall(m_pResourceObject, RCSResourceObject::setGetRequestHandler);
mocks.ExpectCall(m_pResourceObject, RCSResourceObject::setSetRequestHandler);
{
mocks.OnCallFunc(ResourceContainerImpl::buildResourceObject).Return(
RCSResourceObject::Ptr(m_pResourceObject, [](RCSResourceObject *)
- {}));
+ {
+ }));
mocks.ExpectCall(m_pResourceObject, RCSResourceObject::setGetRequestHandler);
mocks.ExpectCall(m_pResourceObject, RCSResourceObject::setSetRequestHandler);
testObject->createResource();
m_bundleId = "/a/TempHumSensor/Container";
m_pDiscoverResourceUnit = std::make_shared< DiscoverResourceUnit >( m_bundleId );
- m_updatedCB = ([](const std::string, std::vector< RCSResourceAttributes::Value >) { });
+ m_updatedCB = ([](const std::string, std::vector< RCSResourceAttributes::Value >)
+ {
+ });
}
void TearDown()
namespace
{
- void onCacheCB(const RCSResourceAttributes &) { }
+ void onCacheCB(const RCSResourceAttributes &)
+ {
+ }
}
class RemoteResourceUnitTest: public TestWithMock
testObject = std::make_shared<ResourceContainerTestSimulator>();
testObject->defaultRunSimulator();
m_pRCSRemoteResourceObject = testObject->getRemoteResource();
- m_updatedCBFromServer = ([](RemoteResourceUnit::UPDATE_MSG, RCSRemoteResourceObject::Ptr) {});
+ m_updatedCBFromServer = ([](RemoteResourceUnit::UPDATE_MSG, RCSRemoteResourceObject::Ptr)
+ {
+ });
}
void TearDown()
RESOURCEINTERFACE("oic.if.baseline"),
ATTR_KEY("TestResourceContainer"),
ATTR_VALUE(0)
- { }
+ {
+ }
~ResourceContainerTestSimulator()
{
{
std::chrono::milliseconds interval(DEFAULT_WAITTIME);
if (server != nullptr)
+ {
server->setAttribute(ATTR_KEY, ATTR_VALUE + 10);
+ }
std::this_thread::sleep_for(interval);
}
{
std::chrono::milliseconds interval(DEFAULT_WAITTIME);
if (server != nullptr)
+ {
server = nullptr;
+ }
std::this_thread::sleep_for(interval);
}
class TestBundleResource : public BundleResource
{
public:
- void initAttributes() { };
+ void initAttributes()
+ {
+
+ };
RCSResourceAttributes handleGetAttributesRequest(
const std::map< std::string, std::string > &queryParams)
displayMenu();
if (selectClientMenu(processUserInput()) == QUIT_INPUT)
+ {
break;
+ }
}
}
int ret = selectServerMenu();
- if (ret == QUIT) return;
- if (ret == CORRECT_INPUT) break;
+ if (ret == QUIT)
+ {
+ return;
+ }
+ if (ret == CORRECT_INPUT)
+ {
+ break;
+ }
}
while (true)
{
displayControlMenu();
- if (selectControlMenu() == QUIT) return;
+ if (selectControlMenu() == QUIT)
+ {
+ return;
+ }
}
}
std::cin >> input;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
- if (!std::cin.fail() && min <= input && input <= max) return input;
+ if (!std::cin.fail() && min <= input && input <= max)
+ {
+ return input;
+ }
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
const auto width = (items.size() + 1) / 10 + 1;
- for(size_t i = 0; i < items.size(); ++i)
+ for (size_t i = 0; i < items.size(); ++i)
{
displayItem(width, i + 1, items[i]);
}
{
int selected = processUserInput(1, items.size() + 1) - 1;
- if(selected == static_cast<int>(items.size())) throw CloseApp();
+ if (selected == static_cast<int>(items.size()))
+ {
+ throw CloseApp();
+ }
onSelected(items[selected]);
}
std::cout << "\tattributes is empty" << std::endl;
}
- for(const auto& attr : attributes)
+ for (const auto& attr : attributes)
{
printAttribute(attr.key(), attr.value());
}
}
std::cout << "\t" << name << " : " << std::endl;
- for(const auto& item : elements)
+ for (const auto& item : elements)
{
std::cout << item << " ";
}
void printUri(const std::string& uri)
{
- if(uri.empty())
+ if (uri.empty())
{
std::cout << "\turi is empty" << std::endl;
}
const auto& children = rep.getChildren();
- if(children.empty())
+ if (children.empty())
{
std::cout << "\tchildren is empty" << std::endl;
}
else
{
int cnt = 0;
- for(const auto& child : children)
+ for (const auto& child : children)
{
std::cout << "========================================================" << std::endl;
std::cout << ++cnt << " chlid" << std::endl;
{
std::cout << "onResourceStateChanged callback" << std::endl;
- switch(resourceState)
+ switch (resourceState)
{
case ResourceState::NONE:
std::cout << "\tState changed to : NOT_MONITORING" << std::endl;
void stopCaching()
{
- if(!g_selectedResource->isCaching())
+ if (!g_selectedResource->isCaching())
{
std::cout << "\tCaching not started..." << std::endl;
return;
switch (processUserInput(RESOURCE_TEMP, RESOURCE_LIGHT))
{
case RESOURCE_TEMP:
+ {
g_attrKey = "Temperature";
return RESOURCE_TYPE_TEMP;
+ }
case RESOURCE_LIGHT:
+ {
g_attrKey = "Brightness";
return RESOURCE_TYPE_LIGHT;
}
+ }
throw std::logic_error("unreachable");
}
std::string address;
- if(std::cin.peek() != '\n') std::cin >> address;
+ if (std::cin.peek() != '\n')
+ {
+ std::cin >> address;
+ }
return address.empty() ? RCSAddress::multicast() : RCSAddress::unicast(address);
}
auto discoveryTask = RCSDiscoveryManager::getInstance()->discoverResourceByType(address,
resourceType, onResourceDiscovered);
- while(processUserInput() != 1);
+ while (processUserInput() != 1);
discoveryTask->cancel();
}
handleItems(discoveryMenuItems);
- if (g_discoveredResources.empty()) throw std::runtime_error("No resource found!");
+ if (g_discoveredResources.empty())
+ {
+ throw std::runtime_error("No resource found!");
+ }
g_currentRun = runResourceSelection;
}
if (!std::cin.fail())
{
- if(input == max + 1) throw CloseApp();
- if(min <= input && input <= max) return input;
+ if (input == max + 1)
+ {
+ throw CloseApp();
+ }
+ if (min <= input && input <= max)
+ {
+ return input;
+ }
}
std::cin.clear();
void printAttributes(const RCSResourceAttributes& attrs)
{
- for(const auto& attr : attrs)
+ for (const auto& attr : attrs)
{
std::cout << "\tkey : " << attr.key() << "\n\tvalue : "
<< attr.value().toString() << std::endl;
attrs[attrKey] = attrs[attrKey].get<int>() + diff;
}
- if(control == INCREASE)
+ if (control == INCREASE)
{
std::cout << attrKey << " increased." << std::endl;
}
{
g_currentRun = runPresenceSelection;
- while(true)
+ while (true)
{
try
{
g_currentRun();
}
- catch(const std::exception& e)
+ catch (const std::exception& e)
{
std::cout << e.what() << std::endl;
}
- catch(const CloseApp&)
+ catch (const CloseApp&)
{
break;
}
g_resource.reset();
- if(g_isPresenceStarted)
+ if (g_isPresenceStarted)
{
stopPresence();
}
auto& resAttrs = resObject->getAttributes();
for (const auto& kv : requestedAttrs)
{
- if (resAttrs.contains(kv.key())) resAttrs[kv.key()] = kv.value();
+ if (resAttrs.contains(kv.key()))
+ {
+ resAttrs[kv.key()] = kv.value();
+ }
}
}
if (!std::cin.fail())
{
- if(min <= input && input <= max) return input;
+ if(min <= input && input <= max)
+ {
+ return input;
+ }
}
std::cin.clear();
class FunctionObject
{
public:
- virtual ~FunctionObject() { }
+ virtual ~FunctionObject()
+ {
+
+ }
- virtual void execute(ExpiryTimerImpl::Id) { }
+ virtual void execute(ExpiryTimerImpl::Id)
+ {
+
+ }
};
class ExpiryTimerImplTest: public TestWithMock
TEST_F(ExpiryTimerImplTest, PostThrowsIfDelayIsNegative)
{
- ASSERT_THROW(ExpiryTimerImpl::getInstance()->post(-1, [](ExpiryTimerImpl::Id){}), RCSException);
+ ASSERT_THROW(ExpiryTimerImpl::getInstance()->post(-1,
+ [](ExpiryTimerImpl::Id)
+ {
+ }), RCSException);
}
TEST_F(ExpiryTimerImplTest, PostThrowsIfCallbackIsEmpty)
FunctionObject* functor = mocks.Mock< FunctionObject >();
mocks.ExpectCall(functor, FunctionObject::execute).Do(
- [this](ExpiryTimerImpl::Id){
+ [this](ExpiryTimerImpl::Id)
+ {
Proceed();
}
);
FunctionObject* functor = mocks.Mock< FunctionObject >();
mocks.ExpectCall(functor, FunctionObject::execute).Match(
- [this, &returnedId](ExpiryTimerImpl::Id id){
+ [this, &returnedId](ExpiryTimerImpl::Id id)
+ {
return returnedId == id;
}
).Do(
- [this](ExpiryTimerImpl::Id){
+ [this](ExpiryTimerImpl::Id)
+ {
Proceed();
}
);
FunctionObject* functor = mocks.Mock< FunctionObject >();
mocks.ExpectCall(functor, FunctionObject::execute).Do(
- [this](ExpiryTimerImpl::Id){
+ [this](ExpiryTimerImpl::Id)
+ {
Proceed();
}
);
TEST_F(ExpiryTimerTest, PostThrowsIfDelayIsNegative)
{
- ASSERT_THROW(timer.post(-1, [](ExpiryTimer::Id){}), RCSException);
+ ASSERT_THROW(timer.post(-1,
+ [](ExpiryTimer::Id)
+ {
+ }), RCSException);
}
TEST_F(ExpiryTimerTest, PostThrowsIfCallbackIsEmpty)
FunctionObject* functor = mocks.Mock< FunctionObject >();
mocks.ExpectCall(functor, FunctionObject::execute).Do(
- [this](ExpiryTimer::Id){
+ [this](ExpiryTimer::Id)
+ {
Proceed();
}
);
FunctionObject* functor = mocks.Mock< FunctionObject >();
mocks.ExpectCall(functor, FunctionObject::execute).Match(
- [this, &returnedId](ExpiryTimer::Id id){
+ [this, &returnedId](ExpiryTimer::Id id)
+ {
return returnedId == id;
}
).Do(
- [this](ExpiryTimer::Id){
+ [this](ExpiryTimer::Id)
+ {
Proceed();
}
);
FunctionObject* functor = mocks.Mock< FunctionObject >();
mocks.ExpectCall(functor, FunctionObject::execute).Do(
- [this](ExpiryTimer::Id){
+ [this](ExpiryTimer::Id)
+ {
Proceed();
}
);
class PresenceSubscriberTest: public TestWithMock
{
protected:
- void SetUp() {
+ void SetUp()
+ {
mocks.OnCallFuncOverload(
static_cast< SubscribePresence1 >(OC::OCPlatform::subscribePresence)).Do(
int count = 0;
- for (auto& i : resourceAttributes) {
+ for (auto& i : resourceAttributes)
+ {
i.key();
++count;
}
const char arbitraryStr[] { "ftryb457" };
resourceAttributes[KEY] = 1;
- for (auto& i : resourceAttributes) {
+ for (auto& i : resourceAttributes)
+ {
i.value() = arbitraryStr;
}
TestWithMock::SetUp();
instance = DeviceAssociation::getInstance();
device = (DevicePresencePtr)new DevicePresence();
- pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), [](PrimitiveResource*){});
+ pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(),
+ [](PrimitiveResource*)
+ {
+ });
}
void TearDown()
{
TestWithMock::SetUp();
instance = (DevicePresence*)new DevicePresence();
- pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), [](PrimitiveResource*){});
- cb = ([](BROKER_STATE)->OCStackResult{return OC_STACK_OK;});
+ pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(),
+ [](PrimitiveResource*)
+ {
+
+ });
+ cb = ([](BROKER_STATE)->OCStackResult
+ {
+ return OC_STACK_OK;
+ });
id = 0;
}
mocks.OnCall(pResource.get(), PrimitiveResource::getHost).Return(std::string());
mocks.OnCallFuncOverload(static_cast< subscribePresenceSig1 >(OC::OCPlatform::subscribePresence)).Do(
[](OC::OCPlatform::OCPresenceHandle&,
- const std::string&, OCConnectivityType, SubscribeCallback callback)->OCStackResult{
+ const std::string&, OCConnectivityType, SubscribeCallback callback)->OCStackResult
+ {
callback(OC_STACK_OK,0,std::string());
return OC_STACK_OK;
{
TestWithMock::SetUp();
brokerInstance = ResourceBroker::getInstance();
- pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), [](PrimitiveResource*){});
- cb = ([](BROKER_STATE)->OCStackResult{return OC_STACK_OK;});
+ pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(),
+ [](PrimitiveResource*)
+ {
+
+ });
+ cb = ([](BROKER_STATE)->OCStackResult
+ {
+ return OC_STACK_OK;
+ });
id = 0;
}
for(int i=0;i!=3;i++)
{
- resource[i] = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), [](PrimitiveResource*){});
+ resource[i] = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(),
+ [](PrimitiveResource*)
+ {
+ });
mocks.OnCall(resource[i].get(), PrimitiveResource::requestGet);
mocks.OnCall(resource[i].get(), PrimitiveResource::getHost).Return(std::string());
mocks.OnCallFuncOverload(static_cast< subscribePresenceSig1 >(OC::OCPlatform::subscribePresence)).Return(OC_STACK_OK);
{
TestWithMock::SetUp();
instance.reset(new ResourcePresence());
- pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), [](PrimitiveResource*){});
- cb = ([](BROKER_STATE)->OCStackResult{return OC_STACK_OK;});
+ pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(),
+ [](PrimitiveResource*)
+ {
+
+ });
+ cb = ([](BROKER_STATE)->OCStackResult
+ {
+ return OC_STACK_OK;
+ });
id = 0;
}
void MockingFunc()
{
- mocks.OnCall(pResource.get(), PrimitiveResource::requestGet).Do([](GetCallback){});
+ mocks.OnCall(pResource.get(), PrimitiveResource::requestGet).Do(
+ [](GetCallback)
+ {
+
+ });
mocks.OnCall(pResource.get(), PrimitiveResource::getHost).Return(std::string());
mocks.OnCallFuncOverload(static_cast< subscribePresenceSig1 >(OC::OCPlatform::subscribePresence)).Return(OC_STACK_OK);
}
{
mocks.ExpectCall(pResource.get(), PrimitiveResource::requestGet).Do(
- [](GetCallback callback){
-
- OIC::Service::HeaderOptions op;
- RCSResourceAttributes attr;
- OIC::Service::ResponseStatement res(attr);
+ [](GetCallback callback)
+ {
+ OIC::Service::HeaderOptions op;
+ RCSResourceAttributes attr;
+ OIC::Service::ResponseStatement res(attr);
- callback(op,res,OC_STACK_OK);
+ callback(op,res,OC_STACK_OK);
- });
+ });
mocks.OnCall(pResource.get(), PrimitiveResource::requestGet).Do(
- [](GetCallback){
- std::cout <<"End call requestGetFunc()\n";
- });
+ [](GetCallback)
+ {
+ std::cout <<"End call requestGetFunc()\n";
+ });
mocks.OnCall(pResource.get(), PrimitiveResource::getHost).Return("address1");
mocks.OnCallFuncOverload(static_cast< subscribePresenceSig1 >(OC::OCPlatform::subscribePresence)).Do(
[](OC::OCPlatform::OCPresenceHandle&,
- const std::string&, OCConnectivityType, SubscribeCallback callback)->OCStackResult{
-
- callback(OC_STACK_OK,0,std::string());
- return OC_STACK_OK;
+ const std::string&, OCConnectivityType, SubscribeCallback callback)->OCStackResult
+ {
+ callback(OC_STACK_OK,0,std::string());
+ return OC_STACK_OK;
- }).Return(OC_STACK_OK);
+ }
+ ).Return(OC_STACK_OK);
instance->initializeResourcePresence(pResource);
sleep(3);
virtual void SetUp()
{
TestWithMock::SetUp();
- pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), [](PrimitiveResource *) {});
+ pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(),
+ [](PrimitiveResource *)
+ {
+
+ });
mocks.OnCall(pResource.get(), PrimitiveResource::isObservable).Return(false);
cacheHandler.reset(new DataCache());
- cb = ([](std::shared_ptr<PrimitiveResource >, const RCSResourceAttributes &)->OCStackResult {return OC_STACK_OK;});
+ cb = ([](std::shared_ptr<PrimitiveResource >, const RCSResourceAttributes &)->OCStackResult
+ {
+ return OC_STACK_OK;
+ });
}
virtual void TearDown()
{
TestWithMock::SetUp();
cacheInstance = ResourceCacheManager::getInstance();
- pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), [](PrimitiveResource *) {});
+ pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(),
+ [](PrimitiveResource *)
+ {
+
+ });
mocks.OnCall(pResource.get(), PrimitiveResource::isObservable).Return(false);
- cb = ([](std::shared_ptr<PrimitiveResource >, const RCSResourceAttributes &)->OCStackResult {return OC_STACK_OK;});
+ cb = ([](std::shared_ptr<PrimitiveResource >, const RCSResourceAttributes &)->OCStackResult
+ {
+ return OC_STACK_OK;
+ });
}
virtual void TearDown()
constexpr char RESOURCE_TYPE[]{ "resource.type" };
constexpr char SECOND_RESOURCETYPE[]{ "resource.type.second" };
-void onResourceDiscovered(RCSRemoteResourceObject::Ptr) {}
+void onResourceDiscovered(RCSRemoteResourceObject::Ptr)
+{
+
+}
class ScopedTask
{
~ScopedTask()
{
- if (m_task) m_task->cancel();
+ if (m_task)
+ {
+ m_task->cancel();
+ }
}
RCSDiscoveryManager::DiscoveryTask* operator->()
ASSERT_TRUE(aTaskToBeCanceled->isCanceled());
}
-TEST(DiscoveryManagerTest, CallbackWouldNotBeCalledForSameRemoteResource) {
+TEST(DiscoveryManagerTest, CallbackWouldNotBeCalledForSameRemoteResource)
+{
FindCallback callback;
MockRepository mocks;
QueryParamsMap test;
if (OC_STACK_OK != resource->observe(ObserveType::Observe , test , &onObserve))
+ {
std::cout << "To Fail resource observe() process" << std::endl;
+ }
}
void startGet(std::shared_ptr< OCResource > resource)
QueryParamsMap test;
std::cout << "URI :" << resource->uri() << std::endl;
if (OC_STACK_OK != resource->get(test, &onGet))
+ {
std::cout << "To Fail resource get() process" << std::endl;
+ }
}
void startPost(std::shared_ptr< OCResource > resource)
QueryParamsMap test;
if (OC_STACK_OK != resource->post(rep, test, &onPost))
+ {
std::cout << "To Fail resource post() process" << std::endl;
+ }
}
void startDelete(std::shared_ptr< OCResource > resource)
g_curResource = resource;
if (OC_STACK_OK != resource->deleteResource(&onDelete))
+ {
std::cout << "To Fail resource delete() process" << std::endl;
+ }
}
int observe_count()
continue;
}
- try {
+ try
+ {
switch ((int)in)
{
case OBSERVE:
std::cout << "Invalid input, please try again" << std::endl;
break;
}
- }catch(OCException & e) {
+ }
+ catch(OCException & e)
+ {
std::cout<< "Caught OCException [Code: "<<e.code()<<" Reason: "<<e.reason()<<std::endl;
}
}
void HostingObject::destroyHostingObject()
{
- if (pDestroyCB) pDestroyCB();
+ if (pDestroyCB)
+ {
+ pDestroyCB();
+ }
}
void HostingObject::stateChangedCB(ResourceState state)
break;
}
default:
+ {
// not support of state
break;
}
+ }
}
void HostingObject::dataChangedCB(const RCSResourceAttributes & attributes)
std::bind(&HostingObject::setRequestHandler, this,
std::placeholders::_1, std::placeholders::_2));
return retResource;
- } catch (...)
+ }
+ catch (...)
{
OIC_HOSTING_LOG(DEBUG, "[HostingObject::createMirroredServer] %s", "Exception");
throw;
RequestObject::invokeRequest(getRemoteResource(),
primitiveRequest, RequestObject::RequestMethod::Set, resourceAttibutes);
- } catch (const RCSPlatformException & e)
+ }
+ catch (const RCSPlatformException & e)
{
OIC_HOSTING_LOG(DEBUG,
"[HostingObject::setRequestHandler] PlatformException:%s",
case RequestMethod::Get:
case RequestMethod::Delete:
default:
+ {
// unknown type of method.
break;
}
+ }
}
void RequestObject::setRequestCB(
const RCSRequest & request, RequestObject::Ptr /*this_ptr*/)
{
auto server = request.getResourceObject().lock();
- if (!server) return;
+ if (!server)
+ {
+ return;
+ }
RCSResourceObject::LockGuard guard(server);
server->getAttributes() = RCSResourceAttributes(returnedAttributes);
void ResourceHosting::startHosting()
{
- if (m_isStartedHosting) return;
+ if (m_isStartedHosting)
+ {
+ return;
+ }
m_isStartedHosting = true;
createDiscoveryListener();
}
void ResourceHosting::stopHosting()
{
- if (!m_isStartedHosting) return;
+ if (!m_isStartedHosting)
+ {
+ return;
+ }
if (!m_discoveryTask->isCanceled())
{
}
auto foundHostingObject = findRemoteResource(remoteResource);
- if (foundHostingObject != nullptr) return;
+ if (foundHostingObject != nullptr)
+ {
+ return;
+ }
try
{
RHLock lock(m_mutexForList);
m_hostingObjects.insert(std::make_pair(key, foundHostingObject));
- } catch (const RCSException & e)
+ }
+ catch (const RCSException & e)
{
OIC_HOSTING_LOG(DEBUG,
"[ResourceHosting::discoverHandler]InvalidParameterException:%s", e.what());
RHLock lock(m_mutexForList);
auto iter = m_hostingObjects.find(generateHostingObjectKey(remoteResource));
- if (iter != m_hostingObjects.end()) return iter->second;
+ if (iter != m_hostingObjects.end())
+ {
+ return iter->second;
+ }
return nullptr;
}
m_configurationRep.setResourceTypes(m_configurationTypes);
}
-FactorySetResource::~FactorySetResource(){}
+FactorySetResource::~FactorySetResource()
+{
+}
/// This function internally calls registerResource API.
void FactorySetResource::createResources(ResourceEntityHandler callback)
std::cout << "\tResource URI: " << rep.getUri() << std::endl;
if (rep.hasAttribute("n"))
+ {
std::cout << "\t\tDeviceName:" << rep.getValue< std::string >("n") << std::endl;
+ }
if (rep.hasAttribute("loc"))
+ {
std::cout << "\t\tLocation:" << rep.getValue< std::string >("loc") << std::endl;
+ }
if (rep.hasAttribute("locn"))
+ {
std::cout << "\t\tLocationName:" << rep.getValue< std::string >("locn") << std::endl;
+ }
if (rep.hasAttribute("c"))
+ {
std::cout << "\t\tCurrency:" << rep.getValue< std::string >("c") << std::endl;
+ }
if (rep.hasAttribute("r"))
+ {
std::cout << "\t\tRegion:" << rep.getValue< std::string >("r") << std::endl;
+ }
}
void onGet(const HeaderOptions& /*headerOptions*/, const OCRepresentation& rep, const int eCode)
std::cout << "\tResource URI: " << rep.getUri() << std::endl;
if (rep.hasAttribute("n"))
+ {
std::cout << "\t\tDeviceName:" << rep.getValue< std::string >("n") << std::endl;
+ }
if (rep.hasAttribute("loc"))
+ {
std::cout << "\t\tLocation:" << rep.getValue< std::string >("loc") << std::endl;
+ }
if (rep.hasAttribute("locn"))
+ {
std::cout << "\t\tLocationName:" << rep.getValue< std::string >("locn") << std::endl;
+ }
if (rep.hasAttribute("c"))
+ {
std::cout << "\t\tCurrency:" << rep.getValue< std::string >("c") << std::endl;
+ }
if (rep.hasAttribute("r"))
+ {
std::cout << "\t\tRegion:" << rep.getValue< std::string >("r") << std::endl;
+ }
}
// Callback to found collection resource
if (resource)
{
if (resource->uri() == "/core/a/configuration/resourceset")
+ {
g_configurationCollection = resource;
+ }
else if (resource->uri() == "/core/a/maintenance/resourceset")
+ {
g_maintenanceCollection = resource;
+ }
else if (resource->uri() == "/core/a/factoryset/resourceset")
+ {
g_setCollection = resource;
+ }
else
{
pthread_mutex_lock(&mutex_lock);
OCPlatform::bindResource(configurationCollectionHandle,
foundResourceHandle);
if (g_configurationResource == NULL)
+ {
g_configurationResource = resource;
+ }
}
else if (resource->uri() == "/oic/mnt")
{
OCPlatform::bindResource(maintenanceCollectionHandle,
foundResourceHandle);
if (g_maintenanceResource == NULL)
+ {
g_maintenanceResource = resource;
+ }
}
else if (resource->uri() == "/factoryset")
{
OCPlatform::bindResource(setCollectionHandle, foundResourceHandle);
if (g_setResource == NULL)
+ {
g_setResource = resource;
+ }
}
resourceHandleVector.push_back(foundResourceHandle);
}
}
- }catch (OCException e)
+ }
+ catch (OCException e)
{
std::cout << "Exception in main: " << e.what();
}
void Time::setDayOfWeekForRecursive(int day)
{
if (day != -1)
+ {
type = RECURSIVE;
+ }
else
+ {
return;
+ }
setTime(0, 0, 0, 0, 0, 0, day);
}
}
long int Time::getSecondsFromAbsoluteTime()
{
- if(mTime.tm_year > 1900)
+ if (mTime.tm_year > 1900)
+ {
mTime.tm_year -= 1900;
+ }
mTime.tm_mon -= 1;
}
long int Time::getSecondsForWeeklySchedule()
{
- if(mTime.tm_year > 1900)
+ if (mTime.tm_year > 1900)
+ {
mTime.tm_year -= 1900;
+ }
mTime.tm_mon -= 1;
return getRelativeIntervalOfWeek(&mTime);
void Time::setDelay(long int seconds)
{
- if(type != NONE)
+ if (type != NONE)
{
mDelay = seconds;
}
}
return result;
- }
+}
std::bind(&GroupManager::collectionPresenceHandler, this,
std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3, hostAddress, oit->getUri())));
- }catch(OCException& e)
+ }
+ catch(OCException& e)
{
std::cout<< "Exception in subscribePresence: "<< e.what() << std::endl;
}
std::string message = "";
if(newActionSet == NULL)
+ {
return message;
+ }
message = newActionSet->actionsetName;
message.append("*");
message.append((*iterCapa)->status);
if (iterCapa + 1 != (*iterAction)->listOfCapability.end())
+ {
message.append("|");
+ }
}
if (iterAction + 1 != newActionSet->listOfAction.end())
return message;
}
-#define DELETE(p) { \
+#define DELETE(p) \
+{ \
delete p; \
p = NULL; \
}
-#define DELETEARRAY(p) { \
+#define DELETEARRAY(p) \
+{ \
delete[] p; \
p = NULL; \
}
actionset->actionsetName = std::string(token);
if((actionset->actionsetName).empty())
+ {
goto exit;
+ }
// Find the second token
token = strtok_r(NULL, ACTION_DELIMITER, &plainPtr);
token = strtok_r(NULL, ATTR_DELIMITER, &attrPtr);
if( token == NULL )
+ {
goto exit;
+ }
capa->status = std::string(token);
if (action != NULL)
+ {
action->listOfCapability.push_back(capa);
+ }
else
+ {
goto exit;
+ }
}
token = strtok_r(NULL, ATTR_DELIMITER, &attrPtr);
action = NULL;
}
else
+ {
goto exit;
+ }
//delete action;
}
else
{ "c","Currency", "/oic/con" } };
for (int i = 0; i < NUMCONFUNIT; i++)
+ {
ConfigurationUnitTable.push_back(unit[i]);
+ }
}
- ThingsConfiguration::~ThingsConfiguration(void){}
+ ThingsConfiguration::~ThingsConfiguration(void)
+ {
+ }
void ThingsConfiguration::setGroupManager(GroupManager *groupmanager)
{
for (auto it = ConfigurationUnitTable.begin(); ConfigurationUnitTable.end() != it; it++)
{
if ((*it).m_name == name)
+ {
return (*it).m_attribute;
+ }
}
return "";
for (auto it = ConfigurationUnitTable.begin(); ConfigurationUnitTable.end() != it; it++)
{
if ((*it).m_name == name)
+ {
return (*it).m_uri;
+ }
}
return "";
configurationRequestTable.find(conf);
if (it == configurationRequestTable.end())
+ {
return NULL;
+ }
else
+ {
return it->second.m_updateVal;
+ }
}
std::shared_ptr< OCResource > ThingsConfiguration::getResource(std::string conf)
configurationRequestTable.find(conf);
if (it == configurationRequestTable.end())
+ {
return NULL;
+ }
else
+ {
return it->second.m_resource;
+ }
}
ConfigurationCallback ThingsConfiguration::getCallback(std::string conf)
configurationRequestTable.find(conf);
if (it == configurationRequestTable.end())
+ {
return NULL;
+ }
else
+ {
return it->second.m_callback;
+ }
}
std::string ThingsConfiguration::getListOfSupportedConfigurationUnits()
it++;
if (it == ConfigurationUnitTable.end())
+ {
break;
+ }
else
+ {
res += ",";
+ }
}
res += "]}";
std::string newUri;
if ((f = oldUri.find("/factoryset/oic/")) != string::npos)
+ {
newUri = oldUri.replace(f, oldUri.size(), "");
+ }
else if ((f = oldUri.find("/oic/")) != string::npos)
+ {
newUri = oldUri.replace(f, oldUri.size(), "");
+ }
return newUri;
}
std::string attrKey = conf;
if (uri == "")
+ {
return;
+ }
if (resource)
{
std::string uri = getUriByConfigurationName(conf);
if (uri == "")
+ {
return;
+ }
if (uri == "/factoryset" || uri == "/factoryset/oic/con")
+ {
m_if.push_back(BATCH_INTERFACE);
+ }
else
+ {
m_if.push_back(DEFAULT_INTERFACE);
+ }
std::vector < OCRepresentation > children = rep.getChildren();
for (auto oit = children.begin(); oit != children.end(); ++oit)
oit->getResourceTypes(), m_if);
p_resources.push_back(tempResource);
- } catch (std::exception& e)
+ }
+ catch (std::exception& e)
{
std::cout << "Exception: " << e.what() << std::endl;
}
for (unsigned int i = 0; i < resource->getResourceTypes().size(); ++i)
{
if (resource->getResourceTypes().at(i).find(".resourceset", 0) != std::string::npos)
+ {
return false;
+ }
}
return true;
for (unsigned int i = 0; i < resource->getResourceInterfaces().size(); ++i)
{
if (resource->getResourceInterfaces().at(i) == BATCH_INTERFACE)
+ {
return true;
+ }
}
return false;
std::map< std::string, ConfigurationRequestEntry >::iterator iter =
configurationRequestTable.find(conf);
if (iter != configurationRequestTable.end())
+ {
configurationRequestTable.erase(iter);
+ }
// Create new request entry stored in the queue
ConfigurationRequestEntry newCallback(conf, callback, resource, it->second);
std::map< std::string, ConfigurationRequestEntry >::iterator iter =
configurationRequestTable.find(conf);
if (iter != configurationRequestTable.end())
+ {
configurationRequestTable.erase(iter);
+ }
// Create new request entry stored in the queue
ConfigurationRequestEntry newCallback(conf, callback, resource, conf);
std::string m_if = DEFAULT_INTERFACE;
if (hasBatchInterface(resource))
+ {
m_if = BATCH_INTERFACE;
+ }
return resource->get(resource->getResourceTypes().at(0), m_if, query,
std::function<
OCStackResult ThingsConfiguration::doBootstrap(ConfigurationCallback callback)
{
if(callback == NULL)
+ {
return OC_STACK_ERROR;
+ }
else
+ {
g_bootstrapCallback = callback;
+ }
// Find bootstrap server.
std::vector < std::string > type;
{ "fr", "Factory Reset", "/oic/mnt" } };
for (int i = 0; i < NUMDIAGUNIT; i++)
+ {
MaintenanceUnitTable.push_back(unit[i]);
+ }
}
ThingsMaintenance::~ThingsMaintenance()
for (auto it = MaintenanceUnitTable.begin(); MaintenanceUnitTable.end() != it; it++)
{
if ((*it).m_name == name)
+ {
return (*it).m_attribute;
+ }
}
return "";
for (auto it = MaintenanceUnitTable.begin(); MaintenanceUnitTable.end() != it; it++)
{
if ((*it).m_name == name)
+ {
return (*it).m_uri;
+ }
}
return "";
maintenanceRequestTable.find(mnt);
if (it == maintenanceRequestTable.end())
+ {
return NULL;
+ }
else
+ {
return it->second.m_updateVal;
+ }
}
std::shared_ptr< OCResource > ThingsMaintenance::getResource(std::string mnt)
maintenanceRequestTable.find(mnt);
if (it == maintenanceRequestTable.end())
+ {
return NULL;
+ }
else
+ {
return it->second.m_resource;
+ }
}
MaintenanceCallback ThingsMaintenance::getCallback(std::string mnt)
maintenanceRequestTable.find(mnt);
if (it == maintenanceRequestTable.end())
+ {
return NULL;
+ }
else
+ {
return it->second.m_callback;
+ }
}
std::string ThingsMaintenance::getHostFromURI(std::string oldUri)
std::string newUri;
if ((f = oldUri.find("/factoryset/oic/")) != string::npos)
+ {
newUri = oldUri.replace(f, oldUri.size(), "");
+ }
else if ((f = oldUri.find("/oic/")) != string::npos)
+ {
newUri = oldUri.replace(f, oldUri.size(), "");
+ }
return newUri;
}
it++;
if (it == MaintenanceUnitTable.end())
+ {
break;
+ }
else
+ {
res += ",";
+ }
}
res += "]}";
std::string attrKey = mnt;
if (uri == "")
+ {
return;
+ }
if (resource)
{
for (unsigned int i = 0; i < resource->getResourceTypes().size(); ++i)
{
if (resource->getResourceTypes().at(0).find(".resourceset", 0) != std::string::npos)
+ {
return false;
+ }
}
return true;
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
MaintenanceRequestEntry newCallback(mnt, callback, resource, "true");
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
MaintenanceRequestEntry newCallback(mnt, callback, resource, "true");
mocks.ExpectCallFunc(onPut).
Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
- const int /*eCode*/) { Proceed();});
+ const int /*eCode*/)
+ {
+ Proceed();
+ });
for (auto iter = lights.begin(); iter != lights.end(); ++iter)
{
mocks.ExpectCallFunc(onPut).
Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
- const int /*eCode*/) { Proceed();});
+ const int /*eCode*/)
+ {
+ Proceed();
+ });
for (auto iter = lights.begin(); iter != lights.end(); ++iter)
{
mocks.ExpectCallFunc(onPost).
Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
- const int /*eCode*/) { Proceed();});
+ const int /*eCode*/)
+ {
+ Proceed();
+ });
if (g_resource)
{
{
mocks.ExpectCallFunc(onPost).
Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
- const int /*eCode*/) { Proceed();});
+ const int /*eCode*/)
+ {
+ Proceed();
+ });
if (g_resource)
{
mocks.ExpectCallFunc(onPut).
Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
- const int /*eCode*/) { Proceed();});
+ const int /*eCode*/)
+ {
+ Proceed();
+ });
for (auto iter = lights.begin(); iter != lights.end(); ++iter)
{
mocks.ExpectCallFunc(onPost).
Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
- const int /*eCode*/) { Proceed();});
+ const int /*eCode*/)
+ {
+ Proceed();
+ });
if (g_resource)
{
mocks.ExpectCallFunc(onPut).
Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
- const int /*eCode*/) { Proceed();});
+ const int /*eCode*/)
+ {
+ Proceed();
+ });
for (auto iter = lights.begin(); iter != lights.end(); ++iter)
{
mocks.ExpectCallFunc(onPut).
Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
- const int /*eCode*/) { Proceed();});
+ const int /*eCode*/)
+ {
+ Proceed();
+ });
for (auto iter = lights.begin(); iter != lights.end(); ++iter)
{
mocks.ExpectCallFunc(onPut).
Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
- const int /*eCode*/) { Proceed();});
+ const int /*eCode*/)
+ {
+ Proceed();
+ });
for (auto iter = lights.begin(); iter != lights.end(); ++iter)
{
{
mocks.ExpectCallFunc(onPost).
Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
- const int /*eCode*/) { Proceed();});
+ const int /*eCode*/)
+ {
+ Proceed();
+ });
if (g_resource)
{
{
mocks.ExpectCallFunc(onPut).
Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
- const int /*eCode*/) { Proceed();});
+ const int /*eCode*/)
+ {
+ Proceed();
+ });
if (g_resource)
{
{
mocks.ExpectCallFunc(onPost).
Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
- const int /*eCode*/) { Proceed();});
+ const int /*eCode*/)
+ {
+ Proceed();
+ });
if (g_resource)
{
mocks.ExpectCallFunc(onGet).
Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
- const int /*eCode*/) { Proceed();});
+ const int /*eCode*/)
+ {
+ Proceed();
+ });
vector<string> types;
types.push_back("oic.wk.con");
mocks.ExpectCallFunc(onGetBootstrapInformation).
Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
- const int /*eCode*/) { Proceed();});
+ const int /*eCode*/)
+ {
+ Proceed();
+ });
result = g_thingsConf->doBootstrap(&onGetBootstrapInformation);
Wait();
EXPECT_TRUE(result == OC_STACK_OK);
mocks.ExpectCallFunc(onUpdate).
Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
- const int /*eCode*/) { Proceed();});
+ const int /*eCode*/)
+ {
+ Proceed();
+ });
vector<string> types;
types.push_back("oic.wk.con");
mocks.ExpectCallFunc(onReboot).
Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
- const int /*eCode*/) { Proceed();});
+ const int /*eCode*/)
+ {
+ Proceed();
+ });
vector<string> types;
types.push_back("oic.wk.mnt");
mocks.ExpectCallFunc(onFactoryReset).
Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
- const int /*eCode*/) { Proceed();});
+ const int /*eCode*/)
+ {
+ Proceed();
+ });
vector<string> types;
types.push_back("oic.wk.mnt");