X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fcsdk%2Fsecurity%2Fprovisioning%2Fsample%2Fsampleserver_justworks.cpp;h=a06bc03a91d6dbc0faab5d5c7bb2af018364e9b9;hb=7f00f942c39b7bc27c7eeecf213a239c3fe4173c;hp=03e741efac2e9a34c5a8c4f557534b7acad86e34;hpb=bb93e3a07afd2126aa7665c4c56de50e2a1c9bfa;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 03e741e..a06bc03 100644 --- a/resource/csdk/security/provisioning/sample/sampleserver_justworks.cpp +++ b/resource/csdk/security/provisioning/sample/sampleserver_justworks.cpp @@ -20,15 +20,32 @@ /////////////////////////////////////////////////////////////////////// //NOTE : This sample server is generated based on ocserverbasicops.cpp /////////////////////////////////////////////////////////////////////// +#include "iotivity_config.h" #include #include #include +#ifdef HAVE_UNISTD_H #include -#include +#endif +#ifdef HAVE_PTHREAD_H #include +#endif +#include #include "ocstack.h" -#include "logger.h" #include "ocpayload.h" +#include "pinoxmcommon.h" +#include "srmutility.h" + +#ifdef HAVE_WINDOWS_H +#include +/** @todo stop-gap for naming issue. Windows.h does not like us to use ERROR */ +#ifdef ERROR +#undef ERROR +#endif //ERROR +#endif //HAVE_WINDOWS_H +#include "platform_features.h" +#include "logger.h" + #define TAG "SAMPLE_JUSTWORKS" @@ -53,7 +70,7 @@ char *gResourceUri= (char *)"/a/led"; //Secure Virtual Resource database for Iotivity Server //It contains Server's Identity and the PSK credentials //of other devices which the server trusts -static char CRED_FILE[] = "oic_svr_db_server_justworks.json"; +static char CRED_FILE[] = "oic_svr_db_server_justworks.dat"; /* Function that creates a new LED resource by calling the * OCCreateResource() method. @@ -262,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; } } @@ -395,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);