3 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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.
20 #include <dpl/log/log.h>
21 #include "JSCellularNetworkInfo.h"
25 using namespace WrtDeviceApis::CommonsJavaScript;
26 using namespace WrtDeviceApis::Commons;
27 using namespace Api::Systeminfo;
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_IPV6ADDRESS_PROPERTY = "ipv6Address";
34 const char* CELLULARNETWORK_MCC_PROPERTY = "mcc";
35 const char* CELLULARNETWORK_MNC_PROPERTY = "mnc";
36 const char* CELLULARNETWORK_CELLID_PROPERTY = "cellId";
37 const char* CELLULARNETWORK_LAC_PROPERTY = "lac";
38 const char* CELLULARNETWORK_ROAMING_PROPERTY = "isRoaming";
41 JSClassRef JSCellularNetworkInfo::m_classRef = NULL;
43 JSClassDefinition JSCellularNetworkInfo::m_classInfo = {
45 kJSClassAttributeNone,
46 "cellularnetworkinfo",
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_IPV6ADDRESS_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
68 { CELLULARNETWORK_MCC_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
69 { CELLULARNETWORK_MNC_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
70 { CELLULARNETWORK_CELLID_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
71 { CELLULARNETWORK_LAC_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
72 { CELLULARNETWORK_ROAMING_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
76 const JSClassRef JSCellularNetworkInfo::getClassRef()
79 m_classRef = JSClassCreate(&m_classInfo);
84 const JSClassDefinition* JSCellularNetworkInfo::getClassInfo()
89 void JSCellularNetworkInfo::Initialize(JSContextRef context, JSObjectRef object)
93 void JSCellularNetworkInfo::Finalize(JSObjectRef object)
96 JSCellularNetworkPriv* priv = static_cast<JSCellularNetworkPriv*>(JSObjectGetPrivate(object));
97 JSObjectSetPrivate(object, NULL);
98 LogDebug("Deleting CellularNetworkInfo object");
102 bool JSCellularNetworkInfo::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
104 return JSUtils::hasProperty(m_properties, propertyName);
107 JSObjectRef JSCellularNetworkInfo::createJSObject(JSContextRef context, const Api::Systeminfo::CellularNetworkPropertiesPtr cellularNetworkInfo)
110 JSCellularNetworkPriv *priv = new JSCellularNetworkPriv(context, cellularNetworkInfo);
111 return JSObjectMake(context, getClassRef(), priv);
114 JSValueRef JSCellularNetworkInfo::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
117 JSCellularNetworkPriv *priv = static_cast<JSCellularNetworkPriv*>(JSObjectGetPrivate(object));
119 LogError("Private object not set.");
120 return JSValueMakeUndefined(context);
125 Api::Systeminfo::CellularNetworkPropertiesPtr cellularNetworkInfo = priv->getObject();
126 Converter convert(context);
128 if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_STATUS_PROPERTY)) {
129 return convert.toJSValueRef(cellularNetworkInfo->status);
130 } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_APN_PROPERTY)) {
131 return convert.toJSValueRef(cellularNetworkInfo->apn);
132 } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_IPADDRESS_PROPERTY)) {
133 return convert.toJSValueRef(cellularNetworkInfo->ipAddress);
134 } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_IPV6ADDRESS_PROPERTY)) {
135 return convert.toJSValueRef(cellularNetworkInfo->ipv6Address);
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_ROAMING_PROPERTY)) {
145 return convert.toJSValueRef(cellularNetworkInfo->isRoaming);
150 LogError("Exception: " << _rethrown_exception.GetMessage());
152 return JSValueMakeUndefined(context);