#ifndef _PIO_IMPL_H
#define _PIO_IMPL_H

#ifdef HAVE_CONFIG_H
#  include "config.h"
#endif

#include <stdbool.h>

#ifdef USE_MPI
#include "mpi.h"

typedef enum 
{
  IO_Open_file,
  IO_Close_file,
  IO_Get_fp,
  IO_Set_fp,
  IO_Send_buffer,
  IO_Finalize
} IO_Server_command;

struct dBuffer
{
  size_t wr_pointer;
  size_t size;
  unsigned char * buffer;
};

typedef struct listElem 
{
  int idx;
  void * val;
  struct listElem * next;
} listElem_t;

typedef int ( * valDestroyFunction ) ( void * );
typedef bool ( * keyCompareFunction ) ( void *, void * );

typedef struct 
{
  listElem_t * head;
  listElem_t * tail;
  valDestroyFunction valDestroy;
  keyCompareFunction keyCompare;
  int count;
} queue_t;

typedef struct
{
  int id;
  int command;
} tag_t;

/* pio.c */
int       setTag ( int, int );
tag_t *   getTag ( int );
void      ungetTag ( tag_t * );

/* pio_dbuffer.c */
int       dbuffer_init ( struct dBuffer **, size_t );
int       dbuffer_push ( struct dBuffer *, unsigned char *, size_t );
size_t    dbuffer_data_size ( struct dBuffer * );
int       dbuffer_reset ( struct dBuffer * );
void      dbuffer_cleanup ( struct dBuffer ** );
size_t    dbuffer_free ( struct dBuffer * );

/* pio_queue.c */
queue_t * queueInit ( valDestroyFunction, keyCompareFunction );
void      queueDestroy ( queue_t * );
int       queuePush ( queue_t *, void *, int, ... );
void *    queueIdx2val ( queue_t *, int );
int       queueDelNode ( queue_t *, int );

/* pio_mpinonb.c */
int       fowMPINONB ( const char * );
int       fcMPINONB ( int );
size_t    fwMPINONB( int, int, const void *, size_t );
void      initMPINONB ( void );
void      finalizeMPINONB ( void );

/* pio_posixasynch.c */
#ifndef _SX
void      pwPOSIXASYNCH ( void );
int       fowPOSIXASYNCH ( const char * );
int       fcPOSIXASYNCH ( int );
size_t    fwPOSIXASYNCH( int, int, const void *, size_t );
void      initPOSIXASYNCH ( void );
void      finalizePOSIXASYNCH ( void );
#endif

/* pio_posixfpguardsendrecv.c */
void      fpgPOSIXFPGUARDSENDRECV ( void );
int       fowPOSIXFPGUARDSENDRECV ( const char * );
int       fcPOSIXFPGUARDSENDRECV ( int );
size_t    fwPOSIXFPGUARDSENDRECV ( int, int, const void *, size_t );
void      initPOSIXFPGUARDSENDRECV ( void );
void      finalizePOSIXFPGUARDSENDRECV ( void );

/* pio_posixnonb.c */
void      pwPOSIXNONB ( void );
int       fowPOSIXNONB ( const char * );
int       fcPOSIXNONB ( int );
size_t    fwPOSIXNONB( int, int, const void *, size_t );
void      initPOSIXNONB ( void );
void      finalizePOSIXNONB ( void );

#endif
#endif
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */
