private const string LogTag = "Tizen.Applications.DataControl";
private bool _disposed = false;
private static Mutex _lock = new Mutex();
+ private static Mutex _requestLock = new Mutex();
private Interop.DataControl.DataChangeCallback _dataChangeCallback;
private Interop.DataControl.AddCallbackResultCallback _addCallbackResultCallback;
private static void InsertResponse(int reqId, IntPtr provider, long insertedRowId, bool providerResult, string error, IntPtr userData)
{
Log.Debug(LogTag, $"InsertResponse {reqId.ToString()}");
- if (!_reqConsumerDictionary.ContainsKey(reqId))
+ Consumer consumer = null;
+ if (!UnregisterReqId(reqId, ref consumer))
{
- Log.Error(LogTag, $"Invalid reqId {reqId.ToString()}");
return;
}
Log.Error(LogTag, $"reqId {reqId.ToString()}, error : {error}, rowID : {insertedRowId.ToString()}");
}
- Consumer consumer = _reqConsumerDictionary[reqId];
consumer.OnInsertResult(new InsertResult(insertedRowId, providerResult));
- _reqConsumerDictionary.Remove(reqId);
}
private static void BulkInsertResponse(int reqId, IntPtr provider, IntPtr bulkResults, bool providerResult, string error, IntPtr userData)
{
- BulkResultData brd;
Log.Debug(LogTag, $"BulkInsertResponse {reqId.ToString()}");
- if (!_reqConsumerDictionary.ContainsKey(reqId))
+
+ BulkResultData brd;
+ Consumer consumer = null;
+ if (!UnregisterReqId(reqId, ref consumer))
{
- Log.Error(LogTag, $"Invalid reqId {reqId.ToString()}");
return;
}
Log.Error(LogTag, $"reqId {reqId.ToString()}, bulkResults is null");
}
- Consumer consumer = _reqConsumerDictionary[reqId];
consumer.OnBulkInsertResult(new BulkInsertResult(brd, providerResult));
- _reqConsumerDictionary.Remove(reqId);
}
private static void SelectResponse(int reqId, IntPtr provider, IntPtr cursor, bool providerResult, string error, IntPtr userData)
{
- MatrixCursor dmc;
Log.Debug(LogTag, $"SelectResponse {reqId.ToString()}");
- if (!_reqConsumerDictionary.ContainsKey(reqId))
+
+ MatrixCursor dmc;
+ Consumer consumer = null;
+ if (!UnregisterReqId(reqId, ref consumer))
{
- Log.Error(LogTag, $"Invalid reqId {reqId.ToString()}");
return;
}
dmc = new MatrixCursor();
Log.Error(LogTag, $"reqId {reqId.ToString()}, cursor is null");
}
- Consumer consumer = _reqConsumerDictionary[reqId];
+
consumer.OnSelectResult(new SelectResult(dmc, providerResult));
- _reqConsumerDictionary.Remove(reqId);
}
private static void UpdateResponse(int reqId, IntPtr provider, bool providerResult, string error, IntPtr userData)
{
- if (!_reqConsumerDictionary.ContainsKey(reqId))
+ Consumer consumer = null;
+ if (!UnregisterReqId(reqId, ref consumer))
{
- Log.Error(LogTag, $"Invalid reqId {reqId.ToString()}");
return;
}
Log.Error(LogTag, $"reqId {reqId.ToString()}, error : {error}");
}
- Consumer consumer = _reqConsumerDictionary[reqId];
consumer.OnUpdateResult(new UpdateResult(providerResult));
- _reqConsumerDictionary.Remove(reqId);
}
private static void DeleteResponse(int reqId, IntPtr provider, bool providerResult, string error, IntPtr userData)
{
- if (!_reqConsumerDictionary.ContainsKey(reqId))
+ Consumer consumer = null;
+ if (!UnregisterReqId(reqId, ref consumer))
{
- Log.Error(LogTag, $"Invalid reqId {reqId.ToString()}");
return;
}
Log.Error(LogTag, $"reqId {reqId.ToString()}, error : {error}");
}
- Consumer consumer = _reqConsumerDictionary[reqId];
consumer.OnDeleteResult(new DeleteResult(providerResult));
- _reqConsumerDictionary.Remove(reqId);
}
static void IntPtrToStringArray(IntPtr unmanagedArray, int size, out string[] managedArray)
private static void MapGetResponse(int reqId, IntPtr provider, IntPtr valueList, int valueCount, bool providerResult, string error, IntPtr userData)
{
- MapGetResult mgr;
Log.Debug(LogTag, $"MapGetResponse {reqId.ToString()}");
- if (!_reqConsumerDictionary.ContainsKey(reqId))
+
+ MapGetResult mgr;
+ Consumer consumer = null;
+ if (!UnregisterReqId(reqId, ref consumer))
{
- Log.Error(LogTag, $"Invalid reqId {reqId.ToString()}");
return;
}
Log.Error(LogTag, $"reqId {reqId.ToString()}, valueList is null");
}
- Consumer consumer = _reqConsumerDictionary[reqId];
consumer.OnMapGetResult(mgr);
- _reqConsumerDictionary.Remove(reqId);
}
private static void MapBulkAddResponse(int reqId, IntPtr provider, IntPtr bulkResults, bool providerResult, string error, IntPtr userData)
{
- BulkResultData brd;
Log.Debug(LogTag, $"MapBulkAddResponse {reqId.ToString()}");
- if (!_reqConsumerDictionary.ContainsKey(reqId))
+
+ BulkResultData brd;
+ Consumer consumer = null;
+ if (!UnregisterReqId(reqId, ref consumer))
{
- Log.Error(LogTag, $"Invalid reqId {reqId.ToString()}");
return;
}
Log.Error(LogTag, $"reqId {reqId.ToString()}, bulkResults is null");
}
- Consumer consumer = _reqConsumerDictionary[reqId];
consumer.OnMapBulkAddResult(new MapBulkAddResult(brd, providerResult));
- _reqConsumerDictionary.Remove(reqId);
}
private static void MapAddResponse(int reqId, IntPtr provider, bool providerResult, string error, IntPtr userData)
{
Log.Debug(LogTag, $"MapAddResponse {reqId.ToString()}");
- if (!_reqConsumerDictionary.ContainsKey(reqId))
+
+ Consumer consumer = null;
+ if (!UnregisterReqId(reqId, ref consumer))
{
- Log.Error(LogTag, $"Invalid reqId {reqId.ToString()}");
return;
}
Log.Error(LogTag, $"reqId {reqId.ToString()}, error : {error}");
}
- Consumer consumer = _reqConsumerDictionary[reqId];
consumer.OnMapAddResult(new MapAddResult(providerResult));
- _reqConsumerDictionary.Remove(reqId);
}
private static void MapSetResponse(int reqId, IntPtr provider, bool providerResult, string error, IntPtr userData)
{
Log.Debug(LogTag, $"MapSetResponse {reqId.ToString()}");
- if (!_reqConsumerDictionary.ContainsKey(reqId))
+
+ Consumer consumer = null;
+ if (!UnregisterReqId(reqId, ref consumer))
{
- Log.Error(LogTag, $"Invalid reqId {reqId.ToString()}");
return;
}
Log.Error(LogTag, $"reqId {reqId.ToString()}, error : {error}");
}
- Consumer consumer = _reqConsumerDictionary[reqId];
consumer.OnMapSetResult(new MapSetResult(providerResult));
- _reqConsumerDictionary.Remove(reqId);
}
private static void MapRemoveResponse(int reqId, IntPtr provider, bool providerResult, string error, IntPtr userData)
{
- if (!_reqConsumerDictionary.ContainsKey(reqId))
+ Consumer consumer = null;
+ if (!UnregisterReqId(reqId, ref consumer))
{
- Log.Error(LogTag, $"Invalid reqId {reqId.ToString()}");
return;
}
Log.Error(LogTag, $"reqId {reqId.ToString()}, error : {error}");
}
- Consumer consumer = _reqConsumerDictionary[reqId];
consumer.OnMapRemoveResult(new MapRemoveResult(providerResult));
- _reqConsumerDictionary.Remove(reqId);
}
private static MatrixCursor CloneCursor(CloneCursorCore coreCursor)
internal static void RegisterReqId(int reqId, Consumer consumer)
{
- _lock.WaitOne();
+ _requestLock.WaitOne();
_reqConsumerDictionary.Add(reqId, consumer);
- _lock.ReleaseMutex();
+ _requestLock.ReleaseMutex();
+ }
+
+ internal static bool UnregisterReqId(int reqId, ref Consumer consumer)
+ {
+ _requestLock.WaitOne();
+ if (!_reqConsumerDictionary.ContainsKey(reqId))
+ {
+ Log.Error(LogTag, $"Invalid reqId {reqId.ToString()}");
+ _requestLock.ReleaseMutex();
+ return false;
+ }
+
+ consumer = _reqConsumerDictionary[reqId];
+ _reqConsumerDictionary.Remove(reqId);
+ _requestLock.ReleaseMutex();
+ return true;
}
internal static void RegisterCallback(Interop.DataControl.SafeDataControlHandle handle, string providerId)