Update change log and spec for wrt-plugins-tizen_0.4.13
[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, char *changes, void* user_data);
64         static void removeBatchCB(int error, void *user_data);
65         static void removeAllCB(int error, void *user_data);
66         void find(const EventFindCallHistoryPtr& event);
67         bool remove(const unsigned long entryId);
68         void removeBatch(const EventRemoveBatchPtr& event);
69         void removeAll(const EventRemoveAllPtr& event);
70         long addListener(const EventCallHistoryListenerEmitterPtr& emitter);
71         void removeListener(const long id);
72
73         class Watcher
74         {
75         private:
76                 long m_handle;
77                 EventCallHistoryListenerEmitterPtr m_emitter;
78                 unsigned int m_currentLogId;
79                 MissedCallListPtr m_missedCallList;
80
81         public:
82                 Watcher(long handle, const EventCallHistoryListenerEmitterPtr& emitter);
83                 ~Watcher();
84
85                 void setHandle(long handle)
86                 {
87                         m_handle = handle;
88                 }
89
90                 long getHandle()
91                 {
92                         return m_handle;
93                 }
94
95                 void setCurrentLogId(unsigned int logId)
96                 {
97                         m_currentLogId = logId;
98                 }
99
100                 unsigned int getCurrentLogId()
101                 {
102                         return m_currentLogId;
103                 }
104
105                 EventCallHistoryListenerEmitterPtr getEmitter()
106                 {
107                         return m_emitter;
108                 }
109
110                 void emit(const EventCallHistoryListenerPtr& event)
111                 {
112                         m_emitter->emit(event);
113                 }
114
115                 void stateHasChanged(CallHistoryEntryListPtr &entryList, EventCallHistoryListener::ResultStates state);
116                 void stateHasRemoved(StringArrayPtr &entryList, EventCallHistoryListener::ResultStates state);
117
118                 bool parseRecord(contacts_list_h *recordList, CallHistoryEntryListPtr &entryList);
119                 bool parseRemoveRecord(char* record, StringArrayPtr &removeRecords);
120
121                 void ListenerCB(char* changes);
122         };
123         typedef DPL::SharedPtr<Watcher> WatcherPtr;
124
125 private:
126         bool convertCallHistory(callhistory_query_s *query_log, CallHistoryEntryListPtr &callEntries);
127         bool parseRecord(contacts_list_h *recordList, CallHistoryEntryListPtr &callEntries);
128         unsigned int  convertAttrName(std::string &name);
129
130         std::vector<EventRemoveBatchDataPtr> m_removeBatchEvent;
131         std::vector<EventRemoveAllDataPtr> m_removeAllEvent;
132
133         void callRemoveBatchEvent(int error, const EventRemoveBatchPtr &event);
134         void callRemoveAllEvent(int error, const EventRemoveAllPtr &event);
135
136 protected:
137         void OnRequestReceived(const EventCallHistoryPtr& event);
138         void OnRequestReceived(const EventFindCallHistoryPtr& event);
139         void OnRequestReceived(const EventRemoveBatchPtr& event);
140         void OnRequestReceived(const EventRemoveAllPtr& event);
141
142 private:
143         static std::vector<WatcherPtr> m_watchers;
144 };
145
146 }
147 }
148
149 #endif