From: saerome.kim Date: Mon, 15 Jan 2018 05:04:24 +0000 (+0900) Subject: mot-agent: add OCUnlinkDevices X-Git-Tag: submit/tizen/20190131.065036~223 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fde3ea44a24217a00f04b860a526bb180bb773a0;p=platform%2Fcore%2Fapi%2Fmulti-device-group.git mot-agent: add OCUnlinkDevices Signed-off-by: saerome.kim --- diff --git a/oic_svr_db_server_justworks.dat b/oic_svr_db_server_justworks.dat new file mode 100644 index 0000000..987ca60 Binary files /dev/null and b/oic_svr_db_server_justworks.dat differ diff --git a/src/mot-agent/ma-db.c b/src/mot-agent/ma-db.c index 26b8b0a..edf9ff9 100644 --- a/src/mot-agent/ma-db.c +++ b/src/mot-agent/ma-db.c @@ -92,6 +92,9 @@ typedef enum PdmDeviceState { #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) @@ -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();