#ifndef _DWC_IPC_H
#define _DWC_IPC_H

/*--------------------------------------------------------------------------
 *  Copyright (c) 2001-2004 Igor Daniloff. 
 *	All rights reserved.
 *
 * By using this file, you agree to the terms and conditions set
 * forth in the LICENSE file which can be found at this directory.
 *------------------------------------------------------------------------*/
 
/* $Id: dwc_ipc.h,v 1.35 2007/08/27 10:10:33 akorkov Exp $ */

#include <stddef.h>
#include "dwc_type.h"
#include "dwc_timo.h"
#include "dwc_fd.h"

#ifdef  __cplusplus
extern "C" {
#endif

#define INVALID_IPC             (NULL)
#define DWC_MAX_ADDR_LEN        (255)
#define DWC_IPC_SEPARATOR_CHR   ':'
#define DWC_IPC_SEPARATOR_STR   ":"
#define DWC_IPC_PID_PREFIX      "pid"DWC_IPC_SEPARATOR_STR
#define DWC_IPC_INET_PREFIX     "inet"DWC_IPC_SEPARATOR_STR
#define DWC_IPC_UNIX_PREFIX     "local"DWC_IPC_SEPARATOR_STR

typedef struct _DWC_ipc*         DWC_ipc_t;
typedef struct _DWC_ipc_addr*    DWC_ipc_addr_ptr_t;
typedef DWC_ipc_t                dwc_ipc_t;
typedef DWC_ipc_addr_ptr_t       dwc_ipc_addr_ptr_t;

extern DWC_error_code_t     init_ipc_subsystem ( void );
extern DWC_error_code_t     dinit_ipc_subsystem ( void );
extern DWC_error_code_t     create_ipc ( DWC_ipc_type_t type, DWC_ipc_addr_ptr_t local, DWC_ipc_addr_ptr_t remote, DWC_timeout_t, DWC_bool_t localscan, DWC_bool_t phys, DWC_ipc_t* ipc ); 
extern DWC_error_code_t     delete_ipc ( DWC_ipc_t* ipc );
extern DWC_error_code_t     bind_ipc ( DWC_ipc_t );
extern DWC_error_code_t     listen_ipc ( DWC_ipc_t, int backlog );
extern DWC_error_code_t     accept_ipc ( DWC_ipc_t, DWC_ipc_t*, DWC_timeout_t );
extern DWC_error_code_t     connect_ipc ( DWC_ipc_t ipc );
extern DWC_error_code_t     send_ipc ( DWC_ipc_t ipc, DWC_const_pointer_t buf, DWC_length_t* len_ptr );
extern DWC_error_code_t     recv_ipc ( DWC_ipc_t ipc, DWC_pointer_t buf, DWC_length_t* len_ptr );
extern DWC_error_code_t     recv_ipc_all ( DWC_ipc_t ipc, DWC_pointer_t *buf_ptr, DWC_length_t* len_ptr, DWC_bool_t is_string );
extern DWC_bool_t           is_localscan_allowed_by_ipc( DWC_ipc_t ipc );
extern DWC_ipc_addr_ptr_t   create_ipc_addr ( dwc_const_string_t spec, dwc_bool_t cache, DWC_ipc_type_t* ipc_type );
extern DWC_error_code_t     delete_ipc_addr ( DWC_ipc_addr_ptr_t addr );

/* new interface */
extern dwc_ipc_t            dwc_ipc_create_server( dwc_const_string_t addr, dwc_timeout_t timeout, dwc_bool_t cache, dwc_count_t backlog );
extern dwc_ipc_t            dwc_ipc_create_client( dwc_const_string_t addr, dwc_timeout_t timeout, dwc_bool_t cache );
extern dwc_fdsocket_t       dwc_ipc_get_handle( dwc_ipc_t ipc );
extern dwc_bool_t           dwc_ipc_delete( dwc_ipc_t ipc );
extern dwc_bool_t           dwc_ipc_set_timeout( dwc_ipc_t ipc, dwc_timeout_t seconds );
extern dwc_bool_t           dwc_ipc_set_nodelay( dwc_ipc_t ipc, dwc_bool_t nodelay );    
extern dwc_string_t         dwc_ipc_get_local_address( dwc_ipc_t ipc );
extern dwc_string_t         dwc_ipc_get_remote_address( dwc_ipc_t ipc );
extern dwc_string_t         dwc_ipc_unix_filename( DWC_ipc_addr_ptr_t addr );

extern dwc_bool_t           dw_sig_ignore( int sig );
extern dwc_bool_t           dw_sig_sethandler( int sig, void (*handler)(int) );

/* some useful interface */
extern dwc_bool_t   parse_addr( dwc_const_string_t spec, DWC_ipc_addr_ptr_t paddr, DWC_ipc_type_t* ptype, dwc_bool_t need_resolve );
extern dwc_bool_t   dwc_ipc_inited ( void );
#ifdef  __cplusplus
}
#endif

#endif /* _DWC_IPC_H */
