Update change log and spec for wrt-plugins-tizen_0.4.49
[framework/web/wrt-plugins-tizen.git] / src / DataControl / SqlDataControlConsumer.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 #ifndef TIZENAPIS_PLATFORM_SQL_DATACONTRIL_CONSUMER_H_
19 #define TIZENAPIS_PLATFORM_SQL_DATACONTRIL_CONSUMER_H_
20
21 #include <vector>
22 #include <string>
23 #include <dpl/noncopyable.h>
24 #include <bundle.h>
25 #include "ISqlDataControlConsumer.h"
26 #include "DataControlFactory.h"
27 #include <dpl/mutex.h>
28
29 namespace DeviceAPI {
30 namespace DataControl {
31
32 class SQLDataControlConsumer : public ISQLDataControlConsumer
33 {
34         friend class DataControlFactory;
35
36 public:
37
38         virtual void insertData(const EventInsertPtr& event);
39         virtual void deleteData(const EventDeletePtr& event);
40         virtual void selectData(const EventSelectPtr& event);
41         virtual void updateData(const EventUpdatePtr& event);
42         
43         virtual ~SQLDataControlConsumer();
44         void setType(std::string& type);
45         void setProviderId(const std::string& id );
46         void setDataId(const std::string& id );
47
48         std::string getType();
49         std::string getDataId();
50         std::string getProviderId();
51         
52         void SendAppControlLaunchToProvider(void* event);
53         void handlePendingEvent(const EventInsertPtr& event);
54         void handlePendingEvent(const EventDeletePtr& event);
55         void handlePendingEvent(const EventSelectPtr& event);
56         void handlePendingEvent(const EventUpdatePtr& event);
57
58 private:
59         std::string m_type;
60         std::string m_dataId;
61         std::string m_providerId;
62         std::string m_appId;
63         
64         std::string getApplicationId(const std::string& provId);
65         std::string getProviderPkgId(const std::string& appId);
66         std::string getCurrentApplicationId();
67         void addArrayToBundle(bundle* passData, std::vector<std::string>& array);
68         void handleCommonErrorEvent(void* userData, unsigned int code, std::string msg);
69
70         std::string convertIntToString(unsigned int data);
71         
72         static std::vector<unsigned int> m_currentReqIds;
73         bool checkReqIdUniqueness(unsigned int reqId);
74         
75         void removeReqId(unsigned int reqId);           
76         std::string generateFileName(unsigned int reqId);
77         void saveArrayToFile(std::string filename, RowData* rowData);
78         void createResultDir();
79         static DPL::Mutex m_mutex;
80 protected:
81         SQLDataControlConsumer(std::string& provId, std::string& dataId, std::string& type);
82
83         virtual void OnRequestReceived(const EventInsertPtr& event);
84         virtual void OnRequestReceived(const EventDeletePtr& event);
85         virtual void OnRequestReceived(const EventSelectPtr& event);
86         virtual void OnRequestReceived(const EventUpdatePtr& event);
87 private:
88         std::string m_currentAppId;
89         std::string m_ProviderPkgId;
90
91
92 };
93
94 class CommonPendingEvent
95 {
96 public: 
97         CommonPendingEvent() {}
98         ~CommonPendingEvent() {}
99
100         virtual void* getThisObject() const = 0;
101 };
102
103 class EventInsertPendingEvent : public CommonPendingEvent
104 {
105 public:
106         EventInsertPendingEvent() {}
107         EventInsertPendingEvent(void *thisObject, const  EventInsertPtr &event) :
108                 m_thisObject(thisObject),
109                 m_event(event)
110         {
111         }
112
113         virtual ~EventInsertPendingEvent()
114         {
115         }
116         virtual void* getThisObject() const { return m_thisObject; }
117         EventInsertPtr getEvent() const { return m_event; }
118 private:
119         void *m_thisObject;
120         EventInsertPtr m_event;
121 };
122
123 class EventDeletePendingEvent : public  CommonPendingEvent
124 {
125 public:
126         EventDeletePendingEvent() {}
127         EventDeletePendingEvent(void *thisObject, const  EventDeletePtr &event) :
128                 m_thisObject(thisObject),
129                 m_event(event)
130         {
131         }
132
133         virtual ~EventDeletePendingEvent()
134         {
135         }
136         virtual void* getThisObject() const { return m_thisObject; }
137         EventDeletePtr getEvent() const { return m_event; }
138 private:
139         void *m_thisObject;
140         EventDeletePtr m_event;
141 };
142
143 class EventUpdatePendingEvent : public CommonPendingEvent
144 {
145 public:
146         EventUpdatePendingEvent() {}
147         EventUpdatePendingEvent(void *thisObject, const  EventUpdatePtr &event) :
148                 m_thisObject(thisObject),
149                 m_event(event)
150         {
151         }
152
153         virtual ~EventUpdatePendingEvent()
154         {
155         }
156         virtual void* getThisObject() const { return m_thisObject; }
157         EventUpdatePtr getEvent() const { return m_event; }
158 private:
159         void *m_thisObject;
160         EventUpdatePtr m_event;
161 };
162
163 class EventSelectPendingEvent : public CommonPendingEvent
164 {
165 public:
166         EventSelectPendingEvent() {}
167         EventSelectPendingEvent(void *thisObject, const  EventSelectPtr &event) :
168                 m_thisObject(thisObject),
169                 m_event(event)
170         {
171         }
172
173         virtual ~EventSelectPendingEvent()
174         {
175         }
176         virtual void* getThisObject() const { return m_thisObject; }
177         EventSelectPtr getEvent() const { return m_event; }
178 private:
179         void *m_thisObject;
180         EventSelectPtr m_event;
181 };
182
183 }
184 }
185
186 #endif