From a869334775a91cdb5f988b6ae6f0f96d603a957c Mon Sep 17 00:00:00 2001 From: Jihun Ha Date: Mon, 29 Feb 2016 17:25:53 +0900 Subject: [PATCH] Remove a sample application for group-manager APIs for the existing group manager are going to be deprecated and a functionality to control multiple resources is replaced with one of scene manager. Due to this, a sample application for the group manager should be removed. Change-Id: I3882ab6c2e699d1872154cef5dd25dea73cef89c Signed-off-by: Jihun Ha Reviewed-on: https://gerrit.iotivity.org/gerrit/5263 Tested-by: jenkins-iotivity Reviewed-by: Habib Virji --- service/things-manager/sampleapp/SConscript | 1 - .../sampleapp/linux/groupaction/SConscript | 64 --- .../sampleapp/linux/groupaction/bookmark.cpp | 229 -------- .../sampleapp/linux/groupaction/groupserver.cpp | 596 --------------------- .../sampleapp/linux/groupaction/lightserver.cpp | 331 ------------ 5 files changed, 1221 deletions(-) delete mode 100644 service/things-manager/sampleapp/linux/groupaction/SConscript delete mode 100755 service/things-manager/sampleapp/linux/groupaction/bookmark.cpp delete mode 100755 service/things-manager/sampleapp/linux/groupaction/groupserver.cpp delete mode 100755 service/things-manager/sampleapp/linux/groupaction/lightserver.cpp diff --git a/service/things-manager/sampleapp/SConscript b/service/things-manager/sampleapp/SConscript index 8abb615..6f4d2ea 100644 --- a/service/things-manager/sampleapp/SConscript +++ b/service/things-manager/sampleapp/SConscript @@ -40,4 +40,3 @@ target_os = env.get('TARGET_OS') if target_os == 'linux' : # Build linux sample app SConscript('linux/configuration/SConscript') - SConscript('linux/groupaction/SConscript') diff --git a/service/things-manager/sampleapp/linux/groupaction/SConscript b/service/things-manager/sampleapp/linux/groupaction/SConscript deleted file mode 100644 index dd73a8a..0000000 --- a/service/things-manager/sampleapp/linux/groupaction/SConscript +++ /dev/null @@ -1,64 +0,0 @@ -#****************************************************************** -# -# 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. -# -#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - -## -# linux sample app build script -## - -Import('env') - -# Add third party libraries -lib_env = env.Clone() -SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env') -linux_sample_env = lib_env.Clone() - -###################################################################### -# Build flags -###################################################################### -linux_sample_env.AppendUnique(CPPPATH = ['include']) -linux_sample_env.AppendUnique(CPPPATH = ['../../../../../extlibs/timer']) -linux_sample_env.AppendUnique(CPPPATH = ['../../../sdk/inc']) -linux_sample_env.AppendUnique(CPPPATH = ['../../../sdk/src']) -linux_sample_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-DLINUX', '-pthread']) -linux_sample_env.AppendUnique(CPPDEFINES = ['LINUX']) -linux_sample_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')]) -linux_sample_env.AppendUnique(LIBS = ['libTGMSDKLibrary', 'oc', 'octbstack', - 'connectivity_abstraction', - 'libcoap', 'liboc_logger', 'dl', 'pthread']) -if env.get('SECURED') == '1': - linux_sample_env.AppendUnique(LIBS = ['tinydtls']) - -# On some platforms link order can miss functions so librt needs to be -# re-scanned at the end if present. gcc 4.6 is one with this issue. -if 'rt' in linux_sample_env.get('LIBS'): - linux_sample_env.Append(LIBS = ['rt']) - -###################################################################### -#build sampleapp -###################################################################### -groupserver = linux_sample_env.Program('groupserver', 'groupserver.cpp') -lightserver = linux_sample_env.Program('lightserver', 'lightserver.cpp') -bookmark = linux_sample_env.Program('bookmark', 'bookmark.cpp') -Alias("GroupServerApp", groupserver) -Alias("LightServerApp", lightserver) -Alias("BookmarkApp", bookmark) -env.AppendTarget('GroupServerApp') -env.AppendTarget('LightServerApp') -env.AppendTarget('BookmarkApp') diff --git a/service/things-manager/sampleapp/linux/groupaction/bookmark.cpp b/service/things-manager/sampleapp/linux/groupaction/bookmark.cpp deleted file mode 100755 index 18d1127..0000000 --- a/service/things-manager/sampleapp/linux/groupaction/bookmark.cpp +++ /dev/null @@ -1,229 +0,0 @@ -//****************************************************************** -// -// 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. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - -#include -#include - -#include "OCPlatform.h" -#include "OCApi.h" - -using namespace OC; -using namespace std; - -namespace PH = std::placeholders; - -unsigned int startedThread; -unsigned int gObservation; -pthread_t threadId; - -void* ObserveHandler(void *param); - -class BookmarkResource -{ - -private: - OCEntityHandlerResult entityHandler(std::shared_ptr< OCResourceRequest > request) - { - OCEntityHandlerResult ehResult = OC_EH_ERROR; - - if (request) - { - // Get the request type and request flag - std::string requestType = request->getRequestType(); - int requestFlag = request->getRequestHandlerFlag(); - - if (requestFlag & RequestHandlerFlag::RequestFlag) - { - auto pResponse = std::make_shared< OC::OCResourceResponse >(); - pResponse->setRequestHandle(request->getRequestHandle()); - pResponse->setResourceHandle(request->getResourceHandle()); - - // If the request type is GET - if (requestType == "GET") - { - } - else if (requestType == "PUT") - { - cout << "\t\t\trequestType : PUT\n"; - } - else if (requestType == "POST") - { - // POST request operations - } - else if (requestType == "DELETE") - { - // DELETE request operations - } - - pResponse->setErrorCode(200); - pResponse->setResponseResult(OC_EH_OK); - pResponse->setResourceRepresentation(getRepresentation()); - if (OC_STACK_OK == OCPlatform::sendResponse(pResponse)) - { - ehResult = OC_EH_OK; - } - } - - if (requestFlag & RequestHandlerFlag::ObserverFlag) - { - cout << "\t\trequestFlag : Observer\n"; - - if (!startedThread) - { - pthread_create(&threadId, NULL, ObserveHandler, (void *) NULL); - startedThread = 1; - gObservation = 1; - } - - ehResult = OC_EH_OK; - } - } - else - { - std::cout << "Request invalid" << std::endl; - } - - return ehResult; - } - -public: - /// Constructor - BookmarkResource() - { - m_pressure = 0; - - m_BookmarkUri = "/core/bookmark"; // URI of the resource - m_BookmarkType = "core.bookmark"; // resource type name. In this case, it is light - - m_BookmarkInterface = DEFAULT_INTERFACE; // resource interface. - m_BookmarkHandle = 0; - } - - /// This function internally calls registerResource API. - void createResources() - { - EntityHandler cb = std::bind(&BookmarkResource::entityHandler, this, PH::_1); - - // This will internally create and register the resource. - OCStackResult result = OC::OCPlatform::registerResource(m_BookmarkHandle, m_BookmarkUri, - m_BookmarkType, m_BookmarkInterface, cb, OC_DISCOVERABLE | OC_OBSERVABLE); - - if (OC_STACK_OK != result) - { - cout << "Resource creation (bookmark) was unsuccessful\n"; - } - else - { - cout << "Resource URI : " << m_BookmarkUri << endl; - cout << "\tResource Type Name : " << m_BookmarkType << endl; - cout << "\tResource Interface : " << DEFAULT_INTERFACE << endl; - cout << "\tResource creation is successful with resource handle : " << m_BookmarkHandle - << endl; - } - } - - void setRepresentation(OCRepresentation& /*rep*/) - { - // AttributeMap attributeMap = rep.getAttributeMap(); - // if(rep.getValue("level", m_pressure) == true) - { - std::cout << m_pressure << endl; - } - } - - OCRepresentation getRepresentation() - { - OCRepresentation rep; - - rep.setValue("level", (int) m_pressure); - - return rep; - } - -public: - // Members of Bookmark - std::string m_BookmarkUri; - std::string m_BookmarkType; - std::string m_BookmarkInterface; - unsigned int m_pressure; - OCResourceHandle m_BookmarkHandle; -}; - -// Create the instance of the resource class (in this case instance of class 'BookmarkResource'). -BookmarkResource myBookmarkResource; - -void* ObserveHandler(void* /*param*/) -{ - while (startedThread) - { - sleep(1); - - cout << "input a integer(0:opened, 5:close) : "; - cin >> myBookmarkResource.m_pressure; - - if (myBookmarkResource.m_pressure == 0 || // When your book opened. - myBookmarkResource.m_pressure == 5) // When your book closed. - { - cout << "notifyObservers call!" << endl; - - OCStackResult result = OCPlatform::notifyAllObservers( - myBookmarkResource.m_BookmarkHandle); - - if (OC_STACK_NO_OBSERVERS == result) - { - cout << "No More observers, stopping notifications" << endl; - gObservation = 0; - startedThread = 0; - } - } - } - - return NULL; -} - -int main() -{ - // Create PlatformConfig object - - OC::PlatformConfig cfg - { OC::ServiceType::InProc, OC::ModeType::Server, "0.0.0.0", - // By setting to "0.0.0.0", it binds to all available interfaces - 0,// Uses randomly available port - OC::QualityOfService::LowQos }; - - // Create a OCPlatform instance. - // Note: Platform creation is synchronous call. - try - { - - // Invoke createResource function of class bookmark. - myBookmarkResource.createResources(); - - // Perform app tasks - while (true) - { - // some tasks - } - } - catch (OCException e) - { - std::cout << "Exception: " << e.what() << std::endl; - } -} diff --git a/service/things-manager/sampleapp/linux/groupaction/groupserver.cpp b/service/things-manager/sampleapp/linux/groupaction/groupserver.cpp deleted file mode 100755 index add3d12..0000000 --- a/service/things-manager/sampleapp/linux/groupaction/groupserver.cpp +++ /dev/null @@ -1,596 +0,0 @@ -//****************************************************************** -// -// 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. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - -#include -#include - -#include -#include -#include - -#include "timer.h" - -#include - -using namespace std; -using namespace OC; -using namespace OIC; -namespace PH = std::placeholders; - -bool isReady = false; - -OCResourceHandle resourceHandle = NULL; -std::vector resourceHandleVector; - -shared_ptr g_resource = NULL; -vector lights; - -GroupManager *groupMgr = new GroupManager(); - -void onGet(const HeaderOptions& opt, const OCRepresentation &rep, - const int eCode); - -void onPut(const HeaderOptions& headerOptions, const OCRepresentation& rep, - const int eCode); - -void onPost(const HeaderOptions& headerOptions, const OCRepresentation& rep, - const int eCode); - -void onObserve(const HeaderOptions headerOptions, const OCRepresentation& rep, - const int& eCode, const int& sequenceNumber); - -void allBulbOn(); -void allBulbOff(); - -shared_ptr g_light; - -void foundResources( - std::vector > listOfResource) -{ - try - { - for (auto rsrc = listOfResource.begin(); rsrc != listOfResource.end(); - ++rsrc) - { - std::string resourceURI = (*rsrc)->uri(); - std::string hostAddress = (*rsrc)->host(); - - if (resourceURI == "/a/light") - { - cout << "\tResource URI : " << resourceURI << endl; - cout << "\tResource Host : " << hostAddress << endl; - - OCResourceHandle foundResourceHandle = NULL; - OCStackResult result = OCPlatform::registerResource( - foundResourceHandle, (*rsrc)); - cout << "\tresource registed!" << endl; - if (result == OC_STACK_OK) - { - OCPlatform::bindResource(resourceHandle, foundResourceHandle); - resourceHandleVector.push_back(foundResourceHandle); - } - else - { - cout << "\tresource Error!" << endl; - } - - lights.push_back((hostAddress + resourceURI)); - - g_light = (*rsrc); - } - } - } - catch (std::exception& e) - { - std::cout << "Exception in foundResource:"<< e.what() << std::endl; - } - - isReady = true; -} - -void foundResource(std::shared_ptr resource) -{ - std::string resourceURI; - std::string hostAddress; - - cout << "FOUND RESOURCE" << endl; - - try - { - if (resource) - { - resourceURI = resource->uri(); - hostAddress = resource->host(); - if (resourceURI == "/core/a/collection") - { - g_resource = resource; - - // g_resource->get("", DEFAULT_INTERFACE, QueryParamsMap(), onGet); - - cout << "FOUND " << resourceURI << endl; - // printf("\tHOST :: %s\n", resource->host().c_str()); - } - else if (resourceURI == "/core/bookmark") - { - resource->observe(ObserveType::Observe, QueryParamsMap(), - &onObserve); - } - } - } - catch (std::exception& e) - { - std::cout << "Exception: " << e.what() << std::endl; - } -} - -void onGet(const HeaderOptions& /*opt*/, const OCRepresentation &/*rep*/, - const int eCode) -{ - cout << "\nonGet" << endl; - if (eCode == OC_STACK_OK) - cout << "\tResult is OK." << endl; - else - cout << "\tInvalid parameter." << endl; -} - -void onPut(const HeaderOptions& /*opt*/, const OCRepresentation &/*rep*/, - const int eCode) -{ - cout << "\nonPut" << endl; - if (eCode == OC_STACK_OK) - cout << "\tResult is OK." << endl; - else - cout << "\tInvalid parameter." << endl; -} - -void onPost(const HeaderOptions& /*opt*/, const OCRepresentation &rep, - const int /*eCode*/) -{ - printf("\nonPost\n"); - - if (rep.hasAttribute("ActionSet")) - { - std::string plainText; - - if (rep.getValue("ActionSet", plainText)) - { - ActionSet *actionset = groupMgr->getActionSetfromString(plainText); - if (actionset != NULL) - { - cout << endl << "\tACTIONSET NAME :: " - << actionset->actionsetName << endl; - for (auto actIter = actionset->listOfAction.begin(); - actIter != actionset->listOfAction.end(); ++actIter) - { - cout << "\t\tTARGET :: " << (*actIter)->target << endl; - - for (auto capaIter = (*actIter)->listOfCapability.begin(); - capaIter != (*actIter)->listOfCapability.end(); - ++capaIter) - { - cout << "\t\t\t" << (*capaIter)->capability << " :: " - << (*capaIter)->status << endl; - } - } - } - delete actionset; - } - - // printf( "\tPlain Text :: %s\n", plainText.c_str() ); - } - else if (rep.hasAttribute("DoAction")) - { - std::string plainText; - if (rep.getValue("DoAction", plainText)) - { - cout << "\t" << plainText << endl; - } - } - else - { - - } -} - -void allBulbOff() -{ - OCRepresentation rep; - - rep.setValue("DoAction", std::string("AllBulbOff")); - - if (g_resource) - { - g_resource->post("a.collection", GROUP_INTERFACE, rep, QueryParamsMap(), - &onPost); - } -} - -void allBulbOn() -{ - OCRepresentation rep; - - rep.setValue("DoAction", std::string("AllBulbOn")); - - if (g_resource) - { - OCStackResult res = g_resource->post("a.collection", GROUP_INTERFACE, - rep, QueryParamsMap(), &onPost); - - if( res != OC_STACK_OK ) - cout << "failed" << endl; - } -} - -void Scheduled_AllbulbOff() -{ - groupMgr->executeActionSet(g_resource, "AllBulbOffScheduledCall", &onPost); -} -void Scheduled_AllbulbOffEx() -{ - groupMgr->executeActionSet(g_resource, "AllBulbOffScheduledCall", 10, &onPost); -} -void CancelScheduled_AllBulbOff() -{ - groupMgr->cancelActionSet(g_resource, "AllBulbOffScheduledCall", &onPost); -} -void Recursive_allBulbOn() -{ - groupMgr->executeActionSet(g_resource, "AllBulbOnRecursiveCall", &onPost); -} -void Recursive_allBulbOnEx() -{ - groupMgr->executeActionSet(g_resource, "AllBulbOnRecursiveCall", 10, &onPost); -} - -void CancelRecursive_allBulbOn() -{ - - groupMgr->cancelActionSet(g_resource, "AllBulbOnRecursiveCall", &onPost); -} - -void onObserve(const HeaderOptions /*headerOptions*/, const OCRepresentation& rep, - const int& eCode, const int& sequenceNumber) -{ - if (eCode == OC_STACK_OK) - { - int level; - - std::cout << "OBSERVE RESULT:" << std::endl; - std::cout << "\tSequenceNumber: " << sequenceNumber << endl; - - if (rep.getValue("level", level)) - { - if (level == 0) - { - allBulbOn(); - } - else - { - allBulbOff(); - } - } - std::cout << "\tlevel: " << level << std::endl; - } - else - { - std::cout << "onObserve Response error: " << eCode << std::endl; - std::exit(-1); - } -} - -void createActionSet_AllBulbOff() -{ - string actionsetDesc; - ActionSet *allBulbOff = new ActionSet(); - allBulbOff->actionsetName = "AllBulbOff"; - - for (auto iter = lights.begin(); iter != lights.end(); ++iter) - { - Action *action = new Action(); - action->target = (*iter); - - Capability *capa = new Capability(); - capa->capability = "power"; - capa->status = "off"; - - action->listOfCapability.push_back(capa); - allBulbOff->listOfAction.push_back(action); - } - if (g_resource) - { - groupMgr->addActionSet(g_resource, allBulbOff, onPut); - } - - delete allBulbOff; -} - -void createActionSet_AllBulbOn() -{ - string actionsetDesc; - ActionSet *allBulbOff = new ActionSet(); - allBulbOff->actionsetName = "AllBulbOn"; - - for (auto iter = lights.begin(); iter != lights.end(); ++iter) - { - Action *action = new Action(); - action->target = (*iter); - - Capability *capa = new Capability(); - capa->capability = "power"; - capa->status = "on"; - - action->listOfCapability.push_back(capa); - allBulbOff->listOfAction.push_back(action); - } - if (g_resource) - { - groupMgr->addActionSet(g_resource, allBulbOff, onPut); - } - - delete allBulbOff; -} - -void createScheduledActionSet_AllBulbOff() -{ - string actionsetDesc; - ActionSet *allBulbOff = new ActionSet(); - allBulbOff->type = OIC::ACTIONSET_TYPE::SCHEDULED; - allBulbOff->actionsetName = "AllBulbOffScheduledCall"; - - printf("ENTER(YYYY-MM-DD hh:mm:ss) :: "); - int res = scanf("%d-%d-%d %d:%d:%d", &allBulbOff->mTime.tm_year, - &allBulbOff->mTime.tm_mon, &allBulbOff->mTime.tm_mday, - &allBulbOff->mTime.tm_hour, &allBulbOff->mTime.tm_min, - &allBulbOff->mTime.tm_sec); - if( res < 0 ) - { - printf("Invalid Input. try again."); - delete allBulbOff; - return; - } - - allBulbOff->setDelay(allBulbOff->getSecondsFromAbsoluteTime()); - printf("DELAY :: %ld\n", allBulbOff->getSecondsFromAbsoluteTime()); - - for (auto iter = lights.begin(); iter != lights.end(); ++iter) - { - Action *action = new Action(); - action->target = (*iter); - - Capability *capa = new Capability(); - capa->capability = "power"; - capa->status = "off"; - - action->listOfCapability.push_back(capa); - allBulbOff->listOfAction.push_back(action); - } - if (g_resource) - { - groupMgr->addActionSet(g_resource, allBulbOff, onPut); - } - - delete allBulbOff; -} - -void createRecursiveActionSet_AllBulbOn() -{ - string actionsetDesc; - ActionSet *allBulbOn = new ActionSet(); - allBulbOn->type = OIC::ACTIONSET_TYPE::RECURSIVE; - - allBulbOn->actionsetName = "AllBulbOnRecursiveCall"; - allBulbOn->mTime.tm_year = 0; - allBulbOn->mTime.tm_mon = 0; - allBulbOn->mTime.tm_mday = 0; - allBulbOn->mTime.tm_hour = 0; - allBulbOn->mTime.tm_min = 0; - allBulbOn->mTime.tm_sec = 5; - - allBulbOn->setDelay(allBulbOn->getSecAbsTime()); - - for (auto iter = lights.begin(); iter != lights.end(); ++iter) - { - Action *action = new Action(); - action->target = (*iter); - - Capability *capa = new Capability(); - capa->capability = "power"; - capa->status = "on"; - - action->listOfCapability.push_back(capa); - allBulbOn->listOfAction.push_back(action); - } - if (g_resource) - { - groupMgr->addActionSet(g_resource, allBulbOn, onPut); - } - - delete allBulbOn; -} - -int main() -{ - PlatformConfig config - { OC::ServiceType::InProc, ModeType::Both, "0.0.0.0", 0, - OC::QualityOfService::LowQos }; - - try - { - string resourceURI = "/core/a/collection"; - string resourceTypeName = "a.collection"; - string resourceInterface = BATCH_INTERFACE; - OCPlatform::Configure(config); - - // Find lights for group creation. - vector types; - types.push_back("core.light"); - groupMgr->findCandidateResources(types, &foundResources, 5); - - OCStackResult res = OCPlatform::registerResource(resourceHandle, resourceURI, - resourceTypeName, resourceInterface, NULL, OC_DISCOVERABLE); - - if( res != OC_STACK_OK ) - { - cout << "Resource registeration failed." << endl; - return 0; - } - - cout << "registerResource is called." << endl; - - OCPlatform::bindInterfaceToResource(resourceHandle, GROUP_INTERFACE); - OCPlatform::bindInterfaceToResource(resourceHandle, DEFAULT_INTERFACE); - - bool isRun = true; - - while (isRun) - { - while (isReady) - { - int n; - - cout << endl; - cout << "1 :: CREATE ACTIONSET" << endl; - cout << "2 :: EXECUTE ACTIONSET(ALLBULBON)" << endl; - cout << "3 :: EXECUTE ACTIONSET(ALLBULBOFF)" << endl; - cout << "4 :: CREATE ACTIONSET(R_ALLBULBON)" << endl; - cout << "\t41 :: EXECUTE ACTIONSET 42 :: CANCEL ACTIONSET" << endl; - cout << "5 :: CREATE ACTIONSET(S_ALLBULBON)" << endl; - cout << "\t51 :: EXECUTE ACTIONSET 52 :: CANCEL ACTIONSET" << endl; - cout << "6 :: GET ACTIONSET" << endl; - cout << "7 :: DELETE ACTIONSET" << endl; - cout << "8 :: QUIT" << endl; - cout << "9 :: FIND GROUP" << endl; - cout << "0 :: FIND BOOKMARK TO OBSERVE" - << endl; - - //fflush(stdin); - cin >> n; - - if (n == 9) - { - std::string query = OC_RSRVD_WELL_KNOWN_URI; - query.append("?rt="); - query.append(resourceTypeName); - - OCPlatform::findResource("", - query, - CT_DEFAULT, - &foundResource); - - // OCPlatform::findResource("", - // query, - // OC_WIFI, - // &foundResource); - } - else if (n == 0) - { - std::string query = OC_RSRVD_WELL_KNOWN_URI; - query.append("?rt="); - query.append("core.bookmark"); - - OCPlatform::findResource("", - query, - CT_DEFAULT, - &foundResource); - // OCPlatform::findResource("", - // query, - // OC_WIFI, - // &foundResource); - } - else if (n == 1) - { - createActionSet_AllBulbOff(); - createActionSet_AllBulbOn(); - } - else if (n == 2) - { - allBulbOn(); - } - else if (n == 3) - { - allBulbOff(); - } - else if (n == 4) - { - createRecursiveActionSet_AllBulbOn(); - } - else if (n == 41) - { - Recursive_allBulbOn(); - } - else if (n == 42) - { - CancelRecursive_allBulbOn(); - } - // Exampel of - else if (n == 43) - { - Recursive_allBulbOnEx(); - } - else if (n == 5) - { - createScheduledActionSet_AllBulbOff(); - } - else if (n == 51) - { - Scheduled_AllbulbOff(); - } - else if (n == 52) - { - CancelScheduled_AllBulbOff(); - } - else if (n == 53) - { - Scheduled_AllbulbOffEx(); - } - else if (n == 6) - { - groupMgr->getActionSet(g_resource, "AllBulbOff", onPost); - } - else if (n == 7) - { - groupMgr->deleteActionSet(g_resource, "AllBulbOff", onPut); - } - else if (n == 8) - { - isRun = false; - break; - } - else if(n == 100) - { - - OCRepresentation rep; - - rep.setValue("power", std::string("on")); - - g_light->put(rep, QueryParamsMap(), &onPut); - - } - } - } - usleep(500*1000); - } - catch (OCException& e) - { - cout << "ERROR :: " << e.reason() << endl; - } - - return 0; -} diff --git a/service/things-manager/sampleapp/linux/groupaction/lightserver.cpp b/service/things-manager/sampleapp/linux/groupaction/lightserver.cpp deleted file mode 100755 index 45ae0f0..0000000 --- a/service/things-manager/sampleapp/linux/groupaction/lightserver.cpp +++ /dev/null @@ -1,331 +0,0 @@ -//****************************************************************** -// -// Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved. -// 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. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - -/// -/// This sample provides steps to define an interface for a resource -/// (properties and methods) and host this resource on the server. -/// - -#include - -#include -#include -#include - -#include "OCPlatform.h" -#include "OCApi.h" - -using namespace OC; -using namespace std; -namespace PH = std::placeholders; - -int gObservation = 0; -void * ChangeLightRepresentation(void *param); -void * handleSlowResponse(void *param, std::shared_ptr< OCResourceRequest > pRequest); - -// Specifies secure or non-secure -// false: non-secure resource -// true: secure resource -bool isSecure = false; - -/// Specifies whether Entity handler is going to do slow response or not -bool isSlowResponse = false; - -// Forward declaring the entityHandler - -/// This class represents a single resource named 'lightResource'. This resource has -/// two simple properties named 'state' and 'power' - -class LightResource -{ - -public: - /// Access this property from a TB client - std::string m_power; - std::string m_lightUri; - OCResourceHandle m_resourceHandle; - OCRepresentation m_lightRep; - -public: - /// Constructor - LightResource() : - m_power(""), m_lightUri("/a/light"), m_resourceHandle(0) - { - // Initialize representation - m_lightRep.setUri(m_lightUri); - - m_lightRep.setValue("power", m_power); - } - - /* Note that this does not need to be a member function: for classes you do not have - access to, you can accomplish this with a free function: */ - - /// This function internally calls registerResource API. - void createResource() - { - std::string resourceURI = m_lightUri; //URI of the resource - std::string resourceTypeName = "core.light"; //resource type name. In this case, it is light - std::string resourceInterface = DEFAULT_INTERFACE; // resource interface. - - EntityHandler cb = std::bind(&LightResource::entityHandler, this, PH::_1); - - // This will internally create and register the resource. - OCStackResult result = OCPlatform::registerResource(m_resourceHandle, resourceURI, - resourceTypeName, resourceInterface, cb, OC_DISCOVERABLE | OC_OBSERVABLE); - - if (OC_STACK_OK != result) - { - cout << "Resource creation was unsuccessful\n"; - } - else - { - cout << "Resource URI : " << resourceURI << endl; - cout << "\tResource Type Name : " << resourceTypeName << endl; - cout << "\tResource Interface : " << DEFAULT_INTERFACE << endl; - cout << "\tResource creation is successful with resource handle : " << m_resourceHandle - << endl; - } - } - - OCResourceHandle getHandle() - { - return m_resourceHandle; - } - - // Puts representation. - // Gets values from the representation and - // updates the internal state - void put(OCRepresentation& rep) - { - try - { - if (rep.getValue("power", m_power)) - { - cout << "\t\t\t\t" << "power: " << m_power << endl; - } - else - { - cout << "\t\t\t\t" << "power not found in the representation" << endl; - } - } - catch (exception& e) - { - cout << e.what() << endl; - } - - } - - // Post representation. - // Post can create new resource or simply act like put. - // Gets values from the representation and - // updates the internal state - OCRepresentation post(OCRepresentation& rep) - { - put(rep); - return get(); - } - - // gets the updated representation. - // Updates the representation with latest internal state before - // sending out. - OCRepresentation get() - { - m_lightRep.setValue("power", m_power); - - return m_lightRep; - } - - void addType(const std::string& type) const - { - OCStackResult result = OCPlatform::bindTypeToResource(m_resourceHandle, type); - if (OC_STACK_OK != result) - { - cout << "Binding TypeName to Resource was unsuccessful\n"; - } - } - - void addInterface(const std::string& interface) const - { - OCStackResult result = OCPlatform::bindInterfaceToResource(m_resourceHandle, interface); - if (OC_STACK_OK != result) - { - cout << "Binding TypeName to Resource was unsuccessful\n"; - } - } - -private: -// This is just a sample implementation of entity handler. -// Entity handler can be implemented in several ways by the manufacturer - OCEntityHandlerResult entityHandler(std::shared_ptr< OCResourceRequest > request) - { - cout << "\tIn Server CPP entity handler:\n"; - OCEntityHandlerResult ehResult = OC_EH_ERROR; - if (request) - { - // Get the request type and request flag - std::string requestType = request->getRequestType(); - int requestFlag = request->getRequestHandlerFlag(); - - if (requestFlag & RequestHandlerFlag::RequestFlag) - { - cout << "\t\trequestFlag : Request\n"; - auto pResponse = std::make_shared< OC::OCResourceResponse >(); - pResponse->setRequestHandle(request->getRequestHandle()); - pResponse->setResourceHandle(request->getResourceHandle()); - - // If the request type is GET - if (requestType == "GET") - { - cout << "\t\t\trequestType : GET\n"; - if (isSlowResponse) // Slow response case - { - static int startedThread = 0; - if (!startedThread) - { - std::thread t(handleSlowResponse, (void *) this, request); - startedThread = 1; - t.detach(); - } - ehResult = OC_EH_SLOW; - } - else // normal response case. - { - pResponse->setErrorCode(200); - pResponse->setResponseResult(OC_EH_OK); - pResponse->setResourceRepresentation(get()); - if (OC_STACK_OK == OCPlatform::sendResponse(pResponse)) - { - ehResult = OC_EH_OK; - } - } - } - else if (requestType == "PUT") - { - cout << "\t\t\trequestType : PUT\n"; - OCRepresentation rep = request->getResourceRepresentation(); - - // Do related operations related to PUT request - // Update the lightResource - put(rep); - pResponse->setErrorCode(200); - pResponse->setResponseResult(OC_EH_OK); - pResponse->setResourceRepresentation(get()); - if (OC_STACK_OK == OCPlatform::sendResponse(pResponse)) - { - ehResult = OC_EH_OK; - } - } - else if (requestType == "POST") - { - cout << "\t\t\trequestType : POST\n"; - - OCRepresentation rep = request->getResourceRepresentation(); - - // Do related operations related to POST request - OCRepresentation rep_post = post(rep); - pResponse->setResourceRepresentation(rep_post); - pResponse->setErrorCode(200); - if (rep_post.hasAttribute("createduri")) - { - pResponse->setResponseResult(OC_EH_RESOURCE_CREATED); - pResponse->setNewResourceUri( - rep_post.getValue< std::string >("createduri")); - } - - if (OC_STACK_OK == OCPlatform::sendResponse(pResponse)) - { - ehResult = OC_EH_OK; - } - } - else if (requestType == "DELETE") - { - // DELETE request operations - } - } - } - else - { - std::cout << "Request invalid" << std::endl; - } - - return ehResult; - } -}; - -void * handleSlowResponse(void *param, std::shared_ptr< OCResourceRequest > pRequest) -{ - // This function handles slow response case - LightResource* lightPtr = (LightResource*) param; - // Induce a case for slow response by using sleep - std::cout << "SLOW response" << std::endl; - sleep(10); - - auto pResponse = std::make_shared< OC::OCResourceResponse >(); - pResponse->setRequestHandle(pRequest->getRequestHandle()); - pResponse->setResourceHandle(pRequest->getResourceHandle()); - pResponse->setResourceRepresentation(lightPtr->get()); - pResponse->setErrorCode(200); - pResponse->setResponseResult(OC_EH_OK); - - // Set the slow response flag back to false - isSlowResponse = false; - OCPlatform::sendResponse(pResponse); - return NULL; -} - -int main() -{ - // Create PlatformConfig object - PlatformConfig cfg - { OC::ServiceType::InProc, OC::ModeType::Server, "0.0.0.0", - // By setting to "0.0.0.0", it binds to all available interfaces - 0,// Uses randomly available port - OC::QualityOfService::LowQos }; - - OCPlatform::Configure(cfg); - try - { - // Create the instance of the resource class - // (in this case instance of class 'LightResource'). - LightResource myLight; - - // Invoke createResource function of class light. - myLight.createResource(); - - // A condition variable will free the mutex it is given, then do a non- - // intensive block until 'notify' is called on it. In this case, since we - // don't ever call cv.notify, this should be a non-processor intensive version - // of while(true); - std::mutex blocker; - std::condition_variable cv; - std::unique_lock < std::mutex > lock(blocker); - cv.wait(lock); - } - catch (OCException e) - { - //log(e.what()); - } - - // No explicit call to stop the platform. - // When OCPlatform::destructor is invoked, internally we do platform cleanup - - return 0; -} -- 2.7.4