From 004f03b1455bf064a236e3cc8f078b9c23e67daa Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Tue, 12 Aug 2014 10:53:04 -0700 Subject: [PATCH] US1313, abillity to create an OCResource object without discovering it Change-Id: Ie283435901a6438c4695496c79cca15e248273a2 --- OCLib/OCPlatform.cpp | 16 +++++++++++++++- include/OCPlatform.h | 29 ++++++++++++++++++++++++++++- include/OCResource.h | 1 + 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/OCLib/OCPlatform.cpp b/OCLib/OCPlatform.cpp index 2321211..1394149 100644 --- a/OCLib/OCPlatform.cpp +++ b/OCLib/OCPlatform.cpp @@ -90,9 +90,23 @@ namespace OC } } + OCResource::Ptr OCPlatform::constructResourceObject(const std::string& host, const std::string& uri, + bool isObservable, const std::vector& resourceTypes, + const std::vector& interfaces) + { + if(m_client) + { + return std::shared_ptr(new OCResource(m_client, host, uri, isObservable, resourceTypes, interfaces)); + } + + else + { + return std::shared_ptr(); + } + } OCStackResult OCPlatform::findResource(const std::string& host, const std::string& resourceName, - std::function resourceHandler) + std::function resourceHandler) { if(m_client) { diff --git a/include/OCPlatform.h b/include/OCPlatform.h index 9b9bbb6..e8cbf9f 100644 --- a/include/OCPlatform.h +++ b/include/OCPlatform.h @@ -226,7 +226,34 @@ namespace OC OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle, const std::string& resourceInterfaceName) const; - + /** + * Creates a resource proxy object so that get/put/observe functionality + * can be used without discovering the object in advance. Note that the + * consumer of this method needs to provide all of the details required to + * correctly contact and observe the object. If the consumer lacks any of + * this information, they should discover the resource object normally. + * Additionally, you can only create this object if OCPlatform was initialized + * to be a Client or Client/Server. Otherwise, this will return an empty + * shared ptr. + * + * @param host - a string containing a resolvable host address of the server + * holding the resource. Currently this should be in the format + * coap://address:port, though in the future, we expect this to + * change to //address:port + * + * @param uri - the rest of the resource's URI that will permit messages to be + * properly routed. Example: /a/light + * + * @param isObservable - a boolean containing whether the resource supports observation + * + * @param resourceTypes - a collection of resource types implemented by the resource + * + * @param interfaces - a collection of interfaces that the resource supports/implements + * @return OCResource::Ptr - a shared pointer to the new resource object + */ + OCResource::Ptr constructResourceObject(const std::string& host, const std::string& uri, + bool isObservable, const std::vector& resourceTypes, + const std::vector& interfaces); private: std::unique_ptr m_WrapperInstance; IServerWrapper::Ptr m_server; diff --git a/include/OCResource.h b/include/OCResource.h index d2b3796..5f3e8db 100644 --- a/include/OCResource.h +++ b/include/OCResource.h @@ -50,6 +50,7 @@ namespace OC */ class OCResource { + friend class OCPlatform; friend class InProcClientWrapper; public: typedef std::shared_ptr Ptr; -- 2.7.4