ed81e4dc2e6ba9fc581b867f10ae3a5e620e4aa2
[framework/web/wrt-plugins-tizen.git] / src / Callhistory / CallHistory.h
1 //
2 // Tizen Web Device API
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
19 #ifndef TIZENAPIS_PLATFORM_CALLHISTORY_H_
20 #define TIZENAPIS_PLATFORM_CALLHISTORY_H_
21
22 #include <vector>
23 #include <dpl/shared_ptr.h>
24 #include <dpl/noncopyable.h>
25
26 #include "ICallHistory.h"
27 #include "CallHistoryFactory.h"
28 #include "EventCallHistoryTemplate.h"
29 #include "EventCallHistory.h"
30 #include "EventFindCallHistory.h"
31 #include "EventRemoveBatch.h"
32 #include "EventRemoveAll.h"
33 #include "EventCallHistoryListener.h"
34 #include "CallHistoryEntryProperties.h"
35 #include "RemoteParty.h"
36 #include <contacts.h>
37
38 namespace DeviceAPI {
39 namespace CallHistory {
40
41 typedef DPL::SharedPtr<EventCallHistoryPtrs<EventRemoveBatch>> EventRemoveBatchDataPtr;
42 typedef DPL::SharedPtr<EventCallHistoryPtrs<EventRemoveAll>> EventRemoveAllDataPtr;
43
44 typedef std::vector<unsigned long> MissedCallList;
45 typedef DPL::SharedPtr<MissedCallList> MissedCallListPtr;
46
47 typedef struct
48 {
49         int             calllog_db_id;
50         contacts_phone_log_type_e       calllog_type;
51         int             person_db_id;
52         char*           phone_number;
53         time_t          timestamp;
54         int             duration_sec;
55 } callhistory_query_s;
56
57 class CallHistory : public ICallHistory
58 {
59 public:
60         CallHistory();
61         ~CallHistory();
62
63         static void callhistoryListenerCB(const char* view_uri, void* user_data);
64         static void removeBatchCB(int error, void *user_data);
65         static void removeAllCB(int error, void *user_data);
66
67         void find(const EventFindCallHistoryPtr& event);
68         bool remove(const unsigned long entryId);
69         void removeBatch(const EventRemoveBatchPtr& event);
70         void removeAll(const EventRemoveAllPtr& event);
71         long addListener(const EventCallHistoryListenerEmitterPtr& emitter);
72         void removeListener(const long id);
73
74         class Watcher
75         {
76         private:
77                 long m_handle;
78                 EventCallHistoryListenerEmitterPtr m_emitter;
79                 unsigned int m_currentLogId;
80                 MissedCallListPtr m_missedCallList;
81
82         public:
83                 Watcher(long handle, const EventCallHistoryListenerEmitterPtr& emitter);
84                 ~Watcher();
85
86                 void setHandle(long handle)
87                 {
88                         LogDebug("setHandle : handle ["<<handle<<"]");
89                         m_handle = handle;
90                 }
91
92                 long getHandle()
93                 {
94                         LogDebug("getHandle : handle ["<<m_handle<<"]");
95                         return m_handle;
96                 }
97
98                 void setCurrentLogId(unsigned int logId)
99                 {
100                         m_currentLogId = logId;
101                         LogDebug("setCurrentLogId : logId ["<<logId);
102
103                 }
104
105                 unsigned int getCurrentLogId()
106                 {
107                         return m_currentLogId;
108                 }
109
110                 void setMissedCallList(const MissedCallListPtr &missedCallList)
111                 {
112                         m_missedCallList = missedCallList;
113                 }
114
115                 MissedCallListPtr getMissedCallList()
116                 {
117                         return m_missedCallList;
118                 }
119
120                 EventCallHistoryListenerEmitterPtr getEmitter()
121                 {
122                         return m_emitter;
123                 }
124
125                 void emit(const EventCallHistoryListenerPtr& event)
126                 {
127                         m_emitter->emit(event);
128                 }
129
130                 void stateHasChanged(CallHistoryEntryListPtr &entryList, EventCallHistoryListener::ResultStates state);
131                 bool parseRecord(contacts_list_h *recordList, CallHistoryEntryListPtr &entryList);
132                 bool addMissedCall(CallHistoryEntryListPtr &entryList);
133                 bool updateCurrentMissedCall();
134                 void addedListenerCB();
135                 void changedListenerCB();
136         };
137         typedef DPL::SharedPtr<Watcher> WatcherPtr;
138
139 private:
140         bool convertCallHistory(callhistory_query_s *query_log, CallHistoryEntryListPtr &callEntries);
141         bool parseRecord(contacts_list_h *recordList, CallHistoryEntryListPtr &callEntries);
142         unsigned int  convertAttrName(std::string &name);
143         MissedCallListPtr updateCurrentMissedCall();
144
145         std::vector<EventRemoveBatchDataPtr> m_removeBatchEvent;
146         std::vector<EventRemoveAllDataPtr> m_removeAllEvent;
147
148         void callRemoveBatchEvent(int error, const EventRemoveBatchPtr &event);
149         void callRemoveAllEvent(int error, const EventRemoveAllPtr &event);
150
151 protected:
152         void OnRequestReceived(const EventCallHistoryPtr& event);
153         void OnRequestReceived(const EventFindCallHistoryPtr& event);
154         void OnRequestReceived(const EventRemoveBatchPtr& event);
155         void OnRequestReceived(const EventRemoveAllPtr& event);
156
157 private:
158         static std::vector<WatcherPtr> m_watchers;
159 };
160
161 }
162 }
163
164 #endif