Supporting QoS in C++ layer:
authorSashi Penta <sashi.kumar.penta@intel.com>
Tue, 14 Oct 2014 17:18:19 +0000 (10:18 -0700)
committerSashi Penta <sashi.kumar.penta@intel.com>
Tue, 14 Oct 2014 17:18:19 +0000 (10:18 -0700)
1) Modified the QoS enums so they are not transport specific
2) Overleaded member functions in Platform and Resource to allow specifying QoS
3) Modified internal function hierarchy to pass QoS to C layer
4) Added examples for C++: simpleclientHQ and simpleserverHQ to demo the usage of QoS
5) Modified examples to use the new QoS enums
6) Minor mods in the C layer
7) Minfor fix for OCICUC tests
8) Minfor fix for arduino sample
9) Fixes for received reviews
10)Rebase on to master
11)OCICUC : Platform bare pointer to reference

Change-Id: I5789935e16c851e7d47921a9acdfb15a363daa8e

42 files changed:
README
csdk/occoap/include/occoaphelper.h
csdk/occoap/src/occoap.c
csdk/occoap/src/occoaphelper.c
csdk/stack/include/internal/ocobserve.h
csdk/stack/include/ocstack.h
csdk/stack/samples/arduino/SimpleClientServer/ocserver/ocserver.cpp
csdk/stack/samples/linux/SimpleClientServer/occlient.cpp
csdk/stack/samples/linux/SimpleClientServer/occlientcoll.cpp
csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp
csdk/stack/samples/linux/SimpleClientServer/ocservercoll.cpp
csdk/stack/src/ocobserve.c
csdk/stack/src/ocresource.c
csdk/stack/src/ocstack.c
examples/fridgeclient.cpp
examples/fridgeserver.cpp
examples/garageclient.cpp
examples/garageserver.cpp
examples/makefile
examples/ocicuc/client.cpp
examples/ocicuc/light_resource.cpp
examples/ocicuc/light_resource.hpp
examples/ocicuc/monoprocess.cpp
examples/ocicuc/server.cpp
examples/presenceclient.cpp
examples/presenceserver.cpp
examples/roomclient.cpp
examples/roomserver.cpp
examples/simpleclient.cpp
examples/simpleclientHQ.cpp [new file with mode: 0644]
examples/simpleclientserver.cpp
examples/simpleserver.cpp
examples/simpleserverHQ.cpp [new file with mode: 0644]
include/IClientWrapper.h
include/InProcClientWrapper.h
include/OCApi.h
include/OCPlatform.h
include/OCResource.h
include/OutOfProcClientWrapper.h
src/InProcClientWrapper.cpp
src/OCPlatform.cpp
src/OCResource.cpp

diff --git a/README b/README
index b042e2b..f8b9c45 100644 (file)
--- a/README
+++ b/README
-******************************************************************
-
- Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
-
--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
-      http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-===============================================================================
-==                      UB Stack & TB Stack                                  ==
-===============================================================================
-
-The OIC-RESOURCE repository contains two SDKs with underlying code
-(i.e. "stack"). The two SDKs are referred to as "UB SDK" (or "C++ SDK") and "TB
-SDK" (or "C SDK"). The associated stacks are referred to as "UB Stack" (or "C++
-Stack") and "TB Stack" (or "C Stack"), respectively. The UB Stack-SDK pair
-requires that the TB Stack-SDK pair is built under it.
-
-For a list of artifact locations for all possible build processes in the
-OIC-RESOURCE repository, please refer to:
-<oic-resource>/artifact_output_locations.txt.
-
-===============================================================================
-
-The UB Stack is intended ONLY for Linux Ubuntu 12.04 operating system.
-To build UB Stack, please follow these requirements:
-- GCC compiler version is 4.6
-- Pre-install the "gnu-libc" libraries package.
-- The OIC-UTILITIES repository must be a sibling directory to the OIC-RESOURCE
-  repository.
-- You have pre-built the TB Stack for Linux Ubuntu 12.04.
-
-The TB Stack is intended ONLY for Linux Ubuntu 12.04, Arduino ATMega 2560 with
-Arduino Framework 1.0.5, and Arduino Due with Arduino Framework 1.5.7.
-Tip: Use Cutecom in Ubuntu 12.04 to view logs from Arduino ATMega 2560 and
-Arduino Due.
-
-To build TB Stack, please follow these requirements for Linux Ubuntu 12.04:
-- GCC compiler version is 4.6
-- Pre-install the "gnu-libc" libraries package.
-- The OIC-UTILITIES repository must be a sibling directory to the OIC-RESOURCE
-  repository.
-
-To build TB Stack, please follow these requirements for Arduino ATMega 2560:
-- AVR-GCC compiler version is 4.5.3 (Distributed with Arduino 1.0.5, no further
-  action necessary if framework was obtained from http://www.arduino.cc. Note:
-  Frameworks obtained from apt-get have had different compiler versions.)
-- Unzip the Time Library from here to your Arduino Directory Structure:
-  http://playground.arduino.cc/code/time
-- The OIC-UTILITIES repository must be a sibling directory to the OIC-RESOURCE
-  repository.
-- Apply patches at OIC-UTILITIES/tb/ to your Arduino Directory Structure at
-  locations <Arduino 1.0.5>/libraries/Ethernet &
-  <Arduino 1.0.5>/libraries/Ethernet/utility/.
-
-To build TB Stack, please follow these requirements for Arduino Due:
-- AVR-GCC compiler version is 4.8.3 (Distributed with Arduino 1.5.7, no further
-  action necessary if framework was obtained from http://www.arduino.cc. Note:
-  Frameworks obtained from apt-get have had different compiler versions.)
-- Unzip the Time Library from here to your Arduino Directory Structure:
-  http://www.pjrc.com/teensy/td_libs_Time.html
-- The OIC-UTILITIES repository must be a sibling directory to the OIC-RESOURCE
-  repository.
-- Apply patches at OIC-UTILITIES/tb/ to your Arduino Directory Structure at
-  locations <Arduino 1.5.7>/libraries/Ethernet &
-  <Arduino 1.5.7>/libraries/Ethernet/utility/.
-
-===============================================================================
-
-Instructions for Common Build Processes:
-
-NOTE: 'GNU Make' is required to utilize the build script at location:
-<oic-resource>/buildScript.mk.
-
-=======================================
-== All Targets - Linux, ATMega & Due ==
-=======================================
-
-- All Modules, including OCICUC, in Release & Debug (TB Stack, TB Unit Tests,
-TB Examples, UB Stack, UB Examples, UB OCICUC) for linux, Arduino ATMega 2560
-with Ethernet Shield, Arduino ATMega ATMega 2560 with WiFi Shield, Arduino
-Due with Ethernet Shield and Arduino Due with WiFi Shield:
-(This will be what is used on the Build Server(s) to limit regression.)
-
-       make -f buildScript.mk all_dev
-
-=======================================
-== All Targets - Linux & ATMega 2560 ==
-=======================================
-
-- All Modules in Release (TB Stack, TB Unit Tests, TB Examples, UB Stack, UB
-Examples) for Linux & Arduino ATMega 2560 with Ethernet Shield:
-
-       make -f buildScript.mk all
-
-- All Modules in Debug (TB Stack, TB Unit Tests, TB Examples, UB Stack, UB
-Examples) for Linux & Arduino ATMega 2560 with Ethernet Shield:
-
-       make -f buildScript.mk all_debug
-
-=======================================
-==     All Targets - Linux & Due     ==
-=======================================
-
-- All Modules in Release (TB Stack, TB Unit Tests, TB Examples, UB Stack, UB
-Examples) for Linux & Arduino Due with Ethernet Shield:
-
-       make -f buildScript.mk complement
-
-- All Modules in Debug (TB Stack, TB Unit Tests, TB Examples, UB Stack, UB
-Examples) for Linux & Arduino Due with Ethernet Shield:
-
-       make -f buildScript.mk complement_debug
-
-=======================================
-==     All Targets - Linux Only      ==
-=======================================
-
-- All Modules, without OCICUC, in Release (TB Stack, TB Unit Tests,
-TB Examples, UB Stack, UB Examples) for linux:
-
-       make -f buildScript.mk linux
-
-- All Modules, without OCICUC, in Debug (TB Stack, TB Unit Tests,
-TB Examples, UB Stack, UB Examples) for linux:
-
-       make -f buildScript.mk linux_debug
-
-- All UB Stack Modules in Release, without OCICUC, (TB Stack, UB Stack, UB
-Examples) for Linux:
-
-       make -f buildScript.mk linux_ub
-
-- All UB Stack Modules in Debug, without OCICUC, (TB Stack, UB Stack, UB
-Examples) for Linux:
-
-       make -f buildScript.mk linux_ub_debug
-
-- All UB Stack Modules, including OCICUC, in Release & Debug (TB Stack,
-UB Stack, UB Examples, UB OCICUC) for linux:
-
-       make -f buildScript.mk linux_ub_dev
-
-- All TB Stack Modules in Release (TB Stack, TB Unit Tests,
-TB Examples) for Linux:
-
-       make -f buildScript.mk linux_tb
-
-- All TB Stack Modules in Debug (TB Stack, TB Unit Tests,
-TB Examples) for Linux:
-
-       make -f buildScript.mk linux_tb_debug
-
-=======================================
-==      All Targets - Mega Only      ==
-=======================================
-
-- All TB Stack Modules in Release (TB Stack, TB Unit Tests,
-TB Examples) for Arduino ATMega 2560 with Ethernet Shield:
-
-       make -f buildScript.mk arduinomega
-
-- All TB Stack Modules in Debug (TB Stack, TB Unit Tests,
-TB Examples) for Arduino ATMega 2560 with Ethernet Shield:
-
-       make -f buildScript.mk arduinomega_debug
-
-- All TB Stack Modules in Release (TB Stack, TB Unit Tests,
-TB Examples) for Arduino ATMega 2560 with WiFi Shield:
-
-       make -f buildScript.mk arduinomega_wifi
-
-- All TB Stack Modules in Debug (TB Stack, TB Unit Tests,
-TB Examples) for Arduino ATMega 2560 with WiFi Shield:
-
-       make -f buildScript.mk arduinomega_wifi_debug
-
-=======================================
-==      All Targets - Due Only      ==
-=======================================
-
-- All TB Stack Modules in Release (TB Stack, TB Unit Tests,
-TB Examples) for Arduino Due with Ethernet Shield:
-
-       make -f buildScript.mk arduinodue_all
-
-- All TB Stack Modules in Debug (TB Stack, TB Unit Tests,
-TB Examples) for Arduino Due with Ethernet Shield:
-
-       make -f buildScript.mk arduinodue_all_debug
-
-- All TB Stack Modules in Release (TB Stack, TB Unit Tests,
-TB Examples) for Arduino Due with WiFi Shield:
-
-       make -f buildScript.mk arduinodue_wifi
-
-- All TB Stack Modules in Debug (TB Stack, TB Unit Tests,
-TB Examples) for Arduino Due with WiFi Shield:
-
-       make -f buildScript.mk arduinodue_wifi_debug
-
-=======================================
-==         Clean All Targets         ==
-=======================================
-
-- Clean All:
-
-       make -f buildScript.mk clean
-
+1) Build with default option
+  To build with default option:
+  # scons
+
+  To see help information with default option(the output may be different with different options):
+  # scons -Q -h
+
+  To clean the project:
+  # scons -c
+
+2) Build with options
+  To build with options:
+  # scons OPTION1=xxx OPTION2=xxx OPTION3=....
+
+  To see help information:
+  # scons OPTION1=xxx OPTION2=xxx OPTION3=.... -Q -h
+
+  To clean the project:
+  # scons OPTION1=xxx OPTION2=xxx OPTION3=.... -c
+
+3) Examples
+  To build default
+  # scons
+  To see default help
+  # scons -Q -h
+  To clean
+  # scons -c
+
+  To build android armeabi-v7a
+  # scon BUILD_TARGET=Android CPU_ARCH=armeabi-v7a
+  To see help
+  # scon BUILD_TARGET=Android CPU_ARCH=armeabi-v7a -Q -h
+  To clean
+  # scon BUILD_TARGET=Android CPU_ARCH=armeabi-v7a -c
+
+Note:
+  1. To build android binary, android NDK should be newer than r8e(recommend r10).
+  2. You may be asked to set some options. Besides set it in command line, you
+can also set it by create a environment variable. Command line has higher priority.
+If both are set, the command line value will be used.
index 3e3874c..23f2fa5 100644 (file)
@@ -43,6 +43,9 @@ OCStackResult isVendorSpecific(uint16_t optionID);
 // Convert OCStack code to CoAP code
 uint8_t OCToCoAPResponseCode(OCStackResult result);
 
+//Convert OCQualityOfService to coap NON vs CON
+uint8_t OCToCoAPQoS(OCQualityOfService qos);
+
 // Convert CoAP code to OCStack code
 OCStackResult CoAPToOCResponseCode(uint8_t coapCode);
 
index ae1b39e..c449da3 100644 (file)
@@ -196,7 +196,7 @@ static void HandleCoAPRequests(struct coap_context_t *ctx,
 
     // fill OCRequest structure
     result = FormOCRequest(&request, (recvPdu->hdr->type == COAP_MESSAGE_CON) ?
-            OC_CONFIRMABLE : OC_NON_CONFIRMABLE, rcvdUri, rcvdObsReq, &entityHandlerRequest);
+            OC_HIGH_QOS : OC_LOW_QOS, rcvdUri, rcvdObsReq, &entityHandlerRequest);
     VERIFY_SUCCESS(result, OC_STACK_OK);
 
     OC_LOG_V(INFO, TAG, " Receveid uri:     %s", request->resourceUrl);
@@ -618,11 +618,7 @@ OCStackResult OCDoCoAPResource(OCMethod method, OCQualityOfService qos, OCCoAPTo
         OC_LOG_V(DEBUG, TAG, "uri.query.s %s", uri.query.s);
     }
 
