2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <JSTizenExceptionFactory.h>
20 #include <JSTizenException.h>
21 #include <SecurityExceptions.h>
22 #include "JSCellularNetworkInfo.h"
23 #include "plugin_config.h"
27 namespace Systeminfo {
28 using namespace WrtDeviceApis::CommonsJavaScript;
29 using namespace WrtDeviceApis::Commons;
30 using namespace DeviceAPI::Common;
33 const char* CELLULARNETWORK_STATUS_PROPERTY = "status";
34 const char* CELLULARNETWORK_APN_PROPERTY = "apn";
35 const char* CELLULARNETWORK_IPADDRESS_PROPERTY = "ipAddress";
36 const char* CELLULARNETWORK_IPV6ADDRESS_PROPERTY = "ipv6Address";
37 const char* CELLULARNETWORK_MCC_PROPERTY = "mcc";
38 const char* CELLULARNETWORK_MNC_PROPERTY = "mnc";
39 const char* CELLULARNETWORK_CELLID_PROPERTY = "cellId";
40 const char* CELLULARNETWORK_LAC_PROPERTY = "lac";
41 const char* CELLULARNETWORK_ROAMING_PROPERTY = "isRoaming";
42 const char* CELLULARNETWORK_FLIGHT_MODE_PROPERTY = "isFlightMode";
43 const char* CELLULARNETWORK_IMEI_PROPERTY = "imei";
46 JSClassRef JSCellularNetworkInfo::m_classRef = NULL;
48 JSClassDefinition JSCellularNetworkInfo::m_classInfo = {
50 kJSClassAttributeNone,
51 "cellularnetworkinfo",
68 JSStaticValue JSCellularNetworkInfo::m_properties[] = {
69 { CELLULARNETWORK_STATUS_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
70 { CELLULARNETWORK_APN_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
71 { CELLULARNETWORK_IPADDRESS_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
72 { CELLULARNETWORK_IPV6ADDRESS_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
73 { CELLULARNETWORK_MCC_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
74 { CELLULARNETWORK_MNC_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
75 { CELLULARNETWORK_CELLID_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
76 { CELLULARNETWORK_LAC_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
77 { CELLULARNETWORK_ROAMING_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
78 { CELLULARNETWORK_FLIGHT_MODE_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
79 { CELLULARNETWORK_IMEI_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
83 const JSClassRef JSCellularNetworkInfo::getClassRef()
86 m_classRef = JSClassCreate(&m_classInfo);
91 const JSClassDefinition* JSCellularNetworkInfo::getClassInfo()
96 void JSCellularNetworkInfo::Initialize(JSContextRef context, JSObjectRef object)
100 void JSCellularNetworkInfo::Finalize(JSObjectRef object)
103 JSCellularNetworkPriv* priv = static_cast<JSCellularNetworkPriv*>(JSObjectGetPrivate(object));
104 JSObjectSetPrivate(object, NULL);
105 LoggerD("Deleting CellularNetworkInfo object");
109 bool JSCellularNetworkInfo::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
111 return JSUtils::hasProperty(m_properties, propertyName);
114 JSObjectRef JSCellularNetworkInfo::createJSObject(JSContextRef context, const CellularNetworkPropertiesPtr cellularNetworkInfo)
117 JSCellularNetworkPriv *priv = new JSCellularNetworkPriv(context, cellularNetworkInfo);
118 return JSObjectMake(context, getClassRef(), priv);
121 JSValueRef JSCellularNetworkInfo::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
124 JSCellularNetworkPriv *priv = static_cast<JSCellularNetworkPriv*>(JSObjectGetPrivate(object));
126 LoggerE("Private object not set.");
127 return JSValueMakeUndefined(context);
132 CellularNetworkPropertiesPtr cellularNetworkInfo = priv->getObject();
133 Converter convert(context);
135 if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_STATUS_PROPERTY)) {
136 return convert.toJSValueRef(cellularNetworkInfo->status);
137 } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_APN_PROPERTY)) {
138 return convert.toJSValueRef(cellularNetworkInfo->apn);
139 } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_IPADDRESS_PROPERTY)) {
140 return convert.toJSValueRef(cellularNetworkInfo->ipAddress);
141 } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_IPV6ADDRESS_PROPERTY)) {
142 return convert.toJSValueRef(cellularNetworkInfo->ipv6Address);
143 } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_MCC_PROPERTY)) {
144 return convert.toJSValueRef(cellularNetworkInfo->mcc);
145 } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_MNC_PROPERTY)) {
146 return convert.toJSValueRef(cellularNetworkInfo->mnc);
147 } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_CELLID_PROPERTY)) {
148 return convert.toJSValueRef(cellularNetworkInfo->cellId);
149 } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_LAC_PROPERTY)) {
150 return convert.toJSValueRef(cellularNetworkInfo->lac);
151 } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_ROAMING_PROPERTY)) {
152 return convert.toJSValueRef(cellularNetworkInfo->isRoaming);
153 } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_FLIGHT_MODE_PROPERTY)) {
154 return convert.toJSValueRef(cellularNetworkInfo->isFlightMode);
155 } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_IMEI_PROPERTY)) {
156 AceSecurityStatus status = SYSTEMINFO_CHECK_ACCESS(SYSTEMINFO_FUNCTION_API_GET_PROPERTY_PARTNER_VALUE);
157 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
158 return convert.toJSValueRef(cellularNetworkInfo->imei);
163 LoggerE("Exception: " << _rethrown_exception.GetMessage());
165 return JSValueMakeUndefined(context);