gwenhywfar  5.10.1
testmodule.c
Go to the documentation of this file.
1 /**********************************************************
2  * This file has been automatically created by "typemaker2"
3  * from the file "testmodule.xml".
4  * Please do not edit this file, all changes will be lost.
5  * Better edit the mentioned source file instead.
6  **********************************************************/
7 
8 #ifdef HAVE_CONFIG_H
9 # include <config.h>
10 #endif
11 
12 #include "./testmodule_p.h"
13 
14 #include <gwenhywfar/misc.h>
15 #include <gwenhywfar/debug.h>
16 
17 /* code headers */
18 
19 /* macro functions */
20 GWEN_TREE2_FUNCTIONS(GWEN_TEST_MODULE, GWEN_Test_Module)
22 
23 
25 {
26  GWEN_TEST_MODULE *p_struct;
27 
29  p_struct->_refCount=1;
31  GWEN_TREE2_INIT(GWEN_TEST_MODULE, p_struct, GWEN_Test_Module)
32  /* members */
33  p_struct->id=0;
34  p_struct->name=NULL;
35  p_struct->description=NULL;
36  p_struct->result=0;
37  p_struct->paramsDb=NULL;
38  /* virtual functions */
39 
40  return p_struct;
41 }
42 
44 {
45  if (p_struct) {
46  assert(p_struct->_refCount);
47  if (p_struct->_refCount==1) {
49  GWEN_TREE2_FINI(GWEN_TEST_MODULE, p_struct, GWEN_Test_Module)
50  /* members */
51  free(p_struct->name);
52  p_struct->name=NULL;
53  free(p_struct->description);
54  p_struct->description=NULL;
55  GWEN_DB_Group_free(p_struct->paramsDb);
56  p_struct->paramsDb=NULL;
57  p_struct->_refCount=0;
58  GWEN_FREE_OBJECT(p_struct);
59  }
60  else
61  p_struct->_refCount--;
62  }
63 }
64 
66 {
67  assert(p_struct);
68  assert(p_struct->_refCount);
69  p_struct->_refCount++;
70 }
71 
73 {
74  GWEN_TEST_MODULE *p_struct;
75 
76  assert(p_src);
77  p_struct=GWEN_Test_Module_new();
78  /* member "id" */
79  p_struct->id=p_src->id;
80 
81  /* member "name" */
82  if (p_struct->name) {
83  free(p_struct->name);
84  p_struct->name=NULL;
85  p_struct->name=NULL;
86  }
87  if (p_src->name) {
88  p_struct->name=strdup(p_src->name);
89  }
90 
91  /* member "description" */
92  if (p_struct->description) {
93  free(p_struct->description);
94  p_struct->description=NULL;
95  p_struct->description=NULL;
96  }
97  if (p_src->description) {
98  p_struct->description=strdup(p_src->description);
99  }
100 
101  /* member "result" */
102  p_struct->result=p_src->result;
103 
104  /* member "paramsDb" */
105  if (p_struct->paramsDb) {
106  GWEN_DB_Group_free(p_struct->paramsDb);
107  p_struct->paramsDb=NULL;
108  p_struct->paramsDb=NULL;
109  }
110  if (p_src->paramsDb) {
111  p_struct->paramsDb=GWEN_DB_Group_dup(p_src->paramsDb);
112  }
113 
114  return p_struct;
115 }
116 
118 {
119  assert(p_struct);
120  assert(p_src);
121  /* member "id" */
122  p_struct->id=p_src->id;
123 
124  /* member "name" */
125  if (p_struct->name) {
126  free(p_struct->name);
127  p_struct->name=NULL;
128  p_struct->name=NULL;
129  }
130  if (p_src->name) {
131  p_struct->name=strdup(p_src->name);
132  }
133 
134  /* member "description" */
135  if (p_struct->description) {
136  free(p_struct->description);
137  p_struct->description=NULL;
138  p_struct->description=NULL;
139  }
140  if (p_src->description) {
141  p_struct->description=strdup(p_src->description);
142  }
143 
144  /* member "result" */
145  p_struct->result=p_src->result;
146 
147  /* member "paramsDb" */
148  if (p_struct->paramsDb) {
149  GWEN_DB_Group_free(p_struct->paramsDb);
150  p_struct->paramsDb=NULL;
151  p_struct->paramsDb=NULL;
152  }
153  if (p_src->paramsDb) {
154  p_struct->paramsDb=GWEN_DB_Group_dup(p_src->paramsDb);
155  }
156 
157  return p_struct;
158 }
159 
160 uint32_t GWEN_Test_Module_GetId(const GWEN_TEST_MODULE *p_struct)
161 {
162  assert(p_struct);
163  return p_struct->id;
164 }
165 
166 const char *GWEN_Test_Module_GetName(const GWEN_TEST_MODULE *p_struct)
167 {
168  assert(p_struct);
169  return p_struct->name;
170 }
171 
173 {
174  assert(p_struct);
175  return p_struct->description;
176 }
177 
179 {
180  assert(p_struct);
181  return p_struct->result;
182 }
183 
185 {
186  assert(p_struct);
187  return p_struct->paramsDb;
188 }
189 
190 void GWEN_Test_Module_SetId(GWEN_TEST_MODULE *p_struct, uint32_t p_src)
191 {
192  assert(p_struct);
193  p_struct->id=p_src;
194 }
195 
196 void GWEN_Test_Module_SetName(GWEN_TEST_MODULE *p_struct, const char *p_src)
197 {
198  assert(p_struct);
199  if (p_struct->name) {
200  free(p_struct->name);
201  p_struct->name=NULL;
202  }
203  if (p_src) {
204  p_struct->name=strdup(p_src);
205  }
206  else {
207  p_struct->name=NULL;
208  }
209 }
210 
211 void GWEN_Test_Module_SetDescription(GWEN_TEST_MODULE *p_struct, const char *p_src)
212 {
213  assert(p_struct);
214  if (p_struct->description) {
215  free(p_struct->description);
216  p_struct->description=NULL;
217  }
218  if (p_src) {
219  p_struct->description=strdup(p_src);
220  }
221  else {
222  p_struct->description=NULL;
223  }
224 }
225 
227 {
228  assert(p_struct);
229  p_struct->result=p_src;
230 }
231 
233 {
234  assert(p_struct);
235  if (p_struct->paramsDb) {
236  GWEN_DB_Group_free(p_struct->paramsDb);
237  p_struct->paramsDb=NULL;
238  }
239  if (p_src) {
240  p_struct->paramsDb=GWEN_DB_Group_dup(p_src);
241  }
242  else {
243  p_struct->paramsDb=NULL;
244  }
245 }
246 
247 /* code for virtual functions */
249 {
250  assert(p_struct);
251  if (p_struct->testFn)
252  return p_struct->testFn(p_struct);
253  else
255 }
256 
257 /* setters for virtual functions */
259 {
261 
262  assert(p_struct);
263  oldFn=p_struct->testFn;
264  p_struct->testFn=fn;
265  return oldFn;
266 }
267 
269 {
270  assert(p_struct);
271  /* member "id" */
272  p_struct->id=GWEN_DB_GetIntValue(p_db, "id", 0, 0);
273 
274  /* member "name" */
275  if (p_struct->name) {
276  free(p_struct->name);
277  p_struct->name=NULL;
278  }
279  {
280  const char *s;
281  s=GWEN_DB_GetCharValue(p_db, "name", 0, NULL);
282  if (s)
283  p_struct->name=strdup(s);
284  }
285  if (p_struct->name==NULL) {
286  p_struct->name=NULL;
287  }
288 
289  /* member "description" */
290  if (p_struct->description) {
291  free(p_struct->description);
292  p_struct->description=NULL;
293  }
294  {
295  const char *s;
296  s=GWEN_DB_GetCharValue(p_db, "description", 0, NULL);
297  if (s)
298  p_struct->description=strdup(s);
299  }
300  if (p_struct->description==NULL) {
301  p_struct->description=NULL;
302  }
303 
304  /* member "result" */
305  p_struct->result=GWEN_DB_GetIntValue(p_db, "result", 0, 0);
306 
307  /* member "paramsDb" */
308  if (p_struct->paramsDb) {
309  GWEN_DB_Group_free(p_struct->paramsDb);
310  p_struct->paramsDb=NULL;
311  }
312  {
313  GWEN_DB_NODE *dbSrc;
314  dbSrc=GWEN_DB_GetGroup(p_db, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "paramsDb");
315  if (dbSrc) {
316  p_struct->paramsDb=GWEN_DB_Group_dup(dbSrc);
317  }
318  else
319  p_struct->paramsDb=NULL;
320  }
321  if (p_struct->paramsDb==NULL) {
322  p_struct->paramsDb=NULL;
323  }
324 
325 }
326 
328 {
329  int p_rv;
330 
331  assert(p_struct);
332  /* member "id" */
333  p_rv=GWEN_DB_SetIntValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "id", p_struct->id);
334  if (p_rv<0) {
335  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
336  return p_rv;
337  }
338 
339  /* member "name" */
340  if (p_struct->name)
341  p_rv=GWEN_DB_SetCharValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "name", p_struct->name);
342  else {
343  GWEN_DB_DeleteVar(p_db, "name");
344  p_rv=0;
345  }
346  if (p_rv<0) {
347  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
348  return p_rv;
349  }
350 
351  /* member "description" */
352  if (p_struct->description)
353  p_rv=GWEN_DB_SetCharValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "description", p_struct->description);
354  else {
355  GWEN_DB_DeleteVar(p_db, "description");
356  p_rv=0;
357  }
358  if (p_rv<0) {
359  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
360  return p_rv;
361  }
362 
363  /* member "result" */
364  p_rv=GWEN_DB_SetIntValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "result", p_struct->result);
365  if (p_rv<0) {
366  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
367  return p_rv;
368  }
369 
370  /* member "paramsDb" */
371  if (p_struct->paramsDb) {
372  GWEN_DB_NODE *dbCopy;
373  dbCopy=GWEN_DB_GetGroup(p_db, GWEN_DB_FLAGS_DEFAULT, "paramsDb");
374  assert(dbCopy);
375  p_rv=GWEN_DB_AddGroupChildren(dbCopy, p_struct->paramsDb);
376  }
377  else {
378  GWEN_DB_DeleteGroup(p_db, "paramsDb");
379  p_rv=0;
380  }
381  if (p_rv<0) {
382  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
383  return p_rv;
384  }
385 
386  return 0;
387 }
388 
390 {
391  GWEN_TEST_MODULE *p_struct;
392  p_struct=GWEN_Test_Module_new();
393  GWEN_Test_Module_ReadDb(p_struct, p_db);
394  return p_struct;
395 }
396 
398 {
399  return GWEN_Test_Module_WriteDb(p_struct, p_db);
400 }
401 
403 {
404  GWEN_TEST_MODULE *p_struct;
405 
406  assert(p_object);
407  p_struct = GWEN_Test_Module_Tree2_GetFirstChild(p_object);
408  while (p_struct) {
409  int p_rv;
410 
411  if (p_struct->id==p_cmp)
412  p_rv=0;
413  else if (p_cmp<p_struct->id)
414  p_rv=-1;
415  else
416  p_rv=1;
417  if (p_rv == 0)
418  return p_struct;
419  p_struct = GWEN_Test_Module_Tree2_GetBelow(p_struct);
420  }
421  return NULL;
422 }
423 
425  const char *tDescr)
426 {
427  GWEN_TEST_MODULE *mod;
428 
429  mod=GWEN_Test_Module_new();
430  if (tName && *tName)
431  GWEN_Test_Module_SetName(mod, tName);
432  if (tDescr && *tDescr)
433  GWEN_Test_Module_SetDescription(mod, tDescr);
434  if (fn)
436 
437  GWEN_Test_Module_Tree2_AddChild(st, mod);
438  return mod;
439 }
440 GWEN_TEST_MODULE *GWEN_Test_Module_AddModule(GWEN_TEST_MODULE *st, const char *tName, const char *tDescr)
441 {
442  GWEN_TEST_MODULE *mod;
443 
444  mod=GWEN_Test_Module_new();
445  if (tName && *tName)
446  GWEN_Test_Module_SetName(mod, tName);
447  if (tDescr && *tDescr)
448  GWEN_Test_Module_SetDescription(mod, tDescr);
449 
450  GWEN_Test_Module_Tree2_AddChild(st, mod);
451  return mod;
452 }
453 const char *GWEN_Test_Module_GetCharParam(const GWEN_TEST_MODULE *st, const char *paramName, const char *defVal)
454 {
455  assert(st);
456  while (st) {
457  if (st->paramsDb) {
458  const char *s;
459 
460  s=GWEN_DB_GetCharValue(st->paramsDb, paramName, 0, NULL);
461  if (s)
462  return s;
463  }
464  st=GWEN_Test_Module_Tree2_GetParent(st);
465  }
466 
467  return defVal;
468 }
469 void GWEN_Test_Module_SetCharParam(GWEN_TEST_MODULE *st, const char *paramName, const char *val)
470 {
471  assert(st);
472  if (st->paramsDb==NULL)
473  st->paramsDb=GWEN_DB_Group_new("params");
474  GWEN_DB_SetCharValue(st->paramsDb, GWEN_DB_FLAGS_OVERWRITE_VARS, paramName, val);
475 }
476 
477 /* code headers */
478 
void GWEN_Test_Module_SetParamsDb(GWEN_TEST_MODULE *p_struct, const GWEN_DB_NODE *p_src)
Definition: testmodule.c:232
void GWEN_Test_Module_free(GWEN_TEST_MODULE *p_struct)
Definition: testmodule.c:43
void GWEN_Test_Module_Attach(GWEN_TEST_MODULE *p_struct)
Definition: testmodule.c:65
#define GWEN_DB_FLAGS_OVERWRITE_VARS
Definition: db.h:121
GWEN_TEST_MODULE * GWEN_Test_Module_new(void)
Definition: testmodule.c:24
struct GWEN_DB_NODE GWEN_DB_NODE
Definition: db.h:228
#define GWEN_INHERIT_FINI(t, element)
Definition: inherit.h:238
void GWEN_DB_Group_free(GWEN_DB_NODE *n)
Definition: db.c:421
void GWEN_Test_Module_SetDescription(GWEN_TEST_MODULE *p_struct, const char *p_src)
Definition: testmodule.c:211
void GWEN_Test_Module_SetId(GWEN_TEST_MODULE *p_struct, uint32_t p_src)
Definition: testmodule.c:190
const char * GWEN_Test_Module_GetName(const GWEN_TEST_MODULE *p_struct)
Definition: testmodule.c:166
int GWEN_Test_Module_toDb(const GWEN_TEST_MODULE *p_struct, GWEN_DB_NODE *p_db)
Definition: testmodule.c:397
GWEN_TEST_MODULE * GWEN_Test_Module_Tree2_GetById(const GWEN_TEST_MODULE *p_object, uint32_t p_cmp)
Definition: testmodule.c:402
#define GWEN_FREE_OBJECT(varname)
Definition: memory.h:61
#define NULL
Definition: binreloc.c:300
const GWEN_DB_NODE * GWEN_Test_Module_GetParamsDb(const GWEN_TEST_MODULE *p_struct)
Definition: testmodule.c:184
#define GWEN_TREE2_FUNCTIONS(t, pr)
Definition: tree2.h:354
#define GWEN_LOGDOMAIN
Definition: logger.h:35
const char * GWEN_Test_Module_GetDescription(const GWEN_TEST_MODULE *p_struct)
Definition: testmodule.c:172
GWEN_TEST_MODULE * GWEN_Test_Module_copy(GWEN_TEST_MODULE *p_struct, const GWEN_TEST_MODULE *p_src)
Definition: testmodule.c:117
GWEN_TEST_MODULE * GWEN_Test_Module_AddTest(GWEN_TEST_MODULE *st, const char *tName, GWEN_TEST_MODULE_TEST_FN fn, const char *tDescr)
Definition: testmodule.c:424
#define GWEN_TREE2_FINI(t, element, pr)
Definition: tree2.h:457
GWEN_TEST_MODULE_TEST_FN GWEN_Test_Module_SetTestFn(GWEN_TEST_MODULE *p_struct, GWEN_TEST_MODULE_TEST_FN fn)
Definition: testmodule.c:258
#define GWEN_NEW_OBJECT(typ, varname)
Definition: memory.h:55
GWEN_TEST_MODULE * GWEN_Test_Module_fromDb(GWEN_DB_NODE *p_db)
Definition: testmodule.c:389
const char * GWEN_Test_Module_GetCharParam(const GWEN_TEST_MODULE *st, const char *paramName, const char *defVal)
Definition: testmodule.c:453
int GWEN_Test_Module_WriteDb(const GWEN_TEST_MODULE *p_struct, GWEN_DB_NODE *p_db)
Definition: testmodule.c:327
int GWEN_DB_DeleteGroup(GWEN_DB_NODE *n, const char *path)
Definition: db.c:922
int GWENHYWFAR_CB(* GWEN_TEST_MODULE_TEST_FN)(GWEN_TEST_MODULE *p_struct)
Definition: testmodule.h:75
struct GWEN_TEST_MODULE GWEN_TEST_MODULE
Definition: testmodule.h:65
int GWEN_Test_Module_GetResult(const GWEN_TEST_MODULE *p_struct)
Definition: testmodule.c:178
const char * GWEN_DB_GetCharValue(GWEN_DB_NODE *n, const char *path, int idx, const char *defVal)
Definition: db.c:971
GWEN_DB_NODE * GWEN_DB_Group_dup(const GWEN_DB_NODE *n)
Definition: db.c:428
#define GWEN_INHERIT_INIT(t, element)
Definition: inherit.h:223
GWEN_DB_NODE * GWEN_DB_GetGroup(GWEN_DB_NODE *n, uint32_t flags, const char *path)
Definition: db.c:1381
int GWEN_DB_DeleteVar(GWEN_DB_NODE *n, const char *path)
Definition: db.c:899
void GWEN_Test_Module_SetResult(GWEN_TEST_MODULE *p_struct, int p_src)
Definition: testmodule.c:226
void GWEN_Test_Module_ReadDb(GWEN_TEST_MODULE *p_struct, GWEN_DB_NODE *p_db)
Definition: testmodule.c:268
void GWEN_Test_Module_SetCharParam(GWEN_TEST_MODULE *st, const char *paramName, const char *val)
Definition: testmodule.c:469
uint32_t GWEN_Test_Module_GetId(const GWEN_TEST_MODULE *p_struct)
Definition: testmodule.c:160
int GWEN_DB_SetCharValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, const char *val)
Definition: db.c:997
GWEN_TEST_MODULE * GWEN_Test_Module_dup(const GWEN_TEST_MODULE *p_src)
Definition: testmodule.c:72
#define DBG_INFO(dbg_logger, format, args...)
Definition: debug.h:181
#define GWEN_TREE2_INIT(t, element, pr)
Definition: tree2.h:445
int GWEN_DB_GetIntValue(GWEN_DB_NODE *n, const char *path, int idx, int defVal)
Definition: db.c:1163
GWEN_DB_NODE * GWEN_DB_Group_new(const char *name)
Definition: db.c:173
int GWEN_DB_SetIntValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, int val)
Definition: db.c:1202
GWEN_TEST_MODULE * GWEN_Test_Module_AddModule(GWEN_TEST_MODULE *st, const char *tName, const char *tDescr)
Definition: testmodule.c:440
int GWEN_DB_AddGroupChildren(GWEN_DB_NODE *n, GWEN_DB_NODE *nn)
Definition: db.c:1524
#define GWEN_PATH_FLAGS_NAMEMUSTEXIST
Definition: path.h:84
#define GWEN_INHERIT_FUNCTIONS(t)
Definition: inherit.h:163
#define GWEN_DB_FLAGS_DEFAULT
Definition: db.h:168
int GWEN_Test_Module_Test(GWEN_TEST_MODULE *p_struct)
Definition: testmodule.c:248
void GWEN_Test_Module_SetName(GWEN_TEST_MODULE *p_struct, const char *p_src)
Definition: testmodule.c:196
#define GWEN_ERROR_NOT_IMPLEMENTED
Definition: error.h:108