-    coapMsgType = COAP_MESSAGE_NON;
-    // Decide message type
-    if (qos == OC_CONFIRMABLE) {
-        coapMsgType = COAP_MESSAGE_CON;
-    }
+    coapMsgType = OCToCoAPQoS(qos);
 
     // Decide method type
     switch (method) {
@@ -681,11 +677,7 @@ OCStackResult OCSendCoAPNotification (unsigned char * uri, OCDevAddr *dstAddr,
 
     OC_LOG(INFO, TAG, PCF("Entering OCSendCoAPNotification"));
 
-    coapMsgType = COAP_MESSAGE_NON;
-    // Decide message type
-    if (qos == OC_CONFIRMABLE) {
-        coapMsgType = COAP_MESSAGE_CON;
-    }
+    coapMsgType = OCToCoAPQoS(qos);
 
     #ifdef WITH_PRESENCE
     if(!strcmp((const char *)uri, OC_PRESENCE_URI))
index 19fe9d7..3636695 100644 (file)
@@ -79,7 +79,21 @@ uint8_t OCToCoAPResponseCode(OCStackResult result)
     return ret;
 }
 
-
+uint8_t OCToCoAPQoS(OCQualityOfService qos)
+{
+    switch (qos)
+    {
+        case OC_HIGH_QOS:
+            return COAP_MESSAGE_CON;
+            break;
+        case OC_MEDIUM_QOS:
+        case OC_LOW_QOS:
+        case OC_NA_QOS:
+        default:
+            return COAP_MESSAGE_NON;
+            break;
+    }
+}
 // Convert CoAP code to OCStack code
 OCStackResult CoAPToOCResponseCode(uint8_t coapCode)
 {
index 40e2f6f..3efc1ad 100644 (file)
@@ -53,9 +53,9 @@ typedef struct ResourceObserver {
     // number of times the server failed to reach the observer
     uint8_t failedCommCount;
     // number of times the server sent NON notifications
-    uint8_t NONCount;
+    uint8_t lowQosCount;
     // force the qos value to CON
-    uint8_t forceCON;
+    uint8_t forceHighQos;
     // next node in this list
     struct ResourceObserver *next;
 } ResourceObserver;
@@ -64,7 +64,8 @@ OCStackResult OCObserverStatus(OCCoAPToken * token, uint8_t status);
 
 OCStackResult ProcessObserveRequest (OCResource *resource, OCRequest *request);
 
-OCStackResult SendObserverNotification (OCMethod method, OCResource *resPtr, uint32_t maxAge);
+OCStackResult SendObserverNotification (OCMethod method, OCResource *resPtr, uint32_t maxAge,
+        OCQualityOfService qos);
 
 void DeleteObserverList();
 
index 8f9ce69..1fe8f36 100644 (file)
@@ -97,8 +97,10 @@ extern OCMode myStackMode;
  * Quality of Service
  */
 typedef enum {
-    OC_NON_CONFIRMABLE = 0,
-    OC_CONFIRMABLE
+    OC_LOW_QOS = 0,
+    OC_MEDIUM_QOS,
+    OC_HIGH_QOS,
+    OC_NA_QOS // No Quality is defined, let the stack decide
 } OCQualityOfService;
 
 /**
@@ -674,7 +676,7 @@ OCEntityHandler OCGetResourceHandler(OCResourceHandle handle);
  *     OC_STACK_NO_RESOURCE - invalid resource handle
  *     OC_STACK_NO_OBSERVERS - no more observers intrested in resource
  */
-OCStackResult OCNotifyAllObservers(OCResourceHandle handle);
+OCStackResult OCNotifyAllObservers(OCResourceHandle handle, OCQualityOfService qos);
 
 /**
  * Notify specific observers with updated value of representation.
@@ -697,7 +699,8 @@ OCStackResult
 OCNotifyListOfObservers (OCResourceHandle handle,
                          OCObservationId  *obsIdList,
                          uint8_t          numberOfIds,
-                         unsigned char    *notificationJSONPayload);
+                         unsigned char    *notificationJSONPayload,
+                         OCQualityOfService qos);
 
 #ifdef __cplusplus
 }
index d46127f..bba1f90 100644 (file)
@@ -209,7 +209,7 @@ void *ChangeLEDRepresentation (void *param)
         if (gLEDUnderObservation)
         {
             OC_LOG_V(INFO, TAG, " =====> Notifying stack of new power level %d\n", LED.power);
-            result = OCNotifyAllObservers (LED.handle);
+            result = OCNotifyAllObservers (LED.handle, OC_NA_QOS);
             if (OC_STACK_NO_OBSERVERS == result)
             {
                 gLEDUnderObservation = 0;
index e0d140a..885e78f 100644 (file)
@@ -236,14 +236,14 @@ OCStackApplicationResult obsReqCB(void* ctx, OCDoHandle handle, OCClientResponse
             printf ("************************** CANCEL OBSERVE with ");
             if(TEST_CASE == TEST_OBS_REQ_NON || TEST_CASE == TEST_OBS_REQ_CON){
                 printf ("RESET\n");
-                if (OCCancel (gObserveDoHandle, OC_NON_CONFIRMABLE, NULL, 0) != OC_STACK_OK){
+                if (OCCancel (gObserveDoHandle, OC_LOW_QOS, NULL, 0) != OC_STACK_OK){
                     OC_LOG(ERROR, TAG, "Observe cancel error");
                 }
                 return OC_STACK_DELETE_TRANSACTION;
             }else if(TEST_CASE == TEST_OBS_REQ_NON_CANCEL_IMM){
                 printf ("Deregister\n");
 
-                if (OCCancel (gObserveDoHandle, OC_CONFIRMABLE, NULL, 0) != OC_STACK_OK){
+                if (OCCancel (gObserveDoHandle, OC_HIGH_QOS, NULL, 0) != OC_STACK_OK){
                     OC_LOG(ERROR, TAG, "Observe cancel error");
                 }
             }
@@ -277,7 +277,7 @@ OCStackApplicationResult presenceCB(void* ctx, OCDoHandle handle, OCClientRespon
         if (gNumPresenceNotifies == 15)
         {
             printf ("************************** CANCEL PRESENCE\n");
-            if (OCCancel (gPresenceHandle, OC_NON_CONFIRMABLE, NULL, 0) != OC_STACK_OK){
+            if (OCCancel (gPresenceHandle, OC_LOW_QOS, NULL, 0) != OC_STACK_OK){
                 OC_LOG(ERROR, TAG, "Presence cancel error");
             }
             return OC_STACK_DELETE_TRANSACTION;
@@ -315,29 +315,29 @@ OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
 
         switch(TEST_CASE){
         case TEST_GET_REQ_NON:
-            InitGetRequest(OC_NON_CONFIRMABLE, 0);
+            InitGetRequest(OC_LOW_QOS, 0);
             break;
         case TEST_PUT_REQ_NON:
             InitPutRequest();
             break;
         case TEST_POST_REQ_NON:
-            InitPostRequest(OC_NON_CONFIRMABLE);
+            InitPostRequest(OC_LOW_QOS);
             break;
         case TEST_OBS_REQ_NON:
         case TEST_OBS_REQ_NON_CANCEL_IMM:
-            InitObserveRequest(OC_NON_CONFIRMABLE);
+            InitObserveRequest(OC_LOW_QOS);
             break;
         case TEST_GET_UNAVAILABLE_RES_REQ_NON:
             InitGetRequestToUnavailableResource();
             break;
         case TEST_GET_REQ_CON:
-            InitGetRequest(OC_CONFIRMABLE, 0);
+            InitGetRequest(OC_HIGH_QOS, 0);
             break;
         case TEST_POST_REQ_CON:
-            InitPostRequest(OC_CONFIRMABLE);
+            InitPostRequest(OC_HIGH_QOS);
             break;
         case TEST_OBS_REQ_CON:
-            InitObserveRequest(OC_CONFIRMABLE);
+            InitObserveRequest(OC_HIGH_QOS);
             break;
         #ifdef WITH_PRESENCE
         case TEST_OBS_PRESENCE:
@@ -345,7 +345,7 @@ OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
             break;
         #endif
         case TEST_GET_REQ_NON_WITH_VENDOR_HEADER_OPTIONS:
-            InitGetRequest(OC_NON_CONFIRMABLE, 1);
+            InitGetRequest(OC_LOW_QOS, 1);
             break;
         default:
             PrintUsage();
@@ -362,7 +362,7 @@ int InitPresence()
     OC_LOG_V(INFO, TAG, "\n\nExecuting %s", __func__);
     std::ostringstream query;
     query << "coap://" << coapServerIP << ":" << coapServerPort << OC_PRESENCE_URI;
-    return (InvokeOCDoResource(query, OC_REST_PRESENCE, OC_NON_CONFIRMABLE, presenceCB, NULL, 0));
+    return (InvokeOCDoResource(query, OC_REST_PRESENCE, OC_LOW_QOS, presenceCB, NULL, 0));
 }
 #endif
 int InitGetRequestToUnavailableResource()
@@ -370,7 +370,7 @@ int InitGetRequestToUnavailableResource()
     OC_LOG_V(INFO, TAG, "\n\nExecuting %s", __func__);
     std::ostringstream query;
     query << "coap://" << coapServerIP << ":" << coapServerPort << "/SomeUnknownResource";
-    return (InvokeOCDoResource(query, OC_REST_GET, OC_NON_CONFIRMABLE, getReqCB, NULL, 0));
+    return (InvokeOCDoResource(query, OC_REST_GET, OC_LOW_QOS, getReqCB, NULL, 0));
 }
 
 int InitObserveRequest(OCQualityOfService qos)
@@ -378,7 +378,7 @@ int InitObserveRequest(OCQualityOfService qos)
     OC_LOG_V(INFO, TAG, "\n\nExecuting %s", __func__);
     std::ostringstream query;
     query << "coap://" << coapServerIP << ":" << coapServerPort << coapServerResource;
-    return (InvokeOCDoResource(query, OC_REST_OBSERVE, (qos == OC_CONFIRMABLE)? OC_CONFIRMABLE:OC_NON_CONFIRMABLE, obsReqCB, NULL, 0));
+    return (InvokeOCDoResource(query, OC_REST_OBSERVE, (qos == OC_HIGH_QOS)? OC_HIGH_QOS:OC_LOW_QOS, obsReqCB, NULL, 0));
 }
 
 int InitPutRequest()
@@ -386,7 +386,7 @@ int InitPutRequest()
     OC_LOG_V(INFO, TAG, "\n\nExecuting %s", __func__);
     std::ostringstream query;
     query << "coap://" << coapServerIP << ":" << coapServerPort << coapServerResource;
-    return (InvokeOCDoResource(query, OC_REST_PUT, OC_NON_CONFIRMABLE, putReqCB, NULL, 0));
+    return (InvokeOCDoResource(query, OC_REST_PUT, OC_LOW_QOS, putReqCB, NULL, 0));
 }
 
 int InitPostRequest(OCQualityOfService qos)
@@ -398,7 +398,7 @@ int InitPostRequest(OCQualityOfService qos)
 
     // First POST operation (to create an LED instance)
     result = InvokeOCDoResource(query, OC_REST_POST,
-                               ((qos == OC_CONFIRMABLE) ? OC_CONFIRMABLE: OC_NON_CONFIRMABLE),
+                               ((qos == OC_HIGH_QOS) ? OC_HIGH_QOS: OC_LOW_QOS),
                                postReqCB, NULL, 0);
     if (OC_STACK_OK != result)
     {
@@ -408,7 +408,7 @@ int InitPostRequest(OCQualityOfService qos)
 
     // Second POST operation (to create an LED instance)
     result = InvokeOCDoResource(query, OC_REST_POST,
-                               ((qos == OC_CONFIRMABLE) ? OC_CONFIRMABLE: OC_NON_CONFIRMABLE),
+                               ((qos == OC_HIGH_QOS) ? OC_HIGH_QOS: OC_LOW_QOS),
                                postReqCB, NULL, 0);
     if (OC_STACK_OK != result)
     {
@@ -417,7 +417,7 @@ int InitPostRequest(OCQualityOfService qos)
 
     // This POST operation will update the original resourced /a/led
     return (InvokeOCDoResource(query, OC_REST_POST,
-                               ((qos == OC_CONFIRMABLE) ? OC_CONFIRMABLE: OC_NON_CONFIRMABLE),
+                               ((qos == OC_HIGH_QOS) ? OC_HIGH_QOS: OC_LOW_QOS),
                                postReqCB, NULL, 0));
 }
 
@@ -445,11 +445,11 @@ int InitGetRequest(OCQualityOfService qos, uint8_t withVendorSpecificHeaderOptio
     }
     if(withVendorSpecificHeaderOptions)
     {
-        return (InvokeOCDoResource(query, OC_REST_GET, (qos == OC_CONFIRMABLE)? OC_CONFIRMABLE:OC_NON_CONFIRMABLE, getReqCB, options, 2));
+        return (InvokeOCDoResource(query, OC_REST_GET, (qos == OC_HIGH_QOS)? OC_HIGH_QOS:OC_LOW_QOS, getReqCB, options, 2));
     }
     else
     {
-        return (InvokeOCDoResource(query, OC_REST_GET, (qos == OC_CONFIRMABLE)? OC_CONFIRMABLE:OC_NON_CONFIRMABLE, getReqCB, NULL, 0));
+        return (InvokeOCDoResource(query, OC_REST_GET, (qos == OC_HIGH_QOS)? OC_HIGH_QOS:OC_LOW_QOS, getReqCB, NULL, 0));
     }
 }
 
@@ -471,7 +471,7 @@ int InitDiscovery()
     cbData.cb = discoveryReqCB;
     cbData.context = (void*)CTX_VAL;
     cbData.cd = NULL;
-    ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_NON_CONFIRMABLE, &cbData, NULL, 0);
+    ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_LOW_QOS, &cbData, NULL, 0);
     if (ret != OC_STACK_OK)
     {
         OC_LOG(ERROR, TAG, "OCStack resource error");
index 4a616ea..8ee05e6 100644 (file)
@@ -100,7 +100,7 @@ OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse
             gNumObserveNotifies++;
             if (gNumObserveNotifies == 3)
             {
-                if (OCCancel (gObserveDoHandle, OC_NON_CONFIRMABLE, NULL, 0) != OC_STACK_OK){
+                if (OCCancel (gObserveDoHandle, OC_LOW_QOS, NULL, 0) != OC_STACK_OK){
                     OC_LOG(ERROR, TAG, "Observe cancel error");
                 }
             }
@@ -153,7 +153,7 @@ int InitGetRequestToUnavailableResource(OCClientResponse * clientResponse)
     cbData.context = (void*)CTX_VAL;
     cbData.cd = NULL;
 
-    ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, OC_NON_CONFIRMABLE,
+    ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, OC_LOW_QOS,
             &cbData, NULL, 0);
     if (ret != OC_STACK_OK)
     {
@@ -175,7 +175,7 @@ int InitObserveRequest(OCClientResponse * clientResponse)
     cbData.cd = NULL;
     OC_LOG_V(INFO, TAG, "PUT payload from client = %s ", putPayload.c_str());
 
-    ret = OCDoResource(&handle, OC_REST_OBSERVE, obsReg.str().c_str(), 0, 0, OC_NON_CONFIRMABLE,
+    ret = OCDoResource(&handle, OC_REST_OBSERVE, obsReg.str().c_str(), 0, 0, OC_LOW_QOS,
             &cbData, NULL, 0);
     if (ret != OC_STACK_OK)
     {
@@ -204,7 +204,7 @@ int InitPutRequest(OCClientResponse * clientResponse)
     OC_LOG_V(INFO, TAG, "PUT payload from client = %s ", putPayload.c_str());
 
     ret = OCDoResource(&handle, OC_REST_PUT, getQuery.str().c_str(), 0, putPayload.c_str(),
-            OC_NON_CONFIRMABLE, &cbData, NULL, 0);
+            OC_LOW_QOS, &cbData, NULL, 0);
     if (ret != OC_STACK_OK)
     {
         OC_LOG(ERROR, TAG, "OCStack resource error");
@@ -238,7 +238,7 @@ int InitGetRequest(OCClientResponse * clientResponse)
     cbData.cb = getReqCB;
     cbData.context = (void*)CTX_VAL;
     cbData.cd = NULL;
-    ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, OC_NON_CONFIRMABLE,
+    ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, OC_LOW_QOS,
             &cbData, NULL, 0);
     if (ret != OC_STACK_OK)
     {
@@ -262,7 +262,7 @@ int InitDiscovery()
     cbData.cb = discoveryReqCB;
     cbData.context = (void*)CTX_VAL;
     cbData.cd = NULL;
-    ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_NON_CONFIRMABLE,
+    ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_LOW_QOS,
             &cbData, NULL, 0);
     if (ret != OC_STACK_OK)
     {
index c9a3e67..17ac1e5 100644 (file)
@@ -443,12 +443,12 @@ void *ChangeLEDRepresentation (void *param)
                 json = cJSON_Parse((char *)jSONResponseSkel);
                 cJSON_Delete(json);
                 result = OCNotifyListOfObservers (LED.handle, obsNotify, j,
-                        (unsigned char *)obsResp);
+                        (unsigned char *)obsResp, OC_NA_QOS);
             }
             else if (gObserveNotifyType == 0)
             {
                 // Notifying all observers
-                result = OCNotifyAllObservers (LED.handle);
+                result = OCNotifyAllObservers (LED.handle, OC_NA_QOS);
                 if (OC_STACK_NO_OBSERVERS == result)
                 {
                     OC_LOG (INFO, TAG,
index 35caaf0..537e9c9 100644 (file)
@@ -171,7 +171,7 @@ void *ChangeLEDRepresentation (void *param)
         if (gLEDUnderObservation)
         {
      OC_LOG_V(INFO, TAG, " =====> Notifying stack of new power level %d\n", LED.power);
-            result = OCNotifyAllObservers (LED.handle);
+            result = OCNotifyAllObservers (LED.handle, OC_NA_QOS);
             if (OC_STACK_NO_OBSERVERS == result)
             {
                 gLEDUnderObservation = 0;
index 71e42e5..5aeefa3 100644 (file)
@@ -79,7 +79,7 @@ OCStackResult OCObserverStatus(OCCoAPToken * token, uint8_t status)
         observer = GetObserverUsingToken(token);
         if(observer)
         {
-            observer->forceCON = 0;
+            observer->forceHighQos = 0;
             observer->failedCommCount = 0;
             result = OC_STACK_OK;
         }
@@ -117,7 +117,7 @@ OCStackResult OCObserverStatus(OCCoAPToken * token, uint8_t status)
                 observer->failedCommCount++;
                 result = OC_STACK_OBSERVER_NOT_REMOVED;
             }
-            observer->forceCON = 1;
+            observer->forceHighQos = 1;
             OC_LOG_V(DEBUG, TAG, "Failed count for this observer is %d",observer->failedCommCount);
         }
         break;
@@ -232,7 +232,8 @@ OCStackResult ProcessObserveRequest (OCResource *resource, OCRequest *request)
     return stackRet;
 }
 
-OCStackResult SendObserverNotification (OCMethod method, OCResource *resPtr, uint32_t maxAge)
+OCStackResult SendObserverNotification (OCMethod method, OCResource *resPtr, uint32_t maxAge,
+        OCQualityOfService qos)
 {
     uint8_t numObs = 0;
     OCStackResult stackRet = OC_STACK_ERROR;
@@ -241,8 +242,6 @@ OCStackResult SendObserverNotification (OCMethod method, OCResource *resPtr, uin
     OCEntityHandlerRequest entityHandlerReq;
     unsigned char* jsonPayload = NULL;
     unsigned char bufRes[MAX_RESPONSE_LENGTH] = {0};
-    // TODO: we should allow the server application to define qos for each notification
-    OCQualityOfService qos = OC_NON_CONFIRMABLE;
 
     // Find clients that are observing this resource
     while (resourceObserver)
@@ -283,30 +282,35 @@ OCStackResult SendObserverNotification (OCMethod method, OCResource *resPtr, uin
                         jsonPayload);
 
                 // send notifications based on the qos of the request
-                qos = resourceObserver->qos;
-                if(qos == OC_NON_CONFIRMABLE)
+                // The qos passed as a parameter overrides what the client requested
+                // If we want the client preference taking high priority add:
+                // qos = resourceObserver->qos;
+                if(qos == OC_NA_QOS){
+                    qos = resourceObserver->qos;
+                }
+                if(qos != OC_HIGH_QOS)
                 {
                     OC_LOG_V(INFO, TAG, "Current NON count for this observer is %d",
-                            resourceObserver->NONCount);
+                            resourceObserver->lowQosCount);
                     #ifdef WITH_PRESENCE
-                    if((resourceObserver->forceCON \
-                            || resourceObserver->NONCount >= MAX_OBSERVER_NON_COUNT) \
+                    if((resourceObserver->forceHighQos \
+                            || resourceObserver->lowQosCount >= MAX_OBSERVER_NON_COUNT) \
                             && method != OC_REST_PRESENCE)
                     #else
                     if(resourceObserver->forceCON \
                             || resourceObserver->NONCount >= MAX_OBSERVER_NON_COUNT)
                     #endif
                     {
-                        resourceObserver->NONCount = 0;
+                        resourceObserver->lowQosCount = 0;
                         // at some point we have to to send CON to check on the
                         // availability of observer
                         OC_LOG(INFO, TAG, PCF("This time we are sending the \
-                                notification as CON"));
-                        qos = OC_CONFIRMABLE;
+                                notification as High qos"));
+                        qos = OC_HIGH_QOS;
                     }
                     else
                     {
-                        resourceObserver->NONCount++;
+                        resourceObserver->lowQosCount++;
                     }
                 }
                 stackRet = OCSendCoAPNotification(resourceObserver->resUri, resourceObserver->addr,
index 763f20d..7f3dec3 100644 (file)
@@ -389,7 +389,7 @@ HandleVirtualResource (OCRequest *request, OCResource* resource)
         else
         {
             if(resource->resourceProperties & OC_ACTIVE){
-                OCNotifyAllObservers((OCResourceHandle) resource);
+                OCNotifyAllObservers((OCResourceHandle) resource, OC_LOW_QOS);
             }
             result = OC_STACK_PRESENCE_DO_NOT_HANDLE;
         }
index 97f4149..743018f 100644 (file)
@@ -393,6 +393,7 @@ OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requ
 
     uint16_t uriLen = strlen(requiredUri);
 
+    // ToDo: We should also check if the requiredUri has a mutlicast address, then qos has to be OC_Low_QOS
     switch (method)
     {
         case OC_REST_GET:
@@ -509,7 +510,7 @@ OCStackResult OCCancel(OCDoHandle handle, OCQualityOfService qos, OCHeaderOption
         {
             case OC_REST_OBSERVE:
             case OC_REST_OBSERVE_ALL:
-                if(qos == OC_CONFIRMABLE)
+                if(qos == OC_HIGH_QOS)
                 {
                     ret = OCDoCoAPResource(OC_REST_CANCEL_OBSERVE, qos,
                             &(clientCB->token), (const char *) clientCB->requestUri, NULL, options,
@@ -556,7 +557,7 @@ OCStackResult OCProcessPresence()
                     OC_LOG_V(DEBUG, TAG, "----------------timeout ticks %d",
                             cbNode->presence->timeOut[cbNode->presence->TTLlevel]);
                 }
-                if(cbNode->presence->TTLlevel == PresenceTimeOutSize)
+                if(cbNode->presence->TTLlevel >= PresenceTimeOutSize)
                 {
                     OC_LOG(DEBUG, TAG, "----------------No more timeout ticks");
                     if (ParseIPv4Address( cbNode->requestUri, ipAddr, &port))
@@ -587,7 +588,7 @@ OCStackResult OCProcessPresence()
                     OC_LOG(DEBUG, TAG, "time to test server presence ==========");
                     OCCoAPToken token;
                     OCGenerateCoAPToken(&token);
-                    result = OCDoCoAPResource(OC_REST_GET, OC_NON_CONFIRMABLE,
+                    result = OCDoCoAPResource(OC_REST_GET, OC_LOW_QOS,
                             &token, (const char *)cbNode->requestUri, NULL, NULL, 0);
                     if(result != OC_STACK_OK)
                     {
@@ -663,14 +664,14 @@ OCStackResult OCStartPresence(const uint32_t ttl)
         OCBuildIPv4Address(224, 0, 1, 187, 5683, &multiCastAddr);
         //add the presence observer
         AddObserver(OC_PRESENCE_URI, NULL, 0, &token, &multiCastAddr,
-            (OCResource *)presenceResource.handle, OC_NON_CONFIRMABLE);
+            (OCResource *)presenceResource.handle, OC_LOW_QOS);
     }
 
     // Each time OCStartPresence is called
     // a different random 32-bit integer number is used
     ((OCResource *)presenceResource.handle)->sequenceNum = OCGetRandom();
 
-    return OCNotifyAllObservers(presenceResource.handle);
+    return OCNotifyAllObservers(presenceResource.handle, OC_LOW_QOS);
 }
 
 /**
@@ -691,7 +692,7 @@ OCStackResult OCStopPresence()
     result = OCChangeResourceProperty(
             &(((OCResource *) presenceResource.handle)->resourceProperties),
             OC_ACTIVE, 0);
-    result = OCNotifyAllObservers(presenceResource.handle);
+    result = OCNotifyAllObservers(presenceResource.handle, OC_LOW_QOS);
     return result;
 }
 #endif
@@ -824,7 +825,7 @@ OCStackResult OCCreateResource(OCResourceHandle *handle,
     if(presenceResource.handle)
     {
         ((OCResource *)presenceResource.handle)->sequenceNum = OCGetRandom();
-        OCNotifyAllObservers(presenceResource.handle);
+        OCNotifyAllObservers(presenceResource.handle, OC_LOW_QOS);
     }
     #endif
 exit:
@@ -885,7 +886,7 @@ OCStackResult OCBindResource(
     if(presenceResource.handle)
     {
         ((OCResource *)presenceResource.handle)->sequenceNum = OCGetRandom();
-        OCNotifyAllObservers(presenceResource.handle);
+        OCNotifyAllObservers(presenceResource.handle, OC_LOW_QOS);
     }
     #endif
 
@@ -943,7 +944,7 @@ OCStackResult OCUnBindResource(
     if(presenceResource.handle)
     {
         ((OCResource *)presenceResource.handle)->sequenceNum = OCGetRandom();
-        OCNotifyAllObservers(presenceResource.handle);
+        OCNotifyAllObservers(presenceResource.handle, OC_LOW_QOS);
     }
     #endif
 
@@ -1010,7 +1011,7 @@ OCStackResult OCBindResourceTypeToResource(OCResourceHandle handle,
     if(presenceResource.handle)
     {
         ((OCResource *)presenceResource.handle)->sequenceNum = OCGetRandom();
-        OCNotifyAllObservers(presenceResource.handle);
+        OCNotifyAllObservers(presenceResource.handle, OC_LOW_QOS);
     }
     #endif
 
@@ -1079,7 +1080,7 @@ OCStackResult OCBindResourceInterfaceToResource(OCResourceHandle handle,
     if(presenceResource.handle)
     {
         ((OCResource *)presenceResource.handle)->sequenceNum = OCGetRandom();
-        OCNotifyAllObservers(presenceResource.handle);
+        OCNotifyAllObservers(presenceResource.handle, OC_LOW_QOS);
     }
     #endif
 
@@ -1163,7 +1164,7 @@ OCStackResult OCDeleteResource(OCResourceHandle handle) {
     if(presenceResource.handle)
     {
         ((OCResource *)presenceResource.handle)->sequenceNum = OCGetRandom();
-        OCNotifyAllObservers(presenceResource.handle);
+        OCNotifyAllObservers(presenceResource.handle, OC_LOW_QOS);
     }
     #endif
 
@@ -1381,7 +1382,7 @@ OCStackResult OCBindResourceHandler(OCResourceHandle handle,
     if(presenceResource.handle)
     {
         ((OCResource *)presenceResource.handle)->sequenceNum = OCGetRandom();
-        OCNotifyAllObservers(presenceResource.handle);
+        OCNotifyAllObservers(presenceResource.handle, OC_LOW_QOS);
     }
     #endif
 
@@ -1434,7 +1435,7 @@ void incrementSequenceNumber(OCResource * resPtr)
  *     OC_STACK_NO_RESOURCE - invalid resource handle
  *     OC_STACK_NO_OBSERVERS - no more observers intrested in resource
  */
-OCStackResult OCNotifyAllObservers(OCResourceHandle handle) {
+OCStackResult OCNotifyAllObservers(OCResourceHandle handle, OCQualityOfService qos) {
     OCResource *resPtr = NULL;
     OCStackResult result;
     OCMethod method = OC_REST_NOMETHOD;
@@ -1474,7 +1475,7 @@ OCStackResult OCNotifyAllObservers(OCResourceHandle handle) {
 
         }
         #endif
-        result = SendObserverNotification (method, resPtr, maxAge);
+        result = SendObserverNotification (method, resPtr, maxAge, qos);
         return result;
     }
 }
@@ -1483,7 +1484,8 @@ OCStackResult
 OCNotifyListOfObservers (OCResourceHandle handle,
                          OCObservationId  *obsIdList,
                          uint8_t          numberOfIds,
-                         unsigned char    *notificationJSONPayload)
+                         unsigned char    *notificationJSONPayload,
+                         OCQualityOfService qos)
 {
     OC_LOG(INFO, TAG, PCF("Entering OCNotifyListOfObservers"));
 
@@ -1497,7 +1499,6 @@ OCNotifyListOfObservers (OCResourceHandle handle,
     uint32_t maxAge = 0;
     unsigned char bufNotify[MAX_RESPONSE_LENGTH] = {0};
     unsigned char *currPtr;
-    OCQualityOfService qos = OC_NON_CONFIRMABLE;
     uint8_t numSentNotification = 0;
 
     // Verify the notification payload length does not exceed the maximim
@@ -1539,24 +1540,29 @@ OCNotifyListOfObservers (OCResourceHandle handle,
                 strcpy((char*)currPtr, OC_JSON_SUFFIX);
 
                 // send notifications based on the qos of the request
-                qos = observation->qos;
-                if(qos == OC_NON_CONFIRMABLE)
+                // The qos passed as a parameter overrides what the client requested
+                // If we want the client preference taking high priority add:
+                // QoS = resourceObserver->qos;
+                if(qos == OC_NA_QOS){
+                    qos = observation->qos;
+                }
+                if(qos != OC_HIGH_QOS)
                 {
                     OC_LOG_V(INFO, TAG, "Current NON count for this observer is %d",
-                            observation->NONCount);
-                    if(observation->forceCON \
-                            || observation->NONCount >= MAX_OBSERVER_NON_COUNT)
+                            observation->lowQosCount);
+                    if(observation->forceHighQos \
+                            || observation->lowQosCount >= MAX_OBSERVER_NON_COUNT)
                     {
-                        observation->NONCount = 0;
+                        observation->lowQosCount = 0;
                         // at some point we have to to send CON to check on the
                         // availability of observer
                         OC_LOG(INFO, TAG, PCF("This time we are sending the \
-                                notification as CON"));
-                        qos = OC_CONFIRMABLE;
+                                notification as High qos"));
+                        qos = OC_HIGH_QOS;
                     }
                     else
                     {
-                        observation->NONCount++;
+                        observation->lowQosCount++;
                     }
                 }
                 OCSendCoAPNotification (observation->resUri, observation->addr,
@@ -1724,7 +1730,7 @@ int deleteResource(OCResource *resource) {
             }
 
             resource->resourceProperties = (OCResourceProperty) 0; // Invalidate all Resource Properties.
-            OCNotifyAllObservers((OCResourceHandle)resource);
+            OCNotifyAllObservers((OCResourceHandle)resource, OC_HIGH_QOS);
 
             deleteResourceElements(temp);
             OCFree(temp);
index f594318..2895ae1 100644 (file)
@@ -205,7 +205,7 @@ int main()
         ModeType::Client,
         "0.0.0.0",
         0,
-        QualityOfService::NonConfirmable
+        QualityOfService::LowQos
     };
 
     ClientFridge cf (cfg);
index dcc575f..3f80836 100644 (file)
@@ -400,7 +400,7 @@ int main ()
         ModeType::Server,
         "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
         0,         // Uses randomly available port
-        QualityOfService::NonConfirmable
+        QualityOfService::LowQos
     };
 
     Refridgerator rf(cfg);
index 20e88ce..a4f5a32 100644 (file)
@@ -274,7 +274,7 @@ int main(int argc, char* argv[]) {
         OC::ModeType::Client,
         "0.0.0.0",
         0,
-        OC::QualityOfService::NonConfirmable
+        OC::QualityOfService::LowQos
     };
 
     // Create a OCPlatform instance.
index 343b2a6..9550437 100644 (file)
@@ -255,7 +255,7 @@ int main(int argc, char* argv[1])
         OC::ModeType::Server,
         "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
         0,         // Uses randomly available port
-        OC::QualityOfService::NonConfirmable
+        OC::QualityOfService::LowQos
     };
 
     // Create a OCPlatform instance.
index d703be3..cb72d09 100644 (file)
@@ -43,11 +43,11 @@ LIB_OC_LOGGER := ../oc_logger/lib/oc_logger.a
 CXX_LIBS  := ../$(BUILD)/obj/liboc.a ../csdk/$(PLATFORM)/$(BUILD)/liboctbstack.a $(LIB_OC_LOGGER)
 
 # Force metatargets to build:
-all.PHONY: prep_dirs oc_cpp_sdk simpleserver simpleclient simpleclientserver roomserver roomclient presenceserver presenceclient garageserver garageclient fridgeserver fridgeclient ocicuc_target
+all.PHONY: prep_dirs oc_cpp_sdk simpleserver simpleserverHQ simpleclient simpleclientHQ simpleclientserver roomserver roomclient presenceserver presenceclient garageserver garageclient fridgeserver fridgeclient ocicuc_target
 
-apps.PHONY: prep_dirs oc_cpp_sdk simpleserver simpleclient simpleclientserver roomserver roomclient presenceserver presenceclient garageserver garageclient fridgeserver fridgeclient
+apps.PHONY: prep_dirs oc_cpp_sdk simpleserver simpleserverHQ simpleclient simpleclientHQ simpleclientserver roomserver roomclient presenceserver presenceclient garageserver garageclient fridgeserver fridgeclient
 
-buildScript_all.PHONY: prep_dirs simpleserver simpleclient simpleclientserver roomserver roomclient presenceserver presenceclient garageserver garageclient fridgeserver fridgeclient
+buildScript_all.PHONY: prep_dirs simpleserver simpleserverHQ simpleclient simpleclientHQ simpleclientserver roomserver roomclient presenceserver presenceclient garageserver garageclient fridgeserver fridgeclient
 
 all: all.PHONY
 
@@ -64,6 +64,12 @@ oc_cpp_sdk:
 simpleserver: simpleserver.cpp
        $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OUT_DIR)/$@ simpleserver.cpp $(CXX_INC) $(CXX_LIBS)
 
