Fix code for TDIS-5396
[framework/osp/social.git] / src / FScl_AccountDbMonitor.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18 * @file         FScl_AccountDbMonitor.h
19 * @brief        This is the header file for the _AccountDbMonitor class.
20 *
21 * This header file contains the declarations of the _AccountDbMonitor class.
22 */
23
24 #ifndef _FSCL_INTERNAL_ACCOUNT_DB_MONITOR_H_
25 #define _FSCL_INTERNAL_ACCOUNT_DB_MONITOR_H_
26
27 #include <new>
28 #include <pthread.h>
29 #include <unique_ptr.h>
30 #include <account.h>
31 #include <FBaseTypes.h>
32 #include <FBaseResult.h>
33 #include <FBaseObject.h>
34
35 namespace Tizen { namespace Base {
36
37 namespace Collection
38 {
39 template<typename Type>
40 class ArrayListT;
41 }
42
43 namespace Runtime
44 {
45 class Mutex;
46 }
47
48 }}
49
50 namespace Tizen { namespace Social
51 {
52 class _IAccountDbChangeEventListener;
53 class _AccountDbChangeEvent;
54
55 /**
56  * @class       _AccountDbMonitor
57  * @brief       This class handles the _AccountDbMonitor operations.
58  * @since       2.1
59  */
60 class _AccountDbMonitor
61         : public Tizen::Base::Object
62 {
63 public:
64         result AddListener(const _IAccountDbChangeEventListener& listener);
65
66         result RemoveListener(const _IAccountDbChangeEventListener& listener);
67
68         static _AccountDbMonitor* GetInstance(void);
69
70 private:
71         _AccountDbMonitor(void);
72
73         virtual ~_AccountDbMonitor(void);
74
75         result Construct(void);
76
77         _AccountDbMonitor(const _AccountDbMonitor& rhs);
78
79         static bool OnAccountChangeEventReceived(const char* pEventType, int accountId, void* pUserData);
80
81         _AccountDbMonitor& operator =(const _AccountDbMonitor& rhs);
82
83         static void InitSingleton(void);
84
85         static void DestroySingleton(void);
86
87 private:
88         class __Callback
89         {
90         public:
91                 __Callback(account_subscribe_h accountSubscribeHandle, account_event_cb callback, void* pUserData);
92                 result Register(void);
93                 ~__Callback(void);
94
95         private:
96                 account_subscribe_h __accountSubscribeHandle;
97                 account_event_cb __callback;
98                 void* __pUserData;
99         };
100
101 private:
102         std::unique_ptr<_AccountDbChangeEvent> __pEvent;
103         std::unique_ptr<Tizen::Base::Runtime::Mutex> __pMutex;
104         std::unique_ptr<__Callback> __pAccountChangeCallback;
105
106         static _AccountDbMonitor* __pTheInstance;
107         friend struct std::default_delete< _AccountDbMonitor >;
108 };      // _AccountDbMonitor
109
110 }}  // Tizen::Social
111
112 #endif //_FSCL_INTERNAL_ACCOUNT_DB_MONITOR_H_