Added URI parameter for Device Entity Handler.
authorSashi Penta <sashi.kumar.penta@intel.com>
Tue, 30 Sep 2014 07:35:52 +0000 (00:35 -0700)
committerSashi Penta <sashi.kumar.penta@intel.com>
Tue, 30 Sep 2014 21:43:34 +0000 (14:43 -0700)
Change-Id: If37e64f6578b6a8eccee9b9ea43690123d6ac2aa

csdk/stack/include/internal/ocstackinternal.h
csdk/stack/include/ocstack.h
csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp
csdk/stack/src/ocresource.c
csdk/stack/src/ocstack.c
examples/fridgeserver.cpp
include/OCApi.h
include/OCResourceRequest.h
include/OutOfProcServerWrapper.h
src/InProcServerWrapper.cpp

index 91b493b..075b109 100644 (file)
@@ -43,7 +43,7 @@ extern "C" {
 //-----------------------------------------------------------------------------
 // Global variables
 //-----------------------------------------------------------------------------
-extern OCEntityHandler defaultDeviceHandler;
+extern OCDeviceEntityHandler defaultDeviceHandler;
 
 //-----------------------------------------------------------------------------
 // Defines
index e6e8b3b..80a5d4d 100644 (file)
@@ -262,6 +262,11 @@ typedef enum {
 typedef OCEntityHandlerResult (*OCEntityHandler)
 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest);
 
+/**
+ * Device Entity handler need to use this call back instead of OCEntityHandler
+ */
+typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
+(OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri);
 
 //-----------------------------------------------------------------------------
 // Function prototypes
@@ -377,7 +382,7 @@ OCStackResult OCStopPresence();
  *     OC_STACK_OK    - no errors
  *     OC_STACK_ERROR - stack process error
  */
-OCStackResult OCSetDefaultDeviceEntityHandler(OCEntityHandler entityHandler);
+OCStackResult OCSetDefaultDeviceEntityHandler(OCDeviceEntityHandler entityHandler);
 
 /**
  * Create a resource.
index 2e3ae24..27fd71c 100644 (file)
@@ -129,11 +129,11 @@ void ProcessObserveDeregister (OCEntityHandlerRequest *ehRequest)
 }
 OCEntityHandlerResult
 OCDeviceEntityHandlerCb (OCEntityHandlerFlag flag,
-                   OCEntityHandlerRequest *entityHandlerRequest)
+                   OCEntityHandlerRequest *entityHandlerRequest, char* uri)
 {
     const char* typeOfMessage;
 
-    OC_LOG_V (INFO, TAG, "Inside device default entity handler - flags: 0x%x", flag);
+    OC_LOG_V (INFO, TAG, "Inside device default entity handler - flags: 0x%x, uri: %s", flag, uri);
     if (flag & OC_INIT_FLAG)
     {
         OC_LOG (INFO, TAG, "Flag includes OC_INIT_FLAG");
index 73300a8..763f20d 100644 (file)
@@ -412,7 +412,7 @@ HandleDefaultDeviceEntityHandler (OCRequest *request)
     OCEntityHandlerRequest *ehRequest = request->entityHandlerRequest;
 
     // At this point we know for sure that defaultDeviceHandler exists
-    defaultDeviceHandler(OC_REQUEST_FLAG, ehRequest);
+    defaultDeviceHandler(OC_REQUEST_FLAG, ehRequest, (char*) request->resourceUrl);
 
     ehRequest->resJSONPayloadLen = ehRequest->resJSONPayloadLen -
                                     strlen((char*)ehRequest->resJSONPayload);
index b444814..9bc3a3c 100644 (file)
@@ -59,7 +59,7 @@ uint32_t PresenceTimeOut[] = {50, 75, 85, 95, 100};
 #endif
 
 OCMode myStackMode;
-OCEntityHandler defaultDeviceHandler;
+OCDeviceEntityHandler defaultDeviceHandler;
 
 //-----------------------------------------------------------------------------
 // Macros
@@ -638,7 +638,7 @@ OCStackResult OCStopPresence()
 #endif
 
 
-OCStackResult OCSetDefaultDeviceEntityHandler(OCEntityHandler entityHandler)
+OCStackResult OCSetDefaultDeviceEntityHandler(OCDeviceEntityHandler entityHandler)
 {
     defaultDeviceHandler = entityHandler;
 
index 18287b1..9c0d3b3 100644 (file)
@@ -117,6 +117,9 @@ class DeviceResource : public Resource
     {
         if(request)
         {
+            std::cout << "In Default Entity Handler, uri received: "
+                        << request->getResourceUri() << std::endl;
+
             if(request->getRequestHandlerFlag() == RequestHandlerFlag::RequestFlag)
             {
                 if(request->getRequestType() == "GET")
index 1c8c2a2..3a1300f 100644 (file)
@@ -612,7 +612,8 @@ namespace OC
     const std::string BATCH_INTERFACE = "oc.mi.b";
 
     typedef std::function<void(std::shared_ptr<OCResource>)> FindCallback;
-    typedef std::function<void(const std::shared_ptr<OCResourceRequest>, const std::shared_ptr<OCResourceResponse>)> EntityHandler;
+    typedef std::function<void(const std::shared_ptr<OCResourceRequest>,
+                                const std::shared_ptr<OCResourceResponse>)> EntityHandler;
     typedef std::function<void(OCStackResult, const unsigned int)> SubscribeCallback;
     typedef std::function<void(const OCRepresentation&, const int)> GetCallback;
     typedef std::function<void(const OCRepresentation&, const int)> PutCallback;
index d922e24..f556246 100644 (file)
@@ -62,14 +62,14 @@ namespace OC
         const QueryParamsMap& getQueryParameters() const {return m_queryParameters;}
 
         /**
-        *  Retrieves the request handler flag type. This can be either INIT flag or 
+        *  Retrieves the request handler flag type. This can be either INIT flag or
         *  REQUEST flag or OBSERVE flag.
         *  NOTE:
-        *  INIT indicates that the vendor's entity handler should go and perform 
+        *  INIT indicates that the vendor's entity handler should go and perform
         *  initialization operations
-        *  REQUEST indicates that it is a request of certain type (GET/PUT/POST/DELETE) 
+        *  REQUEST indicates that it is a request of certain type (GET/PUT/POST/DELETE)
         *  and entity handler needs to perform corresponding operations
-        *  OBSERVE indicates that the request is of type Observe and entity handler 
+        *  OBSERVE indicates that the request is of type Observe and entity handler
         *  needs to perform corresponding operations
         *  @return int type of request flag
         */
@@ -82,13 +82,32 @@ namespace OC
         const OCRepresentation& getResourceRepresentation() const {return m_representation;}
 
         /**
-        *  Provides the entire resource representation
-        *  @return OCRepresentation reference which provides entire resource information
+        *  @return ObservationInfo reference provides observation information
         */
         const ObservationInfo& getObservationInfo() const {return m_observationInfo;}
 
+        /**
+        *  sets resource uri
+        *  @param resourceUri specifies the resource uri
+        */
+        void setResourceUri(const std::string resourceUri)
+        {
+            m_resourceUri = resourceUri;
+        }
+
+        /**
+        *  gets resource uri
+        *  @return std::string resource uri
+        */
+        std::string getResourceUri(void)
+        {
+            return m_resourceUri;
+        }
+
+
     private:
         std::string m_requestType;
+        std::string m_resourceUri;
         QueryParamsMap m_queryParameters;
         int m_requestHandlerFlag;
         OCRepresentation m_representation;
index 9de3401..a3bf64d 100644 (file)
@@ -28,7 +28,7 @@ namespace OC
     class OutOfProcServerWrapper : public IServerWrapper
     {
     public:
-        OutOfProcServerWrapper(OC::OCPlatform& owner, PlatformConfig cfg) 
+        OutOfProcServerWrapper(OC::OCPlatform& owner, PlatformConfig cfg)
          : IServerWrapper(owner)
         {};
 
index 3d2e511..f2333e7 100644 (file)
@@ -132,7 +132,8 @@ void processResourceResponse(OCEntityHandlerFlag flag,
 }
 
 OCEntityHandlerResult DefaultEntityHandlerWrapper(OCEntityHandlerFlag flag,
-                                                  OCEntityHandlerRequest * entityHandlerRequest)
+                                                  OCEntityHandlerRequest * entityHandlerRequest,
+                                                  char* uri)
 {
     // TODO we need to have a better way of logging (with various levels of logging)
     std::clog << "\nIn Default device entity handler wrapper: " << endl;
@@ -148,6 +149,10 @@ OCEntityHandlerResult DefaultEntityHandlerWrapper(OCEntityHandlerFlag flag,
 
     formResourceRequest(flag, entityHandlerRequest, pRequest);
 
+    // TODO : This is currently being done only for Device entity handler
+    //        we will need to do the similar things for regular entity handler
+    pRequest->setResourceUri(std::string(uri));
+
     if(defaultDeviceEntityHandler)
     {
         defaultDeviceEntityHandler(pRequest, pResponse);
@@ -316,7 +321,8 @@ namespace OC
         return result;
     }
 
-    OCStackResult InProcServerWrapper::setDefaultDeviceEntityHandler(EntityHandler entityHandler)
+    OCStackResult InProcServerWrapper::setDefaultDeviceEntityHandler
+                                        (EntityHandler entityHandler)
     {
         OCStackResult result = OC_STACK_ERROR;