X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=resource%2Fcsdk%2Fstack%2Fsamples%2Flinux%2FSimpleClientServer%2Focserverslow.cpp;h=2e45cbce2b602d402c0d7fb8bc3f271d6af3a93a;hb=refs%2Ftags%2Faccepted%2Ftizen%2Funified%2F20171010.063815;hp=e56e144108db0cec13a880a558a53abc260497e0;hpb=bb93e3a07afd2126aa7665c4c56de50e2a1c9bfa;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/ocserverslow.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/ocserverslow.cpp index e56e144..2e45cbc 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/ocserverslow.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/ocserverslow.cpp @@ -18,19 +18,34 @@ // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +#include "iotivity_config.h" #include #include #include +#ifdef HAVE_UNISTD_H #include +#endif +#ifdef HAVE_WINDOWS_H +#include +#endif #include +#ifdef HAVE_PTHREAD_H #include +#endif +#ifdef HAVE_SYS_TIME_H #include +#endif +#include #include #include "ocstack.h" #include "oic_malloc.h" #include "oic_string.h" #include "logger.h" +#if defined (__TIZENRT__) +#include +#else #include "cJSON.h" +#endif #include "ocserverslow.h" #include "ocpayload.h" #include "payload_logging.h" @@ -38,11 +53,11 @@ volatile sig_atomic_t gQuitFlag = 0; static std::list gRequestList; -static constexpr unsigned int SLOW_RESPONSE_DELAY_SEC = 5; +BOOST_STATIC_CONSTEXPR unsigned int SLOW_RESPONSE_DELAY_SEC = 5; static LEDResource LED; -static constexpr unsigned int SAMPLE_MAX_NUM_POST_INSTANCE = 2; +BOOST_STATIC_CONSTEXPR unsigned int SAMPLE_MAX_NUM_POST_INSTANCE = 2; static LEDResource gLedInstance[SAMPLE_MAX_NUM_POST_INSTANCE]; //char *gResourceUri= const_cast("/a/led"); @@ -138,7 +153,7 @@ void ProcessGetPutRequest (OCEntityHandlerRequest *ehRequest) OIC_LOG(ERROR, TAG, "Error sending response"); } - free(getResp); + OCRepPayloadDestroy(getResp); } OCEntityHandlerRequest *CopyRequest(OCEntityHandlerRequest *entityHandlerRequest) @@ -187,6 +202,21 @@ OCEntityHandlerRequest *CopyRequest(OCEntityHandlerRequest *entityHandlerRequest return copyOfRequest; } +#if !defined(SIGALRM) +void AlarmHandler(int sig); +int WINAPI AlarmThread(void *seconds) +{ + sleep((unsigned int)seconds); + AlarmHandler(0); + return 0; +} + +void alarm(unsigned int seconds) +{ + CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)AlarmThread, (void*)seconds, 0, NULL); +} +#endif + OCEntityHandlerResult OCEntityHandlerCb (OCEntityHandlerFlag flag, OCEntityHandlerRequest *entityHandlerRequest, void* /*callbackParam*/) { @@ -246,7 +276,9 @@ void handleSigInt(int signum) // slow response when fired void AlarmHandler(int sig) { +#ifdef SIGALRM if (sig == SIGALRM) +#endif { OIC_LOG (INFO, TAG, "Server starting slow response"); if (gRequestList.empty()) @@ -299,8 +331,10 @@ int main(int /*argc*/, char** /*argv[]*/) // Declare and create the example resource: LED createLEDResource(gResourceUri, &LED, false, 42); +#ifdef SIGALRM // Initialize slow response alarm signal(SIGALRM, AlarmHandler); +#endif // Break from loop with Ctrl-C OIC_LOG(INFO, TAG, "Entering ocserver main loop...");