wrt-plugins-tizen_0.4.23
[framework/web/wrt-plugins-tizen.git] / src / Messaging / IMessagingService.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 WRTPLUGINS_API_IMESSAGING_SERVICE_H_
20 #define WRTPLUGINS_API_IMESSAGING_SERVICE_H_
21
22 #include "IMessagingTypes.h"
23 #include <string>
24 #include <dpl/shared_ptr.h>
25 #include <Commons/ThreadPool.h>
26 #include "IEmailAccount.h"
27 #include "IMessageFolder.h"
28 #include "IMessage.h"
29 #include <Commons/EventReceiver.h>
30 #include <Commons/IExternEventCanceler.h>
31
32 namespace DeviceAPI {
33 namespace Messaging {
34
35 enum MessagingServiceOpType
36 {
37         MESSAGING_SERVICE_OP_SEND_MESSAGE = 0,
38         MESSAGING_SERVICE_OP_DOWNLOAD_BODY,
39         MESSAGING_SERVICE_OP_DOWNLOAD_ATTACHMENT,
40         MESSAGING_SERVICE_OP_SYNC,
41         MESSAGING_SERVICE_OP_SYNC_FOLDER,
42         MESSAGING_SERVICE_OP_COUNT,
43 };
44
45 class ReqReceiverMessage;
46 class IMessagingService;
47
48 typedef DPL::SharedPtr<IMessagingService> IMessagingServicePtr;
49
50 class IMessagingService:
51         public WrtDeviceApis::Commons::IExternEventCanceler< EventMessagingService >,
52         public IEmailAccount
53 {
54 public:
55         virtual  ~IMessagingService();
56
57 //      /**
58 //       * Gets a service of messaging
59 //       * @param event @see TizenApis::Api::PluginTemplete::EventGetMessagingService
60 //       * @exception WrtDeviceApis::Commons::PlatformException when platform error occurs
61 //       */
62
63         int getAccountID() const
64         {       
65                 if ( m_messagingServiceType == EMAIL)
66                 {
67                         return getCurrentEmailAccount().getIntId();
68                 }
69                 else if(m_messagingServiceType == SMS)
70                 {
71                         return m_messagingServiceId;
72                 }
73                 else if(m_messagingServiceType == MMS)
74                 {
75                         return m_messagingServiceId;
76                 }
77                 else 
78                 {
79                         return -1;              //default is -1
80                 }
81         }
82         
83         int getType() const
84         {
85                 return m_messagingServiceType;
86         }
87         
88         std::string getName() const
89         {       
90                 if ( m_messagingServiceType == EMAIL)
91                 {
92                         return getCurrentEmailAccount().getName();
93                 }
94                 else
95                 {
96                         return m_messagingServiceName;
97                 }
98         }
99                 
100         virtual int createOpId(int type) = 0;
101         virtual int getHandleFromOpId(int opId) = 0;
102         virtual int getOpTypeFromOpId(int opId) = 0;
103         virtual IMessagePtr getMessageFromOpId(int opId) = 0;
104         virtual EventMessagingServicePtr getEventFromOpId(int opId) = 0;
105         virtual EventMessagingServicePtr getEventFromHandle(int handle) = 0;
106         virtual void setHandleToOpId(int opId, int handle) = 0;
107         virtual void setMessageToOpId(int opId, IMessagePtr& message) = 0;
108         virtual void setEventToOpId(int opId, EventMessagingServicePtr &event) = 0;
109         virtual int deleteOpId(int opId)=0;
110                                         
111         virtual int sync(const IMessagingServicePtr& messagingService, const int limit) = 0;
112         virtual void syncCancel(int handle) = 0;
113         virtual int syncFolder(const IMessagingServicePtr& messagingService, const int folder_id, const int limit) = 0;
114         virtual void syncFolderCancel(int handle) = 0;
115
116         virtual void cancelOperation(int opId, int handle, int eventType, IMessagePtr& message) = 0;
117         
118     void OnCancelEvent(const EventMessagingServicePtr &event);
119     void setMessagingServiceEvent(const EventMessagingServicePtr &event);
120     EventMessagingServicePtr getMessagingServiceEvent() const;
121
122     void setRequestReceiver(ReqReceiverMessage* reqReceiver)
123     {
124                 m_requestReceiver = reqReceiver;
125     }
126
127     ReqReceiverMessage* getRequestReceiver() const
128     {
129                 return m_requestReceiver;
130     }
131
132 private: 
133          short m_messagingServiceType;          //type
134          std::string m_messagingServiceName;
135          int m_messagingServiceId;
136          /*
137           * Request receiver. Used when there are callback funtions assigned at function executing scope
138           */
139          ReqReceiverMessage *m_requestReceiver;
140          
141          /*
142           * Messaging Service event. Used when there are callback funtions assigned at function executing scope
143          */
144          EventMessagingServicePtr m_messagingServiceEvent;
145           
146 protected:
147         IMessagingService();
148         
149         void setType(int type)
150         {
151                 m_messagingServiceType = type;
152         }
153
154         void setName(const std::string& name = "" )
155         {
156                 m_messagingServiceName = name;
157         }
158
159         void setId(int serviceId)
160         {
161                 m_messagingServiceId = serviceId;
162         }
163
164 };
165
166 }
167 }
168
169 #endif //WRTPLUGINS_API_IMESSAGING_SERVICE_H_
170
171
172