upload tizen1.0 source
[profile/ivi/wrt-plugins-tizen.git] / src / standards / Tizen / Route / RouteSegment.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
18 #include "RouteSegment.h"
19 #include "JSRouteSegment.h"
20 #include "JSSimpleCoordinates.h" 
21 #include "LBSUtil.h"
22 #include <CommonsJavaScript/Converter.h>
23  
24 using namespace std;
25 using namespace WrtDeviceApis::CommonsJavaScript;
26  
27 namespace TizenApis {
28 namespace Tizen1_0 {
29 namespace LBS{
30
31 RouteSegment::~RouteSegment()
32 {
33     std::vector<RouteStep*>::iterator pos;
34     for( pos = steps.begin() ; pos != steps.end() ; ++pos)
35         delete *pos;
36 }
37
38 JSObjectRef RouteSegment::toJSObject(JSContextRef ctx){
39     Converter convert(ctx);
40     JSObjectRef obj = JSObjectMake(ctx, JSRouteSegment::getClassRef(), NULL);
41
42     JSObjectRef originObj = JSObjectMake(ctx, Tizen::JSSimpleCoordinates::getClassRef(), NULL);
43     LBSUtil::setProperty(ctx, originObj, "latitude", originLatitude, kJSPropertyAttributeNone);
44     LBSUtil::setProperty(ctx, originObj, "longitude", orginLogitude, kJSPropertyAttributeNone);
45     LBSUtil::setProperty(ctx, obj, "origin", originObj, kJSPropertyAttributeNone);
46
47     JSObjectRef destObj = JSObjectMake(ctx, Tizen::JSSimpleCoordinates::getClassRef(), NULL);
48     LBSUtil::setProperty(ctx, destObj, "latitude", destLatitude, kJSPropertyAttributeNone);
49     LBSUtil::setProperty(ctx, destObj, "longitude", destLogitude, kJSPropertyAttributeNone);
50     LBSUtil::setProperty(ctx, obj, "destination", destObj, kJSPropertyAttributeNone);
51     
52     LBSUtil::setProperty(ctx, obj, "distance", totalDistance.toJSObject(ctx), kJSPropertyAttributeNone);
53     LBSUtil::setProperty(ctx, obj, "duration", totalDuration.toJSObject(ctx), kJSPropertyAttributeNone);    
54
55     int length = steps.size();
56     JSValueRef* stepsArray = NULL;
57     stepsArray = new JSValueRef[length];
58     
59     for(int i = 0; i < length ; i++){
60         stepsArray[i] = (*(steps[i])).toJSObject(ctx);
61     }
62     JSObjectRef stepsObj = JSObjectMakeArray(ctx, length, stepsArray, NULL);
63     LBSUtil::setProperty(ctx, obj, "steps", stepsObj , kJSPropertyAttributeReadOnly);
64     delete [] stepsArray;    
65
66     return obj;
67 }
68
69
70 } //LBS
71 } //Tizen1_0
72 }//LBS