/**********************************************************
 * This file has been automatically created by "typemaker2"
 * from the file "oh_institute_data.xml".
 * Please do not edit this file, all changes will be lost.
 * Better edit the mentioned source file instead.
 **********************************************************/

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include "oh_institute_data_p.h"

#include <gwenhywfar/misc.h>
#include <gwenhywfar/debug.h>

/* code headers */

/* macro functions */
GWEN_LIST_FUNCTIONS(OH_INSTITUTE_DATA, OH_InstituteData)
GWEN_LIST2_FUNCTIONS(OH_INSTITUTE_DATA, OH_InstituteData)


OH_INSTITUTE_DATA *OH_InstituteData_new(void) {
  OH_INSTITUTE_DATA *p_struct;

  GWEN_NEW_OBJECT(OH_INSTITUTE_DATA, p_struct)
  p_struct->_refCount=1;
  GWEN_LIST_INIT(OH_INSTITUTE_DATA, p_struct)
  /* members */
  p_struct->id=0;
  p_struct->flags=0;
  p_struct->name=NULL;
  p_struct->fid=NULL;
  p_struct->org=NULL;
  p_struct->brokerId=NULL;
  p_struct->url=NULL;
  p_struct->lastOfxValidationTime=NULL;
  p_struct->lastSslValidationTime=NULL;
  p_struct->fileName=NULL;
  /* virtual functions */

  return p_struct;
}

void OH_InstituteData_free(OH_INSTITUTE_DATA *p_struct) {
  if (p_struct) {
  assert(p_struct->_refCount);
  if (p_struct->_refCount==1) {
    GWEN_LIST_FINI(OH_INSTITUTE_DATA, p_struct)
  /* members */
    free(p_struct->name);
    free(p_struct->fid);
    free(p_struct->org);
    free(p_struct->brokerId);
    free(p_struct->url);
    GWEN_Time_free(p_struct->lastOfxValidationTime);
    GWEN_Time_free(p_struct->lastSslValidationTime);
    free(p_struct->fileName);
    p_struct->_refCount=0;
    GWEN_FREE_OBJECT(p_struct);
  }
  else
    p_struct->_refCount--;
  }
}

void OH_InstituteData_Attach(OH_INSTITUTE_DATA *p_struct) {
  assert(p_struct);
  assert(p_struct->_refCount);
  p_struct->_refCount++;
}

OH_INSTITUTE_DATA *OH_InstituteData_dup(const OH_INSTITUTE_DATA *p_src) {
  OH_INSTITUTE_DATA *p_struct;

  assert(p_src);
  p_struct=OH_InstituteData_new();
  /* member "id" */
  p_struct->id=p_src->id;

  /* member "flags" */
  p_struct->flags=p_src->flags;

  /* member "name" */
  if (p_struct->name) {
    free(p_struct->name);
    p_struct->name=NULL;
  }
  if (p_src->name) {
    p_struct->name=strdup(p_src->name);
  }

  /* member "fid" */
  if (p_struct->fid) {
    free(p_struct->fid);
    p_struct->fid=NULL;
  }
  if (p_src->fid) {
    p_struct->fid=strdup(p_src->fid);
  }

  /* member "org" */
  if (p_struct->org) {
    free(p_struct->org);
    p_struct->org=NULL;
  }
  if (p_src->org) {
    p_struct->org=strdup(p_src->org);
  }

  /* member "brokerId" */
  if (p_struct->brokerId) {
    free(p_struct->brokerId);
    p_struct->brokerId=NULL;
  }
  if (p_src->brokerId) {
    p_struct->brokerId=strdup(p_src->brokerId);
  }

  /* member "url" */
  if (p_struct->url) {
    free(p_struct->url);
    p_struct->url=NULL;
  }
  if (p_src->url) {
    p_struct->url=strdup(p_src->url);
  }

  /* member "lastOfxValidationTime" */
  if (p_struct->lastOfxValidationTime) {
    GWEN_Time_free(p_struct->lastOfxValidationTime);
    p_struct->lastOfxValidationTime=NULL;
  }
  if (p_src->lastOfxValidationTime) {
    p_struct->lastOfxValidationTime=GWEN_Time_dup(p_src->lastOfxValidationTime);
  }

  /* member "lastSslValidationTime" */
  if (p_struct->lastSslValidationTime) {
    GWEN_Time_free(p_struct->lastSslValidationTime);
    p_struct->lastSslValidationTime=NULL;
  }
  if (p_src->lastSslValidationTime) {
    p_struct->lastSslValidationTime=GWEN_Time_dup(p_src->lastSslValidationTime);
  }

  /* member "fileName" */
  if (p_struct->fileName) {
    free(p_struct->fileName);
    p_struct->fileName=NULL;
  }
  if (p_src->fileName) {
    p_struct->fileName=strdup(p_src->fileName);
  }

  return p_struct;
}

