Remove duplicate init and move sics dependency out of nwatch
This commit is contained in:
25
nwatch.c
25
nwatch.c
@ -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;
|
||||
|
||||
|
Reference in New Issue
Block a user