Makefile again builds OCProperties.
authorJesse Williamson <jesse.f.williamson@intel.com>
Thu, 21 Aug 2014 17:53:25 +0000 (10:53 -0700)
committerJesse Williamson <jesse.f.williamson@intel.com>
Thu, 21 Aug 2014 20:02:23 +0000 (13:02 -0700)
AttributeMap -> OCRepresentation

Change-Id: I49effbd0a76845391a26aedcedacf783de8d0aa6

examples/ocicuc/client.cpp
examples/ocicuc/server.cpp
makefile

index af01153..9d1e3c7 100644 (file)
@@ -57,7 +57,7 @@ auto make_description()
  return desc;
 }
 
-// Prettyprinter for AttributeMaps:
+// Prettyprinters:
 std::ostream& operator<<(std::ostream& os, const OC::AttributeMap& attrs)
 {
  for(const auto& attr : attrs)
@@ -165,9 +165,9 @@ class resource_handle
  // Callbacks (note that the signature after binding will match exactly:
  private:
  void onFoundResource(std::shared_ptr<OC::OCResource> in_resource);
- void onResourceGet(OC::AttributeMap attr_map, const int error_code);
- void onResourcePut(OC::AttributeMap attribute_map, const int error_code);
- void onObserve(const OC::AttributeMap attribute_map, const int error_code, const int& sequence_number);
+ void onResourceGet(OC::OCRepresentation rep, const int error_code);
+ void onResourcePut(const OC::OCRepresentation rep, const int error_code);
+ void onObserve(const OC::OCRepresentation rep, const int error_code, const int& sequence_number);
 };
 
 class resource_handler