OH_INSTITUTE_DATA *OH_InstituteData_copy(OH_INSTITUTE_DATA *p_struct, const OH_INSTITUTE_DATA *p_src) {
    assert(p_struct);
  assert(p_src);
  /* member "id" */
  p_struct->id=p_src->id;

  /* member "flags" */
  p_struct->flags=p_src->flags;

  /* member "name" */
  if (p_struct->name) {
    free(p_struct->name);
    p_struct->name=NULL;
  }
  if (p_src->name) {
    p_struct->name=strdup(p_src->name);
  }

  /* member "fid" */
  if (p_struct->fid) {
    free(p_struct->fid);
    p_struct->fid=NULL;
  }
  if (p_src->fid) {
    p_struct->fid=strdup(p_src->fid);
  }

  /* member "org" */
  if (p_struct->org) {
    free(p_struct->org);
    p_struct->org=NULL;
  }
  if (p_src->org) {
    p_struct->org=strdup(p_src->org);
  }

  /* member "brokerId" */
  if (p_struct->brokerId) {
    free(p_struct->brokerId);
    p_struct->brokerId=NULL;
  }
  if (p_src->brokerId) {
    p_struct->brokerId=strdup(p_src->brokerId);
  }

  /* member "url" */
  if (p_struct->url) {
    free(p_struct->url);
    p_struct->url=NULL;
  }
  if (p_src->url) {
    p_struct->url=strdup(p_src->url);
  }

  /* member "lastOfxValidationTime" */
  if (p_struct->lastOfxValidationTime) {
    GWEN_Time_free(p_struct->lastOfxValidationTime);
    p_struct->lastOfxValidationTime=NULL;
  }
  if (p_src->lastOfxValidationTime) {
    p_struct->lastOfxValidationTime=GWEN_Time_dup(p_src->lastOfxValidationTime);
  }

  /* member "lastSslValidationTime" */
  if (p_struct->lastSslValidationTime) {
    GWEN_Time_free(p_struct->lastSslValidationTime);
    p_struct->lastSslValidationTime=NULL;
  }
  if (p_src->lastSslValidationTime) {
    p_struct->lastSslValidationTime=GWEN_Time_dup(p_src->lastSslValidationTime);
  }

  /* member "fileName" */
  if (p_struct->fileName) {
    free(p_struct->fileName);
    p_struct->fileName=NULL;
  }
  if (p_src->fileName) {
    p_struct->fileName=strdup(p_src->fileName);
  }

  return p_struct;
}

int OH_InstituteData_GetId(const OH_INSTITUTE_DATA *p_struct) {
  assert(p_struct);
  return p_struct->id;
}

uint32_t OH_InstituteData_GetFlags(const OH_INSTITUTE_DATA *p_struct) {
  assert(p_struct);
  return p_struct->flags;
}

const char *OH_InstituteData_GetName(const OH_INSTITUTE_DATA *p_struct) {
  assert(p_struct);
  return p_struct->name;
}

const char *OH_InstituteData_GetFid(const OH_INSTITUTE_DATA *p_struct) {
  assert(p_struct);
  return p_struct->fid;
}

const char *OH_InstituteData_GetOrg(const OH_INSTITUTE_DATA *p_struct) {
  assert(p_struct);
  return p_struct->org;
}

const char *OH_InstituteData_GetBrokerId(const OH_INSTITUTE_DATA *p_struct) {
  assert(p_struct);
  return p_struct->brokerId;
}

const char *OH_InstituteData_GetUrl(const OH_INSTITUTE_DATA *p_struct) {
  assert(p_struct);
  return p_struct->url;
}

