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