Added Get and Put for collection. TODO: implementation
authorSudarshan Prasad <sudarshan.prasad@intel.com>
Mon, 11 Aug 2014 19:58:18 +0000 (12:58 -0700)
committerSudarshan Prasad <sudarshan.prasad@intel.com>
Mon, 11 Aug 2014 19:58:18 +0000 (12:58 -0700)
examples/simpleserver.cpp
include/OCApi.h
include/OCResource.h

index 0209bac..b723607 100644 (file)
@@ -61,7 +61,7 @@ public:
     {
         std::string resourceURI = "/a/light"; // URI of the resource
         std::string resourceTypeName = "core.light"; // resource type name. In this case, it is light
-        std::string resourceInterface = PARAMETER_INTERFACE; // resource interface.
+        std::string resourceInterface = DEFAULT_INTERFACE; // resource interface.
 
         // OCResourceProperty is defined ocstack.h
         uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
index 834dedd..b6fd91c 100644 (file)
@@ -87,21 +87,15 @@ namespace OC {
  typedef std::map<std::string, std::string> QueryParamsMap;
 
  // const strings for different interfaces
- // Used in discovering (GET) links to other resources of a container/collection.  
- const std::string LINK_INTERFACE = "oc.mi.ll";
-
- // Used in GET, PUT, POST, DELETE methods on links to other resources of a container/collection. 
- const std::string BATCH_INTERFACE = "oc.mi.b";
 
- // Used to signify that the resource supports ONLY GET method 
- const std::string SENSOR_INTERFACE = "oc.mi.s";
+ // Default interface
+ const std::string DEFAULT_INTERFACE = "oc.mi.def";
 
- // Used to signify that the resource supports GET, PUT, POST, DELETE methods
- const std::string ACTUATOR_INTERFACE = "oc.mi.a";
+ // Used in discovering (GET) links to other resources of a collection.  
+ const std::string LINK_INTERFACE = "oc.mi.ll";
 
- // OPENS 
- const std::string PARAMETER_INTERFACE = "oc.mi.p";
- const std::string READ_PARAMETER_INTERFACE = "oc.mi.rp";
+ // Used in GET, PUT, POST, DELETE methods on links to other resources of a collection. 
+ const std::string BATCH_INTERFACE = "oc.mi.b";
 
 } // namespace OC
 
index 14dba11..7e0699f 100644 (file)
@@ -69,6 +69,32 @@ namespace OC
         * NOTE: OCStackResult is defined in ocstack.h.
         */
         OCStackResult get(std::function<void(const AttributeMap, const int)> attributeHandler);
+        
+        /**
+        * Function to get the attributes of a resource. 
+        *
+        * @param resourceType resourceType of the resource operate on
+        * @param resourceInterface interface type of the resource to operate on
+        * @param attributeHandler handles callback
+        *        The callback function will be invoked with a map of attribute name and values. 
+        *        The callback function will be invoked with a list of URIs if 'get' is invoked on a resource container 
+        *        (list will be empty if not a container)
+        *        The callback function will also have the result from this Get operation. This will have error codes
+        * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
+        * NOTE: OCStackResult is defined in ocstack.h.<br>
+        * <b>Example:</b><br>
+        * Consider resource "a/home" (with link interface and resource type as home) contains links to "a/kitchen" and "a/room". 
+        * Step 1: get("home", Link_Interface, &onGet)<br>
+        * Callback onGet will receive a) Empty attribute map because there are no attributes for a/home b) list with 
+        * full URI of "a/kitchen" and "a/room" resources and their properties c) error code for GET operation<br>
+        * NOTE: A resource may contain single or multiple resource types. Also, a resource may contain single or multiple interfaces.<br>
+        * Currently, single GET request is allowed to do operate on single resource type or resource interface. In future, a single GET <br>
+        * can operate on multiple resource types and interfaces. <br>
+        * NOTE: A client can traverse a tree or graph by doing successive GETs on the returned resources at a node.<br>
+        * TODO: Implementation
+        */
+        OCStackResult get(const std::string& resourceType, const std::string& resourceInterface,
+            std::function<void(const AttributeMap& attributeMap, const std::vector<std::string>& resourceUriList, const int& errorCode)> attributeHandler) { return OC_STACK_OK; }
 
         /**
         * Function to set the attributes of a resource (via PUT)
@@ -84,6 +110,26 @@ namespace OC
         OCStackResult put(const AttributeMap& attributeMap, const QueryParamsMap& queryParametersMap, std::function< void(const AttributeMap,const int)> attributeHandler);
 
         /**
+        * Function to set the attributes of a resource (via PUT)
+        * @param resourceType resource type of the resource to operate on
+        * @param resourceInterface interface type of the resource to operate on
+        * @param AttributeMap Map which can either have all the attribute names and values
+        *        (which will represent entire state of the resource) or a
+        *        set of attribute names and values which needs to be modified
+        * @param QueryParamsMap Map which can have the query parameter name and value 
+        * @param attributeHandler
+        *        The callback function will be invoked with a map of attribute name and values.
+        *        The callback function will also have the result from this Put operation
+        *        This will have error codes
+        * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
+        * NOTE: OCStackResult is defined in ocstack.h. <br>
+        * TODO: consider to input hrefs for resource collection
+        * 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; }
+
+        /**
         * Function to set observation on the resource
         * @param observeHandler handles callback
         *        The callback function will be invoked with a map of attribute name and values.