From: Erich Keane Date: Fri, 5 Sep 2014 17:35:33 +0000 (-0700) Subject: Updated the name of the API to unregisterResource. And this API returns X-Git-Tag: 0.9.0-CA-RC1~223 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=884e7ab4459f78961438db9bdedbdc819ec8355e;p=contrib%2Fiotivity.git Updated the name of the API to unregisterResource. And this API returns whatever result it got from the stack. NOTE: Only this API has been changed. Added C++ API for unregistering a resource Patch 3: Rebase Patch 4: added test code, fixed ocicuc bug Change-Id: Ida95886fcbbaceab349bc127ae4b4e44ff823828 --- diff --git a/examples/ocicuc/light_resource.cpp b/examples/ocicuc/light_resource.cpp index 56a2a7f..370a54e 100644 --- a/examples/ocicuc/light_resource.cpp +++ b/examples/ocicuc/light_resource.cpp @@ -44,14 +44,12 @@ void LightResource::createResource(OC::OCPlatform& platform, const unsigned int cout << "registering resource: " << resourceURI << '\n'; cout << "registering type name \"" << resourceTypeName << "\".\n"; - // This will internally create and register the resource, binding the current instance's method as a callback: OCStackResult result = platform.registerResource( m_resourceHandle, resourceURI, resourceTypeName, DEFAULT_INTERFACE, std::bind(&LightResource::entityHandler, this, std::placeholders::_1, std::placeholders::_2), OC_DISCOVERABLE | OC_OBSERVABLE); - if (OC_STACK_OK != result) std::cout << "Resource creation failed.\n"; } @@ -81,6 +79,22 @@ void LightResource::observe_function() cerr << "Observation thread is shutting down.\n"; } +void LightResource::unregisterResource(OC::OCPlatform& platform) +{ + std::cout << "Unregistering light resource"< request, std::shared_ptr response) diff --git a/examples/ocicuc/light_resource.hpp b/examples/ocicuc/light_resource.hpp index bfb1692..3cd2031 100644 --- a/examples/ocicuc/light_resource.hpp +++ b/examples/ocicuc/light_resource.hpp @@ -62,7 +62,7 @@ class LightResource public: // This function internally calls registerResource API. void createResource(OC::OCPlatform& platform, const unsigned int resource_number); - + void unregisterResource(OC::OCPlatform& platform); OCResourceHandle getHandle() const { return m_resourceHandle; } void setRepresentation(AttributeMap& attributeMap); diff --git a/examples/ocicuc/server.cpp b/examples/ocicuc/server.cpp index a564624..3b175e5 100644 --- a/examples/ocicuc/server.cpp +++ b/examples/ocicuc/server.cpp @@ -40,6 +40,7 @@ auto make_description() ("host_port", po::value()->default_value(56832), "port of host") ("interface", po::value()->default_value("eth0"), "network interface name") ("uri", po::value>(), "resource URI") + ("runtime", po::value()->default_value(3600), "time in seconds to keep the server alive") ; return desc; @@ -67,8 +68,6 @@ int exec(const boost::program_options::variables_map& vm) const unsigned long& nresources = vm["nres"].as(); - lights.resize(nresources); - for(unsigned int resource_number = 1; nresources >= resource_number; resource_number++) { cout << "Registering resource " << resource_number << ": " << std::flush; @@ -85,9 +84,12 @@ int exec(const boost::program_options::variables_map& vm) } // Perform app tasks - while(true) + cout << "Sleeping for "<< vm["runtime"].as()<<" seconds."<())); + + for(auto light: lights) { - std::this_thread::sleep_for(std::chrono::seconds(5)); + light->unregisterResource(platform); } return 1; diff --git a/include/IServerWrapper.h b/include/IServerWrapper.h index b102329..4126a17 100644 --- a/include/IServerWrapper.h +++ b/include/IServerWrapper.h @@ -47,7 +47,8 @@ namespace OC const std::string& resourceInterface, std::function entityHandler, uint8_t resourceProperty) = 0; - + virtual OCStackResult unregisterResource( + const OCResourceHandle& resourceHandle) = 0; virtual OCStackResult bindTypeToResource( const OCResourceHandle& resourceHandle, const std::string& resourceTypeName) = 0; diff --git a/include/InProcServerWrapper.h b/include/InProcServerWrapper.h index bcd85eb..f06c3db 100644 --- a/include/InProcServerWrapper.h +++ b/include/InProcServerWrapper.h @@ -45,6 +45,9 @@ namespace OC std::function entityHandler, uint8_t resourceProperty); + virtual OCStackResult unregisterResource( + const OCResourceHandle& resourceHandle); + virtual OCStackResult bindTypeToResource( const OCResourceHandle& resourceHandle, const std::string& resourceTypeName); diff --git a/include/OCPlatform.h b/include/OCPlatform.h index e39fae0..26ce6a6 100644 --- a/include/OCPlatform.h +++ b/include/OCPlatform.h @@ -132,6 +132,17 @@ namespace OC uint8_t resourceProperty); /** + * This API unregisters a resource with the server + * NOTE: This API applies to server side only. + * + * @param resourceHandle - This is the resource handle which we which to unregister from the server + * + * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. + * NOTE: OCStackResult is defined in ocstack.h. + */ + OCStackResult unregisterResource(const OCResourceHandle& resourceHandle) const; + + /** * Add a resource to a collection resource. * * @param collectionHandle - handle to the collection resource diff --git a/include/OutOfProcServerWrapper.h b/include/OutOfProcServerWrapper.h index 3c2108f..2503ee5 100644 --- a/include/OutOfProcServerWrapper.h +++ b/include/OutOfProcServerWrapper.h @@ -42,7 +42,14 @@ namespace OC // Not implemented return OC_STACK_NOTIMPL; } - virtual OCStackResult bindTypeToResource( + + virtual OCStackResult unregisterResource( + const OCResourceHandle& resourceHandle) + { //Not implemented yet + return OC_STACK_ERROR; + } + + virtual OCStackResult bindTypeToResource( const OCResourceHandle& resourceHandle, const std::string& resourceTypeName) { //Not implemented yet diff --git a/src/InProcServerWrapper.cpp b/src/InProcServerWrapper.cpp index fea13c3..0be188c 100644 --- a/src/InProcServerWrapper.cpp +++ b/src/InProcServerWrapper.cpp @@ -272,6 +272,19 @@ namespace OC return result; } + OCStackResult InProcServerWrapper::unregisterResource(const OCResourceHandle& resourceHandle) + { + cout << "Unregistering Resource: \n"; + + auto cLock = m_csdkLock.lock(); + OCStackResult result = OC_STACK_ERROR; + if(cLock) + { + std::lock_guard lock(*cLock); + result = OCDeleteResource(resourceHandle); + } + return result; + } OCStackResult InProcServerWrapper::bindTypeToResource(const OCResourceHandle& resourceHandle, const std::string& resourceTypeName) { diff --git a/src/OCPlatform.cpp b/src/OCPlatform.cpp index ec272e4..dbf5a14 100644 --- a/src/OCPlatform.cpp +++ b/src/OCPlatform.cpp @@ -126,6 +126,20 @@ namespace OC return result; } + + OCStackResult OCPlatform::unregisterResource(const OCResourceHandle& resourceHandle) const + { + OCStackResult result = OC_STACK_ERROR; + + if(m_server) + { + result = m_server->unregisterResource(resourceHandle); + } + return result; + } + + + OCStackResult OCPlatform::unbindResource(OCResourceHandle collectionHandle, OCResourceHandle resourceHandle) { OCStackResult result = OC_STACK_OK;