From: Erich Keane Date: Mon, 11 Aug 2014 16:09:08 +0000 (-0700) Subject: 1) Minor change in ocsocket and libcoap to identify if a packet was received on unica... X-Git-Tag: 1.2.0+RC1~2336 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2e6f92a275453bc5cda04b18e99b73bab198e004;p=platform%2Fupstream%2Fiotivity.git 1) Minor change in ocsocket and libcoap to identify if a packet was received on unicast or multicast address/socket Patch 2 : Fixed identified review comments. Modified ocserver to listen on '5683' so that occlient can send unicast discovery requests to it. Patch 3 : 'Really' taking care of tabs this time. Change-Id: I50c0d47133a469d20ba17e26f2df540e97d099bc --- diff --git a/csdk/libcoap-4.1.1/net.c b/csdk/libcoap-4.1.1/net.c index ab70fd6..c8307f9 100644 --- a/csdk/libcoap-4.1.1/net.c +++ b/csdk/libcoap-4.1.1/net.c @@ -3,7 +3,7 @@ * Copyright (C) 2010--2014 Olaf Bergmann * * This file is part of the CoAP library libcoap. Please see - * README for terms of use. + * README for terms of use. */ #include "config.h" @@ -18,7 +18,7 @@ #elif HAVE_SYS_UNISTD_H #include #endif -#ifdef HAVE_SYS_TYPES_H +#ifdef HAVE_SYS_TYPES_H #include #endif #ifdef HAVE_SYS_SOCKET_H @@ -279,7 +279,7 @@ coap_pop_next(coap_context_t *context) { #ifdef COAP_DEFAULT_WKC_HASHKEY /** Checks if @p Key is equal to the pre-defined hash key for.well-known/core. */ -#define is_wkc(Key) \ +#define is_wkc(Key) \ (memcmp((Key), COAP_DEFAULT_WKC_HASHKEY, sizeof(coap_key_t)) == 0) #else /* Implements a singleton to store a hash key for the .wellknown/core @@ -554,7 +554,7 @@ void coap_transaction_id(const coap_address_t *peer, const coap_pdu_t *pdu, #if defined(WITH_LWIP) || defined(WITH_CONTIKI) /* FIXME: with lwip, we can do better */ coap_hash((const unsigned char *)&peer->port, sizeof(peer->port), h); - coap_hash((const unsigned char *)&peer->addr, sizeof(peer->addr), h); + coap_hash((const unsigned char *)&peer->addr, sizeof(peer->addr), h); #endif /* WITH_LWIP || WITH_CONTIKI */ coap_hash((const unsigned char * )&pdu->hdr->id, sizeof(unsigned short), h); @@ -835,7 +835,7 @@ coap_tid_t coap_retransmit(coap_context_t *context, coap_queue_t *node) { return COAP_INVALID_TID; } -/** +/** * Checks if @p opt fits into the message that ends with @p maxpos. * This function returns @c 1 on success, or @c 0 if the option @p opt * would exceed @p maxpos. @@ -878,11 +878,10 @@ int coap_read(coap_context_t *ctx, int sockfd) { coap_address_init(&src); #if defined(WITH_POSIX) || defined(WITH_ARDUINO) - //bytes_read = recvfrom(ctx->sockfd, buf, sizeof(buf), 0, - // &src.addr.sa, &src.size); bytes_read = OCRecvFrom( sockfd, (uint8_t*)buf, sizeof(buf), 0, - (OCDevAddr*)&src); + (OCDevAddr*)&src); + #endif /* WITH_POSIX || WITH_ARDUINO */ #ifdef WITH_CONTIKI if(uip_newdata()) { @@ -960,19 +959,19 @@ int coap_read(coap_context_t *ctx, int sockfd) { } #endif - return 0; + return bytes_read; error: /* FIXME: send back RST? */ coap_delete_node(node); - return -1; + return bytes_read; error_early: #ifdef WITH_LWIP /* even if there was an error, clean up */ pbuf_free(ctx->pending_package); ctx->pending_package = NULL; #endif - return -1; + return bytes_read; } int coap_remove_from_queue(coap_queue_t **queue, coap_tid_t id, @@ -1304,7 +1303,7 @@ wellknown_response(coap_context_t *context, coap_pdu_t *request) { return resp; } -#define WANT_WKC(Pdu,Key) \ +#define WANT_WKC(Pdu,Key) \ (((Pdu)->hdr->code == COAP_REQUEST_GET) && is_wkc(Key)) /************************************************************************************************ diff --git a/csdk/occoap/src/occoap.c b/csdk/occoap/src/occoap.c index fb84765..82742fe 100644 --- a/csdk/occoap/src/occoap.c +++ b/csdk/occoap/src/occoap.c @@ -534,10 +534,18 @@ int OCStopCoAP() { */ int OCProcessCoAP() { OC_LOG(INFO, TAG, PCF("Entering OCProcessCoAP")); - - coap_read(gCoAPCtx, gCoAPCtx->sockfd); + int read = 0; + read = coap_read(gCoAPCtx, gCoAPCtx->sockfd); + if(read > 0) + { + OC_LOG(INFO, TAG, "This is a Unicast<============"); + } if (-1 != gCoAPCtx->sockfd_wellknown) { - coap_read(gCoAPCtx, gCoAPCtx->sockfd_wellknown); + read = coap_read(gCoAPCtx, gCoAPCtx->sockfd_wellknown); + if(read > 0) + { + OC_LOG(INFO, TAG, "This is a Multicast<==========="); + } } coap_dispatch(gCoAPCtx); return 0; diff --git a/csdk/ocsocket/src/ocsocket.c b/csdk/ocsocket/src/ocsocket.c index ac1b96e..14203cb 100644 --- a/csdk/ocsocket/src/ocsocket.c +++ b/csdk/ocsocket/src/ocsocket.c @@ -249,7 +249,7 @@ int32_t OCInitUDPMulticast(OCDevAddr* ipmcastaddr, int32_t* sockfd) sin = (struct sockaddr_in *)(ipmcastaddr->addr); memset(&sa, 0, sizeof(sa)); sa.sin_family = AF_INET; - sa.sin_addr.s_addr = INADDR_ANY; + sa.sin_addr.s_addr = sin->sin_addr.s_addr; sa.sin_port = sin->sin_port; if ((ret = bind(sfd, (struct sockaddr*)&sa, sizeof(sa))) < 0) { diff --git a/csdk/stack/samples/SimpleClientServer/occlient.cpp b/csdk/stack/samples/SimpleClientServer/occlient.cpp index 6b29355..6990df7 100644 --- a/csdk/stack/samples/SimpleClientServer/occlient.cpp +++ b/csdk/stack/samples/SimpleClientServer/occlient.cpp @@ -42,6 +42,7 @@ std::string getQueryStrForGetPut(unsigned const char * responsePayload); 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\":\"0\"}"; // The handle for the observe registration @@ -52,9 +53,9 @@ int gNumNotifies = 1; int gQuitFlag = 0; /* SIGINT handler: set gQuitFlag to 1 for graceful termination */ void handleSigInt(int signum) { - if (signum == SIGINT) { - gQuitFlag = 1; - } + if (signum == SIGINT) { + gQuitFlag = 1; + } } // Forward Declaration @@ -76,13 +77,13 @@ void PrintUsage() } OCStackApplicationResult putReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse) { - if(clientResponse) {} - if(ctx == (void*)CTX_VAL) { - OC_LOG_V(INFO, TAG, "Callback Context for PUT query recvd successfully"); - OC_LOG_V(INFO, TAG, "JSON = %s =============> Discovered", clientResponse->resJSONPayload); - } + if(clientResponse) {} + if(ctx == (void*)CTX_VAL) { + OC_LOG_V(INFO, TAG, "Callback Context for PUT query recvd successfully"); + OC_LOG_V(INFO, TAG, "JSON = %s =============> Discovered", clientResponse->resJSONPayload); + } - return OC_STACK_KEEP_TRANSACTION; + return OC_STACK_KEEP_TRANSACTION; } OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse) { @@ -105,8 +106,8 @@ OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse } } } - } - return OC_STACK_KEEP_TRANSACTION; + } + return OC_STACK_KEEP_TRANSACTION; } @@ -150,14 +151,14 @@ OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle, { InitGetRequestToUnavailableResource(clientResponse); } - return OC_STACK_KEEP_TRANSACTION; + return OC_STACK_KEEP_TRANSACTION; } int InitGetRequestToUnavailableResource(OCClientResponse * clientResponse) { OCStackResult ret; - OCCallbackData cbData; + OCCallbackData cbData; OCDoHandle handle; std::ostringstream getQuery; getQuery << "coap://" << getIPAddrTBServer(clientResponse) << ":" << getPortTBServer(clientResponse) << "/SomeUnknownResource"; @@ -166,7 +167,7 @@ int InitGetRequestToUnavailableResource(OCClientResponse * clientResponse) ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, OC_NON_CONFIRMABLE, &cbData); if (ret != OC_STACK_OK) { - OC_LOG(ERROR, TAG, "OCStack resource error"); + OC_LOG(ERROR, TAG, "OCStack resource error"); } return ret; } @@ -187,7 +188,7 @@ int InitObserveRequest(OCClientResponse * clientResponse) { OC_LOG(ERROR, TAG, "OCStack resource error"); } - else + else { gObserveDoHandle = handle; } @@ -218,7 +219,7 @@ int InitPutRequest(OCClientResponse * clientResponse) int InitGetRequest(OCClientResponse * clientResponse) { OCStackResult ret; - OCCallbackData cbData; + OCCallbackData cbData; OCDoHandle handle; //* Make a GET query*/ std::ostringstream getQuery; @@ -228,19 +229,18 @@ int InitGetRequest(OCClientResponse * clientResponse) ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, OC_NON_CONFIRMABLE, &cbData); if (ret != OC_STACK_OK) { - OC_LOG(ERROR, TAG, "OCStack resource error"); + OC_LOG(ERROR, TAG, "OCStack resource error"); } return ret; } -#define TEST_APP_UNICAST_DISCOVERY_QUERY PCF("coap://0.0.0.0:5683/oc/core") int InitDiscovery() { OCStackResult ret; - OCCallbackData cbData; + OCCallbackData cbData; OCDoHandle handle; - /* Start a discovery query*/ - char szQueryUri[64] = { 0 }; + /* Start a discovery query*/ + char szQueryUri[64] = { 0 }; if (UNICAST_DISCOVERY) { strcpy(szQueryUri, TEST_APP_UNICAST_DISCOVERY_QUERY); @@ -249,21 +249,21 @@ int InitDiscovery() { strcpy(szQueryUri, OC_WELL_KNOWN_QUERY); } - cbData.cb = discoveryReqCB; - cbData.context = (void*)CTX_VAL; - ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_NON_CONFIRMABLE, &cbData); + cbData.cb = discoveryReqCB; + cbData.context = (void*)CTX_VAL; + ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_NON_CONFIRMABLE, &cbData); if (ret != OC_STACK_OK) { - OC_LOG(ERROR, TAG, "OCStack resource error"); + OC_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"; + uint8_t addr[20] = {0}; + uint8_t* paddr = NULL; + uint16_t port = USE_RANDOM_PORT; + uint8_t ifname[] = "eth0"; if (argc == 3) { @@ -283,47 +283,47 @@ int main(int argc, char* argv[]) { } - /*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*/ + /*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) { - OC_LOG_V(INFO, TAG, "Starting occlient on address %s",addr); + OC_LOG_V(INFO, TAG, "Starting occlient on address %s",addr); paddr = addr; } - /* Initialize OCStack*/ - if (OCInit((char *) paddr, port, OC_CLIENT) != OC_STACK_OK) { - OC_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; + } InitDiscovery(); - // Break from loop with Ctrl+C - OC_LOG(INFO, TAG, "Entering occlient main loop..."); - signal(SIGINT, handleSigInt); - while (!gQuitFlag) { + // Break from loop with Ctrl+C + OC_LOG(INFO, TAG, "Entering occlient main loop..."); + signal(SIGINT, handleSigInt); + while (!gQuitFlag) { - if (OCProcess() != OC_STACK_OK) { - OC_LOG(ERROR, TAG, "OCStack process error"); - return 0; - } + if (OCProcess() != OC_STACK_OK) { + OC_LOG(ERROR, TAG, "OCStack process error"); + return 0; + } - sleep(3); - } - OC_LOG(INFO, TAG, "Exiting occlient main loop..."); + sleep(3); + } + OC_LOG(INFO, TAG, "Exiting occlient main loop..."); - if (OCStop() != OC_STACK_OK) { - OC_LOG(ERROR, TAG, "OCStack stop error"); - } + if (OCStop() != OC_STACK_OK) { + OC_LOG(ERROR, TAG, "OCStack stop error"); + } - return 0; + return 0; } char *getResult(OCStackResult result) { - char *resString = new char[40]; - memset(resString, 0, 40); + char *resString = new char[40]; + memset(resString, 0, 40); strcpy(resString, "Result: "); switch (result) { case OC_STACK_OK: @@ -379,34 +379,34 @@ char *getResult(OCStackResult result) { 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); + 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(); + 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){ - // JSON = {"oc":{"payload":[{"href":"/a/led","rt":["core.led"],"if":["core.rw"],"obs":1}]}} + // JSON = {"oc":{"payload":[{"href":"/a/led","rt":["core.led"],"if":["core.rw"],"obs":1}]}} - //std::string jsonPayload(responsePayload, responsePayload + sizeof responsePayload / sizeof responsePayload[0]); - std::string jsonPayload(reinterpret_cast(const_cast(responsePayload))); - //std::cout << jsonPayload << std::endl; + //std::string jsonPayload(responsePayload, responsePayload + sizeof responsePayload / sizeof responsePayload[0]); + std::string jsonPayload(reinterpret_cast(const_cast(responsePayload))); + //std::cout << jsonPayload << std::endl; - return "/a/led"; + return "/a/led"; } diff --git a/csdk/stack/samples/SimpleClientServer/ocserver.cpp b/csdk/stack/samples/SimpleClientServer/ocserver.cpp index cb9e222..2f61ead 100644 --- a/csdk/stack/samples/SimpleClientServer/ocserver.cpp +++ b/csdk/stack/samples/SimpleClientServer/ocserver.cpp @@ -36,8 +36,8 @@ int gQuitFlag = 0; int gLEDUnderObservation = 0; void createLEDResource(); typedef struct LEDRESOURCE{ - OCResourceHandle handle; - bool state; + OCResourceHandle handle; + bool state; int power; } LEDResource; @@ -46,50 +46,51 @@ static LEDResource LED; // TODO: hard coded for now, change after Sprint4 static unsigned char responsePayloadGet[] = "{\"oc\": {\"payload\": {\"state\" : \"on\",\"power\" : \"10\"}}}"; static unsigned char responsePayloadPut[] = "{\"oc\": {\"payload\": {\"state\" : \"off\",\"power\" : \"0\"}}}"; +static uint16_t OC_WELL_KNOWN_PORT = 5683; OCStackResult OCEntityHandlerCb(OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest ) { - const char* typeOfMessage; - - switch (flag) { - case OC_INIT_FLAG: - typeOfMessage = "OC_INIT_FLAG"; - break; - case OC_REQUEST_FLAG: - typeOfMessage = "OC_REQUEST_FLAG"; - break; - case OC_OBSERVE_FLAG: - typeOfMessage = "OC_OBSERVE_FLAG"; - break; - default: - typeOfMessage = "UNKNOWN"; - } - OC_LOG_V(INFO, TAG, "Receiving message type: %s", typeOfMessage); - if(entityHandlerRequest && flag == OC_REQUEST_FLAG){ //[CL] - if(OC_REST_GET == entityHandlerRequest->method) - //entityHandlerRequest->resJSONPayload = reinterpret_cast(const_cast (responsePayloadGet.c_str())); - entityHandlerRequest->resJSONPayload = responsePayloadGet; - if(OC_REST_PUT == entityHandlerRequest->method) { - //std::cout << std::string(reinterpret_cast(entityHandlerRequest->reqJSONPayload)) << std::endl; - OC_LOG_V(INFO, TAG, "PUT JSON payload from client: %s", entityHandlerRequest->reqJSONPayload); - //entityHandlerRequest->resJSONPayload = reinterpret_cast(const_cast (responsePayloadPut.c_str())); - entityHandlerRequest->resJSONPayload = responsePayloadPut; - //responsePayloadGet = responsePayloadPut; // just a bad hack! - } - - } else if (entityHandlerRequest && flag == OC_OBSERVE_FLAG) { + const char* typeOfMessage; + + switch (flag) { + case OC_INIT_FLAG: + typeOfMessage = "OC_INIT_FLAG"; + break; + case OC_REQUEST_FLAG: + typeOfMessage = "OC_REQUEST_FLAG"; + break; + case OC_OBSERVE_FLAG: + typeOfMessage = "OC_OBSERVE_FLAG"; + break; + default: + typeOfMessage = "UNKNOWN"; + } + OC_LOG_V(INFO, TAG, "Receiving message type: %s", typeOfMessage); + if(entityHandlerRequest && flag == OC_REQUEST_FLAG){ //[CL] + if(OC_REST_GET == entityHandlerRequest->method) + //entityHandlerRequest->resJSONPayload = reinterpret_cast(const_cast (responsePayloadGet.c_str())); + entityHandlerRequest->resJSONPayload = responsePayloadGet; + if(OC_REST_PUT == entityHandlerRequest->method) { + //std::cout << std::string(reinterpret_cast(entityHandlerRequest->reqJSONPayload)) << std::endl; + OC_LOG_V(INFO, TAG, "PUT JSON payload from client: %s", entityHandlerRequest->reqJSONPayload); + //entityHandlerRequest->resJSONPayload = reinterpret_cast(const_cast (responsePayloadPut.c_str())); + entityHandlerRequest->resJSONPayload = responsePayloadPut; + //responsePayloadGet = responsePayloadPut; // just a bad hack! + } + + } else if (entityHandlerRequest && flag == OC_OBSERVE_FLAG) { gLEDUnderObservation = 1; } - //OC_LOG_V(INFO, TAG, "/nReceiving message type:/n/t %s. /n/nWith request:/n/t %s", typeOfMessage, request); + //OC_LOG_V(INFO, TAG, "/nReceiving message type:/n/t %s. /n/nWith request:/n/t %s", typeOfMessage, request); - return OC_STACK_OK; + return OC_STACK_OK; } /* SIGINT handler: set gQuitFlag to 1 for graceful termination */ void handleSigInt(int signum) { - if (signum == SIGINT) { - gQuitFlag = 1; - } + if (signum == SIGINT) { + gQuitFlag = 1; + } } void *ChangeLEDRepresentation (void *param) @@ -103,7 +104,7 @@ void *ChangeLEDRepresentation (void *param) LED.power += 5; if (gLEDUnderObservation) { - OC_LOG_V(INFO, TAG, " =====> Notifying stack of new power level %d\n", LED.power); + OC_LOG_V(INFO, TAG, " =====> Notifying stack of new power level %d\n", LED.power); result = OCNotifyObservers (LED.handle); if (OC_STACK_NO_OBSERVERS == result) { @@ -115,15 +116,15 @@ void *ChangeLEDRepresentation (void *param) } int main() { - OC_LOG(DEBUG, TAG, "OCServer is starting..."); - uint8_t addr[20] = {0}; - uint8_t* paddr = NULL; - uint16_t port = USE_RANDOM_PORT; - uint8_t ifname[] = "eth0"; + OC_LOG(DEBUG, TAG, "OCServer is starting..."); + uint8_t addr[20] = {0}; + uint8_t* paddr = NULL; + uint16_t port = OC_WELL_KNOWN_PORT; + uint8_t ifname[] = "eth0"; pthread_t threadId; - /*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*/ + /*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) { @@ -131,53 +132,53 @@ int main() { paddr = addr; } - if (OCInit((char *) paddr, port, OC_SERVER) != OC_STACK_OK) { - OC_LOG(ERROR, TAG, "OCStack init error"); - return 0; - } + if (OCInit((char *) paddr, port, OC_SERVER) != OC_STACK_OK) { + OC_LOG(ERROR, TAG, "OCStack init error"); + return 0; + } - /* - * Declare and create the example resource: LED - */ - createLEDResource(); + /* + * Declare and create the example resource: LED + */ + createLEDResource(); /* * Create a thread for changing the representation of the LED */ pthread_create (&threadId, NULL, ChangeLEDRepresentation, (void *)NULL); - // Break from loop with Ctrl-C - OC_LOG(INFO, TAG, "Entering ocserver main loop..."); - signal(SIGINT, handleSigInt); - while (!gQuitFlag) { - if (OCProcess() != OC_STACK_OK) { - OC_LOG(ERROR, TAG, "OCStack process error"); - return 0; - } - sleep(3); - } + // Break from loop with Ctrl-C + OC_LOG(INFO, TAG, "Entering ocserver main loop..."); + signal(SIGINT, handleSigInt); + while (!gQuitFlag) { + if (OCProcess() != OC_STACK_OK) { + OC_LOG(ERROR, TAG, "OCStack process error"); + return 0; + } + sleep(3); + } - OC_LOG(INFO, TAG, "Exiting ocserver main loop..."); + OC_LOG(INFO, TAG, "Exiting ocserver main loop..."); - if (OCStop() != OC_STACK_OK) { - OC_LOG(ERROR, TAG, "OCStack process error"); - } + if (OCStop() != OC_STACK_OK) { + OC_LOG(ERROR, TAG, "OCStack process error"); + } - return 0; + return 0; } void createLEDResource() { - LED.state = false; - OCStackResult res = OCCreateResource(&LED.handle, - "core.led", - "core.rw", - "/a/led", - OCEntityHandlerCb, - OC_DISCOVERABLE|OC_OBSERVABLE); - OC_LOG_V(INFO, TAG, "Created LED resource with result: %s", getResult(res)); + LED.state = false; + OCStackResult res = OCCreateResource(&LED.handle, + "core.led", + "core.rw", + "/a/led", + OCEntityHandlerCb, + OC_DISCOVERABLE|OC_OBSERVABLE); + OC_LOG_V(INFO, TAG, "Created LED resource with result: %s", getResult(res)); } char *getResult(OCStackResult result) { char *resString = new char[40]; - memset(resString, 0, 40); + memset(resString, 0, 40); strcpy(resString, "Result: "); switch (result) { case OC_STACK_OK: