/**********************************************************
 * This file has been automatically created by "typemaker2"
 * from the file "providerqueue.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 "./providerqueue_p.h"

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

/* code headers */

/* macro functions */
GWEN_LIST_FUNCTIONS(AB_PROVIDERQUEUE, AB_ProviderQueue)
GWEN_INHERIT_FUNCTIONS(AB_PROVIDERQUEUE)


AB_PROVIDERQUEUE *AB_ProviderQueue_new(void) {
  AB_PROVIDERQUEUE *p_struct;

  GWEN_NEW_OBJECT(AB_PROVIDERQUEUE, p_struct)
  p_struct->_refCount=1;
  GWEN_INHERIT_INIT(AB_PROVIDERQUEUE, p_struct)
  GWEN_LIST_INIT(AB_PROVIDERQUEUE, p_struct)
  /* members */
  p_struct->providerName=NULL;
  p_struct->provider=NULL;
  p_struct->accountQueueList=AB_AccountQueue_List_new();
  /* virtual functions */

  return p_struct;
}

void AB_ProviderQueue_free(AB_PROVIDERQUEUE *p_struct) {
  if (p_struct) {
  assert(p_struct->_refCount);
  if (p_struct->_refCount==1) {
    GWEN_INHERIT_FINI(AB_PROVIDERQUEUE, p_struct)
    GWEN_LIST_FINI(AB_PROVIDERQUEUE, p_struct)
  /* members */
    free(p_struct->providerName); p_struct->providerName=NULL;
    AB_AccountQueue_List_free(p_struct->accountQueueList); p_struct->accountQueueList=NULL;
    p_struct->_refCount=0;
    GWEN_FREE_OBJECT(p_struct);
  }
  else
    p_struct->_refCount--;
  }
}

void AB_ProviderQueue_Attach(AB_PROVIDERQUEUE *p_struct) {
  assert(p_struct);
  assert(p_struct->_refCount);
  p_struct->_refCount++;
}

AB_PROVIDERQUEUE *AB_ProviderQueue_dup(const AB_PROVIDERQUEUE *p_src) {
  AB_PROVIDERQUEUE *p_struct;

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

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

  /* member "accountQueueList" */
  if (p_struct->accountQueueList) {
    AB_AccountQueue_List_free(p_struct->accountQueueList); p_struct->accountQueueList=NULL;
    p_struct->accountQueueList=NULL;
  }
  if (p_src->accountQueueList) {
    p_struct->accountQueueList=AB_AccountQueue_List_dup(p_src->accountQueueList);
  }

  return p_struct;
}

const char *AB_ProviderQueue_GetProviderName(const AB_PROVIDERQUEUE *p_struct) {
  assert(p_struct);
  return p_struct->providerName;
}

AB_PROVIDER *AB_ProviderQueue_GetProvider(const AB_PROVIDERQUEUE *p_struct) {
  assert(p_struct);
  return p_struct->provider;
}

AB_ACCOUNTQUEUE_LIST *AB_ProviderQueue_GetAccountQueueList(const AB_PROVIDERQUEUE *p_struct) {
  assert(p_struct);
  return p_struct->accountQueueList;
}

void AB_ProviderQueue_SetProviderName(AB_PROVIDERQUEUE *p_struct, const char *p_src) {
  assert(p_struct);
  if (p_struct->providerName) {
    free(p_struct->providerName); p_struct->providerName=NULL;
  }
  if (p_src) {
    p_struct->providerName=strdup(p_src);
  }
  else {
    p_struct->providerName=NULL;
  }
}

void AB_ProviderQueue_SetProvider(AB_PROVIDERQUEUE *p_struct, AB_PROVIDER *p_src) {
  assert(p_struct);
  p_struct->provider=p_src;
}

void AB_ProviderQueue_SetAccountQueueList(AB_PROVIDERQUEUE *p_struct, AB_ACCOUNTQUEUE_LIST *p_src) {
  assert(p_struct);
  if (p_struct->accountQueueList) {
    AB_AccountQueue_List_free(p_struct->accountQueueList); p_struct->accountQueueList=NULL;
  }
  p_struct->accountQueueList=p_src;
}

/* list1 functions */
AB_PROVIDERQUEUE_LIST *AB_ProviderQueue_List_dup(const AB_PROVIDERQUEUE_LIST *p_src) {
  AB_PROVIDERQUEUE_LIST *p_dest;
  AB_PROVIDERQUEUE *p_elem;

  assert(p_src);
  p_dest=AB_ProviderQueue_List_new();
  p_elem=AB_ProviderQueue_List_First(p_src);
  while(p_elem) {
    AB_PROVIDERQUEUE *p_cpy;

    p_cpy=AB_ProviderQueue_dup(p_elem);
    AB_ProviderQueue_List_Add(p_cpy, p_dest);
    p_elem=AB_ProviderQueue_List_Next(p_elem);
  }

  return p_dest;
}

AB_PROVIDERQUEUE *AB_ProviderQueue_List_GetByProviderName(const AB_PROVIDERQUEUE_LIST *p_list,  const char *p_cmp) {
  AB_PROVIDERQUEUE *p_struct;

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

    if (p_struct->providerName && p_cmp) p_rv=strcasecmp(p_cmp, p_struct->providerName); else if (p_cmp) p_rv=1; else if (p_struct->providerName) p_rv=-1; else p_rv=0;
    if (p_rv == 0)
      return p_struct;
    p_struct = AB_ProviderQueue_List_Next(p_struct);
  }
  return NULL;
}

AB_ACCOUNTQUEUE *AB_ProviderQueue_FindAccountQueueById(const AB_PROVIDERQUEUE *pq, uint32_t uid) { if (pq->accountQueueList==NULL) return NULL; return AB_AccountQueue_List_GetByAccountId(pq->accountQueueList, uid); }
void AB_ProviderQueue_AddAccountQueue(AB_PROVIDERQUEUE *pq, AB_ACCOUNTQUEUE *aq) { if (pq->accountQueueList==NULL) pq->accountQueueList=AB_AccountQueue_List_new(); AB_AccountQueue_List_Add(aq, pq->accountQueueList); }
AB_ACCOUNTQUEUE *AB_ProviderQueue_GetFirstAccountQueue(const AB_PROVIDERQUEUE *pq) { if (pq->accountQueueList==NULL) return NULL; return AB_AccountQueue_List_First(pq->accountQueueList); }

/* code headers */

