replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / security / provisioning / sample / sampleserver_justworks.cpp
index 94d79d0..a06bc03 100644 (file)
@@ -34,6 +34,7 @@
 #include "ocstack.h"
 #include "ocpayload.h"
 #include "pinoxmcommon.h"
+#include "srmutility.h"
 
 #ifdef HAVE_WINDOWS_H
 #include <windows.h>
@@ -411,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);