From f41c2c9a2f7e18d248604da8048c220a337bed30 Mon Sep 17 00:00:00 2001 From: Hyunho Kang Date: Tue, 4 Dec 2018 16:45:52 +0900 Subject: [PATCH] [DataControl] Add current caller client appid and current provider id property (#526) * Add latest caller client appid property - string LatestClientAppId Signed-off-by: hyunho * Modify LatestCallerAppid to CurrentCallerAppid Signed-off-by: hyunho * Add CurrentProviderId property Signed-off-by: hyunho * Modify static Current* value to non-static Signed-off-by: hyunho * Add curly braces around the nested statements Signed-off-by: hyunho * Add missing return, param documentation Signed-off-by: hyunho * Move suppress finalize position Signed-off-by: hyunho --- .../Interop/Interop.DataControl.cs | 3 + .../Tizen.Applications.DataControl/Provider.cs | 161 +++++++++++++++++++-- 2 files changed, 152 insertions(+), 12 deletions(-) mode change 100755 => 100644 src/Tizen.Applications.DataControl/Tizen.Applications.DataControl/Provider.cs diff --git a/src/Tizen.Applications.DataControl/Interop/Interop.DataControl.cs b/src/Tizen.Applications.DataControl/Interop/Interop.DataControl.cs index f7c32d0..11625be 100755 --- a/src/Tizen.Applications.DataControl/Interop/Interop.DataControl.cs +++ b/src/Tizen.Applications.DataControl/Interop/Interop.DataControl.cs @@ -300,6 +300,9 @@ internal static partial class Interop [DllImport(Libraries.DataControl, EntryPoint = "data_control_provider_send_error")] internal static extern ResultType SendError(int requestID, string error); + [DllImport(Libraries.DataControl, EntryPoint = "data_control_provider_get_client_appid")] + internal static extern ResultType GetClientAppId(int requestID, out string clientAppId); + [DllImport(Libraries.DataControl, EntryPoint = "data_control_sql_insert")] internal static extern ResultType Insert(SafeDataControlHandle provider, SafeBundleHandle insertData, out int requestId); diff --git a/src/Tizen.Applications.DataControl/Tizen.Applications.DataControl/Provider.cs b/src/Tizen.Applications.DataControl/Tizen.Applications.DataControl/Provider.cs old mode 100755 new mode 100644 index 06acac7..a2c75f7 --- a/src/Tizen.Applications.DataControl/Tizen.Applications.DataControl/Provider.cs +++ b/src/Tizen.Applications.DataControl/Tizen.Applications.DataControl/Provider.cs @@ -41,6 +41,8 @@ namespace Tizen.Applications.DataControl private static Mutex _lock = new Mutex(); private bool _disposed = false; private bool _isRunning = false; + private string _currentClientAppId; + private string _currentProviderId; /// /// Gets the data ID. @@ -52,6 +54,38 @@ namespace Tizen.Applications.DataControl private set; } + /// + /// Gets the current client appid. + /// + /// 6 + public string CurrentClientAppId + { + get + { + return _currentClientAppId; + } + internal set + { + _currentClientAppId = value; + } + } + + /// + /// Gets the current provider ID. + /// + /// 6 + public string CurrentProviderId + { + get + { + return _currentProviderId; + } + internal set + { + _currentProviderId = value; + } + } + private static bool DataChangeListenFilter(IntPtr handlePtr, string consumerAppid, IntPtr userData) { Provider provider; @@ -125,6 +159,19 @@ namespace Tizen.Applications.DataControl return query; } + internal static ResultType UpdateCurrentClient(Provider provider, int requestId) + { + string clientAppId; + ResultType ret = Interop.DataControl.GetClientAppId(requestId, out clientAppId); + if (ret != ResultType.Success) + { + Log.Error(LogTag, "Get client id fail " + ret.ToString()); + return ResultType.IoError; + } + provider.CurrentClientAppId = clientAppId; + return ResultType.Success; + } + private static void InsertRequest(int requestId, IntPtr handlePtr, IntPtr insertData, IntPtr userData) { Provider provider; @@ -140,6 +187,12 @@ namespace Tizen.Applications.DataControl return; } + ret = UpdateCurrentClient(provider, requestId); + if (ret != ResultType.Success) + { + return; + } + result = provider.OnInsert(query, new Bundle(sbh)); if (result != null) { @@ -191,6 +244,12 @@ namespace Tizen.Applications.DataControl return; } + ret = UpdateCurrentClient(provider, requestId); + if (ret != ResultType.Success) + { + return; + } + result = provider.OnBulkInsert(queryList, bulkData); if (result != null) { @@ -433,6 +492,11 @@ namespace Tizen.Applications.DataControl return; } + ret = UpdateCurrentClient(provider, requestId); + if (ret != ResultType.Success) + { + return; + } result = provider.OnSelect(query, where, _columnList, _columnList.Length, order, pageNum, countPerPage); if (result != null) { @@ -504,6 +568,11 @@ namespace Tizen.Applications.DataControl return; } + ret = UpdateCurrentClient(provider, requestId); + if (ret != ResultType.Success) + { + return; + } result = provider.OnUpdate(query, where, new Bundle(sbh)); if (result != null) { @@ -545,6 +614,11 @@ namespace Tizen.Applications.DataControl return; } + ret = UpdateCurrentClient(provider, requestId); + if (ret != ResultType.Success) + { + return; + } result = provider.OnDelete(query, where); if (result != null) { @@ -585,6 +659,11 @@ namespace Tizen.Applications.DataControl return; } + ret = UpdateCurrentClient(provider, requestId); + if (ret != ResultType.Success) + { + return; + } result = provider.OnMapAdd(key, value); if (result != null) { @@ -624,6 +703,11 @@ namespace Tizen.Applications.DataControl return; } + ret = UpdateCurrentClient(provider, requestId); + if (ret != ResultType.Success) + { + return; + } result = provider.OnMapSet(key, oldValue, newValue); if (result != null) { @@ -663,6 +747,11 @@ namespace Tizen.Applications.DataControl return; } + ret = UpdateCurrentClient(provider, requestId); + if (ret != ResultType.Success) + { + return; + } result = provider.OnMapRemove(key, value); if (result != null) { @@ -690,7 +779,7 @@ namespace Tizen.Applications.DataControl } } - private static void MapGetRequest(int requestID, IntPtr handlePtr, string key, IntPtr userData) + private static void MapGetRequest(int requestId, IntPtr handlePtr, string key, IntPtr userData) { Provider provider; MapGetResult result; @@ -703,6 +792,11 @@ namespace Tizen.Applications.DataControl return; } + ret = UpdateCurrentClient(provider, requestId); + if (ret != ResultType.Success) + { + return; + } result = provider.OnMapGet(key); if (result != null) { @@ -711,7 +805,7 @@ namespace Tizen.Applications.DataControl int valueCount = 0; if (result.ValueList != null) valueCount = result.ValueList.Length; - ret = Interop.DataControl.SendMapGetResult(requestID, result.ValueList, valueCount); + ret = Interop.DataControl.SendMapGetResult(requestId, result.ValueList, valueCount); if (ret != ResultType.Success) { Log.Error(LogTag, "SendMapGetResult fail " + ret.ToString()); @@ -720,7 +814,7 @@ namespace Tizen.Applications.DataControl } else { - ret = Interop.DataControl.SendError(requestID, result.Result.ToString()); + ret = Interop.DataControl.SendError(requestId, result.Result.ToString()); if (ret != ResultType.Success) { Log.Error(LogTag, "SendError fail " + ret.ToString()); @@ -729,11 +823,11 @@ namespace Tizen.Applications.DataControl } else { - Log.Info(LogTag, $"MapRemoveRequest is null : {requestID.ToString()}"); + Log.Info(LogTag, $"MapRemoveRequest is null : {requestId.ToString()}"); } } - private static void MapBulkAddRequest(int requestID, IntPtr handlePtr, IntPtr bulkDataPtr, IntPtr userData) + private static void MapBulkAddRequest(int requestId, IntPtr handlePtr, IntPtr bulkDataPtr, IntPtr userData) { Provider provider; MapBulkAddResult result; @@ -757,12 +851,18 @@ namespace Tizen.Applications.DataControl return; } + ret = UpdateCurrentClient(provider, requestId); + if (ret != ResultType.Success) + { + return; + } + result = provider.OnMapBulkAdd(bulkData); if (result != null) { if (result.Result) { - ret = Interop.DataControl.SendMapBulkAddResult(requestID, result.BulkResultData.SafeBulkDataHandle); + ret = Interop.DataControl.SendMapBulkAddResult(requestId, result.BulkResultData.SafeBulkDataHandle); if (ret != ResultType.Success) { Log.Error(LogTag, "SendMapBulkAddResult fail " + ret.ToString()); @@ -770,7 +870,7 @@ namespace Tizen.Applications.DataControl } else { - ret = Interop.DataControl.SendError(requestID, result.Result.ToString()); + ret = Interop.DataControl.SendError(requestId, result.Result.ToString()); if (ret != ResultType.Success) { Log.Error(LogTag, "SendError fail " + ret.ToString()); @@ -784,7 +884,7 @@ namespace Tizen.Applications.DataControl } else { - Log.Info(LogTag, $"MapBulkAddRequest is null : {requestID.ToString()}"); + Log.Info(LogTag, $"MapBulkAddRequest is null : {requestId.ToString()}"); } } @@ -819,11 +919,14 @@ namespace Tizen.Applications.DataControl Interop.DataControl.SafeDataControlHandle handle = new Interop.DataControl.SafeDataControlHandle(handlePtr, false); Provider provider = null; string dataID; + string providerID; + Interop.DataControl.DataControlGetProviderId(handle, out providerID); Interop.DataControl.DataControlGetDataId(handle, out dataID); if (dataID != null && _providerDict.ContainsKey(dataID)) { provider = _providerDict[dataID]; + provider.CurrentProviderId = providerID; Log.Info(LogTag, "DataID :" + dataID + ", hash code : " + provider.GetHashCode().ToString()); } handle.Dispose(); @@ -985,30 +1088,51 @@ namespace Tizen.Applications.DataControl /// /// Overrides this method if you want to handle the behavior when the select request is received. /// + /// The select query. + /// The where statement. + /// The requested column list. + /// The requested column count. + /// The select order. + /// The page number. + /// The count per page. + /// The result of select operation. /// 3 protected abstract SelectResult OnSelect(string query, string where, string[] columList, int columnCount, string order, int pageNum, int countPerPage); /// /// Overrides this method if you want to handle the behavior when the insert request is received. /// + /// The select query. + /// The insert data. + /// The result of insert operation. /// 3 protected abstract InsertResult OnInsert(string query, Bundle insertData); /// /// Overrides this method if you want to handle the behavior when the update request is received. /// + /// The update query. + /// The where statement. + /// The update data. + /// The result of update operation. /// 3 protected abstract UpdateResult OnUpdate(string query, string where, Bundle updateData); /// /// Overrides this method if you want to handle the behavior when the delete request is received. /// + /// The delete query. + /// The where statement. + /// The result of delete operation. /// 3 protected abstract DeleteResult OnDelete(string query, string where); /// /// Overrides this method if you want to handle the behavior when the bulk insert request is received. /// + /// The insert query list. + /// The bulk insert data. + /// The result of bulk insert operation. /// 3 protected virtual BulkInsertResult OnBulkInsert(IEnumerable query, BulkData bulkInsertData) { @@ -1019,6 +1143,8 @@ namespace Tizen.Applications.DataControl /// /// Overrides this method if you want to handle the behavior when the map get request is received. /// + /// The key of requested data. + /// The result of get operation. /// 3 protected virtual MapGetResult OnMapGet(string key) { @@ -1029,6 +1155,9 @@ namespace Tizen.Applications.DataControl /// /// Overrides this method if you want to handle the behavior when the map add request is received. /// + /// The key of added data. + /// The value of added data. + /// The result of add operation. /// 3 protected virtual MapAddResult OnMapAdd(string key, string value) { @@ -1039,6 +1168,10 @@ namespace Tizen.Applications.DataControl /// /// Overrides this method if you want to handle the behavior when the update request is received. /// + /// The key of set data. + /// The old value of set data. + /// The new value. + /// The result of set operation. /// 3 protected virtual MapSetResult OnMapSet(string key, string oldValue, string newValue) { @@ -1049,6 +1182,9 @@ namespace Tizen.Applications.DataControl /// /// Overrides this method if you want to handle the behavior when the delete request is received. /// + /// The key of removed data. + /// The value of removed data. + /// The result of remove operation. /// 3 protected virtual MapRemoveResult OnMapRemove(string key, string value) { @@ -1059,6 +1195,8 @@ namespace Tizen.Applications.DataControl /// /// Overrides this method if you want to handle the behavior when the bulk add request is received. /// + /// The bulk add data. + /// The result of bulk add operation. /// 3 protected virtual MapBulkAddResult OnMapBulkAdd(BulkData bulkAddData) { @@ -1069,6 +1207,8 @@ namespace Tizen.Applications.DataControl /// /// Overrides this method if you want to handle the behavior when the data change listen request is received. /// + /// The app ID sent data change listen request. + /// The result of data change listen operation. /// 3 protected virtual DataChangeListenResult OnDataChangeListenRequest(string requestAppID) { @@ -1088,10 +1228,6 @@ namespace Tizen.Applications.DataControl Stop(); _disposed = true; } - if (disposing) - { - GC.SuppressFinalize(this); - } } /// @@ -1101,6 +1237,7 @@ namespace Tizen.Applications.DataControl public void Dispose() { Dispose(true); + GC.SuppressFinalize(this); } } } -- 2.7.4