Fix for CompatTC Fail
[framework/osp/social.git] / src / FScl_ContactDbMonitor.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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         FScl_ContactDbMonitor.h
18 * @brief        This is the header file for the _ContactDbMonitor class.
19 *
20 * This header file contains the declarations of the _ContactDbMonitor class.
21 */
22
23 #ifndef _FSCL_INTERNAL_CONTACT_DB_MONITOR_H_
24 #define _FSCL_INTERNAL_CONTACT_DB_MONITOR_H_
25
26 #include <new>
27 #include <pthread.h>
28 #include <unique_ptr.h>
29 #include <contacts.h>
30 #include <FBaseTypes.h>
31 #include <FBaseResult.h>
32 #include <FBaseObject.h>
33
34 namespace Tizen { namespace Base {
35
36 namespace Collection
37 {
38 template<typename Type>
39 class ArrayListT;
40 }
41
42 namespace Runtime
43 {
44 class Mutex;
45 }
46
47 }}
48
49 namespace Tizen { namespace Social
50 {
51 class _IContactDbChangeEventListener;
52 class _ContactDbChangeEvent;
53
54 /**
55  * @class       _ContactDbMonitor
56  * @brief       This class handles the _ContactDbMonitor operations.
57  * @since       2.0
58  * @see   _AddressbookImpl
59  *
60  */
61 class _ContactDbMonitor
62         : public Tizen::Base::Object
63 {
64 public:
65         result AddListener(const _IContactDbChangeEventListener& listener);
66
67         result RemoveListener(const _IContactDbChangeEventListener& listener);
68
69         int GetAccountIdByAddressbookId(int addressbookId);
70
71         static _ContactDbMonitor* GetInstance(void);
72
73 private:
74         _ContactDbMonitor(void);
75
76         virtual ~_ContactDbMonitor(void);
77
78         result Construct(void);
79
80         _ContactDbMonitor(const _ContactDbMonitor& rhs);
81
82         static void OnContactDbChanged(const char* viewUri, void* pUserData);
83
84         _ContactDbMonitor& operator =(const _ContactDbMonitor& rhs);
85
86         static void InitSingleton(void);
87
88         static void DestroySingleton(void);
89
90         result UpdateAddressbookList(void);
91
92
93 private:
94         class __Callback
95         {
96         public:
97                 __Callback(const char* uri, contacts_db_changed_cb callback, void* pData);
98                 result Register(void);
99                 ~__Callback(void);
100
101         private:
102                 char* __uri;
103                 contacts_db_changed_cb __callback;
104                 void* __pData;
105                 bool __registerred;
106         };
107
108         class __List
109         {
110                 public:
111                         __List(contacts_list_h list)
112                         : __list(list)
113                         {
114                         }
115
116                         contacts_list_h Release(void)
117                         {
118                                 contacts_list_h list = __list;
119
120                                 __list = null;
121
122                                 return list;
123                         }
124
125                         ~__List(void)
126                         {
127                                 if (__list != null)
128                                 {
129                                         contacts_list_destroy(__list, true);
130                                 }
131                         }
132                 private:
133                         contacts_list_h __list;
134         };
135
136         class __Lock
137         {
138                 public:
139                         __Lock(Tizen::Base::Runtime::Mutex* pMutex)
140                         :__pMutex(null)
141                         {
142                                 result r = pMutex->Acquire();
143                                 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
144
145                                 __pMutex = pMutex;
146                         }
147
148                         ~__Lock(void)
149                         {
150                                 if (__pMutex != null)
151                                 {
152                                         result r = __pMutex->Release();
153                                         SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
154                                 }
155                         }
156
157                 private:
158                         Tizen::Base::Runtime::Mutex* __pMutex;
159         };
160
161 private:
162         std::unique_ptr<_ContactDbChangeEvent> __pEvent;
163         std::unique_ptr<Tizen::Base::Runtime::Mutex> __pMutex;
164         std::unique_ptr<__Callback> __pContactChangeCallback;
165         std::unique_ptr<__Callback> __pGroupChangeCallback;
166         std::unique_ptr<__Callback> __pGroupRelationChagneCallback;
167         std::unique_ptr<__Callback> __pAddressbookChagneCallback;
168         contacts_list_h __pAddressbookList;
169
170         static _ContactDbMonitor* __pTheInstance;
171         friend struct std::default_delete< _ContactDbMonitor >;
172 };      // _ContactDbMonitor
173
174 }}  // Tizen::Social
175
176 #endif //_FSCL_INTERNAL_CONTACT_DB_MONITOR_H_