upload tizen1.0 source
[profile/ivi/wrt-plugins-tizen.git] / src / standards / Tizen / POI / JSGeoRectBounds.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 #include <CommonsJavaScript/Converter.h>
18 #include <CommonsJavaScript/Validator.h>
19 #include <CommonsJavaScript/JSUtils.h>
20 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
21 #include <Tizen/Common/JSTizenExceptionFactory.h>
22 #include <Tizen/Common/JSTizenException.h>
23 #include <Tizen/Common/SecurityExceptions.h>
24 #include "JSSimpleCoordinates.h"
25 #include "JSGeoRectBounds.h"
26 #include "LBSUtil.h"
27
28 #include <dlog.h>
29
30 #undef LOG_TAG
31 #define LOG_TAG "TIZEN_POI"
32
33 using namespace std;
34 using namespace WrtDeviceApis::CommonsJavaScript;
35
36 namespace TizenApis {
37 namespace Tizen1_0 {
38 namespace LBS {
39
40 JSClassRef JSGeoRectBounds::m_jsClassRef = NULL;
41
42 JSClassDefinition JSGeoRectBounds::m_jsClassInfo = {
43         0,                                                                                                                              // current (and only) version is 0
44         kJSClassAttributeNone,                                                  //attributes
45         "GeoRectBounds",                                                                                                                // class name
46         NULL,                                                                                                           // parent class
47         NULL,                                                                                                           // static values
48         NULL,           // static functions
49         JSGeoRectBounds::initialize,                    // initialize
50         JSGeoRectBounds::finalize,
51         NULL, //hasProperty
52         NULL, //getProperty
53         NULL, //setProperty
54         NULL, //deleteProperty
55         NULL, //getPropertyNames
56         NULL,
57         JSGeoRectBounds::constructor, // constructor
58         JSGeoRectBounds::hasInstance,
59         NULL
60 };
61
62
63
64 const JSClassRef JSGeoRectBounds::getClassRef() 
65 {
66         if (!m_jsClassRef) {
67                 m_jsClassRef = JSClassCreate(&m_jsClassInfo);
68         }
69         return m_jsClassRef;
70 }
71
72 const JSClassDefinition* JSGeoRectBounds::getClassInfo() 
73 {
74         return &m_jsClassInfo;
75 }
76
77 JSObjectRef JSGeoRectBounds::constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){
78         JSValueRef convertedArguments[2];
79         for( unsigned int i = 0 ; i < 2; i++ ){
80                 if( i < argumentCount )
81                         convertedArguments[i] = arguments[i];
82                 else
83                         convertedArguments[i] = JSValueMakeUndefined(ctx);
84         }
85
86         if( !JSValueIsObjectOfClass(ctx, convertedArguments[0],TizenApis::Tizen1_0::Tizen::JSSimpleCoordinates::getClassRef() ) || !JSValueIsObjectOfClass(ctx, convertedArguments[1],TizenApis::Tizen1_0::Tizen::JSSimpleCoordinates::getClassRef() ) ){
87                 *exception = Commons::JSTizenExceptionFactory::makeErrorObject(ctx, Commons::JSTizenException::TYPE_MISMATCH_ERROR, "Arguments are not SimpleCoordinates");
88                 return NULL;
89         }
90
91         JSObjectRef obj = JSObjectMake(ctx, getClassRef(), NULL);       
92
93         LBSUtil::setProperty(ctx , obj ,"northEast" ,convertedArguments[0], kJSPropertyAttributeReadOnly );
94         LBSUtil::setProperty(ctx , obj ,"southWest" ,convertedArguments[1], kJSPropertyAttributeReadOnly );
95
96         return obj;
97 }
98
99
100 void JSGeoRectBounds::initialize(JSContextRef ctx, JSObjectRef object) 
101 {
102 }
103
104 void JSGeoRectBounds::finalize(JSObjectRef object) 
105 {
106 }
107
108 bool JSGeoRectBounds::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception) {
109         return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
110 }
111
112
113 } //LBS
114 } // Tizen1_0
115 } // TizenApis
116
117
118