tizen 2.3.1 release
[framework/web/wearable/wrt-plugins-tizen.git] / src / TimeUtil / JSTimeDuration.h
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #ifndef __TIZEN_JS_TIMEDURATION_H_
19 #define __TIZEN_JS_TIMEDURATION_H_
20
21 #include "TimeDuration.h"
22 #include <PlatformException.h>
23 #include <Logger.h>
24 #include <JSUtil.h>
25
26 #ifdef IMPL_BACKWARD_COMPATIBLE
27 #include <CommonsJavaScript/PrivateObject.h>
28 #include "DurationProperties.h"
29 #endif // IMPL_BACKWARD_COMPATIBLE
30
31 namespace DeviceAPI {
32 namespace Time {
33
34 #ifdef IMPL_BACKWARD_COMPATIBLE
35 typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<
36              DurationPropertiesPtr>::
37     Type TimeDurationPrivObject;
38 #endif // IMPL_BACKWARD_COMPATIBLE
39
40 /**
41  * @class JSTimeDuration
42  * @brief This class is javascript extension
43  *
44  */
45 class JSTimeDuration {
46 public:
47     /**
48      * Gets object's class description.
49      */
50     static const JSClassDefinition* getClassInfo();
51
52     /**
53      * Gets class definition reference.
54      * @remarks New instance of JSClassRef is created (only once) if none was
55      * @remarks set before.
56      * @return Class reference.
57      */
58     static const JSClassRef getClassRef();
59
60     static JSObjectRef constructor(JSContextRef context,
61             JSObjectRef constructor,
62             size_t argumentCount,
63             const JSValueRef arguments[],
64             JSValueRef* exception);
65
66     static TimeDurationPtr getPrivateObject(JSContextRef context, JSValueRef value);
67
68     static void setPrivateObject(JSObjectRef object, TimeDurationPtr native);
69
70     static JSObjectRef makeJSObject(JSContextRef context, TimeDurationPtr native);
71
72 #ifdef IMPL_BACKWARD_COMPATIBLE
73     static JSObjectRef createJSObject(JSContextRef context, const DurationProperties &durations);
74     static JSObjectRef createJSObject(JSContextRef context, const DurationPropertiesPtr duration);
75 #endif // IMPL_BACKWARD_COMPATIBLE
76
77 private:
78     /**
79      * This structure contains properties and callbacks that define a type of object.
80      */
81     static JSClassDefinition m_classInfo;
82
83     /**
84      * This member variable contains the initialization values for the static properties
85      * of this class.
86      * The values are given according to the data structure JSPropertySpec
87      */
88     static JSStaticValue m_property[];
89
90     /**
91      * This structure describes a statically declared function property.
92      */
93     static JSStaticFunction m_function[];
94
95     static JSClassRef m_jsClassRef;
96
97     /**
98      * The callback invoked when an object is first created.
99      */
100     static void initialize(JSContextRef context, JSObjectRef object);
101
102     /**
103      * The callback invoked when an object is finalized.
104      */
105     static void finalize(JSObjectRef object);
106
107     /**
108      * Getters for properties
109      */
110     static JSValueRef getLength(JSContextRef context,
111             JSObjectRef object,
112             JSStringRef propertyName,
113             JSValueRef* exception);
114
115     static JSValueRef getUnit(JSContextRef context,
116             JSObjectRef object,
117             JSStringRef propertyName,
118             JSValueRef* exception);
119
120     static bool setLength(JSContextRef context,
121             JSObjectRef object,
122             JSStringRef propertyName,
123             JSValueRef value,
124             JSValueRef* exception);
125
126     static bool setUnit(JSContextRef context,
127             JSObjectRef object,
128             JSStringRef propertyName,
129             JSValueRef value,
130             JSValueRef* exception);
131
132     /**
133      * Functions declaration for the JSTimeDuration interface.
134      */
135     static JSValueRef difference(JSContextRef context,
136             JSObjectRef function,
137             JSObjectRef thisObject,
138             size_t argumentCount,
139             const JSValueRef arguments[],
140             JSValueRef * exception);
141
142     static JSValueRef equalsTo(JSContextRef context,
143             JSObjectRef function,
144             JSObjectRef thisObject,
145             size_t argumentCount,
146             const JSValueRef arguments[],
147             JSValueRef * exception);
148
149     static JSValueRef lessThan(JSContextRef context,
150             JSObjectRef function,
151             JSObjectRef thisObject,
152             size_t argumentCount,
153             const JSValueRef arguments[],
154             JSValueRef * exception);
155
156     static JSValueRef greaterThan(JSContextRef context,
157             JSObjectRef function,
158             JSObjectRef thisObject,
159             size_t argumentCount,
160             const JSValueRef arguments[],
161             JSValueRef * exception);
162 };
163
164 }
165 }
166
167 #endif // __TIZEN_JS_TIMEDURATION_H_