tizen 2.4 release
[framework/web/wrt-plugins-common.git] / src / CommonsJavaScript / JSPendingOperation.cpp
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  * @file        JSPendingOperation.cpp
18  * @author      Pete Cole (peter.cole@partner.samsung.com)
19  * @version     0.1
20  *              0.2 k.majewski@samsung.com
21  * @brief       Implementation of the JSPendingOperation class
22  */
23
24 #include <Commons/IEvent.h>
25 #include "JSPendingOperation.h"
26 #include "JSPendingOperationPrivateObject.h"
27
28 namespace WrtDeviceApis {
29 namespace CommonsJavaScript {
30 namespace {
31 const char* PLUGIN_NAME = "PendingOperation";
32 }
33
34 JSClassRef JSPendingOperation::m_classRef = NULL;
35
36 JSClassDefinition JSPendingOperation::m_classInfo = {
37     0,
38     kJSClassAttributeNone,
39     PLUGIN_NAME,
40     0,
41     NULL,
42     m_functions,
43     initialize,
44     finalize,
45     NULL, //hasProperty,
46     NULL, //GetProperty,
47     NULL, //SetProperty,
48     NULL, //DeleteProperty,
49     NULL, //getPropertyNames,
50     NULL,
51     NULL,
52     NULL,
53     NULL, //ConvertToType,
54 };
55
56 JSStaticFunction JSPendingOperation::m_functions[] = {
57     { "cancel", cancel, kJSPropertyAttributeNone },
58     { 0, 0, 0 }
59 };
60
61 JSClassRef JSPendingOperation::getClassRef()
62 {
63     if (!m_classRef) {
64         m_classRef = JSClassCreate(&m_classInfo);
65     }
66     return m_classRef;
67 }
68
69 void JSPendingOperation::initialize(JSContextRef /*context*/,
70                                     JSObjectRef object)
71 {
72     Assert(NULL != JSObjectGetPrivate(object));
73 }
74
75 void JSPendingOperation::finalize(JSObjectRef object)
76 {
77     delete static_cast<IJSPendingOperationPrivateObject *>(
78         JSObjectGetPrivate(object));
79 }
80
81 JSValueRef JSPendingOperation::cancel(JSContextRef context,
82                                       JSObjectRef object,
83                                       JSObjectRef thisObject,
84                                       size_t argumentCount,
85                                       const JSValueRef arguments[],
86                                       JSValueRef* exception)
87 {
88     (void) object;
89     (void) argumentCount;
90     (void) arguments;
91     (void) exception;
92     LogDebug(__FUNCTION__);
93     IJSPendingOperationPrivateObject *priv =
94         static_cast<IJSPendingOperationPrivateObject *>(
95             JSObjectGetPrivate(thisObject));
96     Assert(NULL != priv);
97     bool cancelResult = priv->cancel();
98     LogDebug("cancel result : " << cancelResult);
99     return JSValueMakeBoolean(context, cancelResult);
100 }
101 } // CommonsJavaScript
102 } // WrtDeviceApis
103