#define PDM_SQLITE_UPDATE_LINK_STALE_FOR_STALE_DEVICE "UPDATE T_DEVICE_LINK_STATE SET STATE = 1\
WHERE ID = ? or ID2 = ?"
+#define ASCENDING_ORDER(id1, id2) do{if( (id1) > (id2) )\
+ { int temp; temp = id1; id1 = id2; id2 = temp; }}while(0)
+
#define CHECK_PDM_INIT() do{if(true != gInit)\
{ MA_LOGE("PDB is not initialized"); \
return OC_STACK_PDM_IS_NOT_INITIALIZED; }}while(0)
static OCStackResult begin()
{
- int res = 0;
- res = sqlite3_exec(g_db, PDM_SQLITE_TRANSACTION_BEGIN, NULL, NULL, NULL);
- PDM_VERIFY_SQLITE_OK(res, ERROR, OC_STACK_ERROR);
- return OC_STACK_OK;
+ int res = 0;
+ res = sqlite3_exec(g_db, PDM_SQLITE_TRANSACTION_BEGIN, NULL, NULL, NULL);
+ PDM_VERIFY_SQLITE_OK(res, ERROR, OC_STACK_ERROR);
+ return OC_STACK_OK;
}
static OCStackResult commit()
return OC_STACK_OK;
}
-int delete_mowned_device_db(const OicUuid_t *UUID)
+int PDMDeleteDevice(const OicUuid_t *UUID)
{
CHECK_PDM_INIT();
if (NULL == UUID)
commit();
return OC_STACK_OK;
}
+
+static OCStackResult removeLink(int id1, int id2)
+{
+ int res = 0;
+ sqlite3_stmt *stmt = 0;
+ res = sqlite3_prepare_v2(g_db, PDM_SQLITE_DELETE_LINK, strlen(PDM_SQLITE_DELETE_LINK) + 1, &stmt, NULL);
+ PDM_VERIFY_SQLITE_OK(res, ERROR, OC_STACK_ERROR);
+
+ res = sqlite3_bind_int(stmt, PDM_BIND_INDEX_FIRST, id1);
+ PDM_VERIFY_SQLITE_OK(res, ERROR, OC_STACK_ERROR);
+
+ res = sqlite3_bind_int(stmt, PDM_BIND_INDEX_SECOND, id2);
+ PDM_VERIFY_SQLITE_OK(res, ERROR, OC_STACK_ERROR);
+
+ if (SQLITE_DONE != sqlite3_step(stmt))
+ {
+ MA_LOGE("Error message: %s", sqlite3_errmsg(g_db));
+ sqlite3_finalize(stmt);
+ return OC_STACK_ERROR;
+ }
+ sqlite3_finalize(stmt);
+ return OC_STACK_OK;
+}
+
+int PDMUnlinkDevices(const OicUuid_t *UUID1, const OicUuid_t *UUID2)
+{
+ CHECK_PDM_INIT();
+ if (NULL == UUID1 || NULL == UUID2)
+ {
+ MA_LOGE("Invalid PARAM");
+ return OC_STACK_INVALID_PARAM;
+ }
+
+ int id1 = 0;
+ if (OC_STACK_OK != getIdForUUID(UUID1, &id1))
+ {
+ MA_LOGE("Requested value not found");
+ return OC_STACK_INVALID_PARAM;
+ }
+
+ int id2 = 0;
+ if (OC_STACK_OK != getIdForUUID(UUID2, &id2))
+ {
+ MA_LOGE("Requested value not found");
+ return OC_STACK_INVALID_PARAM;
+ }
+ ASCENDING_ORDER(id1, id2);
+ return removeLink(id1, id2);
+}
\ No newline at end of file
for ( ; num > i; ++i) {
if (OC_STACK_OK !=arr[i].res) {
- ret = delete_mowned_device_db((const OicUuid_t*) &arr[i].deviceId);
+ ret = PDMDeleteDevice((const OicUuid_t*) &arr[i].deviceId);
}
}
ret = closeDB();
_print_result_list((const OCProvisionResult_t*) arr, num);
}
client->g_doneCB = true;
+ OCTerminatePM();
}
static gpointer _remove_mo_func(gpointer data)
ret = openDB();
if (OC_STACK_OK != ret)
MA_LOGE( "openDB: ret = %d (%s)", ret, _error_to_string(ret));
- ret = delete_mowned_device_db((const OicUuid_t*) uuid_target);
+ ret = PDMDeleteDevice((const OicUuid_t*) uuid_target);
if (OC_STACK_OK != ret)
MA_LOGE( "delete_mowned_device_db: ret = %d (%s)", ret, _error_to_string(ret));
ret = closeDB();