+simpleserverHQ: simpleserverHQ.cpp
+       $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OUT_DIR)/$@ simpleserverHQ.cpp $(CXX_INC) $(CXX_LIBS)
+
+simpleclientHQ: simpleclientHQ.cpp
+       $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OUT_DIR)/$@ simpleclientHQ.cpp $(CXX_INC) $(CXX_LIBS)
+
 simpleclient: simpleclient.cpp
        $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OUT_DIR)/$@ simpleclient.cpp $(CXX_INC) $(CXX_LIBS)
 
index 9673a46..3e509c0 100644 (file)
@@ -69,7 +69,7 @@ int exec(const boost::program_options::variables_map& vm)
                           OC::ModeType::Client,                 // client mode
                           vm["host_ip"].as<string>(),           // host
                           vm["host_port"].as<uint16_t>(),       // port
-                          OC::QualityOfService::NonConfirmable
+                          OC::QualityOfService::LowQos
                         });
 
  vector<string> resource_URIs;
index d58ff09..9c462f0 100644 (file)
@@ -26,7 +26,7 @@ OCRepresentation LightResource::getRepresentation(void)
 void LightResource::addType(const OC::OCPlatform& platform, const std::string& type) const
 {
  OCStackResult result = platform.bindTypeToResource(m_resourceHandle, type);
+
  if(OC_STACK_OK != result)
   cout << "Binding TypeName to Resource was unsuccessful, result was " << result << '\n';
 }
