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 the Provider class for the DataControl provider application.
29 /// <since_tizen> 3 </since_tizen>
30 public abstract class Provider : IDisposable
32 private const string LogTag = "Tizen.Applications.DataControl";
33 private static IDictionary<string, Provider> _providerDict = new Dictionary<string, Provider>();
34 private static Interop.DataControl.SqlRequestCallbacks _sqlRequestCallbacks;
35 private static Interop.DataControl.MapRequestCallbacks _mapRequestCallbacks;
36 private IntPtr _nativeHandle;
37 private static Interop.DataControl.DataChangeConsumerFilterCb _filterCallback;
38 private static int _filterCallbackID;
39 private static bool _filterRegistered;
40 private static Interop.DataControl.SqlBulkInsertRequestCallback _sqlBulkCallback;
41 private static Interop.DataControl.MapBulkAddRequestCallback _mapBulkCallback;
42 private static Mutex _lock = new Mutex();
43 private bool _disposed = false;
44 private bool _isRunning = false;
49 /// <since_tizen> 3 </since_tizen>
56 private static bool DataChangeListenFilter(IntPtr handlePtr, string consumerAppid, IntPtr userData)
59 DataChangeListenResult result;
61 provider = GetProvider(handlePtr);
64 Log.Error(LogTag, "Provider not exist ");
68 result = provider.OnDataChangeListenRequest(consumerAppid);
69 if (result == null || result.Result != ResultType.Success)
79 private enum OperationType : short
87 private static string CreateSelectQuery(IntPtr handlePtr, string[] columnList, int columnCount, string where, string order, int pageNum, int countPerPage)
89 Interop.DataControl.SafeDataControlHandle handle = new Interop.DataControl.SafeDataControlHandle(handlePtr, false);
90 string query = "SELECT";
92 if (columnList == null)
98 for (int i = 0; i < columnCount; i++)
105 query += " " + columnList[i];
109 Interop.DataControl.DataControlGetDataId(handle, out dataId);
110 query += " FROM " + dataId;
113 query += " WHERE " + where;
118 query += " ORDER BY " + order;
123 query += " LIMIT " + countPerPage + " OFFSET " + (countPerPage * (pageNum - 1));
129 private static void InsertRequest(int requestId, IntPtr handlePtr, IntPtr insertData, IntPtr userData)
133 SafeBundleHandle sbh = new SafeBundleHandle(insertData, false);
134 string query = GetQuery(handlePtr, sbh, null, OperationType.Update);
137 provider = GetProvider(handlePtr);
138 if (provider == null)
140 Log.Error(LogTag, "Provider not exist ");
144 result = provider.OnInsert(query, new Bundle(sbh));
149 ret = Interop.DataControl.SendInsertResult(requestId, result.RowID);
150 if (ret != ResultType.Success)
152 Log.Error(LogTag, "SendInsertResult fail " + ret.ToString());
157 ret = Interop.DataControl.SendError(requestId, result.Result.ToString());
158 if (ret != ResultType.Success)
160 Log.Error(LogTag, "SendError fail " + ret.ToString());
166 Log.Info(LogTag, $"InsertResult is null : {requestId.ToString()}");
170 private static void BulkInsertRequest(int requestId, IntPtr handlePtr, IntPtr bulk_data, IntPtr userData)
173 BulkInsertResult result;
174 BulkData bulkData = new BulkData(new Interop.DataControl.SafeBulkDataHandle(bulk_data, false));
175 Interop.DataControl.SafeBulkDataHandle sbdh = bulkData.SafeBulkDataHandle;
179 int count = bulkData.GetCount();
180 List<string> queryList = new List<string>();
182 for (int i = 0; i < count; i++)
184 Interop.DataControl.BulkGetData(sbdh, i, out bundleHandel);
185 queryList.Add(GetQuery(handlePtr, new SafeBundleHandle(bundleHandel, false), null, OperationType.Insert));
188 provider = GetProvider(handlePtr);
189 if (provider == null)
191 Log.Error(LogTag, "Provider not exist ");
195 result = provider.OnBulkInsert(queryList, bulkData);
200 ret = Interop.DataControl.SendBulkInsertResult(requestId, result.BulkResultData.SafeBulkDataHandle);
201 if (ret != ResultType.Success)
203 Log.Error(LogTag, "SendBulkInsertResult fail " + ret.ToString());
208 ret = Interop.DataControl.SendError(requestId, result.Result.ToString());
209 if (ret != ResultType.Success)
211 Log.Error(LogTag, "SendError fail " + ret.ToString());
215 if (result.BulkResultData != null)
217 result.BulkResultData.Dispose();
222 Log.Info(LogTag, $"BulkInsertResult is null : {requestId.ToString()}");
226 private static void SendNativeProtocol(int socketFd, ICursor cursor, int requestId)
229 int DATACONTROL_RESULT_NO_DATA = -1;
230 int COLUMN_TYPE_NULL = 5;
231 int column_count, i, rowcount, size = 0, total_len_of_column_names = 0;
232 byte[] type_array, length_array, string_array, int_tmp, value_array = null;
237 if (cursor.Reset() == false)
239 Log.Error(LogTag, "Reset is failed : " + requestId.ToString());
243 if (cursor.GetRowCount() <= 0)
245 Log.Error(LogTag, "The DB does not have another row : " + requestId.ToString());
246 int_tmp = BitConverter.GetBytes(DATACONTROL_RESULT_NO_DATA);
247 result = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, int_tmp, int_tmp.Length, out write_len);
251 /* 1. column count */
252 column_count = cursor.GetColumnCount();
253 int_tmp = BitConverter.GetBytes(column_count);
254 result = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, int_tmp, int_tmp.Length, out write_len);
255 if (result != ResultType.Success)
257 Log.Error(LogTag, "Writing a column_count to a file descriptor is failed.");
261 Log.Info(LogTag, "Writing a column_count " + column_count.ToString());
263 /* 2.column type x column_count */
264 for (i = 0; i < column_count; i++)
266 type_array = BitConverter.GetBytes((int)cursor.GetColumnType(i));
267 result = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, type_array, type_array.Length, out write_len);
268 if (result != ResultType.Success)
270 Log.Error(LogTag, "Writing a type to a file descriptor is failed.");
274 Log.Info(LogTag, "Writing a column_type " + cursor.GetColumnType(i).ToString());
277 /* 3. column name x column_count */
278 for (i = 0; i < column_count; i++)
280 Log.Info(LogTag, "Writing a name " + cursor.GetColumnName(i));
282 total_len_of_column_names += cursor.GetColumnName(i).Length;
283 string_array = Encoding.UTF8.GetBytes(cursor.GetColumnName(i));
284 value_array = new byte[string_array.Length + 1];/*insert null */
285 string_array.CopyTo(value_array, 0);
286 length_array = BitConverter.GetBytes(value_array.Length);
288 result = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, length_array, length_array.Length, out write_len);
289 if (result != ResultType.Success)
291 Log.Error(LogTag, "Writing a type to a file descriptor is failed.");
295 result = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, value_array, value_array.Length, out write_len);
296 if (result != ResultType.Success)
298 Log.Error(LogTag, "Writing a type to a file descriptor is failed.");
304 /* 4. total length of column names */
305 length_array = BitConverter.GetBytes(total_len_of_column_names);
306 result = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, length_array, length_array.Length, out write_len);
307 if (result != ResultType.Success)
309 Log.Error(LogTag, "Writing a total_len_of_column_names to a file descriptor is failed");
313 Log.Info(LogTag, "Writing total length of column namese " + total_len_of_column_names.ToString());
316 length_array = BitConverter.GetBytes(cursor.GetRowCount());
317 Log.Error(LogTag, "=========================== select rowcount " + cursor.GetRowCount().ToString());
318 result = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, length_array, length_array.Length, out write_len);
319 if (result != ResultType.Success)
321 Log.Error(LogTag, "Writing a row count to a file descriptor is failed");
325 Log.Error(LogTag, "Writing a row count " + cursor.GetRowCount().ToString());
330 ms = new MemoryStream();
332 for (i = 0; i < column_count; i++)
334 type_array = BitConverter.GetBytes((int)cursor.GetColumnType(i));
335 switch (cursor.GetColumnType(i))
337 case ColumnType.ColumnTypeInt:
338 value_array = BitConverter.GetBytes(cursor.GetInt64Value(i));
339 size = value_array.Length;
342 case ColumnType.ColumnTypeDouble:
343 value_array = BitConverter.GetBytes(cursor.GetDoubleValue(i));
344 size = value_array.Length;
347 case ColumnType.ColumnTypeString:
348 txt = cursor.GetStringValue(i);
351 type_array = BitConverter.GetBytes(COLUMN_TYPE_NULL);
356 string_array = Encoding.UTF8.GetBytes(txt);
357 value_array = new byte[string_array.Length + 1];/*insert null */
358 string_array.CopyTo(value_array, 0);
359 size = value_array.Length;
362 case ColumnType.ColumnTypeBlob:
363 int_tmp = cursor.GetBlobValue(i);
366 type_array = BitConverter.GetBytes(COLUMN_TYPE_NULL);
371 value_array = int_tmp;
372 size = value_array.Length;
376 ms.Write(type_array, 0, type_array.Length);
378 length_array = BitConverter.GetBytes(size);
379 ms.Write(length_array, 0, length_array.Length);
382 ms.Write(value_array, 0, value_array.Length);
386 value_array = ms.ToArray();
388 result = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, value_array, value_array.Length, out write_len);
389 if (result != ResultType.Success)
391 Log.Error(LogTag, "Writing a row to a file descriptor is failed");
397 Log.Info(LogTag, "row_count ~~~~ ", rowcount.ToString());
400 while (cursor.Next());
403 private static void SelectRequest(int requestId,
404 IntPtr handlePtr, IntPtr columnList, int columnCount, string where, string order, IntPtr userData)
409 int countPerPage = 0;
410 int MAX_WRITE_SIZE = 1024; /* 1kbyte */
412 int socketFd, write_size, i;
415 string[] _columnList = new string[columnCount];
420 byte** _sbyte_columnList = (byte**)columnList;
422 for (i = 0; i < columnCount; i++)
424 _columnList[i] = Marshal.PtrToStringAnsi((IntPtr)_sbyte_columnList[i]);
428 Interop.DataControl.GetSelectPageInfo(requestId, out pageNum, out countPerPage);
429 query = CreateSelectQuery(handlePtr, _columnList, _columnList.Length, where, order, pageNum, countPerPage);
430 provider = GetProvider(handlePtr);
431 if (provider == null)
433 Log.Error(LogTag, "Provider not exist ");
437 result = provider.OnSelect(query, where, _columnList, _columnList.Length, order, pageNum, countPerPage);
442 Interop.DataControl.SendSelectResult(requestId, out socketFd);
444 MatrixCursor mc = result.ResultCursor as MatrixCursor;
448 SendNativeProtocol(socketFd, result.ResultCursor, requestId);
452 FileStream fs = mc.GetFileStream();
453 fs.Seek(0, SeekOrigin.Begin);
455 buffer = new byte[MAX_WRITE_SIZE];
459 write_size = fs.Read(buffer, 0, MAX_WRITE_SIZE);
463 ret = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, buffer, write_size, out write_len);
464 if (ret != ResultType.Success)
466 Log.Error(LogTag, "Writing a row to a file descriptor is failed");
472 while (write_size > 0);
479 ret = Interop.DataControl.SendError(requestId, result.Result.ToString());
480 if (ret != ResultType.Success)
482 Log.Error(LogTag, "SendError fail " + ret.ToString());
488 Log.Info(LogTag, $"SelectResult is null : {requestId.ToString()}");
492 private static void UpdateRequest(int requestId,
493 IntPtr handlePtr, IntPtr updateData, string where, IntPtr userData)
497 SafeBundleHandle sbh = new SafeBundleHandle(updateData, false);
498 string query = GetQuery(handlePtr, sbh, where, OperationType.Update);
501 provider = GetProvider(handlePtr);
502 if (provider == null)
504 Log.Error(LogTag, "Provider not exist ");
508 result = provider.OnUpdate(query, where, new Bundle(sbh));
513 ret = Interop.DataControl.SendUpdateResult(requestId);
514 if (ret != ResultType.Success)
516 Log.Error(LogTag, "SendUpdateResult fail " + ret.ToString());
521 ret = Interop.DataControl.SendError(requestId, result.Result.ToString());
522 if (ret != ResultType.Success)
524 Log.Error(LogTag, "SendError fail " + ret.ToString());
530 Log.Info(LogTag, $"UpdateResult is null : {requestId.ToString()}");
534 private static void DeleteRequest(int requestId,
535 IntPtr handlePtr, string where, IntPtr userData)
539 string query = GetQuery(handlePtr, null, where, OperationType.Delete);
542 provider = GetProvider(handlePtr);
543 if (provider == null)
545 Log.Error(LogTag, "Provider not exist ");
549 result = provider.OnDelete(query, where);
554 ret = Interop.DataControl.SendDeleteResult(requestId);
555 if (ret != ResultType.Success)
557 Log.Error(LogTag, "SendDeleteResult fail " + ret.ToString());
563 ret = Interop.DataControl.SendError(requestId, result.Result.ToString());
564 if (ret != ResultType.Success)
566 Log.Error(LogTag, "SendError fail " + ret.ToString());
572 Log.Info(LogTag, $"DeleteResult is null : {requestId.ToString()}");
576 private static void MapAddRequest(int requestId, IntPtr handlePtr, string key, string value, IntPtr userData)
582 provider = GetProvider(handlePtr);
583 if (provider == null)
585 Log.Error(LogTag, "Provider not exist");
589 result = provider.OnMapAdd(key, value);
594 ret = Interop.DataControl.SendMapResult(requestId);
595 if (ret != ResultType.Success)
597 Log.Error(LogTag, "SendMapResult fail " + ret.ToString());
602 ret = Interop.DataControl.SendError(requestId, result.Result.ToString());
603 if (ret != ResultType.Success)
605 Log.Error(LogTag, "SendError fail " + ret.ToString());
611 Log.Info(LogTag, $"MapAddResult is null : {requestId.ToString()}");
615 private static void MapSetRequest(int requestId, IntPtr handlePtr, string key, string oldValue, string newValue, IntPtr userData)
621 provider = GetProvider(handlePtr);
622 if (provider == null)
624 Log.Error(LogTag, "Provider not exist");
628 result = provider.OnMapSet(key, oldValue, newValue);
633 ret = Interop.DataControl.SendMapResult(requestId);
634 if (ret != ResultType.Success)
636 Log.Error(LogTag, "SendMapResult fail " + ret.ToString());
641 ret = Interop.DataControl.SendError(requestId, result.Result.ToString());
642 if (ret != ResultType.Success)
644 Log.Error(LogTag, "SendError fail " + ret.ToString());
650 Log.Info(LogTag, $"MapSetResult is null : {requestId.ToString()}");
654 private static void MapRemoveRequest(int requestId, IntPtr handlePtr, string key, string value, IntPtr userData)
657 MapRemoveResult result;
660 provider = GetProvider(handlePtr);
661 if (provider == null)
663 Log.Error(LogTag, "Provider not exist");
667 result = provider.OnMapRemove(key, value);
672 ret = Interop.DataControl.SendMapResult(requestId);
673 if (ret != ResultType.Success)
675 Log.Error(LogTag, "SendMapResult fail " + ret.ToString());
681 ret = Interop.DataControl.SendError(requestId, result.Result.ToString());
682 if (ret != ResultType.Success)
684 Log.Error(LogTag, "SendError fail " + ret.ToString());
690 Log.Info(LogTag, $"MapRemoveRequest is null : {requestId.ToString()}");
694 private static void MapGetRequest(int requestID, IntPtr handlePtr, string key, IntPtr userData)
700 provider = GetProvider(handlePtr);
701 if (provider == null)
703 Log.Error(LogTag, "Provider not exist");
707 result = provider.OnMapGet(key);
713 if (result.ValueList != null)
714 valueCount = result.ValueList.Length;
715 ret = Interop.DataControl.SendMapGetResult(requestID, result.ValueList, valueCount);
716 if (ret != ResultType.Success)
718 Log.Error(LogTag, "SendMapGetResult fail " + ret.ToString());
724 ret = Interop.DataControl.SendError(requestID, result.Result.ToString());
725 if (ret != ResultType.Success)
727 Log.Error(LogTag, "SendError fail " + ret.ToString());
733 Log.Info(LogTag, $"MapRemoveRequest is null : {requestID.ToString()}");
737 private static void MapBulkAddRequest(int requestID, IntPtr handlePtr, IntPtr bulkDataPtr, IntPtr userData)
740 MapBulkAddResult result;
741 BulkData bulkData = new BulkData(new Interop.DataControl.SafeBulkDataHandle(bulkDataPtr, false));
742 Interop.DataControl.SafeBulkDataHandle sbdh = bulkData.SafeBulkDataHandle;
744 int count = bulkData.GetCount();
745 List<string> queryList = new List<string>();
748 for (int i = 0; i < count; i++)
750 Interop.DataControl.BulkGetData(sbdh, i, out bundleHandel);
751 queryList.Add(GetQuery(handlePtr, new SafeBundleHandle(bundleHandel, false), null, OperationType.Insert));
754 provider = GetProvider(handlePtr);
755 if (provider == null)
757 Log.Error(LogTag, "Provider not exist");
761 result = provider.OnMapBulkAdd(bulkData);
766 ret = Interop.DataControl.SendMapBulkAddResult(requestID, result.BulkResultData.SafeBulkDataHandle);
767 if (ret != ResultType.Success)
769 Log.Error(LogTag, "SendMapBulkAddResult fail " + ret.ToString());
774 ret = Interop.DataControl.SendError(requestID, result.Result.ToString());
775 if (ret != ResultType.Success)
777 Log.Error(LogTag, "SendError fail " + ret.ToString());
781 if (result.BulkResultData != null)
783 result.BulkResultData.Dispose();
788 Log.Info(LogTag, $"MapBulkAddRequest is null : {requestID.ToString()}");
792 private static string GetQuery(IntPtr handlePtr, SafeBundleHandle data, string where, OperationType type)
794 Interop.DataControl.SafeDataControlHandle handle = new Interop.DataControl.SafeDataControlHandle(handlePtr, false);
799 case OperationType.Select:
801 case OperationType.Update:
802 query = Interop.DataControl.CreateUpdateStatement(handle, data, where);
804 case OperationType.Delete:
805 query = Interop.DataControl.CreateDeleteStatement(handle, where);
807 case OperationType.Insert:
808 query = Interop.DataControl.CreateInsertStatement(handle, data);
818 private static Provider GetProvider(IntPtr handlePtr)
820 Interop.DataControl.SafeDataControlHandle handle = new Interop.DataControl.SafeDataControlHandle(handlePtr, false);
821 Provider provider = null;
824 Interop.DataControl.DataControlGetDataId(handle, out dataID);
825 if (dataID != null && _providerDict.ContainsKey(dataID))
827 provider = _providerDict[dataID];
828 provider._nativeHandle = handlePtr;
829 Log.Info(LogTag, "DataID :" + dataID + ", hash code : " + provider.GetHashCode().ToString());
837 /// Sends a data change notification to consumer applications which have successfully added a data change listen.
839 /// <param name="type">The changed data type.</param>
840 /// <param name="changedData">Customized information about the changed data.</param>
841 /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
842 /// <exception cref="UnauthorizedAccessException">Thrown in case a permission is denied.</exception>
843 /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
844 /// <privilege>http://tizen.org/privilege/datasharing</privilege>
845 /// <since_tizen> 3 </since_tizen>
846 public void SendDataChange(ChangeType type, Bundle changedData)
850 if (changedData == null || changedData.SafeBundleHandle.IsInvalid)
852 ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "changedData");
855 if (this._nativeHandle == IntPtr.Zero)
860 ret = Interop.DataControl.SendDataChange(this._nativeHandle, type, changedData.SafeBundleHandle);
861 if (ret != ResultType.Success)
863 ErrorFactory.ThrowException(ret, false);
868 /// Initializes the Provider class with the dataID.
870 /// <param name="dataID">The DataControl Data ID.</param>
871 /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
872 /// <since_tizen> 3 </since_tizen>
873 public Provider(string dataID)
875 if (string.IsNullOrEmpty(dataID))
877 ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "dataID");
884 /// Starts the Provider service.
886 /// <remarks>Only one Provider service can be run for each process.</remarks>
887 /// <exception cref="UnauthorizedAccessException">Thrown in case a permission is denied.</exception>
888 /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
889 /// <privilege>http://tizen.org/privilege/datasharing</privilege>
890 /// <since_tizen> 3 </since_tizen>
895 if (_providerDict.ContainsKey(DataID))
897 _lock.ReleaseMutex();
898 ErrorFactory.ThrowException((ResultType)1, true, "The provider is already running");
902 if (_providerDict.Count == 0)
904 Log.Debug(LogTag, "Provider create");
906 _sqlRequestCallbacks.Insert = new Interop.DataControl.SqlInsertRequestCallback(InsertRequest);
907 _sqlRequestCallbacks.Select = new Interop.DataControl.SqlSelectRequestCallback(SelectRequest);
908 _sqlRequestCallbacks.Update = new Interop.DataControl.SqlUpdateRequestCallback(UpdateRequest);
909 _sqlRequestCallbacks.Delete = new Interop.DataControl.SqlDeleteRequestCallback(DeleteRequest);
911 ret = Interop.DataControl.RegisterSqlRequest(ref _sqlRequestCallbacks, IntPtr.Zero);
912 if (ret != ResultType.Success)
914 _lock.ReleaseMutex();
915 ErrorFactory.ThrowException(ret, false);
918 _sqlBulkCallback = new Interop.DataControl.SqlBulkInsertRequestCallback(BulkInsertRequest);
919 ret = Interop.DataControl.RegisterSqlBulkRequest(_sqlBulkCallback, IntPtr.Zero);
920 if (ret != ResultType.Success)
922 _lock.ReleaseMutex();
923 ErrorFactory.ThrowException(ret, false);
926 _mapRequestCallbacks.Add = new Interop.DataControl.MapAddRequestCallback(MapAddRequest);
927 _mapRequestCallbacks.Remove = new Interop.DataControl.MapRemoveRequestCallback(MapRemoveRequest);
928 _mapRequestCallbacks.Set = new Interop.DataControl.MapSetRequestCallback(MapSetRequest);
929 _mapRequestCallbacks.Get = new Interop.DataControl.MapGetRequestCallback(MapGetRequest);
930 ret = Interop.DataControl.RegisterMapRequest(ref _mapRequestCallbacks, IntPtr.Zero);
931 if (ret != ResultType.Success)
933 _lock.ReleaseMutex();
934 ErrorFactory.ThrowException(ret, false);
937 _mapBulkCallback = new Interop.DataControl.MapBulkAddRequestCallback(MapBulkAddRequest);
938 ret = Interop.DataControl.RegisterMapBulkRequest(_mapBulkCallback, IntPtr.Zero);
939 if (ret != ResultType.Success)
941 _lock.ReleaseMutex();
942 ErrorFactory.ThrowException(ret, false);
945 if (_filterRegistered == false)
947 if (_filterCallback == null)
948 _filterCallback = new Interop.DataControl.DataChangeConsumerFilterCb(DataChangeListenFilter);
950 ret = Interop.DataControl.AddDataChangeConsumerFilterCallback(
952 IntPtr.Zero, out _filterCallbackID);
954 if (ret != ResultType.Success)
956 _lock.ReleaseMutex();
957 ErrorFactory.ThrowException(ret, false);
961 _filterRegistered = true;
964 _providerDict.Add(DataID, this);
965 Log.Info(LogTag, "DataID :" + DataID + ", hash code : " + this.GetHashCode().ToString());
967 _lock.ReleaseMutex();
971 /// Stops the Provider service.
973 /// <since_tizen> 3 </since_tizen>
976 if (_isRunning == true)
978 Log.Info(LogTag, "DataID :" + DataID);
980 _providerDict.Remove(DataID);
985 /// Destructor of the Provider class.
993 /// Overrides this method if you want to handle the behavior when the select request is received.
995 /// <since_tizen> 3 </since_tizen>
996 protected abstract SelectResult OnSelect(string query, string where, string[] columList, int columnCount, string order, int pageNum, int countPerPage);
999 /// Overrides this method if you want to handle the behavior when the insert request is received.
1001 /// <since_tizen> 3 </since_tizen>
1002 protected abstract InsertResult OnInsert(string query, Bundle insertData);
1005 /// Overrides this method if you want to handle the behavior when the update request is received.
1007 /// <since_tizen> 3 </since_tizen>
1008 protected abstract UpdateResult OnUpdate(string query, string where, Bundle updateData);
1011 /// Overrides this method if you want to handle the behavior when the delete request is received.
1013 /// <since_tizen> 3 </since_tizen>
1014 protected abstract DeleteResult OnDelete(string query, string where);
1017 /// Overrides this method if you want to handle the behavior when the bulk insert request is received.
1019 /// <since_tizen> 3 </since_tizen>
1020 protected virtual BulkInsertResult OnBulkInsert(IEnumerable<string> query, BulkData bulkInsertData)
1022 Log.Info(LogTag, "The OnBulkInsert is not implemented.");
1027 /// Overrides this method if you want to handle the behavior when the map get request is received.
1029 /// <since_tizen> 3 </since_tizen>
1030 protected virtual MapGetResult OnMapGet(string key)
1032 Log.Info(LogTag, "The OnMapGet is not implemented.");
1037 /// Overrides this method if you want to handle the behavior when the map add request is received.
1039 /// <since_tizen> 3 </since_tizen>
1040 protected virtual MapAddResult OnMapAdd(string key, string value)
1042 Log.Info(LogTag, "The OnMapAdd is not implemented.");
1047 /// Overrides this method if you want to handle the behavior when the update request is received.
1049 /// <since_tizen> 3 </since_tizen>
1050 protected virtual MapSetResult OnMapSet(string key, string oldValue, string newValue)
1052 Log.Info(LogTag, "The OnMapSet is not implemented.");
1057 /// Overrides this method if you want to handle the behavior when the delete request is received.
1059 /// <since_tizen> 3 </since_tizen>
1060 protected virtual MapRemoveResult OnMapRemove(string key, string value)
1062 Log.Info(LogTag, "The OnMapRemove is not implemented.");
1067 /// Overrides this method if you want to handle the behavior when the bulk add request is received.
1069 /// <since_tizen> 3 </since_tizen>
1070 protected virtual MapBulkAddResult OnMapBulkAdd(BulkData bulkAddData)
1072 Log.Info(LogTag, "The OnMapBulkAdd is not implemented.");
1077 /// Overrides this method if you want to handle the behavior when the data change listen request is received.
1079 /// <since_tizen> 3 </since_tizen>
1080 protected virtual DataChangeListenResult OnDataChangeListenRequest(string requestAppID)
1082 Log.Info(LogTag, "The OnDataChangeListenRequest is not implemented.");
1087 /// Releases unmanaged resources used by the Provider class specifying whether to perform a normal dispose operation.
1089 /// <param name="disposing">true for a normal dispose operation; false to finalize the handle.</param>
1090 /// <since_tizen> 3 </since_tizen>
1091 protected virtual void Dispose(bool disposing)
1100 GC.SuppressFinalize(this);
1105 /// Releases all the resources used by the Provider class.
1107 /// <since_tizen> 3 </since_tizen>
1108 public void Dispose()