request.c

Go to the documentation of this file.
00001 /* This file is auto-generated from "request.xml" by the typemaker
00002    tool of Gwenhywfar. 
00003    Do not edit this file -- all changes will be lost! */
00004 #ifdef HAVE_CONFIG_H
00005 # include "config.h"
00006 #endif
00007 
00008 #include "request_p.h"
00009 #include <gwenhywfar/misc.h>
00010 #include <gwenhywfar/db.h>
00011 #include <gwenhywfar/debug.h>
00012 #include <assert.h>
00013 #include <stdlib.h>
00014 #include <strings.h>
00015 
00016 
00017 GWEN_INHERIT_FUNCTIONS(GWEN_IPC_REQUEST)
00018 GWEN_LIST_FUNCTIONS(GWEN_IPC_REQUEST, GWEN_IpcRequest)
00019 GWEN_LIST2_FUNCTIONS(GWEN_IPC_REQUEST, GWEN_IpcRequest)
00020 
00021 
00022 GWEN_IPC_REQUEST_STATUS GWEN_IpcRequest_Status_fromString(const char *s) {
00023   if (s) {
00024     if (strcasecmp(s, "new")==0)
00025       return GWEN_IpcRequest_StatusNew;
00026     else if (strcasecmp(s, "sent")==0)
00027       return GWEN_IpcRequest_StatusSent;
00028     else if (strcasecmp(s, "partial")==0)
00029       return GWEN_IpcRequest_StatusPartial;
00030     else if (strcasecmp(s, "answered")==0)
00031       return GWEN_IpcRequest_StatusAnswered;
00032     else if (strcasecmp(s, "finished")==0)
00033       return GWEN_IpcRequest_StatusFinished;
00034   }
00035   return GWEN_IpcRequest_StatusUnknown;
00036 }
00037 
00038 
00039 const char *GWEN_IpcRequest_Status_toString(GWEN_IPC_REQUEST_STATUS v) {
00040   switch(v) {
00041     case GWEN_IpcRequest_StatusNew:
00042       return "new";
00043 
00044     case GWEN_IpcRequest_StatusSent:
00045       return "sent";
00046 
00047     case GWEN_IpcRequest_StatusPartial:
00048       return "partial";
00049 
00050     case GWEN_IpcRequest_StatusAnswered:
00051       return "answered";
00052 
00053     case GWEN_IpcRequest_StatusFinished:
00054       return "finished";
00055 
00056     default:
00057       return "unknown";
00058   } /* switch */
00059 } 
00060 
00061 
00062 GWEN_IPC_REQUEST *GWEN_IpcRequest_new() {
00063   GWEN_IPC_REQUEST *st;
00064 
00065   GWEN_NEW_OBJECT(GWEN_IPC_REQUEST, st)
00066   st->_usage=1;
00067   GWEN_INHERIT_INIT(GWEN_IPC_REQUEST, st)
00068   GWEN_LIST_INIT(GWEN_IPC_REQUEST, st)
00069   st->subRequests=GWEN_IpcRequest_List_new();
00070   return st;
00071 }
00072 
00073 
00074 void GWEN_IpcRequest_free(GWEN_IPC_REQUEST *st) {
00075   if (st) {
00076     assert(st->_usage);
00077     if (--(st->_usage)==0) {
00078   GWEN_INHERIT_FINI(GWEN_IPC_REQUEST, st)
00079   GWEN_LIST_FINI(GWEN_IPC_REQUEST, st)
00080   GWEN_FREE_OBJECT(st);
00081     }
00082   }
00083 
00084 }
00085 
00086 
00087 GWEN_IPC_REQUEST *GWEN_IpcRequest_dup(const GWEN_IPC_REQUEST *d) {
00088   GWEN_IPC_REQUEST *st;
00089 
00090   assert(d);
00091   st=GWEN_IpcRequest_new();
00092   st->id=d->id;
00093   if (d->name)
00094     st->name=strdup(d->name);
00095   st->ipcId=d->ipcId;
00096   if (d->expires)
00097     st->expires=GWEN_Time_dup(d->expires);
00098   if (d->subRequests)
00099     st->subRequests=GWEN_IpcRequest_List_dup(d->subRequests);
00100   st->status=d->status;
00101   return st;
00102 }
00103 
00104 
00105 int GWEN_IpcRequest_toDb(const GWEN_IPC_REQUEST *st, GWEN_DB_NODE *db) {
00106   assert(st);
00107   assert(db);
00108   if (GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "id", st->id))
00109     return -1;
00110   if (st->name)
00111     if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "name", st->name))
00112       return -1;
00113   if (GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "ipcId", st->ipcId))
00114     return -1;
00115   if (st->expires)
00116     if (GWEN_Time_toDb(st->expires, GWEN_DB_GetGroup(db, GWEN_DB_FLAGS_DEFAULT, "expires")))
00117       return -1;
00118   if (st->subRequests)
00119   if (1) {
00120     GWEN_DB_NODE *dbT;
00121     GWEN_IPC_REQUEST *e;
00122 
00123     dbT=GWEN_DB_GetGroup(db, GWEN_PATH_FLAGS_CREATE_GROUP, "subRequests");
00124     assert(dbT);
00125     e=GWEN_IpcRequest_List_First(st->subRequests);
00126     while(e) {
00127       if (GWEN_IpcRequest_toDb(e, GWEN_DB_GetGroup(dbT, GWEN_PATH_FLAGS_CREATE_GROUP, "element")))
00128         return -1;
00129       e=GWEN_IpcRequest_List_Next(e);
00130     } /* while */
00131   } /* if (1) */
00132   if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "status", GWEN_IpcRequest_Status_toString(st->status))) 
00133     return -1;
00134   return 0;
00135 }
00136 
00137 
00138 GWEN_IPC_REQUEST *GWEN_IpcRequest_fromDb(GWEN_DB_NODE *db) {
00139 GWEN_IPC_REQUEST *st;
00140 
00141   assert(db);
00142   st=GWEN_IpcRequest_new();
00143   GWEN_IpcRequest_SetId(st, GWEN_DB_GetIntValue(db, "id", 0, 0));
00144   GWEN_IpcRequest_SetName(st, GWEN_DB_GetCharValue(db, "name", 0, 0));
00145   GWEN_IpcRequest_SetIpcId(st, GWEN_DB_GetIntValue(db, "ipcId", 0, 0));
00146   if (1) {
00147     GWEN_DB_NODE *dbT;
00148 
00149     dbT=GWEN_DB_GetGroup(db, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "expires");
00150     if (dbT) st->expires=GWEN_Time_fromDb(dbT);
00151   }
00152   st->subRequests=GWEN_IpcRequest_List_new();
00153   if (1) {
00154     GWEN_DB_NODE *dbT;
00155     GWEN_IPC_REQUEST *e;
00156 
00157     dbT=GWEN_DB_GetGroup(db, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "subRequests");
00158     if (dbT) {
00159       GWEN_DB_NODE *dbT2;
00160 
00161       dbT2=GWEN_DB_FindFirstGroup(dbT, "element");
00162       while(dbT2) {
00163         e=GWEN_IpcRequest_fromDb(dbT2);
00164         if (!e) {
00165           DBG_ERROR(0, "Bad element for type \"GWEN_IPC_REQUEST\"");
00166           if (GWEN_Logger_GetLevel(0)>=GWEN_LoggerLevel_Debug)
00167             GWEN_DB_Dump(dbT2, stderr, 2);
00168           GWEN_IpcRequest_free(st);
00169           return 0;
00170         }
00171         GWEN_IpcRequest_List_Add(e, st->subRequests);    dbT2=GWEN_DB_FindNextGroup(dbT2, "element");
00172       } /* while */
00173     } /* if (dbT) */
00174   } /* if (1) */
00175   GWEN_IpcRequest_SetStatus(st, GWEN_IpcRequest_Status_fromString(GWEN_DB_GetCharValue(db, "status", 0, 0)));
00176   st->_modified=0;
00177   return st;
00178 }
00179 
00180 
00181 uint32_t GWEN_IpcRequest_GetId(const GWEN_IPC_REQUEST *st) {
00182   assert(st);
00183   return st->id;
00184 }
00185 
00186 
00187 void GWEN_IpcRequest_SetId(GWEN_IPC_REQUEST *st, uint32_t d) {
00188   assert(st);
00189   st->id=d;
00190   st->_modified=1;
00191 }
00192 
00193 
00194 
00195 
00196 const char *GWEN_IpcRequest_GetName(const GWEN_IPC_REQUEST *st) {
00197   assert(st);
00198   return st->name;
00199 }
00200 
00201 
00202 void GWEN_IpcRequest_SetName(GWEN_IPC_REQUEST *st, const char *d) {
00203   assert(st);
00204   if (d)
00205     st->name=strdup(d);
00206   else
00207     st->name=0;
00208   st->_modified=1;
00209 }
00210 
00211 
00212 
00213 
00214 uint32_t GWEN_IpcRequest_GetIpcId(const GWEN_IPC_REQUEST *st) {
00215   assert(st);
00216   return st->ipcId;
00217 }
00218 
00219 
00220 void GWEN_IpcRequest_SetIpcId(GWEN_IPC_REQUEST *st, uint32_t d) {
00221   assert(st);
00222   st->ipcId=d;
00223   st->_modified=1;
00224 }
00225 
00226 
00227 
00228 
00229 const GWEN_TIME *GWEN_IpcRequest_GetExpires(const GWEN_IPC_REQUEST *st) {
00230   assert(st);
00231   return st->expires;
00232 }
00233 
00234 
00235 void GWEN_IpcRequest_SetExpires(GWEN_IPC_REQUEST *st, const GWEN_TIME *d) {
00236   assert(st);
00237   if (d)
00238     st->expires=GWEN_Time_dup(d);
00239   else
00240     st->expires=0;
00241   st->_modified=1;
00242 }
00243 
00244 
00245 
00246 
00247 GWEN_IPC_REQUEST_LIST *GWEN_IpcRequest_GetSubRequests(const GWEN_IPC_REQUEST *st) {
00248   assert(st);
00249   return st->subRequests;
00250 }
00251 
00252 
00253 void GWEN_IpcRequest_SetSubRequests(GWEN_IPC_REQUEST *st, GWEN_IPC_REQUEST_LIST *d) {
00254   assert(st);
00255   if (d) {
00256     GWEN_IPC_REQUEST *e;
00257 
00258   st->subRequests=GWEN_IpcRequest_List_new();
00259     e=GWEN_IpcRequest_List_First(d);
00260     while(e) {
00261       GWEN_IPC_REQUEST *ne;
00262 
00263       ne=GWEN_IpcRequest_dup(e);
00264       assert(ne);
00265       GWEN_IpcRequest_List_Add(ne, st->subRequests);
00266       e=GWEN_IpcRequest_List_Next(e);
00267     } /* while (e) */
00268   } /* if LIST */
00269   else
00270     st->subRequests=0;
00271   st->_modified=1;
00272 }
00273 
00274 
00275 
00276 
00277 GWEN_IPC_REQUEST_STATUS GWEN_IpcRequest_GetStatus(const GWEN_IPC_REQUEST *st) {
00278   assert(st);
00279   return st->status;
00280 }
00281 
00282 
00283 void GWEN_IpcRequest_SetStatus(GWEN_IPC_REQUEST *st, GWEN_IPC_REQUEST_STATUS d) {
00284   assert(st);
00285   st->status=d;
00286   st->_modified=1;
00287 }
00288 
00289 
00290 GWEN_IPC_REQUEST_WORK_FN GWEN_IpcRequest_GetWorkFn(const GWEN_IPC_REQUEST *st) {
00291   assert(st);
00292   return st->workFn;
00293 }
00294 
00295 
00296 void GWEN_IpcRequest_SetWorkFn(GWEN_IPC_REQUEST *st, GWEN_IPC_REQUEST_WORK_FN d) {
00297   assert(st);
00298   st->workFn=d;
00299 }
00300 
00301 
00302 int GWEN_IpcRequest_WorkFn(GWEN_IPC_REQUEST *st) {
00303   assert(st);
00304   if (st->workFn)
00305     return st->workFn(st);
00306 return 1;
00307 }
00308 
00309 
00310 
00311 
00312 int GWEN_IpcRequest_IsModified(const GWEN_IPC_REQUEST *st) {
00313   assert(st);
00314   return st->_modified;
00315 }
00316 
00317 
00318 void GWEN_IpcRequest_SetModified(GWEN_IPC_REQUEST *st, int i) {
00319   assert(st);
00320   st->_modified=i;
00321 }
00322 
00323 
00324 void GWEN_IpcRequest_Attach(GWEN_IPC_REQUEST *st) {
00325   assert(st);
00326   st->_usage++;
00327 }
00328 GWEN_IPC_REQUEST *GWEN_IpcRequest_List2__freeAll_cb(GWEN_IPC_REQUEST *st, void *user_data) {
00329   GWEN_IpcRequest_free(st);
00330 return 0;
00331 }
00332 
00333 
00334 void GWEN_IpcRequest_List2_freeAll(GWEN_IPC_REQUEST_LIST2 *stl) {
00335   if (stl) {
00336     GWEN_IpcRequest_List2_ForEach(stl, GWEN_IpcRequest_List2__freeAll_cb, 0);
00337     GWEN_IpcRequest_List2_free(stl); 
00338   }
00339 }
00340 
00341 
00342 
00343 
00344 GWEN_IPC_REQUEST_LIST *GWEN_IpcRequest_List_dup(const GWEN_IPC_REQUEST_LIST *stl) {
00345   if (stl) {
00346     GWEN_IPC_REQUEST_LIST *nl;
00347     GWEN_IPC_REQUEST *e;
00348 
00349     nl=GWEN_IpcRequest_List_new();
00350     e=GWEN_IpcRequest_List_First(stl);
00351     while(e) {
00352       GWEN_IPC_REQUEST *ne;
00353 
00354       ne=GWEN_IpcRequest_dup(e);
00355       assert(ne);
00356       GWEN_IpcRequest_List_Add(ne, nl);
00357       e=GWEN_IpcRequest_List_Next(e);
00358     } /* while (e) */
00359     return nl;
00360   }
00361   else
00362     return 0;
00363 }
00364 
00365 
00366 

Generated on Wed Sep 3 15:21:59 2008 for gwenhywfar by  doxygen 1.5.6