(1) add platform overload api : registerResource(resourcehandle, resource), (2) add...
authorjjack.lee <jjack.lee@samsung.com>
Mon, 10 Nov 2014 10:18:31 +0000 (19:18 +0900)
committerjjack.lee <jjack.lee@samsung.com>
Mon, 10 Nov 2014 10:18:31 +0000 (19:18 +0900)
Change-Id: I4809566e153eb3f488617adb7e044da869c1d88c

resource/csdk/stack/include/internal/ocstackinternal.h
resource/csdk/stack/include/ocstack.h
resource/csdk/stack/src/ocstack.c
resource/include/IServerWrapper.h
resource/include/InProcServerWrapper.h
resource/include/OCPlatform.h
resource/include/OCPlatform_impl.h
resource/include/OutOfProcServerWrapper.h
resource/src/InProcServerWrapper.cpp
resource/src/OCPlatform.cpp
resource/src/OCPlatform_impl.cpp

index 075b109..6169520 100644 (file)
@@ -118,6 +118,7 @@ typedef struct resourceinterface_t {
 typedef struct rsrc_t {
     struct rsrc_t *next; // Points to next resource in list
     // Relative path on the device; will be combined with base url to create fully qualified path
+    char *host;
     char *uri;
     OCResourceType *rsrcType; // Resource type(s); linked list
     OCResourceInterface *rsrcInterface; // Resource interface(s); linked list
index f1a04fd..b17ce8f 100644 (file)
@@ -479,6 +479,30 @@ OCStackResult OCCreateResource(OCResourceHandle *handle,
                                uint8_t resourceProperties);
 
 /**
+ * Create a resource. with host ip address for rsrc_t
+ *
+ * @param handle - pointer to handle to newly created resource.  Set by ocstack.  Used to refer to resource
+ * @param resourceTypeName - name of resource type.  Example: "core.led"
+ * @param resourceInterfaceName - name of resource interface.  Example: "core.rw"
+ * @param host - HOST address of the resource.  Example:  "coap://xxx.xxx.xxx.xxx:xxxxx"
+ * @param uri - URI of the resource.  Example:  "/a/led"
+ * @param entityHandler - entity handler function that is called by ocstack to handle requests, etc
+ *                        NULL for default entity handler
+ * @param resourceProperties - properties supported by resource.  Example: OC_DISCOVERABLE|OC_OBSERVABLE
+ *
+ * @return
+ *     OC_STACK_OK    - no errors
+ *     OC_STACK_ERROR - stack process error
+ */
+OCStackResult OCCreateResourceWithHost(OCResourceHandle *handle,
+                               const char *resourceTypeName,
+                               const char *resourceInterfaceName,
+                               const char *host,
+                               const char *uri,
+                               OCEntityHandler entityHandler,
+                               uint8_t resourceProperties);
+
+/**
  * Add a resource to a collection resource.
  *
  * @param collectionHandle - handle to the collection resource
index d1d9d84..c1dc1c4 100644 (file)
@@ -839,6 +839,55 @@ exit:
     return result;
 }
 
+
+
+/**
+ * Create a resource. with host ip address for rsrc_t
+ *
+ * @param handle - pointer to handle to newly created resource.  Set by ocstack.  Used to refer to resource
+ * @param resourceTypeName - name of resource type.  Example: "core.led"
+ * @param resourceInterfaceName - name of resource interface.  Example: "core.rw"
+ * @param host - HOST address of the resource.  Example:  "coap://xxx.xxx.xxx.xxx:xxxxx"
+ * @param uri - URI of the resource.  Example:  "/a/led"
+ * @param entityHandler - entity handler function that is called by ocstack to handle requests, etc
+ *                        NULL for default entity handler
+ * @param resourceProperties - properties supported by resource.  Example: OC_DISCOVERABLE|OC_OBSERVABLE
+ *
+ * @return
+ *     OC_STACK_OK    - no errors
+ *     OC_STACK_ERROR - stack process error
+ */
+
+OCStackResult OCCreateResourceWithHost(OCResourceHandle *handle,
+        const char *resourceTypeName,
+        const char *resourceInterfaceName,
+        const char *host,
+        const char *uri,
+        OCEntityHandler entityHandler,
+        uint8_t resourceProperties) {
+
+
+       char *str = NULL;
+       size_t size;
+       OCStackResult result = OC_STACK_ERROR;
+
+       result = OCCreateResource(handle,resourceTypeName,resourceInterfaceName,uri,entityHandler,resourceProperties);
+
+       if( result != OC_STACK_ERROR)
+       {
+               // Set the uri
+           size = strlen(host) + 1;
+           str = (char *) OCMalloc(size);
+           if (!str) {
+               return OC_STACK_ERROR;
+           }
+           strncpy(str, host, size);
+               ((OCResource *)*handle)->host = str;
+       }
+
+       return result;
+}
+
 /**
  * Add a resource to a collection resource.
  *
@@ -1157,7 +1206,7 @@ OCStackResult OCDeleteResource(OCResourceHandle handle) {
         OC_LOG(ERROR, TAG, PCF("Invalid param"));
         return OC_STACK_INVALID_PARAM;
     }
-    
+
     OCResource *resource = findResource((OCResource *) handle);
     if (resource == NULL) {
         OC_LOG(ERROR, TAG, PCF("Resource not found"));
index 2371ce5..e617302 100644 (file)
@@ -52,6 +52,17 @@ namespace OC
                     const std::string& resourceInterface,
                     EntityHandler& entityHandler,
                     uint8_t resourceProperty) = 0;
+
+
+               virtual OCStackResult registerResourceWithHost(
+                    OCResourceHandle& resourceHandle,
+                    std::string& resourceHOST,
+                    std::string& resourceURI,
+                    const std::string& resourceTypeName,
+                    const std::string& resourceInterface,
+                    EntityHandler& entityHandler,
+                    uint8_t resourceProperty) = 0;
+
         virtual OCStackResult unregisterResource(
                     const OCResourceHandle& resourceHandle) = 0;
         virtual OCStackResult bindTypeToResource(
index 654f10b..ca6eeea 100644 (file)
@@ -44,6 +44,15 @@ namespace OC
                     EntityHandler& entityHandler,
                     uint8_t resourceProperty);
 
+               virtual OCStackResult registerResourceWithHost(
+                    OCResourceHandle& resourceHandle,
+                    std::string& resourceHOST,
+                    std::string& resourceURI,
+                    const std::string& resourceTypeName,
+                    const std::string& resourceInterface,
+                    EntityHandler& entityHandler,
+                    uint8_t resourceProperty);
+
         virtual OCStackResult unregisterResource(
                     const OCResourceHandle& resourceHandle);
 
index 491f1ce..ac9495e 100644 (file)
@@ -154,6 +154,19 @@ namespace OC
                         uint8_t resourceProperty);
 
         /**
+        * This API registers a resource with the server
+        * NOTE: This API applies to server & client side.
+
+               * @param resourceHandle - Upon successful registration, resourceHandle will be filled
+               * @param resource - The resource that all data filled.
+               *
+               * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
+        */
+
+               OCStackResult registerResource(OCResourceHandle& resourceHandle,
+                                                                       const std::shared_ptr<OCResource> resource);
+
+        /**
         * Set default device entity handler
         *
         * @param entityHandler - entity handler to handle requests for
@@ -383,6 +396,9 @@ namespace OC
         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);
+
+
+
     }
 }
 
index 27e383b..823d4ff 100644 (file)
@@ -179,6 +179,19 @@ namespace OC
                         EntityHandler entityHandler,
                         uint8_t resourceProperty);
 
+               /**
+        * This API registers a resource with the server
+        * NOTE: This API applies to server & client side.
+
+               * @param resourceHandle - Upon successful registration, resourceHandle will be filled
+               * @param resource - The resource that all data filled.
+               *
+               * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
+        */
+
+               OCStackResult registerResource(OCResourceHandle& resourceHandle,
+                                                                       const std::shared_ptr<OCResource> resource);
+
         /**
         * Set default device entity handler
         *
index 0e7666e..5fc209e 100644 (file)
@@ -44,6 +44,17 @@ namespace OC
             // Not implemented
             return OC_STACK_NOTIMPL;
         }
+               virtual OCStackResult registerResourceWithHost(
+                    OCResourceHandle& resourceHandle,
+                    std::string& resourceHOST,
+                    std::string& resourceURI,
+                    const std::string& resourceTypeName,
+                    const std::string& resourceInterface,
+                    EntityHandler& entityHandler,
+                    uint8_t resourceProperty)
+               {
+                       return OC_STACK_NOTIMPL;
+               }
 
         virtual OCStackResult unregisterResource(
                      const OCResourceHandle& resourceHandle)
index 80a3d7f..90cdc7d 100644 (file)
@@ -388,6 +388,64 @@ namespace OC
         return result;
     }
 
+       OCStackResult InProcServerWrapper::registerResourceWithHost(
+                                               OCResourceHandle& resourceHandle,
+                                               std::string& resourceHOST,
+                                               std::string& resourceURI,
+                                               const std::string& resourceTypeName,
+                                               const std::string& resourceInterface,
+                                               EntityHandler& eHandler,
+                                               uint8_t resourceProperties)
+
+               {
+                       OCStackResult result = OC_STACK_ERROR;
+
+                       auto cLock = m_csdkLock.lock();
+
+                       if(cLock)
+                       {
+                               std::lock_guard<std::recursive_mutex> lock(*cLock);
+
+                               if(NULL != eHandler)
+                               {
+                                       result = OCCreateResourceWithHost(&resourceHandle, // OCResourceHandle *handle
+                                                               resourceTypeName.c_str(), // const char * resourceTypeName
+                                                               resourceInterface.c_str(), //const char * resourceInterfaceName //TODO fix this
+                                                               resourceHOST.c_str(), // const char * host
+                                                               resourceURI.c_str(), // const char * uri
+                                                               EntityHandlerWrapper, // OCEntityHandler entityHandler
+                                                               resourceProperties // uint8_t resourceProperties
+                                                               );
+                               }
+                               else
+                               {
+                                       result = OCCreateResourceWithHost(&resourceHandle, // OCResourceHandle *handle
+                                                               resourceTypeName.c_str(), // const char * resourceTypeName
+                                                               resourceInterface.c_str(), //const char * resourceInterfaceName //TODO fix this
+                                                               resourceHOST.c_str(), // const char * host
+                                                               resourceURI.c_str(), // const char * uri
+                                                               NULL, // OCEntityHandler entityHandler
+                                                               resourceProperties // uint8_t resourceProperties
+                                                               );
+                               }
+
+                               if(result != OC_STACK_OK)
+                               {
+                                       resourceHandle = (OCResourceHandle) 0;
+                               }
+                               else
+                               {
+                                       entityHandlerMap[resourceHandle] = eHandler;
+                                       resourceUriMap[resourceHandle] = resourceURI;
+                               }
+                       }
+                       else
+                       {
+                               result = OC_STACK_ERROR;
+                       }
+
+                       return result;
+               }
     OCStackResult InProcServerWrapper::setDefaultDeviceEntityHandler
                                         (EntityHandler entityHandler)
     {
index 6c7691e..441a413 100644 (file)
@@ -108,6 +108,12 @@ namespace OC
                                                 entityHandler, resourceProperty);
         }
 
+               OCStackResult registerResource(OCResourceHandle& resourceHandle,
+                                                                       const std::shared_ptr<OCResource> resource)
+        {
+            return OCPlatform_impl::Instance().registerResource(resourceHandle, resource);
+        }
+
         OCStackResult unregisterResource(const OCResourceHandle& resourceHandle)
         {
             return OCPlatform_impl::Instance().unregisterResource(resourceHandle);
index d41154c..36f909c 100644 (file)
@@ -185,6 +185,18 @@ namespace OC
                              resourceInterface, entityHandler, resourceProperty);
     }
 
+
+       OCStackResult OCPlatform_impl::registerResource(OCResourceHandle& resourceHandle,
+                                                                                                               const std::shared_ptr<OCResource> resource)
+       {
+               uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
+
+               return checked_guard(m_server, &IServerWrapper::registerResourceWithHost,
+                                                  ref(resourceHandle), resource->host(), resource->uri(), "core.remote",
+                                                  "oc.mi.def", (EntityHandler) NULL, resourceProperty);
+
+
+       }
     OCStackResult OCPlatform_impl::unregisterResource(const OCResourceHandle& resourceHandle) const
     {
         return checked_guard(m_server, &IServerWrapper::unregisterResource,