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