7ea5d93112fb916919ab6285752128af6bee7513
[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   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      * The callback invoked when converting an object to a particular JavaScript type.
162      */
163     static JSValueRef convertToType(JSContextRef context,
164             JSObjectRef object,
165             JSType type,
166             JSValueRef* exception);
167     static JSValueRef getAttachments(JSContextRef context,
168             JSObjectRef object,
169             JSStringRef propertyName,
170             JSValueRef* exception);
171     static JSValueRef getBccAddress(JSContextRef context,
172             JSObjectRef object,
173             JSStringRef propertyName,
174             JSValueRef* exception);
175     static JSValueRef getBody(JSContextRef context,
176             JSObjectRef object,
177             JSStringRef propertyName,
178             JSValueRef* exception);
179     static JSValueRef getCallbackNumber(JSContextRef context,
180             JSObjectRef object,
181             JSStringRef propertyName,
182             JSValueRef* exception);
183     static JSValueRef getCcAddress(JSContextRef context,
184             JSObjectRef object,
185             JSStringRef propertyName,
186             JSValueRef* exception);
187     static JSValueRef getDestinationAddress(JSContextRef context,
188             JSObjectRef object,
189             JSStringRef propertyName,
190             JSValueRef* exception);
191     static JSValueRef getIsRead(JSContextRef context,
192             JSObjectRef object,
193             JSStringRef propertyName,
194             JSValueRef* exception);
195     static JSValueRef getMessageId(JSContextRef context,
196             JSObjectRef object,
197             JSStringRef propertyName,
198             JSValueRef* exception);
199     static JSValueRef getMessagePriority(JSContextRef context,
200             JSObjectRef object,
201             JSStringRef propertyName,
202             JSValueRef* exception);
203     static JSValueRef getMessageType(JSContextRef context,
204             JSObjectRef object,
205             JSStringRef propertyName,
206             JSValueRef* exception);
207     static JSValueRef getSourceAddress(JSContextRef context,
208             JSObjectRef object,
209             JSStringRef propertyName,
210             JSValueRef* exception);
211     static JSValueRef getSubject(JSContextRef context,
212             JSObjectRef object,
213             JSStringRef propertyName,
214             JSValueRef* exception);
215     static JSValueRef getTime(JSContextRef context,
216             JSObjectRef object,
217             JSStringRef propertyName,
218             JSValueRef* exception);
219     static JSValueRef getFolder(JSContextRef context,
220             JSObjectRef object,
221             JSStringRef propertyName,
222             JSValueRef* exception);
223     static JSValueRef getMessageBody(JSContextRef context,
224             JSObjectRef object,
225             JSStringRef propertyName,
226             JSValueRef* exception);
227     static JSValueRef getAccountID(JSContextRef context,
228             JSObjectRef object,
229             JSStringRef propertyName,
230             JSValueRef* exception);
231     static JSValueRef getUID(JSContextRef context,
232             JSObjectRef object,
233             JSStringRef propertyName,
234             JSValueRef* exception);
235 #if 0 // MESSAGING ATTACHMENT IS BLOCKED
236     static bool setAttachments(JSContextRef context,
237             JSObjectRef object,
238             JSStringRef propertyName,
239             JSValueRef value,
240             JSValueRef* exception);
241 #endif
242     static bool setBccAddress(JSContextRef context,
243             JSObjectRef object,
244             JSStringRef propertyName,
245             JSValueRef value,
246             JSValueRef* exception);
247     static bool setBody(JSContextRef context,
248             JSObjectRef object,
249             JSStringRef propertyName,
250             JSValueRef value,
251             JSValueRef* exception);
252     static bool setCcAddress(JSContextRef context,
253             JSObjectRef object,
254             JSStringRef propertyName,
255             JSValueRef value,
256             JSValueRef* exception);
257     static bool setDestinationAddress(JSContextRef context,
258             JSObjectRef object,
259             JSStringRef propertyName,
260             JSValueRef value,
261             JSValueRef* exception);
262     static bool setIsRead(JSContextRef context,
263             JSObjectRef object,
264             JSStringRef propertyName,
265             JSValueRef value,
266             JSValueRef* exception);
267     static bool setMessagePriority(JSContextRef context,
268             JSObjectRef object,
269             JSStringRef propertyName,
270             JSValueRef value,
271             JSValueRef* exception);
272     static bool setSubject(JSContextRef context,
273             JSObjectRef object,
274             JSStringRef propertyName,
275             JSValueRef value,
276             JSValueRef* exception);
277         static bool setMessageBody(JSContextRef context,
278             JSObjectRef object,
279             JSStringRef propertyName,
280             JSValueRef value,
281             JSValueRef* exception);
282
283     static JSValueRef update(JSContextRef context,
284             JSObjectRef function,
285             JSObjectRef thisObject,
286             size_t argumentCount,
287             const JSValueRef arguments[],
288             JSValueRef* exception);
289     static JSValueRef getConversationId(JSContextRef context,
290                         JSObjectRef object,
291                         JSStringRef propertyName,
292                         JSValueRef* exception);
293     static JSValueRef getInResponseTo(JSContextRef context,
294                         JSObjectRef object,
295                         JSStringRef propertyName,
296                         JSValueRef* exception);
297
298
299     static JSValueRef getMessageStatus(JSContextRef context,
300                                 JSObjectRef object,
301                                 JSStringRef propertyName,
302                                 JSValueRef* exception);
303
304     /**
305      * This structure describes a statically declared function property.
306      */
307     static JSStaticFunction m_function[];
308
309     /**
310      * This structure contains properties and callbacks that define a type of object.
311      */
312     static JSClassDefinition m_classInfo;
313
314     /**
315      * This member variable contains the initialization values for the static properties of this class.
316      * The values are given according to the data structure JSPropertySpec
317      */
318     static JSStaticValue m_property[];
319 };
320 }
321 }
322
323 #endif