replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / security / provisioning / sample / sampleserver_justworks.cpp
index 7047ae9..a06bc03 100644 (file)
 ///////////////////////////////////////////////////////////////////////
 //NOTE :  This sample server is generated based on ocserverbasicops.cpp
 ///////////////////////////////////////////////////////////////////////
+#include "iotivity_config.h"
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#include <signal.h>
+#endif
+#ifdef HAVE_PTHREAD_H
 #include <pthread.h>
+#endif
+#include <signal.h>
 #include "ocstack.h"
-#include "logger.h"
 #include "ocpayload.h"
+#include "pinoxmcommon.h"
+#include "srmutility.h"
+
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
+/** @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"
 
@@ -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);