-******************************************************************
-
- 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.
// 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);
// 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);
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) {
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))
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)
{
// 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;
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();
* 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;
/**
* 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.
OCNotifyListOfObservers (OCResourceHandle handle,
OCObservationId *obsIdList,
uint8_t numberOfIds,
- unsigned char *notificationJSONPayload);
+ unsigned char *notificationJSONPayload,
+ OCQualityOfService qos);
#ifdef __cplusplus
}
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;
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");
}
}
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;
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:
break;
#endif
case TEST_GET_REQ_NON_WITH_VENDOR_HEADER_OPTIONS:
- InitGetRequest(OC_NON_CONFIRMABLE, 1);
+ InitGetRequest(OC_LOW_QOS, 1);
break;
default:
PrintUsage();
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()
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)
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()
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)
// 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)
{
// 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)
{
// 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));
}
}
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));
}
}
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");
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");
}
}
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)
{
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)
{
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");
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)
{
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)
{
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,
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;
observer = GetObserverUsingToken(token);
if(observer)
{
- observer->forceCON = 0;
+ observer->forceHighQos = 0;
observer->failedCommCount = 0;
result = OC_STACK_OK;
}
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;
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;
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)
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,
else
{
if(resource->resourceProperties & OC_ACTIVE){
- OCNotifyAllObservers((OCResourceHandle) resource);
+ OCNotifyAllObservers((OCResourceHandle) resource, OC_LOW_QOS);
}
result = OC_STACK_PRESENCE_DO_NOT_HANDLE;
}
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:
{
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,
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))
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)
{
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);
}
/**
result = OCChangeResourceProperty(
&(((OCResource *) presenceResource.handle)->resourceProperties),
OC_ACTIVE, 0);
- result = OCNotifyAllObservers(presenceResource.handle);
+ result = OCNotifyAllObservers(presenceResource.handle, OC_LOW_QOS);
return result;
}
#endif
if(presenceResource.handle)
{
((OCResource *)presenceResource.handle)->sequenceNum = OCGetRandom();
- OCNotifyAllObservers(presenceResource.handle);
+ OCNotifyAllObservers(presenceResource.handle, OC_LOW_QOS);
}
#endif
exit:
if(presenceResource.handle)
{
((OCResource *)presenceResource.handle)->sequenceNum = OCGetRandom();
- OCNotifyAllObservers(presenceResource.handle);
+ OCNotifyAllObservers(presenceResource.handle, OC_LOW_QOS);
}
#endif
if(presenceResource.handle)
{
((OCResource *)presenceResource.handle)->sequenceNum = OCGetRandom();
- OCNotifyAllObservers(presenceResource.handle);
+ OCNotifyAllObservers(presenceResource.handle, OC_LOW_QOS);
}
#endif
if(presenceResource.handle)
{
((OCResource *)presenceResource.handle)->sequenceNum = OCGetRandom();
- OCNotifyAllObservers(presenceResource.handle);
+ OCNotifyAllObservers(presenceResource.handle, OC_LOW_QOS);
}
#endif
if(presenceResource.handle)
{
((OCResource *)presenceResource.handle)->sequenceNum = OCGetRandom();
- OCNotifyAllObservers(presenceResource.handle);
+ OCNotifyAllObservers(presenceResource.handle, OC_LOW_QOS);
}
#endif
if(presenceResource.handle)
{
((OCResource *)presenceResource.handle)->sequenceNum = OCGetRandom();
- OCNotifyAllObservers(presenceResource.handle);
+ OCNotifyAllObservers(presenceResource.handle, OC_LOW_QOS);
}
#endif
if(presenceResource.handle)
{
((OCResource *)presenceResource.handle)->sequenceNum = OCGetRandom();
- OCNotifyAllObservers(presenceResource.handle);
+ OCNotifyAllObservers(presenceResource.handle, OC_LOW_QOS);
}
#endif
* 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;
}
#endif
- result = SendObserverNotification (method, resPtr, maxAge);
+ result = SendObserverNotification (method, resPtr, maxAge, qos);
return result;
}
}
OCNotifyListOfObservers (OCResourceHandle handle,
OCObservationId *obsIdList,
uint8_t numberOfIds,
- unsigned char *notificationJSONPayload)
+ unsigned char *notificationJSONPayload,
+ OCQualityOfService qos)
{
OC_LOG(INFO, TAG, PCF("Entering OCNotifyListOfObservers"));
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
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,
}
resource->resourceProperties = (OCResourceProperty) 0; // Invalidate all Resource Properties.
- OCNotifyAllObservers((OCResourceHandle)resource);
+ OCNotifyAllObservers((OCResourceHandle)resource, OC_HIGH_QOS);
deleteResourceElements(temp);
OCFree(temp);
ModeType::Client,
"0.0.0.0",
0,
- QualityOfService::NonConfirmable
+ QualityOfService::LowQos
};
ClientFridge cf (cfg);
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);
OC::ModeType::Client,
"0.0.0.0",
0,
- OC::QualityOfService::NonConfirmable
+ OC::QualityOfService::LowQos
};
// Create a OCPlatform instance.
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.
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
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)
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;
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';
}
// 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";
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)
return;
}
- switch(request->getRequestHandlerFlag())
+ switch(request->getRequestHandlerFlag())
{
default:
cerr << "entityHandler(): invalid request flag\n";
}
}
-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';
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";
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();
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)
// ...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();
class LightResource
{
public:
+ OCPlatform& m_platform;
bool m_state; // off or on?
int m_power; // power level
OCRepresentation m_rep;
OCResourceHandle m_resourceHandle;
public:
- LightResource()
- : m_state(false),
+ LightResource(OCPlatform& platform)
+ : m_platform(platform),
+ m_state(false),
m_power(0),
m_observation(false)
{}
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;
}
}} // namespace Intel::OCDemo
-#endif
+#endif
{
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");
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;
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;
{
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"));
OC::ModeType::Client,
"0.0.0.0",
0,
- OC::QualityOfService::NonConfirmable
+ OC::QualityOfService::LowQos
};
// Create a OCPlatform instance.
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.
OC::ModeType::Client,
"0.0.0.0",
0,
- OC::QualityOfService::NonConfirmable
+ OC::QualityOfService::LowQos
};
// Create a OCPlatform instance.
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.
OC::ModeType::Client,
"0.0.0.0",
0,
- OC::QualityOfService::NonConfirmable
+ OC::QualityOfService::LowQos
};
// Create a OCPlatform instance.
--- /dev/null
+//******************************************************************
+//
+// 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;
+}
+
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;
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);
}
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
--- /dev/null
+//******************************************************************
+//
+// 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
+}
{}
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(){}
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);
// 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);
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
};
/**
* 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.
* 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.
*
* 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.
* (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
* 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
* 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.
* 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>
* 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)
* 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)
* 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
* 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
* 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
* 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
* NOTE: OCStackResult is defined in ocstack.h.
*/
OCStackResult cancelObserve();
+ OCStackResult cancelObserve(QualityOfService qos);
/**
* Function to set header information.
{}
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)
SubscribeCallback& presenceHandler){return OC_STACK_NOTIMPL;}
virtual OCStackResult UnsubscribePresence(OCDoHandle handle){return OC_STACK_NOTIMPL;}
+
+ virtual OCStackResult GetDefaultQos(QualityOfService& QoS){return OC_STACK_NOTIMPL;}
};
}
}
OCStackResult InProcClientWrapper::ListenForResource(const std::string& serviceUrl,
- const std::string& resourceType, FindCallback& callback)
+ const std::string& resourceType, FindCallback& callback, QualityOfService QoS)
{
OCStackResult result;
result = OCDoResource(&handle, OC_REST_GET,
resourceType.c_str(),
nullptr, nullptr,
- static_cast<OCQualityOfService>(m_cfg.QoS),
+ static_cast<OCQualityOfService>(QoS),
&cbdata,
NULL, 0);
}
OCRepresentation parseGetSetCallback(OCClientResponse* clientResponse)
{
std::stringstream requestStream;
-
requestStream<<clientResponse->resJSONPayload;
if(strlen((char*)clientResponse->resJSONPayload) == 0)
{
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};
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());
}
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};
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
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};
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());
}
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};
result = OCDoResource(handle, method,
os.str().c_str(), nullptr,
nullptr,
- static_cast<OCQualityOfService>(m_cfg.QoS),
+ static_cast<OCQualityOfService>(QoS),
&cbdata,
options, headerOptions.size());
}
}
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();
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
{
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)
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
{
return result;
}
+ OCStackResult InProcClientWrapper::GetDefaultQos(QualityOfService& qos)
+ {
+ qos = m_cfg.QoS;
+ return OC_STACK_OK;
+ }
+
void InProcClientWrapper::assembleHeaderOptions(OCHeaderOption options[],
const HeaderOptions& headerOptions)
{
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);
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,
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);
}
{
return checked_guard(m_server, &IServerWrapper::registerResource,
ref(resourceHandle), resourceURI, resourceTypeName,
- resourceInterface, entityHandler, resourceProperty);
+ resourceInterface, entityHandler, resourceProperty);
}
OCStackResult OCPlatform::unregisterResource(const OCResourceHandle& resourceHandle) const
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),
}
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())
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,
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,
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())
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)
{
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