Beta merge 2
[profile/ivi/wrt-plugins-tizen.git] / src / standards / Tizen / TimeUtil / JSTimeDuration.h
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
18
19 #ifndef WRT_PLUGINS_TIZEN_1_0_JS_TIMEDURATION_H_
20 #define WRT_PLUGINS_TIZEN_1_0_JS_TIMEDURATION_H_
21
22 #include <dpl/shared_ptr.h>
23 #include <JavaScriptCore/JavaScript.h>
24 #include <CommonsJavaScript/PrivateObject.h>
25 #include <API/TimeUtil/DurationProperties.h>
26
27 namespace TizenApis {
28 namespace Tizen1_0 {
29 typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<
30             TizenApis::Api::TimeUtil::DurationProperties*>::
31     Type TimeDurationPrivObject;
32
33 /**
34  * @class JSTimeDuration
35  * @brief This class is javascript extension
36  *
37  */
38 class JSTimeDuration
39 {
40   public:
41     /**
42      * Gets object's class description.
43      */
44     static const JSClassDefinition* getClassInfo();
45
46     /**
47      * Gets class definition reference.
48      * @remarks New instance of JSClassRef is created (only once) if none was
49      * @remarks set before.
50      * @return Class reference.
51      */
52     static const JSClassRef getClassRef();
53     static JSObjectRef createJSObject(JSContextRef context, const Api::TimeUtil::DurationProperties &durations);
54   private:
55         enum CompareType {
56                 DIFFERENCE,
57                 EQUALSTO,
58                 LESSTHAN,
59                 GREATERTHAN
60                 };
61     /**
62      * The callback invoked when an object is first created.
63      */
64     static void initialize(JSContextRef context,
65             JSObjectRef object);
66
67     /**
68      * The callback invoked when an object is finalized.
69      */
70     static void finalize(JSObjectRef object);
71
72     /**
73      * Getters for properties
74      */
75     static JSValueRef getProperty(JSContextRef context, JSObjectRef object,
76             JSStringRef propertyName, JSValueRef* exception);
77
78     static bool setProperty(JSContextRef context, JSObjectRef object,
79             JSStringRef propertyName,  JSValueRef value,  JSValueRef* exception);
80
81     static JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
82
83     /**
84      * The callback invoked when an object is used as the target of an 'instanceof' expression.
85      */
86     static bool hasInstance(JSContextRef context,
87             JSObjectRef constructor,
88             JSValueRef possibleInstance,
89             JSValueRef* exception);
90
91     static JSValueRef diffTimeDuration(JSContextRef context, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception, CompareType type);
92     static JSValueRef difference(JSContextRef context, JSObjectRef function, 
93         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
94     static JSValueRef equalsTo(JSContextRef context, JSObjectRef function, 
95         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
96     static JSValueRef lessThan(JSContextRef context, JSObjectRef function, 
97         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
98     static JSValueRef greaterThan(JSContextRef context, JSObjectRef function, 
99         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
100
101     /**
102      * This structure contains properties and callbacks that define a type of object.
103      */
104     static JSClassDefinition m_classInfo;
105
106     static JSClassRef m_jsClassRef;
107
108     /**
109      * This structure describes a statically declared function property.
110      */
111     static JSStaticFunction m_function[];
112
113     /**
114      * This member variable contains the initialization values for the 
115      * properties of this class. The values are given according to the
116      * data structure JSPropertySpec.
117      */
118     static JSStaticValue m_property[];
119 };
120 }
121 }
122
123 #endif //WRT_PLUGINS_TIZEN_1_0_JS_TIMEDURATION_H_