/* -TAG:LICENSE-
   
   This file is under the DigitalSpark Freeware Class License, see the
   file LICENSE for complete licensing information.
                                                         
                                                         -TAG:LICENSE- */
#define MAIN
#include <Threading.h>
#include <Strings.h>
#include <CommandLine.h>
#include "tricky.h"

extern int Startup( void );
extern void *Manager( void );
extern void *ClientBridge( void );
extern void *ServerBridge( void );
extern void *IRCServerManager( void );

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

long	keycount=0;

int	VerboseOn = 0;

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

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

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

int	spin=1;

int	ShutdownControl=0;
int	ThreadCount=0;
int	ThreadRunLevel=2;	/* Number of threads running till the */

int	IRCSlot=-1;

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

int main ( int argc, char *argv[] )
{
pthread_attr_t attr, *attrPtr = &attr;

CheckCMD("-d|--debug","",0,0,argc,argv);

if ( TestFlag("-d|--debug",argc,argv) == 0 )
   {
   Detach = 0;
   VerboseOn = 1;
   }

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 *)&ServerBridge, 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);

while ( 1 )
   {
   sleep(100);
   }

return 0;
}
