|
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 "xaledarrayitf.h" |
|
22 #ifdef _GSTREAMER_BACKEND_ |
|
23 #include "XALEDArrayItfAdaptation.h" |
|
24 #endif |
|
25 #include "xathreadsafety.h" |
|
26 |
|
27 /* XALEDArrayItfImpl* GetImpl(XALEDArrayItf self) |
|
28 * Description: Validate interface pointer and cast it to implementation pointer. |
|
29 */ |
|
30 static XALEDArrayItfImpl* GetImpl(XALEDArrayItf self) |
|
31 { |
|
32 if( self ) |
|
33 { |
|
34 XALEDArrayItfImpl* impl = (XALEDArrayItfImpl*)(*self); |
|
35 if( impl && (impl == impl->self) ) |
|
36 { |
|
37 return impl; |
|
38 } |
|
39 } |
|
40 return NULL; |
|
41 } |
|
42 |
|
43 /***************************************************************************** |
|
44 * Base interface XALEDArrayItf implementation |
|
45 *****************************************************************************/ |
|
46 /* |
|
47 * XAresult XALEDArrayItfImpl_ActivateLEDArray ( XALEDArrayItf self, |
|
48 * XAuint32 lightMask ) |
|
49 * Description: Activates or deactivates individual LEDs in an array of LEDs. |
|
50 */ |
|
51 XAresult XALEDArrayItfImpl_ActivateLEDArray ( XALEDArrayItf self, |
|
52 XAuint32 lightMask ) |
|
53 { |
|
54 XAresult ret = XA_RESULT_SUCCESS; |
|
55 XALEDArrayItfImpl* impl = GetImpl(self); |
|
56 |
|
57 DEBUG_API("->XALEDArrayItfImpl_ActivateLEDArray"); |
|
58 XA_IMPL_THREAD_SAFETY_ENTRY(XATSLEDArray); |
|
59 |
|
60 if( !impl || lightMask > LED_COUNT) |
|
61 { |
|
62 /* invalid parameter */ |
|
63 XA_IMPL_THREAD_SAFETY_EXIT(XATSLEDArray); |
|
64 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
65 DEBUG_API("<-XALEDArrayItfImpl_ActivateLEDArray"); |
|
66 return XA_RESULT_PARAMETER_INVALID; |
|
67 } |
|
68 |
|
69 /* check is ligtMask mode changed */ |
|
70 if( impl->lightMask != lightMask ) |
|
71 { |
|
72 #ifdef _GSTREAMER_BACKEND_ |
|
73 ret = XALEDArrayItfAdapt_ActivateLEDArray( impl->adapCtx, lightMask ); |
|
74 #endif |
|
75 if ( ret == XA_RESULT_SUCCESS ) |
|
76 { |
|
77 impl->lightMask = lightMask; |
|
78 } |
|
79 } |
|
80 |
|
81 XA_IMPL_THREAD_SAFETY_EXIT(XATSLEDArray); |
|
82 DEBUG_API("<-XALEDArrayItfImpl_ActivateLEDArray"); |
|
83 return ret; |
|
84 } |
|
85 /* |
|
86 * XAresult XALEDArrayItfImpl_IsLEDArrayActivated ( XALEDArrayItf self, |
|
87 * XAuint32 * pLightMask ) |
|
88 * Description: Returns the state of each LED in an array of LEDs. |
|
89 */ |
|
90 XAresult XALEDArrayItfImpl_IsLEDArrayActivated ( XALEDArrayItf self, |
|
91 XAuint32 * pLightMask ) |
|
92 { |
|
93 XAresult ret = XA_RESULT_SUCCESS; |
|
94 XALEDArrayItfImpl* impl = GetImpl(self); |
|
95 DEBUG_API("->XALEDArrayItfImpl_IsLEDArrayActivated"); |
|
96 |
|
97 if( !impl || !pLightMask) |
|
98 { |
|
99 /* invalid parameter */ |
|
100 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
101 DEBUG_API("<-XALEDArrayItfImpl_IsLEDArrayActivated"); |
|
102 return XA_RESULT_PARAMETER_INVALID; |
|
103 } |
|
104 |
|
105 *pLightMask = impl->lightMask; |
|
106 |
|
107 if( *pLightMask ) |
|
108 { |
|
109 DEBUG_API("The LED is on."); |
|
110 } |
|
111 else |
|
112 { |
|
113 DEBUG_API("The LED is off."); |
|
114 } |
|
115 |
|
116 DEBUG_API("<-XALEDArrayItfImpl_IsLEDArrayActivated"); |
|
117 return ret; |
|
118 } |
|
119 /* |
|
120 * XAresult XALEDArrayItfImpl_SetColor ( XALEDArrayItf self, |
|
121 * XAuint8 index, |
|
122 * const XAHSL * pColor ) |
|
123 * Description: Sets the color of an individual LED. |
|
124 */ |
|
125 XAresult XALEDArrayItfImpl_SetColor ( XALEDArrayItf self, |
|
126 XAuint8 index, |
|
127 const XAHSL * pColor ) |
|
128 { |
|
129 XAresult ret = XA_RESULT_SUCCESS; |
|
130 XALEDArrayItfImpl* impl = GetImpl(self); |
|
131 XAboolean support = XA_BOOLEAN_FALSE; |
|
132 |
|
133 DEBUG_API("->XALEDArrayItfImpl_SetColor"); |
|
134 XA_IMPL_THREAD_SAFETY_ENTRY(XATSLEDArray); |
|
135 |
|
136 if( !impl || index > LED_COUNT - 1 || !pColor ) |
|
137 { |
|
138 /* invalid parameter */ |
|
139 XA_IMPL_THREAD_SAFETY_EXIT(XATSLEDArray); |
|
140 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
141 DEBUG_API("<-XALEDArrayItfImpl_SetColor"); |
|
142 return XA_RESULT_PARAMETER_INVALID; |
|
143 } |
|
144 |
|
145 support = ( COLOR_MASK >> index ) & 0x1; |
|
146 if( !support ) /* Not supporting color*/ |
|
147 { |
|
148 XA_IMPL_THREAD_SAFETY_EXIT(XATSLEDArray); |
|
149 DEBUG_ERR("XA_RESULT_PRECONDITIONS_VIOLATED: not supporting color"); |
|
150 DEBUG_API("<-XALEDArrayItfImpl_SetColor"); |
|
151 return XA_RESULT_PRECONDITIONS_VIOLATED; |
|
152 } |
|
153 else |
|
154 { |
|
155 #ifdef _GSTREAMER_BACKEND_ |
|
156 ret = XALEDArrayItfAdapt_SetColor( impl->adapCtx, index, pColor); |
|
157 #endif |
|
158 if ( ret == XA_RESULT_SUCCESS ) |
|
159 { |
|
160 impl->color = *pColor; |
|
161 } |
|
162 } |
|
163 |
|
164 XA_IMPL_THREAD_SAFETY_EXIT(XATSLEDArray); |
|
165 DEBUG_API("<-XALEDArrayItfImpl_SetColor"); |
|
166 return ret; |
|
167 } |
|
168 /* |
|
169 * XAresult XALEDArrayItfImpl_GetColor ( XALEDArrayItf self, |
|
170 * XAuint8 index, |
|
171 * const XAHSL * pColor ) |
|
172 * Description: Returns the color of an individual LED. |
|
173 */ |
|
174 XAresult XALEDArrayItfImpl_GetColor ( XALEDArrayItf self, |
|
175 XAuint8 index, |
|
176 XAHSL * pColor ) |
|
177 { |
|
178 XAresult ret = XA_RESULT_SUCCESS; |
|
179 XALEDArrayItfImpl* impl = GetImpl(self); |
|
180 XAboolean support = XA_BOOLEAN_FALSE; |
|
181 DEBUG_API("->XALEDArrayItfImpl_GetColor"); |
|
182 |
|
183 if( !impl || index > LED_COUNT - 1 || !pColor ) |
|
184 { |
|
185 /* invalid parameter */ |
|
186 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
187 DEBUG_API("<-XALEDArrayItfImpl_GetColor"); |
|
188 return XA_RESULT_PARAMETER_INVALID; |
|
189 } |
|
190 |
|
191 |
|
192 support = ( COLOR_MASK >> index ) & 0x1; |
|
193 if( !support ) /* Not supporting color*/ |
|
194 { |
|
195 DEBUG_ERR("XA_RESULT_PRECONDITIONS_VIOLATED: not supporting color"); |
|
196 DEBUG_API("<-XALEDArrayItfImpl_GetColor"); |
|
197 return XA_RESULT_PRECONDITIONS_VIOLATED; |
|
198 } |
|
199 else |
|
200 { |
|
201 *pColor = impl->color; |
|
202 } |
|
203 |
|
204 DEBUG_API_A3("<-XALEDArrayItfImpl_GetColor: hue = %ld, saturation = %d, lightness = %d", pColor->hue, pColor->saturation, pColor->lightness); |
|
205 return ret; |
|
206 } |
|
207 |
|
208 /***************************************************************************** |
|
209 * XALEDArrayItfImpl -specific methods |
|
210 *****************************************************************************/ |
|
211 #ifdef _GSTREAMER_BACKEND_ |
|
212 |
|
213 /* XALEDArrayItfImpl* XALEDArrayItfImpl_Create() |
|
214 * Description: Allocate and initialize LEDArrayItfImpl |
|
215 */ |
|
216 XALEDArrayItfImpl* XALEDArrayItfImpl_Create( XAAdaptationBaseCtx *adapCtx ) |
|
217 { |
|
218 XALEDArrayItfImpl* self = (XALEDArrayItfImpl*) |
|
219 calloc(1,sizeof(XALEDArrayItfImpl)); |
|
220 DEBUG_API("->XALEDArrayItfImpl_Create"); |
|
221 if( self ) |
|
222 { |
|
223 /* init itf default implementation */ |
|
224 self->itf.ActivateLEDArray = XALEDArrayItfImpl_ActivateLEDArray; |
|
225 self->itf.IsLEDArrayActivated = XALEDArrayItfImpl_IsLEDArrayActivated; |
|
226 self->itf.SetColor = XALEDArrayItfImpl_SetColor; |
|
227 self->itf.GetColor = XALEDArrayItfImpl_GetColor; |
|
228 |
|
229 /* init variables */ |
|
230 self->lightMask = 0; |
|
231 self->color.hue = 0; |
|
232 self->color.saturation = 0; |
|
233 self->color.lightness = 0; |
|
234 self->adapCtx = adapCtx; |
|
235 |
|
236 self->self = self; |
|
237 } |
|
238 |
|
239 DEBUG_API("<-XALEDArrayItfImpl_Create"); |
|
240 return self; |
|
241 } |
|
242 #endif |
|
243 /* void XALEDArrayItfImpl_Free(XALEDArrayItfImpl* self) |
|
244 * Description: Free all resources reserved at XALEDArrayItfImpl_Create |
|
245 */ |
|
246 void XALEDArrayItfImpl_Free(XALEDArrayItfImpl* self) |
|
247 { |
|
248 DEBUG_API("->XALEDArrayItfImpl_Free"); |
|
249 assert( self==self->self ); |
|
250 free( self ); |
|
251 DEBUG_API("<-XALEDArrayItfImpl_Free"); |
|
252 } |