221cf67deb0def564eebcad30545720022859753
[framework/web/wrt-plugins-tizen.git] / src / Messaging / MessagingService.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 WRTPLUGINS_PLATFORM_MESSAGING_SERVICE_H_
19 #define WRTPLUGINS_PLATFORM_MESSAGING_SERVICE_H_
20
21 #include <map>
22 #include <dpl/generic_event.h>
23 #include <dpl/shared_ptr.h>
24 #include <dpl/noncopyable.h>
25
26 #include "IMessagingService.h"
27 #include "EventMessagingService.h"
28
29 //#include <Commons/Emitters.h>
30
31 namespace DeviceAPI {
32 namespace Messaging {
33
34 //DECLARE_GENERIC_EVENT_0(JobDoneEvent) //for manual answer  (async call)
35 //=============================================================================
36 class MessagingService: 
37    public IMessagingService
38 {
39 public:
40         MessagingService();
41         virtual ~MessagingService();
42         //interface     
43         //virtual void createMessage(const EventMessagingServicePtr& event);
44         void setMessagingServiceType(int type);
45         void setMessagingServiceName(const std::string& name);
46         void setMessagingServiceId(int serviceId);
47                 
48         virtual int sync(const IMessagingServicePtr& messagingService, const int limit);
49         virtual void syncCancel(int handle);
50         virtual int syncFolder(const IMessagingServicePtr& messagingService, const int folder_id, const int limit);
51         virtual void syncFolderCancel(int handle);
52
53         virtual void cancelOperation(int opId, int handle, int eventType, IMessagePtr& message);
54
55         int createOpId(int type);
56         int getHandleFromOpId(int opId);
57         int getOpTypeFromOpId(int opId);
58         IMessagePtr getMessageFromOpId(int opId);
59         EventMessagingServicePtr getEventFromOpId(int opId);
60         
61         void setHandleToOpId(int opId, int handle);
62         void setMessageToOpId(int opId, IMessagePtr& message);
63         void setEventToOpId(int opId, EventMessagingServicePtr& event);
64         int deleteOpId(int opId);
65
66 protected:
67         //virtual void OnRequestReceived(const EventMessagingServicePtr& event);
68
69 private:
70         
71         int create_messaging_service();
72         void initialize();
73         bool m_initialized;
74
75         //EventGetMessagingServicePtr plugin_event;
76
77         enum {
78                 MessagingServiceManager_ERROR_NONE = 0,
79                 MessagingServiceManager_ERROR_INVALID_PARAMETER = 1,
80                 MessagingServiceManager_ERROR_PLATFORM_SERVICE_NOT_AVAILABLE = 2,
81                 MessagingServiceManager_ERROR_UNKNOWN = 3,
82         };
83
84         struct MessagingServiceOpData
85         {
86                 unsigned int handle;
87                 unsigned short type;
88                 IMessagePtr message;
89                 EventMessagingServicePtr event;
90
91                 explicit MessagingServiceOpData(int handle, int type) :
92                     handle(handle),
93                     type(type),
94                     message(NULL),
95                     event(NULL)
96                 {
97                 }
98         };
99         
100         typedef std::map<int, MessagingServiceOpData> OpRequests;
101         typedef OpRequests::iterator OpRequestsIterator;        
102
103         OpRequests m_opRequests;        // create operation
104         
105 };
106
107
108 }
109 }
110 #endif /* WRTPLUGINS_PLATFORM_MESSAGING_SERVICE_H_ */