wrt-plugins-tizen_0.4.23
[framework/web/wrt-plugins-tizen.git] / src / Messaging / JSMessage.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 JSMESSAGE_H
19 #define JSMESSAGE_H
20
21 #include <CommonsJavaScript/Converter.h>
22 #include <CommonsJavaScript/PrivateObject.h>
23 #include "IMessagingTypes.h"
24 #include "IMessage.h"
25 #include "EventUpdateMessage.h"
26 #include "JSMessageBody.h"
27 #include <Logger.h>
28
29 namespace DeviceAPI {
30 namespace Messaging {
31 class JSMessage
32 {
33     static JSClassRef m_jsClassRef;
34
35   public:
36
37     /*
38      * This method initializes object in the JS Engine.
39      */
40     static JSClassRef jsInit(JSContextRef context)
41     {
42         LoggerI("enter");
43         return JSClassCreate(&m_classInfo);
44     }
45
46     static const JSClassDefinition* getClassInfo()
47     {
48         LoggerI("enter");
49         return &(m_classInfo);
50     }
51
52     static JSClassRef getClassRef()
53     {
54         LoggerI("enter");
55         if (!m_jsClassRef) {
56             m_jsClassRef = JSClassCreate(&m_classInfo);
57         }
58         return m_jsClassRef;
59     }
60
61     static JSObjectRef constructor(JSContextRef ctx,
62                         JSObjectRef constructor,
63                         size_t argumentCount,
64                         const JSValueRef arguments[],
65                         JSValueRef* exception);
66
67     static JSValueRef createJSObject(JSContextRef context,
68             EmailAccountInfo& account,
69             MessageType msgType,
70             const std::string& msgId = "");
71
72     static JSValueRef createJSObject(JSContextRef context,
73             EventUpdateMessageAnswerReceiver* listener,
74             MessageType msgType = MESSAGETYPE_COUNT,
75             const std::string& msgId = "");
76
77     static JSValueRef createJSObject(JSContextRef context,
78                 MessageType msgType = MESSAGETYPE_COUNT,
79                 const std::string& msgId = "");
80
81         static JSValueRef createJSObject(JSContextRef context,
82             const IMessagePtr& msg,
83             EventUpdateMessageAnswerReceiver* listener);
84
85     static JSValueRef createJSObject(JSContextRef context,
86                   const IMessagePtr& msg);
87
88         static JSValueRef createDummyMessageJSObject(JSContextRef context,
89                 MessageType msgType);
90
91   private:
92     /**
93      * The callback invoked when an object is first created.
94      */
95     static void initialize(JSContextRef context,
96             JSObjectRef object);
97
98     /**
99      * The callback invoked when an object is finalized.
100      */
101     static void finalize(JSObjectRef object);
102
103     /**
104      * The callback invoked when determining whether an object has a property.
105      */
106     static bool hasProperty(JSContextRef context,
107             JSObjectRef object,
108             JSStringRef propertyName);
109
110     /**
111      * The callback invoked when getting a property's value.
112      */
113     static JSValueRef getProperty(JSContextRef context,
114             JSObjectRef object,
115             JSStringRef propertyName,
116             JSValueRef* exception);
117
118     /**
119      * The callback invoked when setting a property's value.
120      */
121     static bool setProperty(JSContextRef context,
122             JSObjectRef object,
123             JSStringRef propertyName,
124             JSValueRef value,
125             JSValueRef* exception);
126
127     /**
128      * The callback invoked when deleting a property.
129      */
130     static bool deleteProperty(JSContextRef context,
131             JSObjectRef object,
132             JSStringRef propertyName,
133             JSValueRef* exception);
134
135     /**
136      * The callback invoked when collecting the names of an object's properties.
137      */
138     static void getPropertyNames(JSContextRef context,
139             JSObjectRef object,
140             JSPropertyNameAccumulatorRef propertyNames);
141
142     /**
143      * The callback invoked when an object is called as a function.
144      */
145     static JSValueRef callAsFunction(JSContextRef context,
146             JSObjectRef object,
147             JSObjectRef thisObject,
148             size_t argumentCount,
149             const JSValueRef arguments[],
150             JSValueRef* exception);
151
152     /**
153      * The callback invoked when an object is used as the target of an 'instanceof' expression.
154      */
155     static bool hasInstance(JSContextRef context,
156             JSObjectRef constructor,
157             JSValueRef possibleInstance,
158             JSValueRef* exception);
159
160
161     /**
162      * The callback invoked when converting an object to a particular JavaScript type.
163      */
164     static JSValueRef convertToType(JSContextRef context,
165             JSObjectRef object,
166             JSType type,
167             JSValueRef* exception);
168     static JSValueRef getAttachments(JSContextRef context,
169             JSObjectRef object,
170             JSStringRef propertyName,
171             JSValueRef* exception);
172     static JSValueRef getBccAddress(JSContextRef context,
173             JSObjectRef object,
174             JSStringRef propertyName,
175             JSValueRef* exception);
176     static JSValueRef getBody(JSContextRef context,
177             JSObjectRef object,
178             JSStringRef propertyName,
179             JSValueRef* exception);
180     static JSValueRef getCallbackNumber(JSContextRef context,
181             JSObjectRef object,
182             JSStringRef propertyName,
183             JSValueRef* exception);
184     static JSValueRef getCcAddress(JSContextRef context,
185             JSObjectRef object,
186             JSStringRef propertyName,
187             JSValueRef* exception);
188     static JSValueRef getDestinationAddress(JSContextRef context,
189             JSObjectRef object,
190             JSStringRef propertyName,
191             JSValueRef* exception);
192     static JSValueRef getIsRead(JSContextRef context,
193             JSObjectRef object,
194             JSStringRef propertyName,
195             JSValueRef* exception);
196     static JSValueRef getMessageId(JSContextRef context,
197             JSObjectRef object,
198             JSStringRef propertyName,
199             JSValueRef* exception);
200     static JSValueRef getMessagePriority(JSContextRef context,
201             JSObjectRef object,
202             JSStringRef propertyName,
203             JSValueRef* exception);
204     static JSValueRef getMessageType(JSContextRef context,
205             JSObjectRef object,
206             JSStringRef propertyName,
207             JSValueRef* exception);
208     static JSValueRef getSourceAddress(JSContextRef context,
209             JSObjectRef object,
210             JSStringRef propertyName,
211             JSValueRef* exception);
212     static JSValueRef getSubject(JSContextRef context,
213             JSObjectRef object,
214             JSStringRef propertyName,
215             JSValueRef* exception);
216     static JSValueRef getTime(JSContextRef context,
217             JSObjectRef object,
218             JSStringRef propertyName,
219             JSValueRef* exception);
220     static JSValueRef getFolder(JSContextRef context,
221             JSObjectRef object,
222             JSStringRef propertyName,
223             JSValueRef* exception);
224     static JSValueRef getMessageBody(JSContextRef context,
225             JSObjectRef object,
226             JSStringRef propertyName,
227             JSValueRef* exception);
228     static JSValueRef getAccountID(JSContextRef context,
229             JSObjectRef object,
230             JSStringRef propertyName,
231             JSValueRef* exception);
232     static JSValueRef getUID(JSContextRef context,
233             JSObjectRef object,
234             JSStringRef propertyName,
235             JSValueRef* exception);
236 #if 0 // MESSAGING ATTACHMENT IS BLOCKED
237     static bool setAttachments(JSContextRef context,
238             JSObjectRef object,
239             JSStringRef propertyName,
240             JSValueRef value,
241             JSValueRef* exception);
242 #endif
243     static bool setAttachments(JSContextRef context,
244             JSObjectRef object,
245             JSStringRef propertyName,
246             JSValueRef value,
247             JSValueRef* exception);
248
249     static bool setBccAddress(JSContextRef context,
250             JSObjectRef object,
251             JSStringRef propertyName,
252             JSValueRef value,
253             JSValueRef* exception);
254     static bool setBody(JSContextRef context,
255             JSObjectRef object,
256             JSStringRef propertyName,
257             JSValueRef value,
258             JSValueRef* exception);
259     static bool setCcAddress(JSContextRef context,
260             JSObjectRef object,
261             JSStringRef propertyName,
262             JSValueRef value,
263             JSValueRef* exception);
264     static bool setDestinationAddress(JSContextRef context,
265             JSObjectRef object,
266             JSStringRef propertyName,
267             JSValueRef value,
268             JSValueRef* exception);
269     static bool setIsRead(JSContextRef context,
270             JSObjectRef object,
271             JSStringRef propertyName,
272             JSValueRef value,
273             JSValueRef* exception);
274     static bool setMessagePriority(JSContextRef context,
275             JSObjectRef object,
276             JSStringRef propertyName,
277             JSValueRef value,
278             JSValueRef* exception);
279     static bool setSubject(JSContextRef context,
280             JSObjectRef object,
281             JSStringRef propertyName,
282             JSValueRef value,
283             JSValueRef* exception);
284         static bool setMessageBody(JSContextRef context,
285             JSObjectRef object,
286             JSStringRef propertyName,
287             JSValueRef value,
288             JSValueRef* exception);
289
290     static JSValueRef update(JSContextRef context,
291             JSObjectRef function,
292             JSObjectRef thisObject,
293             size_t argumentCount,
294             const JSValueRef arguments[],
295             JSValueRef* exception);
296     static JSValueRef getConversationId(JSContextRef context,
297                         JSObjectRef object,
298                         JSStringRef propertyName,
299                         JSValueRef* exception);
300     static JSValueRef getInResponseTo(JSContextRef context,
301                         JSObjectRef object,
302                         JSStringRef propertyName,
303                         JSValueRef* exception);
304
305     static JSValueRef getMessageStatus(JSContextRef context,
306                                 JSObjectRef object,
307                                 JSStringRef propertyName,
308                                 JSValueRef* exception);
309
310     static JSValueRef hasAttachment(JSContextRef context,
311                                 JSObjectRef object,
312                                 JSStringRef propertyName,
313                                 JSValueRef* exception);
314
315     /**
316      * This structure describes a statically declared function property.
317      */
318     static JSStaticFunction m_function[];
319
320     /**
321      * This structure contains properties and callbacks that define a type of object.
322      */
323     static JSClassDefinition m_classInfo;
324
325     /**
326      * This member variable contains the initialization values for the static properties of this class.
327      * The values are given according to the data structure JSPropertySpec
328      */
329     static JSStaticValue m_property[];
330
331     // Utility functions. After full refactoring should be moved into lower layer
332     /**
333      * Functions that provides enum MessageServiceTag support. Converts message
334      * type given as string into MessageType value
335      */
336     static MessageType stringToMessageType(std::string type);
337 };
338 }
339 }
340
341 #endif