/*
 * Portions of this file Copyright 1999-2005 University of Chicago
 * Portions of this file Copyright 1999-2005 The University of Southern California.
 *
 * This file or a portion of this file is licensed under the
 * terms of the Globus Toolkit Public License, found at
 * http://www.globus.org/toolkit/download/license.html.
 * If you redistribute this file, with or without
 * modifications, you must include this notice in the file.
 */


/*
 * This file or a portion of this file is licensed under the terms of the
 * Globus Toolkit Public License, found at
 * http://www.globus.org/toolkit/download/license.html.
 * If you redistribute this file, with or without modifications,
 * you must include this notice in the file.
 */

/**
 * @author $Author: bester $
 */

#ifndef _GLOBUS_XSD_TYPE_SERIALIZATION_H_
#define _GLOBUS_XSD_TYPE_SERIALIZATION_H_

#include "globus_common.h"
#include "xsd_QName.h"
#include "globus_xsd_primitives.h"
#include "globus_soap_message_handle.h"

EXTERN_C_BEGIN

#define GlobusXSDTypeExport(FILE, TYPE, INSTANCE, ELEMENT, RESULT)      \
{                                                                       \
    globus_soap_message_handle_t handle;                                \
    RESULT = globus_soap_message_handle_init_to_file(                   \
        &handle,                                                        \
        FILE,                                                           \
        0);                                                             \
    if(RESULT == GLOBUS_SUCCESS)                                        \
    {                                                                   \
        RESULT = TYPE##_serialize(                                      \
            ELEMENT, (TYPE *)INSTANCE, handle, 0);                      \
                                                                        \
        globus_soap_message_handle_destroy(handle);                     \
    }                                                                   \
}

#define GlobusXSDTypeImport(FILE, TYPE, INSTANCE, ELEMENT, RESULT)      \
{                                                                       \
    globus_soap_message_handle_t        handle;                         \
                                                                        \
    RESULT = globus_soap_message_handle_init_from_file(                 \
        &handle,                                                        \
        FILE);                                                          \
    if(RESULT == GLOBUS_SUCCESS)                                        \
    {                                                                   \
        RESULT = TYPE##_deserialize(                                    \
            ELEMENT, INSTANCE, handle, 0);                              \
                                                                        \
        globus_soap_message_handle_destroy(handle);                     \
    }                                                                   \
}

typedef globus_result_t (* globus_xsd_init_func_t) (
    void **                             obj);

typedef globus_result_t (* globus_xsd_init_contents_func_t) (
    void *                              obj);

typedef void (* globus_xsd_destroy_func_t) (
    void *                              obj);

typedef void (* globus_xsd_destroy_contents_func_t) (
    void *                              obj);

typedef globus_result_t (* globus_xsd_copy_func_t) (
    void **                             dest_obj,
    void *                              src_obj);

typedef globus_result_t (* globus_xsd_copy_contents_func_t) (
    void *                              dest_obj,
    void *                              src_obj);

typedef globus_result_t (* globus_xsd_serialize_func_t) (
    xsd_QName *                         element_name,
    void *                              instance,
    globus_soap_message_handle_t        soap_message_handle,
    globus_xsd_element_options_t        options);

typedef globus_result_t (* globus_xsd_deserialize_func_t) (
    xsd_QName *                         element_name,
    void **                             instance,
    globus_soap_message_handle_t        soap_message_handle,
    globus_xsd_element_options_t        options);

typedef void * (* globus_xsd_array_push_func_t) (
    void *                              array);

EXTERN_C_END

#endif
