scons TARGET_OS=android TARGET_ARCH=armeabi-v7a-hard ANDROID_NDK=$1 RELEASE=$3
fi
+: '
echo "*********** Build for arduino avr *************"
scons TARGET_OS=arduino TARGET_ARCH=avr ARDUINO_HOME=$2 RELEASE=$3
echo "*********** Build for arduino arm *************"
scons TARGET_OS=arduino TARGET_ARCH=arm ARDUINO_HOME=$2 RELEASE=$3
+'
if [ $(uname -s) = "Darwin" ]
then
target_os = env.get('TARGET_OS')
# Build libcoap
+SConscript('csdk/connectivity/lib/libcoap-4.1.1/SConscript')
SConscript('csdk/libcoap/SConscript')
+# Build connectivity
+SConscript('csdk/connectivity/SConscript')
+
# Build liboctbstack
SConscript('csdk/SConscript')
# Build examples
SConscript('examples/SConscript')
+
+ SConscript('csdk/stack/samples/linux/SimpleClientServer/SConscript')
else:
- SConscript('csdk/stack/samples/arduino/SimpleClientServer/ocserver/SConscript')
\ No newline at end of file
+ SConscript('csdk/stack/samples/arduino/SimpleClientServer/ocserver/SConscript')
'occoap/include',
'stack/include',
'stack/include/internal',
- '../oc_logger/include'
+ '../oc_logger/include',
+ 'connectivity/inc',
+ 'connectivity/api',
])
if target_os not in ['arduino', 'windows', 'winrt']:
if not env.get('RELEASE'):
liboctbstack_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+liboctbstack_env.AppendUnique(CPPDEFINES = ['CA_INT'])
+
######################################################################
# Source files and Targets
######################################################################
--- /dev/null
+##
+# CA library (share library) build script
+##
+Import('env')
+
+# Add third party libraries
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/resource/third_party_libs.scons', 'lib_env')
+
+calib_env = lib_env.Clone()
+######################################################################
+# Build flags
+######################################################################
+calib_env.AppendUnique(CPPPATH = [
+ './common/inc',
+ './api',
+ './inc',
+ './src/ethernet_adapter/linux',
+ './src/wifi_adapter/linux',
+ './src/bt_edr_adapter/linux',
+ './src/bt_le_adapter/linux',
+ './lib/libcoap-4.1.1'
+ ])
+
+target_os = env.get('TARGET_OS')
+
+if target_os not in ['windows', 'winrt']:
+ calib_env.AppendUnique(CFLAGS = ['-Wall', '-fPIC', '-fstack-protector-all']);
+ calib_env.AppendUnique(CPPDEFINES = [
+ '__LINUX__', 'WITH_POSIX',
+ 'NO_EDR_ADAPTER', 'NO_LE_ADAPTER',
+ 'WIFI_ADAPTER', 'ETHERNET_ADAPTER',
+ #'TB_LOG'
+ ])
+
+calib_env.ParseConfig('pkg-config --cflags glib-2.0')
+
+#TODO add SConscript for libcoap
+#`/home/tester/iotivity/resource/csdk/connectivity/lib/libcoap-4.1.1'
+
+######################################################################
+# Source files and Targets
+######################################################################
+calib_src = [
+ './common/src/logger.c',
+ './common/src/oic_logger.c',
+ './common/src/oic_console_logger.c',
+ './common/src/oic_malloc.c',
+ './common/src/oic_string.c',
+ './common/src/uqueue.c',
+ './common/src/uarraylist.c',
+ './common/src/umutex.c',
+ './common/src/uthreadpool.c',
+ './src/caretransmission.c',
+ './src/caconnectivitymanager.c',
+ './src/caremotehandler.c',
+ './src/cainterfacecontroller.c',
+ './src/camessagehandler.c',
+ './src/caqueueingthread.c',
+ './src/canetworkconfigurator.c',
+ './src/caprotocolmessage.c',
+ './src/adapter_util/caadapterutils.c',
+ './src/ethernet_adapter/caethernetadapter.c',
+ './src/wifi_adapter/cawifiadapter.c',
+ './src/bt_edr_adapter/linux/caedradapter.c',
+ './src/bt_le_adapter/linux/caleadapter.c',
+ './src/wifi_adapter/linux/cawifiserver.c',
+ './src/wifi_adapter/linux/cawificlient.c',
+ './src/wifi_adapter/linux/cawifinwmonitor.c',
+ './src/ethernet_adapter/linux/caethernetserver.c',
+ './src/ethernet_adapter/linux/caethernetclient.c',
+ './src/ethernet_adapter/linux/caethernetnwmonitor.c'
+ ]
+
+calib = calib_env.SharedLibrary('connectivity_abstraction', calib_src)
+calib_env.InstallTarget(calib, 'libconnectivity_abstraction')
+
--- /dev/null
+##
+# libcoap (share library) build script
+##
+
+Import('env')
+
+libcoap_env = env.Clone()
+
+target_os = env.get('TARGET_OS')
+# As in the source code(C) includes arduino Time library head file(C++)
+# It requires compile the .c with g++
+if target_os == 'arduino':
+ libcoap_env.Replace(CC = env.get('CXX'))
+ libcoap_env.Replace(CFLAGS = env.get('CXXFLAGS'))
+
+######################################################################
+# Build flags
+######################################################################
+libcoap_env.PrependUnique(CPPPATH = [
+ '../ocsocket/include',
+ '../ocmalloc/include',
+ '../logger/include',
+ '../ocrandom/include',
+ '../stack',
+ '../../oc_logger/include'
+ ])
+
+if target_os not in ['arduino', 'windows', 'winrt']:
+ libcoap_env.AppendUnique(CPPDEFINES = ['WITH_POSIX'])
+ libcoap_env.AppendUnique(CFLAGS = ['-std=gnu99', '-fPIC'])
+
+if target_os not in ['windows', 'winrt']:
+ libcoap_env.AppendUnique(CFLAGS = ['-Wall', '-ffunction-sections',
+ '-fdata-sections', '-fno-exceptions'])
+
+if target_os == 'android':
+ libcoap_env.AppendUnique(LIBS = ['log'])
+
+if target_os == 'arduino':
+ libcoap_env.AppendUnique(CPPDEFINES = ['NDEBUG', 'WITH_ARDUINO'])
+
+if target_os in ['darwin', 'ios']:
+ libcoap_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
+
+if not env.get('RELEASE'):
+ libcoap_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+
+######################################################################
+# Source files and Target(s)
+######################################################################
+libcoap_src = [
+ 'pdu.c',
+ 'net.c',
+ 'debug.c',
+ 'encode.c',
+ 'uri.c',
+ 'coap_list.c',
+ 'resource.c',
+ 'hashkey.c',
+ 'str.c',
+ 'option.c',
+ 'async.c',
+ 'subscribe.c',
+ 'block.c',
+# '../logger/src/logger.c',
+# '../ocrandom/src/ocrandom.c',
+# '../ocmalloc/src/ocmalloc.c',
+# '../../oc_logger/c/oc_logger.c',
+# '../../oc_logger/c/oc_console_logger.c'
+ ]
+
+if target_os == 'arduino':
+ libcoap = libcoap_env.StaticLibrary('libcoap', libcoap_src, OBJPREFIX='libcoap_')
+else:
+ libcoap = libcoap_env.SharedLibrary('libcoap', libcoap_src, OBJPREFIX='libcoap_')
+
+libcoap_env.InstallTarget(libcoap, 'libcoap')
memset(&requestData, 0, sizeof(CAInfo_t));
requestData.token = token;
requestData.payload = "Temp Json Payload";
+ requestData.type = CA_MSG_NONCONFIRM;
CARequestInfo_t requestInfo;
memset(&requestInfo, 0, sizeof(CARequestInfo_t));
OIC_LOG_V(DEBUG, TAG, "responseInfo is available..");
pdu = (coap_pdu_t *) CAGeneratePdu(data->remoteEndpoint->resourceUri,
- data->responseInfo->result,
+ data->responseInfo->result,
data->responseInfo->info);
}
else
info.options = data->options;
info.numOptions = data->numOptions;
info.token = data->requestInfo->info.token;
+ info.type = data->requestInfo->info.type;
pdu = (coap_pdu_t *) CAGeneratePdu(data->remoteEndpoint->resourceUri, CA_GET, info);
memset(ReqInfo, 0, sizeof(CARequestInfo_t));
ReqInfo->method = CA_GET;
ReqInfo->info.token = token;
+ ReqInfo->info.type = CA_MSG_NONCONFIRM;
data->requestInfo = ReqInfo;
data->responseInfo = NULL;
info.options = data->options;
info.numOptions = data->numOptions;
info.token = data->requestInfo->info.token;
+ info.type = data->requestInfo->info.type;
pdu = (coap_pdu_t *) CAGeneratePdu(data->remoteEndpoint->resourceUri, CA_GET, info);
memset(ReqInfo, 0, sizeof(CARequestInfo_t));
ReqInfo->method = CA_GET;
ReqInfo->info.token = token;
+ ReqInfo->info.type = CA_MSG_NONCONFIRM;
data->requestInfo = ReqInfo;
data->responseInfo = NULL;
libcoap_src.append(['../ocsocket/src/ocsocket.c'])
if target_os == 'arduino':
- libcoap = libcoap_env.StaticLibrary('libcoap', libcoap_src, OBJPREFIX='libcoap_')
+ libcoap = libcoap_env.StaticLibrary('libcoap_csdk', libcoap_src, OBJPREFIX='libcoap_')
else:
- libcoap = libcoap_env.SharedLibrary('libcoap', libcoap_src, OBJPREFIX='libcoap_')
+ libcoap = libcoap_env.SharedLibrary('libcoap_csdk', libcoap_src, OBJPREFIX='libcoap_')
-libcoap_env.InstallTarget(libcoap, 'libcoap')
+libcoap_env.InstallTarget(libcoap, 'libcoap_csdk')
OC_STACK_KEEP_TRANSACTION
} OCStackApplicationResult;
+#ifdef CA_INT
+typedef enum {
+ OC_ETHERNET = (1 << 0),
+ OC_WIFI = (1 << 1),
+ OC_EDR = (1 << 2),
+ OC_LE = (1 << 3)
+} OCConnectivityType;
+#endif
+
//-----------------------------------------------------------------------------
// Callback function definitions
//-----------------------------------------------------------------------------
* OC_STACK_INVALID_QUERY - number of resource types specified for filtering presence
* notifications exceeds @ref MAX_PRESENCE_FILTERS.
*/
-OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requiredUri, const char *referenceUri,
- const char *request, OCQualityOfService qos, OCCallbackData *cbData, OCHeaderOption * options,
+#ifdef CA_INT
+OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requiredUri,
+ const char *referenceUri, const char *request, uint8_t conType,
+ OCQualityOfService qos, OCCallbackData *cbData, OCHeaderOption * options,
uint8_t numOptions);
+#else
+OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requiredUri,
+ const char *referenceUri, const char *request, OCQualityOfService qos,
+ OCCallbackData *cbData, OCHeaderOption * options, uint8_t numOptions);
+#endif
/**
* Cancel a request associated with a specific @ref OCDoResource invocation.
--- /dev/null
+
+Import('env')
+
+samples_env = env.Clone()
+######################################################################
+# Build flags
+######################################################################
+samples_env.PrependUnique(CPPPATH = [
+ '../../../../ocsocket/include',
+ '../../../../logger/include',
+ '../../../../stack/include',
+ '../../../../../../extlibs/cjson',
+ '../../../../../oc_logger/include'
+ ])
+
+target_os = env.get('TARGET_OS')
+if target_os not in ['windows', 'winrt']:
+ samples_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
+
+ # Note: 'pthread' is in libc for android. On other platform, if use
+ # new gcc(>4.9?) it isn't required, otherwise, it's required
+ if target_os != 'android':
+ samples_env.AppendUnique(LIBS = ['-lpthread'])
+
+samples_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+samples_env.PrependUnique(LIBS = ['oc', 'm', 'octbstack', 'coap', 'coap_csdk', 'oc_logger', 'connectivity_abstraction'])
+
+samples_env.ParseConfig('pkg-config --libs glib-2.0');
+
+if target_os == 'android':
+ samples_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
+ samples_env.AppendUnique(LIBS = ['gnustl_static'])
+ samples_env.AppendUnique(CPPDEFINES = ['_GLIBCXX_USE_C99=1', '_GLIBCXX_HAVE_WCSTOF=1'])
+
+ if not env.get('RELEASE'):
+ samples_env.AppendUnique(LIBS = ['log'])
+
+if target_os in ['darwin', 'ios']:
+ samples_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
+
+samples_env.AppendUnique(CPPDEFINES = ['CA_INT'])
+
+######################################################################
+# Source files and Targets
+######################################################################
+ocserver = samples_env.Program('ocserver', 'ocserver.cpp')
+occlient = samples_env.Program('occlient', 'occlient.cpp')
+#ocserverslow = samples_env.Program('ocserverslow', 'ocserverslow.cpp')
+#occlientslow = samples_env.Program('occlientslow', 'occlientslow.cpp')
+#ocservercoll = samples_env.Program('ocservercoll', 'ocservercoll.cpp')
+#occlientcoll = samples_env.Program('occlientcoll', 'occlientcoll.cpp')
+#ocserverbasicops = samples_env.Program('ocserverbasicops', 'ocserverbasicops.cpp')
+#occlientbasicops = samples_env.Program('occlientbasicops', 'occlientbasicops.cpp')
+
+Alias("samples", [ocserver, occlient,
+ #ocservercoll, occlientcoll,
+ #ocserverbasicops, occlientbasicops,
+ #ocserverslow, occlientslow
+ ])
+
+env.AppendTarget('samples')
+
+#ios doesn't allow run application from terminal, so won't build these samples
+#if target_os != 'ios':
+# SConscript('ocicuc/SConscript')
// 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
#include <string.h>
#include <signal.h>
#include <unistd.h>
-#include <iostream>
+
+#include <set>
+#include <string>
#include <sstream>
+#include <iostream>
+#include <algorithm>
+
#include "ocstack.h"
#include "logger.h"
#include "occlientbasicops.h"
static int UNICAST_DISCOVERY = 0;
static int TEST_CASE = 0;
+
static const char * TEST_APP_UNICAST_DISCOVERY_QUERY = "coap://0.0.0.0:5683/oc/core";
+
static std::string putPayload = "{\"state\":\"off\",\"power\":10}";
+
static std::string coapServerIP = "255.255.255.255";
static std::string coapServerPort = "5683";
static std::string coapServerResource = "/a/led";
int gQuitFlag = 0;
+namespace {
+ typedef std::pair<bool, std::string> extract_result_t;
+ typedef std::string sid_t;
+ typedef std::set<std::string> SID_set_t;
+} // namespace
+
+void collateSIDs(const OCClientResponse * clientResponse, const std::string& server_ip);
+
/* SIGINT handler: set gQuitFlag to 1 for graceful termination */
void handleSigInt(int signum)
{
OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse)
{
- if(clientResponse == NULL)
- {
- OC_LOG(INFO, TAG, "The clientResponse is NULL");
- return OC_STACK_DELETE_TRANSACTION;
- }
if(ctx == (void*)DEFAULT_CONTEXT_VALUE)
{
OC_LOG(INFO, TAG, "Callback Context for GET query recvd successfully");
}
- OC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
- OC_LOG_V(INFO, TAG, "SEQUENCE NUMBER: %d", clientResponse->sequenceNumber);
- OC_LOG_V(INFO, TAG, "JSON = %s =============> Get Response",
- clientResponse->resJSONPayload);
-
+ if(clientResponse)
+ {
+ OC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
+ OC_LOG_V(INFO, TAG, "SEQUENCE NUMBER: %d", clientResponse->sequenceNumber);
+ OC_LOG_V(INFO, TAG, "JSON = %s =============> Get Response",
+ clientResponse->resJSONPayload);
+ }
if(clientResponse->rcvdVendorSpecificHeaderOptions &&
clientResponse->numRcvdVendorSpecificHeaderOptions)
{
uint8_t remoteIpAddr[4];
uint16_t remotePortNu;
- if (ctx == (void*) DEFAULT_CONTEXT_VALUE)
+ if (ctx == (void*)DEFAULT_CONTEXT_VALUE)
{
OC_LOG(INFO, TAG, "Callback Context for DISCOVER query recvd successfully");
}
parseClientResponse(clientResponse);
+ collateSIDs(clientResponse, getIPAddrTBServer(clientResponse));
+
switch(TEST_CASE)
{
case TEST_NON_CON_OP:
}
return (UNICAST_DISCOVERY) ? OC_STACK_DELETE_TRANSACTION : OC_STACK_KEEP_TRANSACTION ;
-
}
int InitPutRequest()
InitDiscovery();
// Break from loop with Ctrl+C
- OC_LOG(INFO, TAG, "Entering occlient main loop...");
signal(SIGINT, handleSigInt);
+
while (!gQuitFlag)
{
if (OCProcess() != OC_STACK_OK)
return "/a/led";
}
+
+/* You could do this with the JSON parser of your choice, a regular expression, PEG
+grammar, etc.. This "sample" version does not handle cases like escaping strings,
+but shows a simple way you might approach the task with just the C++98 library: */
+extract_result_t extract_value(const std::string& search_key, const std::string& input)
+{
+ const std::string key('\"' + search_key + "\":\"");
+
+ const size_t key_mark = input.find(key);
+ const size_t key_edge = key_mark + key.length();
+ const size_t val_mark = input.find_first_of("\"", key_edge);
+
+ if(std::string::npos == key_mark || std::string::npos == val_mark) {
+ std::ostringstream os;
+
+ os << "extract_value(): \"" << search_key << "\" not found in input";
+ OC_LOG(ERROR, TAG, os.str().c_str());
+
+ return std::make_pair(false, "");
+ }
+
+ return std::make_pair(true, input.substr(key_edge, val_mark - key_edge));
+}
+
+extract_result_t parseSID(const OCClientResponse * const clientResponse)
+{
+ const char* const& pl_in = reinterpret_cast<const char *>(clientResponse->resJSONPayload);
+
+ const std::string pl(pl_in, strlen(pl_in));
+
+ const extract_result_t sid = extract_value("sid", pl);
+ const extract_result_t uri = extract_value("href", pl);
+ //TODO-CA: It should be just enough to send the SID alone and not the combination
+ // of it.
+ return std::make_pair(sid.first and uri.first, sid.second + ':' + uri.second);
+}
+
void parseClientResponse(OCClientResponse * clientResponse)
{
coapServerIP = getIPAddrTBServer(clientResponse);
coapServerPort = getPortTBServer(clientResponse);
coapServerResource = getQueryStrForGetPut(clientResponse);
}
+
+void collateSIDs(const OCClientResponse * clientResponse, const std::string& server_ip)
+{
+ static SID_set_t sids;
+
+ const extract_result_t sid_result = parseSID(clientResponse);
+
+ if(false == sid_result.first)
+ return;
+
+ const sid_t& sid = sid_result.second;
+
+ /* ...there's no need for an application to take any special action, but we can tell
+ if we've seen a resource before, regardless of the transport it arrive on: */
+ std::ostringstream msg;
+
+ if(not sids.insert(sid).second)
+ msg << "SID " << sid << " has been seen before.\n";
+ else
+ msg << "SID " << sid << " is new.\n";
+
+ OC_LOG(INFO, TAG, msg.str().c_str());
+}
OCMode myStackMode;
OCDeviceEntityHandler defaultDeviceHandler;
+OCStackResult getQueryFromUri(const char * uri, unsigned char** resourceType, char ** newURI);
//-----------------------------------------------------------------------------
// Macros
OCServerProtocolRequest serverRequest;
memset (&serverRequest, 0, sizeof(OCServerProtocolRequest));
- // copy URI of resource
- memcpy (&(serverRequest.resourceUrl), endPoint->resourceUri, strlen(endPoint->resourceUri));
+ OC_LOG_V(INFO, TAG, PCF("***** Endpoint URI ***** : %s\n"), (char*)endPoint->resourceUri);
+
+ char * newUri = (char *)endPoint->resourceUri;
+ unsigned char * query = NULL;
+ unsigned char * resourceType = NULL;
+ getQueryFromUri(endPoint->resourceUri, &query, &newUri);
+ OC_LOG_V(INFO, TAG, PCF("**********URI without query ****: %s\n"), newUri);
+ OC_LOG_V(INFO, TAG, PCF("**********Query ****: %s\n"), query);
+ //copy URI
+ memcpy (&(serverRequest.resourceUrl), newUri, strlen(newUri));
//copy query
- // TODO-CA: Is the query part of header option?
+ if(query)
+ {
+ memcpy (&(serverRequest.query), query, strlen(query));
+ }
//copy request payload
if (requestInfo->info.payload)
{
static OCStackResult verifyUriQueryLength(const char * inputUri,
uint16_t uriLen);
static uint8_t OCIsPacketTransferRequired(const char *request, const char *response, uint16_t size);
-OCStackResult getResourceType(const char * uri, unsigned char** resourceType, char ** newURI);
+OCStackResult getResourceType(const char * query, unsigned char** resourceType);
//-----------------------------------------------------------------------------
// Public APIs
* OC_STACK_INVALID_METHOD - invalid resource method
* OC_STACK_INVALID_URI - invalid required or reference URI
*/
-
+#ifdef CA_INT
+OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requiredUri,
+ const char *referenceUri, const char *request, uint8_t conType,
+ OCQualityOfService qos, OCCallbackData *cbData,
+ OCHeaderOption * options, uint8_t numOptions)
+#else
OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requiredUri,
const char *referenceUri, const char *request,
OCQualityOfService qos, OCCallbackData *cbData,
OCHeaderOption * options, uint8_t numOptions)
+#endif
{
OCStackResult result = OC_STACK_ERROR;
OCCoAPToken token;
ClientCB *clientCB = NULL;
unsigned char * requestUri = NULL;
unsigned char * resourceType = NULL;
+ unsigned char * query = NULL;
char * newUri = (char *)requiredUri;
(void) referenceUri;
#ifdef CA_INT
#ifdef WITH_PRESENCE
if(method == OC_REST_PRESENCE)
{
- result = getResourceType(requiredUri, &resourceType, &newUri);
- if(resourceType) {
- OC_LOG_V(DEBUG, TAG, "Got Resource Type: %s", resourceType);
+ // Replacing method type with GET because "presence" is a stack layer only implementation.
+ method = OC_REST_GET;
+ result = getQueryFromUri(requiredUri, &query, &newUri);
+ if(query)
+ {
+ result = getResourceType((char *) query, &resourceType);
+ if(resourceType)
+ {
+ OC_LOG_V(DEBUG, TAG, "Got Resource Type: %s", resourceType);
+ }
+ else
+ {
+ OC_LOG(DEBUG, TAG, PCF("Resource type is NULL."));
+ }
}
else
{
- OC_LOG(DEBUG, TAG, PCF("Got Resource Type is NULL."));
+ OC_LOG(DEBUG, TAG, PCF("Query string is NULL."));
}
if(result != OC_STACK_OK)
{
goto exit;
}
-#ifdef WITH_PRESENCE
- if(method == OC_REST_PRESENCE)
- {
- // Replacing method type with GET because "presence" is a stack layer only implementation.
- method = OC_REST_GET;
- }
-#endif
-
// Make call to OCCoAP layer
result = OCDoCoAPResource(method, qos, &token, newUri, request, options, numOptions);
#endif // CA_INT
}
/**
- * Retrieves a resource type based upon a uri string if the uri string contains only just one
+ * Retrieves a resource type based upon a query ontains only just one
* resource attribute (and that has to be of type "rt").
*
- * @remark This API malloc's memory for the resource type and newURI. Do not malloc resourceType
- * or newURI before passing in.
+ * @remark This API malloc's memory for the resource type. Do not malloc resourceType
+ * before passing in.
*
- * @param uri - Valid URI for "requiredUri" parameter to OCDoResource API.
+ * @param query - The quert part of the URI
* @param resourceType - The resource type to be populated; pass by reference.
- * @param newURI - Return URI without resourceType appended to the end of it. This is used to
- * ensure that the uri parameter is not modified; pass by reference.
*
* @return
- * OC_STACK_INVALID_URI - Returns this if the URI is invalid/NULL.
* OC_STACK_INVALID_PARAM - Returns this if the resourceType parameter is invalid/NULL.
* OC_STACK_OK - Success
*/
-OCStackResult getResourceType(const char * uri, unsigned char** resourceType, char ** newURI)
+OCStackResult getResourceType(const char * query, unsigned char** resourceType)
+{
+ if(!query)
+ {
+ return OC_STACK_INVALID_PARAM;
+ }
+
+ OCStackResult result = OC_STACK_ERROR;
+
+ if(strncmp(query, "rt=", 3) == 0)
+ {
+ *resourceType = (unsigned char *) OCMalloc(strlen(query)-3);
+ if(!*resourceType)
+ {
+ result = OC_STACK_NO_MEMORY;
+ }
+
+ strcpy((char *)*resourceType, ((const char *)&query[3]));
+ result = OC_STACK_OK;
+ }
+
+ return result;
+}
+
+OCStackResult getQueryFromUri(const char * uri, unsigned char** query, char ** newURI)
{
if(!uri)
{
return OC_STACK_INVALID_URI;
}
- if(!resourceType || !newURI)
+ if(!query || !newURI)
{
return OC_STACK_INVALID_PARAM;
}
char* strTokPtr;
leftToken = strtok_r((char *)tempURI, "?", &strTokPtr);
+ //TODO-CA: This could be simplified. Clean up required.
while(leftToken != NULL)
{
- if(strncmp(leftToken, "rt=", 3) == 0)
+ if(strncmp(leftToken, "rt=", 3) == 0 || strncmp(leftToken, "if=", 3) == 0)
{
- *resourceType = (unsigned char *) OCMalloc(strlen(leftToken)-3);
- if(!*resourceType)
+ *query = (unsigned char *) OCMalloc(strlen(leftToken));
+ if(!*query)
{
goto exit;
}
- strcpy((char *)*resourceType, ((const char *)&leftToken[3]));
+ strcpy((char *)*query, ((const char *)&leftToken[0]));
break;
}
leftToken = strtok_r(NULL, "?", &strTokPtr);
examples_env.AppendUnique(LIBS = ['-lpthread'])
examples_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
-examples_env.PrependUnique(LIBS = ['oc', 'octbstack', 'coap', 'oc_logger'])
+examples_env.PrependUnique(LIBS = ['oc', 'octbstack', 'coap', 'coap_csdk', 'oc_logger', 'connectivity_abstraction'])
+
+examples_env.ParseConfig('pkg-config --libs glib-2.0');
if target_os == 'android':
examples_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
env.AppendTarget('examples')
#ios doesn't allow run application from terminal, so won't build these examples
-if target_os != 'ios':
- SConscript('ocicuc/SConscript')
+#if target_os != 'ios':
+# SConscript('ocicuc/SConscript')
OCPlatform::Configure(cfg);
try
{
+#ifdef CA_INT
+ OCConnectivityType connectivityType = OC_WIFI;
+ OCPlatform::getDeviceInfo("", "coap://224.0.1.187/oc/core/d", connectivityType,
+ &receivedDeviceInfo);
+#else
OCPlatform::getDeviceInfo("", "coap://224.0.1.187/oc/core/d", &receivedDeviceInfo);
+#endif
std::cout<< "Querying for device information... " <<std::endl;
// A condition variable will free the mutex it is given, then do a non-
{
std::cout << "Fridge Client has started " <<std::endl;
FindCallback f (std::bind(&ClientFridge::foundDevice, this, PH::_1));
-
+#ifdef CA_INT
+ OCConnectivityType connectivityType = OC_WIFI;
+ OCStackResult result = OCPlatform::findResource(
+ "", "coap://224.0.1.187/oc/core?rt=intel.fridge", connectivityType, f);
+#else
OCStackResult result = OCPlatform::findResource(
"", "coap://224.0.1.187/oc/core?rt=intel.fridge", f);
+#endif
if(OC_STACK_OK != result)
{
// server, and query them.
std::vector<std::string> lightTypes = {"intel.fridge.light"};
std::vector<std::string> ifaces = {DEFAULT_INTERFACE};
+#ifdef CA_INT
+ OCConnectivityType connectivityType = OC_WIFI;
+ OCResource::Ptr light = constructResourceObject(resource->host(),
+ "/light", connectivityType, false, lightTypes, ifaces);
+#else
OCResource::Ptr light = constructResourceObject(resource->host(),
"/light", false, lightTypes, ifaces);
+#endif
if(!light)
{
}
std::vector<std::string> doorTypes = {"intel.fridge.door"};
-
+#ifdef CA_INT
+ OCResource::Ptr leftdoor = constructResourceObject(resource->host(),
+ "/door/left", connectivityType, false, doorTypes, ifaces);
+#else
OCResource::Ptr leftdoor = constructResourceObject(resource->host(),
"/door/left", false, doorTypes, ifaces);
+#endif
+
if(!leftdoor)
{
std::cout << "Error: Left Door Resource Object construction returned null\n";
return;
}
+#ifdef CA_INT
+ OCResource::Ptr rightdoor = constructResourceObject(resource->host(),
+ "/door/right", connectivityType, false, doorTypes, ifaces);
+#else
OCResource::Ptr rightdoor = constructResourceObject(resource->host(),
"/door/right", false, doorTypes, ifaces);
+#endif
+
if(!rightdoor)
{
std::cout << "Error: Right Door Resource Object construction returned null\n";
return;
}
+#ifdef CA_INT
+ OCResource::Ptr randomdoor = constructResourceObject(resource->host(),
+ "/door/random", connectivityType, false, doorTypes, ifaces);
+#else
OCResource::Ptr randomdoor = constructResourceObject(resource->host(),
"/door/random", false, doorTypes, ifaces);
+#endif
if(!randomdoor)
{
std::cout << "Error: Random Door Resource Object construction returned null\n";
try
{
// Find all resources
+#ifdef CA_INT
+ OCConnectivityType connectivityType = OC_WIFI;
+ OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.garage",
+ connectivityType, &foundResource);
+#else
OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.garage",
&foundResource);
+#endif
std::cout<< "Finding Resource... " <<std::endl;
// A condition variable will free the mutex it is given, then do a non-
OCPlatform::Configure(config);
string resourceTypeName = "a.collection";
+#ifdef CA_INT
+ OCConnectivityType connectivityType = OC_WIFI;
+ OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=a.collection",
+ connectivityType, &foundResource);
+#else
OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=a.collection", &foundResource);
+#endif
isReady = false;
cout << "registerResource is called." << endl;
+#ifdef CA_INT
+ OCConnectivityType connectivityType = OC_WIFI;
+ OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.light",
+ connectivityType, &foundResource);
+#else
OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.light", &foundResource);
+#endif
+
OCPlatform::bindInterfaceToResource(resourceHandle, GROUP_INTERFACE);
OCPlatform::bindInterfaceToResource(resourceHandle, DEFAULT_INTERFACE);
])
ocicuc_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
-ocicuc_env.PrependUnique(LIBS = ['oc', 'octbstack', 'coap', 'oc_logger'])
+ocicuc_env.PrependUnique(LIBS = ['oc', 'octbstack', 'coap_csdk', 'coap', 'oc_logger', 'connectivity_abstraction'])
+
+ocicuc_env.ParseConfig('pkg-config --libs glib-2.0');
target_os = env.get('TARGET_OS')
if target_os not in ['windows', 'winrt']:
small_example = ocicuc_env.Program('small_example', ['small_example.cpp', 'driver.cpp', 'utility.cpp'])
Alias("examples_ocicuc", [client, server, monoprocess, small_example])
-env.AppendTarget('examples_ocicuc')
\ No newline at end of file
+env.AppendTarget('examples_ocicuc')
OCStackResult result = OC_STACK_OK;
curResource = resource;
OCPlatform::OCPresenceHandle presenceHandle = nullptr;
+#ifdef CA_INT
+ OCConnectivityType connectivityType = OC_WIFI;
+#endif
if(TEST_CASE == TEST_UNICAST_PRESENCE_NORMAL)
{
+#ifdef CA_INT
+ result = OCPlatform::subscribePresence(presenceHandle, hostAddress,
+ connectivityType, &presenceHandler);
+#else
result = OCPlatform::subscribePresence(presenceHandle, hostAddress,
&presenceHandler);
+#endif
if(result == OC_STACK_OK)
{
std::cout<< "Subscribed to unicast address: " << hostAddress << std::endl;
if(TEST_CASE == TEST_UNICAST_PRESENCE_WITH_FILTER ||
TEST_CASE == TEST_UNICAST_PRESENCE_WITH_FILTERS)
{
+#ifdef CA_INT
+ result = OCPlatform::subscribePresence(presenceHandle, hostAddress,
+ "core.light", connectivityType, &presenceHandler);
+#else
result = OCPlatform::subscribePresence(presenceHandle, hostAddress,
"core.light", &presenceHandler);
+#endif
if(result == OC_STACK_OK)
{
std::cout<< "Subscribed to unicast address: " << hostAddress;
}
if(TEST_CASE == TEST_UNICAST_PRESENCE_WITH_FILTERS)
{
+#ifdef CA_INT
+ result = OCPlatform::subscribePresence(presenceHandle, hostAddress, "core.fan",
+ connectivityType, &presenceHandler);
+#else
result = OCPlatform::subscribePresence(presenceHandle, hostAddress, "core.fan",
&presenceHandler);
+#endif
if(result == OC_STACK_OK)
{
std::cout<< "Subscribed to unicast address: " << hostAddress;
OCPlatform::OCPresenceHandle presenceHandle = nullptr;
OCStackResult result = OC_STACK_OK;
+#ifdef CA_INT
+ OCConnectivityType connectivityType = OC_WIFI;
+#endif
if(TEST_CASE == TEST_MULTICAST_PRESENCE_NORMAL)
{
+#ifdef CA_INT
+ result = OCPlatform::subscribePresence(presenceHandle,
+ OC_MULTICAST_IP, connectivityType, presenceHandler);
+#else
result = OCPlatform::subscribePresence(presenceHandle,
OC_MULTICAST_IP, presenceHandler);
+#endif
+
if(result == OC_STACK_OK)
{
std::cout << "Subscribed to multicast presence." << std::endl;
}
else if(TEST_CASE == TEST_MULTICAST_PRESENCE_WITH_FILTER)
{
+#ifdef CA_INT
+ result = OCPlatform::subscribePresence(presenceHandle, OC_MULTICAST_IP, "core.light",
+ connectivityType, &presenceHandler);
+#else
result = OCPlatform::subscribePresence(presenceHandle, OC_MULTICAST_IP, "core.light",
&presenceHandler);
+#endif
if(result == OC_STACK_OK)
{
std::cout << "Subscribed to multicast presence with resource type";
}
else if(TEST_CASE == TEST_MULTICAST_PRESENCE_WITH_FILTERS)
{
+#ifdef CA_INT
+ result = OCPlatform::subscribePresence(presenceHandle, OC_MULTICAST_IP, "core.light",
+ connectivityType, &presenceHandler);
+#else
result = OCPlatform::subscribePresence(presenceHandle, OC_MULTICAST_IP, "core.light",
&presenceHandler);
+#endif
if(result == OC_STACK_OK)
{
std::cout << "Subscribed to multicast presence with resource type";
}
std::cout << "\"core.light\"." << std::endl;
+#ifdef CA_INT
+ result = OCPlatform::subscribePresence(presenceHandle, OC_MULTICAST_IP, "core.fan",
+ connectivityType, &presenceHandler);
+#else
result = OCPlatform::subscribePresence(presenceHandle, OC_MULTICAST_IP, "core.fan",
&presenceHandler);
+#endif
if(result == OC_STACK_OK)
{
std::cout<< "Subscribed to multicast presence with resource type";
else
{
// Find all resources
+#ifdef CA_INT
+ OCConnectivityType connectivityType = OC_WIFI;
+ result = OCPlatform::findResource("", "coap://224.0.1.187/oc/core",
+ connectivityType, &foundResource);
+#else
result = OCPlatform::findResource("", "coap://224.0.1.187/oc/core", &foundResource);
+#endif
if(result == OC_STACK_OK)
{
std::cout << "Finding Resource... " << std::endl;
try
{
// Find all resources
+#ifdef CA_INT
+ OCConnectivityType connectivityType = OC_WIFI;
+ OCPlatform::findResource("", "coap://224.0.1.187/oc/core", connectivityType,
+ &foundResource);
+#else
OCPlatform::findResource("", "coap://224.0.1.187/oc/core", &foundResource);
+#endif
+
std::cout<< "Finding Resource... " <<std::endl;
// A condition variable will free the mutex it is given, then do a non-
// makes it so that all boolean values are printed as 'true/false' in this stream
std::cout.setf(std::ios::boolalpha);
// Find all resources
+#ifdef CA_INT
+ OCConnectivityType connectivityType = OC_WIFI;
+ OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.light",
+ connectivityType, &foundResource);
+#else
OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.light", &foundResource);
+#endif
std::cout<< "Finding Resource... " <<std::endl;
// A condition variable will free the mutex it is given, then do a non-
try
{
// Find all resources
+#ifdef CA_INT
+ OCConnectivityType connectivityType = OC_WIFI;
+ OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.light",
+ connectivityType, &foundResource, OC::QualityOfService::LowQos);
+#else
OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.light", &foundResource,
OC::QualityOfService::LowQos);
+#endif
std::cout<< "Finding Resource... " <<std::endl;
// A condition variable will free the mutex it is given, then do a non-
{
std::cout<<"Starting Client find:"<<std::endl;
FindCallback f (std::bind(&ClientWorker::foundResource, this, std::placeholders::_1));
+#ifdef CA_INT
+ OCConnectivityType connectivityType = OC_WIFI;
std::cout<<"result:" <<
- OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.foo", f)
- << std::endl;
+ OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.foo", connectivityType, f)
+ << std::endl;
+#else
+ std::cout<<"result:" <<
+ OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.foo", f)
+ << std::endl;
+#endif
+
std::cout<<"Finding Resource..."<<std::endl;
{
void client1()
{
std::cout << "in client1\n";
-
+#ifdef CA_INT
+ OCConnectivityType connectivityType = OC_WIFI;
+ std::cout<<"result1:" << OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.foo",
+ connectivityType, foundResource1)<< std::endl;
+#else
std::cout<<"result1:" << OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.foo",
foundResource1)<< std::endl;
+#endif
// A condition variable will free the mutex it is given, then do a non-
// intensive block until 'notify' is called on it. In this case, since we
void client2()
{
std::cout << "in client2\n";
-
+#ifdef CA_INT
+ OCConnectivityType connectivityType = OC_WIFI;
+ std::cout<<"result2:" << OCPlatform::findResource("",
+ "coap://224.0.1.187/oc/core?rt=core.foo",
+ connectivityType, foundResource2)<< std::endl;
+#else
std::cout<<"result2:" << OCPlatform::findResource("",
"coap://224.0.1.187/oc/core?rt=core.foo",
foundResource2)<< std::endl;
+#endif
// A condition variable will free the mutex it is given, then do a non-
// intensive block until 'notify' is called on it. In this case, since we
IClientWrapper()
{}
+#ifdef CA_INT
+ virtual OCStackResult ListenForResource(const std::string& serviceUrl,
+ const std::string& resourceType, uint8_t connectivityType,
+ FindCallback& callback,
+ QualityOfService QoS) = 0;
+
+ virtual OCStackResult ListenForDevice(const std::string& serviceUrl,
+ const std::string& deviceURI, uint8_t connectivityType,
+ FindDeviceCallback& callback,
+ QualityOfService QoS) = 0;
+
+ virtual OCStackResult GetResourceRepresentation(const std::string& host,
+ const std::string& uri, uint8_t connectivityType,
+ const QueryParamsMap& queryParams,
+ const HeaderOptions& headerOptions,
+ GetCallback& callback, QualityOfService QoS)=0;
+
+ virtual OCStackResult PutResourceRepresentation(const std::string& host,
+ const std::string& uri, uint8_t connectivityType,
+ const OCRepresentation& rep, const QueryParamsMap& queryParams,
+ const HeaderOptions& headerOptions,
+ PutCallback& callback, QualityOfService QoS) = 0;
+
+ virtual OCStackResult PostResourceRepresentation(const std::string& host,
+ const std::string& uri, uint8_t connectivityType,
+ const OCRepresentation& rep, const QueryParamsMap& queryParams,
+ const HeaderOptions& headerOptions,
+ PostCallback& callback, QualityOfService QoS) = 0;
+
+ virtual OCStackResult DeleteResource(const std::string& host, const std::string& uri,
+ uint8_t connectivityType, const HeaderOptions& headerOptions,
+ DeleteCallback& callback, QualityOfService QoS) = 0;
+
+ virtual OCStackResult ObserveResource(ObserveType observeType, OCDoHandle* handle,
+ const std::string& host, const std::string& uri, uint8_t connectivityType,
+ const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
+ ObserveCallback& callback, QualityOfService QoS)=0;
+#else
virtual OCStackResult ListenForResource(const std::string& serviceUrl,
const std::string& resourceType, FindCallback& callback,
QualityOfService QoS) = 0;
const std::string& host, const std::string& uri,
const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
ObserveCallback& callback, QualityOfService QoS)=0;
-
+#endif
virtual OCStackResult CancelObserveResource(OCDoHandle handle, const std::string& host,
const std::string& uri, const HeaderOptions& headerOptions, QualityOfService QoS)=0;
+#ifdef CA_INT
+ virtual OCStackResult SubscribePresence(OCDoHandle* handle, const std::string& host,
+ const std::string& resourceType, uint8_t connectivityType,
+ SubscribeCallback& presenceHandler)=0;
+#else
virtual OCStackResult SubscribePresence(OCDoHandle* handle, const std::string& host,
const std::string& resourceType, SubscribeCallback& presenceHandler)=0;
-
+#endif
virtual OCStackResult UnsubscribePresence(OCDoHandle handle) =0;
virtual OCStackResult GetDefaultQos(QualityOfService& qos) = 0;
PlatformConfig cfg);
virtual ~InProcClientWrapper();
+#ifdef CA_INT
+ virtual OCStackResult ListenForResource(const std::string& serviceUrl,
+ const std::string& resourceType, uint8_t connectivityType, FindCallback& callback,
+ QualityOfService QoS);
+
+ virtual OCStackResult ListenForDevice(const std::string& serviceUrl,
+ const std::string& deviceURI, uint8_t connectivityType, FindDeviceCallback& callback,
+ QualityOfService QoS);
+
+ virtual OCStackResult GetResourceRepresentation(const std::string& host,
+ const std::string& uri, uint8_t connectivityType, const QueryParamsMap& queryParams,
+ const HeaderOptions& headerOptions,
+ GetCallback& callback, QualityOfService QoS);
+
+ virtual OCStackResult PutResourceRepresentation(const std::string& host,
+ const std::string& uri, uint8_t connectivityType, const OCRepresentation& attributes,
+ const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
+ PutCallback& callback, QualityOfService QoS);
+
+ virtual OCStackResult PostResourceRepresentation(const std::string& host,
+ const std::string& uri, uint8_t connectivityType, const OCRepresentation& attributes,
+ const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
+ PostCallback& callback, QualityOfService QoS);
+
+ virtual OCStackResult DeleteResource(const std::string& host, const std::string& uri,
+ uint8_t connectivityType, const HeaderOptions& headerOptions,
+ DeleteCallback& callback, QualityOfService QoS);
+
+ virtual OCStackResult ObserveResource(ObserveType observeType, OCDoHandle* handle,
+ const std::string& host, const std::string& uri, uint8_t connectivityType,
+ const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
+ ObserveCallback& callback, QualityOfService QoS);
+#else
virtual OCStackResult ListenForResource(const std::string& serviceUrl,
const std::string& resourceType, FindCallback& 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, QualityOfService QoS);
-
+#endif
virtual OCStackResult CancelObserveResource(OCDoHandle handle, const std::string& host,
const std::string& uri, const HeaderOptions& headerOptions, QualityOfService QoS);
+#ifdef CA_INT
+ virtual OCStackResult SubscribePresence(OCDoHandle* handle, const std::string& host,
+ const std::string& resourceType, uint8_t connectivityType,
+ SubscribeCallback& presenceHandler);
+#else
virtual OCStackResult SubscribePresence(OCDoHandle* handle, const std::string& host,
const std::string& resourceType, SubscribeCallback& presenceHandler);
+#endif
virtual OCStackResult UnsubscribePresence(OCDoHandle handle);
OCStackResult GetDefaultQos(QualityOfService& QoS);
* as BTH etc.
* NOTE: OCStackResult is defined in ocstack.h.
*/
+#ifdef CA_INT
+ OCStackResult findResource(const std::string& host, const std::string& resourceURI,
+ uint8_t connectivityType, FindCallback resourceHandler);
+ OCStackResult findResource(const std::string& host, const std::string& resourceURI,
+ uint8_t connectivityType, FindCallback resourceHandler, QualityOfService QoS);
+#else
OCStackResult findResource(const std::string& host, const std::string& resourceURI,
FindCallback resourceHandler);
OCStackResult findResource(const std::string& host, const std::string& resourceURI,
FindCallback resourceHandler, QualityOfService QoS);
-
+#endif
/**
* API for Device Discovery
*
* @param QualityOfService the quality of communication
*
*/
+#ifdef CA_INT
+ OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
+ uint8_t connectivityType, FindDeviceCallback deviceInfoHandler);
+ OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
+ uint8_t connectivityType, FindDeviceCallback deviceInfoHandler,
+ QualityOfService QoS);
+#else
OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
FindDeviceCallback deviceInfoHandler);
OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
FindDeviceCallback deviceInfoHandler, QualityOfService QoS);
-
+#endif
/**
* This API registers a resource with the server
* NOTE: This API applies to server side only.
*
* @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
*/
+#ifdef CA_INT
+ OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
+ uint8_t connectivityType, SubscribeCallback presenceHandler);
+ OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
+ const std::string& resourceType, uint8_t connectivityType,
+ SubscribeCallback presenceHandler);
+#else
OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
SubscribeCallback presenceHandler);
OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
const std::string& resourceType, SubscribeCallback presenceHandler);
-
+#endif
/**
* unsubscribes from a previously subscribed server's presence events. Note that
* you may for a short time still receive events from the server since it may take time
* @param interfaces - a collection of interfaces that the resource supports/implements
* @return OCResource::Ptr - a shared pointer to the new resource object
*/
+#ifdef CA_INT
+ OCResource::Ptr constructResourceObject(const std::string& host, const std::string& uri,
+ uint8_t connectivityType, bool isObservable,
+ const std::vector<std::string>& resourceTypes,
+ const std::vector<std::string>& interfaces);
+#else
OCResource::Ptr constructResourceObject(const std::string& host, const std::string& uri,
bool isObservable, const std::vector<std::string>& resourceTypes,
const std::vector<std::string>& interfaces);
-
+#endif
/**
* Allows application entity handler to send response to an incoming request.
*
* as BTH etc.
* NOTE: OCStackResult is defined in ocstack.h.
*/
+#ifdef CA_INT
+ OCStackResult findResource(const std::string& host, const std::string& resourceURI,
+ uint8_t connectivityType, FindCallback resourceHandler);
+ OCStackResult findResource(const std::string& host, const std::string& resourceURI,
+ uint8_t connectivityType, FindCallback resourceHandler, QualityOfService QoS);
+#else
OCStackResult findResource(const std::string& host, const std::string& resourceURI,
FindCallback resourceHandler);
OCStackResult findResource(const std::string& host, const std::string& resourceURI,
FindCallback resourceHandler, QualityOfService QoS);
-
+#endif
/**
* API for Device Discovery
*
* @param QualityOfService the quality of communication
*
*/
+#ifdef CA_INT
+ OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
+ uint8_t connectivityType, FindDeviceCallback deviceInfoHandler);
+ OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
+ uint8_t connectivityType, FindDeviceCallback deviceInfoHandler,
+ QualityOfService QoS);
+#else
OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
FindDeviceCallback deviceInfoHandler);
OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
FindDeviceCallback deviceInfoHandler, QualityOfService QoS);
-
+#endif
/**
* This API registers a resource with the server
* NOTE: This API applies to server side only.
*
* @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
*/
+#ifdef CA_INT
+ OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
+ uint8_t connectivityType, SubscribeCallback presenceHandler);
+ OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
+ const std::string& resourceType, uint8_t connectivityType,
+ SubscribeCallback presenceHandler);
+#else
OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
SubscribeCallback presenceHandler);
OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
const std::string& resourceType, SubscribeCallback presenceHandler);
-
+#endif
/**
* unsubscribes from a previously subscribed server's presence events. Note that
* you may for a short time still receive events from the server since it may take time
* @param interfaces - a collection of interfaces that the resource supports/implements
* @return OCResource::Ptr - a shared pointer to the new resource object
*/
+#ifdef CA_INT
+ OCResource::Ptr constructResourceObject(const std::string& host, const std::string& uri,
+ uint8_t connectivityType, bool isObservable,
+ const std::vector<std::string>& resourceTypes,
+ const std::vector<std::string>& interfaces);
+#else
OCResource::Ptr constructResourceObject(const std::string& host, const std::string& uri,
bool isObservable, const std::vector<std::string>& resourceTypes,
const std::vector<std::string>& interfaces);
-
+#endif
/**
* Allows application entity handler to send response to an incoming request.
*
*/
std::string uri() const;
+#ifdef CA_INT
+ /**
+ * Function to get the connectivity type of this resource
+ * @return uint8_t connectivity type
+ */
+ uint8_t connectivityType() const;
+#endif
+
/**
* Function to provide ability to check if this resource is observable or not
* @return bool true indicates resource is observable; false indicates resource is
std::weak_ptr<IClientWrapper> m_clientWrapper;
std::string m_uri;
std::string m_host;
+#ifdef CA_INT
+ uint8_t m_connectivityType;
+#endif
bool m_isObservable;
bool m_isCollection;
std::vector<std::string> m_resourceTypes;
HeaderOptions m_headerOptions;
private:
+#ifdef CA_INT
+ OCResource(std::weak_ptr<IClientWrapper> clientWrapper, const std::string& host,
+ const std::string& uri, uint8_t m_connectivityType, bool observable,
+ const std::vector<std::string>& resourceTypes,
+ const std::vector<std::string>& interfaces);
+#else
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);
+#endif
};
} // namespace OC
{
if(res.loaded())
{
+#ifdef CA_INT
+ //CA_TODO: To get the connectivity type correctly.
+ uint8_t connectivityType;
+ m_resources.push_back(std::shared_ptr<OCResource>(
+ new OCResource(m_clientWrapper,
+ ConvertOCAddrToString(res.secureType(),res.port()),
+ res.m_uri, connectivityType, res.observable(), res.resourceTypes(),
+ res.interfaces())));
+#else
m_resources.push_back(std::shared_ptr<OCResource>(
new OCResource(m_clientWrapper,
ConvertOCAddrToString(res.secureType(),res.port()),
res.m_uri, res.observable(), res.resourceTypes(),
res.interfaces())));
+#endif
}
}
PlatformConfig cfg)
{}
+#ifdef CA_INT
+ virtual OCStackResult ListenForResource(const std::string& serviceUrl,
+ const std::string& resourceType, uint8_t connectivityType,
+ FindCallback& callback, QualityOfService QoS)
+ {return OC_STACK_NOTIMPL;}
+
+ virtual OCStackResult ListenForDevice(const std::string& serviceUrl,
+ const std::string& deviceURI, uint8_t connectivityType, FindDeviceCallback& callback,
+ QualityOfService QoS)
+ {return OC_STACK_NOTIMPL;}
+
+ virtual OCStackResult GetResourceRepresentation(const std::string& host,
+ const std::string& uri, uint8_t connectivityType, const QueryParamsMap& queryParams,
+ const HeaderOptions& headerOptions, GetCallback& callback,
+ QualityOfService QoS)
+ {return OC_STACK_NOTIMPL;}
+
+ virtual OCStackResult PutResourceRepresentation(const std::string& host,
+ const std::string& uri, uint8_t connectivityType, const OCRepresentation& attributes,
+ const QueryParamsMap& queryParams,
+ const HeaderOptions& headerOptions, PutCallback& callback,
+ QualityOfService QoS)
+ {return OC_STACK_NOTIMPL;}
+
+ virtual OCStackResult PostResourceRepresentation(const std::string& host,
+ const std::string& uri, uint8_t connectivityType, const OCRepresentation& attributes,
+ const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
+ PostCallback& callback, QualityOfService QoS)
+ {return OC_STACK_NOTIMPL;}
+
+ virtual OCStackResult DeleteResource(const std::string& host, const std::string& uri,
+ uint8_t connectivityType, const HeaderOptions& headerOptions, DeleteCallback& callback,
+ QualityOfService QoS) {return OC_STACK_NOTIMPL;}
+
+ virtual OCStackResult ObserveResource(ObserveType observeType, OCDoHandle* handle,
+ const std::string& host, const std::string& uri, uint8_t connectivityType,
+ const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
+ ObserveCallback& callback, QualityOfService QoS){return OC_STACK_NOTIMPL;}
+#else
virtual OCStackResult ListenForResource(const std::string& serviceUrl,
const std::string& resourceType, FindCallback& callback, QualityOfService QoS)
{return OC_STACK_NOTIMPL;}
const std::string& host, const std::string& uri, const QueryParamsMap& queryParams,
const HeaderOptions& headerOptions,
ObserveCallback& callback, QualityOfService QoS){return OC_STACK_NOTIMPL;}
-
+#endif
virtual OCStackResult CancelObserveResource(OCDoHandle handle, const std::string& host,
const std::string& uri,
const HeaderOptions& headerOptions, QualityOfService QoS){return OC_STACK_NOTIMPL;}
-
+#ifdef CA_INT
+ virtual OCStackResult SubscribePresence(OCDoHandle* handle, const std::string& host,
+ const std::string& resourceType, uint8_t connectivityType,
+ SubscribeCallback& presenceHandler)
+ {return OC_STACK_NOTIMPL;}
+#else
virtual OCStackResult SubscribePresence(OCDoHandle* handle, const std::string& host,
const std::string& resourceType, SubscribeCallback& presenceHandler)
{return OC_STACK_NOTIMPL;}
-
+#endif
virtual OCStackResult UnsubscribePresence(OCDoHandle handle){return OC_STACK_NOTIMPL;}
virtual OCStackResult GetDefaultQos(QualityOfService& QoS){return OC_STACK_NOTIMPL;}
OUT_DIR := $(ROOT_DIR)/$(BUILD)
OBJ_DIR := $(OUT_DIR)/obj
-CXX_FLAGS.debug := -g3 -std=c++0x -Wall -pthread -O0
-CXX_FLAGS.release := -std=c++0x -Wall -pthread -O3
+#TODO-CA Need to remove flag later
+CXX_FLAGS.debug := -g3 -std=c++0x -Wall -pthread -O0 -DCA_INT
+CXX_FLAGS.release := -std=c++0x -Wall -pthread -O3 -DCA_INT
CXX_INC := -I./include/
CXX_INC += -I./oc_logger/include
return OC_STACK_KEEP_TRANSACTION;
}
+#ifdef CA_INT
+ OCStackResult InProcClientWrapper::ListenForResource(const std::string& serviceUrl,
+ const std::string& resourceType, uint8_t connectivityType,
+ FindCallback& callback, QualityOfService QoS)
+#else
OCStackResult InProcClientWrapper::ListenForResource(const std::string& serviceUrl,
const std::string& resourceType, FindCallback& callback, QualityOfService QoS)
+#endif
{
OCStackResult result;
{
std::lock_guard<std::recursive_mutex> lock(*cLock);
OCDoHandle handle;
+#ifdef CA_INT
+ result = OCDoResource(&handle, OC_REST_GET,
+ resourceType.c_str(),
+ nullptr, nullptr, connectivityType,
+ static_cast<OCQualityOfService>(QoS),
+ &cbdata,
+ NULL, 0);
+#else
result = OCDoResource(&handle, OC_REST_GET,
resourceType.c_str(),
nullptr, nullptr,
static_cast<OCQualityOfService>(QoS),
&cbdata,
NULL, 0);
+#endif
}
else
{
return OC_STACK_KEEP_TRANSACTION;
}
+#ifdef CA_INT
+ OCStackResult InProcClientWrapper::ListenForDevice(const std::string& serviceUrl,
+ const std::string& deviceURI, uint8_t connectivityType,
+ FindDeviceCallback& callback, QualityOfService QoS)
+#else
OCStackResult InProcClientWrapper::ListenForDevice(const std::string& serviceUrl,
const std::string& deviceURI, FindDeviceCallback& callback, QualityOfService QoS)
+#endif
{
OCStackResult result;
{
std::lock_guard<std::recursive_mutex> lock(*cLock);
OCDoHandle handle;
+#ifdef CA_INT
+ result = OCDoResource(&handle, OC_REST_GET,
+ deviceURI.c_str(),
+ nullptr, nullptr, connectivityType,
+ static_cast<OCQualityOfService>(QoS),
+ &cbdata,
+ NULL, 0);
+#else
result = OCDoResource(&handle, OC_REST_GET,
deviceURI.c_str(),
nullptr, nullptr,
static_cast<OCQualityOfService>(QoS),
&cbdata,
NULL, 0);
+#endif
}
else
{
return OC_STACK_DELETE_TRANSACTION;
}
+#ifdef CA_INT
+ OCStackResult InProcClientWrapper::GetResourceRepresentation(const std::string& host,
+ const std::string& uri, uint8_t connectivityType, const QueryParamsMap& queryParams,
+ const HeaderOptions& headerOptions, GetCallback& callback,
+ QualityOfService QoS)
+#else
OCStackResult InProcClientWrapper::GetResourceRepresentation(const std::string& host,
const std::string& uri, const QueryParamsMap& queryParams,
const HeaderOptions& headerOptions, GetCallback& callback,
QualityOfService QoS)
+#endif
{
OCStackResult result;
OCCallbackData cbdata = {0};
OCHeaderOption options[MAX_HEADER_OPTIONS];
assembleHeaderOptions(options, headerOptions);
+#ifdef CA_INT
+ result = OCDoResource(&handle, OC_REST_GET, os.str().c_str(),
+ nullptr, nullptr, connectivityType,
+ static_cast<OCQualityOfService>(QoS),
+ &cbdata,
+ options, headerOptions.size());
+#else
result = OCDoResource(&handle, OC_REST_GET, os.str().c_str(),
nullptr, nullptr,
static_cast<OCQualityOfService>(QoS),
&cbdata,
options, headerOptions.size());
+#endif
}
else
{
return ocInfo.getJSONRepresentation(OCInfoFormat::IncludeOC);
}
+#ifdef CA_INT
+ OCStackResult InProcClientWrapper::PostResourceRepresentation(const std::string& host,
+ const std::string& uri, uint8_t connectivityType, const OCRepresentation& rep,
+ const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
+ PostCallback& callback, QualityOfService QoS)
+#else
OCStackResult InProcClientWrapper::PostResourceRepresentation(const std::string& host,
const std::string& uri, const OCRepresentation& rep,
const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
PostCallback& callback, QualityOfService QoS)
+#endif
{
OCStackResult result;
OCCallbackData cbdata = {0};
OCDoHandle handle;
assembleHeaderOptions(options, headerOptions);
+#ifdef CA_INT
+ result = OCDoResource(&handle, OC_REST_POST,
+ os.str().c_str(), nullptr,
+ assembleSetResourcePayload(rep).c_str(), connectivityType,
+ static_cast<OCQualityOfService>(QoS),
+ &cbdata, options, headerOptions.size());
+#else
result = OCDoResource(&handle, OC_REST_POST,
os.str().c_str(), nullptr,
assembleSetResourcePayload(rep).c_str(),
static_cast<OCQualityOfService>(QoS),
&cbdata, options, headerOptions.size());
+#endif
}
else
{
return result;
}
-
+#ifdef CA_INT
+ OCStackResult InProcClientWrapper::PutResourceRepresentation(const std::string& host,
+ const std::string& uri, uint8_t connectivityType, const OCRepresentation& rep,
+ const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
+ PutCallback& callback, QualityOfService QoS)
+#else
OCStackResult InProcClientWrapper::PutResourceRepresentation(const std::string& host,
const std::string& uri, const OCRepresentation& rep,
const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
PutCallback& callback, QualityOfService QoS)
+#endif
{
OCStackResult result;
OCCallbackData cbdata = {0};
OCHeaderOption options[MAX_HEADER_OPTIONS];
assembleHeaderOptions(options, headerOptions);
+#ifdef CA_INT
+ result = OCDoResource(&handle, OC_REST_PUT,
+ os.str().c_str(), nullptr,
+ assembleSetResourcePayload(rep).c_str(), connectivityType,
+ static_cast<OCQualityOfService>(QoS),
+ &cbdata,
+ options, headerOptions.size());
+#else
result = OCDoResource(&handle, OC_REST_PUT,
os.str().c_str(), nullptr,
assembleSetResourcePayload(rep).c_str(),
static_cast<OCQualityOfService>(QoS),
&cbdata,
options, headerOptions.size());
+#endif
}
else
{
return OC_STACK_DELETE_TRANSACTION;
}
+#ifdef CA_INT
+ OCStackResult InProcClientWrapper::DeleteResource(const std::string& host,
+ const std::string& uri, uint8_t connectivityType, const HeaderOptions& headerOptions,
+ DeleteCallback& callback, QualityOfService QoS)
+#else
OCStackResult InProcClientWrapper::DeleteResource(const std::string& host,
const std::string& uri, const HeaderOptions& headerOptions,
DeleteCallback& callback, QualityOfService QoS)
+#endif
{
OCStackResult result;
OCCallbackData cbdata = {0};
assembleHeaderOptions(options, headerOptions);
std::lock_guard<std::recursive_mutex> lock(*cLock);
-
+#ifdef CA_INT
+ result = OCDoResource(&handle, OC_REST_DELETE,
+ os.str().c_str(), nullptr,
+ nullptr, connectivityType,
+ static_cast<OCQualityOfService>(m_cfg.QoS),
+ &cbdata, options, headerOptions.size());
+#else
result = OCDoResource(&handle, OC_REST_DELETE,
os.str().c_str(), nullptr,
nullptr, static_cast<OCQualityOfService>(m_cfg.QoS),
&cbdata, options, headerOptions.size());
+#endif
}
else
{
return OC_STACK_KEEP_TRANSACTION;
}
+#ifdef CA_INT
+ OCStackResult InProcClientWrapper::ObserveResource(ObserveType observeType, OCDoHandle* handle,
+ const std::string& host, const std::string& uri, uint8_t connectivityType,
+ const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
+ ObserveCallback& callback, QualityOfService QoS)
+#else
OCStackResult InProcClientWrapper::ObserveResource(ObserveType observeType, OCDoHandle* handle,
const std::string& host, const std::string& uri, const QueryParamsMap& queryParams,
const HeaderOptions& headerOptions, ObserveCallback& callback, QualityOfService QoS)
+#endif
{
OCStackResult result;
OCCallbackData cbdata = {0};
OCHeaderOption options[MAX_HEADER_OPTIONS];
assembleHeaderOptions(options, headerOptions);
+#ifdef CA_INT
+ result = OCDoResource(handle, method,
+ os.str().c_str(), nullptr,
+ nullptr, connectivityType,
+ static_cast<OCQualityOfService>(QoS),
+ &cbdata,
+ options, headerOptions.size());
+#else
result = OCDoResource(handle, method,
os.str().c_str(), nullptr,
nullptr,
static_cast<OCQualityOfService>(QoS),
&cbdata,
options, headerOptions.size());
+#endif
}
else
{
return OC_STACK_KEEP_TRANSACTION;
}
+#ifdef CA_INT
+ OCStackResult InProcClientWrapper::SubscribePresence(OCDoHandle* handle,
+ const std::string& host, const std::string& resourceType, uint8_t connectivityType,
+ SubscribeCallback& presenceHandler)
+#else
OCStackResult InProcClientWrapper::SubscribePresence(OCDoHandle* handle,
const std::string& host, const std::string& resourceType,
SubscribeCallback& presenceHandler)
+#endif
{
OCCallbackData cbdata = {0};
return OC_STACK_ERROR;
}
+#ifdef CA_INT
+ return OCDoResource(handle, OC_REST_PRESENCE, os.str().c_str(), nullptr, nullptr,
+ connectivityType, OC_LOW_QOS, &cbdata, NULL, 0);
+#else
return OCDoResource(handle, OC_REST_PRESENCE, os.str().c_str(), nullptr, nullptr,
OC_LOW_QOS, &cbdata, NULL, 0);
+#endif
}
OCStackResult InProcClientWrapper::UnsubscribePresence(OCDoHandle handle)
observationIds, pResponse, QoS);
}
+#ifdef CA_INT
+ OCResource::Ptr constructResourceObject(const std::string& host,
+ const std::string& uri, uint8_t connectivityType,
+ bool isObservable,
+ const std::vector<std::string>& resourceTypes,
+ const std::vector<std::string>& interfaces)
+ {
+ return OCPlatform_impl::Instance().constructResourceObject(host, uri, connectivityType,
+ isObservable,
+ resourceTypes, interfaces);
+ }
+
+ OCStackResult findResource(const std::string& host,
+ const std::string& resourceName,
+ uint8_t connectivityType,
+ FindCallback resourceHandler)
+ {
+ return OCPlatform_impl::Instance().findResource(host, resourceName,
+ connectivityType, resourceHandler);
+ }
+
+ OCStackResult findResource(const std::string& host,
+ const std::string& resourceName,
+ uint8_t connectivityType,
+ FindCallback resourceHandler, QualityOfService QoS)
+ {
+ return OCPlatform_impl::Instance().findResource(host, resourceName, connectivityType,
+ resourceHandler, QoS);
+ }
+
+ OCStackResult getDeviceInfo(const std::string& host,
+ const std::string& deviceURI,
+ uint8_t connectivityType,
+ FindDeviceCallback deviceInfoHandler)
+ {
+ return OCPlatform_impl::Instance().getDeviceInfo(host, deviceURI,
+ connectivityType, deviceInfoHandler);
+ }
+
+ OCStackResult getDeviceInfo(const std::string& host,
+ const std::string& deviceURI,
+ uint8_t connectivityType,
+ FindDeviceCallback deviceInfoHandler,
+ QualityOfService QoS)
+ {
+ return OCPlatform_impl::Instance().getDeviceInfo(host, deviceURI, connectivityType,
+ deviceInfoHandler, QoS);
+ }
+#else
OCResource::Ptr constructResourceObject(const std::string& host,
const std::string& uri,
bool isObservable,
return OCPlatform_impl::Instance().getDeviceInfo(host, deviceURI,
deviceInfoHandler, QoS);
}
-
+#endif
OCStackResult registerResource(OCResourceHandle& resourceHandle,
std::string& resourceURI,
return OCPlatform_impl::Instance().stopPresence();
}
+#ifdef CA_INT
+ OCStackResult subscribePresence(OCPresenceHandle& presenceHandle,
+ const std::string& host,
+ uint8_t connectivityType,
+ SubscribeCallback presenceHandler)
+ {
+ return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
+ connectivityType, presenceHandler);
+ }
+
+ OCStackResult subscribePresence(OCPresenceHandle& presenceHandle,
+ const std::string& host,
+ const std::string& resourceType,
+ uint8_t connectivityType,
+ SubscribeCallback presenceHandler)
+ {
+ return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
+ resourceType, connectivityType, presenceHandler);
+ }
+#else
OCStackResult subscribePresence(OCPresenceHandle& presenceHandle,
const std::string& host,
SubscribeCallback presenceHandler)
return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
resourceType, presenceHandler);
}
-
+#endif
OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle)
{
return OCPlatform_impl::Instance().unsubscribePresence(presenceHandle);
static_cast<OCQualityOfService>(QoS)));
}
+#ifdef CA_INT
+ OCResource::Ptr OCPlatform_impl::constructResourceObject(const std::string& host,
+ const std::string& uri, uint8_t connectivityType,
+ bool isObservable,
+ const std::vector<std::string>& resourceTypes,
+ const std::vector<std::string>& interfaces)
+ {
+ if(!m_client)
+ {
+ return std::shared_ptr<OCResource>();
+ }
+
+ return std::shared_ptr<OCResource>(new OCResource(m_client,
+ host,
+ uri, connectivityType,
+ isObservable,
+ resourceTypes,
+ interfaces));
+ }
+
+ OCStackResult OCPlatform_impl::findResource(const std::string& host,
+ const std::string& resourceName,
+ uint8_t connectivityType,
+ FindCallback resourceHandler)
+ {
+ return findResource(host, resourceName, connectivityType, resourceHandler, m_cfg.QoS);
+ }
+
+ OCStackResult OCPlatform_impl::findResource(const std::string& host,
+ const std::string& resourceName,
+ uint8_t connectivityType,
+ FindCallback resourceHandler, QualityOfService QoS)
+ {
+
+ return checked_guard(m_client, &IClientWrapper::ListenForResource,
+ host, resourceName, connectivityType, resourceHandler, QoS);
+ }
+
+ OCStackResult OCPlatform_impl::getDeviceInfo(const std::string& host,
+ const std::string& deviceURI,
+ uint8_t connectivityType,
+ FindDeviceCallback deviceInfoHandler)
+ {
+ return result_guard(getDeviceInfo(host, deviceURI, connectivityType,
+ deviceInfoHandler, m_cfg.QoS));
+ }
+
+ OCStackResult OCPlatform_impl::getDeviceInfo(const std::string& host,
+ const std::string& deviceURI,
+ uint8_t connectivityType,
+ FindDeviceCallback deviceInfoHandler,
+ QualityOfService QoS)
+ {
+ return checked_guard(m_client, &IClientWrapper::ListenForDevice,
+ host, deviceURI, connectivityType, deviceInfoHandler, QoS);
+ }
+
+#else
OCResource::Ptr OCPlatform_impl::constructResourceObject(const std::string& host,
const std::string& uri,
bool isObservable,
const std::string& resourceName,
FindCallback resourceHandler, QualityOfService QoS)
{
+
return checked_guard(m_client, &IClientWrapper::ListenForResource,
host, resourceName, resourceHandler, QoS);
}
host, deviceURI, deviceInfoHandler, QoS);
}
+#endif
+
OCStackResult OCPlatform_impl::registerResource(OCResourceHandle& resourceHandle,
std::string& resourceURI,
const std::string& resourceTypeName,
return checked_guard(m_server, &IServerWrapper::stopPresence);
}
+#ifdef CA_INT
+ OCStackResult OCPlatform_impl::subscribePresence(OCPresenceHandle& presenceHandle,
+ const std::string& host, uint8_t connectivityType,
+ SubscribeCallback presenceHandler)
+ {
+ return subscribePresence(presenceHandle, host, "", connectivityType, presenceHandler);
+ }
+
+
+ OCStackResult OCPlatform_impl::subscribePresence(OCPresenceHandle& presenceHandle,
+ const std::string& host,
+ const std::string& resourceType,
+ uint8_t connectivityType,
+ SubscribeCallback presenceHandler)
+ {
+ return checked_guard(m_client, &IClientWrapper::SubscribePresence,
+ &presenceHandle, host, resourceType, connectivityType,
+ presenceHandler);
+ }
+#else
OCStackResult OCPlatform_impl::subscribePresence(OCPresenceHandle& presenceHandle,
const std::string& host,
SubscribeCallback presenceHandler)
SubscribeCallback presenceHandler)
{
return checked_guard(m_client, &IClientWrapper::SubscribePresence,
- &presenceHandle, host, resourceType, presenceHandler);
+ &presenceHandle, host, resourceType,
+ presenceHandler);
}
+#endif
OCStackResult OCPlatform_impl::unsubscribePresence(OCPresenceHandle presenceHandle)
{
using OC::result_guard;
using OC::checked_guard;
+#ifdef CA_INT
+OCResource::OCResource(std::weak_ptr<IClientWrapper> clientWrapper, const std::string& host,
+ const std::string& uri, uint8_t connectivityType, bool observable,
+ const std::vector<std::string>& resourceTypes,
+ const std::vector<std::string>& interfaces)
+ : m_clientWrapper(clientWrapper), m_uri(uri), m_connectivityType(connectivityType),
+ m_host(host), m_isObservable(observable),
+ m_isCollection(false), m_resourceTypes(resourceTypes), m_interfaces(interfaces),
+ m_observeHandle(nullptr)
+{
+ m_isCollection = std::find(m_interfaces.begin(), m_interfaces.end(), LINK_INTERFACE)
+ != m_interfaces.end();
+
+ if (m_uri.empty() ||
+ resourceTypes.empty() ||
+ interfaces.empty()||
+ m_clientWrapper.expired())
+ {
+ throw ResourceInitException(m_uri.empty(), resourceTypes.empty(),
+ interfaces.empty(), m_clientWrapper.expired(), false, false);
+ }
+}
+#else
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::vector<std::string>& interfaces)
interfaces.empty(), m_clientWrapper.expired(), false, false);
}
}
+#endif
OCResource::~OCResource()
{
OCStackResult OCResource::get(const QueryParamsMap& queryParametersMap,
GetCallback attributeHandler, QualityOfService QoS)
{
+#ifdef CA_INT
+ return checked_guard(m_clientWrapper.lock(), &IClientWrapper::GetResourceRepresentation,
+ m_host, m_uri, m_connectivityType, queryParametersMap, m_headerOptions,
+ attributeHandler, QoS);
+#else
return checked_guard(m_clientWrapper.lock(), &IClientWrapper::GetResourceRepresentation,
m_host, m_uri, queryParametersMap, m_headerOptions, attributeHandler, QoS);
+#endif
}
OCStackResult OCResource::get(const QueryParamsMap& queryParametersMap,
const QueryParamsMap& queryParametersMap, PutCallback attributeHandler,
QualityOfService QoS)
{
+#ifdef CA_INT
+ return checked_guard(m_clientWrapper.lock(), &IClientWrapper::PutResourceRepresentation,
+ m_host, m_uri, m_connectivityType, rep, queryParametersMap,
+ m_headerOptions, attributeHandler, QoS);
+#else
return checked_guard(m_clientWrapper.lock(), &IClientWrapper::PutResourceRepresentation,
m_host, m_uri, rep, queryParametersMap, m_headerOptions, attributeHandler, QoS);
+#endif
}
OCStackResult OCResource::put(const OCRepresentation& rep,
const QueryParamsMap& queryParametersMap, PostCallback attributeHandler,
QualityOfService QoS)
{
+#ifdef CA_INT
+ return checked_guard(m_clientWrapper.lock(), &IClientWrapper::PostResourceRepresentation,
+ m_host, m_uri, m_connectivityType, rep, queryParametersMap,
+ m_headerOptions, attributeHandler, QoS);
+#else
return checked_guard(m_clientWrapper.lock(), &IClientWrapper::PostResourceRepresentation,
m_host, m_uri, rep, queryParametersMap, m_headerOptions, attributeHandler, QoS);
+#endif
}
OCStackResult OCResource::post(const OCRepresentation& rep,
OCStackResult OCResource::deleteResource(DeleteCallback deleteHandler, QualityOfService QoS)
{
+#ifdef CA_INT
+ return checked_guard(m_clientWrapper.lock(), &IClientWrapper::DeleteResource,
+ m_host, m_uri, m_connectivityType, m_headerOptions, deleteHandler, QoS);
+#else
return checked_guard(m_clientWrapper.lock(), &IClientWrapper::DeleteResource,
m_host, m_uri, m_headerOptions, deleteHandler, QoS);
+#endif
}
OCStackResult OCResource::deleteResource(DeleteCallback deleteHandler)
return result_guard(OC_STACK_INVALID_PARAM);
}
+#ifdef CA_INT
+ return checked_guard(m_clientWrapper.lock(), &IClientWrapper::ObserveResource,
+ observeType, &m_observeHandle, m_host,
+ m_uri, m_connectivityType, queryParametersMap, m_headerOptions,
+ observeHandler, QoS);
+#else
return checked_guard(m_clientWrapper.lock(), &IClientWrapper::ObserveResource,
observeType, &m_observeHandle, m_host,
m_uri, queryParametersMap, m_headerOptions, observeHandler, QoS);
+#endif
}
OCStackResult OCResource::observe(ObserveType observeType,
return m_uri;
}
+#ifdef CA_INT
+uint8_t OCResource::connectivityType() const
+{
+ return m_connectivityType;
+}
+#endif
+
bool OCResource::isObservable() const
{
return m_isObservable;