X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fcsdk%2Fstack%2Fsamples%2Ftizen%2FSimpleClientServer%2Focserver.cpp;h=650b428bc529e158a96304e8cd307287394f3004;hb=7f00f942c39b7bc27c7eeecf213a239c3fe4173c;hp=43053998d324bc8bedecd030368f1a8749ffbbe6;hpb=edcfc3d2329da7b914771c0dcff5f42c9b74fd93;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/csdk/stack/samples/tizen/SimpleClientServer/ocserver.cpp b/resource/csdk/stack/samples/tizen/SimpleClientServer/ocserver.cpp index 4305399..650b428 100644 --- a/resource/csdk/stack/samples/tizen/SimpleClientServer/ocserver.cpp +++ b/resource/csdk/stack/samples/tizen/SimpleClientServer/ocserver.cpp @@ -39,8 +39,10 @@ using namespace std; //string length of "/a/light/" + std::numeric_limits::digits10 + '\0'" // 9 + 9 + 1 = 19 const int URI_MAXSIZE = 19; +static const char* DEFAULT_DB_FILE_PATH = "/opt/usr/etc/oic_svr_db_server.dat"; static int gObserveNotifyType = 3; +static int gSecure = 0; int gQuitFlag = 0; int gLightUnderObservation = 0; @@ -505,6 +507,7 @@ OCDeviceEntityHandlerCb (OCEntityHandlerFlag flag, } } + OCPayloadDestroy(response.payload); return ehResult; } @@ -735,13 +738,20 @@ void *presenceNotificationGenerator(void *param) if(res == OC_STACK_OK) { sleep(2); + + uint8_t resourceProperties = OC_DISCOVERABLE | OC_OBSERVABLE; + if (gSecure) + { + resourceProperties |= OC_SECURE; + } + res = OCCreateResource(&presenceNotificationHandles[i], presenceNotificationResources.at(i).c_str(), OC_RSRVD_INTERFACE_DEFAULT, presenceNotificationUris.at(i).c_str(), OCNOPEntityHandlerCb, NULL, - OC_DISCOVERABLE|OC_OBSERVABLE); + resourceProperties); } if(res != OC_STACK_OK) { @@ -780,13 +790,20 @@ int createLightResource (char *uri, LightResource *lightResource) lightResource->state = false; lightResource->power= 0; + + uint8_t resourceProperties = OC_DISCOVERABLE | OC_OBSERVABLE; + if (gSecure) + { + resourceProperties |= OC_SECURE; + } + OCStackResult res = OCCreateResource(&(lightResource->handle), "core.light", "oc.mi.def", uri, OCEntityHandlerCb, NULL, - OC_DISCOVERABLE|OC_OBSERVABLE); + resourceProperties); cout << "\nCreated Light resource with result " << getResult(res); return 0; @@ -936,9 +953,11 @@ OCStackResult SetDeviceInfo(const char* deviceName, const char* specVersion, con static void PrintUsage() { - cout << "\nUsage : ocserver -o <0|1>"; + cout << "\nUsage : ocserver -o <0|1> -s <0|1>"; cout << "\n-o 0 : Notify all observers"; cout << "\n-o 1 : Notify list of observers"; + cout << "\n-s 0 : Non secure resource"; + cout << "\n-s 1 : Secure resource"; } void *GMainLoopThread(void *param) @@ -963,6 +982,11 @@ void *GMainLoopThread(void *param) return NULL; } +static FILE *server_fopen(const char */*path*/, const char *mode) +{ + return fopen(DEFAULT_DB_FILE_PATH, mode); +} + int main(int argc, char* argv[]) { pthread_t threadId; @@ -976,20 +1000,24 @@ int main(int argc, char* argv[]) return 0; } - while ((opt = getopt(argc, argv, "o:")) != -1) + while ((opt = getopt(argc, argv, "o:s:")) != -1) { switch(opt) { case 'o': gObserveNotifyType = atoi(optarg); break; + case 's': + gSecure = atoi(optarg); + break; default: PrintUsage(); return -1; } } - if ((gObserveNotifyType != 0) && (gObserveNotifyType != 1)) + if ((gObserveNotifyType != 0) && (gObserveNotifyType != 1) && + (gSecure != 0) && (gSecure != 1)) { PrintUsage(); return -1; @@ -997,6 +1025,9 @@ int main(int argc, char* argv[]) cout << "\nOCServer is starting..."; + OCPersistentStorage ps{ server_fopen, fread, fwrite, fclose, unlink }; + OCRegisterPersistentStorageHandler(&ps); + if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK) { cout << "\nOCStack init error";