#define MAIN
#include <Threading.h>

extern int Startup( void );
extern void *Keeper( void );
extern void *NetworkManager( void );
extern void *ErrorManager( void );
extern void *Manager( void );
extern void *ConfigManager( void );

int     ErrorNo;
char    ErrorString[255][255];
int     ErrorType[255];

/* Initalize the mutex lockers for the error que and the thread couter */
pthread_mutex_t error_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t threadcount_mutex = PTHREAD_MUTEX_INITIALIZER;

int	VerMajor = 0;
int	VerMinor = 0;
int	VerTiny  = 0;

int	EnforcedWait = 50; 	/* This is the number of mseconds to wait in thread loops */

int	spin=1;

int	ShutdownControl=0;
int	ThreadCount=0;
int	ThreadRunLevel=1;	/* Number of threads running till the program is considered 
                                   started up */

long	keycount=0;

int	VerboseOn=0;

pthread_t KeeperPID;
pthread_t ErrorPID;
pthread_t ManagerPID;
pthread_t ConfigManagerPID;

int main ( void )
{
pthread_attr_t attr, *attrPtr = &attr;

if ( Startup() != NULL ) /* Startup failed if it returns anything but NULL */
   {
   printf("\nStartup Failed ... Exiting.\n");
   exit(1);
   }

pthread_attr_init(attrPtr);
pthread_attr_setdetachstate(attrPtr,1);

pthread_create(&ManagerPID, &attr, (void *)Manager, NULL);
pthread_create(&KeeperPID, &attr, (void *)&Keeper, NULL);
pthread_create(&ConfigManagerPID, &attr, (void *)&ConfigManager, NULL);

/* 
   Note how this last thread is started differently, this is so the program's 
   control is removed off the main() function.
*/
pthread_create(&ErrorPID, NULL, ErrorManager(), NULL);

return 0;
}
