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