Added notification callback on reset SVR DB 50/217950/1
authorVitalii Irkha <v.irkha@samsung.com>
Fri, 8 Nov 2019 15:52:54 +0000 (17:52 +0200)
committerSudipto Bal <sudipto.bal@samsung.com>
Mon, 18 Nov 2019 03:04:28 +0000 (12:04 +0900)
Created API's for notifing when SVR DB is reset

https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/599/commits/93a9f532a2da7526cbede4f77f27c727480ec270
(cherry-picked from 93a9f532a2da7526cbede4f77f27c727480ec270)

Change-Id: Ib4ac7d36f2232dce6ce0f6a1ecb64d9d2e153cf7
Signed-off-by: Vitalii Irkha <v.irkha@samsung.com>
Signed-off-by: Sudipto Bal <sudipto.bal@samsung.com>
resource/csdk/security/include/internal/psinterface.h
resource/csdk/security/provisioning/include/ocprovisioningmanager.h
resource/csdk/security/provisioning/src/ocprovisioningmanager.c
resource/csdk/security/src/psinterface.c
resource/csdk/stack/include/octypes.h

index ae228bf..73bc90e 100644 (file)
@@ -152,4 +152,10 @@ void DeinitPersistentStorageInterface(void);
 OCStackResult setSecurePSI(const unsigned char *key, const OCPersistentStorage *psPlain,
         const OCPersistentStorage *psEnc, const OCPersistentStorage *psRescue);
 
+/**
+ *
+ * @return pointer on resetSVRDB structure for manipulating with callback
+ */
+resetSVRDBCB_t* const GetResetSVRDBCB(void);
+
 #endif //IOTVT_SRM_PSI_H
index 483afa2..b27d8ec 100644 (file)
@@ -449,6 +449,19 @@ OCStackResult OCResetDevice(void *ctx, unsigned short waitTimeForOwnedDeviceDisc
 OCStackResult OCResetSVRDB(void);\r
 \r
 /**\r
+ * The function registers callback, for getting notification if SVR DB was reseted.\r
+ *\r
+ * @param[in] ResetSVRDBCB notifier callback function.\r
+ * @return OC_STACK_OK in case of success and other value otherwise.\r
+ */\r
+OCStackResult OCRegisterResetSVRDBNotifier(ResetSVRDBCB callback);\r
+\r
+/**\r
+ * The function unregisters ResetSVRDBCB notification callback.\r
+ */\r
+void OCUnregisterResetSVRDBNotifier(void);\r
+\r
+/**\r
  * This function configures SVR DB as self-ownership.\r
  *\r
  *@return OC_STACK_OK in case of successful configue and other value otherwise.\r
index a46843f..7453a82 100644 (file)
@@ -934,6 +934,44 @@ OCStackResult OCResetSVRDB(void)
 }
 
 /**
+ * This function to register callback, for getting notification if SVR DB was reseted.
+ * @param[in] ResetSVRDBCB notifier callback function.
+ * @return OC_STACK_OK in case of successful reset and other value otherwise.
+ */
+
+OCStackResult OCRegisterResetSVRDBNotifier(ResetSVRDBCB callback)
+{
+    OIC_LOG_V(INFO, TAG, "IN %s", __func__);
+
+    if(NULL != GetResetSVRDBCB()->callback)
+    {
+        OIC_LOG_V(ERROR, TAG,"%s Can't register notifier callback, unregister previous one!" ,__func__);
+        return OC_STACK_ERROR;
+    }
+
+    GetResetSVRDBCB()->callback = callback;
+
+    OIC_LOG_V(INFO, TAG, "Out %s", __func__);
+    return OC_STACK_OK;
+}
+
+
+/**
+ * This function to unregister ResetSVRDBCB notification callback.
+ */
+void OCUnregisterResetSVRDBNotifier(void)
+{
+    OIC_LOG_V(INFO, TAG, "IN %s", __func__);
+
+    if(NULL != GetResetSVRDBCB()->callback)
+    {
+        GetResetSVRDBCB()->callback = NULL;
+    }
+
+    OIC_LOG_V(INFO, TAG, "Out %s", __func__);
+}
+
+/**
  * This function configures SVR DB as self-ownership.
  *
  *@return OC_STACK_OK in case of successful configue and other value otherwise.
index baba287..029592f 100644 (file)
@@ -59,6 +59,12 @@ static oc_mutex g_mutexDb = NULL;
 // Persistent Storage status
 static PSStatus_t g_psStatus = PS_NO_EXTERNAL_DB_SET;
 
+static resetSVRDBCB_t g_resetSVRDBCB = {0};
+
+resetSVRDBCB_t* const GetResetSVRDBCB(void)
+{
+    return &g_resetSVRDBCB;
+}
 /**
  * Update the Persistent Storage Database size.
  */
@@ -1058,6 +1064,8 @@ exit:
     OICFree(pstatCbor);
     OICFree(doxmCbor);
     OICFree(resetPfCbor);
+
+    g_resetSVRDBCB.callback(ret);
     return ret;
 }
 
index 8187b88..128470c 100644 (file)
@@ -1772,6 +1772,21 @@ typedef enum
 typedef void (*OCOtmEventHandler)(void *ctx, const char *addr, uint16_t port,
         const char *ownerId, OCOtmEvent_t event);
 
+/**
+ * Callback function for notification SVR DB was reseted.
+ *
+ * @param[in] result of OCResetSVRDB API call
+ */
+typedef void (*ResetSVRDBCB)(OCStackResult result);
+
+/**
+ * resetSVRDBCB structure.
+ */
+typedef struct resetSVRDBCB
+{
+    ResetSVRDBCB callback;
+} resetSVRDBCB_t;
+
 #ifdef __cplusplus
 }
 #endif // __cplusplus