@@ -49,8 +49,8 @@ void LightResource::createResource(OC::OCPlatform& platform, const unsigned int
  // This will internally create and register the resource, binding the current instance's method as a callback:
  OCStackResult result = platform.registerResource(
                                             m_resourceHandle, resourceURI, resourceTypeName,
-                                            DEFAULT_INTERFACE, 
-                                            std::bind(&LightResource::entityHandler, this, std::placeholders::_1, std::placeholders::_2), 
+                                            DEFAULT_INTERFACE,
+                                            std::bind(&LightResource::entityHandler, this, std::placeholders::_1, std::placeholders::_2),
                                             OC_DISCOVERABLE | OC_OBSERVABLE);
   if (OC_STACK_OK != result)
    std::cout << "Resource creation failed.\n";
@@ -69,7 +69,7 @@ void LightResource::observe_function()
 
     m_power += 10;
 
-    const auto result = OCPlatform::notifyAllObservers(getHandle());
+    const auto result = m_platform.notifyAllObservers(getHandle());
 
     // Stop notifications when there are no more observers:
     if(OC_STACK_NO_OBSERVERS == result)
@@ -113,7 +113,7 @@ void LightResource::entityHandler(std::shared_ptr<OCResourceRequest> request, st
         return;
      }
 
-    switch(request->getRequestHandlerFlag())   
+    switch(request->getRequestHandlerFlag())
     {
         default:
                 cerr << "entityHandler(): invalid request flag\n";
@@ -133,7 +133,7 @@ void LightResource::entityHandler(std::shared_ptr<OCResourceRequest> request, st
     }
 }
 
-void LightResource::dispatch_request(const std::string& request_type, std::shared_ptr<OCResourceRequest> request, std::shared_ptr<OCResourceResponse> response) 
+void LightResource::dispatch_request(const std::string& request_type, std::shared_ptr<OCResourceRequest> request, std::shared_ptr<OCResourceResponse> response)
 {
  std::cout << "dispatch_request(): " << request_type << '\n';
 
@@ -152,7 +152,7 @@ void LightResource::dispatch_request(const std::string& request_type, std::share
  cerr << "entityHandler(): Invalid request type \"" << request_type << "\".\n";
 }
 
-void LightResource::handle_get_request(std::shared_ptr<OCResourceRequest> request, std::shared_ptr<OCResourceResponse> response) 
+void LightResource::handle_get_request(std::shared_ptr<OCResourceRequest> request, std::shared_ptr<OCResourceResponse> response)
 {
  cout << "handle_get_request():\n";
 
@@ -165,7 +165,7 @@ void LightResource::handle_get_request(std::shared_ptr<OCResourceRequest> reques
  response->setResourceRepresentation(getRepresentation());
 }
 
-void LightResource::handle_put_request(std::shared_ptr<OCResourceRequest> request, std::shared_ptr<OCResourceResponse> response) 
+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();
@@ -179,7 +179,7 @@ void LightResource::handle_put_request(std::shared_ptr<OCResourceRequest> reques
   return;
 
  response->setErrorCode(200);
- response->setResourceRepresentation(getRepresentation()); 
+ response->setResourceRepresentation(getRepresentation());
 }
 
 void LightResource::handle_post_request(std::shared_ptr<OCResourceRequest> request, std::shared_ptr<OCResourceResponse> response)
@@ -187,16 +187,16 @@ void LightResource::handle_post_request(std::shared_ptr<OCResourceRequest> reque
  // ...demo-code...
 }
 
-void LightResource::handle_delete_request(std::shared_ptr<OCResourceRequest> request, std::shared_ptr<OCResourceResponse> response) 
+void LightResource::handle_delete_request(std::shared_ptr<OCResourceRequest> request, std::shared_ptr<OCResourceResponse> response)
 {
  // ...demo-code...
 }
 
 // Set up observation in a separate thread:
-void LightResource::handle_observe_event(std::shared_ptr<OCResourceRequest> request, std::shared_ptr<OCResourceResponse> response) 
+void LightResource::handle_observe_event(std::shared_ptr<OCResourceRequest> request, std::shared_ptr<OCResourceResponse> response)
 {
  if(observe_thread.joinable())
-  return; 
+  return;
 
  observe_thread = thread(bind(&LightResource::observe_function, this));
  observe_thread.detach();
index f4b2cd6..556d61b 100644 (file)
@@ -25,6 +25,7 @@ using namespace std;
 class LightResource
 {
  public:
+    OCPlatform& m_platform;
     bool m_state;       // off or on?
     int m_power;        // power level
     OCRepresentation m_rep;
@@ -40,8 +41,9 @@ class LightResource
     OCResourceHandle m_resourceHandle;
 
     public:
-    LightResource()
-     : m_state(false), 
+    LightResource(OCPlatform& platform)
+     : m_platform(platform),
+       m_state(false),
        m_power(0),
        m_observation(false)
     {}
@@ -57,7 +59,7 @@ class LightResource
     private:
     inline std::string make_URI(const unsigned int resource_number)
     {
-        std::string uri = std::string("/a/light") + "_" + std::to_string(resource_number); 
+        std::string uri = std::string("/a/light") + "_" + std::to_string(resource_number);
         m_rep.setUri(uri);
         return uri;
     }
@@ -92,4 +94,4 @@ class LightResource
 
 }} // namespace Intel::OCDemo
 
-#endif 
+#endif
index 72d974e..dc2175f 100644 (file)
@@ -176,7 +176,7 @@ void server_t::init()
   {
     cout << "Registering resource " << resource_number << ": " << std::flush;
 
-    auto lr = make_shared<Intel::OCDemo::LightResource>();
+    auto lr = make_shared<Intel::OCDemo::LightResource>(m_platform);
 
     lr->createResource(m_platform, resource_number);
     lr->addType(m_platform, "core.brightlight");
@@ -199,7 +199,7 @@ int exec(const boost::program_options::variables_map& vm)
                           OC::ModeType::Both,                   // run in client/server mode
                           vm["host_ip"].as<string>(),           // host
                           vm["host_port"].as<uint16_t>(),       // port
-                          OC::QualityOfService::NonConfirmable
+                          OC::QualityOfService::LowQos
                         });
 
  std::cout << "Ok." << std::endl;
index 64b5028..990bc45 100644 (file)
@@ -57,7 +57,7 @@ int exec(const boost::program_options::variables_map& vm)
                           OC::ModeType::Server,                 // run in server mode
                           vm["host_ip"].as<string>(),           // host
                           vm["host_port"].as<uint16_t>(),       // port
-                          OC::QualityOfService::NonConfirmable
+                          OC::QualityOfService::LowQos
                         });
 
  std::cout << "Ok." << std::endl;
@@ -72,7 +72,7 @@ int exec(const boost::program_options::variables_map& vm)
   {
         cout << "Registering resource " << resource_number << ": " << std::flush;
 
-        auto lr = make_shared<Intel::OCDemo::LightResource>();
+        auto lr = make_shared<Intel::OCDemo::LightResource>(platform);
 
         lr->createResource(platform, resource_number);
         lr->addType(platform, std::string("core.brightlight"));
index bd9cade..f74d27f 100644 (file)
@@ -118,7 +118,7 @@ int main(int argc, char* argv[]) {
         OC::ModeType::Client,
         "0.0.0.0",
         0,
-        OC::QualityOfService::NonConfirmable
+        OC::QualityOfService::LowQos
     };
 
     // Create a OCPlatform instance.
index db2163c..5414344 100644 (file)
@@ -163,7 +163,7 @@ int main()
         OC::ModeType::Server,
         "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
         0,         // Uses randomly available port
-        OC::QualityOfService::NonConfirmable
+        OC::QualityOfService::LowQos
     };
 
     // Create a OCPlatform instance.
index e39cafe..9630925 100644 (file)
@@ -227,7 +227,7 @@ int main(int argc, char* argv[]) {
         OC::ModeType::Client,
         "0.0.0.0",
         0,
-        OC::QualityOfService::NonConfirmable
+        OC::QualityOfService::LowQos
     };
 
     // Create a OCPlatform instance.
index 5953544..2056ad8 100644 (file)
@@ -468,7 +468,7 @@ int main()
         OC::ModeType::Server,
         "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
         0,         // Uses randomly available port
-        OC::QualityOfService::NonConfirmable
+        OC::QualityOfService::LowQos
     };
 
     // Create a OCPlatform instance.
index 8c4cb1a..bf3bf93 100644 (file)
@@ -360,7 +360,7 @@ int main(int argc, char* argv[]) {
         OC::ModeType::Client,
         "0.0.0.0",
         0,
-        OC::QualityOfService::NonConfirmable
+        OC::QualityOfService::LowQos
     };
 
     // Create a OCPlatform instance.