const GWEN_TIME *OH_InstituteData_GetLastOfxValidationTime(const OH_INSTITUTE_DATA *p_struct) {
  assert(p_struct);
  return p_struct->lastOfxValidationTime;
}

const GWEN_TIME *OH_InstituteData_GetLastSslValidationTime(const OH_INSTITUTE_DATA *p_struct) {
  assert(p_struct);
  return p_struct->lastSslValidationTime;
}

const char *OH_InstituteData_GetFileName(const OH_INSTITUTE_DATA *p_struct) {
  assert(p_struct);
  return p_struct->fileName;
}

void OH_InstituteData_SetId(OH_INSTITUTE_DATA *p_struct, int p_src) {
  assert(p_struct);
  p_struct->id=p_src;
}

void OH_InstituteData_SetFlags(OH_INSTITUTE_DATA *p_struct, uint32_t p_src) {
  assert(p_struct);
  p_struct->flags=p_src;
}

void OH_InstituteData_AddFlags(OH_INSTITUTE_DATA *p_struct, uint32_t p_src) {
  assert(p_struct);
  p_struct->flags|=p_src;
}

void OH_InstituteData_SubFlags(OH_INSTITUTE_DATA *p_struct, uint32_t p_src) {
  assert(p_struct);
  p_struct->flags&=~p_src;
}

void OH_InstituteData_SetName(OH_INSTITUTE_DATA *p_struct, const char *p_src) {
  assert(p_struct);
  if (p_struct->name) {
    free(p_struct->name);
  }
  if (p_src) {
    p_struct->name=strdup(p_src);
  }
  else {
    p_struct->name=NULL;
  }
}

void OH_InstituteData_SetFid(OH_INSTITUTE_DATA *p_struct, const char *p_src) {
  assert(p_struct);
  if (p_struct->fid) {
    free(p_struct->fid);
  }
  if (p_src) {
    p_struct->fid=strdup(p_src);
  }
  else {
    p_struct->fid=NULL;
  }
}

void OH_InstituteData_SetOrg(OH_INSTITUTE_DATA *p_struct, const char *p_src) {
  assert(p_struct);
  if (p_struct->org) {
    free(p_struct->org);
  }
  if (p_src) {
    p_struct->org=strdup(p_src);
  }
  else {
    p_struct->org=NULL;
  }
}

void OH_InstituteData_SetBrokerId(OH_INSTITUTE_DATA *p_struct, const char *p_src) {
  assert(p_struct);
  if (p_struct->brokerId) {
    free(p_struct->brokerId);
  }
  if (p_src) {
    p_struct->brokerId=strdup(p_src);
  }
  else {
    p_struct->brokerId=NULL;
  }
}

void OH_InstituteData_SetUrl(OH_INSTITUTE_DATA *p_struct, const char *p_src) {
  assert(p_struct);
  if (p_struct->url) {
    free(p_struct->url);
  }
  if (p_src) {
    p_struct->url=strdup(p_src);
  }
  else {
    p_struct->url=NULL;
  }
}

void OH_InstituteData_SetLastOfxValidationTime(OH_INSTITUTE_DATA *p_struct, const GWEN_TIME *p_src) {
  assert(p_struct);
  if (p_struct->lastOfxValidationTime) {
    GWEN_Time_free(p_struct->lastOfxValidationTime);
  }
  if (p_src) {
    p_struct->lastOfxValidationTime=GWEN_Time_dup(p_src);
  }
  else {
    p_struct->lastOfxValidationTime=NULL;
  }
}

void OH_InstituteData_SetLastSslValidationTime(OH_INSTITUTE_DATA *p_struct, const GWEN_TIME *p_src) {
  assert(p_struct);
  if (p_struct->lastSslValidationTime) {
    GWEN_Time_free(p_struct->lastSslValidationTime);
  }
  if (p_src) {
    p_struct->lastSslValidationTime=GWEN_Time_dup(p_src);
  }
  else {
    p_struct->lastSslValidationTime=NULL;
  }
}

void OH_InstituteData_SetFileName(OH_INSTITUTE_DATA *p_struct, const char *p_src) {
  assert(p_struct);
  if (p_struct->fileName) {
    free(p_struct->fileName);
  }
  if (p_src) {
    p_struct->fileName=strdup(p_src);
  }
  else {
    p_struct->fileName=NULL;
  }
}

