upload tizen1.0 source
[profile/ivi/wrt-plugins-tizen.git] / src / platform / Tizen / Call / CallHistory.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
18 #ifndef TIZENAPIS_PLATFORM_CALLHISTORY_H_
19 #define TIZENAPIS_PLATFORM_CALLHISTORY_H_
20
21 #include <vector>
22 #include <dpl/shared_ptr.h>
23 #include <dpl/noncopyable.h>
24
25 #include <API/Call/ICallHistory.h>
26 #include <API/Call/CallHistoryFactory.h>
27 #include <API/Call/EventFindCallHistory.h>
28 #include <API/Call/EventRemoveBatch.h>
29 #include <API/Call/EventRemoveAll.h>
30 #include <API/Call/EventCallHistoryListener.h>
31 #include <API/Call/CallHistoryEntryProperties.h>
32 #include <API/Call/RemoteParty.h>
33 #include "CallHistoryQuery.h"
34
35 namespace TizenApis {
36 namespace Platform {
37 namespace Call {
38
39 typedef std::vector<unsigned long> MissedCallList;
40 typedef DPL::SharedPtr<MissedCallList> MissedCallListPtr;
41
42 class CallHistory : public Api::Call::ICallHistory
43 {
44 public:
45         CallHistory();
46         ~CallHistory();
47
48         void find(const Api::Call::EventFindCallHistoryPtr& event);
49         bool remove(const unsigned long entryId);
50         void removeBatch(const Api::Call::EventRemoveBatchPtr& event);
51         void removeAll(const Api::Call::EventRemoveAllPtr& event);
52         long addListener(const Api::Call::EventCallHistoryListenerEmitterPtr& emitter);
53         void removeListener(const Api::Call::EventCallHistoryListenerEmitter::IdType id);
54
55         static void addedListenerCB(void *user_data);
56         static void changedListenerCB(void *user_data);
57
58         class Watcher
59         {
60         private:
61                 int m_handle;
62                 Api::Call::EventCallHistoryListenerEmitterPtr m_emitter;
63                 unsigned int m_currentLogId;
64                 Platform::Call::MissedCallListPtr m_missedCallList;
65
66         public:
67                 Watcher(int handle, const Api::Call::EventCallHistoryListenerEmitterPtr& emitter);
68                 ~Watcher();
69
70                 void setHandle(int handle)
71                 {
72                         m_handle = handle;
73                 }
74
75                 int& getHandle()
76                 {
77                         return m_handle;
78                 }
79
80                 void setCurrentLogId(unsigned int logId)
81                 {
82                         m_currentLogId = logId;
83                 }
84
85                 unsigned int getCurrentLogId()
86                 {
87                         return m_currentLogId;
88                 }
89
90                 void setMissedCallList(const Platform::Call::MissedCallListPtr &missedCallList)
91                 {
92                         m_missedCallList = missedCallList;
93                 }
94
95                 Platform::Call::MissedCallListPtr getMissedCallList()
96                 {
97                         return m_missedCallList;
98                 }
99
100                 Api::Call::EventCallHistoryListenerEmitterPtr getEmitter()
101                 {
102                         return m_emitter;
103                 }
104
105                 void emit(const Api::Call::EventCallHistoryListenerPtr& event)
106                 {
107                         m_emitter->emit(event);
108                 }
109
110                 void stateHasChanged(Api::Call::CallHistoryEntryListPtr &entryList, Api::Call::EventCallHistoryListener::ResultStates state);
111                 bool executeQuery(std::string &query, Api::Call::CallHistoryEntryListPtr &entryList);
112                 bool addMissedCall(Api::Call::CallHistoryEntryListPtr &entryList);
113                 bool updateCurrentMissedCall();
114         };
115         typedef DPL::SharedPtr<Watcher> WatcherPtr;
116
117 private:
118         bool convertCallHistory(callhistory_query_s *query_log, Api::Call::CallHistoryEntryListPtr &callEntries);
119         bool executeQuery(std::string &query, Api::Call::CallHistoryEntryListPtr &callEntries);
120         std::string convertAttrName(std::string &name);
121         std::string makeQuerySortMode(Api::Tizen::SortModePtr attr);
122         Platform::Call::MissedCallListPtr updateCurrentMissedCall();
123
124 protected:
125         void OnRequestReceived(const Api::Call::EventFindCallHistoryPtr& event);
126         void OnRequestReceived(const Api::Call::EventRemoveBatchPtr& event);
127         void OnRequestReceived(const Api::Call::EventRemoveAllPtr& event);
128
129 private:
130         static std::vector<WatcherPtr> m_watchers;
131 };
132
133 }
134 }
135 }
136
137 #endif