2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 * @author Pawel Misiak (p.misiak@samsung.com)
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"
42 static JSClassRef m_jsClassRef;
47 * This method initializes object in the JS Engine.
49 static JSClassRef jsInit(JSContextRef context)
52 return JSClassCreate(&m_classInfo);
55 static const JSClassDefinition* getClassInfo()
58 return &(m_classInfo);
61 static JSClassRef getClassRef()
65 m_jsClassRef = JSClassCreate(&m_classInfo);
70 static JSValueRef createJSObject(JSContextRef context,
71 Api::Messaging::EmailAccountInfo& account,
72 Api::Messaging::MessageType msgType,
73 const std::string& msgId = "");
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 = "");
80 static JSValueRef createJSObject(JSContextRef context,
81 Api::Messaging::MessageType msgType = Api::Messaging::MESSAGETYPE_COUNT,
82 const std::string& msgId = "");
84 static JSValueRef createJSObject(JSContextRef context,
85 const Api::Messaging::IMessagePtr& msg,
86 Api::Messaging::EventUpdateMessageAnswerReceiver* listener);
88 static JSValueRef createJSObject(JSContextRef context,
89 const Api::Messaging::IMessagePtr& msg);
91 static JSValueRef createDummyMessageJSObject(JSContextRef context,
92 Api::Messaging::MessageType msgType);
96 * The callback invoked when an object is first created.
98 static void initialize(JSContextRef context,
102 * The callback invoked when an object is finalized.
104 static void finalize(JSObjectRef object);
107 * The callback invoked when determining whether an object has a property.
109 static bool hasProperty(JSContextRef context,
111 JSStringRef propertyName);
114 * The callback invoked when getting a property's value.
116 static JSValueRef getProperty(JSContextRef context,
118 JSStringRef propertyName,
119 JSValueRef* exception);
122 * The callback invoked when setting a property's value.
124 static bool setProperty(JSContextRef context,
126 JSStringRef propertyName,
128 JSValueRef* exception);
131 * The callback invoked when deleting a property.
133 static bool deleteProperty(JSContextRef context,
135 JSStringRef propertyName,
136 JSValueRef* exception);
139 * The callback invoked when collecting the names of an object's properties.
141 static void getPropertyNames(JSContextRef context,
143 JSPropertyNameAccumulatorRef propertyNames);
146 * The callback invoked when an object is called as a function.
148 static JSValueRef callAsFunction(JSContextRef context,
150 JSObjectRef thisObject,
151 size_t argumentCount,
152 const JSValueRef arguments[],
153 JSValueRef* exception);
156 * The callback invoked when an object is used as the target of an 'instanceof' expression.
158 static bool hasInstance(JSContextRef context,
159 JSObjectRef constructor,
160 JSValueRef possibleInstance,
161 JSValueRef* exception);
163 static JSObjectRef constructor(JSContextRef ctx,
164 JSObjectRef constructor,
165 size_t argumentCount,
166 const JSValueRef arguments[],
167 JSValueRef* exception);
170 * The callback invoked when converting an object to a particular JavaScript type.
172 static JSValueRef convertToType(JSContextRef context,
175 JSValueRef* exception);
176 static JSValueRef getAttachments(JSContextRef context,
178 JSStringRef propertyName,
179 JSValueRef* exception);
180 static JSValueRef getBccAddress(JSContextRef context,
182 JSStringRef propertyName,
183 JSValueRef* exception);
184 static JSValueRef getBody(JSContextRef context,
186 JSStringRef propertyName,
187 JSValueRef* exception);
188 static JSValueRef getCallbackNumber(JSContextRef context,
190 JSStringRef propertyName,
191 JSValueRef* exception);
192 static JSValueRef getCcAddress(JSContextRef context,
194 JSStringRef propertyName,
195 JSValueRef* exception);
196 static JSValueRef getDestinationAddress(JSContextRef context,
198 JSStringRef propertyName,
199 JSValueRef* exception);
200 static JSValueRef getIsRead(JSContextRef context,
202 JSStringRef propertyName,
203 JSValueRef* exception);
204 static JSValueRef getMessageId(JSContextRef context,
206 JSStringRef propertyName,
207 JSValueRef* exception);
208 static JSValueRef getMessagePriority(JSContextRef context,
210 JSStringRef propertyName,
211 JSValueRef* exception);
212 static JSValueRef getMessageType(JSContextRef context,
214 JSStringRef propertyName,
215 JSValueRef* exception);
216 static JSValueRef getSourceAddress(JSContextRef context,
218 JSStringRef propertyName,
219 JSValueRef* exception);
220 static JSValueRef getSubject(JSContextRef context,
222 JSStringRef propertyName,
223 JSValueRef* exception);
224 static JSValueRef getTime(JSContextRef context,
226 JSStringRef propertyName,
227 JSValueRef* exception);
228 static JSValueRef getFolder(JSContextRef context,
230 JSStringRef propertyName,
231 JSValueRef* exception);
232 static JSValueRef getMessageBody(JSContextRef context,
234 JSStringRef propertyName,
235 JSValueRef* exception);
236 static JSValueRef getAccountID(JSContextRef context,
238 JSStringRef propertyName,
239 JSValueRef* exception);
240 static JSValueRef getUID(JSContextRef context,
242 JSStringRef propertyName,
243 JSValueRef* exception);
244 #if 0 // MESSAGING ATTACHMENT IS BLOCKED
245 static bool setAttachments(JSContextRef context,
247 JSStringRef propertyName,
249 JSValueRef* exception);
251 static bool setAttachments(JSContextRef context,
253 JSStringRef propertyName,
255 JSValueRef* exception);
257 static bool setBccAddress(JSContextRef context,
259 JSStringRef propertyName,
261 JSValueRef* exception);
262 static bool setBody(JSContextRef context,
264 JSStringRef propertyName,
266 JSValueRef* exception);
267 static bool setCcAddress(JSContextRef context,
269 JSStringRef propertyName,
271 JSValueRef* exception);
272 static bool setDestinationAddress(JSContextRef context,
274 JSStringRef propertyName,
276 JSValueRef* exception);
277 static bool setIsRead(JSContextRef context,
279 JSStringRef propertyName,
281 JSValueRef* exception);
282 static bool setMessagePriority(JSContextRef context,
284 JSStringRef propertyName,
286 JSValueRef* exception);
287 static bool setSubject(JSContextRef context,
289 JSStringRef propertyName,
291 JSValueRef* exception);
292 static bool setMessageBody(JSContextRef context,
294 JSStringRef propertyName,
296 JSValueRef* exception);
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,
306 JSStringRef propertyName,
307 JSValueRef* exception);
308 static JSValueRef getInResponseTo(JSContextRef context,
310 JSStringRef propertyName,
311 JSValueRef* exception);
313 static JSValueRef getMessageStatus(JSContextRef context,
315 JSStringRef propertyName,
316 JSValueRef* exception);
318 static JSValueRef hasAttachment(JSContextRef context,
320 JSStringRef propertyName,
321 JSValueRef* exception);
324 * This structure describes a statically declared function property.
326 static JSStaticFunction m_function[];
329 * This structure contains properties and callbacks that define a type of object.
331 static JSClassDefinition m_classInfo;
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
337 static JSStaticValue m_property[];