Update change log and spec for wrt-plugins-tizen_0.4.13
[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         EventMessagingServicePtr getEventFromHandle(int handle);
61         
62         void setHandleToOpId(int opId, int handle);
63         void setMessageToOpId(int opId, IMessagePtr& message);
64         void setEventToOpId(int opId, EventMessagingServicePtr& event);
65         int deleteOpId(int opId);
66
67 protected:
68         //virtual void OnRequestReceived(const EventMessagingServicePtr& event);
69
70 private:
71         
72         int create_messaging_service();
73         void initialize();
74         bool m_initialized;
75
76         //EventGetMessagingServicePtr plugin_event;
77
78         enum {
79                 MessagingServiceManager_ERROR_NONE = 0,
80                 MessagingServiceManager_ERROR_INVALID_PARAMETER = 1,
81                 MessagingServiceManager_ERROR_PLATFORM_SERVICE_NOT_AVAILABLE = 2,
82                 MessagingServiceManager_ERROR_UNKNOWN = 3,
83         };
84
85         struct MessagingServiceOpData
86         {
87                 unsigned int handle;
88                 unsigned short type;
89                 IMessagePtr message;
90                 EventMessagingServicePtr event;
91
92                 explicit MessagingServiceOpData(int handle, int type) :
93                     handle(handle),
94                     type(type),
95                     message(NULL),
96                     event(NULL)
97                 {
98                 }
99         };
100         
101         typedef std::map<int, MessagingServiceOpData> OpRequests;
102         typedef OpRequests::iterator OpRequestsIterator;        
103
104         OpRequests m_opRequests;        // create operation
105         
106 };
107
108
109 }
110 }
111 #endif /* WRTPLUGINS_PLATFORM_MESSAGING_SERVICE_H_ */