@@ -296,7 +296,7 @@ void resource_handle::onFoundResource(std::shared_ptr<OC::OCResource> in_resourc
 
        call_timer.report_and_reset("find_resources");
 
-       // Now, fixup our own representation:
+       // Now, fixup our own representation ptr:
        resource = in_resource;
 
        /* Note: You can combine the host and URI to get a unique identifier, for
@@ -307,8 +307,10 @@ void resource_handle::onFoundResource(std::shared_ptr<OC::OCResource> in_resourc
 
        call_timer.mark("get_resource");
 
-       resource->get(std::bind(&resource_handle::onResourceGet, this, 
-                               std::placeholders::_1, std::placeholders::_2));
+       OC::QueryParamsMap qpm;
+
+       resource->get(qpm, std::bind(&resource_handle::onResourceGet, this, 
+                                    std::placeholders::_1, std::placeholders::_2));
   }
  catch(OC::OCException& e)
   {
@@ -320,7 +322,7 @@ void resource_handle::onFoundResource(std::shared_ptr<OC::OCResource> in_resourc
   }
 }
 
-void resource_handle::onResourceGet(const OC::AttributeMap attr_map, const int error_code)
+void resource_handle::onResourceGet(const OC::OCRepresentation rep, const int error_code)
 {
  using std::cout;
 
@@ -340,7 +342,7 @@ void resource_handle::onResourceGet(const OC::AttributeMap attr_map, const int e
         return;
   }
 
- std::cout << attr_map << '\n';
+ std::cout << "input attributes:\n" << rep.getAttributeMap() << '\n';
 
  // Now, make a change to the light representation (replacing, rather than parsing): 
  OC::AttributeMap attrs {
@@ -348,13 +350,18 @@ void resource_handle::onResourceGet(const OC::AttributeMap attr_map, const int e
                          { "power", { "10" } }
                         };
 
+ std::cout << "output attributes:\n" << attrs << '\n';
+
  call_timer.mark("put_resource");
 
- resource->put(attrs, OC::QueryParamsMap(), 
+ OC::OCRepresentation out_rep;
+ out_rep.setAttributeMap(attrs); 
+ resource->put(out_rep, OC::QueryParamsMap(), 
                std::bind(&resource_handle::onResourcePut, this, std::placeholders::_1, std::placeholders::_2));
 }
 
-void resource_handle::onResourcePut(const OC::AttributeMap attribute_map, const int error_code)
+void resource_handle::onResourcePut(const OC::OCRepresentation rep, const int error_code)
 {
  std::cout << "onResourcePut():\n";
 
@@ -369,16 +376,16 @@ void resource_handle::onResourcePut(const OC::AttributeMap attribute_map, const
         throw OC::OCException(os.str());
   }
 
- std::cout << attribute_map << '\n';
+ std::cout << "input attributes:\n" << rep.getAttributeMap() << '\n';
 
  call_timer.mark("observe_resource");
 
  // Start an observer:
- resource->observe(OC::ObserveType::Observe,
+ resource->observe(OC::ObserveType::Observe, OC::QueryParamsMap(),
                     std::bind(&resource_handle::onObserve, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
 }
 
-void resource_handle::onObserve(const OC::AttributeMap attribute_map, const int error_code, const int& sequence_number)
+void resource_handle::onObserve(const OC::OCRepresentation rep, const int error_code, const int& sequence_number)
 {
  if(0 != error_code)
   {
@@ -391,7 +398,7 @@ void resource_handle::onObserve(const OC::AttributeMap attribute_map, const int
 
  call_timer.report_and_reset("observe_resource");
 
- std::cout << attribute_map << '\n';
+ std::cout << rep.getAttributeMap() << '\n';
 
  const auto oc = observe_count();
 
index b2ff83c..e444fbb 100644 (file)
@@ -284,15 +284,17 @@ void LightResource::handle_get_request(std::shared_ptr<OCResourceRequest> reques
 
 void LightResource::handle_put_request(std::shared_ptr<OCResourceRequest> request, std::shared_ptr<OCResourceResponse> response) 
 {
+ // Here's how you would get any query parameters:
  const auto query_params_map = request->getQueryParameters();
+ // ...do something with the query parameters (if there were any)...
 
- // ...do something with the query parameters...
-
- auto attribute_map = request->getResourceRepresentation();
+ auto attribute_map = request->getAttributeRepresentation();
 
  setRepresentation(attribute_map);
+ getRepresentation(attribute_map);  // in case we changed something
 
- getRepresentation(attribute_map);
+ if(!response)
+  return;
 
  response->setErrorCode(200);
  response->setResourceRepresentation(attribute_map); 
@@ -303,7 +305,7 @@ void LightResource::handle_post_request(std::shared_ptr<OCResourceRequest> reque
  // ...demo-code...
  response->setErrorCode(200);
 
- auto attribute_map = request->getResourceRepresentation();
+ auto attribute_map = request->getAttributeRepresentation();
  getRepresentation(attribute_map);
  response->setResourceRepresentation(attribute_map);
 }
@@ -313,7 +315,7 @@ void LightResource::handle_delete_request(std::shared_ptr<OCResourceRequest> req
  // ...demo-code...
  response->setErrorCode(200);
 
- auto attribute_map = request->getResourceRepresentation();
+ auto attribute_map = request->getAttributeRepresentation();
  getRepresentation(attribute_map);
  response->setResourceRepresentation(attribute_map);
 }
index 5e6e95a..5dbf6a1 100644 (file)
--- a/makefile
+++ b/makefile
@@ -46,8 +46,8 @@ roomserver: OCLib.a examples/roomserver.cpp
 roomclient: OCLib.a examples/roomclient.cpp
        $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(SAMPLES_OUT_DIR)/$@ examples/roomclient.cpp $(CXX_INC) $(OBJ_DIR)/OCLib.a csdk/$(BUILD)/liboctbstack.a
 
-OCLib.a: OCPlatform.o OCResource.o OCReflect.o OCUtilities.o InProcServerWrapper.o InProcClientWrapper.o
-       ar -cvq $(OBJ_DIR)/OCLib.a $(OBJ_DIR)/OCPlatform.o $(OBJ_DIR)/OCResource.o $(OBJ_DIR)/OCReflect.o $(OBJ_DIR)/OCUtilities.o $(OBJ_DIR)/InProcServerWrapper.o $(OBJ_DIR)/InProcClientWrapper.o
+OCLib.a: OCPlatform.o OCResource.o OCReflect.o OCUtilities.o OCProperties.o InProcServerWrapper.o InProcClientWrapper.o
+       ar -cvq $(OBJ_DIR)/OCLib.a $(OBJ_DIR)/OCPlatform.o $(OBJ_DIR)/OCResource.o $(OBJ_DIR)/OCProperties.o $(OBJ_DIR)/OCReflect.o $(OBJ_DIR)/OCUtilities.o $(OBJ_DIR)/InProcServerWrapper.o $(OBJ_DIR)/InProcClientWrapper.o
 
 OCReflect.o: OCLib/OCReflect.cpp
        $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OBJ_DIR)/$@ -c OCLib/OCReflect.cpp $(CXX_INC)
@@ -58,6 +58,9 @@ OCPlatform.o: OCLib/OCPlatform.cpp
 OCResource.o: OCLib/OCResource.cpp
        $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OBJ_DIR)/$@ -c OCLib/OCResource.cpp $(CXX_INC)
 
+OCProperties.o: OCLib/OCProperties.cpp
+       $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OBJ_DIR)/$@ -c OCLib/OCProperties.cpp $(CXX_INC)
+
 OCUtilities.o: OCLib/OCUtilities.cpp
        $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OBJ_DIR)/$@ -c OCLib/OCUtilities.cpp $(CXX_INC)