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