|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "config.h" |
|
21 #include "Device.h" |
|
22 #include "ServiceObject.h" |
|
23 #include "ServiceEventHandler.h" |
|
24 #include "DeviceBridge.h" |
|
25 #include "DeviceBinding.h" |
|
26 #include "DeviceLiwBinding.h" |
|
27 #include <LiwServiceHandler.h> |
|
28 |
|
29 using namespace KJS; |
|
30 |
|
31 const ClassInfo Device::info = { "Device", 0, 0, 0 }; |
|
32 const TInt INIT_SO_ARRAY_SIZE = 10; // initial service object array |
|
33 |
|
34 // ============================= LOCAL FUNCTIONS =============================== |
|
35 /* |
|
36 @begin DeviceTable 1 |
|
37 getServiceObject Device::getServiceObject DontDelete|Function 2 |
|
38 listProviders Device::listProviders DontDelete|Function 2 |
|
39 @end |
|
40 */ |
|
41 |
|
42 // ============================ MEMBER FUNCTIONS =============================== |
|
43 |
|
44 // ---------------------------------------------------------------------------- |
|
45 // Device::Device |
|
46 // |
|
47 // ---------------------------------------------------------------------------- |
|
48 // |
|
49 Device::Device( ExecState* exec ) |
|
50 : JSObject() |
|
51 { |
|
52 m_privateData = new DevicePrivate(); |
|
53 if (!m_privateData || !m_privateData->m_deviceBinding ) |
|
54 m_valid = false; |
|
55 else |
|
56 m_valid = true; |
|
57 } |
|
58 |
|
59 |
|
60 // ---------------------------------------------------------------------------- |
|
61 // Device::SetUid |
|
62 // |
|
63 // ---------------------------------------------------------------------------- |
|
64 // |
|
65 void Device::SetUid( const TUint& aValue) |
|
66 { |
|
67 if(m_privateData) |
|
68 m_privateData->SetUid( aValue); |
|
69 } |
|
70 |
|
71 // ---------------------------------------------------------------------------- |
|
72 // Device::Close |
|
73 // |
|
74 // ---------------------------------------------------------------------------- |
|
75 // |
|
76 void Device::Close() |
|
77 { |
|
78 delete m_privateData; |
|
79 m_privateData = NULL; |
|
80 } |
|
81 |
|
82 |
|
83 // ---------------------------------------------------------------------------- |
|
84 // Device::~Device |
|
85 // |
|
86 // ---------------------------------------------------------------------------- |
|
87 // |
|
88 Device::~Device() |
|
89 { |
|
90 Close(); |
|
91 } |
|
92 |
|
93 // ---------------------------------------------------------------------------- |
|
94 // Device::toString |
|
95 // |
|
96 // ---------------------------------------------------------------------------- |
|
97 // |
|
98 UString Device::toString( ExecState* /*exec*/ ) const |
|
99 { |
|
100 return "[object Device]"; |
|
101 } |
|
102 |
|
103 // ---------------------------------------------------------------------------- |
|
104 // Device::getOwnPropertySlot |
|
105 // |
|
106 // |
|
107 // ---------------------------------------------------------------------------- |
|
108 bool Device::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) |
|
109 { |
|
110 m_privateData->m_exec = exec; |
|
111 m_privateData->m_propName = propertyName; |
|
112 const HashEntry* entry = Lookup::findEntry(&DeviceTable, propertyName); |
|
113 if (entry) |
|
114 { |
|
115 slot.setStaticEntry(this, entry, staticValueGetter<Device>); |
|
116 return true; |
|
117 } |
|
118 |
|
119 return JSObject::getOwnPropertySlot(exec, propertyName, slot); |
|
120 } |
|
121 |
|
122 |
|
123 // ---------------------------------------------------------------------------- |
|
124 // JSVersion::getValueProperty |
|
125 // |
|
126 // |
|
127 // ---------------------------------------------------------------------------- |
|
128 JSValue* Device::getValueProperty(ExecState *exec, int token) const |
|
129 { |
|
130 switch( token ) |
|
131 { |
|
132 case getServiceObject: |
|
133 case listProviders: |
|
134 return new DeviceFunc( exec, m_privateData->m_deviceBinding, token ); |
|
135 |
|
136 default: |
|
137 return throwError(exec, GeneralError); |
|
138 } |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // DevicePrivate constructor |
|
143 // |
|
144 // --------------------------------------------------------------------------- |
|
145 DevicePrivate::DevicePrivate() |
|
146 { |
|
147 m_deviceBinding = NULL; |
|
148 TRAP_IGNORE( |
|
149 m_serviceObjArray = new RPointerArray<ServiceObject>( INIT_SO_ARRAY_SIZE ); |
|
150 m_deviceBinding = CDeviceLiwBinding::NewL(); |
|
151 m_exec = NULL;) |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------------------------- |
|
155 // DevicePrivate Close |
|
156 // |
|
157 // --------------------------------------------------------------------------- |
|
158 void DevicePrivate::Close() |
|
159 { |
|
160 if ( m_serviceObjArray ) |
|
161 { |
|
162 // close all the service objects created for this device |
|
163 for (int i = 0; i < m_serviceObjArray->Count(); i++) |
|
164 { |
|
165 (*m_serviceObjArray)[i]->Close( m_exec, true ); |
|
166 } |
|
167 m_serviceObjArray->Close(); |
|
168 delete m_serviceObjArray; |
|
169 m_serviceObjArray = NULL; |
|
170 } |
|
171 delete m_deviceBinding; |
|
172 m_deviceBinding = NULL; |
|
173 } |
|
174 |
|
175 // --------------------------------------------------------------------------- |
|
176 // DevicePrivate SetUid |
|
177 // |
|
178 // --------------------------------------------------------------------------- |
|
179 void DevicePrivate::SetUid( const TUint& aValue) |
|
180 { |
|
181 if(m_deviceBinding) |
|
182 m_deviceBinding->SetUid( aValue); |
|
183 } |
|
184 |
|
185 // ---------------------------------------------------------------------------- |
|
186 // DeviceFunc::DeviceFunc |
|
187 // |
|
188 // |
|
189 // ---------------------------------------------------------------------------- |
|
190 // |
|
191 DeviceFunc::DeviceFunc( ExecState* exec, MDeviceBinding* deviceBinding, |
|
192 int token ) |
|
193 : JSObject( exec->lexicalInterpreter()->builtinObjectPrototype() ), |
|
194 m_deviceBinding( deviceBinding ), |
|
195 m_func( token ) |
|
196 { |
|
197 } |
|
198 |
|
199 // ---------------------------------------------------------------------------- |
|
200 // DeviceFunc::callAsFunction |
|
201 // |
|
202 // ---------------------------------------------------------------------------- |
|
203 // |
|
204 JSValue* DeviceFunc::callAsFunction(ExecState *exec, JSObject *thisObj, const List &args) |
|
205 { |
|
206 TInt err = KErrNone; |
|
207 JSValue* ret = jsUndefined(); |
|
208 |
|
209 if ( !m_deviceBinding ) |
|
210 { |
|
211 return ret; |
|
212 } |
|
213 |
|
214 if ( m_func == Device::getServiceObject ) |
|
215 { |
|
216 err = m_deviceBinding->LoadServiceProvider( exec, args ); |
|
217 if ( err != KErrNone ) |
|
218 { |
|
219 char * err_msg = "general error "; |
|
220 // process TLiwLoadStatus errors |
|
221 switch ( err ) |
|
222 { |
|
223 case KLiwUnknown: // -5 |
|
224 err_msg = "unknown error"; |
|
225 break; |
|
226 case KLiwMetaDataInvalidFormat: //-4 |
|
227 err_msg = "meta data invalid format"; |
|
228 break; |
|
229 case KLiwInvalidVersionSpecification: //-3 |
|
230 err_msg = "invalid version specification"; |
|
231 break; |
|
232 case KLiwVersionOutOfRange: //-2 |
|
233 err_msg = "version out of range"; |
|
234 break; |
|
235 case KLiwSecurityAccessCheckFailed: //-1 |
|
236 err_msg = "security access check failed"; |
|
237 break; |
|
238 } |
|
239 throwError(exec, GeneralError, err_msg); |
|
240 } |
|
241 else |
|
242 { |
|
243 int argcount = args.size(); |
|
244 if ( argcount == 0 || args[0]->type() != StringType || args[0]->toString( exec ).size() == 0 ) |
|
245 return ret; |
|
246 // Get service name |
|
247 HBufC8* svcName = KJS::GetAsciiBufferL( args[0]->toString( exec ) ); |
|
248 |
|
249 ServiceObject *so = new ServiceObject( exec, svcName, m_deviceBinding ); |
|
250 if ( so != NULL ) |
|
251 { |
|
252 (static_cast<Device*>(thisObj))->m_privateData->m_serviceObjArray->Append( so ); |
|
253 ret = so; |
|
254 } |
|
255 } |
|
256 } |
|
257 else if ( m_func == Device::listProviders ) |
|
258 { |
|
259 ret = m_deviceBinding->ListProviders( exec, args ); |
|
260 } |
|
261 |
|
262 return ret; |
|
263 } |
|
264 |
|
265 //END OF FILE |
|
266 |
|
267 |
|
268 |