diff --git a/examples/simpleclientHQ.cpp b/examples/simpleclientHQ.cpp
new file mode 100644 (file)
index 0000000..995b2a1
--- /dev/null
@@ -0,0 +1,402 @@
+//******************************************************************
+//
+// Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+// OCClient.cpp : Defines the entry point for the console application.
+//
+#include <string>
+#include <cstdlib>
+#include <pthread.h>
+#include "OCPlatform.h"
+#include "OCApi.h"
+
+using namespace OC;
+
+const int SUCCESS_RESPONSE = 0;
+std::shared_ptr<OCResource> curResource;
+static ObserveType OBSERVE_TYPE_TO_USE = ObserveType::Observe;
+
+class Light
+{
+public:
+
+    bool m_state;
+    int m_power;
+    std::string m_name;
+
+    Light() : m_state(false), m_power(0), m_name("")
+    {
+    }
+};
+
+Light mylight;
+
+int observe_count()
+{
+    static int oc = 0;
+    return ++oc;
+}
+
+void onObserve(const HeaderOptions headerOptions, const OCRepresentation& rep,
+                    const int& eCode, const int& sequenceNumber)
+{
+    if(eCode == SUCCESS_RESPONSE)
+    {
+        std::cout << "OBSERVE RESULT:"<<std::endl;
+        if(sequenceNumber == 0)
+        {
+            std::cout << "\tObserve Registration Confirmed: "<< endl;
+        }
+        else if (sequenceNumber == 1)
+        {
+            std::cout << "\tObserve Cancel Confirmed: "<< endl;
+            sleep(10);
+            std::cout << "DONE"<<std::endl;
+            std::exit(0);
+        }
+        else
+        {
+            std::cout << "\tSequenceNumber: "<< sequenceNumber << endl;
+        }
+
+        rep.getValue("state", mylight.m_state);
+        rep.getValue("power", mylight.m_power);
+        rep.getValue("name", mylight.m_name);
+
+        std::cout << "\tstate: " << mylight.m_state << std::endl;
+        std::cout << "\tpower: " << mylight.m_power << std::endl;
+        std::cout << "\tname: " << mylight.m_name << std::endl;
+
+        if(observe_count() > 30)
+        {
+            std::cout<<"Cancelling Observe..."<<std::endl;
+            OCStackResult result = curResource->cancelObserve(OC::QualityOfService::HighQos);
+
+            std::cout << "Cancel result: "<< result << " waiting for confirmation ..." <<std::endl;
+        }
+    }
+    else
+    {
+        std::cout << "onObserve Response error: " << eCode << std::endl;
+        std::exit(-1);
+    }
+}
+
+void onPost2(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+{
+    if(eCode == SUCCESS_RESPONSE)
+    {
+        std::cout << "POST request was successful" << std::endl;
+
+        if(rep.hasAttribute("createduri"))
+        {
+            std::cout << "\tUri of the created resource: "
+                      << rep.getValue<std::string>("createduri") << std::endl;
+        }
+        else
+        {
+            rep.getValue("state", mylight.m_state);
+            rep.getValue("power", mylight.m_power);
+            rep.getValue("name", mylight.m_name);
+
+            std::cout << "\tstate: " << mylight.m_state << std::endl;
+            std::cout << "\tpower: " << mylight.m_power << std::endl;
+            std::cout << "\tname: " << mylight.m_name << 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;
+        sleep(1);
+        curResource->observe(OBSERVE_TYPE_TO_USE, QueryParamsMap(), &onObserve,
+                OC::QualityOfService::HighQos);
+
+    }
+    else
+    {
+        std::cout << "onPost Response error: " << eCode << std::endl;
+        std::exit(-1);
+    }
+}
+
+void onPost(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+{
+    if(eCode == SUCCESS_RESPONSE)
+    {
+        std::cout << "POST request was successful" << std::endl;
+
+        if(rep.hasAttribute("createduri"))
+        {
+            std::cout << "\tUri of the created resource: "
+                      << rep.getValue<std::string>("createduri") << std::endl;
+        }
+        else
+        {
+            rep.getValue("state", mylight.m_state);
+            rep.getValue("power", mylight.m_power);
+            rep.getValue("name", mylight.m_name);
+
+            std::cout << "\tstate: " << mylight.m_state << std::endl;
+            std::cout << "\tpower: " << mylight.m_power << std::endl;
+            std::cout << "\tname: " << mylight.m_name << std::endl;
+        }
+
+        OCRepresentation rep2;
+
+        std::cout << "Posting light representation..."<<std::endl;
+
+        mylight.m_state = true;
+        mylight.m_power = 55;
+
+        rep2.setValue("state", mylight.m_state);
+        rep2.setValue("power", mylight.m_power);
+        sleep(1);
+        curResource->post(rep2, QueryParamsMap(), &onPost2, OC::QualityOfService::HighQos);
+    }
+    else
+    {
+        std::cout << "onPost Response error: " << eCode << std::endl;
+        std::exit(-1);
+    }
+}
+
+// Local function to put a different state for this resource
+void postLightRepresentation(std::shared_ptr<OCResource> resource)
+{
+    if(resource)
+    {
+        OCRepresentation rep;
+
+        std::cout << "Posting light representation..."<<std::endl;
+
+        mylight.m_state = false;
+        mylight.m_power = 105;
+
+        rep.setValue("state", mylight.m_state);
+        rep.setValue("power", mylight.m_power);
+
+        // Invoke resource's post API with rep, query map and the callback parameter
+        resource->post(rep, QueryParamsMap(), &onPost, OC::QualityOfService::HighQos);
+    }
+}
+
+// callback handler on PUT request
+void onPut(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+{
+    if(eCode == SUCCESS_RESPONSE)
+    {
+        std::cout << "PUT request was successful" << std::endl;
+
+        rep.getValue("state", mylight.m_state);
+        rep.getValue("power", mylight.m_power);
+        rep.getValue("name", mylight.m_name);
+
+        std::cout << "\tstate: " << mylight.m_state << std::endl;
+        std::cout << "\tpower: " << mylight.m_power << std::endl;
+        std::cout << "\tname: " << mylight.m_name << std::endl;
+        sleep(1);
+        postLightRepresentation(curResource);
+    }
+    else
+    {
+        std::cout << "onPut Response error: " << eCode << std::endl;
+        std::exit(-1);
+    }
+}
+
+// Local function to put a different state for this resource
+void putLightRepresentation(std::shared_ptr<OCResource> resource)
+{
+    if(resource)
+    {
+        OCRepresentation rep;
+
+        std::cout << "Putting light representation..."<<std::endl;
+
+        mylight.m_state = true;
+        mylight.m_power = 15;
+
+        rep.setValue("state", mylight.m_state);
+        rep.setValue("power", mylight.m_power);
+
+        // Invoke resource's put API with rep, query map and the callback parameter
+        resource->put(rep, QueryParamsMap(), &onPut, OC::QualityOfService::HighQos);
+    }
+}
+
+// Callback handler on GET request
+void onGet(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+{
+    if(eCode == SUCCESS_RESPONSE)
+    {
+        std::cout << "GET request was successful" << std::endl;
+        std::cout << "Resource URI: " << rep.getUri() << std::endl;
+
+        rep.getValue("state", mylight.m_state);
+        rep.getValue("power", mylight.m_power);
+        rep.getValue("name", mylight.m_name);
+
+        std::cout << "\tstate: " << mylight.m_state << std::endl;
+        std::cout << "\tpower: " << mylight.m_power << std::endl;
+        std::cout << "\tname: " << mylight.m_name << std::endl;
+        sleep(1);
+        putLightRepresentation(curResource);
+    }
+    else
+    {
+        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)
+{
+    if(resource)
+    {
+        std::cout << "Getting Light Representation..."<<std::endl;
+        // Invoke resource's get API with the callback parameter
+
+        QueryParamsMap test;
+        resource->get(test, &onGet,OC::QualityOfService::HighQos);
+    }
+}
+
+// Callback to found resources
+void foundResource(std::shared_ptr<OCResource> resource)
+{
+    if(curResource)
+    {
+        std::cout << "Found another resource, ignoring"<<std::endl;
+    }
+
+    std::string resourceURI;
+    std::string hostAddress;
+    try
+    {
+        // Do some operations with resource object.
+        if(resource)
+        {
+            std::cout<<"DISCOVERED Resource:"<<std::endl;
+            // Get the resource URI
+            resourceURI = resource->uri();
+            std::cout << "\tURI of the resource: " << resourceURI << std::endl;
+
+            // Get the resource host address
+            hostAddress = resource->host();
+            std::cout << "\tHost address of the resource: " << hostAddress << std::endl;
+
+            // Get the resource types
+            std::cout << "\tList of resource types: " << std::endl;
+            for(auto &resourceTypes : resource->getResourceTypes())
+            {
+                std::cout << "\t\t" << resourceTypes << std::endl;
+            }
+
+            // Get the resource interfaces
+            std::cout << "\tList of resource interfaces: " << std::endl;
+            for(auto &resourceInterfaces : resource->getResourceInterfaces())
+            {
+                std::cout << "\t\t" << resourceInterfaces << std::endl;
+            }
+
+            if(resourceURI == "/a/light")
+            {
+                curResource = resource;
+                sleep(1);
+                // Call a local function which will internally invoke get API on the resource pointer
+                getLightRepresentation(resource);
+            }
+        }
+        else
+        {
+            // Resource is invalid
+            std::cout << "Resource is invalid" << std::endl;
+        }
+
+    }
+    catch(std::exception& e)
+    {
+        //log(e.what());
+    }
+}
+
+void PrintUsage()
+{
+    std::cout << std::endl;
+    std::cout << "Usage : simpleclient <ObserveType>" << std::endl;
+    std::cout << "   ObserveType : 1 - Observe" << std::endl;
+    std::cout << "   ObserveType : 2 - ObserveAll" << std::endl;
+}
+
+int main(int argc, char* argv[]) {
+    if (argc == 1)
+    {
+        OBSERVE_TYPE_TO_USE = ObserveType::Observe;
+    }
+    else if (argc == 2)
+    {
+        int value = atoi(argv[1]);
+        if (value == 1)
+            OBSERVE_TYPE_TO_USE = ObserveType::Observe;
+        else if (value == 2)
+            OBSERVE_TYPE_TO_USE = ObserveType::ObserveAll;
+        else
+            OBSERVE_TYPE_TO_USE = ObserveType::Observe;
+    }
+    else
+    {
+        PrintUsage();
+        return -1;
+    }
+
+    // Create PlatformConfig object
+    PlatformConfig cfg {
+        OC::ServiceType::InProc,
+        OC::ModeType::Client,
+        "0.0.0.0",
+        0,
+        OC::QualityOfService::LowQos
+    };
+
+    // Create a OCPlatform instance.
+    // Note: Platform creation is synchronous call.
+
+    try
+    {
+        OCPlatform platform(cfg);
+        std::cout << "Created Platform..."<<std::endl;
+        // Find all resources
+        platform.findResource("", "coap://224.0.1.187/oc/core?rt=core.light", &foundResource,
+                OC::QualityOfService::LowQos);
+        std::cout<< "Finding Resource... " <<std::endl;
+        while(true)
+        {
+            // some operations
+        }
+
+    }catch(OCException& e)
+    {
+        //log(e.what());
+    }
+
+    return 0;
+}
+
index f25806e..44cc2d5 100644 (file)
@@ -278,7 +278,7 @@ int main()
         OC::ModeType::Both,
         "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
         0,         // Uses randomly available port
-        OC::QualityOfService::NonConfirmable
+        OC::QualityOfService::LowQos
     };
 
     FooResource fooRes;
index 3847ff9..e3fcbfd 100644 (file)
@@ -373,7 +373,7 @@ void * ChangeLightRepresentation (void *param)
                 resourceResponse->setErrorCode(200);
                 resourceResponse->setResourceRepresentation(lightPtr->get(), DEFAULT_INTERFACE);
 
-                result = OCPlatform::notifyListOfObservers(  lightPtr->getHandle(),
+                result = lightPtr->m_platform.notifyListOfObservers(  lightPtr->getHandle(),
                                                              lightPtr->m_interestedObservers,
                                                              resourceResponse);
             }
@@ -429,7 +429,7 @@ int main(int argc, char* argv[1])
         OC::ModeType::Server,
         "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
         0,         // Uses randomly available port
-        OC::QualityOfService::NonConfirmable
+        OC::QualityOfService::LowQos
     };
 
     try
diff --git a/examples/simpleserverHQ.cpp b/examples/simpleserverHQ.cpp
new file mode 100644 (file)
index 0000000..58f7ad4
--- /dev/null
@@ -0,0 +1,462 @@
+//******************************************************************
+//
+// Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+///
+/// This sample provides steps to define an interface for a resource
+/// (properties and methods) and host this resource on the server.
+///
+
+#include <functional>
+
+#include <pthread.h>
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+
+using namespace OC;
+using namespace std;
+namespace PH = std::placeholders;
+
+int gObservation = 0;
+void * ChangeLightRepresentation (void *param);
+
+// Specifies where to notify all observers or list of observers
+// 0 - notifies all observers
+// 1 - notifies list of observers
+int isListOfObservers = 0;
+
+// Forward declaring the entityHandler
+
+/// This class represents a single resource named 'lightResource'. This resource has
+/// two simple properties named 'state' and 'power'
+
+class LightResource
+{
+
+public:
+    /// Access this property from a TB client
+    OCPlatform m_platform;
+    std::string m_name;
+    bool m_state;
+    int m_power;
+    std::string m_lightUri;
+    OCResourceHandle m_resourceHandle;
+    OCRepresentation m_lightRep;
+    ObservationIds m_interestedObservers;
+
+public:
+    /// Constructor
+    LightResource(PlatformConfig& cfg): m_platform(cfg),
+            m_name("John's light"), m_state(false), m_power(0), m_lightUri("/a/light") {
+        // Initialize representation
+        m_lightRep.setUri(m_lightUri);
+
+        m_lightRep.setValue("state", m_state);
+        m_lightRep.setValue("power", m_power);
+        m_lightRep.setValue("name", m_name);
+    }
+
+    /* Note that this does not need to be a member function: for classes you do not have
+    access to, you can accomplish this with a free function: */
+
+    /// This function internally calls registerResource API.
+    void createResource()
+    {
+        std::string resourceURI = m_lightUri; // URI of the resource
+        std::string resourceTypeName = "core.light"; // resource type name. In this case, it is light
+        std::string resourceInterface = DEFAULT_INTERFACE; // resource interface.
+
+        // OCResourceProperty is defined ocstack.h
+        uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
+
+        EntityHandler cb = std::bind(&LightResource::entityHandler, this,PH::_1, PH::_2);
+
+        // This will internally create and register the resource.
+        OCStackResult result = m_platform.registerResource(
+                                    m_resourceHandle, resourceURI, resourceTypeName,
+                                    resourceInterface, cb, resourceProperty);
+
+        if (OC_STACK_OK != result)
+        {
+            cout << "Resource creation was unsuccessful\n";
+        }
+    }
+
+    OCStackResult createResource1()
+    {
+        std::string resourceURI = "/a/light1"; // URI of the resource
+        std::string resourceTypeName = "core.light"; // resource type name. In this case, it is light
+        std::string resourceInterface = DEFAULT_INTERFACE; // resource interface.
+
+        // OCResourceProperty is defined ocstack.h
+        uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
+
+        EntityHandler cb = std::bind(&LightResource::entityHandler, this,PH::_1, PH::_2);
+
+        OCResourceHandle resHandle;
+
+        // This will internally create and register the resource.
+        OCStackResult result = m_platform.registerResource(
+                                    resHandle, resourceURI, resourceTypeName,
+                                    resourceInterface, cb, resourceProperty);
+
+        if (OC_STACK_OK != result)
+        {
+            cout << "Resource creation was unsuccessful\n";
+        }
+
+        return result;
+    }
+
+    OCResourceHandle getHandle()
+    {
+        return m_resourceHandle;
+    }
+
+    // Puts representation.
+    // Gets values from the representation and
+    // updates the internal state
+    void put(OCRepresentation& rep)
+    {
+        try {
+            if (rep.getValue("state", m_state))
+            {
+                cout << "\t\t\t\t" << "state: " << m_state << endl;
+            }
+            else
+            {
+                cout << "\t\t\t\t" << "state not found in the representation" << endl;
+            }
+
+            if (rep.getValue("power", m_power))
+            {
+                cout << "\t\t\t\t" << "power: " << m_power << endl;
+            }
+            else
+            {
+                cout << "\t\t\t\t" << "power not found in the representation" << endl;
+            }
+        }
+        catch (exception& e)
+        {
+            cout << e.what() << endl;
+        }
+
+    }
+
+    // Post representation.
+    // Post can create new resource or simply act like put.
+    // Gets values from the representation and
+    // updates the internal state
+    OCRepresentation post(OCRepresentation& rep)
+    {
+        static int first = 1;
+
+        std::cout << "In POST\n";
+
+        // for the first time it tries to create a resource
+        if(first)
+        {
+            std::cout << "In POST/First\n";
+
+            first = 0;
+
+            if(OC_STACK_OK == createResource1())
+            {
+                std::cout << "Created a new resource\n";
+
+                OCRepresentation rep1;
+                rep1.setValue("createduri", std::string("/a/light1"));
+
+                return rep1;
+            }
+        }
+
+        // from second time onwards it just puts
+        put(rep);
+        return get();
+    }
+
+
+    // gets the updated representation.
+    // Updates the representation with latest internal state before
+    // sending out.
+    OCRepresentation get()
+    {
+        m_lightRep.setValue("state", m_state);
+        m_lightRep.setValue("power", m_power);
+
+        return m_lightRep;
+    }
+
+    void addType(const std::string& type) const
+    {
+        OCStackResult result = m_platform.bindTypeToResource(m_resourceHandle, type);
+        if (OC_STACK_OK != result)
+        {
+            cout << "Binding TypeName to Resource was unsuccessful\n";
+        }
+    }
+
+    void addInterface(const std::string& interface) const
+    {
+        OCStackResult result = m_platform.bindInterfaceToResource(m_resourceHandle, interface);
+        if (OC_STACK_OK != result)
+        {
+            cout << "Binding TypeName to Resource was unsuccessful\n";
+        }
+    }
+
+private:
+// This is just a sample implementation of entity handler.
+// Entity handler can be implemented in several ways by the manufacturer
+void entityHandler(std::shared_ptr<OCResourceRequest> request, std::shared_ptr<OCResourceResponse> response)
+{
+    cout << "\tIn Server CPP entity handler:\n";
+
+    if(request)
+    {
+        // Get the request type and request flag
+        std::string requestType = request->getRequestType();
+        int requestFlag = request->getRequestHandlerFlag();
+
+        if(requestFlag & RequestHandlerFlag::InitFlag)
+        {
+            cout << "\t\trequestFlag : Init\n";
+
+            // entity handler to perform resource initialization operations
+        }
+        if(requestFlag & RequestHandlerFlag::RequestFlag)
+        {
+            cout << "\t\trequestFlag : Request\n";
+
+            // If the request type is GET
+            if(requestType == "GET")
+            {
+                cout << "\t\t\trequestType : GET\n";
+
+                if(response)
+                {
+                    // TODO Error Code
+                    response->setErrorCode(200);
+
+                    response->setResourceRepresentation(get());
+                }
+            }
+            else if(requestType == "PUT")
+            {
+                cout << "\t\t\trequestType : PUT\n";
+
+                OCRepresentation rep = request->getResourceRepresentation();
+
+                // Do related operations related to PUT request
+
+                // Update the lightResource
+                put(rep);
+
+                if(response)
+                {
+                    // TODO Error Code
+                    response->setErrorCode(200);
+
+                    response->setResourceRepresentation(get());
+                }
+
+            }
+            else if(requestType == "POST")
+            {
+                cout << "\t\t\trequestType : POST\n";
+
+                OCRepresentation rep = request->getResourceRepresentation();
+
+                // Do related operations related to POST request
+
+                OCRepresentation rep_post = post(rep);
+
+                if(response)
+                {
+                    // TODO Error Code
+                    response->setErrorCode(200);
+
+                    response->setResourceRepresentation(rep_post);
+                }
+
+                // POST request operations
+            }
+            else if(requestType == "DELETE")
+            {
+                // DELETE request operations
+            }
+        }
+
+        if(requestFlag & RequestHandlerFlag::ObserverFlag)
+        {
+            ObservationInfo observationInfo = request->getObservationInfo();
+            if(ObserveAction::ObserveRegister == observationInfo.action)
+            {
+                m_interestedObservers.push_back(observationInfo.obsId);
+            }
+            else if(ObserveAction::ObserveUnregister == observationInfo.action)
+            {
+                m_interestedObservers.erase(std::remove(
+                                                            m_interestedObservers.begin(),
+                                                            m_interestedObservers.end(),
+                                                            observationInfo.obsId),
+                                                            m_interestedObservers.end());
+            }
+
+            pthread_t threadId;
+
+            cout << "\t\trequestFlag : Observer\n";
+            gObservation = 1;
+            static int startedThread = 0;
+
+            // Observation happens on a different thread in ChangeLightRepresentation function.
+            // If we have not created the thread already, we will create one here.
+            if(!startedThread)
+            {
+                pthread_create (&threadId, NULL, ChangeLightRepresentation, (void *)this);
+                startedThread = 1;
+            }
+        }
+    }
+    else
+    {
+        std::cout << "Request invalid" << std::endl;
+    }
+}
+
+};
+
+// ChangeLightRepresentaion is an observation function,
+// which notifies any changes to the resource to stack
+// via notifyObservers
+void * ChangeLightRepresentation (void *param)
+{
+    LightResource* lightPtr = (LightResource*) param;
+
+    // This function continuously monitors for the changes
+    while (1)
+    {
+        sleep (5);
+
+        if (gObservation)
+        {
+            // If under observation if there are any changes to the light resource
+            // we call notifyObservors
+            //
+            // For demostration we are changing the power value and notifying.
+            lightPtr->m_power += 10;
+
+            cout << "\nPower updated to : " << lightPtr->m_power << endl;
+            cout << "Notifying observers with resource handle: " << lightPtr->getHandle() << endl;
+
+            OCStackResult result = OC_STACK_OK;
+
+            if(isListOfObservers)
+            {
+                std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
+
+                resourceResponse->setErrorCode(200);
+                resourceResponse->setResourceRepresentation(lightPtr->get(), DEFAULT_INTERFACE);
+
+                result = lightPtr->m_platform.notifyListOfObservers(  lightPtr->getHandle(),
+                                                             lightPtr->m_interestedObservers,
+                                                             resourceResponse, OC::QualityOfService::HighQos);
+            }
+            else
+            {
+                result = lightPtr->m_platform.notifyAllObservers(lightPtr->getHandle(), OC::QualityOfService::HighQos);
+            }
+
+            if(OC_STACK_NO_OBSERVERS == result)
+            {
+                cout << "No More observers, stopping notifications" << endl;
+                gObservation = 0;
+            }
+        }
+    }
+
+    return NULL;
+}
+
+void PrintUsage()
+{
+    std::cout << std::endl;
+    std::cout << "Usage : simplserver <isListOfObservers>\n";
+    std::cout << "   ObserveType : 0 - Observe All\n";
+    std::cout << "   ObserveType : 1 - Observe List of observers\n\n";
+}
+
+
+int main(int argc, char* argv[1])
+{
+    PrintUsage();
+
+    if (argc == 1)
+    {
+        isListOfObservers = 0;
+    }
+    else if (argc == 2)
+    {
+        int value = atoi(argv[1]);
+        if (value == 1)
+            isListOfObservers = 1;
+        else
+            isListOfObservers = 0;
+    }
+    else
+    {
+        return -1;
+    }
+
+    // Create PlatformConfig object
+    PlatformConfig cfg {
+        OC::ServiceType::InProc,
+        OC::ModeType::Server,
+        "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
+        0,         // Uses randomly available port
+        OC::QualityOfService::LowQos
+    };
+
+    try
+    {
+        // Create the instance of the resource class (in this case instance of class 'LightResource').
+        LightResource myLight(cfg);
+
+        // Invoke createResource function of class light.
+        myLight.createResource();
+
+        myLight.addType(std::string("core.brightlight"));
+        myLight.addInterface(std::string("oc.mi.ll"));
+        // Perform app tasks
+        while(true)
+        {
+            // some tasks
+        }
+    }
+    catch(OCException e)
+    {
+        //log(e.what());
+    }
+
+    // No explicit call to stop the platform.
+    // When OCPlatform destructor is invoked, internally we do platform cleanup
+}
index dc3f545..e3244c9 100644 (file)
@@ -43,36 +43,39 @@ namespace OC
         {}
 
         virtual OCStackResult ListenForResource(const std::string& serviceUrl,
-                        const std::string& resourceType, FindCallback& callback) = 0;
+                        const std::string& resourceType, FindCallback& callback,
+                        QualityOfService QoS) = 0;
 
         virtual OCStackResult GetResourceRepresentation(const std::string& host,
                         const std::string& uri, const QueryParamsMap& queryParams,
                         const HeaderOptions& headerOptions,
-                        GetCallback& callback)=0;
+                        GetCallback& callback, QualityOfService QoS)=0;
 
         virtual OCStackResult PutResourceRepresentation(const std::string& host,
                         const std::string& uri, const OCRepresentation& rep,
                         const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
-                        PutCallback& callback) = 0;
+                        PutCallback& callback, QualityOfService QoS) = 0;
 
         virtual OCStackResult PostResourceRepresentation(const std::string& host,
                         const std::string& uri, const OCRepresentation& rep,
                         const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
-                        PostCallback& callback) = 0;
+                        PostCallback& callback, QualityOfService QoS) = 0;
 
         virtual OCStackResult ObserveResource(ObserveType observeType, OCDoHandle* handle,
                         const std::string& host, const std::string& uri,
                         const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
-                        ObserveCallback& callback)=0;
+                        ObserveCallback& callback, QualityOfService QoS)=0;
 
         virtual OCStackResult CancelObserveResource(OCDoHandle handle, const std::string& host,
-            const std::string& uri, const HeaderOptions& headerOptions)=0;
+            const std::string& uri, const HeaderOptions& headerOptions, QualityOfService QoS)=0;
 
         virtual OCStackResult SubscribePresence(OCDoHandle* handle, const std::string& host,
                         SubscribeCallback& presenceHandler)=0;
 
         virtual OCStackResult UnsubscribePresence(OCDoHandle handle) =0;
 
