#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <stdarg.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "threading/include/Config.h"

#ifndef ERROR
extern int Error(int type, char *message, ...);
#endif

#ifndef MAIN
extern	FILE	*ErrorPath[10];
extern	int	ErrorPathCount;
extern	int EnforcedWait;
extern	int VerMajor;
extern	int VerMinor;
extern	int VerTiny;
extern	pthread_mutex_t threadcount_mutex;
extern  int     ShutdownControl;;
extern  int     ThreadCount;
extern  int     ThreadRunLevel;
extern  long    keycount;
extern	int     VerboseOn;
#endif

struct ThreadMessageQue {
	int	State;
        char    *Source;
        char    *Type;
        char    *Dest;
        char    *Data;
        time_t  TimeStamp;
};

typedef struct ThreadMessageQue msg_que;

#ifdef MAIN
FILE	*ErrorPath[10];
int	ErrorPathCount=0;
char	ConfigFilePath[1024];
struct	ThreadRegistryDB {
#else
extern	char	ConfigFilePath[1024];
extern struct	ThreadRegistryDB {
#endif
	int		State;
	int		WaitOnToExit;
	char 		*Name;
	char		*Function;
	msg_que		MsgQue[10];
	int		CurMsg;
	int		ProcMsg;
	pthread_t	pID;
	pthread_mutex_t Mutex;
} ThreadDB[400];

#define	PT_FREE		0
#define	PT_RUNNING	11
#define PT_CLOSING	20
#define PT_CLOSED	30

#define PTM_FREE	0
#define	PTM_CONTROL	10
#define PTM_DATA	20

#ifndef TRUE
#define	TRUE		1
#endif
#ifndef FALSE
#define FALSE		0
#endif

extern char             *StripHeading(char *heading, char *string);

#ifndef INTHREADING
extern	void	initThreadingDB( void );
extern	int	AddThreadingMsg(int class, char *name, char *source, char *type, char *dest, char *data);
extern	int	RegisterThread(char *name, char *function, int wait);
extern	int     StopThread(char *name);
extern	int     CheckForThread(char *name);
extern	int	GetThreadMsg(char *source, char *type, char *dest, char *data, time_t *timestamp);
extern	int	ConfigLoad(char *configfile);
#endif
