/* Copyright (c) 2001, 2004 Alex Leigh, All Rights Reserved
 *
 * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ALEX LEIGH
 * The copyright notice above does not evidence any
 * actual or intended publication of such source code.
 * 
 * Use, disclosure, copying, distribution, or transmission of
 * this code without express permission is prohibited.
 */

#ifndef CONTINUITY_H
#define CONTINUITY_H

/* #define CONT_PROFILE */

#include "csys.h"
#include "mecha.h"

#define BUILD_REV "mk4 mod6 rc3"
#define BUILD_LEV_LEN 12
//#define BUILD_LEV_LEN 8

#ifdef PRODUCTION
#define PROD_NOTICE "Production"
#else
#define PROD_NOTICE "Development"
#endif

#ifdef ONESHOT
#define BUILDMODE "One-Shot."
#else
#define BUILDMODE "Multi-Shot."
#endif

#ifdef TA_64BIT
#define BUILD_STRING "Continuity Enterprise Edition - " BUILD_REV " - 64bit " PROD_NOTICE ", " BUILDMODE
#else
#define BUILD_STRING "Continuity Enterprise Edition - " BUILD_REV " - 32bit " PROD_NOTICE ", " BUILDMODE
#endif

#define TA_LOG_OK 0
#define TA_LOG_WARN 1
#define TA_LOG_ERR 2
#define TA_LOG_DIAG 3
#define TA_LOG_AUX 4

#define STATUS_OK 1
#define STATUS_ERROR 2
#define STATUS_PROCEED 3
#define STATUS_EXIT 4
#define STATUS_RESTART 5

#ifdef __cplusplus
extern "C" {
#endif

typedef int(*cont_handler)(void *, lstTset *);

/* dis.c */
typedef struct disSlistener disTlistener;

int disFwait_for_startup(disTlistener * listener);
int disFsetup(disTlistener * listener);
int disFlisten_loop(disTlistener * listener);

int ipv4_dispatcher(void *p, lstTset *opts);
    int ipv4_openport(MECHA_UNUSED_ARGUMENT void *p, lstTset * opts);


        /* continuity.c */
    const xmlTtag *conFget_config_basetag(void);
    void conFwait_for_init (void);
    const char *conFget_build (void);
    void intr_handler (int sigraised);
    int set_userid(void *p, lstTset *opts);
    int conFsocketstash_update(int sd, int idx);
    int conFsocketstash_find(int idx);

/* tas.c */
#define TA_STAT_STRLEN 32
#define TA_STAT_INT 1
#define TA_STAT_UINT 2
#define TA_STAT_CHAR 3
typedef struct tasSstat tasTstat;
typedef struct tasSctl tasTctl;
int tasFinit (void);
tasTstat *tasFget_chain (void);
tasTstat *tasFcreate (const char *module, int instance, const char *name,
		      const char *class, unsigned char type,
		      unsigned long ndata, unsigned char flag);
tasTstat *tasFstat_lookup (tasTctl * ctl, const char *module,
			   int instance, const char *name);
tasTstat *tasFlookup (char *module, int instance, char *name);
void tasFstat_free (tasTstat * statp);
void tasFstat_install (tasTstat * statp);
void tasFstat_delete (tasTstat * statp);
int tasFstat_counter_add (const char *module, int instance, const char *name,
			  unsigned int value);
int tasFstat_counter_sub (const char *module, int instance, const char *name,
			  unsigned int value);
int tasFstat_set (const char *module, int instance, const char *name, unsigned int value);

/* xfr.c */
int xfrFfile(netTconn *conn, const char *path);
int xfrFis_extant(char *path);
int xfrFmmap(netTconn *conn, const char *fname,
              struct stat *sb
) ;
int xfrFmemory(netTconn *conn, char *p, size_t len);

/* mmc.c */
int mmcFclose(char *buf, int len);
int mmcFopen(char *filename, char **buf, int *len);
void* mmcFmap(const char* filename, struct stat* sbP, struct timeval* nowP );
int mmcFinit(void);
void mmcFcleanup(void);
void mmcFcleanup_thr(void);
void mmc_unmap( void* addr, struct stat* sbP, struct timeval* nowP );
void mmc_destroy( void );

/* dl.c */
typedef struct dlSmap dlTmap;
typedef struct dlScategory dlTcategory;
typedef struct dlSentry dlTentry;

void *dlFget_addr(const char *name);
int dlFpipeline_getid(const char *pipeline);
int dlFpipeline_exec(void *payload, int pipeline, const char *limit_name, const char *limit_value);
/* undoc */
int dlFload_library (const char *shlib);
int dlFload_config(void);
int dlFop_show_dl_loads(netTconn *conn, int argc, char **argv);
int dlFop_show_dl_symbols(netTconn *conn, int argc, char **argv);
/* end undoc */

#ifdef __cplusplus
};
#endif

#endif
