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