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