Remove duplicate init and move sics dependency out of nwatch

This commit is contained in:
Douglas Clowes
2014-04-03 12:11:53 +11:00
parent 719fd7dc5a
commit f9bff7f4f2
3 changed files with 13 additions and 18 deletions

View File

@ -48,7 +48,7 @@ extern void StopExit(void); /* in SICSmain.c */
extern int openDevexecLog(); /* in devexec.c */
extern void NetWatchInit(void); /* in nwatch.c */
extern int NetWatchTask(void *pData); /* in nwatch.c */
/* ========================= Less dreadful file statics =================== */
#define DEFAULTINIFILE "servo.tcl"
@ -120,7 +120,7 @@ int InitServer(char *file, pServer * pServ)
pSICSOptions = IFAddOption(pSICSOptions, "ConMask", "0");
/* initialize the network watcher */
NetWatchInit();
TaskRegister(self->pTasker, NetWatchTask, NULL, NULL, NULL, 1);
/* initialise the server from script */
SetWriteHistory(0);

View File

@ -36,27 +36,24 @@ typedef struct __netwatcher_s {
/* Singleton pattern */
static pNetWatch instance = NULL;
static int NetWatchTask(void *pData);
/**
* \brief Initialises the Net Watcher singleton and starts the task
*
* \return 1=success, 0=failure
*/
int NetWatchInit(void)
static pNetWatch NetWatchGetInstance(void)
{
/*
* If the singleton has not yet been created, do so now
*/
if (instance == NULL) {
instance = (pNetWatch) malloc(sizeof(NetWatch));
if (instance == NULL)
return 0;
memset(instance, 0, sizeof(NetWatch));
instance->lMagic = NWMAGIC;
TaskRegister(pServ->pTasker, NetWatchTask, NULL, NULL, NULL, 1);
if (instance != NULL) {
memset(instance, 0, sizeof(NetWatch));
instance->lMagic = NWMAGIC;
}
}
return 1;
return instance;
}
/*
@ -162,7 +159,7 @@ int NetWatchRegisterTimer(pNWTimer * handle, int mSec,
pNWCallback callback, void *context)
{
assert(callback);
pNetWatch self = instance;
pNetWatch self = NetWatchGetInstance();
if (!self || self->lMagic != NWMAGIC)
return 0;
pNWTimer pNew = (pNWTimer) malloc(sizeof(NWTimer));
@ -238,7 +235,7 @@ int NetWatchSetTimerPeriod(pNWTimer handle, int mSecPeriod)
int NetWatchRemoveTimer(pNWTimer handle)
{
pNetWatch self = instance;
pNetWatch self = NetWatchGetInstance();
if (!self || self->lMagic != NWMAGIC)
return 0;
if (handle == NULL || handle->vrfy != NWMAGIC)
@ -317,7 +314,7 @@ int NetWatchRegisterCallback(pNWContext * handle, int iSocket,
{
assert(callback);
pNWContext pNew = NULL;
pNetWatch self = instance;
pNetWatch self = NetWatchGetInstance();
if (!self || self->lMagic != NWMAGIC)
return 0;
if (iSocket < 0 || iSocket > 65535)
@ -337,7 +334,7 @@ int NetWatchRegisterCallback(pNWContext * handle, int iSocket,
int NetWatchRemoveCallback(pNWContext handle)
{
pNetWatch self = instance;
pNetWatch self = NetWatchGetInstance();
if (handle == NULL || handle->vrfy != NWMAGIC)
return 0;
if (!self || self->lMagic != NWMAGIC)
@ -379,7 +376,7 @@ int NetWatchTask(void *pData)
int iCount;
/* Check the singleton */
self = (pNetWatch) instance;
self = NetWatchGetInstance();
if (!self || self->lMagic != NWMAGIC)
return 0;

View File

@ -320,8 +320,6 @@ int testLogCmd(SConnection *pCon, SicsInterp *pInter, void *pData,
}
void SiteInit(void) {
int NetWatchInit(void);
NetWatchInit();
#define INIT(F) { void F(void); F(); }
/* insert here initialization routines ... */
INIT(SctEmonInit);