gwenhywfar 5.12.0
tm_virtualfn.c
Go to the documentation of this file.
1/***************************************************************************
2 begin : Mon Jun 28 2010
3 copyright : (C) 2010 by Martin Preuss
4 email : martin@libchipcard.de
5
6 ***************************************************************************
7 * Please see toplevel file COPYING for license details *
8 ***************************************************************************/
9
10#ifdef HAVE_CONFIG_H
11# include <config.h>
12#endif
13
14#include "tm_virtualfn_p.h"
15#include "tm_util.h"
16#include "tm_type.h"
17
18
19#include <gwenhywfar/debug.h>
20#include <gwenhywfar/misc.h>
21
22#include <assert.h>
23
24
27
28
29
31{
33
35 vf->refCount=1;
37 vf->access=TypeMaker2_Access_Public;
38
39 vf->paramList=Typemaker2_VirtualFn_Param_List_new();
40 return vf;
41}
42
43
44
46{
47 if (vf) {
48 if (vf->refCount==1) {
50 free(vf->preset);
51 free(vf->name);
52 free(vf->descr);
53 free(vf->returnType);
54 free(vf->defaultReturnValue);
55 free(vf->location);
56 Typemaker2_VirtualFn_Param_List_free(vf->paramList);
57 vf->refCount=0;
59 }
60 else
61 vf->refCount--;
62 }
63}
64
65
66
68{
69 assert(vf);
70 assert(vf->refCount);
71 vf->refCount++;
72}
73
74
75
77{
78 const char *s;
79 GWEN_XMLNODE *n;
80
81 assert(vf);
82 assert(vf->refCount);
83
84 s=GWEN_XMLNode_GetProperty(node, "name", NULL);
85 if (s==NULL) {
86 DBG_ERROR(GWEN_LOGDOMAIN, "Member has no id");
88 }
90
91 s=GWEN_XMLNode_GetProperty(node, "location", "pre");
93
94 /* read flags */
95 s=GWEN_XMLNode_GetCharValue(node, "flags", NULL);
96 if (s && *s)
98
99 /* read access */
100 s=GWEN_XMLNode_GetCharValue(node, "access", NULL);
101 if (s && *s) {
104 DBG_ERROR(GWEN_LOGDOMAIN, "Unknown access type [%s]", s);
105 return GWEN_ERROR_BAD_DATA;
106 }
108 }
109
110 /* read default value */
111 s=GWEN_XMLNode_GetCharValue(node, "defaultReturnValue", NULL);
112 if (s && *s)
114
115 s=GWEN_XMLNode_GetCharValue(node, "preset", NULL);
116 if (s && *s)
118
119 /* read return type */
120 s=GWEN_XMLNode_GetCharValue(node, "returnType", NULL);
121 if (s && *s)
123
124 /* read returnType description */
125 n=GWEN_XMLNode_FindFirstTag(node, "returnType", NULL, NULL);
126 if (n) {
127 s=GWEN_XMLNode_GetCharValue(n, "descr", NULL);
129 }
130
131
132 n=GWEN_XMLNode_FindFirstTag(node, "params", NULL, NULL);
133 if (n) {
134 n=GWEN_XMLNode_FindFirstTag(n, "param", NULL, NULL);
135 while (n) {
136 const char *paramName;
137 const char *paramType;
138 const char *paramDescr;
140
141 paramType=GWEN_XMLNode_GetProperty(n, "type", NULL);
142 paramName=GWEN_XMLNode_GetProperty(n, "name", NULL);
143 paramDescr=GWEN_XMLNode_GetCharValue(n, "descr", NULL);
144
145 if (!(paramType && *paramType)) {
146 DBG_ERROR(GWEN_LOGDOMAIN, "Parameter has no type");
147 return GWEN_ERROR_BAD_DATA;
148 }
149
154 Typemaker2_VirtualFn_Param_List_Add(prm, vf->paramList);
155
156 n=GWEN_XMLNode_FindNextTag(n, "param", NULL, NULL);
157 }
158 }
159
160 /* read descr */
161 s=GWEN_XMLNode_GetCharValue(node, "descr", NULL);
163
164
165 return 0;
166}
167
168
169
171{
172 assert(vf);
173 assert(vf->refCount);
174
175 return vf->name;
176}
177
178
179
181{
182 assert(vf);
183 assert(vf->refCount);
184
185 free(vf->name);
186 if (s)
187 vf->name=strdup(s);
188 else
189 vf->name=NULL;
190}
191
192
193
195{
196 assert(vf);
197 assert(vf->refCount);
198
199 return vf->location;
200}
201
202
203
205{
206 assert(vf);
207 assert(vf->refCount);
208
209 free(vf->location);
210 if (s)
211 vf->location=strdup(s);
212 else
213 vf->location=NULL;
214}
215
216
217
219{
220 assert(vf);
221 assert(vf->refCount);
222
223 return vf->descr;
224}
225
226
227
229{
230 assert(vf);
231 assert(vf->refCount);
232
233 free(vf->descr);
234 if (s)
235 vf->descr=strdup(s);
236 else
237 vf->descr=NULL;
238}
239
240
241
243{
244 assert(vf);
245 assert(vf->refCount);
246
247 return vf->flags;
248}
249
250
251
253{
254 assert(vf);
255 assert(vf->refCount);
256
257 vf->flags=fl;
258}
259
260
261
263{
264 assert(vf);
265 assert(vf->refCount);
266
267 vf->flags|=fl;
268}
269
270
271
273{
274 assert(vf);
275 assert(vf->refCount);
276
277 vf->flags&=~fl;
278}
279
280
281
283{
284 assert(vf);
285 assert(vf->refCount);
286
287 return vf->access;
288}
289
290
291
293{
294 assert(vf);
295 assert(vf->refCount);
296
297 vf->access=i;
298}
299
300
301
303{
304 assert(vf);
305 assert(vf->refCount);
306
307 return vf->returnType;
308}
309
310
311
313{
314 assert(vf);
315 assert(vf->refCount);
316
317 free(vf->returnType);
318 if (s)
319 vf->returnType=strdup(s);
320 else
321 vf->returnType=NULL;
322}
323
324
325
327{
328 assert(vf);
329 return vf->returnTypeDescr;
330}
331
332
333
335{
336 assert(vf);
337 free(vf->returnTypeDescr);
338 if (s)
339 vf->returnTypeDescr=strdup(s);
340 else
341 vf->returnTypeDescr=NULL;
342}
343
344
345
347{
348 assert(vf);
349 assert(vf->refCount);
350
351 return vf->defaultReturnValue;
352}
353
354
355
357{
358 assert(vf);
359 assert(vf->refCount);
360
361 free(vf->defaultReturnValue);
362 if (s)
363 vf->defaultReturnValue=strdup(s);
364 else
365 vf->defaultReturnValue=NULL;
366}
367
368
369
370TYPEMAKER2_VIRTUALFN_PARAM_LIST *Typemaker2_VirtualFn_GetParamTypeList(const TYPEMAKER2_VIRTUALFN *vf)
371{
372 assert(vf);
373 assert(vf->refCount);
374
375 return vf->paramList;
376}
377
378
379
381{
382 assert(vf);
383 assert(vf->refCount);
384
385 return vf->preset;
386}
387
388
389
391{
392 assert(vf);
393 assert(vf->refCount);
394
395 free(vf->preset);
396 if (s)
397 vf->preset=strdup(s);
398 else
399 vf->preset=NULL;
400}
401
402
403
404
405
406
407
408
409
410
411
412
422
423
424
426{
427 if (prm) {
428 free(prm->name);
429 free(prm->type);
430 free(prm->descr);
431
432 GWEN_FREE_OBJECT(prm);
433 }
434}
435
436
437
439{
440 assert(prm);
441 return prm->name;
442}
443
444
445
447{
448 assert(prm);
449 free(prm->name);
450 if (s)
451 prm->name=strdup(s);
452 else
453 prm->name=NULL;
454}
455
456
457
459{
460 assert(prm);
461 return prm->type;
462}
463
464
465
467{
468 assert(prm);
469 free(prm->type);
470 if (s)
471 prm->type=strdup(s);
472 else
473 prm->type=NULL;
474}
475
476
477
479{
480 assert(prm);
481 return prm->descr;
482}
483
484
485
487{
488 assert(prm);
489 free(prm->descr);
490 if (s)
491 prm->descr=strdup(s);
492 else
493 prm->descr=NULL;
494}
495
496
497
498
499
500
501
502
#define NULL
Definition binreloc.c:300
#define DBG_ERROR(dbg_logger, format,...)
Definition debug.h:97
#define GWEN_ERROR_BAD_DATA
Definition error.h:121
#define GWEN_LIST_FINI(t, element)
Definition list1.h:475
#define GWEN_LIST_FUNCTIONS(t, pr)
Definition list1.h:367
#define GWEN_LIST_INIT(t, element)
Definition list1.h:466
#define GWEN_LOGDOMAIN
Definition logger.h:35
#define GWEN_FREE_OBJECT(varname)
Definition memory.h:61
#define GWEN_NEW_OBJECT(typ, varname)
Definition memory.h:55
@ TypeMaker2_Access_Unknown
Definition tm_type.h:85
@ TypeMaker2_Access_Public
Definition tm_type.h:86
int Typemaker2_AccessFromString(const char *s)
Definition tm_util.c:163
uint32_t Typemaker2_FlagsFromString(const char *t)
Definition tm_util.c:23
void Typemaker2_VirtualFn_SetDefaultReturnValue(TYPEMAKER2_VIRTUALFN *vf, const char *s)
const char * Typemaker2_VirtualFn_GetName(const TYPEMAKER2_VIRTUALFN *vf)
const char * Typemaker2_VirtualFn_GetDescr(const TYPEMAKER2_VIRTUALFN *vf)
void Typemaker2_VirtualFn_SetDescr(TYPEMAKER2_VIRTUALFN *vf, const char *s)
void Typemaker2_VirtualFn_SubFlags(TYPEMAKER2_VIRTUALFN *vf, uint32_t fl)
const char * Typemaker2_VirtualFn_GetDefaultReturnValue(const TYPEMAKER2_VIRTUALFN *vf)
void Typemaker2_VirtualFn_Param_SetName(TYPEMAKER2_VIRTUALFN_PARAM *prm, const char *s)
void Typemaker2_VirtualFn_Attach(TYPEMAKER2_VIRTUALFN *vf)
const char * Typemaker2_VirtualFn_GetReturnTypeDescr(const TYPEMAKER2_VIRTUALFN *vf)
const char * Typemaker2_VirtualFn_GetLocation(const TYPEMAKER2_VIRTUALFN *vf)
const char * Typemaker2_VirtualFn_Param_GetDescr(const TYPEMAKER2_VIRTUALFN_PARAM *prm)
const char * Typemaker2_VirtualFn_Param_GetType(const TYPEMAKER2_VIRTUALFN_PARAM *prm)
void Typemaker2_VirtualFn_SetName(TYPEMAKER2_VIRTUALFN *vf, const char *s)
void Typemaker2_VirtualFn_SetReturnTypeDescr(TYPEMAKER2_VIRTUALFN *vf, const char *s)
const char * Typemaker2_VirtualFn_Param_GetName(const TYPEMAKER2_VIRTUALFN_PARAM *prm)
void Typemaker2_VirtualFn_Param_SetType(TYPEMAKER2_VIRTUALFN_PARAM *prm, const char *s)
void Typemaker2_VirtualFn_SetFlags(TYPEMAKER2_VIRTUALFN *vf, uint32_t fl)
uint32_t Typemaker2_VirtualFn_GetFlags(const TYPEMAKER2_VIRTUALFN *vf)
void Typemaker2_VirtualFn_free(TYPEMAKER2_VIRTUALFN *vf)
TYPEMAKER2_VIRTUALFN * Typemaker2_VirtualFn_new()
TYPEMAKER2_VIRTUALFN_PARAM * Typemaker2_VirtualFn_Param_new()
void Typemaker2_VirtualFn_SetPreset(TYPEMAKER2_VIRTUALFN *vf, const char *s)
void Typemaker2_VirtualFn_SetAccess(TYPEMAKER2_VIRTUALFN *vf, int i)
void Typemaker2_VirtualFn_SetReturnType(TYPEMAKER2_VIRTUALFN *vf, const char *s)
void Typemaker2_VirtualFn_AddFlags(TYPEMAKER2_VIRTUALFN *vf, uint32_t fl)
const char * Typemaker2_VirtualFn_GetPreset(const TYPEMAKER2_VIRTUALFN *vf)
int Typemaker2_VirtualFn_GetAccess(const TYPEMAKER2_VIRTUALFN *vf)
void Typemaker2_VirtualFn_Param_SetDescr(TYPEMAKER2_VIRTUALFN_PARAM *prm, const char *s)
void Typemaker2_VirtualFn_Param_free(TYPEMAKER2_VIRTUALFN_PARAM *prm)
TYPEMAKER2_VIRTUALFN_PARAM_LIST * Typemaker2_VirtualFn_GetParamTypeList(const TYPEMAKER2_VIRTUALFN *vf)
int Typemaker2_VirtualFn_readXml(TYPEMAKER2_VIRTUALFN *vf, GWEN_XMLNODE *node)
void Typemaker2_VirtualFn_SetLocation(TYPEMAKER2_VIRTUALFN *vf, const char *s)
const char * Typemaker2_VirtualFn_GetReturnType(const TYPEMAKER2_VIRTUALFN *vf)
struct TYPEMAKER2_VIRTUALFN TYPEMAKER2_VIRTUALFN
struct TYPEMAKER2_VIRTUALFN_PARAM TYPEMAKER2_VIRTUALFN_PARAM
const char * GWEN_XMLNode_GetProperty(const GWEN_XMLNODE *n, const char *name, const char *defaultValue)
Definition xml.c:239
GWEN_XMLNODE * GWEN_XMLNode_FindFirstTag(const GWEN_XMLNODE *n, const char *tname, const char *pname, const char *pvalue)
Definition xml.c:776
GWEN_XMLNODE * GWEN_XMLNode_FindNextTag(const GWEN_XMLNODE *n, const char *tname, const char *pname, const char *pvalue)
Definition xml.c:794
const char * GWEN_XMLNode_GetCharValue(const GWEN_XMLNODE *n, const char *name, const char *defValue)
Definition xml.c:812
struct GWEN__XMLNODE GWEN_XMLNODE
Definition xml.h:156