namespace Tizen.Pims.Contacts
{
- /// <summary>
- /// Delegate for detecting the contacts database changes
- /// </summary>
- /// <param name="uri">The contacts view URI</param>
- /// <remarks>
- /// The delegate must be registered using AddDBChangedDelegate.
- /// It's invoked when the designated view changes.
- /// </remarks>
- public delegate void ContactsDBChanged(string uri);
/// <summary>
/// ContactsDatabase provides methods to manage contacts information from/to the database.
private Object thisLock = new Object();
private Interop.Database.ContactsDBStatusChangedCallback _contactsDBStatusChangedCallback;
private EventHandler<DBStatusChangedEventArgs> _dbStatusChanged;
- private Dictionary<string, ContactsDBChanged> _delegateMap = new Dictionary<string, ContactsDBChanged>();
+ private Dictionary<string, EventHandler<DBChangedEventArgs>> _delegateMap = new Dictionary<string, EventHandler<DBChangedEventArgs>>();
private Dictionary<string, Interop.Database.ContactsDBChangedCallback> _callbackMap = new Dictionary<string, Interop.Database.ContactsDBChangedCallback>();
private Interop.Database.ContactsDBChangedCallback _dbChangedDelegate;
/// Registers a callback function to be invoked when a record changes.
/// </summary>
/// <param name="viewUri">The view URI of records whose changes are monitored</param>
- /// <param name="callback">The callback function to register</param>
+ /// <param name="DBChanged">The EventHandler to register</param>
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
- public void AddDBChangedDelegate(string viewUri, ContactsDBChanged callback)
+ public void AddDBChangedDelegate(string viewUri, EventHandler<DBChangedEventArgs> DBChanged)
{
if (_callbackMap[viewUri] == null)
{
_callbackMap[viewUri] = (string uri, IntPtr userData) =>
{
- _delegateMap[uri](uri);
+ DBChangedEventArgs args = new DBChangedEventArgs(uri);
+ _delegateMap[uri]?.Invoke(this, args);
};
int error = Interop.Database.AddChangedCb(viewUri, _callbackMap[viewUri], IntPtr.Zero);
}
}
- _delegateMap[viewUri] += callback;
+ _delegateMap[viewUri] += DBChanged;
}
/// <summary>
/// Deregisters a callback function.
/// </summary>
/// <param name="viewUri">The view URI of records whose changes are monitored</param>
- /// <param name="callback">The callback function to register</param>
+ /// <param name="DBChanged">The EventHandler to deregister</param>
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
- public void RemoveDBChangedDelegate(string viewUri, ContactsDBChanged callback)
+ public void RemoveDBChangedDelegate(string viewUri, EventHandler<DBChangedEventArgs> DBChanged)
{
- _delegateMap[viewUri] -= callback;
+ _delegateMap[viewUri] -= DBChanged;
if (_delegateMap[viewUri] == null)
{
--- /dev/null
+/*
+* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+
+namespace Tizen.Pims.Contacts
+{
+ /// <summary>
+ /// Event arguments passed when contacts database is changed
+ /// </summary>
+ public class DBChangedEventArgs : EventArgs
+ {
+ internal DBChangedEventArgs(string viewUri)
+ {
+ ViewUri = viewUri;
+ }
+
+ /// <summary>
+ /// The contacts view URI changed.
+ /// </summary>
+ public string ViewUri
+ {
+ get;
+ internal set;
+ }
+ }
+}