/* list1 functions */
OH_INSTITUTE_DATA_LIST *OH_InstituteData_List_dup(const OH_INSTITUTE_DATA_LIST *p_src) {
  OH_INSTITUTE_DATA_LIST *p_dest;
  OH_INSTITUTE_DATA *p_elem;

  assert(p_src);
  p_dest=OH_InstituteData_List_new();
  p_elem=OH_InstituteData_List_First(p_src);
  while(p_elem) {
    OH_INSTITUTE_DATA *p_cpy;

    p_cpy=OH_InstituteData_dup(p_elem);
    OH_InstituteData_List_Add(p_cpy, p_dest);
    p_elem=OH_InstituteData_List_Next(p_elem);
  }

  return p_dest;
}

void OH_InstituteData_ReadDb(OH_INSTITUTE_DATA *p_struct, GWEN_DB_NODE *p_db) {
  assert(p_struct);
  /* member "id" */
  p_struct->id=GWEN_DB_GetIntValue(p_db, "id", 0, 0);

  /* member "flags" */
  p_struct->flags=GWEN_DB_GetIntValue(p_db, "flags", 0, 0);

  /* member "name" */
  if (p_struct->name) {
    free(p_struct->name);
  }
  { const char *s; s=GWEN_DB_GetCharValue(p_db, "name", 0, NULL); if (s) p_struct->name=strdup(s); }
  if (p_struct->name==NULL) {  p_struct->name=NULL;
  }

  /* member "fid" */
  if (p_struct->fid) {
    free(p_struct->fid);
  }
  { const char *s; s=GWEN_DB_GetCharValue(p_db, "fid", 0, NULL); if (s) p_struct->fid=strdup(s); }
  if (p_struct->fid==NULL) {  p_struct->fid=NULL;
  }

  /* member "org" */
  if (p_struct->org) {
    free(p_struct->org);
  }
  { const char *s; s=GWEN_DB_GetCharValue(p_db, "org", 0, NULL); if (s) p_struct->org=strdup(s); }
  if (p_struct->org==NULL) {  p_struct->org=NULL;
  }

  /* member "brokerId" */
  if (p_struct->brokerId) {
    free(p_struct->brokerId);
  }
  { const char *s; s=GWEN_DB_GetCharValue(p_db, "brokerId", 0, NULL); if (s) p_struct->brokerId=strdup(s); }
  if (p_struct->brokerId==NULL) {  p_struct->brokerId=NULL;
  }

  /* member "url" */
  if (p_struct->url) {
    free(p_struct->url);
  }
  { const char *s; s=GWEN_DB_GetCharValue(p_db, "url", 0, NULL); if (s) p_struct->url=strdup(s); }
  if (p_struct->url==NULL) {  p_struct->url=NULL;
  }

  /* member "lastOfxValidationTime" */
  if (p_struct->lastOfxValidationTime) {
    GWEN_Time_free(p_struct->lastOfxValidationTime);
  }
  { GWEN_DB_NODE *dbDest; dbDest=GWEN_DB_GetGroup(p_db, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "lastOfxValidationTime"); if (dbDest) p_struct->lastOfxValidationTime=GWEN_Time_fromDb(dbDest); }
  if (p_struct->lastOfxValidationTime==NULL) {  p_struct->lastOfxValidationTime=NULL;
  }

  /* member "lastSslValidationTime" */
  if (p_struct->lastSslValidationTime) {
    GWEN_Time_free(p_struct->lastSslValidationTime);
  }
  { GWEN_DB_NODE *dbDest; dbDest=GWEN_DB_GetGroup(p_db, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "lastSslValidationTime"); if (dbDest) p_struct->lastSslValidationTime=GWEN_Time_fromDb(dbDest); }
  if (p_struct->lastSslValidationTime==NULL) {  p_struct->lastSslValidationTime=NULL;
  }

  /* member "fileName" */
  if (p_struct->fileName) {
    free(p_struct->fileName);
  }
  /* member "fileName" is volatile, just presetting */
  p_struct->fileName=NULL;

}

