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 "xaglobals.h" |
|
23 #include "xaconfigextensionsitf.h" |
|
24 |
|
25 static XAConfigExtensionsItfImpl* GetImpl(XAConfigExtensionsItf self) |
|
26 { |
|
27 if( self ) |
|
28 { |
|
29 XAConfigExtensionsItfImpl* impl = (XAConfigExtensionsItfImpl*)(*self); |
|
30 if( impl && (impl == impl->self) ) |
|
31 { |
|
32 return impl; |
|
33 } |
|
34 } |
|
35 return NULL; |
|
36 } |
|
37 |
|
38 /** |
|
39 * Base interface XAConfigExtensionsItf implementation |
|
40 */ |
|
41 XAresult XAConfigExtensionsItfImpl_SetConfiguration( |
|
42 XAConfigExtensionsItf self, |
|
43 const XAchar* configKey, |
|
44 XAuint32 valueSize, |
|
45 const void* pConfigValue) |
|
46 { |
|
47 XAConfigExtensionsItfImpl* impl = GetImpl(self); |
|
48 XAresult res = XA_RESULT_SUCCESS; |
|
49 DEBUG_API("->XAConfigExtensionsItfImpl_SetConfiguration"); |
|
50 if( !impl || !configKey ) |
|
51 { |
|
52 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
53 DEBUG_API("<-XAConfigExtensionsItfImpl_SetConfiguration"); |
|
54 return XA_RESULT_PARAMETER_INVALID; |
|
55 } |
|
56 if( strcmp((char *)configKey, CPCONFIGKEY) == 0 |
|
57 && pConfigValue ) |
|
58 { |
|
59 XAuint8 numValue = *(XAuint8*)(pConfigValue); |
|
60 impl->testbufferconf = numValue; |
|
61 if( numValue>4 ) |
|
62 { /* Conformance tester uses only reference-to-string values, try to parse string to integer |
|
63 * First char is enough since legal values are 0 to 4 |
|
64 */ |
|
65 XAchar* chVal = *(XAchar**)(pConfigValue); |
|
66 if(chVal) |
|
67 { |
|
68 impl->testbufferconf = *chVal; |
|
69 numValue = (*chVal) - 48; |
|
70 } |
|
71 if( numValue>4 ) |
|
72 { |
|
73 res = XA_RESULT_PARAMETER_INVALID; |
|
74 } |
|
75 } |
|
76 DEBUG_INFO_A1("CP conf value %d", numValue); |
|
77 if(res == XA_RESULT_SUCCESS) |
|
78 { |
|
79 |
|
80 /*Inform adaptation*/ |
|
81 if( impl->ctx ) |
|
82 { |
|
83 /* res = XAAdaptationBase_SetCPConfiguration(impl->ctx,impl->testbufferconf);*/ |
|
84 } |
|
85 |
|
86 } |
|
87 } |
|
88 else |
|
89 { |
|
90 DEBUG_ERR("Unknown key or invalid value pointer"); |
|
91 res = XA_RESULT_PARAMETER_INVALID; |
|
92 } |
|
93 DEBUG_API("<-XAConfigExtensionsItfImpl_SetConfiguration"); |
|
94 return res; |
|
95 } |
|
96 |
|
97 XAresult XAConfigExtensionsItfImpl_GetConfiguration( |
|
98 XAConfigExtensionsItf self, |
|
99 const XAchar* configKey, |
|
100 XAuint32* pValueSize, |
|
101 void* pConfigValue) |
|
102 { |
|
103 XAConfigExtensionsItfImpl* impl = GetImpl(self); |
|
104 XAresult res = XA_RESULT_SUCCESS; |
|
105 DEBUG_API("->XAConfigExtensionsItfImpl_GetConfiguration"); |
|
106 |
|
107 if( !impl ) |
|
108 { |
|
109 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
110 DEBUG_API("<-XAConfigExtensionsItfImpl_SetConfiguration"); |
|
111 return XA_RESULT_PARAMETER_INVALID; |
|
112 } |
|
113 |
|
114 if( strcmp((char *)configKey, CPCONFIGKEY) == 0 |
|
115 && pValueSize |
|
116 && sizeof(XAuint8) <= *pValueSize |
|
117 && pConfigValue ) |
|
118 { |
|
119 memcpy(*(XAuint8**)pConfigValue, &(impl->testbufferconf),1); |
|
120 *pValueSize = sizeof(XAuint8); |
|
121 res = XA_RESULT_SUCCESS; |
|
122 } |
|
123 else |
|
124 { |
|
125 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
126 res = XA_RESULT_PARAMETER_INVALID; |
|
127 } |
|
128 DEBUG_API("<-XAConfigExtensionsItfImpl_GetConfiguration"); |
|
129 return res; |
|
130 } |
|
131 |
|
132 |
|
133 XAresult XAConfigExtensionsItfImpl_SetContext(XAConfigExtensionsItfImpl* self,XAAdaptationBaseCtx* adptctx) |
|
134 { |
|
135 XAresult res = XA_RESULT_SUCCESS; |
|
136 DEBUG_API("->XAConfigExtensionsItfImpl_SetContext"); |
|
137 if( adptctx && self) |
|
138 { |
|
139 self->ctx = adptctx; |
|
140 res = XA_RESULT_SUCCESS; |
|
141 } |
|
142 else |
|
143 { |
|
144 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
145 res = XA_RESULT_PARAMETER_INVALID; |
|
146 } |
|
147 DEBUG_API("<-XAConfigExtensionsItfImpl_SetContext"); |
|
148 return res; |
|
149 } |
|
150 |
|
151 /** |
|
152 * XAConfigExtensionsItfImpl -specific methods |
|
153 **/ |
|
154 XAConfigExtensionsItfImpl* XAConfigExtensionsItfImpl_Create() |
|
155 { |
|
156 XAConfigExtensionsItfImpl* self = (XAConfigExtensionsItfImpl*) |
|
157 calloc(1,sizeof(XAConfigExtensionsItfImpl)); |
|
158 DEBUG_API("->XAConfigExtensionsItfImpl_Create"); |
|
159 |
|
160 if(self) |
|
161 { |
|
162 /* init itf default implementation */ |
|
163 self->itf.GetConfiguration = |
|
164 XAConfigExtensionsItfImpl_GetConfiguration; |
|
165 self->itf.SetConfiguration = |
|
166 XAConfigExtensionsItfImpl_SetConfiguration; |
|
167 /* init variables */ |
|
168 self->self = self; |
|
169 } |
|
170 DEBUG_API("<-XAConfigExtensionsItfImpl_Create"); |
|
171 return self; |
|
172 } |
|
173 |
|
174 void XAConfigExtensionsItfImpl_Free(XAConfigExtensionsItfImpl* self) |
|
175 { |
|
176 DEBUG_API("->XAConfigExtensionsItfImpl_Free"); |
|
177 assert(self==self->self); |
|
178 free(self); |
|
179 DEBUG_API("<-XAConfigExtensionsItfImpl_Free"); |
|
180 } |
|