GET for CPP/Client
authorSashi Penta <sashi.kumar.penta@intel.com>
Wed, 20 Aug 2014 01:49:02 +0000 (18:49 -0700)
committerSashi Penta <sashi.kumar.penta@intel.com>
Wed, 20 Aug 2014 02:01:33 +0000 (19:01 -0700)
Change-Id: I1a6b9a087bec196387b4a8ab11f153451af54961

OCLib/InProcClientWrapper.cpp
OCLib/OCResource.cpp
examples/roomclient.cpp
examples/simpleclient.cpp
include/IClientWrapper.h
include/InProcClientWrapper.h
include/OCApi.h
include/OCRepresentation.h
include/OCResource.h
include/OutOfProcClientWrapper.h
makefile

index 305294a..c82bfa8 100644 (file)
@@ -117,6 +117,7 @@ namespace OC
     const std::string RESOURCETYPESKEY= "rt";
     const std::string INTERFACESKEY = "if";
     const std::string PROPERTYKEY = "prop";
+    const std::string REPKEY = "rep";
 
     std::shared_ptr<OCResource> InProcClientWrapper::parseOCResource(IClientWrapper::Ptr clientWrapper, const std::string& host, const boost::property_tree::ptree resourceNode)
     {
@@ -218,57 +219,128 @@ namespace OC
    
     struct GetSetContext
     {
-        std::function<void(const AttributeMap&, const int&)> callback;
+        std::function<void(const OCRepresentation&, const int&)> callback;
     };
-    
-    AttributeMap parseGetSetCallback(OCClientResponse* clientResponse)
+   
+        
+    OCRepresentation parseGetSetCallback(OCClientResponse* clientResponse)
     {
         std::stringstream requestStream;
         requestStream<<clientResponse->resJSONPayload;
         if(strlen((char*)clientResponse->resJSONPayload) == 0)
         {
-            return AttributeMap();
+            return OCRepresentation();
         }
 
         boost::property_tree::ptree root;
         boost::property_tree::read_json(requestStream, root);
-        boost::property_tree::ptree payload = root.get_child("oc.payload", boost::property_tree::ptree());
-        
-        AttributeMap attrs;
-        for(auto& item : payload)
-        {
-            if(item.first.data() == URIKEY)
+        boost::property_tree::ptree payload = root.get_child("oc", boost::property_tree::ptree());
+        OCRepresentation root_resource;
+        std::vector<OCRepresentation> children;
+        bool isRoot = true;
+        for ( auto payloadItr : payload)
+        {
+            OCRepresentation child;
+            try
             {
-                continue;
+                auto resourceNode = payloadItr.second;
+                std::string uri = resourceNode.get<std::string>(URIKEY, "");
+
+                if (isRoot)
+                {
+                    root_resource.setUri(uri);
+                }
+                else
+                {
+                    child.setUri(uri);
+                }
+
+                if( resourceNode.count(PROPERTYKEY) != 0 )
+                {
+                    std::vector<std::string> rTs;
+                    std::vector<std::string> ifaces;
+                    boost::property_tree::ptree properties = resourceNode.get_child(PROPERTYKEY, boost::property_tree::ptree());
+
+                    boost::property_tree::ptree rT = properties.get_child(RESOURCETYPESKEY, boost::property_tree::ptree());
+                    for(auto itr : rT)
+                    {
+                        rTs.push_back(itr.second.data());
+                    }
+
+                    boost::property_tree::ptree iF = properties.get_child(INTERFACESKEY, boost::property_tree::ptree());
+                    for(auto itr : iF)
+                    {
+                        ifaces.push_back(itr.second.data());
+                    }
+                    if (isRoot)
+                    {
+                        root_resource.setResourceInterfaces(ifaces);
+                        root_resource.setResourceTypes(rTs);
+                    }
+                    else
+                    {
+                        child.setResourceInterfaces(ifaces);
+                        child.setResourceTypes(rTs);
+                    }
+                }
+
+                if( resourceNode.count(REPKEY) != 0 )
+                {
+                    boost::property_tree::ptree rep = resourceNode.get_child(REPKEY, boost::property_tree::ptree());
+                    AttributeMap attrs;
+                    for( auto item : rep)
+                    {
+                        std::string name = item.first.data();
+                        std::string value = item.second.data();
+                        AttributeValues values;
+                        values.push_back(value);
+                        attrs[name] = values;
+                    }
+                    if (isRoot)
+                    {
+                        root_resource.setAttributeMap(attrs);
+                    }
+                    else
+                    {
+                        child.setAttributeMap(attrs);
+                    }
+                }
+
+                if (!isRoot)
+                    children.push_back(child);
+            }
+            catch (...)
+            {
+                // TODO
             }
 
-            std::string name = item.first.data();
-            std::string value = item.second.data();
-            AttributeValues values;
-            values.push_back(value);
-            attrs[name] = values;
-        }
-        return attrs;
+            isRoot = false;
+         }
+
+         root_resource.setChildren(children);
+
+        return root_resource;
     }
+
     OCStackApplicationResult getResourceCallback(void* ctx, OCDoHandle handle, OCClientResponse* clientResponse)
     {
         GetSetContext* context = static_cast<GetSetContext*>(ctx);
 
         std::cout << "GET JSON: " << (char*) clientResponse->resJSONPayload << endl;
         
-        AttributeMap attrs;
+        OCRepresentation rep;
 
         if(clientResponse->result == OC_STACK_OK)
         {
-            attrs = parseGetSetCallback(clientResponse);
+            rep = parseGetSetCallback(clientResponse);
         }        
 
-        std::thread exec(context->callback, attrs, clientResponse->result);
+        std::thread exec(context->callback, rep, clientResponse->result);
         exec.detach();
         return OC_STACK_DELETE_TRANSACTION;
     }
     OCStackResult InProcClientWrapper::GetResourceAttributes(const std::string& host, const std::string& uri, 
-        const QueryParamsMap& queryParams, std::function<void(const AttributeMap, const int)>& callback)
+        const QueryParamsMap& queryParams, std::function<void(const OCRepresentation, const int)>& callback)
     {
         OCStackResult result;
         OCCallbackData* cbdata = new OCCallbackData();
@@ -302,7 +374,7 @@ namespace OC
     OCStackApplicationResult setResourceCallback(void* ctx, OCDoHandle handle, OCClientResponse* clientResponse)
     {
         GetSetContext* context = static_cast<GetSetContext*>(ctx);
-        AttributeMap attrs;
+        OCRepresentation attrs;
 
         if(clientResponse->result == OC_STACK_OK)
         {
@@ -341,8 +413,10 @@ namespace OC
         return ret;
     }
     
-    std::string InProcClientWrapper::assembleSetResourcePayload(const AttributeMap& attributes)
+    std::string InProcClientWrapper::assembleSetResourcePayload(const OCRepresentation& rep)
     {
+        AttributeMap attributes = rep.getAttributeMap();
+
         ostringstream payload;
         // TODO need to change the format to "{"oc":[]}"
         payload << "{\"oc\":{";
@@ -360,7 +434,7 @@ namespace OC
         return payload.str();
     }
 
-    OCStackResult InProcClientWrapper::SetResourceAttributes(const std::string& host, const std::string& uri, const AttributeMap& attributes, const QueryParamsMap& queryParams, std::function<void(const AttributeMap,const int)>& callback)
+    OCStackResult InProcClientWrapper::SetResourceAttributes(const std::string& host, const std::string& uri, const OCRepresentation& attributes, const QueryParamsMap& queryParams, std::function<void(const OCRepresentation,const int)>& callback)
     {
         OCStackResult result; 
         OCCallbackData* cbdata = new OCCallbackData();
@@ -394,13 +468,13 @@ namespace OC
 
     struct ObserveContext
     {
-        std::function<void(const AttributeMap&, const int&, const int&)> callback;
+        std::function<void(const OCRepresentation&, const int&, const int&)> callback;
     };
 
     OCStackApplicationResult observeResourceCallback(void* ctx, OCDoHandle handle, OCClientResponse* clientResponse)
     {
         ObserveContext* context = static_cast<ObserveContext*>(ctx);
-        AttributeMap attrs;
+        OCRepresentation attrs;
         uint32_t sequenceNumber = clientResponse->sequenceNumber;
         if(clientResponse->result == OC_STACK_OK)
         {
@@ -412,7 +486,7 @@ namespace OC
     }
 
     OCStackResult InProcClientWrapper::ObserveResource(ObserveType observeType, OCDoHandle* handle, const std::string& host, 
-       const std::string& uri, const QueryParamsMap& queryParams, std::function<void(const AttributeMap&, const int&, const int&)>& callback)
+       const std::string& uri, const QueryParamsMap& queryParams, std::function<void(const OCRepresentation&, const int&, const int&)>& callback)
     {
         OCStackResult result;
         OCCallbackData* cbdata = new OCCallbackData();
@@ -468,6 +542,7 @@ namespace OC
         exec.detach();
         return OC_STACK_DELETE_TRANSACTION;
     }
+
     OCStackResult InProcClientWrapper::CancelObserveResource(OCDoHandle handle, const std::string& host, const std::string& uri)
     {
         OCStackResult result;
index 2221839..43728d7 100644 (file)
@@ -37,7 +37,7 @@ namespace OC {
     {
     }
 
-    OCStackResult OCResource::get(const QueryParamsMap& queryParametersMap, std::function<void(const AttributeMap, const int)> attributeHandler)
+    OCStackResult OCResource::get(const QueryParamsMap& queryParametersMap, std::function<void(const OCRepresentation, const int)> attributeHandler)
     {
         auto cw = m_clientWrapper.lock();
 
@@ -51,14 +51,14 @@ namespace OC {
         }
     }
 
-    OCStackResult OCResource::put(const AttributeMap& attributeMap, const QueryParamsMap& queryParametersMap, 
-        std::function<void(const AttributeMap, const int)> attributeHandler)
+    OCStackResult OCResource::put(const OCRepresentation& rep, const QueryParamsMap& queryParametersMap, 
+        std::function<void(const OCRepresentation, const int)> attributeHandler)
     {
         auto cw = m_clientWrapper.lock();
 
         if(cw)
         {
-            return cw->SetResourceAttributes(m_host, m_uri, attributeMap, queryParametersMap, attributeHandler);
+            return cw->SetResourceAttributes(m_host, m_uri, rep, queryParametersMap, attributeHandler);
         }
         else
         {
@@ -67,7 +67,7 @@ namespace OC {
     }
 
     OCStackResult OCResource::observe(ObserveType observeType, const QueryParamsMap& queryParametersMap, 
-        std::function<void(const AttributeMap&, const int&, const int&)> observeHandler)
+        std::function<void(const OCRepresentation&, const int&, const int&)> observeHandler)
     {
         if(m_observeHandle != nullptr)
         {
index 8f527ac..7fb0eb2 100644 (file)
@@ -37,48 +37,20 @@ int observe_count()
     return ++oc;
 }
 
-void onObserve(const AttributeMap& attributeMap, const int& eCode, const int& sequenceNumber)
-{
-    if(eCode == SUCCESS_RESPONSE)
-    {
-        std::cout << "OBSERVE RESULT:"<<std::endl;
-        std::cout << "\tSequenceNumber: "<< sequenceNumber << endl;
-        for(auto it = attributeMap.begin(); it != attributeMap.end(); ++it)
-        {
-            std::cout << "\tAttribute name: "<< it->first << " value: ";
-            for(auto valueItr = it->second.begin(); valueItr != it->second.end(); ++valueItr)
-            {
-                std::cout <<"\t"<< *valueItr << " ";
-            }
-
-            std::cout << std::endl;
-        }
-        
-        if(observe_count() > 30)
-        {
-            std::cout<<"Cancelling Observe..."<<std::endl;
-            OCStackResult result = curResource->cancelObserve();
+// Forward declaration
+void putRoomRepresentation(std::shared_ptr<OCResource> resource);
+void onPut(const OCRepresentation& rep, const int eCode);
 
-            std::cout << "Cancel result: "<< result <<std::endl;
-            sleep(10);
-            std::cout << "DONE"<<std::endl;
-            std::exit(0);
-        }
-    }
-    else
-    {
-        std::cout << "onObserve Response error: " << eCode << std::endl;
-        std::exit(-1);
-    }
-}
-// callback handler on PUT request
-void onGetRep(OCRepresentation& rep, const int eCode)
+// callback handler on GET request
+void onGet(const OCRepresentation& rep, const int eCode)
 {
     if(eCode == SUCCESS_RESPONSE)
     {
         std::cout << "GET request was successful" << std::endl;
 
         AttributeMap attributeMap = rep.getAttributeMap();
+        
+        std::cout << "Resource URI: " << rep.getUri() << std::endl;
 
         for(auto it = attributeMap.begin(); it != attributeMap.end(); ++it)
         {
@@ -95,52 +67,8 @@ void onGetRep(OCRepresentation& rep, const int eCode)
 
         for(auto oit = children.begin(); oit != children.end(); ++oit)
         {
-            attributeMap = oit->getAttributeMap();
+            std::cout << "Child Resource URI: " << oit->getUri() << std::endl;
 
-            for(auto it = attributeMap.begin(); it != attributeMap.end(); ++it)
-            {
-                std::cout << "\tAttribute name: "<< it->first << " value: ";
-                for(auto valueItr = it->second.begin(); valueItr != it->second.end(); ++valueItr)
-                {
-                    std::cout <<"\t"<< *valueItr << " ";
-                }
-
-                std::cout << std::endl;
-            }
-        }
-
-    }
-    else
-    {
-        std::cout << "onGET Response error: " << eCode << std::endl;
-        std::exit(-1);
-    }
-}
-
-// callback handler on PUT request
-void onPutRep(OCRepresentation& rep, const int eCode)
-{
-    if(eCode == SUCCESS_RESPONSE)
-    {
-        std::cout << "PUT request was successful" << std::endl;
-
-        AttributeMap attributeMap = rep.getAttributeMap();
-
-        for(auto it = attributeMap.begin(); it != attributeMap.end(); ++it)
-        {
-            std::cout << "\tAttribute name: "<< it->first << " value: ";
-            for(auto valueItr = it->second.begin(); valueItr != it->second.end(); ++valueItr)
-            {
-                std::cout <<"\t"<< *valueItr << " ";
-            }
-
-            std::cout << std::endl;
-        }
-
-        std::vector<OCRepresentation> children = rep.getChildren();
-
-        for(auto oit = children.begin(); oit != children.end(); ++oit)
-        {
             attributeMap = oit->getAttributeMap();
 
             for(auto it = attributeMap.begin(); it != attributeMap.end(); ++it)
@@ -155,35 +83,11 @@ void onPutRep(OCRepresentation& rep, const int eCode)
             }
         }
 
+        putRoomRepresentation(curResource);
     }
     else
     {
-        std::cout << "onPut Response error: " << eCode << std::endl;
-        std::exit(-1);
-    }
-}
-
-// callback handler on PUT request
-void onPut(const AttributeMap attributeMap, const int eCode)
-{
-    if(eCode == SUCCESS_RESPONSE)
-    {
-        std::cout << "PUT request was successful" << std::endl;
-
-        for(auto it = attributeMap.begin(); it != attributeMap.end(); ++it)
-        {
-            std::cout << "\tAttribute name: "<< it->first << " value: ";
-            for(auto valueItr = it->second.begin(); valueItr != it->second.end(); ++valueItr)
-            {
-                std::cout <<"\t"<< *valueItr << " ";
-            }
-
-            std::cout << std::endl;
-        }
-    }
-    else
-    {
-        std::cout << "onPut Response error: " << eCode << std::endl;
+        std::cout << "onGET Response error: " << eCode << std::endl;
         std::exit(-1);
     }
 }
@@ -193,6 +97,7 @@ void putRoomRepresentation(std::shared_ptr<OCResource> resource)
 {
     if(resource)
     {
+        OCRepresentation rep;
         std::cout << "Putting room representation..."<<std::endl;
         // Create AttributeMap
         AttributeMap attributeMap;
@@ -210,17 +115,22 @@ void putRoomRepresentation(std::shared_ptr<OCResource> resource)
         QueryParamsMap qp;
         qp["if"] = BATCH_INTERFACE;
 
+        rep.setAttributeMap(attributeMap);
+
         // Invoke resource's pit API with attribute map, query map and the callback parameter
-        resource->put(attributeMap, qp, &onPut);
+        resource->put(rep, qp, &onPut);
     }
 }
 
-// callback handler on GET request
-void onGet(const AttributeMap attributeMap, const int eCode)
+// callback handler on PUT request
+void onPut(const OCRepresentation& rep, const int eCode)
 {
     if(eCode == SUCCESS_RESPONSE)
     {
-        std::cout << "GET Succeeded:"<<std::endl;
+        std::cout << "PUT request was successful" << std::endl;
+
+        AttributeMap attributeMap = rep.getAttributeMap();
+
         for(auto it = attributeMap.begin(); it != attributeMap.end(); ++it)
         {
             std::cout << "\tAttribute name: "<< it->first << " value: ";
@@ -232,14 +142,33 @@ void onGet(const AttributeMap attributeMap, const int eCode)
             std::cout << std::endl;
         }
 
-        putRoomRepresentation(curResource);
+        std::vector<OCRepresentation> children = rep.getChildren();
+
+        for(auto oit = children.begin(); oit != children.end(); ++oit)
+        {
+            attributeMap = oit->getAttributeMap();
+
+            for(auto it = attributeMap.begin(); it != attributeMap.end(); ++it)
+            {
+                std::cout << "\tAttribute name: "<< it->first << " value: ";
+                for(auto valueItr = it->second.begin(); valueItr != it->second.end(); ++valueItr)
+                {
+                    std::cout <<"\t"<< *valueItr << " ";
+                }
+
+                std::cout << std::endl;
+            }
+        }
+
     }
     else
     {
-        std::cout << "onGet Response error: " << eCode << std::endl;
+        std::cout << "onPut Response error: " << eCode << std::endl;
         std::exit(-1);
     }
 }
+
+
 // Local function to get representation of light resource
 void getRoomRepresentation(std::shared_ptr<OCResource> resource)
 {
@@ -283,9 +212,7 @@ void foundResource(std::shared_ptr<OCResource> resource)
             {
                 curResource = resource;
                 // Call a local function which will internally invoke get API on the resource pointer
-                // TODO change this back when getRoomRepresentation works
                 getRoomRepresentation(resource);
-                 //putRoomRepresentation(resource);
             }
         }
         else
index 3f7f258..f525e44 100644 (file)
@@ -74,12 +74,14 @@ void onObserve(const AttributeMap& attributeMap, const int& eCode, const int& se
 }
 
 // callback handler on PUT request
-void onPut(const AttributeMap attributeMap, const int eCode)
+void onPut(const OCRepresentation& rep, const int eCode)
 {
     if(eCode == SUCCESS_RESPONSE)
     {
         std::cout << "PUT request was successful" << std::endl;
 
+        AttributeMap attributeMap = rep.getAttributeMap();
+
         for(auto it = attributeMap.begin(); it != attributeMap.end(); ++it)
         {
             std::cout << "\tAttribute name: "<< it->first << " value: ";
@@ -91,15 +93,23 @@ void onPut(const AttributeMap attributeMap, const int eCode)
             std::cout << std::endl;
         }
 
-        if (OBSERVE_TYPE_TO_USE == ObserveType::Observe)
-            std::cout << endl << "Observe is used." << endl << endl;
-        else if (OBSERVE_TYPE_TO_USE == ObserveType::ObserveAll)
-            std::cout << endl << "ObserveAll is used." << endl << endl;
+        std::vector<OCRepresentation> children = rep.getChildren();
 
-        // TODO
-        QueryParamsMap test;
+        for(auto oit = children.begin(); oit != children.end(); ++oit)
+        {
+            attributeMap = oit->getAttributeMap();
 
-        curResource->observe(OBSERVE_TYPE_TO_USE, test, &onObserve);
+            for(auto it = attributeMap.begin(); it != attributeMap.end(); ++it)
+            {
+                std::cout << "\tAttribute name: "<< it->first << " value: ";
+                for(auto valueItr = it->second.begin(); valueItr != it->second.end(); ++valueItr)
+                {
+                    std::cout <<"\t"<< *valueItr << " ";
+                }
+
+                std::cout << std::endl;
+            }
+        }
 
     }
     else
@@ -114,6 +124,8 @@ void putLightRepresentation(std::shared_ptr<OCResource> resource)
 {
     if(resource)
     {
+        OCRepresentation rep;
+        
         std::cout << "Putting light representation..."<<std::endl;
         // Create AttributeMap
         AttributeMap attributeMap;
@@ -130,17 +142,24 @@ void putLightRepresentation(std::shared_ptr<OCResource> resource)
         // Create QueryParameters Map and add query params (if any)
         QueryParamsMap queryParamsMap;
 
+        rep.setAttributeMap(attributeMap);
+
         // Invoke resource's pit API with attribute map, query map and the callback parameter
-        resource->put(attributeMap, queryParamsMap, &onPut);
+        resource->put(rep, queryParamsMap, &onPut);
     }
 }
 
 // callback handler on GET request
-void onGet(const AttributeMap attributeMap, const int eCode)
+void onGet(const OCRepresentation& rep, const int eCode)
 {
     if(eCode == SUCCESS_RESPONSE)
     {
-        std::cout << "GET Succeeded:"<<std::endl;
+        std::cout << "GET request was successful" << std::endl;
+
+        AttributeMap attributeMap = rep.getAttributeMap();
+        
+        std::cout << "Resource URI: " << rep.getUri() << std::endl;
+
         for(auto it = attributeMap.begin(); it != attributeMap.end(); ++it)
         {
             std::cout << "\tAttribute name: "<< it->first << " value: ";
@@ -152,14 +171,35 @@ void onGet(const AttributeMap attributeMap, const int eCode)
             std::cout << std::endl;
         }
 
+        std::vector<OCRepresentation> children = rep.getChildren();
+
+        for(auto oit = children.begin(); oit != children.end(); ++oit)
+        {
+            std::cout << "Child Resource URI: " << oit->getUri() << std::endl;
+
+            attributeMap = oit->getAttributeMap();
+
+            for(auto it = attributeMap.begin(); it != attributeMap.end(); ++it)
+            {
+                std::cout << "\tAttribute name: "<< it->first << " value: ";
+                for(auto valueItr = it->second.begin(); valueItr != it->second.end(); ++valueItr)
+                {
+                    std::cout <<"\t"<< *valueItr << " ";
+                }
+
+                std::cout << std::endl;
+            }
+        }
+
         putLightRepresentation(curResource);
     }
     else
     {
-        std::cout << "onGet Response error: " << eCode << std::endl;
+        std::cout << "onGET Response error: " << eCode << std::endl;
         std::exit(-1);
     }
 }
+
 // Local function to get representation of light resource
 void getLightRepresentation(std::shared_ptr<OCResource> resource)
 {
index f7425cf..b675184 100644 (file)
@@ -25,6 +25,7 @@
 #include <string>
 
 #include <OCApi.h>
+
 namespace OC
 {
     class IClientWrapper : public std::enable_shared_from_this<IClientWrapper>
@@ -36,14 +37,14 @@ namespace OC
             std::function<void(std::shared_ptr<OCResource>)>& callback) = 0;
         
         virtual OCStackResult GetResourceAttributes(const std::string& host, const std::string& uri, const QueryParamsMap& queryParams, 
-            std::function<void(const AttributeMap, const int)>& callback)=0;
-        
-        virtual OCStackResult SetResourceAttributes(const std::string& host, const std::string& uri, const AttributeMap& attributes, 
-            const QueryParamsMap& queryParams, std::function<void(const AttributeMap,const int)>& callback)=0;
+            std::function<void(const OCRepresentation, const int)>& callback)=0;
+
+        virtual OCStackResult SetResourceAttributes(const std::string& host, const std::string& uri, const OCRepresentation& attributes, 
+            const QueryParamsMap& queryParams, std::function<void(const OCRepresentation, const int)>& callback) = 0;
 
         virtual OCStackResult ObserveResource(ObserveType observeType, OCDoHandle* handle, 
             const std::string& host, const std::string& uri, const QueryParamsMap& queryParams, 
-            std::function<void(const AttributeMap&, const int&, const int&)>& callback)=0;
+            std::function<void(const OCRepresentation&, const int&, const int&)>& callback)=0;
         
         virtual OCStackResult CancelObserveResource(OCDoHandle handle, const std::string& host, const std::string& uri)=0;
         
index c71ea30..28a5e66 100644 (file)
@@ -48,14 +48,14 @@ namespace OC
             std::function<void(std::shared_ptr<OCResource>)>& callback);
         
         virtual OCStackResult GetResourceAttributes(const std::string& host, const std::string& uri, const QueryParamsMap& queryParams, 
-            std::function<void(const AttributeMap, const int)>& callback);
+            std::function<void(const OCRepresentation, const int)>& callback);
         
-        virtual OCStackResult SetResourceAttributes(const std::string& host, const std::string& uri, const AttributeMap& attributes, 
-            const QueryParamsMap& queryParams, std::function<void(const AttributeMap,const int)>& callback);
+        virtual OCStackResult SetResourceAttributes(const std::string& host, const std::string& uri, const OCRepresentation& attributes, 
+            const QueryParamsMap& queryParams, std::function<void(const OCRepresentation, const int)>& callback);
         
         virtual OCStackResult ObserveResource(ObserveType observeType, OCDoHandle* handle, 
             const std::string& host, const std::string& uri, const QueryParamsMap& queryParams, 
-            std::function<void(const AttributeMap&, const int&, const int&)>& callback);
+            std::function<void(const OCRepresentation&, const int&, const int&)>& callback);
         
         virtual OCStackResult CancelObserveResource(OCDoHandle handle, const std::string& host, const std::string& uri);
         
@@ -66,7 +66,7 @@ namespace OC
     private:
         void listeningFunc();
         std::string assembleSetResourceUri(std::string uri, const QueryParamsMap& queryParams);
-        std::string assembleSetResourcePayload(const AttributeMap& attributes);
+        std::string assembleSetResourcePayload(const OCRepresentation& attributes);
         std::thread m_listeningThread;
         bool m_threadRun;
         std::weak_ptr<std::mutex> m_csdkLock;
index 68853a5..54236ad 100644 (file)
@@ -103,6 +103,83 @@ namespace OC {
  // Used in GET, PUT, POST, DELETE methods on links to other resources of a collection.
  const std::string BATCH_INTERFACE = "oc.mi.b";
 
+ class OCRepresentation
+    {
+
+    private:
+
+        std::string m_uri;
+        AttributeMap m_attributeMap;
+        std::vector<std::string> m_resourceTypes;
+        std::vector<std::string> m_resourceInterfaces;
+        bool m_observable; // TODO : do we need this here???
+        int errorCode;
+
+        std::vector<OCRepresentation> m_children;
+
+    public:
+
+        OCRepresentation() {}
+
+        std::string getUri(void) const
+        {
+            return m_uri;
+        }
+
+        void setUri(std::string uri)
+        {
+            m_uri = uri;
+        }
+
+        std::vector<OCRepresentation> getChildren(void) const
+        {
+            return m_children;
+        }
+
+        void setChildren(std::vector<OCRepresentation> children)
+        {
+            m_children = children;
+        }
+
+        OCResource* getResource() const
+        {
+            // TODO Needs to be implemented
+            OCResource* res = NULL;
+
+            return res;
+        }
+
+        AttributeMap getAttributeMap() const 
+        {
+            return m_attributeMap;
+        }
+
+        void setAttributeMap(AttributeMap map)
+        {
+            m_attributeMap = map;
+        }
+
+        std::vector<std::string> getResourceTypes() const
+        {
+            return m_resourceTypes;
+        }
+
+        void setResourceTypes(std::vector<std::string> resourceTypes)
+        {
+            m_resourceTypes = resourceTypes;
+        }
+
+        std::vector<std::string> getResourceInterfaces(void) const
+        {
+            return m_resourceInterfaces;
+        }
+
+        void setResourceInterfaces(std::vector<std::string> resourceInterfaces)
+        {
+            m_resourceInterfaces = resourceInterfaces;
+        }
+    };
+
 } // namespace OC
 
 #endif  
index e2226da..ddfb23d 100644 (file)
 
 namespace OC
 {
-    class OCRepresentation
-    {
-
-    private:
-
-        std::string m_uri;
-        AttributeMap m_attributeMap;
-        std::vector<std::string> m_resourceTypes;
-        std::vector<std::string> m_resourceInterfaces;
-        bool m_observable; // TODO : do we need this here???
-        int errorCode;
-
-        std::vector<OCRepresentation> m_children;
-
-    public:
-
-        OCRepresentation() {}
-
-        std::string getUri(void) const
-        {
-            return m_uri;
-        }
-
-        void setUri(std::string uri)
-        {
-            m_uri = uri;
-        }
-
-        std::vector<OCRepresentation> getChildren(void) const
-        {
-            return m_children;
-        }
-
-        void setChildren(std::vector<OCRepresentation> children)
-        {
-            m_children = children;
-        }
-
-        OCResource* getResource() const
-        {
-            // TODO Needs to be implemented
-            OCResource* res = NULL;
-
-            return res;
-        }
-
-        AttributeMap getAttributeMap() const 
-        {
-            return m_attributeMap;
-        }
-
-        void setAttributeMap(AttributeMap map)
-        {
-            m_attributeMap = map;
-        }
-
-        std::vector<std::string> getResourceTypes() const
-        {
-            return m_resourceTypes;
-        }
-
-        void setResourceTypes(std::vector<std::string> resourceTypes)
-        {
-            m_resourceTypes = resourceTypes;
-        }
-
-        std::vector<std::string> getResourceInterfaces(void) const
-        {
-            return m_resourceInterfaces;
-        }
-
-        void setResourceInterfaces(std::vector<std::string> resourceInterfaces)
-        {
-            m_resourceInterfaces = resourceInterfaces;
-        }
-    };
-
+    
 } // namespace OC
 
 #endif //__OCREPRESENTATION_H
index 8ae37ae..2c65d55 100644 (file)
@@ -37,6 +37,7 @@
 #include <ResourceInitException.h>
 #include <IClientWrapper.h>
 #include <InProcClientWrapper.h>
+#include <OCRepresentation.h>
 
 namespace OC
 {
@@ -70,7 +71,7 @@ namespace OC
         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. 
         * NOTE: OCStackResult is defined in ocstack.h.
         */
-        OCStackResult get(const QueryParamsMap& queryParametersMap, std::function<void(const AttributeMap, const int)> attributeHandler);
+        OCStackResult get(const QueryParamsMap& queryParametersMap, std::function<void(const OCRepresentation, const int)> attributeHandler);
         
         /**
         * Function to get the attributes of a resource. 
@@ -97,7 +98,7 @@ namespace OC
         * TODO: Implementation
         */
         OCStackResult get(const std::string& resourceType, const std::string& resourceInterface, const QueryParamsMap& queryParametersMap,
-            std::function<void(const AttributeMap& attributeMap, const std::vector<std::string>& resourceUriList, const int& errorCode)> attributeHandler) 
+            std::function<void(const OCRepresentation& rep, const std::vector<std::string>& resourceUriList, const int& errorCode)> attributeHandler) 
             { return OC_STACK_OK; }
 
         /**
@@ -113,8 +114,8 @@ namespace OC
         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. 
         * NOTE: OCStackResult is defined in ocstack.h.
         */
-        OCStackResult put(const AttributeMap& attributeMap, const QueryParamsMap& queryParametersMap, 
-            std::function< void(const AttributeMap,const int)> attributeHandler);
+        OCStackResult put(const OCRepresentation& attributeMap, const QueryParamsMap& queryParametersMap, 
+            std::function< void(const OCRepresentation,const int)> attributeHandler);
 
         /**
         * Function to set the attributes of a resource (via PUT)
@@ -135,8 +136,8 @@ namespace OC
         * TODO: Implementation
         */
         OCStackResult put(const std::string& resourceType, const std::string& resourceInterface,
-            const AttributeMap& attributeMap, const QueryParamsMap& queryParametersMap, 
-            std::function< void(const AttributeMap&,const int&)> attributeHandler) { return OC_STACK_OK; }
+            const OCRepresentation& attributeMap, const QueryParamsMap& queryParametersMap, 
+            std::function< void(const OCRepresentation&,const int&)> attributeHandler) { return OC_STACK_OK; }
 
         /**
         * Function to set observation on the resource
@@ -150,7 +151,7 @@ namespace OC
         * NOTE: OCStackResult is defined in ocstack.h.
         */
         OCStackResult observe(ObserveType observeType, const QueryParamsMap& queryParametersMap, 
-            std::function<void(const AttributeMap&, const int&, const int&)> observeHandler);
+            std::function<void(const OCRepresentation&, const int&, const int&)> observeHandler);
 
         /**
         * Function to cancel the observation on the resource
@@ -206,7 +207,6 @@ namespace OC
         std::vector<std::string> m_resourceTypes;
         std::vector<std::string> m_interfaces;
         std::vector<std::string> m_children;
-        AttributeMap m_attributeMap;
         OCDoHandle m_observeHandle;
 
     private:
index 7534f25..b57ad52 100644 (file)
@@ -34,14 +34,17 @@ namespace OC
             std::function<void(std::shared_ptr<OCResource>)>& callback) {return OC_STACK_NOTIMPL;}
 
         virtual OCStackResult GetResourceAttributes(const std::string& host, const std::string& uri, 
-            const QueryParamsMap& queryParams, std::function<void(const AttributeMap, const int)>& callback){return OC_STACK_NOTIMPL;}
-        
+            const QueryParamsMap& queryParams, std::function<void(const OCRepresentation, const int)>& callback){return OC_STACK_NOTIMPL;}
+/*        
         virtual OCStackResult SetResourceAttributes(const std::string& host, const std::string& uri, 
             const AttributeMap& attributes, const QueryParamsMap& queryParams, std::function<void(const AttributeMap,const int)>& callback){return OC_STACK_NOTIMPL;}
-        
+ */       
+        virtual OCStackResult SetResourceAttributes(const std::string& host, const std::string& uri, 
+            const OCRepresentation& attributes, const QueryParamsMap& queryParams, std::function<void(const OCRepresentation,const int)>& callback){return OC_STACK_NOTIMPL;}
+
         virtual OCStackResult ObserveResource(ObserveType observeType, OCDoHandle* handle, const std::string& host, 
             const std::string& uri, const QueryParamsMap& queryParams, 
-            std::function<void(const AttributeMap&, const int&, const int&)>& callback){return OC_STACK_NOTIMPL;}
+            std::function<void(const OCRepresentation&, const int&, const int&)>& callback){return OC_STACK_NOTIMPL;}
         
         virtual OCStackResult CancelObserveResource(OCDoHandle handle, const std::string& host, const std::string& uri){return OC_STACK_NOTIMPL;}
 
index 5e6e95a..4c4c489 100644 (file)
--- a/makefile
+++ b/makefile
@@ -19,7 +19,7 @@ CXX_INC         += -I./csdk/logger/include
 CXX_INC          += -I./csdk/libcoap
 
 # Force metatargets to build:
-.PHONY: prep_dirs c_sdk simpleserver simpleclient simpleclientserver roomserver roomclient
+.PHONY: prep_dirs c_sdk simpleserver simpleclient roomserver roomclient
 
 all:   .PHONY