int OH_InstituteData_WriteDb(const OH_INSTITUTE_DATA *p_struct, GWEN_DB_NODE *p_db) {
  int p_rv;

  assert(p_struct);
  /* member "id" */
  p_rv=GWEN_DB_SetIntValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "id", p_struct->id);
  if (p_rv<0) {
    DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
    return p_rv;
  }

  /* member "flags" */
  p_rv=GWEN_DB_SetIntValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "flags", p_struct->flags);
  if (p_rv<0) {
    DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
    return p_rv;
  }

  /* member "name" */
  if (p_struct->name) p_rv=GWEN_DB_SetCharValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "name", p_struct->name); else { GWEN_DB_DeleteVar(p_db, "name"); p_rv=0; }
  if (p_rv<0) {
    DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
    return p_rv;
  }

  /* member "fid" */
  if (p_struct->fid) p_rv=GWEN_DB_SetCharValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "fid", p_struct->fid); else { GWEN_DB_DeleteVar(p_db, "fid"); p_rv=0; }
  if (p_rv<0) {
    DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
    return p_rv;
  }

  /* member "org" */
  if (p_struct->org) p_rv=GWEN_DB_SetCharValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "org", p_struct->org); else { GWEN_DB_DeleteVar(p_db, "org"); p_rv=0; }
  if (p_rv<0) {
    DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
    return p_rv;
  }

  /* member "brokerId" */
  if (p_struct->brokerId) p_rv=GWEN_DB_SetCharValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "brokerId", p_struct->brokerId); else { GWEN_DB_DeleteVar(p_db, "brokerId"); p_rv=0; }
  if (p_rv<0) {
    DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
    return p_rv;
  }

  /* member "url" */
  if (p_struct->url) p_rv=GWEN_DB_SetCharValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "url", p_struct->url); else { GWEN_DB_DeleteVar(p_db, "url"); p_rv=0; }
  if (p_rv<0) {
    DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
    return p_rv;
  }

  /* member "lastOfxValidationTime" */
  if (p_struct->lastOfxValidationTime){ GWEN_DB_NODE *dbDest; dbDest=GWEN_DB_GetGroup(p_db, GWEN_DB_FLAGS_OVERWRITE_GROUPS, "lastOfxValidationTime"); assert(dbDest); p_rv=GWEN_Time_toDb(p_struct->lastOfxValidationTime, dbDest); } else p_rv=0;
  if (p_rv<0) {
    DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
    return p_rv;
  }

  /* member "lastSslValidationTime" */
  if (p_struct->lastSslValidationTime){ GWEN_DB_NODE *dbDest; dbDest=GWEN_DB_GetGroup(p_db, GWEN_DB_FLAGS_OVERWRITE_GROUPS, "lastSslValidationTime"); assert(dbDest); p_rv=GWEN_Time_toDb(p_struct->lastSslValidationTime, dbDest); } else p_rv=0;
  if (p_rv<0) {
    DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
    return p_rv;
  }

  /* member "fileName" is volatile, not writing to db */

  return 0;
}

OH_INSTITUTE_DATA *OH_InstituteData_fromDb(GWEN_DB_NODE *p_db) {
  OH_INSTITUTE_DATA *p_struct;
  p_struct=OH_InstituteData_new();
  OH_InstituteData_ReadDb(p_struct, p_db);
  return p_struct;
}

int OH_InstituteData_toDb(const OH_INSTITUTE_DATA *p_struct, GWEN_DB_NODE *p_db) {
  return OH_InstituteData_WriteDb(p_struct, p_db);
}

OH_INSTITUTE_DATA *OH_InstituteData_List_GetById(const OH_INSTITUTE_DATA_LIST *p_list, int p_cmp) {
  OH_INSTITUTE_DATA *p_struct;

  assert(p_list);
  p_struct = OH_InstituteData_List_First(p_list);
  while(p_struct) {
    int p_rv;

    if (p_struct->id==p_cmp) p_rv=0; else if (p_cmp<p_struct->id) p_rv=-1; else p_rv=1;
    if (p_rv == 0)
      return p_struct;
    p_struct = OH_InstituteData_List_Next(p_struct);
  }
  return NULL;
}


/* code headers */
#include "oh_institute_data_fns.c"