+        virtual OCStackResult GetDefaultQos(QualityOfService& qos) = 0;
+
         virtual ~IClientWrapper(){}
 
 
index 431ba1d..f702c98 100644 (file)
@@ -45,29 +45,30 @@ namespace OC
         virtual ~InProcClientWrapper();
 
         virtual OCStackResult ListenForResource(const std::string& serviceUrl,
-            const std::string& resourceType, FindCallback& callback);
+            const std::string& resourceType, FindCallback& callback,
+            QualityOfService QoS);
 
         virtual OCStackResult GetResourceRepresentation(const std::string& host,
             const std::string& uri, const QueryParamsMap& queryParams,
             const HeaderOptions& headerOptions,
-            GetCallback& callback);
+            GetCallback& callback, QualityOfService QoS);
 
         virtual OCStackResult PutResourceRepresentation(const std::string& host,
             const std::string& uri, const OCRepresentation& attributes,
             const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
-            PutCallback& callback);
+            PutCallback& callback, QualityOfService QoS);
 
         virtual OCStackResult PostResourceRepresentation(const std::string& host,
             const std::string& uri, const OCRepresentation& attributes,
             const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
-            PostCallback& callback);
+            PostCallback& callback, QualityOfService QoS);
 
         virtual OCStackResult ObserveResource(ObserveType observeType, OCDoHandle* handle,
             const std::string& host, const std::string& uri, const QueryParamsMap& queryParams,
-            const HeaderOptions& headerOptions, ObserveCallback& callback);
+            const HeaderOptions& headerOptions, ObserveCallback& callback, QualityOfService QoS);
 
         virtual OCStackResult CancelObserveResource(OCDoHandle handle, const std::string& host,
-            const std::string& uri, const HeaderOptions& headerOptions);
+            const std::string& uri, const HeaderOptions& headerOptions, QualityOfService QoS);
 
         virtual OCStackResult SubscribePresence(OCDoHandle* handle, const std::string& host,
             SubscribeCallback& presenceHandler);
@@ -77,6 +78,8 @@ namespace OC
         // It is public becuase that needs to be a non-instance callback
         virtual std::shared_ptr<OCResource> parseOCResource(IClientWrapper::Ptr clientWrapper,
             const std::string& host, const boost::property_tree::ptree resourceNode);
+
+        OCStackResult GetDefaultQos(QualityOfService& QoS);
     private:
         void listeningFunc();
         std::string assembleSetResourceUri(std::string uri, const QueryParamsMap& queryParams);
index 2fb944e..5bf0afe 100644 (file)
@@ -101,8 +101,10 @@ namespace OC
 
     enum class QualityOfService : uint8_t
     {
-        Confirmable     = OC_CONFIRMABLE,
-        NonConfirmable  = OC_NON_CONFIRMABLE
+        LowQos      = OC_LOW_QOS,
+        MidQos      = OC_MEDIUM_QOS,
+        HighQos     = OC_HIGH_QOS,
+        NaQos       = OC_NA_QOS // No Quality is defined, let the stack decide
     };
 
     /**
index 110b478..1844049 100644 (file)
@@ -69,13 +69,15 @@ namespace OC
         * API for notifying base that resource's attributes have changed.
         *
         * @param OCResourceHandle resource handle of the resource
+        * @param QualityOfService the quality of communication
         *
         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
         * NOTE: This API is for server side only.
         * NOTE: OCResourceHandle is defined in ocstack.h.
         * NOTE: OCStackResult is defined in ocstack.h.
         */
