/** Generated by xsd2c */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "CallList.h"


struct CallList* CallList_Create()
{
	struct CallList* _res;
	_res = (struct CallList*)malloc(sizeof(struct CallList));

	_res->operation_head = NULL;
	_res->operation_tail = NULL;

	return _res;
}

void CallList_Free(struct CallList* obj)
{
	struct CallFunc_List* operation_cur;
	struct CallFunc_List* operation_tmp;
	if (obj == NULL) return;

	operation_cur = obj->operation_head;
	while (operation_cur != NULL)
	{
		operation_tmp = operation_cur->next;
		free(operation_cur);
		operation_cur = operation_tmp;
	}
	free(obj);
}

void CallList_Sax_Serialize(struct CallList* obj,
		 const char *root_element_name,
		 void (*OnStartElement)(const char* element_name, int attr_count, char **keys, char **values, void* userData),
		 void (*OnCharacters)(const char* element_name, const char* chars, void* userData),
		 void (*OnEndElement)(const char* element_name, void* userData),
		 void* userData)
{
	int attrCount, curCount;
	char **keys;
	char **values;
	char buffer[255];

	struct CallFunc_List* operation_cur;

	attrCount = 0;

	keys = (char**)malloc(sizeof(char*)*attrCount);
	values = (char**)malloc(sizeof(char*)*attrCount);

	curCount = 0;


	OnStartElement(root_element_name, attrCount, keys, values, userData);
	operation_cur = obj->operation_head;
	while (operation_cur != NULL)
	{
	if (operation_cur->value)
		CallFunc_Sax_Serialize(operation_cur->value, "operation", OnStartElement, OnCharacters, OnEndElement, userData);

		operation_cur = operation_cur->next;
	}

	OnEndElement(root_element_name, userData);
}

#ifndef _DESERIALIZER_DISABLED_

struct CallList* CallList_Deserialize(xmlNodePtr xmlRoot)
{
	xmlNodePtr cur;
	xmlChar *key;
	struct CallList* obj;
	obj = CallList_Create();
	cur = xmlRoot->xmlChildrenNode;
	while (cur != NULL) {
		if (cur->type != XML_ELEMENT_NODE) {
			cur = cur->next;
			continue;
		}
		printf("CallList->%s\n", cur->name);
		if ((!xmlStrcmp(cur->name, (const xmlChar *)"operation"))){
			CallList_Add_operation( obj, CallFunc_Deserialize(cur) );
		}
	// TODO: 
		cur = cur->next;
	}
	return obj;
}

#endif
struct CallFunc_List* CallList_Get_operation(struct CallList* obj)
{
	return obj->operation_head;
}

void CallList_Add_operation(struct CallList* obj, struct CallFunc* operation)
{
	struct CallFunc_List* operation_node;
	operation_node = (struct CallFunc_List*)malloc(sizeof(struct CallFunc_List));
	operation_node->value = operation;
	operation_node->next = NULL;
	if (obj->operation_tail)
	{
		obj->operation_tail->next = operation_node;
	}
	if (obj->operation_head == NULL)
	{
		obj->operation_head = operation_node;
	}
	obj->operation_tail = operation_node;
}

