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 |
|
22 #include "xametadatatraversalitf.h" |
|
23 |
|
24 #include "xametadataadaptation.h" |
|
25 |
|
26 /* XAMetadataTraversalImpl* GetImpl(XAMetadataTraversalItf self) |
|
27 * Description: Validate interface pointer and cast it to implementation pointer. |
|
28 */ |
|
29 static XAMetadataTraversalImpl* GetImpl(XAMetadataTraversalItf self) |
|
30 { |
|
31 if( self ) |
|
32 { |
|
33 XAMetadataTraversalImpl* impl = (XAMetadataTraversalImpl*)(*self); |
|
34 if( impl && (impl == impl->self) ) |
|
35 { |
|
36 return impl; |
|
37 } |
|
38 } |
|
39 return NULL; |
|
40 } |
|
41 |
|
42 /***************************************************************************** |
|
43 * Base interface XAMetadataTraversalItf implementation |
|
44 *****************************************************************************/ |
|
45 |
|
46 /* XAresult XAMetadataTraversalItfImpl_SetMode |
|
47 * Description: Sets the metadata traversal mode |
|
48 */ |
|
49 XAresult XAMetadataTraversalItfImpl_SetMode(XAMetadataTraversalItf self, |
|
50 XAuint32 mode) |
|
51 { |
|
52 XAMetadataTraversalImpl *impl = NULL; |
|
53 XAresult res = XA_RESULT_SUCCESS; |
|
54 |
|
55 DEBUG_API("->XAMetadataTraversalItfImpl_SetMode"); |
|
56 impl = GetImpl(self); |
|
57 /* check parameters */ |
|
58 if( !impl || |
|
59 (mode!=XA_METADATATRAVERSALMODE_NODE && |
|
60 mode!=XA_METADATATRAVERSALMODE_ALL)) |
|
61 { |
|
62 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
63 res = XA_RESULT_PARAMETER_INVALID; |
|
64 } |
|
65 else if(impl->traversemode != mode) |
|
66 { |
|
67 |
|
68 res =XAMetadataTraversalItfAdapt_SetMode((XAAdaptationGstCtx*)impl->adaptCtx, mode); |
|
69 |
|
70 if( res == XA_RESULT_SUCCESS ) |
|
71 { |
|
72 impl->traversemode = mode; |
|
73 } |
|
74 } |
|
75 else |
|
76 { |
|
77 /* do nothing */ |
|
78 } |
|
79 |
|
80 DEBUG_API("<-XAMetadataTraversalItfImpl_SetMode"); |
|
81 return res; |
|
82 } |
|
83 |
|
84 /* XAresult XAMetadataTraversalItfImpl_GetChildCount |
|
85 * Description: Returns the number of children (nodes, streams, etc.) within the current scope |
|
86 */ |
|
87 XAresult XAMetadataTraversalItfImpl_GetChildCount(XAMetadataTraversalItf self, |
|
88 XAuint32 *pCount) |
|
89 { |
|
90 XAMetadataTraversalImpl *impl = NULL; |
|
91 XAresult res = XA_RESULT_SUCCESS; |
|
92 |
|
93 DEBUG_API("->XAMetadataTraversalItfImpl_GetChildCount"); |
|
94 impl = GetImpl(self); |
|
95 if( !impl || !pCount ) |
|
96 { |
|
97 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
98 res = XA_RESULT_PARAMETER_INVALID; |
|
99 } |
|
100 else |
|
101 { |
|
102 if(impl->traversemode==XA_METADATATRAVERSALMODE_ALL) |
|
103 { |
|
104 /* for this mode, child count is always 0 */ |
|
105 *pCount = 0; |
|
106 res = XA_RESULT_SUCCESS; |
|
107 } |
|
108 else |
|
109 { |
|
110 |
|
111 res = XAMetadataTraversalItfAdapt_GetChildCount((XAAdaptationGstCtx*)impl->adaptCtx, pCount); |
|
112 |
|
113 } |
|
114 } |
|
115 |
|
116 DEBUG_API("<-XAMetadataTraversalItfImpl_GetChildCount"); |
|
117 return res; |
|
118 } |
|
119 |
|
120 /* XAresult XAMetadataTraversalItfImpl_GetChildMIMETypeSize |
|
121 * Description: Returns the size in bytes needed to store the MIME type of a child |
|
122 */ |
|
123 XAresult XAMetadataTraversalItfImpl_GetChildMIMETypeSize(XAMetadataTraversalItf self, |
|
124 XAuint32 index, |
|
125 XAuint32 *pSize) |
|
126 { |
|
127 XAMetadataTraversalImpl *impl = NULL; |
|
128 |
|
129 XAuint32 chCount = 0; |
|
130 |
|
131 XAresult res = XA_RESULT_SUCCESS; |
|
132 |
|
133 DEBUG_API("->XAMetadataTraversalItfImpl_GetChildMIMETypeSize"); |
|
134 impl = GetImpl(self); |
|
135 |
|
136 if( !impl || !pSize) |
|
137 { |
|
138 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
139 res = XA_RESULT_PARAMETER_INVALID; |
|
140 } |
|
141 else |
|
142 { |
|
143 |
|
144 res = XAMetadataTraversalItfAdapt_GetChildCount((XAAdaptationGstCtx*)impl->adaptCtx, &chCount); |
|
145 if(index >= chCount || res != XA_RESULT_SUCCESS) |
|
146 { |
|
147 /* out of bounds */ |
|
148 res = XA_RESULT_PARAMETER_INVALID; |
|
149 } |
|
150 res = XAMetadataTraversalItfAdapt_GetChildMIMETypeSize((XAAdaptationGstCtx*)impl->adaptCtx, index, pSize); |
|
151 |
|
152 } |
|
153 |
|
154 DEBUG_API("<-XAMetadataTraversalItfImpl_GetChildMIMETypeSize"); |
|
155 return res; |
|
156 } |
|
157 |
|
158 /* XAresult XAMetadataTraversalItfImpl_GetChildInfo |
|
159 * Description: Returns information about a child |
|
160 */ |
|
161 XAresult XAMetadataTraversalItfImpl_GetChildInfo(XAMetadataTraversalItf self, |
|
162 XAuint32 index, |
|
163 XAint32 *pNodeID, |
|
164 XAuint32 *pType, |
|
165 XAuint32 size, |
|
166 XAchar *pMimeType) |
|
167 { |
|
168 XAMetadataTraversalImpl *impl = NULL; |
|
169 |
|
170 XAuint32 chCount = 0; |
|
171 |
|
172 XAresult res = XA_RESULT_SUCCESS; |
|
173 |
|
174 DEBUG_API("->XAMetadataTraversalItfImpl_GetChildInfo"); |
|
175 impl = GetImpl(self); |
|
176 if( !impl || !pNodeID || !pType ) |
|
177 { |
|
178 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
179 res = XA_RESULT_PARAMETER_INVALID; |
|
180 } |
|
181 else |
|
182 { |
|
183 |
|
184 res = XAMetadataTraversalItfAdapt_GetChildCount((XAAdaptationGstCtx*)impl->adaptCtx, &chCount); |
|
185 if(index >= chCount || res != XA_RESULT_SUCCESS) |
|
186 { |
|
187 /* out of bounds */ |
|
188 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
189 DEBUG_API("<-XAMetadataTraversalItfImpl_GetChildInfo"); |
|
190 return XA_RESULT_PARAMETER_INVALID; |
|
191 } |
|
192 res = XAMetadataTraversalItfAdapt_GetChildInfo((XAAdaptationGstCtx*)impl->adaptCtx, index, |
|
193 pNodeID, pType, size, pMimeType); |
|
194 |
|
195 } |
|
196 |
|
197 DEBUG_API("<-XAMetadataTraversalItfImpl_GetChildInfo"); |
|
198 return res; |
|
199 } |
|
200 |
|
201 /* XAresult XAMetadataTraversalItfImpl_SetActiveNode |
|
202 * Description: Sets the scope to a child node |
|
203 */ |
|
204 XAresult XAMetadataTraversalItfImpl_SetActiveNode(XAMetadataTraversalItf self, |
|
205 XAuint32 index) |
|
206 { |
|
207 XAMetadataTraversalImpl *impl = NULL; |
|
208 |
|
209 XAuint32 chCount = 0; |
|
210 |
|
211 XAresult res = XA_RESULT_SUCCESS; |
|
212 |
|
213 DEBUG_API("->XAMetadataTraversalItfImpl_SetActiveNode"); |
|
214 impl = GetImpl(self); |
|
215 if( !impl ) |
|
216 { |
|
217 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
218 res = XA_RESULT_PARAMETER_INVALID; |
|
219 } |
|
220 else |
|
221 { |
|
222 |
|
223 res = XAMetadataTraversalItfAdapt_GetChildCount((XAAdaptationGstCtx*)impl->adaptCtx, &chCount); |
|
224 if( res == XA_RESULT_SUCCESS ) |
|
225 { |
|
226 if((impl->nodedepth==0 && index==XA_NODE_PARENT) || |
|
227 (index >= chCount && index!=XA_NODE_PARENT)) |
|
228 { |
|
229 /* try to ascend from root or descend to nonexistend child node */ |
|
230 res = XA_RESULT_PARAMETER_INVALID; |
|
231 } |
|
232 else |
|
233 { |
|
234 /* update node and childs */ |
|
235 res = XAMetadataTraversalItfAdapt_SetActiveNode((XAAdaptationGstCtx*)impl->adaptCtx, index); |
|
236 if( res == XA_RESULT_SUCCESS ) |
|
237 { |
|
238 if(index==XA_NODE_PARENT) |
|
239 { |
|
240 impl->nodedepth++; |
|
241 } |
|
242 else |
|
243 { |
|
244 impl->nodedepth--; |
|
245 } |
|
246 } |
|
247 } |
|
248 } |
|
249 else |
|
250 { |
|
251 DEBUG_ERR("XA_RESULT_INTERNAL_ERROR"); |
|
252 DEBUG_API("<-XAMetadataTraversalItfImpl_SetActiveNode"); |
|
253 return XA_RESULT_INTERNAL_ERROR; |
|
254 } |
|
255 |
|
256 } |
|
257 |
|
258 DEBUG_API("<-XAMetadataTraversalItfImpl_SetActiveNode"); |
|
259 return res; |
|
260 } |
|
261 |
|
262 /***************************************************************************** |
|
263 * XAMetadataTraversalImpl -specific methods |
|
264 *****************************************************************************/ |
|
265 |
|
266 /* XAMetadataTraversalImpl* XAMetadataTraversalItfImpl_Create() |
|
267 * Description: Allocate and initialize XAMetadataTraversalImpl |
|
268 */ |
|
269 XAMetadataTraversalImpl* XAMetadataTraversalItfImpl_Create( XAAdaptationBaseCtx *adaptCtx ) |
|
270 { |
|
271 XAMetadataTraversalImpl *self = NULL; |
|
272 DEBUG_API("->XAMetadataTraversalItfImpl_Create"); |
|
273 |
|
274 self = (XAMetadataTraversalImpl*) calloc(1,sizeof(XAMetadataTraversalImpl)); |
|
275 |
|
276 if( self ) |
|
277 { |
|
278 /* init itf default implementation */ |
|
279 self->itf.SetMode = XAMetadataTraversalItfImpl_SetMode; |
|
280 self->itf.GetChildCount = XAMetadataTraversalItfImpl_GetChildCount; |
|
281 self->itf.GetChildMIMETypeSize = XAMetadataTraversalItfImpl_GetChildMIMETypeSize; |
|
282 self->itf.GetChildInfo = XAMetadataTraversalItfImpl_GetChildInfo; |
|
283 self->itf.SetActiveNode = XAMetadataTraversalItfImpl_SetActiveNode; |
|
284 |
|
285 /* init variables */ |
|
286 self->adaptCtx = adaptCtx; |
|
287 |
|
288 self->self = self; |
|
289 } |
|
290 DEBUG_API("<-XAMetadataTraversalItfImpl_Create"); |
|
291 return self; |
|
292 } |
|
293 |
|
294 /* void XAMetadataTraversalItfImpl_Free(XAMetadataTraversalImpl* self) |
|
295 * Description: Free all resources reserved at XAMetadataTraversalItfImpl_Create |
|
296 */ |
|
297 void XAMetadataTraversalItfImpl_Free(XAMetadataTraversalImpl* self) |
|
298 { |
|
299 DEBUG_API("->XAMetadataTraversalItfImpl_Free"); |
|
300 assert(self==self->self); |
|
301 free(self); |
|
302 DEBUG_API("<-XAMetadataTraversalItfImpl_Free"); |
|
303 } |
|