//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#include "iotivity_config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
+#endif
#include <ocstack.h>
#include <iostream>
#include <sstream>
+#include <getopt.h>
+#include "ocpayload.h"
+#include "payload_logging.h"
#include "logger.h"
-const char *getResult(OCStackResult result);
-std::string getIPAddrTBServer(OCClientResponse * clientResponse);
-std::string getPortTBServer(OCClientResponse * clientResponse);
-std::string getQueryStrForGetPut(unsigned const char * responsePayload);
+#include "common.h"
+#include "oic_string.h"
+
+std::string getQueryStrForGetPut();
-#define TAG PCF("occlient")
+#define TAG ("occlient")
#define DEFAULT_CONTEXT_VALUE 0x99
#ifndef MAX_LENGTH_IPv4_ADDR
#define MAX_LENGTH_IPv4_ADDR 16
#endif
-typedef enum {
+typedef enum
+{
TEST_INVALID = 0,
TEST_GET_DEFAULT,
TEST_GET_BATCH,
TEST_UNKNOWN_RESOURCE_GET_DEFAULT,
TEST_UNKNOWN_RESOURCE_GET_BATCH,
TEST_UNKNOWN_RESOURCE_GET_LINK_LIST,
+ TEST_GET_EMPTY,
+ TEST_GET_NULL,
MAX_TESTS
} CLIENT_TEST;
-unsigned static int TEST = TEST_INVALID;
+/**
+ * List of connectivity types that can be initiated from the client
+ * Required for user input validation
+ */
+typedef enum {
+ CT_ADAPTER_DEFAULT = 0,
+ CT_IP,
+ MAX_CT
+} CLIENT_ConnectivityType_TYPE;
+
+unsigned static int TestType = TEST_INVALID;
+unsigned static int ConnectivityType = 0;
typedef struct
{
- unsigned char text[30];
+ char text[30];
CLIENT_TEST test;
} testToTextMap;
testToTextMap queryInterface[] = {
{"invalid", TEST_INVALID},
- {"?if=oc.mi.def", TEST_GET_DEFAULT},
- {"?if=oc.mi.b", TEST_GET_BATCH},
- {"?if=oc.mi.ll", TEST_GET_LINK_LIST},
- {"?if=oc.mi.def", TEST_UNKNOWN_RESOURCE_GET_DEFAULT},
- {"?if=oc.mi.b", TEST_UNKNOWN_RESOURCE_GET_BATCH},
- {"?if=oc.mi.ll", TEST_UNKNOWN_RESOURCE_GET_LINK_LIST},
- {"?if=oc.mi.def", TEST_PUT_DEFAULT},
- {"?if=oc.mi.b", TEST_PUT_BATCH},
- {"?if=oc.mi.ll", TEST_PUT_LINK_LIST},
+ {"?if=oic.if.baseline", TEST_GET_DEFAULT},
+ {"?if=oic.if.b", TEST_GET_BATCH},
+ {"?if=oic.if.ll", TEST_GET_LINK_LIST},
+ {"?if=oic.if.baseline", TEST_UNKNOWN_RESOURCE_GET_DEFAULT},
+ {"?if=oic.if.b", TEST_UNKNOWN_RESOURCE_GET_BATCH},
+ {"?if=oic.if.ll", TEST_UNKNOWN_RESOURCE_GET_LINK_LIST},
+ {"?if=oic.if.baseline", TEST_PUT_DEFAULT},
+ {"?if=oic.if.b", TEST_PUT_BATCH},
+ {"?if=oic.if.ll", TEST_PUT_LINK_LIST},
+ {"", TEST_GET_EMPTY},
+ {NULL, TEST_GET_NULL}
};
-static std::string putPayload = "{\"state\":\"off\",\"power\":\"0\"}";
-#ifdef CA_INT
-//The following variable determines the interface (wifi, ethernet etc.)
-//to be used for sending unicast messages. Default set to WIFI.
-static OCConnectivityType CA_CONNTYPE = OC_WIFI;
-static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oc/core";
-#endif
+//The following variable determines the interface protocol (IP, etc)
+//to be used for sending unicast messages. Default set to IP.
+static OCConnectivityType ConnType = CT_ADAPTER_IP;
+static const char * RESOURCE_DISCOVERY_QUERY = "/oic/res";
// The handle for the observe registration
OCDoHandle gObserveDoHandle;
int gQuitFlag = 0;
/* SIGINT handler: set gQuitFlag to 1 for graceful termination */
-void handleSigInt(int signum) {
- if (signum == SIGINT) {
+void handleSigInt(int signum)
+{
+ if (signum == SIGINT)
+ {
gQuitFlag = 1;
}
}
int InitGetRequest(OCClientResponse * clientResponse);
int InitDiscovery();
+OCPayload* putPayload()
+{
+ OCRepPayload* payload = OCRepPayloadCreate();
+
+ if(!payload)
+ {
+ std::cout << "Failed to create put payload object"<<std::endl;
+ std::exit(1);
+ }
+
+ OCRepPayloadSetPropInt(payload, "power", 15);
+ OCRepPayloadSetPropBool(payload, "state", true);
+
+ return (OCPayload*) payload;
+}
+
void PrintUsage()
{
-#ifdef CA_INT
- OC_LOG(INFO, TAG, "Usage : occlientcoll -t <Test Case> -c <CA connectivity Type>");
- OC_LOG(INFO, TAG, "-c <0|1|2|3> : Send messages over Ethernet, WIFI, EDR or LE");
-#else
- OC_LOG(INFO, TAG, "Usage : occlientcoll -t <Test Case>");
-#endif
- OC_LOG(INFO, TAG, "Test Case 1 : Discover Resources && Initiate GET Request on an"\
+ OIC_LOG(INFO, TAG, "Usage : occlientcoll -t <Test Case> -c <CA connectivity Type>");
+ OIC_LOG(INFO, TAG, "-c 0 : Default auto-selection");
+ OIC_LOG(INFO, TAG, "-c 1 : IP Connectivity Type");
+ OIC_LOG(INFO, TAG, "Test Case 1 : Discover Resources && Initiate GET Request on an "\
"available resource using default interface.");
- OC_LOG(INFO, TAG, "Test Case 2 : Discover Resources && Initiate GET Request on an"\
+ OIC_LOG(INFO, TAG, "Test Case 2 : Discover Resources && Initiate GET Request on an "\
"available resource using batch interface.");
- OC_LOG(INFO, TAG, "Test Case 3 : Discover Resources && Initiate GET Request on an"\
+ OIC_LOG(INFO, TAG, "Test Case 3 : Discover Resources && Initiate GET Request on an "\
"available resource using link list interface.");
- OC_LOG(INFO, TAG, "Test Case 4 : Discover Resources && Initiate GET & PUT Request on an"\
+ OIC_LOG(INFO, TAG, "Test Case 4 : Discover Resources && Initiate GET & PUT Request on an "\
"available resource using default interface.");
- OC_LOG(INFO, TAG, "Test Case 5 : Discover Resources && Initiate GET & PUT Request on an"\
+ OIC_LOG(INFO, TAG, "Test Case 5 : Discover Resources && Initiate GET & PUT Request on an "\
"available resource using batch interface.");
- OC_LOG(INFO, TAG, "Test Case 6 : Discover Resources && Initiate GET & PUT Request on an"\
+ OIC_LOG(INFO, TAG, "Test Case 6 : Discover Resources && Initiate GET & PUT Request on an "\
"available resource using link list interface.");
- OC_LOG(INFO, TAG, "Test Case 7 : Discover Resources && Initiate GET Request on an"\
+ OIC_LOG(INFO, TAG, "Test Case 7 : Discover Resources && Initiate GET Request on an "\
"unavailable resource using default interface.");
- OC_LOG(INFO, TAG, "Test Case 8 : Discover Resources && Initiate GET Request on an"\
+ OIC_LOG(INFO, TAG, "Test Case 8 : Discover Resources && Initiate GET Request on an "\
"unavailable resource using batch interface.");
- OC_LOG(INFO, TAG, "Test Case 9 : Discover Resources && Initiate GET Request on an"\
+ OIC_LOG(INFO, TAG, "Test Case 9 : Discover Resources && Initiate GET Request on an "\
"unavailable resource using link list interface.");
+ OIC_LOG(INFO, TAG, "Test Case 10 : Discover Resources && Initiate GET Request on an "\
+ "empty resource.");
+ OIC_LOG(INFO, TAG, "Test Case 11 : Discover Resources && Initiate GET Request on an "\
+ "NULL resource.");
+
}
-OCStackApplicationResult putReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse) {
+OCStackApplicationResult putReqCB(void* ctx, OCDoHandle /*handle*/,
+ OCClientResponse * clientResponse)
+{
if(clientResponse == NULL)
{
- OC_LOG(INFO, TAG, "The clientResponse is NULL");
+ OIC_LOG(INFO, TAG, "The clientResponse is NULL");
return OC_STACK_DELETE_TRANSACTION;
}
- if(ctx == (void*)DEFAULT_CONTEXT_VALUE) {
- OC_LOG_V(INFO, TAG, "Callback Context for PUT query recvd successfully");
- OC_LOG_V(INFO, TAG, "JSON = %s =============> Discovered", clientResponse->resJSONPayload);
+ if(ctx == (void*)DEFAULT_CONTEXT_VALUE)
+ {
+ OIC_LOG_V(INFO, TAG, "Callback Context for PUT query recvd successfully");
+ OIC_LOG_PAYLOAD(INFO, clientResponse->payload);
}
return OC_STACK_KEEP_TRANSACTION;
}
-OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse) {
- OC_LOG_V(INFO, TAG, "StackResult: %s",
+OCStackApplicationResult getReqCB(void* ctx, OCDoHandle /*handle*/,
+ OCClientResponse * clientResponse)
+{
+ OIC_LOG_V(INFO, TAG, "StackResult: %s",
getResult(clientResponse->result));
- if(ctx == (void*)DEFAULT_CONTEXT_VALUE) {
- OC_LOG_V(INFO, TAG, "SEQUENCE NUMBER: %d", clientResponse->sequenceNumber);
- if(clientResponse->sequenceNumber == 0) {
- OC_LOG_V(INFO, TAG, "Callback Context for GET query recvd successfully");
- OC_LOG_V(INFO, TAG, "Fnd' Rsrc': %s", clientResponse->resJSONPayload);
+ if(ctx == (void*)DEFAULT_CONTEXT_VALUE)
+ {
+ OIC_LOG_V(INFO, TAG, "SEQUENCE NUMBER: %d", clientResponse->sequenceNumber);
+ if(clientResponse->sequenceNumber == 0)
+ {
+ OIC_LOG_V(INFO, TAG, "Callback Context for GET query recvd successfully");
+ OIC_LOG_PAYLOAD(INFO, clientResponse->payload);
}
- else {
- OC_LOG_V(INFO, TAG, "Callback Context for Get recvd successfully %d", gNumObserveNotifies);
- OC_LOG_V(INFO, TAG, "Fnd' Rsrc': %s", clientResponse->resJSONPayload);
+ else
+ {
+ OIC_LOG_V(INFO, TAG, "Callback Context for Get recvd successfully %d",
+ gNumObserveNotifies);
+ OIC_LOG_PAYLOAD(INFO, clientResponse->payload);;
gNumObserveNotifies++;
if (gNumObserveNotifies == 3)
{
- if (OCCancel (gObserveDoHandle, OC_LOW_QOS, NULL, 0) != OC_STACK_OK){
- OC_LOG(ERROR, TAG, "Observe cancel error");
+ if (OCCancel (gObserveDoHandle, OC_LOW_QOS, NULL, 0) != OC_STACK_OK)
+ {
+ OIC_LOG(ERROR, TAG, "Observe cancel error");
}
}
}
}
- if(TEST == TEST_PUT_DEFAULT || TEST == TEST_PUT_BATCH || TEST == TEST_PUT_LINK_LIST)
+ if(TestType == TEST_PUT_DEFAULT || TestType == TEST_PUT_BATCH || TestType == TEST_PUT_LINK_LIST)
{
InitPutRequest(clientResponse);
}
return OC_STACK_KEEP_TRANSACTION;
}
-
// This is a function called back when a device is discovered
-OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
- OCClientResponse * clientResponse) {
- uint8_t remoteIpAddr[4];
- uint16_t remotePortNu;
-
- OC_LOG(INFO, TAG,
+OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle /*handle*/,
+ OCClientResponse * clientResponse)
+{
+ OIC_LOG(INFO, TAG,
"Entering discoveryReqCB (Application Layer CB)");
- OC_LOG_V(INFO, TAG, "StackResult: %s",
+ OIC_LOG_V(INFO, TAG, "StackResult: %s",
getResult(clientResponse->result));
- if (ctx == (void*) DEFAULT_CONTEXT_VALUE) {
- OC_LOG_V(INFO, TAG, "Callback Context recvd successfully");
+ if (ctx == (void*) DEFAULT_CONTEXT_VALUE)
+ {
+ OIC_LOG_V(INFO, TAG, "Callback Context recvd successfully");
}
- OCDevAddrToIPv4Addr((OCDevAddr *) clientResponse->addr, remoteIpAddr,
- remoteIpAddr + 1, remoteIpAddr + 2, remoteIpAddr + 3);
- OCDevAddrToPort((OCDevAddr *) clientResponse->addr, &remotePortNu);
+ OIC_LOG_V(INFO, TAG,
+ "Device =============> Discovered @ %s:%d",
+ clientResponse->devAddr.addr,
+ clientResponse->devAddr.port);
+ OIC_LOG_PAYLOAD(INFO, clientResponse->payload);
- OC_LOG_V(INFO, TAG,
- "Device =============> Discovered %s @ %d.%d.%d.%d:%d",
- clientResponse->resJSONPayload, remoteIpAddr[0], remoteIpAddr[1],
- remoteIpAddr[2], remoteIpAddr[3], remotePortNu);
+ ConnType = clientResponse->connType;
- if(TEST == TEST_UNKNOWN_RESOURCE_GET_DEFAULT || TEST == TEST_UNKNOWN_RESOURCE_GET_BATCH ||\
- TEST == TEST_UNKNOWN_RESOURCE_GET_LINK_LIST)
+ if(TestType == TEST_UNKNOWN_RESOURCE_GET_DEFAULT || TestType == TEST_UNKNOWN_RESOURCE_GET_BATCH ||\
+ TestType == TEST_UNKNOWN_RESOURCE_GET_LINK_LIST)
{
InitGetRequestToUnavailableResource(clientResponse);
}
{
OCStackResult ret;
OCCallbackData cbData;
- OCDoHandle handle;
std::ostringstream getQuery;
- getQuery << "coap://" << getIPAddrTBServer(clientResponse) << ":" << getPortTBServer(clientResponse) << "/SomeUnknownResource";
+ getQuery << "/SomeUnknownResource";
cbData.cb = getReqCB;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
-#ifdef CA_INT
- ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, CA_CONNTYPE, OC_LOW_QOS,
- &cbData, NULL, 0);
-#else
- ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, OC_LOW_QOS,
- &cbData, NULL, 0);
-#endif
+ ret = OCDoRequest(NULL, OC_REST_GET, getQuery.str().c_str(),
+ &clientResponse->devAddr, 0, ConnType, OC_LOW_QOS,
+ &cbData, NULL, 0);
if (ret != OC_STACK_OK)
{
- OC_LOG(ERROR, TAG, "OCStack resource error");
+ OIC_LOG(ERROR, TAG, "OCStack resource error");
}
return ret;
}
OCCallbackData cbData;
OCDoHandle handle;
std::ostringstream obsReg;
- obsReg << "coap://" << getIPAddrTBServer(clientResponse) << ":" << getPortTBServer(clientResponse) << getQueryStrForGetPut(clientResponse->resJSONPayload);
+ obsReg << getQueryStrForGetPut();
cbData.cb = getReqCB;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
- OC_LOG_V(INFO, TAG, "OBSERVE payload from client = %s ", putPayload.c_str());
-
-#ifdef CA_INT
- ret = OCDoResource(&handle, OC_REST_OBSERVE, obsReg.str().c_str(), 0, 0, CA_CONNTYPE,
- OC_LOW_QOS, &cbData, NULL, 0);
-#else
- ret = OCDoResource(&handle, OC_REST_OBSERVE, obsReg.str().c_str(), 0, 0, OC_LOW_QOS,
- &cbData, NULL, 0);
-#endif
+ OIC_LOG_V(INFO, TAG, "OBSERVE payload from client =");
+ OCPayload* payload = putPayload();
+ OIC_LOG_PAYLOAD(INFO, payload);
+ OCPayloadDestroy(payload);
+
+ ret = OCDoRequest(&handle, OC_REST_OBSERVE, obsReg.str().c_str(),
+ &clientResponse->devAddr, 0, ConnType,
+ OC_LOW_QOS, &cbData, NULL, 0);
if (ret != OC_STACK_OK)
{
- OC_LOG(ERROR, TAG, "OCStack resource error");
+ OIC_LOG(ERROR, TAG, "OCStack resource error");
}
else
{
{
OCStackResult ret;
OCCallbackData cbData;
- OCDoHandle handle;
//* Make a PUT query*/
std::ostringstream getQuery;
- getQuery << "coap://" << getIPAddrTBServer(clientResponse) << ":" << getPortTBServer(clientResponse) <<
- "/a/room" << queryInterface[TEST].text;
+ getQuery << "coap://" << clientResponse->devAddr.addr << ":" <<
+ clientResponse->devAddr.port <<
+ "/a/room" << queryInterface[TestType].text;
cbData.cb = putReqCB;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
- OC_LOG_V(INFO, TAG, "PUT payload from client = %s ", putPayload.c_str());
-
-#ifdef CA_INT
- ret = OCDoResource(&handle, OC_REST_PUT, getQuery.str().c_str(), 0, putPayload.c_str(),
- CA_CONNTYPE, OC_LOW_QOS, &cbData, NULL, 0);
-#else
- ret = OCDoResource(&handle, OC_REST_PUT, getQuery.str().c_str(), 0, putPayload.c_str(),
- OC_LOW_QOS, &cbData, NULL, 0);
-#endif
+ OIC_LOG_V(INFO, TAG, "PUT payload from client = ");
+ OCPayload* payload = putPayload();
+ OIC_LOG_PAYLOAD(INFO, payload);
+
+ ret = OCDoRequest(NULL, OC_REST_PUT, getQuery.str().c_str(),
+ &clientResponse->devAddr, payload, ConnType,
+ OC_LOW_QOS, &cbData, NULL, 0);
+
+ OCPayloadDestroy(payload);
+
if (ret != OC_STACK_OK)
{
- OC_LOG(ERROR, TAG, "OCStack resource error");
+ OIC_LOG(ERROR, TAG, "OCStack resource error");
}
return ret;
}
{
OCStackResult ret;
OCCallbackData cbData;
- OCDoHandle handle;
-
- uint8_t remoteIpAddr[4];
- uint16_t remotePortNu;
-
- OCDevAddrToIPv4Addr((OCDevAddr *) clientResponse->addr, remoteIpAddr,
- remoteIpAddr + 1, remoteIpAddr + 2, remoteIpAddr + 3);
- OCDevAddrToPort((OCDevAddr *) clientResponse->addr, &remotePortNu);
//* Make a GET query*/
std::ostringstream getQuery;
- getQuery << "coap://" << getIPAddrTBServer(clientResponse) << ":" << getPortTBServer(clientResponse) <<
- "/a/room" << queryInterface[TEST].text;
+ getQuery << "/a/room" << queryInterface[TestType].text;
std::cout << "Get Query: " << getQuery.str() << std::endl;
cbData.cb = getReqCB;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
-#ifdef CA_INT
- ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, CA_CONNTYPE, OC_LOW_QOS,
- &cbData, NULL, 0);
-#else
- ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, OC_LOW_QOS,
- &cbData, NULL, 0);
-#endif
+ ret = OCDoRequest(NULL, OC_REST_GET, getQuery.str().c_str(),
+ &clientResponse->devAddr, 0, ConnType, OC_LOW_QOS,
+ &cbData, NULL, 0);
if (ret != OC_STACK_OK)
{
- OC_LOG(ERROR, TAG, "OCStack resource error");
+ OIC_LOG(ERROR, TAG, "OCStack resource error");
}
return ret;
}
{
OCStackResult ret;
OCCallbackData cbData;
- OCDoHandle handle;
/* Start a discovery query*/
- char szQueryUri[64] = { 0 };
+ char szQueryUri[MAX_QUERY_LENGTH] = { 0 };
-#ifdef CA_INT
- strcpy(szQueryUri, MULTICAST_RESOURCE_DISCOVERY_QUERY);
-#else
- strcpy(szQueryUri, OC_WELL_KNOWN_QUERY);
-#endif
+ OICStrcpy(szQueryUri, sizeof(szQueryUri), RESOURCE_DISCOVERY_QUERY);
cbData.cb = discoveryReqCB;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
-#ifdef CA_INT
- ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_ALL,
- OC_LOW_QOS,
- &cbData, NULL, 0);
-#else
- ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_LOW_QOS,
- &cbData, NULL, 0);
-#endif
+ ret = OCDoRequest(NULL, OC_REST_DISCOVER, szQueryUri, NULL, 0, ConnType,
+ OC_LOW_QOS,
+ &cbData, NULL, 0);
if (ret != OC_STACK_OK)
{
- OC_LOG(ERROR, TAG, "OCStack resource error");
+ OIC_LOG(ERROR, TAG, "OCStack resource error");
}
return ret;
}
-int main(int argc, char* argv[]) {
- uint8_t addr[20] = {0};
- uint8_t* paddr = NULL;
- uint16_t port = USE_RANDOM_PORT;
- uint8_t ifname[] = "eth0";
+int main(int argc, char* argv[])
+{
int opt;
-#ifdef CA_INT
while ((opt = getopt(argc, argv, "t:c:")) != -1)
-#else
- while ((opt = getopt(argc, argv, "t:")) != -1)
-#endif
{
- switch(opt)
+ switch (opt)
{
- case 't':
- TEST = atoi(optarg);
- break;
- #ifdef CA_INT
- case 'c':
- CA_CONNTYPE = OCConnectivityType(atoi(optarg));
- break;
- #endif
- default:
- PrintUsage();
- return -1;
+ case 't':
+ TestType = atoi(optarg);
+ break;
+ case 'c':
+ ConnectivityType = atoi(optarg);
+ break;
+ default:
+ PrintUsage();
+ return -1;
}
}
- if(TEST <= TEST_INVALID || TEST >= MAX_TESTS){
+ if ((TestType <= TEST_INVALID || TestType >= MAX_TESTS) ||
+ ConnectivityType >= MAX_CT)
+ {
PrintUsage();
return -1;
}
- /*Get Ip address on defined interface and initialize coap on it with random port number
- * this port number will be used as a source port in all coap communications*/
- if ( OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr,
- sizeof(addr)) == ERR_SUCCESS)
+ /* Initialize OCStack*/
+ if (OCInit(NULL, 0, OC_CLIENT) != OC_STACK_OK)
{
- OC_LOG_V(INFO, TAG, "Starting occlient on address %s",addr);
- paddr = addr;
+ OIC_LOG(ERROR, TAG, "OCStack init error");
+ return 0;
}
- /* Initialize OCStack*/
- if (OCInit((char *) paddr, port, OC_CLIENT) != OC_STACK_OK) {
- OC_LOG(ERROR, TAG, "OCStack init error");
- return 0;
+ if(ConnectivityType == CT_ADAPTER_DEFAULT || ConnectivityType == CT_IP)
+ {
+ ConnType = CT_ADAPTER_IP;
+ }
+ else
+ {
+ OIC_LOG(INFO, TAG, "Default Connectivity type selected...");
+ ConnType = CT_ADAPTER_IP;
}
InitDiscovery();
// Break from loop with Ctrl+C
- OC_LOG(INFO, TAG, "Entering occlient main loop...");
+ OIC_LOG(INFO, TAG, "Entering occlient main loop...");
signal(SIGINT, handleSigInt);
- while (!gQuitFlag) {
+ while (!gQuitFlag)
+ {
- if (OCProcess() != OC_STACK_OK) {
- OC_LOG(ERROR, TAG, "OCStack process error");
+ if (OCProcess() != OC_STACK_OK)
+ {
+ OIC_LOG(ERROR, TAG, "OCStack process error");
return 0;
}
sleep(2);
- }
- OC_LOG(INFO, TAG, "Exiting occlient main loop...");
+ } OIC_LOG(INFO, TAG, "Exiting occlient main loop...");
- if (OCStop() != OC_STACK_OK) {
- OC_LOG(ERROR, TAG, "OCStack stop error");
+ if (OCStop() != OC_STACK_OK)
+ {
+ OIC_LOG(ERROR, TAG, "OCStack stop error");
}
return 0;
}
-std::string getIPAddrTBServer(OCClientResponse * clientResponse) {
- if(!clientResponse) return "";
- if(!clientResponse->addr) return "";
- uint8_t a, b, c, d = 0;
- if(0 != OCDevAddrToIPv4Addr(clientResponse->addr, &a, &b, &c, &d) ) return "";
-
- char ipaddr[16] = {'\0'};
- snprintf(ipaddr, sizeof(ipaddr), "%d.%d.%d.%d", a,b,c,d); // ostringstream not working correctly here, hence snprintf
- //printf("IP address string of the TB server = %s\n", *out_ipaddr);
- return std::string (ipaddr);
-}
-
-
-std::string getPortTBServer(OCClientResponse * clientResponse){
- if(!clientResponse) return "";
- if(!clientResponse->addr) return "";
- uint16_t p = 0;
- if(0 != OCDevAddrToPort(clientResponse->addr, &p) ) return "";
- std::ostringstream ss;
- ss << p;
- return ss.str();
-}
-
-std::string getQueryStrForGetPut(unsigned const char * responsePayload){
-
- std::string jsonPayload(reinterpret_cast<char*>(const_cast<unsigned char*>(responsePayload)));
-
+std::string getQueryStrForGetPut()
+{
return "/a/room";
}