From fde3ea44a24217a00f04b860a526bb180bb773a0 Mon Sep 17 00:00:00 2001 From: "saerome.kim" Date: Mon, 15 Jan 2018 14:04:24 +0900 Subject: [PATCH] mot-agent: add OCUnlinkDevices Signed-off-by: saerome.kim --- oic_svr_db_server_justworks.dat | Bin 0 -> 2207 bytes src/mot-agent/ma-db.c | 62 ++++++++++++++++++++++++++++++++++++---- src/mot-agent/ma-db.h | 3 +- src/mot-agent/ma-subowner.c | 5 ++-- 4 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 oic_svr_db_server_justworks.dat diff --git a/oic_svr_db_server_justworks.dat b/oic_svr_db_server_justworks.dat new file mode 100644 index 0000000000000000000000000000000000000000..987ca608592ccbcf276d3748d89fdd773ad65a99 GIT binary patch literal 2207 zcmd^Ay^`865C(=xmzkuzK2>Hc;O+vxH^?J!U1VvEWo*kMiJvPW&ygZIn!G?-%Dhdg zyP9YPz5@ykEm7!s?P666@edOF$22oa_ zU@#g9K7AMT+J4A8J&%51SKf7}7kK_CFh>%8%g}EcCOzVl= z1h-SCZxgFC0f92JSPDiI!I%OO&Lj>+NCIl(5*e%*Wyx**=OVOHX!Dg*26}!!)T1B< zX3#tOUMSFVq^#!if=3F%sAczQ+1V!(lOe&OH6b=8l7uNpKCJBhe?923 IYkIZ%4S (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) @@ -101,10 +104,10 @@ static bool gInit = false; /* Only if we can open sqlite db successfully, gInit 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() @@ -232,7 +235,7 @@ static OCStackResult removeFromDeviceList(int id) 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) @@ -255,3 +258,52 @@ int delete_mowned_device_db(const OicUuid_t *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 diff --git a/src/mot-agent/ma-db.h b/src/mot-agent/ma-db.h index 83ea83d..4eb8a6c 100644 --- a/src/mot-agent/ma-db.h +++ b/src/mot-agent/ma-db.h @@ -25,7 +25,8 @@ extern "C" { int openDB(); int closeDB(); -int delete_mowned_device_db(const OicUuid_t *UUID); +int PDMDeleteDevice(const OicUuid_t *UUID); +int PDMUnlinkDevices(const OicUuid_t *UUID1, const OicUuid_t *UUID2); #ifdef __cplusplus } diff --git a/src/mot-agent/ma-subowner.c b/src/mot-agent/ma-subowner.c index a4c185b..999d904 100644 --- a/src/mot-agent/ma-subowner.c +++ b/src/mot-agent/ma-subowner.c @@ -915,7 +915,7 @@ static void _mot_cb(void* ctx, int num, OCProvisionResult_t* arr, bool has_error 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(); @@ -1037,6 +1037,7 @@ static void _remove_mo_cb(void* ctx, int num, OCProvisionResult_t* arr, bool has _print_result_list((const OCProvisionResult_t*) arr, num); } client->g_doneCB = true; + OCTerminatePM(); } static gpointer _remove_mo_func(gpointer data) @@ -1071,7 +1072,7 @@ 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(); -- 2.7.4