1 /* |
|
2 * Copyright (c) 2009 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 "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 #include <stdio.h> |
|
19 #include <stdlib.h> |
|
20 #include <assert.h> |
|
21 #include "xaledarraydevice.h" |
|
22 #include "xaledarrayitf.h" |
|
23 #include "xaconfigextensionsitf.h" |
|
24 #include "xadynintmgmtitf.h" |
|
25 #include "xathreadsafety.h" |
|
26 #include "xaledarrayadaptctx.h" |
|
27 |
|
28 /* Static mapping of enumeration XALEDArrayDeviceInterfaces to interface iids */ |
|
29 static const XAInterfaceID* XALEDArrayDeviceItfIIDs[LEDARRAY_ITFCOUNT]= |
|
30 { |
|
31 &XA_IID_OBJECT, |
|
32 &XA_IID_LED, |
|
33 &XA_IID_CONFIGEXTENSION, |
|
34 &XA_IID_DYNAMICINTERFACEMANAGEMENT, |
|
35 }; |
|
36 |
|
37 |
|
38 /***************************************************************************** |
|
39 * Global methods |
|
40 *****************************************************************************/ |
|
41 |
|
42 /* XAResult XALEDArrayDeviceImpl_Create |
|
43 * Description: Create object |
|
44 */ |
|
45 XAresult XALEDArrayDeviceImpl_CreateLEDArrayDevice(FrameworkMap* mapper, |
|
46 XAObjectItf* pDevice, |
|
47 XAuint32 deviceID, |
|
48 XAuint32 numInterfaces, |
|
49 const XAInterfaceID * pInterfaceIds, |
|
50 const XAboolean * pInterfaceRequired) |
|
51 { |
|
52 |
|
53 |
|
54 XAuint8 itfIndex = 0; |
|
55 |
|
56 XALEDArrayDeviceImpl* pImpl = NULL; |
|
57 XAObjectItfImpl* pBaseObj = NULL; |
|
58 |
|
59 |
|
60 DEBUG_API("->XALEDArrayDeviceImpl_Create"); |
|
61 XA_IMPL_THREAD_SAFETY_ENTRY(XATSLEDArray); |
|
62 |
|
63 if( !pDevice ) |
|
64 { |
|
65 /* invalid parameter */ |
|
66 XA_IMPL_THREAD_SAFETY_EXIT(XATSLEDArray); |
|
67 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
68 DEBUG_API("<-XALEDArrayDeviceImpl_Create"); |
|
69 return XA_RESULT_PARAMETER_INVALID; |
|
70 } |
|
71 |
|
72 /* instantiate object implementation */ |
|
73 pImpl = (XALEDArrayDeviceImpl*)calloc(1,sizeof(XALEDArrayDeviceImpl)); |
|
74 if( !pImpl ) |
|
75 { |
|
76 /* memory allocation failed */ |
|
77 XA_IMPL_THREAD_SAFETY_EXIT(XATSLEDArray); |
|
78 DEBUG_ERR("XA_RESULT_MEMORY_FAILURE"); |
|
79 DEBUG_API("<-XALEDArrayDeviceImpl_Create"); |
|
80 return XA_RESULT_MEMORY_FAILURE; |
|
81 } |
|
82 pBaseObj = &pImpl->baseObj; |
|
83 |
|
84 |
|
85 |
|
86 /* Initialize base object default implementation */ |
|
87 XAObjectItfImpl_Init(pBaseObj, |
|
88 LEDARRAY_ITFCOUNT, |
|
89 XALEDArrayDeviceItfIIDs, |
|
90 XALEDArrayDeviceImpl_DoRealize, |
|
91 XALEDArrayDeviceImpl_DoResume, |
|
92 XALEDArrayDeviceImpl_FreeResources); |
|
93 |
|
94 /* Mark interfaces that need to be exposed */ |
|
95 /* Implicit and mandated interfaces */ |
|
96 pBaseObj->interfaceMap[LEDARRAY_LEDARRAYITF].required = XA_BOOLEAN_TRUE; |
|
97 pBaseObj->interfaceMap[LEDARRAY_DIMITF].required = XA_BOOLEAN_TRUE; |
|
98 |
|
99 /* Explicit interfaces */ |
|
100 if( (numInterfaces != 0) && pInterfaceIds && pInterfaceRequired ) |
|
101 { |
|
102 /* Check required interfaces */ |
|
103 for( itfIndex = 0; itfIndex < numInterfaces; itfIndex++ ) |
|
104 { |
|
105 /* If mapEntry is null then required interface is not supported.*/ |
|
106 XAObjItfMapEntry *entry = |
|
107 XAObjectItfImpl_GetItfEntry((XAObjectItf)&(pBaseObj), pInterfaceIds[itfIndex]); |
|
108 if( !entry ) |
|
109 { |
|
110 if( pInterfaceRequired[itfIndex] ) |
|
111 { |
|
112 /* required interface cannot be accommodated - fail creation */ |
|
113 XAObjectItfImpl_Destroy((XAObjectItf)&(pBaseObj)); |
|
114 XA_IMPL_THREAD_SAFETY_EXIT(XATSLEDArray); |
|
115 DEBUG_ERR("Required interface not found - abort creation!"); |
|
116 DEBUG_API("<-XALEDArrayDeviceImpl_Create"); |
|
117 return XA_RESULT_FEATURE_UNSUPPORTED; |
|
118 } |
|
119 else |
|
120 { |
|
121 DEBUG_INFO("Requested (not required) interface not found - continue creation"); |
|
122 } |
|
123 } |
|
124 else |
|
125 { |
|
126 entry->required = XA_BOOLEAN_TRUE; |
|
127 } |
|
128 } |
|
129 } |
|
130 |
|
131 |
|
132 /* This code is put here to return Feature Not Supported since adaptation is not present*/ |
|
133 /*************************************************/ |
|
134 XAObjectItfImpl_Destroy((XAObjectItf)&(pBaseObj)); |
|
135 XA_IMPL_THREAD_SAFETY_EXIT(XATSLEDArray); |
|
136 DEBUG_ERR("Required interface not found - abort creation!"); |
|
137 DEBUG_API("<-XALEDArrayDeviceImpl_Create"); |
|
138 return XA_RESULT_FEATURE_UNSUPPORTED; |
|
139 /*************************************************/ |
|
140 |
|
141 /* // Initialize XALEDArrayDeviceImpl variables |
|
142 pImpl->deviceID = deviceID; |
|
143 pImpl->adaptationCtx = XALEDArrayAdapt_Create(pImpl->deviceID); |
|
144 |
|
145 // Set ObjectItf to point to newly created object |
|
146 *pDevice = (XAObjectItf)&(pBaseObj->self); |
|
147 XA_IMPL_THREAD_SAFETY_EXIT(XATSLEDArray); |
|
148 DEBUG_API("<-XALEDArrayDeviceImpl_Create"); |
|
149 return XA_RESULT_SUCCESS;*/ |
|
150 } |
|
151 |
|
152 /* XAResult XALEDArrayDeviceImpl_QueryNumSupportedInterfaces |
|
153 * Description: Statically query number of supported interfaces |
|
154 */ |
|
155 XAresult XALEDArrayDeviceImpl_QueryNumSupportedInterfaces( XAuint32 *pNumSupportedInterfaces ) |
|
156 { |
|
157 DEBUG_API("->XALEDArrayDeviceImpl_QueryNumSupportedInterfaces"); |
|
158 if( pNumSupportedInterfaces ) |
|
159 { |
|
160 |
|
161 *pNumSupportedInterfaces = LEDARRAY_ITFCOUNT; |
|
162 |
|
163 DEBUG_API_A1("<-XALEDArrayDeviceImpl_QueryNumSupportedInterfaces - %ld", *pNumSupportedInterfaces ); |
|
164 return XA_RESULT_SUCCESS; |
|
165 } |
|
166 else |
|
167 { |
|
168 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
169 DEBUG_API("<-XALEDArrayDeviceImpl_QueryNumSupportedInterfaces"); |
|
170 return XA_RESULT_PARAMETER_INVALID; |
|
171 } |
|
172 } |
|
173 /* XAResult XALEDArrayDeviceImpl_QuerySupportedInterfaces |
|
174 * Description: Statically query supported interfaces |
|
175 */ |
|
176 XAresult XALEDArrayDeviceImpl_QuerySupportedInterfaces( XAuint32 index, |
|
177 XAInterfaceID * pInterfaceId ) |
|
178 { |
|
179 DEBUG_API("->XALEDArrayDeviceImpl_QuerySupportedInterfaces"); |
|
180 |
|
181 |
|
182 if( index >= LEDARRAY_ITFCOUNT || !pInterfaceId ) |
|
183 { |
|
184 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
185 DEBUG_API("<-XALEDArrayDeviceImpl_QuerySupportedInterfaces"); |
|
186 return XA_RESULT_PARAMETER_INVALID; |
|
187 } |
|
188 else |
|
189 { |
|
190 *pInterfaceId = *(XALEDArrayDeviceItfIIDs[index]); |
|
191 |
|
192 DEBUG_API("<-XALEDArrayDeviceImpl_QuerySupportedInterfaces"); |
|
193 return XA_RESULT_SUCCESS; |
|
194 |
|
195 } |
|
196 |
|
197 } |
|
198 |
|
199 |
|
200 /***************************************************************************** |
|
201 * base object XAObjectItfImpl methods |
|
202 *****************************************************************************/ |
|
203 |
|
204 /* XAresult XALEDArrayDeviceImpl_DoRealize( XAObjectItf self ) |
|
205 * Description: Realize all implicit and explicitly wanted interfaces. |
|
206 * Create and initialize implementation-specific variables. |
|
207 * Called from base object XAObjectItfImpl |
|
208 */ |
|
209 XAresult XALEDArrayDeviceImpl_DoRealize( XAObjectItf self ) |
|
210 { |
|
211 |
|
212 XAObjectItfImpl* pObj = (XAObjectItfImpl*)(*self); |
|
213 XAuint8 itfIdx = 0; |
|
214 XALEDArrayDeviceImpl* pObjImpl = (XALEDArrayDeviceImpl*)(pObj); |
|
215 XAresult ret = XA_RESULT_SUCCESS; |
|
216 |
|
217 DEBUG_API("->XALEDArrayDeviceImpl_DoRealize"); |
|
218 XA_IMPL_THREAD_SAFETY_ENTRY(XATSLEDArray); |
|
219 |
|
220 /* check casting from correct pointer type */ |
|
221 if( !pObjImpl || pObj != pObjImpl->baseObj.self ) |
|
222 { |
|
223 /* invalid parameter */ |
|
224 XA_IMPL_THREAD_SAFETY_EXIT(XATSLEDArray); |
|
225 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
226 DEBUG_API("<-XALEDArrayDeviceImpl_DoRealize"); |
|
227 return XA_RESULT_PARAMETER_INVALID; |
|
228 } |
|
229 |
|
230 ret = XALEDArrayAdapt_PostInit( (XAAdaptationGstCtx*)pObjImpl->adaptationCtx ); |
|
231 if( ret != XA_RESULT_SUCCESS ) |
|
232 { |
|
233 XA_IMPL_THREAD_SAFETY_EXIT(XATSLEDArray); |
|
234 DEBUG_ERR_A1("Error: %d",ret); |
|
235 DEBUG_API("<-XALEDArrayDeviceImpl_DoRealize"); |
|
236 return ret; |
|
237 } |
|
238 |
|
239 /* Realize all implicit and explicitly wanted interfaces */ |
|
240 for( itfIdx = 0; itfIdx < LEDARRAY_ITFCOUNT; itfIdx++) |
|
241 { |
|
242 if( !(pObj->interfaceMap[itfIdx].pItf) && |
|
243 pObj->interfaceMap[itfIdx].required ) |
|
244 { |
|
245 void *pItf = NULL; |
|
246 switch( itfIdx ) |
|
247 { |
|
248 case LEDARRAY_LEDARRAYITF: |
|
249 pItf = XALEDArrayItfImpl_Create( pObjImpl->adaptationCtx ); |
|
250 break; |
|
251 case LEDARRAY_CONFIGEXTENSIONITF: |
|
252 pItf = XAConfigExtensionsItfImpl_Create(); |
|
253 break; |
|
254 case LEDARRAY_DIMITF: |
|
255 pItf = XADIMItfImpl_Create(); |
|
256 break; |
|
257 default: |
|
258 break; |
|
259 } |
|
260 if( !pItf ) |
|
261 { |
|
262 /* memory allocation failed */ |
|
263 XA_IMPL_THREAD_SAFETY_EXIT(XATSLEDArray); |
|
264 DEBUG_ERR("XA_RESULT_MEMORY_FAILURE"); |
|
265 DEBUG_API("<-XALEDArrayDeviceImpl_DoRealize"); |
|
266 return XA_RESULT_MEMORY_FAILURE; |
|
267 } |
|
268 else |
|
269 { |
|
270 pObj->interfaceMap[itfIdx].pItf = pItf; |
|
271 } |
|
272 } |
|
273 } |
|
274 |
|
275 pObj->state = XA_OBJECT_STATE_REALIZED; |
|
276 XA_IMPL_THREAD_SAFETY_EXIT(XATSLEDArray); |
|
277 |
|
278 DEBUG_API("<-XALEDArrayDeviceImpl_DoRealize"); |
|
279 return XA_RESULT_SUCCESS; |
|
280 } |
|
281 |
|
282 /* XAresult XALEDArrayDeviceImpl_DoResume |
|
283 * Description: Resume object from suspended state |
|
284 */ |
|
285 XAresult XALEDArrayDeviceImpl_DoResume(XAObjectItf self) |
|
286 { |
|
287 DEBUG_API("->XALEDArrayDeviceImpl_DoResume"); |
|
288 DEBUG_API("<-XALEDArrayDeviceImpl_DoResume"); |
|
289 /* This implementation does not support suspended state */ |
|
290 return XA_RESULT_PRECONDITIONS_VIOLATED; |
|
291 } |
|
292 |
|
293 /* void XALEDArrayDeviceImpl_FreeResources |
|
294 * Description: Free all resources reserved at XALEDArrayDeviceImpl_DoRealize() |
|
295 */ |
|
296 void XALEDArrayDeviceImpl_FreeResources(XAObjectItf self) |
|
297 { |
|
298 |
|
299 XAObjectItfImpl* pObj = (XAObjectItfImpl*)(*self); |
|
300 XALEDArrayDeviceImpl* pImpl = (XALEDArrayDeviceImpl*)(*self); |
|
301 XAuint8 itfIdx = 0; |
|
302 DEBUG_API("->XALEDArrayDeviceImpl_FreeResources"); |
|
303 XA_IMPL_THREAD_SAFETY_ENTRY_FOR_VOID_FUNCTIONS(XATSLEDArray); |
|
304 assert( pObj && pImpl && pObj == pObj->self ); |
|
305 |
|
306 if ( pImpl->adaptationCtx != NULL ) |
|
307 { |
|
308 XALEDArrayAdapt_Destroy( (XAAdaptationGstCtx*)pImpl->adaptationCtx ); |
|
309 pImpl->adaptationCtx = NULL; |
|
310 } |
|
311 |
|
312 /* free all allocated interfaces */ |
|
313 for(itfIdx = 0; itfIdx < LEDARRAY_ITFCOUNT; itfIdx++) |
|
314 { |
|
315 void *pItf = pObj->interfaceMap[itfIdx].pItf; |
|
316 if(pItf) |
|
317 { |
|
318 switch(itfIdx) |
|
319 { |
|
320 case LEDARRAY_LEDARRAYITF: |
|
321 XALEDArrayItfImpl_Free( pItf ); |
|
322 break; |
|
323 case LEDARRAY_CONFIGEXTENSIONITF: |
|
324 XAConfigExtensionsItfImpl_Free( pItf ); |
|
325 break; |
|
326 case LEDARRAY_DIMITF: |
|
327 XADIMItfImpl_Free( pItf ); |
|
328 break; |
|
329 |
|
330 default: |
|
331 break; |
|
332 } |
|
333 pObj->interfaceMap[itfIdx].pItf = NULL; |
|
334 } |
|
335 } |
|
336 |
|
337 if ( pImpl->adaptationCtx != NULL ) |
|
338 { |
|
339 XALEDArrayAdapt_Destroy( (XAAdaptationGstCtx*)pImpl->adaptationCtx ); |
|
340 pImpl->adaptationCtx = NULL; |
|
341 } |
|
342 |
|
343 XA_IMPL_THREAD_SAFETY_EXIT_FOR_VOID_FUNCTIONS(XATSLEDArray); |
|
344 DEBUG_API("<-XALEDArrayDeviceImpl_FreeResources"); |
|
345 |
|
346 return; |
|
347 } |
|
348 /* END OF FILE */ |
|