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.
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_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";
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_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 },
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::CellularNetworkProperties &cellularNetworkInfo)
110 std::auto_ptr<Api::Systeminfo::CellularNetworkProperties> accProps(new Api::Systeminfo::CellularNetworkProperties(cellularNetworkInfo));
111 JSCellularNetworkPriv *priv = new JSCellularNetworkPriv(context, accProps.get());
113 return JSObjectMake(context, getClassRef(), priv);
116 JSValueRef JSCellularNetworkInfo::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
119 JSCellularNetworkPriv *priv = static_cast<JSCellularNetworkPriv*>(JSObjectGetPrivate(object));
121 LogError("Private object not set.");
122 return JSValueMakeUndefined(context);
127 Api::Systeminfo::CellularNetworkProperties *cellularNetworkInfo = priv->getObject();
128 Converter convert(context);
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);
152 LogError("Exception: " << _rethrown_exception.GetMessage());
154 return JSValueMakeUndefined(context);