X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fcsdk%2Fsecurity%2Fprovisioning%2Fsample%2Fsampleserver_justworks.cpp;h=a06bc03a91d6dbc0faab5d5c7bb2af018364e9b9;hb=3c093548382bb2542c87a67e6e5fa32552c29cb3;hp=454554a3570372c483aac69e44d845fcacd59395;hpb=2149e49d0daeec07841f69ee973206f49ae88ec2;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/csdk/security/provisioning/sample/sampleserver_justworks.cpp b/resource/csdk/security/provisioning/sample/sampleserver_justworks.cpp index 454554a..a06bc03 100644 --- a/resource/csdk/security/provisioning/sample/sampleserver_justworks.cpp +++ b/resource/csdk/security/provisioning/sample/sampleserver_justworks.cpp @@ -20,6 +20,7 @@ /////////////////////////////////////////////////////////////////////// //NOTE : This sample server is generated based on ocserverbasicops.cpp /////////////////////////////////////////////////////////////////////// +#include "iotivity_config.h" #include #include #include @@ -33,6 +34,7 @@ #include "ocstack.h" #include "ocpayload.h" #include "pinoxmcommon.h" +#include "srmutility.h" #ifdef HAVE_WINDOWS_H #include @@ -277,7 +279,7 @@ OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest, gLedInstance[gCurrLedInstance].state = 0; gLedInstance[gCurrLedInstance].power = 0; gCurrLedInstance++; - strncpy ((char *)response->resourceUri, newLedUri, MAX_URI_LENGTH); + strncpy ((char *)response->resourceUri, newLedUri, sizeof(response->resourceUri)); ehResult = OC_EH_RESOURCE_CREATED; } } @@ -410,14 +412,48 @@ FILE* server_fopen(const char *path, const char *mode) return fopen(CRED_FILE, mode); } +static void OtmEventHandler(void *ctx, const char *addr, uint16_t port, + const char* ownerId, OCOtmEvent_t event) +{ + (void)ctx; + printf("--------------------------------------\n"); + printf("Get OTM event.\n"); + printf("Address : %s\n", addr); + printf("Port : %d\n", port); + printf("Owner ID : %s\n", ownerId); + + switch (event) + { + case OIC_OTM_READY: + printf("State : OIC_OTM_READY\n"); + break; + case OIC_OTM_STARTED: + printf("State : OIC_OTM_STARTED\n"); + break; + case OIC_OTM_DONE: + printf("State : OIC_OTM_DONE\n"); + break; + case OIC_OTM_ERROR: + printf("State : OIC_OTM_ERROR\n"); + break; + default: + printf("State : Unknown state.\n"); + break; + } + printf("--------------------------------------\n"); +} + int main() { struct timespec timeout; OIC_LOG(DEBUG, TAG, "OCServer is starting..."); + //This function should be invoked before invoke OCInit + OCSetOtmEventHandler(NULL, OtmEventHandler); + // Initialize Persistent Storage for SVR database - OCPersistentStorage ps = {server_fopen, fread, fwrite, fclose, unlink}; + OCPersistentStorage ps = {server_fopen, fread, fwrite, fclose, unlink, NULL, NULL}; OCRegisterPersistentStorageHandler(&ps); @@ -445,11 +481,7 @@ int main() OIC_LOG(ERROR, TAG, "OCStack process error"); return 0; } -#if defined(_WIN32) - Sleep(100); -#else nanosleep(&timeout, NULL); -#endif //defined(_WIN32) } OIC_LOG(INFO, TAG, "Exiting ocserver main loop...");