home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
TIMEXSRC.ZIP
/
BA_MAIN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-03-29
|
5KB
|
192 lines
/* ba_main.c -- Main module of the TIMEX background agent
February 1990 Mark E. Mallett, Personal Workstation Magazine
This is the main module of TIMEXBA, the TIMEX background agent
Included are the following routines:
main Main routine
*/
#define INCL_BASE
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <os2.h>
#include "errhand.h"
#include "timex.h"
#include "ba_timex.h"
/* Local definitions */
/* External data referenced */
extern char *Dbfname; /* Database filename */
extern HSEM Eventsem; /* Event list lock semaphore */
extern TID Evtid; /* Event thread ID */
extern char *Logfname; /* Logfile name */
extern int Priclass; /* My priority class */
extern int Prival; /* My priority value */
extern char *Rqpipe; /* Request-pipe name */
extern HPIPE RqpipeH; /* Handle for request pipe */
extern ERRLIST *Werdisp; /* Wild-all error intercept list */
extern ERRLIST *Werlist; /* Wildcard error list */
/* External routines used */
extern void db_read( void ); /* Read the events database */
extern void err_report( int code, char *msgP );
extern void log_begin( void );
extern void log_end( void );
/* Local data publicly available */
/* Local routines and forward declarations */
void init(void);
static int main1( void ); /* First continuation of main() */
/* Private data */
static int ArgC; /* Copy of argc */
static char **ArgV; /* Copy of argv */
char Evstack[EVSTACKSIZE]; /* Stack for the event thread (this
must be a global, non-static
array or an allocated segment). */
/*
*//* main()
The main routine
*/
main(
int argc, /* Argument count */
char **argv /* Argument vector */
) {
/* Save the command line arg vector parms */
ArgC = argc;
ArgV = argv;
/* Create a universal warning interception list */
Werdisp = condition_list( 0, CTINTCEPT );
any_condition( Werdisp, TRUE, err_report );
/* Activate the list and continue to main1() */
intercept_error( main1, (void *)NULL, Werdisp );
return( 0 );
}
static int
main1( void ) {
int status;
int argX;
char *stackP; /* Stack for threads */
/* Setup the wildcard error handling list */
Werlist = condition_list( 0, CTHANDLER );
any_condition( Werlist, TRUE, (int (*)())NULL );
/* Scan command line arguments in a rather crude way */
for( argX = 1; argX < ArgC; ++argX ) {
if ( strnicmp( ArgV[argX], "/DB=", 4 ) == 0 )
Dbfname = &ArgV[argX][4];
else if ( strnicmp( ArgV[argX], "/LOG=", 5 ) == 0 )
Logfname = &ArgV[argX][5];
else {
fprintf( stderr, "Usage: timexba [/DB=name] [/LOG=name]\n" );
return( 0 );
}
}
/* Perform initialization of global data and resources */
init();
/* Log startup */
log_begin();
log( "" );
log( "-----------------");
log( "TIMEXBA starts." );
log( "" );
log_end();
/* Startup the background (event scheduler) thread */
stackP = &Evstack[EVSTACKSIZE];
DosCreateThread( schedule_events, &Evtid, stackP );
/* Poll for and service requests. */
while( 1 ) {
status = DosConnectNmPipe( RqpipeH );
if ( status != 0 )
error( EC_NOTOK, "DosConnectNmPipe failed (%d)", status );
/* Process the request */
process_request();
/* Disconnect. */
DosDisConnectNmPipe( RqpipeH );
}
return( 0 );
}
/*
*//* init()
Initialize global program elements
Accepts :
Returns :
*/
void
init() {
int status; /* Status result */
/* Open the log file */
/* Read the event database. Note that because we haven't started
the other threads yet, we don't have to lock the event list. */
db_read();
/* Set to the defined running priority */
set_priority( 0, Priclass, Prival );
/* Setup semaphores used */
status = DosCreateSem( CSEM_PRIVATE, &Eventsem, EVSEMNAME );
if ( status != 0 )
error( EC_NOTOK, "Can't create event semaphore(%d)", status );
/* Create the pipe for communications */
status = DosMakeNmPipe( Rqpipe, &RqpipeH,
PIPE_ACCESS_DUPLEX | PIPE_NOWRITEBEHIND,
PIPE_WAIT | PIPE_TYPE_MESSAGE |
PIPE_UNLIMITED_INSTANCES,
512, 512, 0L );
if ( status != 0 )
error( EC_NOTOK, "Can't create request pipe (%d)", status );
}