Git Init
[profile/ivi/wrt-plugins-tizen.git] / src / standards / Tizen / Systeminfo / JSCellularNetworkInfo.cpp
1 /*
2  *
3  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
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
19 #include <memory>
20 #include <dpl/log.h>
21 #include "JSCellularNetworkInfo.h"
22
23 namespace TizenApis {
24 namespace Tizen1_0 {
25 using namespace WrtDeviceApis::CommonsJavaScript;
26 using namespace WrtDeviceApis::Commons;
27 using namespace Api::Systeminfo;
28
29 namespace {
30 const char* CELLULARNETWORK_STATUS_PROPERTY = "status";
31 const char* CELLULARNETWORK_APN_PROPERTY = "apn";
32 const char* CELLULARNETWORK_IPADDRESS_PROPERTY = "ipAddress";
33 const char* CELLULARNETWORK_MCC_PROPERTY = "mcc";
34 const char* CELLULARNETWORK_MNC_PROPERTY = "mnc";
35 const char* CELLULARNETWORK_CELLID_PROPERTY = "cellid";
36 const char* CELLULARNETWORK_LAC_PROPERTY = "lac";
37 const char* CELLULARNETWORK_SERVICETYPE_PROPERTY = "serviceType";
38 const char* CELLULARNETWORK_ROAMING_PROPERTY = "isRoaming";
39
40
41 JSClassRef JSCellularNetworkInfo::m_classRef = NULL;
42
43 JSClassDefinition JSCellularNetworkInfo::m_classInfo = {
44     0,
45     kJSClassAttributeNone,
46     "cellularnetworkinfo",
47     0,
48     m_properties,
49     NULL,
50     Initialize,
51     Finalize,
52     hasProperty,
53     getProperty,
54     NULL,
55     NULL,
56     NULL,
57     NULL,
58     NULL,
59     NULL,
60     NULL
61 };
62
63 JSStaticValue JSCellularNetworkInfo::m_properties[] = {
64     { CELLULARNETWORK_STATUS_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
65     { CELLULARNETWORK_APN_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
66     { CELLULARNETWORK_IPADDRESS_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },        
67     { CELLULARNETWORK_MCC_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },        
68     { CELLULARNETWORK_MNC_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },                
69     { CELLULARNETWORK_CELLID_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
70     { CELLULARNETWORK_LAC_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },        
71     { CELLULARNETWORK_SERVICETYPE_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },        
72     { CELLULARNETWORK_ROAMING_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },                
73     { 0, 0, 0, 0 }
74 };
75
76 const JSClassRef JSCellularNetworkInfo::getClassRef()
77 {
78     if (!m_classRef) {
79         m_classRef = JSClassCreate(&m_classInfo);
80     }
81     return m_classRef;
82 }
83
84 const JSClassDefinition* JSCellularNetworkInfo::getClassInfo()
85 {
86     return &m_classInfo;
87 }
88
89 void JSCellularNetworkInfo::Initialize(JSContextRef context, JSObjectRef object)
90 {
91 }
92
93 void JSCellularNetworkInfo::Finalize(JSObjectRef object)
94 {
95     LogDebug("Entered");
96     JSCellularNetworkPriv* priv = static_cast<JSCellularNetworkPriv*>(JSObjectGetPrivate(object));
97     JSObjectSetPrivate(object, NULL);
98     LogDebug("Deleting CellularNetworkInfo object");
99     delete priv;
100 }
101
102 bool JSCellularNetworkInfo::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
103 {
104     return JSUtils::hasProperty(m_properties, propertyName);
105 }
106
107 JSObjectRef JSCellularNetworkInfo::createJSObject(JSContextRef context, const Api::Systeminfo::CellularNetworkProperties &cellularNetworkInfo)
108 {
109     LogDebug("Enter");
110     std::auto_ptr<Api::Systeminfo::CellularNetworkProperties> accProps(new Api::Systeminfo::CellularNetworkProperties(cellularNetworkInfo));
111     JSCellularNetworkPriv *priv = new JSCellularNetworkPriv(context, accProps.get());
112     accProps.release();
113     return JSObjectMake(context, getClassRef(), priv);
114 }
115
116 JSValueRef JSCellularNetworkInfo::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
117 {
118     LogDebug("Enter");
119     JSCellularNetworkPriv *priv = static_cast<JSCellularNetworkPriv*>(JSObjectGetPrivate(object));
120     if (NULL == priv) {
121         LogError("Private object not set.");
122         return JSValueMakeUndefined(context);
123     }
124
125     Try
126     {
127         Api::Systeminfo::CellularNetworkProperties *cellularNetworkInfo = priv->getObject();
128         Converter convert(context);
129
130         if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_STATUS_PROPERTY)) {
131             return convert.toJSValueRef(cellularNetworkInfo->status);
132         } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_APN_PROPERTY)) {
133             return convert.toJSValueRef(cellularNetworkInfo->apn);
134         } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_IPADDRESS_PROPERTY)) {
135             return convert.toJSValueRef(cellularNetworkInfo->ipAddress);
136         } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_MCC_PROPERTY)) {
137             return convert.toJSValueRef(cellularNetworkInfo->mcc);
138         } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_MNC_PROPERTY)) {
139             return convert.toJSValueRef(cellularNetworkInfo->mnc);            
140         } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_CELLID_PROPERTY)) {
141             return convert.toJSValueRef(cellularNetworkInfo->cellid);            
142         } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_LAC_PROPERTY)) {
143             return convert.toJSValueRef(cellularNetworkInfo->lac);            
144         } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_SERVICETYPE_PROPERTY)) {
145             return convert.toJSValueRef(cellularNetworkInfo->serviceType);            
146         } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_ROAMING_PROPERTY)) {
147             return convert.toJSValueRef(cellularNetworkInfo->isRoaming);            
148         }            
149     }
150     Catch(Exception)
151     {
152         LogError("Exception: " << _rethrown_exception.GetMessage());
153     }
154     return JSValueMakeUndefined(context);
155 }
156 }
157 }