-        static OCStackResult notifyAllObservers(OCResourceHandle resourceHandle);
+        OCStackResult notifyAllObservers(OCResourceHandle resourceHandle);
+        OCStackResult notifyAllObservers(OCResourceHandle resourceHandle, QualityOfService QoS);
 
         /**
         * API for notifying only specific clients that resource's attributes have changed.
@@ -85,6 +87,7 @@ namespace OC
         * which will be notified upon resource change.
         * @param responsePtr OCResourceResponse pointer used by app to fill the response for this
         * resource change.
+        * @param QualityOfService the quality of communication
         *
         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
         *
@@ -92,10 +95,15 @@ namespace OC
         * NOTE: OCResourceHandle is defined in ocstack.h.
         * NOTE: OCStackResult is defined in ocstack.h.
         */
-        static OCStackResult notifyListOfObservers(
-                                OCResourceHandle resourceHandle,
-                                ObservationIds& observationIds,
-                                const std::shared_ptr<OCResourceResponse> responsePtr);
+        OCStackResult notifyListOfObservers(
+                    OCResourceHandle resourceHandle,
+                    ObservationIds& observationIds,
+                    const std::shared_ptr<OCResourceResponse> responsePtr);
+        OCStackResult notifyListOfObservers(
+                    OCResourceHandle resourceHandle,
+                    ObservationIds& observationIds,
+                    const std::shared_ptr<OCResourceResponse> responsePtr,
+                    QualityOfService QoS);
 
         /**
         * API for Service and Resource Discovery.
@@ -113,6 +121,7 @@ namespace OC
         *        (Not Empty, NULL/Empty) - Performs ALL resource discovery on a particular service.
         *        (Not Empty, Not Empty) - Performs query for a filtered/scoped/particular resource(s)
         *                                  from a particular service.
+        * @param QualityOfService the quality of communication
         *
         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
         * NOTE: First parameter 'host' currently represents an IP address. This will change in future
@@ -120,7 +129,9 @@ namespace OC
         * NOTE: OCStackResult is defined in ocstack.h.
         */
         OCStackResult findResource(const std::string& host, const std::string& resourceURI,
-            FindCallback resourceHandler);
+                    FindCallback resourceHandler);
+        OCStackResult findResource(const std::string& host, const std::string& resourceURI,
+                    FindCallback resourceHandler, QualityOfService QoS);
 
         /**
         * This API registers a resource with the server
index 8e98693..ae52e14 100644 (file)
@@ -68,10 +68,13 @@ namespace OC
         *        The callback function will be invoked with a map of attribute name and values.
         *        The callback function will also have the result from this Get operation
         *        This will have error codes
+        * @param QualityOfService the quality of communication
         * @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, GetCallback attributeHandler);
+        OCStackResult get(const QueryParamsMap& queryParametersMap, GetCallback attributeHandler,
+                          QualityOfService QoS);
 
         /**
         * Function to get the attributes of a resource.
@@ -85,6 +88,7 @@ namespace OC
         *        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
+        * @param QualityOfService the quality of communication
         * @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>
@@ -104,7 +108,10 @@ namespace OC
         * resources at a node.<br>
         */
         OCStackResult get(const std::string& resourceType, const std::string& resourceInterface,
-            const QueryParamsMap& queryParametersMap, GetCallback attributeHandler);
+                        const QueryParamsMap& queryParametersMap, GetCallback attributeHandler);
+        OCStackResult get(const std::string& resourceType, const std::string& resourceInterface,
+                        const QueryParamsMap& queryParametersMap, GetCallback attributeHandler,
+                        QualityOfService QoS);
 
         /**
         * Function to set the representation of a resource (via PUT)
@@ -116,11 +123,15 @@ namespace OC
         *        This will have error codes
         * @param queryParametersMap map which can have the query parameter name and value
         * @param attributeHandler attribute handler
+        * @param QualityOfService the quality of communication
         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
         * NOTE: OCStackResult is defined in ocstack.h.
         */
         OCStackResult put(const OCRepresentation& representation,
-                const QueryParamsMap& queryParametersMap, PutCallback attributeHandler);
+                        const QueryParamsMap& queryParametersMap, PutCallback attributeHandler);
+        OCStackResult put(const OCRepresentation& representation,
+                        const QueryParamsMap& queryParametersMap, PutCallback attributeHandler,
+                        QualityOfService QoS);
 
         /**
         * Function to set the attributes of a resource (via PUT)
@@ -134,13 +145,18 @@ namespace OC
         *        This will have error codes.
         *        The Representation parameter maps 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 QualityOfService the quality of communication
         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
         * NOTE: OCStackResult is defined in ocstack.h. <br>
         */
         OCStackResult put(const std::string& resourceType, const std::string& resourceInterface,
-            const OCRepresentation& representation, const QueryParamsMap& queryParametersMap,
-            PutCallback attributeHandler);
+                        const OCRepresentation& representation, const QueryParamsMap& queryParametersMap,
+                        PutCallback attributeHandler);
+        OCStackResult put(const std::string& resourceType, const std::string& resourceInterface,
+                        const OCRepresentation& representation, const QueryParamsMap& queryParametersMap,
+                        PutCallback attributeHandler, QualityOfService QoS);
 
         /**
         * Function to post on a resource
@@ -152,11 +168,15 @@ namespace OC
         *        This will have error codes
         * @param queryParametersMap map which can have the query parameter name and value
         * @param attributeHandler attribute handler
+        * @param QualityOfService the quality of communication
         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
         * NOTE: OCStackResult is defined in ocstack.h.
         */
         OCStackResult post(const OCRepresentation& representation,
-                const QueryParamsMap& queryParametersMap, PostCallback attributeHandler);
+                        const QueryParamsMap& queryParametersMap, PostCallback attributeHandler);
+        OCStackResult post(const OCRepresentation& representation,
+                        const QueryParamsMap& queryParametersMap, PostCallback attributeHandler,
+                        QualityOfService QoS);
 
         /**
         * Function to post on a resource
@@ -172,12 +192,16 @@ namespace OC
         *        and values
         *        (which will represent entire state of the resource) or a
         *        set of attribute names and values which needs to be modified
+        * @param QualityOfService the quality of communication
         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
         * NOTE: OCStackResult is defined in ocstack.h. <br>
         */
         OCStackResult post(const std::string& resourceType, const std::string& resourceInterface,
-            const OCRepresentation& representation, const QueryParamsMap& queryParametersMap,
-            PostCallback attributeHandler);
+                        const OCRepresentation& representation, const QueryParamsMap& queryParametersMap,
+                        PostCallback attributeHandler);
+        OCStackResult post(const std::string& resourceType, const std::string& resourceInterface,
+                        const OCRepresentation& representation, const QueryParamsMap& queryParametersMap,
+                        PostCallback attributeHandler, QualityOfService QoS);
 
         /**
         * Function to set observation on the resource
@@ -187,11 +211,14 @@ namespace OC
         *        The callback function will be invoked with a map of attribute name and values.
         *        The callback function will also have the result from this observe operation
         *        This will have error codes
+        * @param QualityOfService the quality of communication
         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
         * NOTE: OCStackResult is defined in ocstack.h.
         */
         OCStackResult observe(ObserveType observeType, const QueryParamsMap& queryParametersMap,
-            ObserveCallback observeHandler);
+                        ObserveCallback observeHandler);
+        OCStackResult observe(ObserveType observeType, const QueryParamsMap& queryParametersMap,
+                        ObserveCallback observeHandler, QualityOfService qos);
 
         /**
         * Function to cancel the observation on the resource
@@ -199,6 +226,7 @@ namespace OC
         * NOTE: OCStackResult is defined in ocstack.h.
         */
         OCStackResult cancelObserve();
