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

@ -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;