Remove duplicate init and move sics dependency out of nwatch
This commit is contained in:
@ -48,7 +48,7 @@ extern void StopExit(void); /* in SICSmain.c */
|
|||||||
|
|
||||||
extern int openDevexecLog(); /* in devexec.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 =================== */
|
/* ========================= Less dreadful file statics =================== */
|
||||||
|
|
||||||
#define DEFAULTINIFILE "servo.tcl"
|
#define DEFAULTINIFILE "servo.tcl"
|
||||||
@ -120,7 +120,7 @@ int InitServer(char *file, pServer * pServ)
|
|||||||
pSICSOptions = IFAddOption(pSICSOptions, "ConMask", "0");
|
pSICSOptions = IFAddOption(pSICSOptions, "ConMask", "0");
|
||||||
|
|
||||||
/* initialize the network watcher */
|
/* initialize the network watcher */
|
||||||
NetWatchInit();
|
TaskRegister(self->pTasker, NetWatchTask, NULL, NULL, NULL, 1);
|
||||||
|
|
||||||
/* initialise the server from script */
|
/* initialise the server from script */
|
||||||
SetWriteHistory(0);
|
SetWriteHistory(0);
|
||||||
|
25
nwatch.c
25
nwatch.c
@ -36,27 +36,24 @@ typedef struct __netwatcher_s {
|
|||||||
/* Singleton pattern */
|
/* Singleton pattern */
|
||||||
static pNetWatch instance = NULL;
|
static pNetWatch instance = NULL;
|
||||||
|
|
||||||
static int NetWatchTask(void *pData);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Initialises the Net Watcher singleton and starts the task
|
* \brief Initialises the Net Watcher singleton and starts the task
|
||||||
*
|
*
|
||||||
* \return 1=success, 0=failure
|
* \return 1=success, 0=failure
|
||||||
*/
|
*/
|
||||||
int NetWatchInit(void)
|
static pNetWatch NetWatchGetInstance(void)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* If the singleton has not yet been created, do so now
|
* If the singleton has not yet been created, do so now
|
||||||
*/
|
*/
|
||||||
if (instance == NULL) {
|
if (instance == NULL) {
|
||||||
instance = (pNetWatch) malloc(sizeof(NetWatch));
|
instance = (pNetWatch) malloc(sizeof(NetWatch));
|
||||||
if (instance == NULL)
|
if (instance != NULL) {
|
||||||
return 0;
|
memset(instance, 0, sizeof(NetWatch));
|
||||||
memset(instance, 0, sizeof(NetWatch));
|
instance->lMagic = NWMAGIC;
|
||||||
instance->lMagic = NWMAGIC;
|
}
|
||||||
TaskRegister(pServ->pTasker, NetWatchTask, NULL, NULL, NULL, 1);
|
|
||||||
}
|
}
|
||||||
return 1;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -162,7 +159,7 @@ int NetWatchRegisterTimer(pNWTimer * handle, int mSec,
|
|||||||
pNWCallback callback, void *context)
|
pNWCallback callback, void *context)
|
||||||
{
|
{
|
||||||
assert(callback);
|
assert(callback);
|
||||||
pNetWatch self = instance;
|
pNetWatch self = NetWatchGetInstance();
|
||||||
if (!self || self->lMagic != NWMAGIC)
|
if (!self || self->lMagic != NWMAGIC)
|
||||||
return 0;
|
return 0;
|
||||||
pNWTimer pNew = (pNWTimer) malloc(sizeof(NWTimer));
|
pNWTimer pNew = (pNWTimer) malloc(sizeof(NWTimer));
|
||||||
@ -238,7 +235,7 @@ int NetWatchSetTimerPeriod(pNWTimer handle, int mSecPeriod)
|
|||||||
|
|
||||||
int NetWatchRemoveTimer(pNWTimer handle)
|
int NetWatchRemoveTimer(pNWTimer handle)
|
||||||
{
|
{
|
||||||
pNetWatch self = instance;
|
pNetWatch self = NetWatchGetInstance();
|
||||||
if (!self || self->lMagic != NWMAGIC)
|
if (!self || self->lMagic != NWMAGIC)
|
||||||
return 0;
|
return 0;
|
||||||
if (handle == NULL || handle->vrfy != NWMAGIC)
|
if (handle == NULL || handle->vrfy != NWMAGIC)
|
||||||
@ -317,7 +314,7 @@ int NetWatchRegisterCallback(pNWContext * handle, int iSocket,
|
|||||||
{
|
{
|
||||||
assert(callback);
|
assert(callback);
|
||||||
pNWContext pNew = NULL;
|
pNWContext pNew = NULL;
|
||||||
pNetWatch self = instance;
|
pNetWatch self = NetWatchGetInstance();
|
||||||
if (!self || self->lMagic != NWMAGIC)
|
if (!self || self->lMagic != NWMAGIC)
|
||||||
return 0;
|
return 0;
|
||||||
if (iSocket < 0 || iSocket > 65535)
|
if (iSocket < 0 || iSocket > 65535)
|
||||||
@ -337,7 +334,7 @@ int NetWatchRegisterCallback(pNWContext * handle, int iSocket,
|
|||||||
|
|
||||||
int NetWatchRemoveCallback(pNWContext handle)
|
int NetWatchRemoveCallback(pNWContext handle)
|
||||||
{
|
{
|
||||||
pNetWatch self = instance;
|
pNetWatch self = NetWatchGetInstance();
|
||||||
if (handle == NULL || handle->vrfy != NWMAGIC)
|
if (handle == NULL || handle->vrfy != NWMAGIC)
|
||||||
return 0;
|
return 0;
|
||||||
if (!self || self->lMagic != NWMAGIC)
|
if (!self || self->lMagic != NWMAGIC)
|
||||||
@ -379,7 +376,7 @@ int NetWatchTask(void *pData)
|
|||||||
int iCount;
|
int iCount;
|
||||||
|
|
||||||
/* Check the singleton */
|
/* Check the singleton */
|
||||||
self = (pNetWatch) instance;
|
self = NetWatchGetInstance();
|
||||||
if (!self || self->lMagic != NWMAGIC)
|
if (!self || self->lMagic != NWMAGIC)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -320,8 +320,6 @@ int testLogCmd(SConnection *pCon, SicsInterp *pInter, void *pData,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SiteInit(void) {
|
void SiteInit(void) {
|
||||||
int NetWatchInit(void);
|
|
||||||
NetWatchInit();
|
|
||||||
#define INIT(F) { void F(void); F(); }
|
#define INIT(F) { void F(void); F(); }
|
||||||
/* insert here initialization routines ... */
|
/* insert here initialization routines ... */
|
||||||
INIT(SctEmonInit);
|
INIT(SctEmonInit);
|
||||||
|
Reference in New Issue
Block a user