Update change log and spec for wrt-plugins-tizen_0.2.76
[framework/web/wrt-plugins-tizen.git] / src / platform / Tizen / Contact / ContactsSvcChangeListenerManager.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /*
17  * @file        ContactsSvcChangeListenerManager.h
18  * @author      Kisub Song (kisubs.song@samsung.com)
19  * @version     0.1
20  * @brief       
21  */
22
23 #ifndef TIZENAPIS_PLATFORM_CONTACT_CONTACT_LISTENER_MANAGER_H_
24 #define TIZENAPIS_PLATFORM_CONTACT_CONTACT_LISTENER_MANAGER_H_
25
26 #include <string>
27 #include <map>
28 #include <set>
29 #include <dpl/shared_ptr.h>
30 #include <dpl/singleton.h>
31 #include <Commons/EventReceiver.h>
32 #include <Commons/IEvent.h>
33
34 #include <API/Contact/IContact.h>
35
36 namespace TizenApis {
37 namespace Platform {
38 namespace Contact {
39
40 class IContactEventCallbacks
41 {
42 public:
43     friend class ContactsSvcChangeListenerManager;
44
45     IContactEventCallbacks() {}
46         ~IContactEventCallbacks() {}
47
48 protected:
49         virtual void onContactEventAdded(TizenApis::Api::Contact::ContactArrayPtr &contacts) = 0;
50         virtual void onContactEventUpdated(TizenApis::Api::Contact::ContactArrayPtr &contacts) = 0;
51         virtual void onContactEventRemoved(TizenApis::Api::Contact::StringArrayPtr &contactIds) = 0;
52 };
53
54 class EventInvokeChangeListener :
55         public WrtDeviceApis::Commons::IEvent<EventInvokeChangeListener>
56 {
57 };
58 typedef DPL::SharedPtr<EventInvokeChangeListener> EventInvokeChangeListenerPtr;
59
60 class ContactsSvcChangeListenerManager :
61         public WrtDeviceApis::Commons::EventRequestReceiver< EventInvokeChangeListener >
62 {
63 public:
64         ContactsSvcChangeListenerManager();
65         virtual ~ContactsSvcChangeListenerManager();
66
67         // Can throw InvalidArgumentException or PlatformException
68         void registerAppListChangedCallbacks(IContactEventCallbacks *callbacks, int addressBookId);
69
70         // No throws
71         void unregisterAppListChangedCallbacks(IContactEventCallbacks *callbacks);
72         void unregisterAppListChangedCallbacks(int addressBookId);
73
74         long getWatchIdAndInc();
75
76 private:
77         static void contactsSvcEventCallback(void *data);
78         void contactsSvcEventCallback();
79         virtual void OnRequestReceived(const EventInvokeChangeListenerPtr &event);
80
81         void registerContactSvcChangedCallbacks();
82         void unregisterContactSvcChangedCallbacks();
83
84         IContactEventCallbacks* getContactEventCallbacks(int id);
85
86         typedef std::map<int, IContactEventCallbacks *> ContactEventCallbacksMap;
87         ContactEventCallbacksMap m_callbacks;
88
89         bool m_callbackRegistered;
90
91         int m_latestVersion;
92
93         long m_watchIdAcc;
94
95 public:
96         friend class DPL::Singleton<ContactsSvcChangeListenerManager>;
97 };
98
99 typedef DPL::Singleton<ContactsSvcChangeListenerManager> ContactsSvcChangeListenerManagerSingleton;
100
101 } // Contact
102 } // Platform
103 } // TizenApis
104
105 #endif // TIZENAPIS_PLATFORM_CONTACT_CONTACT_LISTENER_MANAGER_H_