Add a NULL aqadapter for use by script context pseudo devices

This allows the creation of a script context device without the need for
a physical device to exist. This pseudo device could derive its values
from other things and apply control to other things.

Writes to, this device are not expected and are logged. Reads from this
device are not expected and are logged and return an "ASCERR: " response.
This commit is contained in:
Douglas Clowes
2014-04-17 13:02:19 +10:00
parent 8306d8587f
commit 29583c51c0

View File

@@ -137,9 +137,72 @@ static void SCAQTransact(Ascon *a)
AsyncUnitSendTxn(unit, command, cmd_len, TransCallback, a, 1024);
}
static int scaqaNullHandler(Ascon *a)
{
const char *command;
int cmd_len;
struct timeval tv;
pPrivate pp = (pPrivate) a->private;
switch (a->state) {
case AsconNotConnected:
return 0;
case AsconConnectStart:
a->state = AsconConnecting;
return 0;
case AsconConnecting:
a->state = AsconConnectDone;
return 0;
case AsconConnectDone:
/* should not get here */
a->state = AsconIdle;
return 0;
case AsconWriteStart:
a->state = AsconWriting;
return 0;
case AsconWriting:
/* Log this as a Warning */
command = GetCharArray(a->wrBuffer);
cmd_len = GetDynStringLength(a->wrBuffer);
gettimeofday(&tv, NULL);
SICSLogWriteTime("WARNING: writing to NULL aqadapter", eWarning, &tv);
SICSLogWriteHexTime(command, cmd_len, eWarning, &tv);
a->state = AsconWriteDone;
return 0;
case AsconWriteDone:
/* should not get here */
a->state = AsconReadStart;
return 0;
case AsconReadStart:
/* Log this as a Warning and Return an ASCERR message */
SICSLogWrite("ASCERR: Reading from NULL aqadapter", eWarning);
DynStringCopy(a->rdBuffer, "ASCERR: Reading from NULL aqadapter");
a->state = AsconReadDone;
return 0;
case AsconReadDone:
/* should not get here */
return 0;
case AsconIdle:
return 0;
case AsconFailed:
a->state = AsconConnectStart;
return 0;
case AsconTimeout:
/* should not get here */
a->state = AsconIdle;
return 0;
case AsconMaxState:
return 0;
default:
return 0;
}
}
static int scaqaProtHandler(Ascon *a)
{
pPrivate pp = (pPrivate) a->private;
if (NULL == pp->unit)
return scaqaNullHandler(a);
switch (a->state) {
case AsconNotConnected:
return 0;
@@ -256,7 +319,10 @@ static int scaqaAsconInit(Ascon *a, SConnection *pCon, int argc, char *argv[])
SCPrintf(pCon, eError, "Insufficient arguments to scaqaAsconInit: %d\n", argc);
return 0;
}
if (!AsyncUnitCreate(argv[1], &asyncUnit)) {
if (strcasecmp("null", argv[1]) == 0) {
asyncUnit = NULL;
}
else if (!AsyncUnitCreate(argv[1], &asyncUnit)) {
SCPrintf(pCon, eError, "Cannot find AsyncQueue '%s' when creating script context adapter '%s'",
argv[1], argv[0]);
return 0;
@@ -268,6 +334,7 @@ static int scaqaAsconInit(Ascon *a, SConnection *pCon, int argc, char *argv[])
a->private = pp;
a->hostport = strdup(argv[1]);
a->killPrivate = SCAQ_KillPrivate;
if (asyncUnit)
AsyncUnitSetNotify(asyncUnit, a, SCAQ_Notify);
return 1;
}