cdb48f479547fa6ac73d0cf37a081673b77a1d00
[framework/web/wrt-plugins-common.git] / src / modules / API / Messaging / IMessage.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  *
18  *
19  * @file       IMessage.h
20  * @author     Pawel Misiak (p.misiak@samsung.com)
21  * @version    0.1
22  * @brief
23  */
24 #ifndef IMESSAGE_H
25 #define IMESSAGE_H
26
27 #include <string>
28 #include <ctime>
29 #include <dpl/shared_ptr.h>
30 #include <dpl/enable_shared_from_this.h>
31 #include "IMessagingTypes.h"
32 #include "ToRecipient.h"
33 #include "Body.h"
34 #include "From.h"
35 #include "SourceAddress.h"
36 #include "MessagePriority.h"
37 #include "CallbackNumber.h"
38 #include "ValidityPeriodHours.h"
39 #include "Subject.h"
40 #include "EventOnSendingFailed.h"
41
42 namespace WrtDeviceApis {
43 namespace Messaging {
44 namespace Api {
45 class EventSendMessage;
46 typedef DPL::SharedPtr<EventSendMessage> EventSendMessagePtr;
47
48 //--------------------------------------------------------------------------
49
50 class IMessage;
51 typedef DPL::SharedPtr<IMessage> IMessagePtr;
52
53 //--------------------------------------------------------------------------
54
55 class ReqReceiverMessage;
56
57 //--------------------------------------------------------------------------
58
59 class IMessage :
60     public DPL::EnableSharedFromThis<IMessage>,
61     public ToRecipient,
62     public Body,
63     public From,
64     public SourceAddress,
65     public MessagePriority,
66     public CallbackNumber,
67     public ValidityPeriodHours,
68     public Subject
69 {
70   private: // fields
71
72     /**
73      * id of message
74      */
75     std::string m_id;
76
77     /**
78      * message type value
79      */
80     const MessageType m_msgType;
81
82     /**
83      * Message creation date time
84      */
85     struct tm m_dateTime;
86
87     /**
88      * Message read status
89      */
90     bool m_readStatus;
91
92     /**
93      * Read status validity.
94      */
95     bool m_validReadStatus;
96
97     /**
98      * Message size in bytes
99      */
100     int m_size;
101
102     /**
103      * Message current folder
104      */
105     FolderType m_folder;
106
107     /**
108      * User folder name
109      */
110     std::string m_userFolderName;
111
112     /*
113      * Event emitter. Used when there is one global callback function
114      */
115     EventOnSendingFailedEmitterPtr m_emitter;
116
117     /*
118      * Request receiver. Used when there are callback funtions assigned at function executing scope
119      */
120     ReqReceiverMessage *m_requestReceiver;
121
122     /*
123      * SendMessage event. Used when there are callback funtions assigned at function executing scope
124      */
125     EventSendMessagePtr m_sendMessageEvent;
126
127   protected:
128     void setSize(int size);
129
130   public: // methods
131
132     /**
133      * constructor of abstraction message
134      * @param[in] msgType - type of message according to MessageType
135      * @param[in] id - id of message, if id is empty, new message will be
136      *                created, othercase message will be read from low
137      *                level message
138      */
139     explicit IMessage(const MessageType msgType,
140             const std::string& id = "");
141
142     virtual ~IMessage();
143
144     /**
145      * method is used to send message specyfied type
146      * @throw PlatformException Thrown when sending fail
147      */
148     virtual void send() = 0;
149
150     /**
151      * method is used to cancel sending message
152      * @throw PlatformException Thrown when sending fail
153      */
154     virtual void sendCancel() = 0;
155
156     /**
157      * method used to update all fields in lower level
158      * @param[in] draftsOnly - if true only draft messages can be
159      * fully updated. Other messages can only have read flag changed
160      * @throw PlatformException Thrown when update fail
161      */
162     virtual void update(bool draftsOnly = false) = 0;
163
164     /**
165      * method used to read all data from low level message
166      * @throw PlatformException Thrown when reading message fail
167      */
168     virtual void readAllData() = 0;
169
170     /**
171      *  method used to get current storage folder
172      */
173     virtual FolderType getCurrentFolder() const;
174
175     /**
176      *  method used to get current user folder name
177      */
178     virtual std::string getCurrentUserFolder() const;
179
180     /**
181      *  method used to set current user folder name
182      */
183     void setCurrentUserFolder(const std::string& arg);
184
185     /**
186      * method used to move message to new folder
187      * @param[in] newFolder - destination folder
188      * @throw PlatformException Thrown when move message to folder fail
189      */
190     virtual void moveToFolder(const FolderType newFolder) = 0;
191
192     /**
193      * method used to move message to user defined new folder
194      * @param[in] newFolder - users destination folder
195      * @throw PlatformException Thrown when move message to folder fail
196      */
197     virtual void moveToFolder(const std::string& newFolder) = 0;
198
199     /**
200      * method used to copy message to new folder (create new message with
201      * new message id)
202      * @param[in] newFolder - destination folder
203      * @throw PlatformException Thrown when copy message to folder fail
204      */
205     virtual void copyToFolder(const FolderType newFolder) = 0;
206
207     /**
208      * method used to copy message to user defined new folder
209      * @param[in] newFolder - users destination folder
210      * @throw PlatformException Thrown when move message to folder fail
211      */
212     virtual void copyToFolder(const std::string& newFolder) = 0;
213
214     /**
215      * method used to identify message type
216      */
217     MessageType getMessageType() const;
218
219     /**
220      * method used to get message id
221      */
222     std::string getId() const;
223
224     /**
225      * method used to get message size
226      */
227     int getSize() const;
228
229     /**
230      * method used to get message id
231      */
232     virtual const std::string& getIdRef() const;
233
234     /**
235      * used for get tm struct
236      */
237     struct tm getDateTime() const;
238
239     /**
240      * Is message already been read
241      */
242     virtual bool isRead() const;
243
244     /**
245      * Is message already been read
246      */
247     virtual void setReadStatus(bool state);
248
249     /**
250      * Returns true if read status is valid
251      */
252     bool isReadStatusValid() const;
253
254     /**
255      * Sets read status validity
256      */
257     void setReadStatusValidity(bool valid);
258
259     /**
260      *  Remove message
261      * @throw PlatformException Thrown when remove message fail
262      */
263     virtual void remove() = 0;
264
265     /**
266      * convert id from int to string
267      */
268     virtual std::string convertId(int arg) const;
269
270     /**
271      * convert id from string to int
272      */
273     virtual int convertId(const std::string& arg) const;
274
275     /**
276      * set message id
277      */
278     void setId(const std::string& id);
279
280     /**
281      * set date time
282      */
283     void setDateTime(const tm dateTime);
284
285     /**
286      * set current folder
287      */
288     virtual void setFolderType(FolderType folder);
289
290     /**
291      * validate phone number, if fail return false
292      * if number contains wrong characters, then cut them
293      */
294     bool validatePhoneNumber(std::string& number);
295
296     /**
297      * validate email address, if fail return false
298      */
299     bool validateEmailAddr(const Recipients& addr);
300
301     /**
302      * validate email address, if fail return false
303      */
304     bool validateEmailAddr(const std::string& email);
305
306     /*
307      * Sets event emitter
308      */
309     void setEmitter(const EventOnSendingFailedEmitterPtr& emitter);
310
311     /*
312      * Gets event emitter
313      */
314     EventOnSendingFailedEmitterPtr getEmitter() const;
315
316     void setSendMessageEvent(const EventSendMessagePtr &event);
317
318     EventSendMessagePtr getSendMessageEvent() const;
319
320     void setRequestReceiver(ReqReceiverMessage* reqReceiver);
321
322     ReqReceiverMessage* getRequestReceiver() const;
323 };
324 }
325 }
326 }
327 #endif