2 * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.Collections.Generic;
20 using Tizen.Applications.DataControl;
21 using System.Runtime.InteropServices;
22 using System.Threading;
24 namespace Tizen.Applications.DataControl
27 /// Represents Provider class for DataControl provider application.
29 public abstract class Provider : IDisposable
31 private const string LogTag = "Tizen.Applications.DataControl";
32 private static IDictionary<string, Provider> _providerDict = new Dictionary<string, Provider>();
33 private static Interop.DataControl.SqlRequestCallbacks _sqlRequestCallbacks;
34 private static Interop.DataControl.MapRequestCallbacks _mapRequestCallbacks;
35 private IntPtr _nativeHandle;
36 private static Interop.DataControl.DataChangeConsumerFilterCb _filterCallback;
37 private static int _filterCallbackID;
38 private static bool _filterRegistered;
39 private static Interop.DataControl.SqlBulkInsertRequestCallback _sqlBulkCallback;
40 private static Interop.DataControl.MapBulkAddRequestCallback _mapBulkCallback;
41 private static Mutex _lock = new Mutex();
42 private bool _disposed = false;
43 private bool _isRunning = false;
54 private static bool DataChangeListenFilter(IntPtr handlePtr, string consumerAppid, IntPtr userData)
57 DataChangeListenResult result;
59 provider = GetProvider(handlePtr);
62 Log.Error(LogTag, "Provider not exist ");
66 result = provider.OnDataChangeListenRequest(consumerAppid);
67 if (result == null || result.Result != ResultType.Success)
77 private enum OperationType : short
85 private static string CreateSelectQuery(IntPtr handlePtr, string[] columnList, int columnCount, string where, string order, int pageNum, int countPerPage)
87 Interop.DataControl.SafeDataControlHandle handle = new Interop.DataControl.SafeDataControlHandle(handlePtr, false);
88 string query = "SELECT";
90 if (columnList == null)
96 for (int i = 0; i < columnCount; i++)
103 query += " " + columnList[i];
107 Interop.DataControl.DataControlGetDataId(handle, out dataId);
108 query += " FROM " + dataId;
111 query += " WHERE " + where;
116 query += " ORDER BY " + order;
121 query += " LIMIT " + countPerPage + " OFFSET " + (countPerPage * (pageNum - 1));
127 private static void InsertRequest(int requestId, IntPtr handlePtr, IntPtr insertData, IntPtr userData)
131 SafeBundleHandle sbh = new SafeBundleHandle(insertData, false);
132 string query = GetQuery(handlePtr, sbh, null, OperationType.Update);
135 provider = GetProvider(handlePtr);
136 if (provider == null)
138 Log.Error(LogTag, "Provider not exist ");
142 result = provider.OnInsert(query, new Bundle(sbh));
147 ret = Interop.DataControl.SendInsertResult(requestId, result.RowID);
148 if (ret != ResultType.Success)
150 Log.Error(LogTag, "SendInsertResult fail " + ret.ToString());
155 ret = Interop.DataControl.SendError(requestId, result.Result.ToString());
156 if (ret != ResultType.Success)
158 Log.Error(LogTag, "SendError fail " + ret.ToString());
164 Log.Info(LogTag, $"InsertResult is null : {requestId.ToString()}");
168 private static void BulkInsertRequest(int requestId, IntPtr handlePtr, IntPtr bulk_data, IntPtr userData)
171 BulkInsertResult result;
172 BulkData bulkData = new BulkData(new Interop.DataControl.SafeBulkDataHandle(bulk_data, false));
173 Interop.DataControl.SafeBulkDataHandle sbdh = bulkData.SafeBulkDataHandle;
177 int count = bulkData.GetCount();
178 List<string> queryList = new List<string>();
180 for (int i = 0; i < count; i++)
182 Interop.DataControl.BulkGetData(sbdh, i, out bundleHandel);
183 queryList.Add(GetQuery(handlePtr, new SafeBundleHandle(bundleHandel, false), null, OperationType.Insert));
186 provider = GetProvider(handlePtr);
187 if (provider == null)
189 Log.Error(LogTag, "Provider not exist ");
193 result = provider.OnBulkInsert(queryList, bulkData);
198 ret = Interop.DataControl.SendBulkInsertResult(requestId, result.BulkResultData.SafeBulkDataHandle);
199 if (ret != ResultType.Success)
201 Log.Error(LogTag, "SendBulkInsertResult fail " + ret.ToString());
206 ret = Interop.DataControl.SendError(requestId, result.Result.ToString());
207 if (ret != ResultType.Success)
209 Log.Error(LogTag, "SendError fail " + ret.ToString());
213 if (result.BulkResultData != null)
215 result.BulkResultData.Dispose();
220 Log.Info(LogTag, $"BulkInsertResult is null : {requestId.ToString()}");
224 private static void SendNativeProtocol(int socketFd, ICursor cursor, int requestId)
227 int DATACONTROL_RESULT_NO_DATA = -1;
228 int COLUMN_TYPE_NULL = 5;
229 int column_count, i, rowcount, size = 0, total_len_of_column_names = 0;
230 byte[] type_array, length_array, string_array, int_tmp, value_array = null;
235 if (cursor.Reset() == false)
237 Log.Error(LogTag, "Reset is failed : " + requestId.ToString());
241 if (cursor.GetRowCount() <= 0)
243 Log.Error(LogTag, "The DB does not have another row : " + requestId.ToString());
244 int_tmp = BitConverter.GetBytes(DATACONTROL_RESULT_NO_DATA);
245 result = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, int_tmp, int_tmp.Length, out write_len);
249 /* 1. column count */
250 column_count = cursor.GetColumnCount();
251 int_tmp = BitConverter.GetBytes(column_count);
252 result = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, int_tmp, int_tmp.Length, out write_len);
253 if (result != ResultType.Success)
255 Log.Error(LogTag, "Writing a column_count to a file descriptor is failed.");
259 Log.Info(LogTag, "Writing a column_count " + column_count.ToString());
261 /* 2.column type x column_count */
262 for (i = 0; i < column_count; i++)
264 type_array = BitConverter.GetBytes((int)cursor.GetColumnType(i));
265 result = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, type_array, type_array.Length, out write_len);
266 if (result != ResultType.Success)
268 Log.Error(LogTag, "Writing a type to a file descriptor is failed.");
272 Log.Info(LogTag, "Writing a column_type " + cursor.GetColumnType(i).ToString());
275 /* 3. column name x column_count */
276 for (i = 0; i < column_count; i++)
278 Log.Info(LogTag, "Writing a name " + cursor.GetColumnName(i));
280 total_len_of_column_names += cursor.GetColumnName(i).Length;
281 string_array = Encoding.UTF8.GetBytes(cursor.GetColumnName(i));
282 value_array = new byte[string_array.Length + 1];/*insert null */
283 string_array.CopyTo(value_array, 0);
284 length_array = BitConverter.GetBytes(value_array.Length);
286 result = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, length_array, length_array.Length, out write_len);
287 if (result != ResultType.Success)
289 Log.Error(LogTag, "Writing a type to a file descriptor is failed.");
293 result = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, value_array, value_array.Length, out write_len);
294 if (result != ResultType.Success)
296 Log.Error(LogTag, "Writing a type to a file descriptor is failed.");
302 /* 4. total length of column names */
303 length_array = BitConverter.GetBytes(total_len_of_column_names);
304 result = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, length_array, length_array.Length, out write_len);
305 if (result != ResultType.Success)
307 Log.Error(LogTag, "Writing a total_len_of_column_names to a file descriptor is failed");
311 Log.Info(LogTag, "Writing total length of column namese " + total_len_of_column_names.ToString());
314 length_array = BitConverter.GetBytes(cursor.GetRowCount());
315 Log.Error(LogTag, "=========================== select rowcount " + cursor.GetRowCount().ToString());
316 result = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, length_array, length_array.Length, out write_len);
317 if (result != ResultType.Success)
319 Log.Error(LogTag, "Writing a row count to a file descriptor is failed");
323 Log.Error(LogTag, "Writing a row count " + cursor.GetRowCount().ToString());
328 ms = new MemoryStream();
330 for (i = 0; i < column_count; i++)
332 type_array = BitConverter.GetBytes((int)cursor.GetColumnType(i));
333 switch (cursor.GetColumnType(i))
335 case ColumnType.ColumnTypeInt:
336 value_array = BitConverter.GetBytes(cursor.GetInt64Value(i));
337 size = value_array.Length;
340 case ColumnType.ColumnTypeDouble:
341 value_array = BitConverter.GetBytes(cursor.GetDoubleValue(i));
342 size = value_array.Length;
345 case ColumnType.ColumnTypeString:
346 txt = cursor.GetStringValue(i);
349 type_array = BitConverter.GetBytes(COLUMN_TYPE_NULL);
354 string_array = Encoding.UTF8.GetBytes(txt);
355 value_array = new byte[string_array.Length + 1];/*insert null */
356 string_array.CopyTo(value_array, 0);
357 size = value_array.Length;
360 case ColumnType.ColumnTypeBlob:
361 int_tmp = cursor.GetBlobValue(i);
364 type_array = BitConverter.GetBytes(COLUMN_TYPE_NULL);
369 value_array = int_tmp;
370 size = value_array.Length;
374 ms.Write(type_array, 0, type_array.Length);
376 length_array = BitConverter.GetBytes(size);
377 ms.Write(length_array, 0, length_array.Length);
380 ms.Write(value_array, 0, value_array.Length);
384 value_array = ms.ToArray();
386 result = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, value_array, value_array.Length, out write_len);
387 if (result != ResultType.Success)
389 Log.Error(LogTag, "Writing a row to a file descriptor is failed");
395 Log.Info(LogTag, "row_count ~~~~ ", rowcount.ToString());
398 while (cursor.Next());
401 private static void SelectRequest(int requestId,
402 IntPtr handlePtr, IntPtr columnList, int columnCount, string where, string order, IntPtr userData)
407 int countPerPage = 0;
408 int MAX_WRITE_SIZE = 1024; /* 1kbyte */
410 int socketFd, write_size, i;
413 string[] _columnList = new string[columnCount];
418 byte** _sbyte_columnList = (byte**)columnList;
420 for (i = 0; i < columnCount; i++)
422 _columnList[i] = Marshal.PtrToStringAnsi((IntPtr)_sbyte_columnList[i]);
426 Interop.DataControl.GetSelectPageInfo(requestId, out pageNum, out countPerPage);
427 query = CreateSelectQuery(handlePtr, _columnList, _columnList.Length, where, order, pageNum, countPerPage);
428 provider = GetProvider(handlePtr);
429 if (provider == null)
431 Log.Error(LogTag, "Provider not exist ");
435 result = provider.OnSelect(query, where, _columnList, _columnList.Length, order, pageNum, countPerPage);
440 Interop.DataControl.SendSelectResult(requestId, out socketFd);
442 MatrixCursor mc = result.ResultCursor as MatrixCursor;
446 SendNativeProtocol(socketFd, result.ResultCursor, requestId);
450 FileStream fs = mc.GetFileStream();
451 fs.Seek(0, SeekOrigin.Begin);
453 buffer = new byte[MAX_WRITE_SIZE];
457 write_size = fs.Read(buffer, 0, MAX_WRITE_SIZE);
461 ret = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, buffer, write_size, out write_len);
462 if (ret != ResultType.Success)
464 Log.Error(LogTag, "Writing a row to a file descriptor is failed");
470 while (write_size > 0);
477 ret = Interop.DataControl.SendError(requestId, result.Result.ToString());
478 if (ret != ResultType.Success)
480 Log.Error(LogTag, "SendError fail " + ret.ToString());
486 Log.Info(LogTag, $"SelectResult is null : {requestId.ToString()}");
490 private static void UpdateRequest(int requestId,
491 IntPtr handlePtr, IntPtr updateData, string where, IntPtr userData)
495 SafeBundleHandle sbh = new SafeBundleHandle(updateData, false);
496 string query = GetQuery(handlePtr, sbh, where, OperationType.Update);
499 provider = GetProvider(handlePtr);
500 if (provider == null)
502 Log.Error(LogTag, "Provider not exist ");
506 result = provider.OnUpdate(query, where, new Bundle(sbh));
511 ret = Interop.DataControl.SendUpdateResult(requestId);
512 if (ret != ResultType.Success)
514 Log.Error(LogTag, "SendUpdateResult fail " + ret.ToString());
519 ret = Interop.DataControl.SendError(requestId, result.Result.ToString());
520 if (ret != ResultType.Success)
522 Log.Error(LogTag, "SendError fail " + ret.ToString());
528 Log.Info(LogTag, $"UpdateResult is null : {requestId.ToString()}");
532 private static void DeleteRequest(int requestId,
533 IntPtr handlePtr, string where, IntPtr userData)
537 string query = GetQuery(handlePtr, null, where, OperationType.Delete);
540 provider = GetProvider(handlePtr);
541 if (provider == null)
543 Log.Error(LogTag, "Provider not exist ");
547 result = provider.OnDelete(query, where);
552 ret = Interop.DataControl.SendDeleteResult(requestId);
553 if (ret != ResultType.Success)
555 Log.Error(LogTag, "SendDeleteResult fail " + ret.ToString());
561 ret = Interop.DataControl.SendError(requestId, result.Result.ToString());
562 if (ret != ResultType.Success)
564 Log.Error(LogTag, "SendError fail " + ret.ToString());
570 Log.Info(LogTag, $"DeleteResult is null : {requestId.ToString()}");
574 private static void MapAddRequest(int requestId, IntPtr handlePtr, string key, string value, IntPtr userData)
580 provider = GetProvider(handlePtr);
581 if (provider == null)
583 Log.Error(LogTag, "Provider not exist");
587 result = provider.OnMapAdd(key, value);
592 ret = Interop.DataControl.SendMapResult(requestId);
593 if (ret != ResultType.Success)
595 Log.Error(LogTag, "SendMapResult fail " + ret.ToString());
600 ret = Interop.DataControl.SendError(requestId, result.Result.ToString());
601 if (ret != ResultType.Success)
603 Log.Error(LogTag, "SendError fail " + ret.ToString());
609 Log.Info(LogTag, $"MapAddResult is null : {requestId.ToString()}");
613 private static void MapSetRequest(int requestId, IntPtr handlePtr, string key, string oldValue, string newValue, IntPtr userData)
619 provider = GetProvider(handlePtr);
620 if (provider == null)
622 Log.Error(LogTag, "Provider not exist");
626 result = provider.OnMapSet(key, oldValue, newValue);
631 ret = Interop.DataControl.SendMapResult(requestId);
632 if (ret != ResultType.Success)
634 Log.Error(LogTag, "SendMapResult fail " + ret.ToString());
639 ret = Interop.DataControl.SendError(requestId, result.Result.ToString());
640 if (ret != ResultType.Success)
642 Log.Error(LogTag, "SendError fail " + ret.ToString());
648 Log.Info(LogTag, $"MapSetResult is null : {requestId.ToString()}");
652 private static void MapRemoveRequest(int requestId, IntPtr handlePtr, string key, string value, IntPtr userData)
655 MapRemoveResult result;
658 provider = GetProvider(handlePtr);
659 if (provider == null)
661 Log.Error(LogTag, "Provider not exist");
665 result = provider.OnMapRemove(key, value);
670 ret = Interop.DataControl.SendMapResult(requestId);
671 if (ret != ResultType.Success)
673 Log.Error(LogTag, "SendMapResult fail " + ret.ToString());
679 ret = Interop.DataControl.SendError(requestId, result.Result.ToString());
680 if (ret != ResultType.Success)
682 Log.Error(LogTag, "SendError fail " + ret.ToString());
688 Log.Info(LogTag, $"MapRemoveRequest is null : {requestId.ToString()}");
692 private static void MapGetRequest(int requestID, IntPtr handlePtr, string key, IntPtr userData)
698 provider = GetProvider(handlePtr);
699 if (provider == null)
701 Log.Error(LogTag, "Provider not exist");
705 result = provider.OnMapGet(key);
711 if (result.ValueList != null)
712 valueCount = result.ValueList.Length;
713 ret = Interop.DataControl.SendMapGetResult(requestID, result.ValueList, valueCount);
714 if (ret != ResultType.Success)
716 Log.Error(LogTag, "SendMapGetResult fail " + ret.ToString());
722 ret = Interop.DataControl.SendError(requestID, result.Result.ToString());
723 if (ret != ResultType.Success)
725 Log.Error(LogTag, "SendError fail " + ret.ToString());
731 Log.Info(LogTag, $"MapRemoveRequest is null : {requestID.ToString()}");
735 private static void MapBulkAddRequest(int requestID, IntPtr handlePtr, IntPtr bulkDataPtr, IntPtr userData)
738 MapBulkAddResult result;
739 BulkData bulkData = new BulkData(new Interop.DataControl.SafeBulkDataHandle(bulkDataPtr, false));
740 Interop.DataControl.SafeBulkDataHandle sbdh = bulkData.SafeBulkDataHandle;
742 int count = bulkData.GetCount();
743 List<string> queryList = new List<string>();
746 for (int i = 0; i < count; i++)
748 Interop.DataControl.BulkGetData(sbdh, i, out bundleHandel);
749 queryList.Add(GetQuery(handlePtr, new SafeBundleHandle(bundleHandel, false), null, OperationType.Insert));
752 provider = GetProvider(handlePtr);
753 if (provider == null)
755 Log.Error(LogTag, "Provider not exist");
759 result = provider.OnMapBulkAdd(bulkData);
764 ret = Interop.DataControl.SendMapBulkAddResult(requestID, result.BulkResultData.SafeBulkDataHandle);
765 if (ret != ResultType.Success)
767 Log.Error(LogTag, "SendMapBulkAddResult fail " + ret.ToString());
772 ret = Interop.DataControl.SendError(requestID, result.Result.ToString());
773 if (ret != ResultType.Success)
775 Log.Error(LogTag, "SendError fail " + ret.ToString());
779 if (result.BulkResultData != null)
781 result.BulkResultData.Dispose();
786 Log.Info(LogTag, $"MapBulkAddRequest is null : {requestID.ToString()}");
790 private static string GetQuery(IntPtr handlePtr, SafeBundleHandle data, string where, OperationType type)
792 Interop.DataControl.SafeDataControlHandle handle = new Interop.DataControl.SafeDataControlHandle(handlePtr, false);
797 case OperationType.Select:
799 case OperationType.Update:
800 query = Interop.DataControl.CreateUpdateStatement(handle, data, where);
802 case OperationType.Delete:
803 query = Interop.DataControl.CreateDeleteStatement(handle, where);
805 case OperationType.Insert:
806 query = Interop.DataControl.CreateInsertStatement(handle, data);
816 private static Provider GetProvider(IntPtr handlePtr)
818 Interop.DataControl.SafeDataControlHandle handle = new Interop.DataControl.SafeDataControlHandle(handlePtr, false);
819 Provider provider = null;
822 Interop.DataControl.DataControlGetDataId(handle, out dataID);
823 if (dataID != null && _providerDict.ContainsKey(dataID))
825 provider = _providerDict[dataID];
826 provider._nativeHandle = handlePtr;
827 Log.Info(LogTag, "DataID :" + dataID + ", hash code : " + provider.GetHashCode().ToString());
835 /// Sends a data change notification to consumer applications which have successfully added a data change listen.
837 /// <param name="type">Changed data type</param>
838 /// <param name="changedData">Customized information about changed data</param>
839 /// <exception cref="ArgumentException">Thrown in case of Invalid parmaeter.</exception>
840 /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception>
841 /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
842 /// <privilege>http://tizen.org/privilege/datasharing</privilege>
843 public void SendDataChange(ChangeType type, Bundle changedData)
847 if (changedData == null || changedData.SafeBundleHandle.IsInvalid)
849 ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "changedData");
852 if (this._nativeHandle == IntPtr.Zero)
857 ret = Interop.DataControl.SendDataChange(this._nativeHandle, type, changedData.SafeBundleHandle);
858 if (ret != ResultType.Success)
860 ErrorFactory.ThrowException(ret, false);
865 /// Initializes Provider class with dataID.
867 /// <param name="dataID">DataControl Data ID</param>
868 /// <exception cref="ArgumentException">Thrown in case of Invalid parmaeter.</exception>
869 public Provider(string dataID)
871 if (string.IsNullOrEmpty(dataID))
873 ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "dataID");
880 /// Starts Provider service.
882 /// <remarks>Only one Provider service can be ran for each process</remarks>
883 /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception>
884 /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
885 /// <privilege>http://tizen.org/privilege/datasharing</privilege>
890 if (_providerDict.ContainsKey(DataID))
892 _lock.ReleaseMutex();
893 ErrorFactory.ThrowException((ResultType)1, true, "The provider is already running");
897 if (_providerDict.Count == 0)
899 Log.Debug(LogTag, "Provider create");
901 _sqlRequestCallbacks.Insert = new Interop.DataControl.SqlInsertRequestCallback(InsertRequest);
902 _sqlRequestCallbacks.Select = new Interop.DataControl.SqlSelectRequestCallback(SelectRequest);
903 _sqlRequestCallbacks.Update = new Interop.DataControl.SqlUpdateRequestCallback(UpdateRequest);
904 _sqlRequestCallbacks.Delete = new Interop.DataControl.SqlDeleteRequestCallback(DeleteRequest);
906 ret = Interop.DataControl.RegisterSqlRequest(ref _sqlRequestCallbacks, IntPtr.Zero);
907 if (ret != ResultType.Success)
909 _lock.ReleaseMutex();
910 ErrorFactory.ThrowException(ret, false);
913 _sqlBulkCallback = new Interop.DataControl.SqlBulkInsertRequestCallback(BulkInsertRequest);
914 ret = Interop.DataControl.RegisterSqlBulkRequest(_sqlBulkCallback, IntPtr.Zero);
915 if (ret != ResultType.Success)
917 _lock.ReleaseMutex();
918 ErrorFactory.ThrowException(ret, false);
921 _mapRequestCallbacks.Add = new Interop.DataControl.MapAddRequestCallback(MapAddRequest);
922 _mapRequestCallbacks.Remove = new Interop.DataControl.MapRemoveRequestCallback(MapRemoveRequest);
923 _mapRequestCallbacks.Set = new Interop.DataControl.MapSetRequestCallback(MapSetRequest);
924 _mapRequestCallbacks.Get = new Interop.DataControl.MapGetRequestCallback(MapGetRequest);
925 ret = Interop.DataControl.RegisterMapRequest(ref _mapRequestCallbacks, IntPtr.Zero);
926 if (ret != ResultType.Success)
928 _lock.ReleaseMutex();
929 ErrorFactory.ThrowException(ret, false);
932 _mapBulkCallback = new Interop.DataControl.MapBulkAddRequestCallback(MapBulkAddRequest);
933 ret = Interop.DataControl.RegisterMapBulkRequest(_mapBulkCallback, IntPtr.Zero);
934 if (ret != ResultType.Success)
936 _lock.ReleaseMutex();
937 ErrorFactory.ThrowException(ret, false);
940 if (_filterRegistered == false)
942 if (_filterCallback == null)
943 _filterCallback = new Interop.DataControl.DataChangeConsumerFilterCb(DataChangeListenFilter);
945 ret = Interop.DataControl.AddDataChangeConsumerFilterCallback(
947 IntPtr.Zero, out _filterCallbackID);
949 if (ret != ResultType.Success)
951 _lock.ReleaseMutex();
952 ErrorFactory.ThrowException(ret, false);
956 _filterRegistered = true;
959 _providerDict.Add(DataID, this);
960 Log.Info(LogTag, "DataID :" + DataID + ", hash code : " + this.GetHashCode().ToString());
962 _lock.ReleaseMutex();
966 /// Stop Provider service.
970 if (_isRunning == true)
972 Log.Info(LogTag, "DataID :" + DataID);
974 _providerDict.Remove(DataID);
984 /// Overrides this method if want to handle behavior when the select request is received.
986 protected abstract SelectResult OnSelect(string query, string where, string[] columList, int columnCount, string order, int pageNum, int countPerPage);
989 /// Overrides this method if want to handle behavior when the insert request is received.
991 protected abstract InsertResult OnInsert(string query, Bundle insertData);
994 /// Overrides this method if want to handle behavior when the update request is received.
996 protected abstract UpdateResult OnUpdate(string query, string where, Bundle updateData);
999 /// Overrides this method if want to handle behavior when the delete request is received.
1001 protected abstract DeleteResult OnDelete(string query, string where);
1004 /// Overrides this method if want to handle behavior when the bulk insert request is received.
1006 protected virtual BulkInsertResult OnBulkInsert(IEnumerable<string> query, BulkData bulkInsertData)
1008 Log.Info(LogTag, "The OnBulkInsert is not implemented.");
1013 /// Overrides this method if want to handle behavior when the map get request is received.
1015 protected virtual MapGetResult OnMapGet(string key)
1017 Log.Info(LogTag, "The OnMapGet is not implemented.");
1022 /// Overrides this method if want to handle behavior when the map add request is received.
1024 protected virtual MapAddResult OnMapAdd(string key, string value)
1026 Log.Info(LogTag, "The OnMapAdd is not implemented.");
1031 /// Overrides this method if want to handle behavior when the update request is received.
1033 protected virtual MapSetResult OnMapSet(string key, string oldValue, string newValue)
1035 Log.Info(LogTag, "The OnMapSet is not implemented.");
1040 /// Overrides this method if want to handle behavior when the delete request is received.
1042 protected virtual MapRemoveResult OnMapRemove(string key, string value)
1044 Log.Info(LogTag, "The OnMapRemove is not implemented.");
1049 /// Overrides this method if want to handle behavior when the bulk add request is received.
1051 protected virtual MapBulkAddResult OnMapBulkAdd(BulkData bulkAddData)
1053 Log.Info(LogTag, "The OnMapBulkAdd is not implemented.");
1058 /// Overrides this method if want to handle behavior when the data change listen request is received.
1060 protected virtual DataChangeListenResult OnDataChangeListenRequest(string requestAppID)
1062 Log.Info(LogTag, "The OnDataChangeListenRequest is not implemented.");
1067 /// Releases the unmanaged resourced used by the Provider class specifying whether to perform a normal dispose operation.
1069 /// <param name="disposing">true for a normal dispose operation; false to finalize the handle.</param>
1070 protected virtual void Dispose(bool disposing)
1079 GC.SuppressFinalize(this);
1084 /// Releases all resources used by the Provider class.
1086 public void Dispose()