/*
 * 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.
 */


#ifndef _GLOBUS_SERVICE_ENGINE_H_
#define _GLOBUS_SERVICE_ENGINE_H_

#include "globus_common.h"

EXTERN_C_BEGIN

#include "globus_soap_message.h"

extern globus_module_descriptor_t globus_l_service_engine_module;
#define GLOBUS_SERVICE_ENGINE_MODULE &globus_l_service_engine_module

#define GLOBUS_SERVICE_ENGINE_MODULE_PATH_PREFIX "globus_service_modules"

typedef enum
{
    GLOBUS_SERVICE_ENGINE_ERROR_TYPE_INIT_FAILED,
    GLOBUS_SERVICE_ENGINE_ERROR_TYPE_INVALID_CONTACT,
    GLOBUS_SERVICE_ENGINE_ERROR_TYPE_UNSUPPORTED_MEDIA_TYPE,
    GLOBUS_SERVICE_ENGINE_ERROR_TYPE_INVALID_URI,
    GLOBUS_SERVICE_ENGINE_ERROR_TYPE_SERVICE_LOAD_FAILED,
    GLOBUS_SERVICE_ENGINE_ERROR_TYPE_READ_REQUEST_FAILED,
    GLOBUS_SERVICE_ENGINE_ERROR_TYPE_FAILED_REQUEST,
    GLOBUS_SERVICE_ENGINE_ERROR_TYPE_ACCEPT_FAILED,
    GLOBUS_SERVICE_ENGINE_ERROR_TYPE_TRANSPORT_FAILED,
    GLOBUS_SERVICE_ENGINE_ERROR_TYPE_FAILED_RESPONSE,
    GLOBUS_SERVICE_ENGINE_ERROR_TYPE_SENDING_FAULT,
    GLOBUS_SERVICE_ENGINE_ERROR_TYPE_ALREADY_STARTED,
    GLOBUS_SERVICE_ENGINE_ERROR_TYPE_STOP_FAILED,
    GLOBUS_SERVICE_ENGINE_ERROR_TYPE_METHOD_NOT_ALLOWED,
    GLOBUS_SERVICE_ENGINE_ERROR_TYPE_OPERATION_LOOKUP_FAILED,
    GLOBUS_SERVICE_ENGINE_ERROR_TYPE_OP_INVOKE_FAILED,
    GLOBUS_SERVICE_ENGINE_ERROR_TYPE_OP_DESERIALIZE_FAILED,
    GLOBUS_SERVICE_ENGINE_ERROR_TYPE_SESSION_FAILED,
    GLOBUS_SERVICE_ENGINE_ERROR_TYPE_FAILED_REQUEST_PROCESS,
    GLOBUS_SERVICE_ENGINE_ERROR_TYPE_FAILED_START,
    GLOBUS_SERVICE_ENGINE_ERROR_TYPE_HANDLER_LOAD_FAILED,
    GLOBUS_SERVICE_ENGINE_ERROR_TYPE_SESSION_START_FAILED,
    GLOBUS_SERVICE_ENGINE_ERROR_TYPE_OUT_OF_MEMORY
} globus_service_engine_error_t;

typedef struct globus_l_service_engine_s *   globus_service_engine_t;

typedef void (* globus_service_session_callback_func_t) (
    globus_result_t                     result,
    globus_service_engine_t             engine,              
    globus_soap_message_handle_t        session,
    void *                              user_args);

typedef void (* globus_service_engine_callback_func_t) (
    globus_result_t                     result,
    globus_service_engine_t             engine,
    void *                              args);

globus_result_t
globus_service_engine_init(
    globus_service_engine_t *           engine, 
    globus_soap_message_attr_t          attrs,
    const char *                        port_contact,
    globus_handler_chain_t              chain,
    globus_bool_t                       enable_https);

globus_result_t
globus_service_engine_get_contact(
    globus_service_engine_t             engine,
    char **                             contact);

void
globus_service_engine_destroy(
    globus_service_engine_t             engine);

globus_result_t
globus_service_engine_set_handlers(
    globus_service_engine_t             engine,
    globus_handler_chain_t              chain);

globus_result_t
globus_service_engine_register_session(
    globus_service_engine_t                  engine,
    globus_service_session_callback_func_t   callback,
    void *                                   user_args);

globus_result_t
globus_service_engine_register_process(
    globus_service_engine_t                engine,
    globus_soap_message_handle_t           message,
    globus_result_t                        fault_result,
    globus_service_session_callback_func_t callback,
    void *                                 user_args);

globus_result_t
globus_service_session_begin_response(
    globus_soap_message_handle_t        message);

globus_result_t
globus_service_session_end_response(
    globus_soap_message_handle_t        message);

#include "globus_soap_message_fault.h"

globus_result_t
globus_service_session_serialize_fault_response(
    globus_soap_message_handle_t        message,
    globus_soap_message_fault_t         fault);

globus_result_t
globus_service_engine_register_start(
    globus_service_engine_t               engine,
    globus_service_engine_callback_func_t stop_callback,
    void *                                args);

globus_result_t
globus_service_engine_register_stop(
    globus_service_engine_t               engine);

EXTERN_C_END

#endif
