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 <string.h> |
|
22 #include "xaradioitf.h" |
|
23 #include "xaradioitfadaptation.h" |
|
24 #include "xathreadsafety.h" |
|
25 |
|
26 #define FREQINTERVAL 200000 |
|
27 |
|
28 /** |
|
29 * XARadioItfImpl* GetImpl(XARadioItf self) |
|
30 * Description: Validated interface pointer and cast it to implementations pointer. |
|
31 **/ |
|
32 static XARadioItfImpl* GetImpl(XARadioItf self) |
|
33 { |
|
34 if(self) |
|
35 { |
|
36 XARadioItfImpl *impl = (XARadioItfImpl*)(*self); |
|
37 if(impl && impl == impl->self) |
|
38 { |
|
39 return impl; |
|
40 } |
|
41 } |
|
42 return NULL; |
|
43 } |
|
44 |
|
45 /** |
|
46 * Base interface XARadioItf implementation |
|
47 */ |
|
48 |
|
49 /** |
|
50 * XAresult XARadioItfImpl_SetFreqRange(XARadioItf self, XAuint8 range) |
|
51 * Description: Sets the frequency range. Asynchronous – xaRadioCallback() callback with |
|
52 * XA_RADIO_EVENT_FREQUENCY_RANGE_CHANGED event is used for notifying of the result. |
|
53 **/ |
|
54 XAresult XARadioItfImpl_SetFreqRange(XARadioItf self, XAuint8 range) |
|
55 { |
|
56 XAresult ret = XA_RESULT_PARAMETER_INVALID; |
|
57 XAboolean isSupported = XA_BOOLEAN_FALSE; |
|
58 XARadioItfImpl* impl = GetImpl(self); |
|
59 |
|
60 DEBUG_API("->XARadioItfImpl_SetFreqRange"); |
|
61 XA_IMPL_THREAD_SAFETY_ENTRY(XATSRadio); |
|
62 |
|
63 if(!impl) |
|
64 { |
|
65 XA_IMPL_THREAD_SAFETY_EXIT(XATSRadio); |
|
66 /* invalid parameter */ |
|
67 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
68 DEBUG_API("<-XARadioItfImpl_SetFreqRange"); |
|
69 |
|
70 return ret; |
|
71 } |
|
72 |
|
73 ret = XARadioItfAdapt_IsFreqRangeSupported(range, &isSupported); |
|
74 |
|
75 if ( ret == XA_RESULT_SUCCESS && isSupported == XA_BOOLEAN_TRUE ) |
|
76 { |
|
77 ret = XARadioItfAdapt_SetFreqRange((XAAdaptationMMFCtx*)impl->adapCtx, range); |
|
78 } |
|
79 else if (!isSupported) |
|
80 { |
|
81 ret = XA_RESULT_PARAMETER_INVALID; |
|
82 } |
|
83 |
|
84 XA_IMPL_THREAD_SAFETY_EXIT(XATSRadio); |
|
85 DEBUG_API("<-XARadioItfImpl_SetFreqRange"); |
|
86 return ret; |
|
87 } |
|
88 |
|
89 /** |
|
90 * XAresult XARadioItfImpl_GetFreqRange(XARadioItf self, XAuint8 * pRange) |
|
91 * Description: Gets the current frequency range. |
|
92 **/ |
|
93 XAresult XARadioItfImpl_GetFreqRange(XARadioItf self, XAuint8 * pRange) |
|
94 { |
|
95 XAresult ret = XA_RESULT_SUCCESS; |
|
96 XARadioItfImpl* impl = GetImpl(self); |
|
97 DEBUG_API("->XARadioItfImpl_GetFreqRange"); |
|
98 |
|
99 if(!impl || !pRange) |
|
100 { |
|
101 XA_IMPL_THREAD_SAFETY_EXIT(XATSRadio); |
|
102 /* invalid parameter */ |
|
103 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
104 DEBUG_API("<-XARadioItfImpl_GetFreqRange"); |
|
105 return XA_RESULT_PARAMETER_INVALID; |
|
106 } |
|
107 |
|
108 ret = XARadioItfAdapt_GetFreqRange(pRange); |
|
109 |
|
110 DEBUG_API("<-XARadioItfImpl_GetFreqRange"); |
|
111 return ret; |
|
112 } |
|
113 |
|
114 /** |
|
115 * XAresult XARadioItfImpl_IsFreqRangeSupported(XARadioItf self, |
|
116 * XAuint8 range, |
|
117 * XAboolean * pSupported) |
|
118 * Description: Queries if the given frequency range is supported. |
|
119 **/ |
|
120 XAresult XARadioItfImpl_IsFreqRangeSupported(XARadioItf self, |
|
121 XAuint8 range, |
|
122 XAboolean * pSupported) |
|
123 { |
|
124 XAresult ret = XA_RESULT_SUCCESS; |
|
125 XARadioItfImpl* impl = GetImpl(self); |
|
126 DEBUG_API("->XARadioItfImpl_IsFreqRangeSupported"); |
|
127 XA_IMPL_THREAD_SAFETY_ENTRY(XATSRadio); |
|
128 |
|
129 if(!impl || !pSupported) |
|
130 { |
|
131 XA_IMPL_THREAD_SAFETY_EXIT(XATSRadio); |
|
132 /* invalid parameter */ |
|
133 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
134 DEBUG_API("<-XARadioItfImpl_IsFreqRangeSupported"); |
|
135 return XA_RESULT_PARAMETER_INVALID; |
|
136 } |
|
137 |
|
138 ret = XARadioItfAdapt_IsFreqRangeSupported( range, pSupported ); |
|
139 |
|
140 XA_IMPL_THREAD_SAFETY_EXIT(XATSRadio); |
|
141 DEBUG_API("<-XARadioItfImpl_IsFreqRangeSupported"); |
|
142 return ret; |
|
143 } |
|
144 |
|
145 |
|
146 /** |
|
147 * XAresult XARadioItfImpl_GetFreqRangeProperties(XARadioItf self, |
|
148 * XAuint8 range, |
|
149 * XAuint32 * pMinFreq, |
|
150 * XAuint32 * pMaxFreq, |
|
151 * XAuint32 * pFreqInterval) |
|
152 * Description: Returns the minimum and maximum supported frequencies and the |
|
153 * modulation of the given frequency range. |
|
154 **/ |
|
155 XAresult XARadioItfImpl_GetFreqRangeProperties(XARadioItf self, |
|
156 XAuint8 range, |
|
157 XAuint32 * pMinFreq, |
|
158 XAuint32 * pMaxFreq, |
|
159 XAuint32 * pFreqInterval) |
|
160 { |
|
161 XAresult ret = XA_RESULT_SUCCESS; |
|
162 XARadioItfImpl* impl = GetImpl(self); |
|
163 |
|
164 DEBUG_API("->XARadioItfImpl_GetFreqRangeProperties"); |
|
165 |
|
166 if(!impl || !pMinFreq || !pMaxFreq || !pFreqInterval) |
|
167 { |
|
168 /* invalid parameter */ |
|
169 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
170 DEBUG_API("<-XARadioItfImpl_GetFreqRangeProperties"); |
|
171 return XA_RESULT_PARAMETER_INVALID; |
|
172 } |
|
173 |
|
174 ret = XARadioItfAdapt_GetFreqRangeProperties( (XAAdaptationMMFCtx*)impl->adapCtx, |
|
175 range, pMinFreq, pMaxFreq ); |
|
176 if (ret == XA_RESULT_SUCCESS) |
|
177 { |
|
178 *pFreqInterval = FREQINTERVAL; |
|
179 } |
|
180 |
|
181 DEBUG_API("<-XARadioItfImpl_GetFreqRangeProperties"); |
|
182 return ret; |
|
183 } |
|
184 |
|
185 /** |
|
186 * XAresult XARadioItfImpl_SetFrequency(XARadioItf self, XAuint32 freq) |
|
187 * Description: Sets the frequency asynchronously – xaRadioCallback() callback |
|
188 * with XA_RADIO_EVENT_FREQUENCY_CHANGED event is used for notifying |
|
189 * of the result. The implementation rounds the given value to the |
|
190 * nearest supported one. See pFreqInterval parameter of |
|
191 * GetFreqRangeProperties() method. |
|
192 **/ |
|
193 XAresult XARadioItfImpl_SetFrequency(XARadioItf self, XAuint32 freq) |
|
194 { |
|
195 XAresult ret = XA_RESULT_SUCCESS; |
|
196 XAuint8 range = 1; // Default to EuroAmerica |
|
197 XAuint32 minFreq; |
|
198 XAuint32 maxFreq; |
|
199 XAuint32 freqInterval; |
|
200 |
|
201 XARadioItfImpl* impl = GetImpl(self); |
|
202 DEBUG_API("->XARadioItfImpl_SetFrequency"); |
|
203 XA_IMPL_THREAD_SAFETY_ENTRY(XATSRadio); |
|
204 |
|
205 if(!impl) |
|
206 { |
|
207 XA_IMPL_THREAD_SAFETY_EXIT(XATSRadio); |
|
208 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
209 DEBUG_API("<-XARadioItfImpl_SetFrequency"); |
|
210 return XA_RESULT_PARAMETER_INVALID; |
|
211 } |
|
212 |
|
213 // Check for valid entries: |
|
214 ret = XARadioItfImpl_GetFreqRangeProperties(self, range, &minFreq, &maxFreq, &freqInterval); |
|
215 if (ret != XA_RESULT_SUCCESS) |
|
216 { |
|
217 XA_IMPL_THREAD_SAFETY_EXIT(XATSRadio); |
|
218 DEBUG_API("<-XARadioItfImpl_SetFrequency"); |
|
219 return ret; |
|
220 } |
|
221 |
|
222 if ( (freq < minFreq) || (freq > maxFreq) ) |
|
223 { |
|
224 XA_IMPL_THREAD_SAFETY_EXIT(XATSRadio); |
|
225 DEBUG_API("<-XARadioItfImpl_SetFrequency"); |
|
226 return XA_RESULT_PARAMETER_INVALID; |
|
227 } |
|
228 |
|
229 ret = XARadioItfAdapt_SetFrequency( (XAAdaptationMMFCtx*)impl->adapCtx, freq ); |
|
230 |
|
231 XA_IMPL_THREAD_SAFETY_EXIT(XATSRadio); |
|
232 DEBUG_API("<-XARadioItfImpl_SetFrequency"); |
|
233 return ret; |
|
234 } |
|
235 |
|
236 /** |
|
237 * XAresult XARadioItfImpl_CancelSetFrequency(XARadioItf self) |
|
238 * Description: Cancels an outstanding SetFrequency() request. The method |
|
239 * blocks while canceling the outstanding request. Has not effect |
|
240 * if no set frequency operation is ongoing. |
|
241 **/ |
|
242 XAresult XARadioItfImpl_CancelSetFrequency(XARadioItf self) |
|
243 |
|
244 { |
|
245 XAresult ret = XA_RESULT_SUCCESS; |
|
246 XARadioItfImpl* impl = GetImpl(self); |
|
247 DEBUG_API("->XARadioItfImpl_CancelSetFrequency"); |
|
248 XA_IMPL_THREAD_SAFETY_ENTRY(XATSRadio); |
|
249 |
|
250 if(!impl) |
|
251 { |
|
252 XA_IMPL_THREAD_SAFETY_EXIT(XATSRadio); |
|
253 /* invalid parameter */ |
|
254 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
255 DEBUG_API("<-XARadioItfImpl_CancelSetFrequency"); |
|
256 return XA_RESULT_PARAMETER_INVALID; |
|
257 } |
|
258 |
|
259 ret = XARadioItfAdapt_CancelSetFrequency(); |
|
260 |
|
261 XA_IMPL_THREAD_SAFETY_EXIT(XATSRadio); |
|
262 DEBUG_API("<-XARadioItfImpl_CancelSetFrequency"); |
|
263 return ret; |
|
264 } |
|
265 |
|
266 /** |
|
267 * XAresult XARadioItfImpl_GetFrequency(XARadioItf self, XAuint32 * pFreq) |
|
268 * Description: Gets the current frequency. |
|
269 **/ |
|
270 XAresult XARadioItfImpl_GetFrequency(XARadioItf self, XAuint32 * pFreq) |
|
271 { |
|
272 XAresult ret = XA_RESULT_SUCCESS; |
|
273 XARadioItfImpl* impl = GetImpl(self); |
|
274 DEBUG_API("->XARadioItfImpl_GetFrequency"); |
|
275 XA_IMPL_THREAD_SAFETY_ENTRY(XATSRadio); |
|
276 |
|
277 if(!impl || !pFreq) |
|
278 { |
|
279 XA_IMPL_THREAD_SAFETY_EXIT(XATSRadio); |
|
280 /* invalid parameter */ |
|
281 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
282 DEBUG_API("<-XARadioItfImpl_GetFrequency"); |
|
283 return XA_RESULT_PARAMETER_INVALID; |
|
284 } |
|
285 |
|
286 ret = XARadioItfAdapt_GetFrequency(pFreq); |
|
287 |
|
288 XA_IMPL_THREAD_SAFETY_EXIT(XATSRadio); |
|
289 DEBUG_API("<-XARadioItfImpl_GetFrequency"); |
|
290 return ret; |
|
291 } |
|
292 |
|
293 /** |
|
294 * XAresult XARadioItfImpl_SetSquelch(XARadioItf self, XAboolean squelch) |
|
295 * Description: Toggles the squelch (muting in frequencies without broadcast). |
|
296 **/ |
|
297 XAresult XARadioItfImpl_SetSquelch(XARadioItf self, XAboolean squelch) |
|
298 { |
|
299 XAresult ret = XA_RESULT_SUCCESS; |
|
300 XARadioItfImpl* impl = GetImpl(self); |
|
301 DEBUG_API("->XARadioItfImpl_SetSquelch"); |
|
302 XA_IMPL_THREAD_SAFETY_ENTRY(XATSRadio); |
|
303 |
|
304 if(!impl) |
|
305 { |
|
306 XA_IMPL_THREAD_SAFETY_EXIT(XATSRadio); |
|
307 /* invalid parameter */ |
|
308 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
309 DEBUG_API("<-XARadioItfImpl_SetSquelch"); |
|
310 return XA_RESULT_PARAMETER_INVALID; |
|
311 } |
|
312 |
|
313 if (impl->squelch != squelch) |
|
314 { |
|
315 ret = XARadioItfAdapt_SetSquelch( squelch ); |
|
316 if ( ret == XA_RESULT_SUCCESS ) |
|
317 { |
|
318 impl->squelch = squelch; |
|
319 } |
|
320 } |
|
321 |
|
322 XA_IMPL_THREAD_SAFETY_EXIT(XATSRadio); |
|
323 DEBUG_API("<-XARadioItfImpl_SetSquelch"); |
|
324 return ret; |
|
325 } |
|
326 |
|
327 /** |
|
328 * XAresult XARadioItfImpl_GetSquelch(XARadioItf self, XAboolean * pSquelch) |
|
329 * Description: Queries the squelch setting (muting in frequencies without broadcast). |
|
330 **/ |
|
331 XAresult XARadioItfImpl_GetSquelch(XARadioItf self, XAboolean * pSquelch) |
|
332 { |
|
333 XAresult ret = XA_RESULT_SUCCESS; |
|
334 XARadioItfImpl* impl = GetImpl(self); |
|
335 DEBUG_API("->XARadioItfImpl_GetSquelch"); |
|
336 if(!impl || !pSquelch) |
|
337 { |
|
338 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
339 /* invalid parameter */ |
|
340 DEBUG_API("<-XARadioItfImpl_GetSquelch"); |
|
341 return XA_RESULT_PARAMETER_INVALID; |
|
342 } |
|
343 |
|
344 ret = XARadioItfAdapt_GetSquelch( pSquelch ); |
|
345 |
|
346 DEBUG_API("<-XARadioItfImpl_GetSquelch"); |
|
347 return ret; |
|
348 } |
|
349 |
|
350 /** |
|
351 * XAresult XARadioItfImpl_SetStereoMode(XARadioItf self, XAuint32 mode) |
|
352 * Description: Sets the current stereo mode. |
|
353 **/ |
|
354 XAresult XARadioItfImpl_SetStereoMode(XARadioItf self, XAuint32 mode) |
|
355 { |
|
356 XAresult ret = XA_RESULT_SUCCESS; |
|
357 XARadioItfImpl* impl = GetImpl(self); |
|
358 DEBUG_API("->XARadioItfImpl_SetStereoMode"); |
|
359 XA_IMPL_THREAD_SAFETY_ENTRY(XATSRadio); |
|
360 |
|
361 if( !impl || mode > XA_STEREOMODE_AUTO ) |
|
362 { |
|
363 XA_IMPL_THREAD_SAFETY_EXIT(XATSRadio); |
|
364 /* invalid parameter */ |
|
365 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
366 DEBUG_API("<-XARadioItfImpl_SetStereoMode"); |
|
367 return XA_RESULT_PARAMETER_INVALID; |
|
368 } |
|
369 if ( impl->stereoMode != mode) |
|
370 { |
|
371 ret = XARadioItfAdapt_SetStereoMode( (XAAdaptationMMFCtx*)impl->adapCtx, mode ); |
|
372 if ( ret == XA_RESULT_SUCCESS ) |
|
373 { |
|
374 impl->stereoMode = mode; |
|
375 } |
|
376 } |
|
377 XA_IMPL_THREAD_SAFETY_EXIT(XATSRadio); |
|
378 DEBUG_API("<-XARadioItfImpl_SetStereoMode"); |
|
379 return ret; |
|
380 } |
|
381 |
|
382 /** |
|
383 * XAresult XARadioItfImpl_GetStereoMode(XARadioItf self, XAuint32 * pMode) |
|
384 * Description: Queries the current stereo mode. |
|
385 **/ |
|
386 XAresult XARadioItfImpl_GetStereoMode(XARadioItf self, XAuint32 * pMode) |
|
387 { |
|
388 |
|
389 XAresult ret = XA_RESULT_SUCCESS; |
|
390 XARadioItfImpl* impl = GetImpl(self); |
|
391 DEBUG_API("->XARadioItfImpl_GetStereoMode"); |
|
392 if(!impl || !pMode) |
|
393 { |
|
394 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
395 /* invalid parameter */ |
|
396 DEBUG_API("<-XARadioItfImpl_GetStereoMode"); |
|
397 return XA_RESULT_PARAMETER_INVALID; |
|
398 } |
|
399 |
|
400 ret = XARadioItfAdapt_GetStereoMode( pMode ); |
|
401 |
|
402 DEBUG_API("<-XARadioItfImpl_GetStereoMode"); |
|
403 return ret; |
|
404 } |
|
405 |
|
406 /** |
|
407 * XAresult XARadioItfImpl_GetSignalStrength(XARadioItf self, XAuint32 * pStrength) |
|
408 * Description: Returns the signal strength in per cents. |
|
409 **/ |
|
410 XAresult XARadioItfImpl_GetSignalStrength(XARadioItf self, XAuint32 * pStrength) |
|
411 { |
|
412 XAresult ret = XA_RESULT_SUCCESS; |
|
413 XARadioItfImpl* impl = GetImpl(self); |
|
414 DEBUG_API("->XARadioItfImpl_GetSignalStrength"); |
|
415 XA_IMPL_THREAD_SAFETY_ENTRY(XATSRadio); |
|
416 |
|
417 if(!impl || !pStrength) |
|
418 { |
|
419 XA_IMPL_THREAD_SAFETY_EXIT(XATSRadio); |
|
420 /* invalid parameter */ |
|
421 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
422 DEBUG_API("<-XARadioItfImpl_GetSignalStrength"); |
|
423 return XA_RESULT_PARAMETER_INVALID; |
|
424 } |
|
425 |
|
426 ret = XARadioItfAdapt_GetSignalStrength( pStrength ); |
|
427 |
|
428 XA_IMPL_THREAD_SAFETY_EXIT(XATSRadio); |
|
429 DEBUG_API("<-XARadioItfImpl_GetSignalStrength"); |
|
430 return ret; |
|
431 } |
|
432 |
|
433 /** |
|
434 * XAresult XARadioItfImpl_Seek(XARadioItf self, XAboolean upwards) |
|
435 * Description: Starts the seek from the current frequency to the given direction. |
|
436 * Asynchronous – xaRadioCallback() callback with XA_RADIO_EVENT_SEEK_COMPLETED |
|
437 * event is used for notifying of the result. If the end of the tuner’s |
|
438 * frequency band is reached before a signal was found, the scan continues |
|
439 * from the other end until a signal is found or the original frequency is reached. |
|
440 **/ |
|
441 XAresult XARadioItfImpl_Seek(XARadioItf self, XAboolean upwards) |
|
442 { |
|
443 XAresult ret = XA_RESULT_SUCCESS; |
|
444 XARadioItfImpl* impl = GetImpl(self); |
|
445 DEBUG_API("->XARadioItfImpl_Seek"); |
|
446 XA_IMPL_THREAD_SAFETY_ENTRY(XATSRadio); |
|
447 |
|
448 if(!impl) |
|
449 { |
|
450 XA_IMPL_THREAD_SAFETY_EXIT(XATSRadio); |
|
451 /* invalid parameter */ |
|
452 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
453 DEBUG_API("<-XARadioItfImpl_Seek"); |
|
454 return XA_RESULT_PARAMETER_INVALID; |
|
455 } |
|
456 |
|
457 ret = XARadioItfAdapt_Seek( (XAAdaptationMMFCtx*)impl->adapCtx, upwards ); |
|
458 |
|
459 XA_IMPL_THREAD_SAFETY_EXIT(XATSRadio); |
|
460 DEBUG_API("<-XARadioItfImpl_Seek"); |
|
461 return ret; |
|
462 } |
|
463 |
|
464 /** |
|
465 * XAresult XARadioItfImpl_StopSeeking(XARadioItf self) |
|
466 * Description: Cancels an outstanding seek request. The method blocks while canceling |
|
467 * the outstanding request. After cancellation, the frequency is the one |
|
468 * where seeking stopped. Has not effect if no seek operation is ongoing. |
|
469 **/ |
|
470 XAresult XARadioItfImpl_StopSeeking(XARadioItf self) |
|
471 { |
|
472 XAresult ret = XA_RESULT_SUCCESS; |
|
473 XARadioItfImpl* impl = GetImpl(self); |
|
474 DEBUG_API("->XARadioItfImpl_StopSeeking"); |
|
475 XA_IMPL_THREAD_SAFETY_ENTRY(XATSRadio); |
|
476 |
|
477 if(!impl) |
|
478 { |
|
479 /* invalid parameter */ |
|
480 XA_IMPL_THREAD_SAFETY_EXIT(XATSRadio); |
|
481 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
482 DEBUG_API("<-XARadioItfImpl_StopSeeking"); |
|
483 return XA_RESULT_PARAMETER_INVALID; |
|
484 } |
|
485 |
|
486 XARadioItfAdapt_StopSeeking( (XAAdaptationMMFCtx*)impl->adapCtx ); |
|
487 |
|
488 XA_IMPL_THREAD_SAFETY_EXIT(XATSRadio); |
|
489 DEBUG_API("<-XARadioItfImpl_StopSeeking"); |
|
490 return ret; |
|
491 } |
|
492 |
|
493 /** |
|
494 * XAresult XARadioItfImpl_GetNumberOfPresets(XARadioItf self, XAuint32 * pNumPresets) |
|
495 * Description: Returns the number of preset slots the device has for storing the presets. |
|
496 **/ |
|
497 XAresult XARadioItfImpl_GetNumberOfPresets(XARadioItf self, XAuint32 * pNumPresets) |
|
498 { |
|
499 XAresult ret = XA_RESULT_FEATURE_UNSUPPORTED; |
|
500 |
|
501 DEBUG_API("->XARadioItfImpl_GetNumberOfPresets"); |
|
502 |
|
503 return ret; |
|
504 } |
|
505 |
|
506 /** |
|
507 * XAresult XARadioItfImpl_SetPreset(XARadioItf self, |
|
508 * XAuint32 preset, |
|
509 * XAuint32 freq, |
|
510 * XAuint8 range, |
|
511 * XAuint32 mode, |
|
512 * const XAchar * name) |
|
513 * Description: Sets the preset. |
|
514 **/ |
|
515 XAresult XARadioItfImpl_SetPreset(XARadioItf self, |
|
516 XAuint32 preset, |
|
517 XAuint32 freq, |
|
518 XAuint8 range, |
|
519 XAuint32 mode, |
|
520 const XAchar * name) |
|
521 { |
|
522 XAresult ret = XA_RESULT_FEATURE_UNSUPPORTED; |
|
523 |
|
524 return ret; |
|
525 } |
|
526 |
|
527 /** |
|
528 * XAresult XARadioItfImpl_GetPreset(XARadioItf self, |
|
529 * XAuint32 preset, |
|
530 * XAuint32 * pFreq, |
|
531 * XAuint8 * pRange, |
|
532 * XAuint32 * pMode, |
|
533 * XAchar * pName, |
|
534 * XAuint16 * pNameLength) |
|
535 * Description: Gets the settings stored into a preset. |
|
536 **/ |
|
537 XAresult XARadioItfImpl_GetPreset(XARadioItf self, |
|
538 XAuint32 preset, |
|
539 XAuint32 * pFreq, |
|
540 XAuint8 * pRange, |
|
541 XAuint32 * pMode, |
|
542 XAchar * pName, |
|
543 XAuint16 * pNameLength) |
|
544 { |
|
545 |
|
546 XAresult ret = XA_RESULT_FEATURE_UNSUPPORTED; |
|
547 |
|
548 DEBUG_API("<-XARadioItfImpl_GetPreset"); |
|
549 return ret; |
|
550 } |
|
551 |
|
552 /** |
|
553 * XAresult XARadioItfImpl_RegisterRadioCallback(XARadioItf self, |
|
554 * xaRadioCallback callback, |
|
555 * void * pContext) |
|
556 * Description: Sets or clears the xaRadioCallback. |
|
557 **/ |
|
558 XAresult XARadioItfImpl_RegisterRadioCallback(XARadioItf self, |
|
559 xaRadioCallback callback, |
|
560 void * pContext) |
|
561 { |
|
562 XAresult ret = XA_RESULT_SUCCESS; |
|
563 XARadioItfImpl* impl = GetImpl(self); |
|
564 DEBUG_API("->XARadioItfImpl_RegisterRadioCallback"); |
|
565 |
|
566 if(!impl) |
|
567 { |
|
568 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
569 /* invalid parameter */ |
|
570 DEBUG_API("<-XARadioItfImpl_RegisterRadioCallback"); |
|
571 return XA_RESULT_PARAMETER_INVALID; |
|
572 } |
|
573 |
|
574 impl->callback = callback; |
|
575 impl->context = pContext; |
|
576 impl->cbPtrToSelf = self; |
|
577 |
|
578 DEBUG_API("<-XARadioItfImpl_RegisterRadioCallback"); |
|
579 return ret; |
|
580 } |
|
581 |
|
582 /** |
|
583 * XARadioItfImpl -specific methods |
|
584 **/ |
|
585 |
|
586 /** |
|
587 * XARadioItfImplImpl* XARadioItfImpl_Create() |
|
588 * Description: Allocate and initialize RadioItfImpl |
|
589 **/ |
|
590 XARadioItfImpl* XARadioItfImpl_Create(XAAdaptationBaseCtx *adapCtx) |
|
591 { |
|
592 |
|
593 XARadioItfImpl *self = (XARadioItfImpl*) |
|
594 calloc(1,sizeof(XARadioItfImpl)); |
|
595 |
|
596 DEBUG_API("->XARadioItfImpl_Create"); |
|
597 |
|
598 if(self) |
|
599 { |
|
600 /* init itf default implementation */ |
|
601 self->itf.SetFreqRange = XARadioItfImpl_SetFreqRange; |
|
602 self->itf.GetFreqRange = XARadioItfImpl_GetFreqRange; |
|
603 self->itf.IsFreqRangeSupported = XARadioItfImpl_IsFreqRangeSupported; |
|
604 self->itf.GetFreqRangeProperties = XARadioItfImpl_GetFreqRangeProperties; |
|
605 self->itf.SetFrequency = XARadioItfImpl_SetFrequency; |
|
606 self->itf.CancelSetFrequency = XARadioItfImpl_CancelSetFrequency; |
|
607 self->itf.GetFrequency = XARadioItfImpl_GetFrequency; |
|
608 self->itf.SetSquelch = XARadioItfImpl_SetSquelch; |
|
609 self->itf.GetSquelch = XARadioItfImpl_GetSquelch; |
|
610 self->itf.SetStereoMode = XARadioItfImpl_SetStereoMode; |
|
611 self->itf.GetStereoMode = XARadioItfImpl_GetStereoMode; |
|
612 self->itf.GetSignalStrength = XARadioItfImpl_GetSignalStrength; |
|
613 self->itf.Seek = XARadioItfImpl_Seek; |
|
614 self->itf.StopSeeking = XARadioItfImpl_StopSeeking; |
|
615 self->itf.RegisterRadioCallback = XARadioItfImpl_RegisterRadioCallback; |
|
616 |
|
617 /* init variables */ |
|
618 |
|
619 self->squelch = XA_BOOLEAN_FALSE; |
|
620 self->stereoMode = XA_STEREOMODE_STEREO; |
|
621 self->callback = NULL; |
|
622 self->context = NULL; |
|
623 self->cbPtrToSelf = NULL; |
|
624 self->adapCtx = adapCtx; |
|
625 |
|
626 XAAdaptationBase_AddEventHandler( adapCtx, &XARadioItfImpl_AdaptCb, XA_RADIOITFEVENTS, self ); |
|
627 |
|
628 self->self = self; |
|
629 } |
|
630 |
|
631 DEBUG_API("<-XARadioItfImpl_Create"); |
|
632 return self; |
|
633 } |
|
634 |
|
635 /** |
|
636 * void XARadioItfImpl_Free(XARadioItfImpl* self) |
|
637 * Description: Free all resources reserved at XARadioItfImpl_Create |
|
638 **/ |
|
639 void XARadioItfImpl_Free(XARadioItfImpl* self) |
|
640 { |
|
641 DEBUG_API("->XARadioItfImpl_Free"); |
|
642 XA_IMPL_THREAD_SAFETY_ENTRY_FOR_VOID_FUNCTIONS(XATSRadio); |
|
643 XAAdaptationBase_RemoveEventHandler( self->adapCtx, &XARadioItfImpl_AdaptCb ); |
|
644 |
|
645 XARadioItfAdapt_Free(); |
|
646 assert(self==self->self); |
|
647 free(self); |
|
648 |
|
649 XA_IMPL_THREAD_SAFETY_EXIT_FOR_VOID_FUNCTIONS(XATSRadio); |
|
650 DEBUG_API("<-XARadioItfImpl_Free"); |
|
651 } |
|
652 |
|
653 /* void XARadioItfimpl_AdaptCb( void *pHandlerCtx, XAAdaptEvent *event ) |
|
654 * Description: Event handler for adaptation events |
|
655 */ |
|
656 void XARadioItfImpl_AdaptCb( void *pHandlerCtx, XAAdaptEvent *event ) |
|
657 { |
|
658 XARadioItfImpl* impl =(XARadioItfImpl*)pHandlerCtx; |
|
659 XAuint32 eventData = 0; |
|
660 XAboolean eventBoolean = XA_BOOLEAN_FALSE; |
|
661 |
|
662 DEBUG_API("->XARadioItfimpl_AdaptCb"); |
|
663 |
|
664 if(!impl) |
|
665 { |
|
666 DEBUG_ERR("XARadioItfImpl_AdaptCb, invalid context pointer!"); |
|
667 DEBUG_API("<-XARadioItfImpl_AdaptCb"); |
|
668 return; |
|
669 } |
|
670 assert(event); |
|
671 |
|
672 if( event->eventid == XA_ADAPT_RADIO_FREQUENCY_CHANGED && impl->callback ) |
|
673 { |
|
674 DEBUG_API("Frequency changed in adaptation"); |
|
675 eventData = *(XAuint32*)event->data; |
|
676 impl->callback( impl->cbPtrToSelf, impl->context, XA_RADIO_EVENT_FREQUENCY_CHANGED, eventData, eventBoolean ); |
|
677 } |
|
678 |
|
679 else if( event->eventid == XA_ADAPT_RADIO_FREQUENCY_RANGE_CHANGED && impl->callback ) |
|
680 { |
|
681 DEBUG_API("Frequency range changed in adaptation"); |
|
682 |
|
683 impl->callback( impl->cbPtrToSelf, impl->context, XA_RADIO_EVENT_FREQUENCY_RANGE_CHANGED, eventData, eventBoolean ); |
|
684 } |
|
685 |
|
686 else if( event->eventid == XA_ADAPT_RADIO_SEEK_COMPLETE && impl->callback ) |
|
687 { |
|
688 DEBUG_API("Seek complete in adaptation"); |
|
689 eventBoolean = *(XAboolean*)event->data; |
|
690 impl->callback( impl->cbPtrToSelf, impl->context, XA_RADIO_EVENT_SEEK_COMPLETED, eventData, eventBoolean ); |
|
691 } |
|
692 |
|
693 else if( event->eventid == XA_ADAPT_RADIO_STEREO_STATUS_CHANGED && impl->callback ) |
|
694 { |
|
695 DEBUG_API("Stereo status change in adaptation"); |
|
696 eventBoolean = *(XAboolean*)event->data; |
|
697 impl->callback( impl->cbPtrToSelf, impl->context, XA_RADIO_EVENT_STEREO_STATUS_CHANGED, eventData, eventBoolean ); |
|
698 } |
|
699 |
|
700 else if( event->eventid == XA_ADAPT_RADIO_SIGNAL_STRENGTH_CHANGED && impl->callback ) |
|
701 { |
|
702 DEBUG_API("Signal Strength Change in adaptation"); |
|
703 impl->callback( impl->cbPtrToSelf, impl->context, XA_RADIO_EVENT_SIGNAL_STRENGTH_CHANGED, eventData, eventBoolean ); |
|
704 } |
|
705 else |
|
706 { |
|
707 /* do nothing */ |
|
708 } |
|
709 DEBUG_API("<-XARadioItfimpl_AdaptCb"); |
|
710 } |
|
711 |
|