+        OCStackResult cancelObserve(QualityOfService qos);
 
         /**
         * Function to set header information.
index df8e1cb..ff7833a 100644 (file)
@@ -34,33 +34,36 @@ namespace OC
         {}
 
         virtual OCStackResult ListenForResource(const std::string& serviceUrl,
-            const std::string& resourceType, FindCallback& callback) {return OC_STACK_NOTIMPL;}
+            const std::string& resourceType, FindCallback& callback, QualityOfService QoS)
+            {return OC_STACK_NOTIMPL;}
 
         virtual OCStackResult GetResourceRepresentation(const std::string& host,
             const std::string& uri, const QueryParamsMap& queryParams,
-            const HeaderOptions& headerOptions, GetCallback& callback)
+            const HeaderOptions& headerOptions, GetCallback& callback,
+            QualityOfService QoS)
             {return OC_STACK_NOTIMPL;}
 
         virtual OCStackResult PutResourceRepresentation(const std::string& host,
             const std::string& uri, const OCRepresentation& attributes,
             const QueryParamsMap& queryParams,
-            const HeaderOptions& headerOptions, PutCallback& callback)
+            const HeaderOptions& headerOptions, PutCallback& callback,
+            QualityOfService QoS)
             {return OC_STACK_NOTIMPL;}
 
         virtual OCStackResult PostResourceRepresentation(const std::string& host,
             const std::string& uri, const OCRepresentation& attributes,
             const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
-            PostCallback& callback)
+            PostCallback& callback, QualityOfService QoS)
             {return OC_STACK_NOTIMPL;}
 
         virtual OCStackResult ObserveResource(ObserveType observeType, OCDoHandle* handle,
             const std::string& host, const std::string& uri, const QueryParamsMap& queryParams,
             const HeaderOptions& headerOptions,
-            ObserveCallback& callback){return OC_STACK_NOTIMPL;}
+            ObserveCallback& callback, QualityOfService QoS){return OC_STACK_NOTIMPL;}
 
         virtual OCStackResult CancelObserveResource(OCDoHandle handle, const std::string& host,
             const std::string& uri,
-            const HeaderOptions& headerOptions){return OC_STACK_NOTIMPL;}
+            const HeaderOptions& headerOptions, QualityOfService QoS){return OC_STACK_NOTIMPL;}
 
         virtual std::shared_ptr<OCResource> parseOCResource(IClientWrapper::Ptr clientWrapper,
             const std::string& host, const boost::property_tree::ptree resourceNode)
@@ -72,6 +75,8 @@ namespace OC
             SubscribeCallback& presenceHandler){return OC_STACK_NOTIMPL;}
 
         virtual OCStackResult UnsubscribePresence(OCDoHandle handle){return OC_STACK_NOTIMPL;}
+
+        virtual OCStackResult GetDefaultQos(QualityOfService& QoS){return OC_STACK_NOTIMPL;}
     };
 }
 
index 7f05d57..779caf2 100644 (file)
@@ -218,7 +218,7 @@ namespace OC
     }
 
     OCStackResult InProcClientWrapper::ListenForResource(const std::string& serviceUrl,
-        const std::string& resourceType, FindCallback& callback)
+        const std::string& resourceType, FindCallback& callback, QualityOfService QoS)
     {
         OCStackResult result;
 
@@ -241,7 +241,7 @@ namespace OC
             result = OCDoResource(&handle, OC_REST_GET,
                                   resourceType.c_str(),
                                   nullptr, nullptr,
-                                  static_cast<OCQualityOfService>(m_cfg.QoS),
+                                  static_cast<OCQualityOfService>(QoS),
                                   &cbdata,
                                   NULL, 0);
         }
@@ -266,7 +266,6 @@ namespace OC
     OCRepresentation parseGetSetCallback(OCClientResponse* clientResponse)
     {
         std::stringstream requestStream;
-
         requestStream<<clientResponse->resJSONPayload;
         if(strlen((char*)clientResponse->resJSONPayload) == 0)
         {
@@ -418,7 +417,8 @@ namespace OC
 
     OCStackResult InProcClientWrapper::GetResourceRepresentation(const std::string& host,
         const std::string& uri, const QueryParamsMap& queryParams,
-        const HeaderOptions& headerOptions, GetCallback& callback)
+        const HeaderOptions& headerOptions, GetCallback& callback,
+        QualityOfService QoS)
     {
         OCStackResult result;
         OCCallbackData cbdata = {0};
@@ -443,7 +443,7 @@ namespace OC
             assembleHeaderOptions(options, headerOptions);
             result = OCDoResource(&handle, OC_REST_GET, os.str().c_str(),
                                   nullptr, nullptr,
-                                  static_cast<OCQualityOfService>(m_cfg.QoS),
+                                  static_cast<OCQualityOfService>(QoS),
                                   &cbdata,
                                   options, headerOptions.size());
         }
@@ -516,7 +516,7 @@ namespace OC
     OCStackResult InProcClientWrapper::PostResourceRepresentation(const std::string& host,
         const std::string& uri, const OCRepresentation& rep,
         const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
-         PostCallback& callback)
+        PostCallback& callback, QualityOfService QoS)
     {
         OCStackResult result;
         OCCallbackData cbdata = {0};
@@ -544,7 +544,7 @@ namespace OC
             result = OCDoResource(&handle, OC_REST_POST,
                                   os.str().c_str(), nullptr,
                                   assembleSetResourcePayload(rep).c_str(),
-                                  static_cast<OCQualityOfService>(m_cfg.QoS),
+                                  static_cast<OCQualityOfService>(QoS),
                                   &cbdata, options, headerOptions.size());
         }
         else
@@ -559,7 +559,7 @@ namespace OC
     OCStackResult InProcClientWrapper::PutResourceRepresentation(const std::string& host,
         const std::string& uri, const OCRepresentation& rep,
         const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
-        PutCallback& callback)
+        PutCallback& callback, QualityOfService QoS)
     {
         OCStackResult result;
         OCCallbackData cbdata = {0};
@@ -587,7 +587,7 @@ namespace OC
             result = OCDoResource(&handle, OC_REST_PUT,
                                   os.str().c_str(), nullptr,
                                   assembleSetResourcePayload(rep).c_str(),
-                                  static_cast<OCQualityOfService>(m_cfg.QoS),
+                                  static_cast<OCQualityOfService>(QoS),
                                   &cbdata,
                                   options, headerOptions.size());
         }
@@ -625,7 +625,7 @@ namespace OC
 
     OCStackResult InProcClientWrapper::ObserveResource(ObserveType observeType, OCDoHandle* handle,
         const std::string& host, const std::string& uri, const QueryParamsMap& queryParams,
-        const HeaderOptions& headerOptions, ObserveCallback& callback)
+        const HeaderOptions& headerOptions, ObserveCallback& callback, QualityOfService QoS)
     {
         OCStackResult result;
         OCCallbackData cbdata = {0};
@@ -664,7 +664,7 @@ namespace OC
             result = OCDoResource(handle, method,
                                   os.str().c_str(), nullptr,
                                   nullptr,
-                                  static_cast<OCQualityOfService>(m_cfg.QoS),
+                                  static_cast<OCQualityOfService>(QoS),
                                   &cbdata,
                                   options, headerOptions.size());
         }
@@ -677,7 +677,8 @@ namespace OC
     }
 
     OCStackResult InProcClientWrapper::CancelObserveResource(OCDoHandle handle,
-        const std::string& host, const std::string& uri, const HeaderOptions& headerOptions)
+        const std::string& host, const std::string& uri, const HeaderOptions& headerOptions,
+        QualityOfService QoS)
     {
         OCStackResult result;
         auto cLock = m_csdkLock.lock();
@@ -688,7 +689,7 @@ namespace OC
             OCHeaderOption options[MAX_HEADER_OPTIONS];
 
             assembleHeaderOptions(options, headerOptions);
-            result = OCCancel(handle, OC_NON_CONFIRMABLE, options, headerOptions.size());
+            result = OCCancel(handle, static_cast<OCQualityOfService>(QoS), options, headerOptions.size());
         }
         else
         {
@@ -733,7 +734,7 @@ namespace OC
             return OC_STACK_ERROR;
 
         return OCDoResource(handle, OC_REST_PRESENCE, os.str().c_str(), nullptr, nullptr,
-                            OC_NON_CONFIRMABLE, &cbdata, NULL, 0);
+                            OC_LOW_QOS, &cbdata, NULL, 0);
     }
 
     OCStackResult InProcClientWrapper::UnsubscribePresence(OCDoHandle handle)
@@ -744,7 +745,7 @@ namespace OC
         if(cLock)
         {
             std::lock_guard<std::recursive_mutex> lock(*cLock);
-            result = OCCancel(handle, OC_NON_CONFIRMABLE, NULL, 0);
+            result = OCCancel(handle, OC_LOW_QOS, NULL, 0);
         }
         else
         {
@@ -754,6 +755,12 @@ namespace OC
         return result;
     }
 
+    OCStackResult InProcClientWrapper::GetDefaultQos(QualityOfService& qos)
+    {
+        qos = m_cfg.QoS;
+        return OC_STACK_OK;
+    }
+
     void InProcClientWrapper::assembleHeaderOptions(OCHeaderOption options[],
            const HeaderOptions& headerOptions)
     {
index 1b43467..bf254a6 100644 (file)
@@ -80,15 +80,28 @@ OCStackResult OCPlatform::setDefaultDeviceEntityHandler(EntityHandler entityHand
                          entityHandler);
 }
 
+OCStackResult OCPlatform::notifyAllObservers(OCResourceHandle resourceHandle, QualityOfService QoS)
+{
+    return result_guard(OCNotifyAllObservers(resourceHandle, static_cast<OCQualityOfService>(QoS)));
+}
+
 OCStackResult OCPlatform::notifyAllObservers(OCResourceHandle resourceHandle)
 {
-    return result_guard(OCNotifyAllObservers(resourceHandle));
+    return notifyAllObservers(resourceHandle, m_cfg.QoS);
 }
 
 OCStackResult OCPlatform::notifyListOfObservers(OCResourceHandle resourceHandle,
                                             ObservationIds& observationIds,
                                             const std::shared_ptr<OCResourceResponse> pResponse)
 {
+    return notifyListOfObservers(resourceHandle, observationIds, pResponse, m_cfg.QoS);
+}
+
+OCStackResult OCPlatform::notifyListOfObservers(OCResourceHandle resourceHandle,
+                                            ObservationIds& observationIds,
+                                            const std::shared_ptr<OCResourceResponse> pResponse,
+                                            QualityOfService QoS)
+{
     if(!pResponse)
     {
      return result_guard(OC_STACK_ERROR);
@@ -99,7 +112,8 @@ OCStackResult OCPlatform::notifyListOfObservers(OCResourceHandle resourceHandle,
     return result_guard(
                OCNotifyListOfObservers(resourceHandle,
                                        &observationIds[0], observationIds.size(),
-                                       reinterpret_cast<unsigned char *>(const_cast<char *>(payload.c_str()))));
+                                       reinterpret_cast<unsigned char *>(const_cast<char *>(payload.c_str())),
+                                       static_cast<OCQualityOfService>(QoS)));
 }
 
 OCResource::Ptr OCPlatform::constructResourceObject(const std::string& host, const std::string& uri,
@@ -117,8 +131,14 @@ OCResource::Ptr OCPlatform::constructResourceObject(const std::string& host, con
 OCStackResult OCPlatform::findResource(const std::string& host, const std::string& resourceName,
                                        FindCallback resourceHandler)
 {
+    return findResource(host, resourceName, resourceHandler, m_cfg.QoS);
+}
+
+OCStackResult OCPlatform::findResource(const std::string& host, const std::string& resourceName,
+                                       FindCallback resourceHandler, QualityOfService QoS)
+{
     return checked_guard(m_client, &IClientWrapper::ListenForResource,
-                         host, resourceName, resourceHandler);
+                         host, resourceName, resourceHandler, QoS);
 }
 
 
@@ -131,7 +151,7 @@ OCStackResult OCPlatform::registerResource(OCResourceHandle& resourceHandle,
 {
     return checked_guard(m_server, &IServerWrapper::registerResource,
                          ref(resourceHandle), resourceURI, resourceTypeName,
-                                resourceInterface, entityHandler, resourceProperty);
+                         resourceInterface, entityHandler, resourceProperty);
 }
 
 OCStackResult OCPlatform::unregisterResource(const OCResourceHandle& resourceHandle) const
index ebe653b..e5321db 100644 (file)
@@ -28,8 +28,7 @@ using OC::result_guard;
 using OC::checked_guard;
 
 OCResource::OCResource(std::weak_ptr<IClientWrapper> clientWrapper, const std::string& host,
-                       const std::string& uri, bool observable,
-                       const std::vector<std::string>& resourceTypes,
+                       const std::string& uri, bool observable, const std::vector<std::string>& resourceTypes,
                        const std::vector<std::string>& interfaces)
  :  m_clientWrapper(clientWrapper), m_uri(uri), m_host(host), m_isObservable(observable),
     m_isCollection(false), m_resourceTypes(resourceTypes), m_interfaces(interfaces),
@@ -53,16 +52,33 @@ OCResource::~OCResource()
 }
 
 OCStackResult OCResource::get(const QueryParamsMap& queryParametersMap,
-                              GetCallback attributeHandler)
+                              GetCallback attributeHandler, QualityOfService QoS)
 {
     return checked_guard(m_clientWrapper.lock(), &IClientWrapper::GetResourceRepresentation,
-                         m_host, m_uri, queryParametersMap, m_headerOptions, attributeHandler);
+                         m_host, m_uri, queryParametersMap, m_headerOptions, attributeHandler, QoS);
+}
+
+OCStackResult OCResource::get(const QueryParamsMap& queryParametersMap,
+                              GetCallback attributeHandler)
+{
+    QualityOfService defaultQos = OC::QualityOfService::NaQos;
+    checked_guard(m_clientWrapper.lock(), &IClientWrapper::GetDefaultQos, defaultQos);
+    return result_guard(get(queryParametersMap, attributeHandler, defaultQos));
 }
 
 OCStackResult OCResource::get(const std::string& resourceType,
                      const std::string& resourceInterface, const QueryParamsMap& queryParametersMap,
                      GetCallback attributeHandler)
 {
+    QualityOfService defaultQoS = OC::QualityOfService::NaQos;
+    checked_guard(m_clientWrapper.lock(), &IClientWrapper::GetDefaultQos, defaultQoS);
+
+    return result_guard(get(resourceType, resourceInterface, queryParametersMap, attributeHandler, defaultQoS));
+}
+
+OCStackResult OCResource::get(const std::string& resourceType, const std::string& resourceInterface, const QueryParamsMap& queryParametersMap, GetCallback attributeHandler,
+        QualityOfService QoS)
+{
     QueryParamsMap mapCpy(queryParametersMap);
 
     if(!resourceType.empty())
@@ -75,14 +91,23 @@ OCStackResult OCResource::get(const std::string& resourceType,
         mapCpy["if"]= resourceInterface;
     }
 
-    return result_guard(get(mapCpy, attributeHandler));
+    return result_guard(get(mapCpy, attributeHandler, QoS));
 }
 
 OCStackResult OCResource::put(const OCRepresentation& rep,
-                     const QueryParamsMap& queryParametersMap, PutCallback attributeHandler)
+                              const QueryParamsMap& queryParametersMap, PutCallback attributeHandler,
+                              QualityOfService QoS)
 {
     return checked_guard(m_clientWrapper.lock(), &IClientWrapper::PutResourceRepresentation,
-                         m_host, m_uri, rep, queryParametersMap, m_headerOptions, attributeHandler);
+                         m_host, m_uri, rep, queryParametersMap, m_headerOptions, attributeHandler, QoS);
+}
+
+OCStackResult OCResource::put(const OCRepresentation& rep,
+                              const QueryParamsMap& queryParametersMap, PutCallback attributeHandler)
+{
+    QualityOfService defaultQos = OC::QualityOfService::NaQos;
+    checked_guard(m_clientWrapper.lock(), &IClientWrapper::GetDefaultQos, defaultQos);
+    return result_guard(put(rep, queryParametersMap, attributeHandler, defaultQos));
 }
 
 OCStackResult OCResource::put(const std::string& resourceType,
@@ -90,26 +115,48 @@ OCStackResult OCResource::put(const std::string& resourceType,
                               const QueryParamsMap& queryParametersMap,
                               PutCallback attributeHandler)
 {
+    QualityOfService defaultQos = OC::QualityOfService::NaQos;
+    checked_guard(m_clientWrapper.lock(), &IClientWrapper::GetDefaultQos, defaultQos);
+
+    return result_guard(put(resourceType, resourceInterface, rep, queryParametersMap,
+            attributeHandler, defaultQos));
+}
+
+OCStackResult OCResource::put(const std::string& resourceType,
+                              const std::string& resourceInterface, const OCRepresentation& rep,
+                              const QueryParamsMap& queryParametersMap,
+                              PutCallback attributeHandler,
+                              QualityOfService QoS)
+{
     QueryParamsMap mapCpy(queryParametersMap);
 
     if(!resourceType.empty())
-     {
-            mapCpy["rt"]=resourceType;
-     }
+    {
+        mapCpy["rt"]=resourceType;
+    }
 
     if(!resourceInterface.empty())
-     {
-            mapCpy["if"]=resourceInterface;
-     }
+    {
+        mapCpy["if"]=resourceInterface;
+    }
 
-    return result_guard(put(rep, mapCpy, attributeHandler));
+    return result_guard(put(rep, mapCpy, attributeHandler, QoS));
 }
 
 OCStackResult OCResource::post(const OCRepresentation& rep,
-                     const QueryParamsMap& queryParametersMap, PostCallback attributeHandler)
+                               const QueryParamsMap& queryParametersMap, PostCallback attributeHandler,
+                               QualityOfService QoS)
 {
     return checked_guard(m_clientWrapper.lock(), &IClientWrapper::PostResourceRepresentation,
-                         m_host, m_uri, rep, queryParametersMap, m_headerOptions, attributeHandler);
+                         m_host, m_uri, rep, queryParametersMap, m_headerOptions, attributeHandler, QoS);
+}
+
+OCStackResult OCResource::post(const OCRepresentation& rep,
+                              const QueryParamsMap& queryParametersMap, PutCallback attributeHandler)
+{
+    QualityOfService defaultQos = OC::QualityOfService::NaQos;
+    checked_guard(m_clientWrapper.lock(), &IClientWrapper::GetDefaultQos, defaultQos);
+    return result_guard(post(rep, queryParametersMap, attributeHandler, defaultQos));
 }
 
 OCStackResult OCResource::post(const std::string& resourceType,
@@ -117,6 +164,19 @@ OCStackResult OCResource::post(const std::string& resourceType,
                                const QueryParamsMap& queryParametersMap,
                                PostCallback attributeHandler)
 {
+    QualityOfService defaultQoS = OC::QualityOfService::NaQos;
+    checked_guard(m_clientWrapper.lock(), &IClientWrapper::GetDefaultQos, defaultQoS);
+
+    return result_guard(post(resourceType, resourceInterface, rep, queryParametersMap, attributeHandler,
+            defaultQoS));
+}
+
+OCStackResult OCResource::post(const std::string& resourceType,
+                               const std::string& resourceInterface, const OCRepresentation& rep,
+                               const QueryParamsMap& queryParametersMap,
+                               PostCallback attributeHandler,
+                               QualityOfService QoS)
+{
     QueryParamsMap mapCpy(queryParametersMap);
 
     if(!resourceType.empty())
@@ -129,11 +189,12 @@ OCStackResult OCResource::post(const std::string& resourceType,
         mapCpy["if"]=resourceInterface;
     }
 
-    return result_guard(post(rep, mapCpy, attributeHandler));
+    return result_guard(post(rep, mapCpy, attributeHandler, QoS));
 }
 
 OCStackResult OCResource::observe(ObserveType observeType,
-                           const QueryParamsMap& queryParametersMap, ObserveCallback observeHandler)
+        const QueryParamsMap& queryParametersMap, ObserveCallback observeHandler,
+        QualityOfService QoS)
 {
     if(m_observeHandle != nullptr)
     {
@@ -142,18 +203,34 @@ OCStackResult OCResource::observe(ObserveType observeType,
 
     return checked_guard(m_clientWrapper.lock(), &IClientWrapper::ObserveResource,
                          observeType, &m_observeHandle, m_host,
-                         m_uri, queryParametersMap, m_headerOptions, observeHandler);
+                         m_uri, queryParametersMap, m_headerOptions, observeHandler, QoS);
+}
+
+OCStackResult OCResource::observe(ObserveType observeType,
+        const QueryParamsMap& queryParametersMap, ObserveCallback observeHandler)
+{
+    QualityOfService defaultQoS = OC::QualityOfService::NaQos;
+    checked_guard(m_clientWrapper.lock(), &IClientWrapper::GetDefaultQos, defaultQoS);
+
+    return result_guard(observe(observeType, queryParametersMap, observeHandler, defaultQoS));
 }
 
 OCStackResult OCResource::cancelObserve()
 {
+    QualityOfService defaultQoS = OC::QualityOfService::NaQos;
+    checked_guard(m_clientWrapper.lock(), &IClientWrapper::GetDefaultQos, defaultQoS);
+    return result_guard(cancelObserve(defaultQoS));
+}
+
+OCStackResult OCResource::cancelObserve(QualityOfService QoS)
+{
     if(m_observeHandle == nullptr)
     {
         return result_guard(OC_STACK_INVALID_PARAM);
     }
 
     return checked_guard(m_clientWrapper.lock(), &IClientWrapper::CancelObserveResource,
-                         m_observeHandle, m_host, m_uri, m_headerOptions);
+            m_observeHandle, m_host, m_uri, m_headerOptions, QoS);
 }
 
 std::string OCResource::host() const