US1313, abillity to create an OCResource object without discovering it
authorErich Keane <erich.keane@intel.com>
Tue, 12 Aug 2014 17:53:04 +0000 (10:53 -0700)
committerGerrit Code Review <gerrit@fmygit6001.fm.intel.com>
Tue, 12 Aug 2014 20:34:11 +0000 (13:34 -0700)
Change-Id: Ie283435901a6438c4695496c79cca15e248273a2

OCLib/OCPlatform.cpp
include/OCPlatform.h
include/OCResource.h

index 2321211..1394149 100644 (file)
@@ -90,9 +90,23 @@ namespace OC
         }
     }
 
+    OCResource::Ptr OCPlatform::constructResourceObject(const std::string& host, const std::string& uri,
+                bool isObservable, const std::vector<std::string>& resourceTypes,
+                const std::vector<std::string>& interfaces)
+    {
+        if(m_client)
+        {
+            return std::shared_ptr<OCResource>(new OCResource(m_client, host, uri, isObservable, resourceTypes, interfaces));
+        }
+
+        else
+        {
+            return std::shared_ptr<OCResource>();
+        }
+    }
 
     OCStackResult OCPlatform::findResource(const std::string& host, const std::string& resourceName,
-        std::function<void(OCResource::Ptr)> resourceHandler)
+                std::function<void(OCResource::Ptr)> resourceHandler)
     {
         if(m_client)
         {
index 9b9bbb6..e8cbf9f 100644 (file)
@@ -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<std::string>& resourceTypes,
+                        const std::vector<std::string>& interfaces);
     private:
         std::unique_ptr<WrapperFactory> m_WrapperInstance;
         IServerWrapper::Ptr m_server;
index d2b3796..5f3e8db 100644 (file)
@@ -50,6 +50,7 @@ namespace OC
     */
     class OCResource
     {
+    friend class OCPlatform;
     friend class InProcClientWrapper;
     public:
         typedef std::shared_ptr<OCResource> Ptr;