cdev-1.7.2n
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
#include <cdevPlatforms.h>
|
||||
#include <cdevSystem.h>
|
||||
#include <cdevRequestObject.h>
|
||||
#include <cdevDevice.h>
|
||||
#include <cdevGroup.h>
|
||||
#include <cdevCommon.h>
|
||||
|
||||
int main ( )
|
||||
{
|
||||
fprintf(stdout, "\n\
|
||||
=> **********************************************************************\n\
|
||||
=> * This is the program is used to test what happens when a default *\n\
|
||||
=> * server is set that does not exist... Does the message go to the *\n\
|
||||
=> * old default server - or does it generate an error. *\n\
|
||||
=> **********************************************************************\n\n");
|
||||
fflush(stdout);
|
||||
cdevRequestObject * setDefReq = cdevRequestObject::attachPtr("device0", "set default");
|
||||
cdevRequestObject * req = cdevRequestObject::attachPtr("device0", "set attrib0");
|
||||
cdevData data;
|
||||
int val = 0;
|
||||
|
||||
fprintf(stdout, "\n\
|
||||
=> **********************************************************************\n\
|
||||
=> * Commencing communications with MonitorTestServer (100 sends). *\n\
|
||||
=> **********************************************************************\n\n");
|
||||
fflush(stdout);
|
||||
data.insert("value", "MonitorTestServer");
|
||||
data.asciiDump();
|
||||
setDefReq->send(data, NULL);
|
||||
|
||||
for(val=0; val<100; val++)
|
||||
{
|
||||
data.insert("value", val);
|
||||
req->send(data, NULL);
|
||||
}
|
||||
|
||||
fprintf(stdout, "\n\
|
||||
=> **********************************************************************\n\
|
||||
=> * Now setting the default server to MonitorTestServer1... This *\n\
|
||||
=> * server should not exist. Performing 100 sends. *\n\
|
||||
=> **********************************************************************\n\n");
|
||||
fflush(stdout);
|
||||
data.insert("value", "MonitorTestServer1");
|
||||
data.asciiDump();
|
||||
setDefReq->send(data, NULL);
|
||||
|
||||
for(val=0; val<100; val++)
|
||||
{
|
||||
data.insert("value", val);
|
||||
req->send(data, NULL);
|
||||
}
|
||||
|
||||
fprintf(stdout, "\n\
|
||||
=> **********************************************************************\n\
|
||||
=> * Switching back to the other default server. *\n\
|
||||
=> **********************************************************************\n\n");
|
||||
fflush(stdout);
|
||||
data.insert("value", "MonitorTestServer");
|
||||
data.asciiDump();
|
||||
setDefReq->send(data, NULL);
|
||||
|
||||
for(val=0; val<100; val++)
|
||||
{
|
||||
data.insert("value", val);
|
||||
req->send(data, NULL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
ARCH = OS
|
||||
SHOBJ = YES
|
||||
|
||||
include ../../include/makeinclude/Makefile.$(ARCH)
|
||||
|
||||
APPNAME = "Client/Server Monitor Test"
|
||||
CXXINCLUDES = -I./
|
||||
SERVER_LIBS = -L$(CDEVLIB) -lcdevGenericServer $(CDEVLIBS) $(OSLIBS)
|
||||
|
||||
ifeq ($(SHOBJ), YES)
|
||||
LIBS = -L$(CDEVLIB) -lcdevGenericServer $(CDEVLIBS) $(OSLIBS)
|
||||
TARGETS = $(BASELIB)/MonitorTestService.so $(BASEBIN)/MonitorTestServer $(BASEBIN)/MonitorTest $(BASEBIN)/MonitorReader $(BASEBIN)/MonitorOffTest $(BASEBIN)/MonitorWriter $(BASEBIN)/DefaultServerTest
|
||||
else
|
||||
LIBS = -L$(CDEVLIB) -lcdevGenericServer $(CDEVLIBS) $(OSLIBS)
|
||||
TARGETS = $(BASELIB)/libMonitorTestService.a $(BASEBIN)/MonitorTestServer $(BASEBIN)/MonitorTest $(BASEBIN)/MonitorReader $(BASEBIN)/MonitorOffTest $(BASEBIN)/MonitorWriter $(BASEBIN)/DefaultServerTest
|
||||
endif
|
||||
|
||||
|
||||
targets : $(TARGETS)
|
||||
|
||||
$(BASEBIN)/MonitorTestServer : $(OBJDIR)/MonitorTestServer.o $(OBJDIR)/MonitorTestAttrib.o
|
||||
$(LINK.cc) $^ $(SERVER_LIBS) -o $@
|
||||
|
||||
$(BASELIB)/MonitorTestService.so : $(OBJDIR)/MonitorTestService.o
|
||||
$(LINK.so) -o $@ $^ -L$(CDEVLIB) -lcdevGenericServer $(OSLIBS)
|
||||
@mkdir -p $(CDEVSHOBJ)/$(CDEVVERSION)
|
||||
@cp $@ $(CDEVSHOBJ)/$(CDEVVERSION)/$(@F)
|
||||
|
||||
$(BASELIB)/libMonitorTestService.a : $(OBJDIR)/MonitorTestService.o
|
||||
$(LINK.a) $@ $^
|
||||
@$(RANLIB) $@ > /dev/null
|
||||
|
||||
$(BASEBIN)/MonitorTest : $(OBJDIR)/MonitorTest.o
|
||||
$(LINK.cc) $^ -o $@ $(LIBS)
|
||||
|
||||
$(BASEBIN)/DefaultServerTest : $(OBJDIR)/DefaultServerTest.o
|
||||
$(LINK.cc) $^ -o $@ $(LIBS)
|
||||
|
||||
$(BASEBIN)/MonitorReader : $(OBJDIR)/MonitorReader.o
|
||||
$(LINK.cc) $^ -o $@ $(LIBS)
|
||||
|
||||
$(BASEBIN)/MonitorOffTest : $(OBJDIR)/MonitorOffTest.o
|
||||
$(LINK.cc) $^ -o $@ $(LIBS)
|
||||
|
||||
$(BASEBIN)/MonitorWriter : $(OBJDIR)/MonitorWriter.o
|
||||
$(LINK.cc) $^ -o $@ $(LIBS)
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
#include <cdevPlatforms.h>
|
||||
#include <cdevSystem.h>
|
||||
#include <cdevRequestObject.h>
|
||||
#include <cdevDevice.h>
|
||||
#include <cdevGroup.h>
|
||||
#include <cdevCommon.h>
|
||||
|
||||
int callbackCount = 0;
|
||||
|
||||
void callback ( int status, void * /*arg*/, cdevRequestObject & req, cdevData & /*data*/ )
|
||||
{
|
||||
if(status==CDEV_SUCCESS)
|
||||
{
|
||||
callbackCount++;
|
||||
if(callbackCount%1==0) fprintf(stdout, "Received callback %i - %s:%s \n", callbackCount, req.device().name(), req.message());
|
||||
}
|
||||
else if(status==CDEV_DISCONNECTED) fprintf(stdout, "The monitor has become disconnected on %s:%s\n", req.device().name(), req.message());
|
||||
else if(status==CDEV_RECONNECTED) fprintf(stdout, "The monitor has become reconnected on %s:%s\n", req.device().name(), req.message());
|
||||
else fprintf(stdout, "Status code %i was received on %s:%s\n", status, req.device().name(), req.message());
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
const int DEVICE_COUNT = 9;
|
||||
const int MESSAGE_COUNT = 9;
|
||||
|
||||
int main ( )
|
||||
{
|
||||
cdevRequestObject & monOnReq = cdevRequestObject::attachRef("ExpSrv", "monitorOn attrib1");
|
||||
cdevRequestObject & monOffReq = cdevRequestObject::attachRef("ExpSrv", "monitorOff attrib1");
|
||||
cdevCallback cb (callback, NULL);
|
||||
monOnReq.sendCallback(NULL, cb);
|
||||
while(callbackCount<10)
|
||||
{
|
||||
cdevSystem::defaultSystem().pend(1.0);
|
||||
}
|
||||
monOffReq.sendCallback(NULL, cb);
|
||||
fprintf(stdout, "Kill me when you're tired of looking at this...\n");
|
||||
fflush(stdout);
|
||||
while(1) cdevSystem::defaultSystem().pend(1.0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
#include <cdevPlatforms.h>
|
||||
#include <cdevSystem.h>
|
||||
#include <cdevRequestObject.h>
|
||||
#include <cdevDevice.h>
|
||||
#include <cdevGroup.h>
|
||||
#include <cdevCommon.h>
|
||||
|
||||
int callbackCount = 0;
|
||||
|
||||
void callback ( int status, void * /*arg*/, cdevRequestObject & req, cdevData & /*data*/ )
|
||||
{
|
||||
if(status==CDEV_SUCCESS)
|
||||
{
|
||||
callbackCount++;
|
||||
if(callbackCount%1000==0) fprintf(stdout, "Received callback %i - %s:%s \n", callbackCount, req.device().name(), req.message());
|
||||
}
|
||||
else if(status==CDEV_DISCONNECTED) fprintf(stdout, "The monitor has become disconnected on %s:%s\n", req.device().name(), req.message());
|
||||
else if(status==CDEV_RECONNECTED) fprintf(stdout, "The monitor has become reconnected on %s:%s\n", req.device().name(), req.message());
|
||||
else fprintf(stdout, "Status code %i was received on %s:%s\n", req.device().name(), req.message());
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
const int DEVICE_COUNT = 9;
|
||||
const int MESSAGE_COUNT = 9;
|
||||
|
||||
int main ( )
|
||||
{
|
||||
fprintf(stdout, "\n\
|
||||
=> **********************************************************************\n\
|
||||
=> * This is is the receiving part of a two part application. This *\n\
|
||||
=> * program willl post monitors and will listen for changes that are *\n\
|
||||
=> * generated by the other application - MonitorWriter *\n\
|
||||
=> **********************************************************************\n\n");
|
||||
cdevDevice * deviceList[DEVICE_COUNT];
|
||||
cdevCallback cb(callback, NULL);
|
||||
cdevData data;
|
||||
char msg[255];
|
||||
int deviceCnt;
|
||||
int msgCnt;
|
||||
|
||||
cdevRequestObject & req = cdevRequestObject::attachRef("device0", "set default");
|
||||
data.insert("value", "MonitorTestServer");
|
||||
req.send(data, NULL);
|
||||
|
||||
for(deviceCnt=0; deviceCnt<DEVICE_COUNT; deviceCnt++)
|
||||
{
|
||||
sprintf(msg, "device%i", deviceCnt);
|
||||
deviceList[deviceCnt] = cdevDevice::attachPtr(msg);
|
||||
|
||||
for(msgCnt=0; msgCnt<MESSAGE_COUNT; msgCnt++)
|
||||
{
|
||||
sprintf(msg, "monitorOn attrib%i", msgCnt);
|
||||
deviceList[deviceCnt]->sendCallback(msg, NULL, cb);
|
||||
}
|
||||
}
|
||||
cdevSystem::defaultSystem().setThreshold(CDEV_SEVERITY_INFO);
|
||||
while(1) cdevSystem::defaultSystem().pend(5.0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
#include <cdevPlatforms.h>
|
||||
#include <cdevSystem.h>
|
||||
#include <cdevRequestObject.h>
|
||||
#include <cdevDevice.h>
|
||||
#include <cdevGroup.h>
|
||||
#include <cdevCommon.h>
|
||||
|
||||
int callbackCount = 0;
|
||||
|
||||
void callback ( int status, void * arg, cdevRequestObject & req, cdevData & data )
|
||||
{
|
||||
if(status==CDEV_SUCCESS) callbackCount++;
|
||||
}
|
||||
|
||||
const int DEVICE_COUNT = 9;
|
||||
const int MESSAGE_COUNT = 9;
|
||||
|
||||
int main ( int argc, char ** argv )
|
||||
{
|
||||
fprintf(stdout, "\n\
|
||||
=> **********************************************************************\n\
|
||||
=> * This is program will post a collection of monitors to the monitor *\n\
|
||||
=> * server and will then post changes to the attributes. The program *\n\
|
||||
=> * will wait for results to be returned. *\n\
|
||||
=> **********************************************************************\n\n");
|
||||
fflush(stdout);
|
||||
cdevDevice * deviceList[DEVICE_COUNT];
|
||||
cdevRequestObject * reqList[DEVICE_COUNT*MESSAGE_COUNT];
|
||||
cdevCallback cb(callback, NULL);
|
||||
cdevData data;
|
||||
float values[DEVICE_COUNT*MESSAGE_COUNT];
|
||||
char msg[255];
|
||||
int deviceCnt;
|
||||
int msgCnt;
|
||||
int repeatCount = (argc>1)?atoi(argv[1]):5;
|
||||
|
||||
// *********************************************************************
|
||||
// * First get all of the values from the devices and install monitors.
|
||||
// *********************************************************************
|
||||
for(deviceCnt=0; deviceCnt<DEVICE_COUNT; deviceCnt++)
|
||||
{
|
||||
sprintf(msg, "device%i", deviceCnt);
|
||||
deviceList[deviceCnt] = cdevDevice::attachPtr(msg);
|
||||
|
||||
for(msgCnt=0; msgCnt<MESSAGE_COUNT; msgCnt++)
|
||||
{
|
||||
sprintf(msg, "get attrib%i", msgCnt);
|
||||
if(deviceList[deviceCnt]->send(msg, NULL, data)==CDEV_SUCCESS)
|
||||
{
|
||||
data.get("value", &values[deviceCnt*MESSAGE_COUNT+msgCnt]);
|
||||
}
|
||||
else {
|
||||
values[deviceCnt*MESSAGE_COUNT+msgCnt] = 0;
|
||||
fprintf(stdout, "ERROR : device %s : %s failed\n", deviceList[deviceCnt]->name(), msg);
|
||||
}
|
||||
sprintf(msg, "monitorOn attrib%i", msgCnt);
|
||||
deviceList[deviceCnt]->sendCallback(msg, NULL, cb);
|
||||
callbackCount--;
|
||||
|
||||
sprintf(msg, "set attrib%i", msgCnt);
|
||||
reqList[deviceCnt*MESSAGE_COUNT+msgCnt] = deviceList[deviceCnt]->getRequestObject(msg);
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stdout, "=> Sending %i changes to %i monitors\n", repeatCount, DEVICE_COUNT*MESSAGE_COUNT);
|
||||
|
||||
for(int i = 0; i<repeatCount; i++)
|
||||
{
|
||||
for(int j=0; j<DEVICE_COUNT*MESSAGE_COUNT; j++)
|
||||
{
|
||||
values[j]+=1.0;
|
||||
data.insert("value", values[j]);
|
||||
reqList[j]->sendNoBlock(data, NULL);
|
||||
}
|
||||
cdevSystem::defaultSystem().pend();
|
||||
fprintf(stdout, "%i Change Requests Transmitted\n", (i+1)*DEVICE_COUNT*MESSAGE_COUNT);
|
||||
}
|
||||
|
||||
while(callbackCount<DEVICE_COUNT*MESSAGE_COUNT*repeatCount)
|
||||
{
|
||||
cdevSystem::defaultSystem().pend(1.0);
|
||||
fprintf(stdout, "=> %i Monitors received so far...\n", callbackCount);
|
||||
}
|
||||
fprintf(stdout, "=> %i Monitors have been fired\n", callbackCount);
|
||||
|
||||
// *********************************************************************
|
||||
// * Finally, remove all monitors.
|
||||
// *********************************************************************
|
||||
for(deviceCnt=0; deviceCnt<DEVICE_COUNT; deviceCnt++)
|
||||
{
|
||||
for(msgCnt=0; msgCnt<MESSAGE_COUNT; msgCnt++)
|
||||
{
|
||||
sprintf(msg, "monitorOff attrib%i", msgCnt);
|
||||
deviceList[deviceCnt]->sendCallback(msg, NULL, cb);
|
||||
}
|
||||
}
|
||||
cdevSystem::defaultSystem().pend();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
service Gateway
|
||||
{
|
||||
tags {server}
|
||||
}
|
||||
|
||||
class MonitorTests
|
||||
{
|
||||
verbs {get, set, monitorOn, monitorOff}
|
||||
attributes
|
||||
{
|
||||
default Gateway;
|
||||
servers Gateway;
|
||||
attrib0 Gateway {server=Gateway1};
|
||||
attrib1 Gateway {server=Gateway1};
|
||||
attrib2 Gateway {server=Gateway1};
|
||||
attrib3 Gateway {server=Gateway1};
|
||||
attrib4 Gateway {server=Gateway1};
|
||||
attrib5 Gateway {server=Gateway1};
|
||||
attrib6 Gateway {server=Gateway1};
|
||||
attrib7 Gateway {server=Gateway1};
|
||||
attrib8 Gateway {server=Gateway1};
|
||||
attrib9 Gateway {server=Gateway1};
|
||||
}
|
||||
messages
|
||||
{
|
||||
disconnect Gateway;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MonitorTests :
|
||||
device0, device1, device2, device3, device4,
|
||||
device5, device6, device7, device8, device9
|
||||
;
|
||||
@@ -0,0 +1,67 @@
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <cdevSystem.h>
|
||||
#include <cdevRequestObject.h>
|
||||
#include <cdevDevice.h>
|
||||
#include <cdevGroup.h>
|
||||
#include <cdevCommon.h>
|
||||
|
||||
void callback ( int status, void * arg, cdevRequestObject & req, cdevData & data )
|
||||
{
|
||||
}
|
||||
|
||||
const int DEVICE_COUNT = 9;
|
||||
const int MESSAGE_COUNT = 9;
|
||||
|
||||
int main ( int argc, char ** argv )
|
||||
{
|
||||
cdevDevice * deviceList[DEVICE_COUNT];
|
||||
cdevRequestObject * reqList[DEVICE_COUNT*MESSAGE_COUNT];
|
||||
cdevCallback cb(callback, NULL);
|
||||
cdevData data;
|
||||
float values[DEVICE_COUNT][MESSAGE_COUNT];
|
||||
char msg[255];
|
||||
int deviceCnt;
|
||||
int msgCnt;
|
||||
|
||||
// *********************************************************************
|
||||
// * First get all of the values from the devices and install monitors.
|
||||
// *********************************************************************
|
||||
for(deviceCnt=0; deviceCnt<DEVICE_COUNT; deviceCnt++)
|
||||
{
|
||||
sprintf(msg, "device%i", deviceCnt);
|
||||
deviceList[deviceCnt] = cdevDevice::attachPtr(str);
|
||||
|
||||
for(msgCnt=0; msgCnt<MESSAGE_COUNT; msgCnt++)
|
||||
{
|
||||
sprintf(msg, "get attrib%i", msgCnt);
|
||||
if(deviceList[deviceCnt]->send(msg, NULL, data)==CDEV_SUCCESS)
|
||||
{
|
||||
data->get("value", &values[deviceCnt][msgCnt]);
|
||||
}
|
||||
else values[deviceCnt][msgCnt] = 0;
|
||||
|
||||
sprintf(msg, "monitorOn attrib%i", msgCnt);
|
||||
deviceList[deviceCnt]->sendCallback(msg, cb, NULL);
|
||||
|
||||
sprintf(msg, "set attrib%i", msgCnt);
|
||||
reqList[deviceCnt*MESSAGE_COUNT+msgCnt] = deviceList[deviceCount]->getRequestObject(msg);
|
||||
}
|
||||
}
|
||||
|
||||
// *********************************************************************
|
||||
// * Finally, remove all monitors.
|
||||
// *********************************************************************
|
||||
for(deviceCnt=0; deviceCnt<DEVICE_COUNT; deviceCnt++)
|
||||
{
|
||||
for(msgCnt=0; msgCnt<MESSAGE_COUNT; msgCnt++)
|
||||
{
|
||||
sprintf(msg, "monitorOff attrib%i", msgCnt);
|
||||
deviceList[deviceCnt]->sendCallback(msg, cb, NULL);
|
||||
}
|
||||
}
|
||||
cdevSystem::defaultSystem().pend();
|
||||
}
|
||||
@@ -0,0 +1,445 @@
|
||||
#include <MonitorTestAttrib.h>
|
||||
|
||||
static int VALUE_TAG_ID = -1;
|
||||
static int STATUS_TAG_ID = -1;
|
||||
static int SEVERITY_TAG_ID = -1;
|
||||
static int UNITS_TAG_ID = -1;
|
||||
static int ALARMHIGH_TAG_ID = -1;
|
||||
static int ALARMLOW_TAG_ID = -1;
|
||||
static int WARNINGHIGH_TAG_ID = -1;
|
||||
static int WARNINGLOW_TAG_ID = -1;
|
||||
static int CONTROLHIGH_TAG_ID = -1;
|
||||
static int CONTROLLOW_TAG_ID = -1;
|
||||
|
||||
#define VALUE_TAG ((VALUE_TAG_ID<0 && cdevData::tagC2I("value", &VALUE_TAG_ID)!=CDEV_SUCCESS)?-1:VALUE_TAG_ID)
|
||||
#define STATUS_TAG ((STATUS_TAG_ID<0 && cdevData::tagC2I("status", &STATUS_TAG_ID)!=CDEV_SUCCESS)?-1:STATUS_TAG_ID)
|
||||
#define SEVERITY_TAG ((SEVERITY_TAG_ID<0 && cdevData::tagC2I("severity", &SEVERITY_TAG_ID)!=CDEV_SUCCESS)?-1:SEVERITY_TAG_ID)
|
||||
#define UNITS_TAG ((UNITS_TAG_ID<0 && cdevData::tagC2I("units", &UNITS_TAG_ID)!=CDEV_SUCCESS)?-1:UNITS_TAG_ID)
|
||||
#define ALARMHIGH_TAG ((ALARMHIGH_TAG_ID<0 && cdevData::tagC2I("alarmHigh", &ALARMHIGH_TAG_ID)!=CDEV_SUCCESS)?-1:ALARMHIGH_TAG_ID)
|
||||
#define ALARMLOW_TAG ((ALARMLOW_TAG_ID<0 && cdevData::tagC2I("alarmLow", &ALARMLOW_TAG_ID)!=CDEV_SUCCESS)?-1:ALARMLOW_TAG_ID)
|
||||
#define WARNINGHIGH_TAG ((WARNINGHIGH_TAG_ID<0 && cdevData::tagC2I("warningHigh", &WARNINGHIGH_TAG_ID)!=CDEV_SUCCESS)?-1:WARNINGHIGH_TAG_ID)
|
||||
#define WARNINGLOW_TAG ((WARNINGLOW_TAG_ID<0 && cdevData::tagC2I("warningLow", &WARNINGLOW_TAG_ID)!=CDEV_SUCCESS)?-1:WARNINGLOW_TAG_ID)
|
||||
#define CONTROLHIGH_TAG ((CONTROLHIGH_TAG_ID<0 && cdevData::tagC2I("controlHigh", &CONTROLHIGH_TAG_ID)!=CDEV_SUCCESS)?-1:CONTROLHIGH_TAG_ID)
|
||||
#define CONTROLLOW_TAG ((CONTROLLOW_TAG_ID<0 && cdevData::tagC2I("controlLow", &CONTROLLOW_TAG_ID)!=CDEV_SUCCESS)?-1:CONTROLLOW_TAG_ID)
|
||||
|
||||
// *****************************************************************************
|
||||
// * MonitorTestAttrib::MonitorTestAttrib :
|
||||
// * This is the constructor for the MonitorTestAttrib class. It initializes the
|
||||
// * internal mechanisms to 0.
|
||||
// *****************************************************************************
|
||||
MonitorTestAttrib::MonitorTestAttrib ( char * Device, char * Attrib )
|
||||
: device(strdup(Device)),
|
||||
attrib(strdup(Attrib)),
|
||||
monitors(NULL),
|
||||
value(0.0),
|
||||
alarmHigh(0.0),
|
||||
alarmLow(0.0),
|
||||
warningHigh(0.0),
|
||||
warningLow(0.0),
|
||||
controlHigh(0.0),
|
||||
controlLow(0.0)
|
||||
{
|
||||
*severity = 0;
|
||||
*units = 0;
|
||||
strcpy(status, "NORMAL");
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * MonitorTestAttrib::~MonitorTestAttrib :
|
||||
// * This is the destructor for the MonitorTestAttrib class. It must free the
|
||||
// * memory associated with the device and attribute names.
|
||||
// *****************************************************************************
|
||||
MonitorTestAttrib::~MonitorTestAttrib ( void )
|
||||
{
|
||||
delete device;
|
||||
delete attrib;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * MonitorTestAttrib::setFromData :
|
||||
// * This method will populate the MonitorTestAttrib object with the data contained in
|
||||
// * the cdevData object.
|
||||
// *****************************************************************************
|
||||
int MonitorTestAttrib::setFromData ( cdevData * data )
|
||||
{
|
||||
double val;
|
||||
int result;
|
||||
if(data!=NULL)
|
||||
{
|
||||
result = CDEV_SUCCESS;
|
||||
data->get(UNITS_TAG, units, 255);
|
||||
if(data->get(CONTROLLOW_TAG, &val)==CDEV_SUCCESS) setControlLow(val);
|
||||
if(data->get(CONTROLHIGH_TAG, &val)==CDEV_SUCCESS) setControlHigh(val);
|
||||
if(data->get(ALARMLOW_TAG, &val)==CDEV_SUCCESS) setAlarmLow(val);
|
||||
if(data->get(ALARMHIGH_TAG, &val)==CDEV_SUCCESS) setAlarmHigh(val);
|
||||
if(data->get(WARNINGLOW_TAG, &val)==CDEV_SUCCESS) setWarningLow(val);
|
||||
if(data->get(WARNINGHIGH_TAG, &val)==CDEV_SUCCESS) setWarningHigh(val);
|
||||
if(data->get(VALUE_TAG, &val)==CDEV_SUCCESS)
|
||||
{
|
||||
result=setValue(val);
|
||||
}
|
||||
}
|
||||
else result = CDEV_ERROR;
|
||||
checkAlarms();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * MonitorTestAttrib::getToData :
|
||||
// * This method will populate the MonitorTestAttrib object with the data contained in
|
||||
// * the cdevData object.
|
||||
// *****************************************************************************
|
||||
void MonitorTestAttrib::getToData ( cdevData * data, cdevData * context )
|
||||
{
|
||||
if(data!=NULL)
|
||||
{
|
||||
data->remove();
|
||||
if(context!=NULL)
|
||||
{
|
||||
if(context->getType(VALUE_TAG)!=CDEV_INVALID) data->insert(VALUE_TAG, getValue());
|
||||
if(context->getType(STATUS_TAG)!=CDEV_INVALID) data->insert(STATUS_TAG, getStatus());
|
||||
if(context->getType(SEVERITY_TAG)!=CDEV_INVALID) data->insert(SEVERITY_TAG, getSeverity());
|
||||
if(context->getType(UNITS_TAG)!=CDEV_INVALID) data->insert(UNITS_TAG, getUnits());
|
||||
if(context->getType(CONTROLLOW_TAG)!=CDEV_INVALID) data->insert(CONTROLLOW_TAG, getControlLow());
|
||||
if(context->getType(CONTROLHIGH_TAG)!=CDEV_INVALID) data->insert(CONTROLHIGH_TAG, getControlHigh());
|
||||
if(context->getType(ALARMLOW_TAG)!=CDEV_INVALID) data->insert(ALARMLOW_TAG, getAlarmLow());
|
||||
if(context->getType(ALARMHIGH_TAG)!=CDEV_INVALID) data->insert(ALARMHIGH_TAG, getAlarmHigh());
|
||||
if(context->getType(WARNINGLOW_TAG)!=CDEV_INVALID) data->insert(WARNINGLOW_TAG, getWarningLow());
|
||||
if(context->getType(WARNINGHIGH_TAG)!=CDEV_INVALID) data->insert(WARNINGHIGH_TAG, getWarningHigh());
|
||||
}
|
||||
else
|
||||
{
|
||||
data->insert(VALUE_TAG, getValue());
|
||||
data->insert(STATUS_TAG, getStatus());
|
||||
data->insert(SEVERITY_TAG, getSeverity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * MonitorTestAttrib::getAllToData :
|
||||
// * This method will populate the MonitorTestAttrib object with the data contained in
|
||||
// * the cdevData object.
|
||||
// *****************************************************************************
|
||||
void MonitorTestAttrib::getAllToData ( cdevData * data )
|
||||
{
|
||||
if(data!=NULL)
|
||||
{
|
||||
data->remove();
|
||||
data->insert(VALUE_TAG, getValue());
|
||||
data->insert(STATUS_TAG, getStatus());
|
||||
data->insert(SEVERITY_TAG, getSeverity());
|
||||
data->insert(UNITS_TAG, getUnits());
|
||||
data->insert(CONTROLLOW_TAG, getControlLow());
|
||||
data->insert(CONTROLHIGH_TAG, getControlHigh());
|
||||
data->insert(ALARMLOW_TAG, getAlarmLow());
|
||||
data->insert(ALARMHIGH_TAG, getAlarmHigh());
|
||||
data->insert(WARNINGLOW_TAG, getWarningLow());
|
||||
data->insert(WARNINGHIGH_TAG, getWarningHigh());
|
||||
}
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * MonitorTestAttrib::setValue :
|
||||
// * This method allows the caller to set the value of the MonitorTestAttrib.
|
||||
// * This call will fail if the specified value is outside of the legal
|
||||
// * range.
|
||||
// *****************************************************************************
|
||||
int MonitorTestAttrib::setValue ( double Value )
|
||||
{
|
||||
resultCode = CDEV_SUCCESS;
|
||||
|
||||
if(controlHigh>controlLow &&
|
||||
(Value<controlLow || Value>controlHigh))
|
||||
{
|
||||
resultCode = CDEV_OUTOFRANGE;
|
||||
}
|
||||
else if(value != Value)
|
||||
{
|
||||
value = Value;
|
||||
checkAlarms();
|
||||
if(monitors && monitors->isMonitored())
|
||||
{
|
||||
cdevData data;
|
||||
getAllToData(&data);
|
||||
monitors->fireMonitor(VALUE_TAG, &data);
|
||||
}
|
||||
}
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * MonitorTestAttrib::setStatus :
|
||||
// * This method allows the caller to set the status of the device.
|
||||
// *****************************************************************************
|
||||
int MonitorTestAttrib::setStatus ( char * Status )
|
||||
{
|
||||
if(strcmp(status, Status))
|
||||
{
|
||||
strncpy(status, Status, 255);
|
||||
status[254] = 0;
|
||||
if(monitors && monitors->isMonitored())
|
||||
{
|
||||
cdevData data;
|
||||
getAllToData(&data);
|
||||
monitors->fireMonitor(STATUS_TAG, &data);
|
||||
}
|
||||
}
|
||||
return CDEV_SUCCESS;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * MonitorTestAttrib::setSeverity :
|
||||
// * This method allows the caller to set the severity flag for the device.
|
||||
// *****************************************************************************
|
||||
int MonitorTestAttrib::setSeverity ( char * Severity )
|
||||
{
|
||||
if(strcmp(severity, Severity))
|
||||
{
|
||||
strncpy(severity, Severity, 255);
|
||||
severity[254] = 0;
|
||||
if(monitors && monitors->isMonitored())
|
||||
{
|
||||
cdevData data;
|
||||
getAllToData(&data);
|
||||
monitors->fireMonitor(SEVERITY_TAG, &data);
|
||||
}
|
||||
}
|
||||
return CDEV_SUCCESS;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * MonitorTestAttrib::setUnits :
|
||||
// * This method allows the caller to set the units for the device.
|
||||
// *****************************************************************************
|
||||
int MonitorTestAttrib::setUnits ( char * Units )
|
||||
{
|
||||
if(strcmp(units, Units))
|
||||
{
|
||||
strncpy(units, Units, 255);
|
||||
units[254] = 0;
|
||||
if(monitors && monitors->isMonitored())
|
||||
{
|
||||
cdevData data;
|
||||
getAllToData(&data);
|
||||
monitors->fireMonitor(UNITS_TAG, &data);
|
||||
}
|
||||
}
|
||||
return CDEV_SUCCESS;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * MonitorTestAttrib::setAlarmHigh :
|
||||
// * This method allows the caller to set the high alarm value of the device.
|
||||
// *****************************************************************************
|
||||
int MonitorTestAttrib::setAlarmHigh ( double AlarmHigh )
|
||||
{
|
||||
if(alarmHigh!=AlarmHigh)
|
||||
{
|
||||
alarmHigh = AlarmHigh;
|
||||
checkAlarms();
|
||||
if(monitors && monitors->isMonitored())
|
||||
{
|
||||
cdevData data;
|
||||
getAllToData(&data);
|
||||
monitors->fireMonitor(ALARMHIGH_TAG, &data);
|
||||
}
|
||||
}
|
||||
return CDEV_SUCCESS;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * MonitorTestAttrib::setAlarmLow :
|
||||
// * This method allows the caller to set the low alarm value of the device.
|
||||
// *****************************************************************************
|
||||
int MonitorTestAttrib::setAlarmLow ( double AlarmLow )
|
||||
{
|
||||
if(alarmLow!=AlarmLow)
|
||||
{
|
||||
alarmLow = AlarmLow;
|
||||
checkAlarms();
|
||||
if(monitors && monitors->isMonitored())
|
||||
{
|
||||
cdevData data;
|
||||
getAllToData(&data);
|
||||
monitors->fireMonitor(ALARMLOW_TAG, &data);
|
||||
}
|
||||
}
|
||||
return CDEV_SUCCESS;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * MonitorTestAttrib::setWarningHigh :
|
||||
// * This method allows the caller to set the high warning value of a device.
|
||||
// *****************************************************************************
|
||||
int MonitorTestAttrib::setWarningHigh ( double WarningHigh )
|
||||
{
|
||||
if(warningHigh!=WarningHigh)
|
||||
{
|
||||
warningHigh = WarningHigh;
|
||||
checkAlarms();
|
||||
if(monitors && monitors->isMonitored())
|
||||
{
|
||||
cdevData data;
|
||||
getAllToData(&data);
|
||||
monitors->fireMonitor(WARNINGHIGH_TAG, &data);
|
||||
}
|
||||
}
|
||||
return CDEV_SUCCESS;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * MonitorTestAttrib::setWarningLow :
|
||||
// * This method allows the caller to set the low warning value of a device.
|
||||
// *****************************************************************************
|
||||
int MonitorTestAttrib::setWarningLow ( double WarningLow )
|
||||
{
|
||||
if(warningLow != WarningLow)
|
||||
{
|
||||
warningLow = WarningLow;
|
||||
checkAlarms();
|
||||
if(monitors && monitors->isMonitored())
|
||||
{
|
||||
cdevData data;
|
||||
getAllToData(&data);
|
||||
monitors->fireMonitor(WARNINGLOW_TAG, &data);
|
||||
}
|
||||
}
|
||||
return CDEV_SUCCESS;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * MonitorTestAttrib::setControlHigh :
|
||||
// * This method allows the caller to set the maximum value for a device.
|
||||
// *****************************************************************************
|
||||
int MonitorTestAttrib::setControlHigh ( double ControlHigh )
|
||||
{
|
||||
if(controlHigh != ControlHigh)
|
||||
{
|
||||
controlHigh = ControlHigh;
|
||||
checkAlarms();
|
||||
if(monitors && monitors->isMonitored())
|
||||
{
|
||||
cdevData data;
|
||||
getAllToData(&data);
|
||||
monitors->fireMonitor(CONTROLHIGH_TAG, &data);
|
||||
}
|
||||
}
|
||||
return CDEV_SUCCESS;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * MonitorTestAttrib::setControlLow :
|
||||
// * This method allows the caller to set the minimum value of a device.
|
||||
// *****************************************************************************
|
||||
int MonitorTestAttrib::setControlLow ( double ControlLow )
|
||||
{
|
||||
if(controlLow != ControlLow)
|
||||
{
|
||||
controlLow = ControlLow;
|
||||
checkAlarms();
|
||||
if(monitors && monitors->isMonitored())
|
||||
{
|
||||
cdevData data;
|
||||
getAllToData(&data);
|
||||
monitors->fireMonitor(CONTROLLOW_TAG, &data);
|
||||
}
|
||||
}
|
||||
return CDEV_SUCCESS;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * MonitorTestAttrib::checkAlarms :
|
||||
// * This method allows the caller to read the value in comparison with all
|
||||
// * of its limits and set the status and severity tag appropriately.
|
||||
// *****************************************************************************
|
||||
void MonitorTestAttrib::checkAlarms ( void )
|
||||
{
|
||||
int done = 0;
|
||||
if(controlHigh>controlLow)
|
||||
{
|
||||
if(value<controlLow)
|
||||
{
|
||||
setStatus("OUT OF RANGE LOW");
|
||||
setSeverity("ERROR");
|
||||
done = 1;
|
||||
}
|
||||
else if (value>controlHigh)
|
||||
{
|
||||
setStatus("OUT OF RANGE HIGH");
|
||||
setSeverity("ERROR");
|
||||
done = 1;
|
||||
}
|
||||
}
|
||||
if(!done && alarmHigh>alarmLow)
|
||||
{
|
||||
if(value<alarmLow)
|
||||
{
|
||||
setStatus("ALARM LOW");
|
||||
setSeverity("ALARM");
|
||||
done = 1;
|
||||
}
|
||||
else if (value>alarmHigh)
|
||||
{
|
||||
setStatus("ALARM HIGH");
|
||||
setSeverity("ALARM");
|
||||
done = 1;
|
||||
}
|
||||
}
|
||||
if(!done && warningHigh>warningLow)
|
||||
{
|
||||
if(value<warningLow)
|
||||
{
|
||||
setStatus("WARNING LOW");
|
||||
setSeverity("WARNING");
|
||||
done = 1;
|
||||
}
|
||||
else if (value>warningHigh)
|
||||
{
|
||||
setStatus("WARNING HIGH");
|
||||
setSeverity("WARNING");
|
||||
done = 1;
|
||||
}
|
||||
}
|
||||
if(!done)
|
||||
{
|
||||
setStatus("NORMAL");
|
||||
setSeverity("\0");
|
||||
}
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * MonitorTestAttrib::insertMonitor :
|
||||
// * This message adds a monitor to the cdevMonitorTable for this device/
|
||||
// * attribute pair. The message parameter becomes the property of the
|
||||
// * monitorTable and should not be accessed again by the caller.
|
||||
// *****************************************************************************
|
||||
void MonitorTestAttrib::insertMonitor ( cdevMonitorTable * table, cdevMessage * message )
|
||||
{
|
||||
if(table!=NULL && message!=NULL)
|
||||
{
|
||||
cdevData data;
|
||||
getAllToData(&data);
|
||||
table->insertMonitor(message, &data);
|
||||
monitors = table->findMonitor(device, attrib);
|
||||
if(monitors && !monitors->isMonitored()) monitors = NULL;
|
||||
}
|
||||
else if(message!=NULL) delete message;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * MonitorTestAttrib::removeMonitor:
|
||||
// * This method uses the cancelTransIdx to locate and delete a monitor
|
||||
// * that was previously posted using that transaction index.
|
||||
// *****************************************************************************
|
||||
void MonitorTestAttrib::removeMonitor (cdevMonitorTable * table, cdevMessage * message )
|
||||
{
|
||||
if(table!=NULL && message!=NULL)
|
||||
{
|
||||
table->removeMonitor(message);
|
||||
if(monitors && !monitors->isMonitored()) monitors = NULL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
#ifndef _VIRTUAL_ATTRIB_H_
|
||||
#define _VIRTUAL_ATTRIB_H_ 1
|
||||
|
||||
#include <cdevData.h>
|
||||
#include <MonitorTestServer.h>
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * class MonitorTestAttrib:
|
||||
// * This class maintains a list of items that make-up a MonitorTest Attrib. And
|
||||
// * access mechanisms.
|
||||
// *****************************************************************************
|
||||
class MonitorTestAttrib
|
||||
{
|
||||
private:
|
||||
char * device;
|
||||
char * attrib;
|
||||
cdevMonitorNode * monitors;
|
||||
|
||||
double value;
|
||||
char status [255];
|
||||
char severity[255];
|
||||
char units [255];
|
||||
double alarmHigh;
|
||||
double alarmLow;
|
||||
double warningHigh;
|
||||
double warningLow;
|
||||
double controlHigh;
|
||||
double controlLow;
|
||||
|
||||
int resultCode;
|
||||
public:
|
||||
MonitorTestAttrib (char * Device, char * Attrib);
|
||||
~MonitorTestAttrib ( void );
|
||||
|
||||
int setFromData ( cdevData * data );
|
||||
void getToData ( cdevData * data, cdevData * context = NULL );
|
||||
void getAllToData ( cdevData * data );
|
||||
|
||||
int setValue ( double Value );
|
||||
int setStatus ( char * Status );
|
||||
int setSeverity ( char * Severity );
|
||||
int setUnits ( char * Units );
|
||||
int setAlarmHigh ( double AlarmHigh );
|
||||
int setAlarmLow ( double AlarmLow );
|
||||
int setWarningHigh ( double WarningHigh );
|
||||
int setWarningLow ( double WarningLow );
|
||||
int setControlHigh ( double ControlHigh );
|
||||
int setControlLow ( double ControlLow );
|
||||
void checkAlarms ( void );
|
||||
|
||||
double getValue ( void ) { return value; }
|
||||
char * getStatus ( void ) { return status; }
|
||||
char * getSeverity ( void ) { return severity; }
|
||||
char * getUnits ( void ) { return units; }
|
||||
double getAlarmHigh ( void ) { return alarmHigh; }
|
||||
double getAlarmLow ( void ) { return alarmLow; }
|
||||
double getWarningHigh ( void ) { return warningHigh; }
|
||||
double getWarningLow ( void ) { return warningLow; }
|
||||
double getControlHigh ( void ) { return controlHigh; }
|
||||
double getControlLow ( void ) { return controlLow; }
|
||||
int getResultCode ( void ) { return resultCode; }
|
||||
|
||||
void insertMonitor ( cdevMonitorTable * table, cdevMessage * message );
|
||||
void removeMonitor ( cdevMonitorTable * table, cdevMessage * message );
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,174 @@
|
||||
#include <MonitorTestServer.h>
|
||||
#include <MonitorTestAttrib.h>
|
||||
|
||||
// *****************************************************************************
|
||||
// * This has to be added in order to support the CenterLine Compiler.
|
||||
// *****************************************************************************
|
||||
#if defined (__CENTERLINE__)
|
||||
long va_alist;
|
||||
#endif
|
||||
|
||||
MonitorTestServer::~MonitorTestServer ( void )
|
||||
{
|
||||
StringHashIterator iter(&attribHash);
|
||||
MonitorTestAttrib * attrib = NULL;
|
||||
char * key = NULL;
|
||||
|
||||
iter.first();
|
||||
while((key=iter.key())!=NULL)
|
||||
{
|
||||
attrib = (MonitorTestAttrib *)iter.data();
|
||||
iter++;
|
||||
attribHash.remove(key);
|
||||
if(attrib!=NULL) delete attrib;
|
||||
}
|
||||
}
|
||||
|
||||
void MonitorTestServer::populateTable ( void )
|
||||
{
|
||||
char device[10];
|
||||
char attrib[10];
|
||||
char key[20];
|
||||
for(int i=0; i<10; i++)
|
||||
{
|
||||
for(int j=0; j<10; j++)
|
||||
{
|
||||
sprintf(device, "device%i", i);
|
||||
sprintf(attrib, "attrib%i", j);
|
||||
sprintf(key, "device%i attrib%i", i, j);
|
||||
attribHash.insert(key, new MonitorTestAttrib(device, attrib));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MonitorTestServer::processMessages ( void )
|
||||
{
|
||||
char key[255];
|
||||
int saveMessageFlag;
|
||||
int sendMessageFlag;
|
||||
cdevMessage * message;
|
||||
MonitorTestAttrib * attrib;
|
||||
cdevData output;
|
||||
|
||||
while(dequeue(message)==0)
|
||||
{
|
||||
// *************************************************************
|
||||
// * Note at this point a cdevTagMap has already been received
|
||||
// * from the client. This tag map will have initialized all
|
||||
// * of the tags that are required by the service.
|
||||
// *************************************************************
|
||||
if(!strcmp(message->getMessage(), "unregister"))
|
||||
{
|
||||
sendMessageFlag = 0;
|
||||
removeClientMonitors(message->getClientID());
|
||||
}
|
||||
if(!strncmp(message->getMessage(), "get ", 4))
|
||||
{
|
||||
output.remove();
|
||||
saveMessageFlag = 0;
|
||||
sendMessageFlag = 1;
|
||||
|
||||
sprintf(key, "%s %s",
|
||||
message->getDeviceList()[0],
|
||||
&message->getMessage()[4]);
|
||||
|
||||
if((attrib = (MonitorTestAttrib *)attribHash.find(key))!=NULL)
|
||||
{
|
||||
attrib->getToData(&output, message->getContext());
|
||||
output.insert("resultCode", CDEV_SUCCESS);
|
||||
}
|
||||
else output.insert("resultCode", CDEV_NOTFOUND);
|
||||
}
|
||||
else if(!strncmp(message->getMessage(), "set ", 4))
|
||||
{
|
||||
output.remove();
|
||||
saveMessageFlag = 0;
|
||||
sendMessageFlag = 1;
|
||||
|
||||
sprintf(key, "%s %s",
|
||||
message->getDeviceList()[0],
|
||||
&message->getMessage()[4]);
|
||||
|
||||
if((attrib = (MonitorTestAttrib *)attribHash.find(key))!=NULL)
|
||||
{
|
||||
output.insert("resultCode",
|
||||
attrib->setFromData(message->getData()));
|
||||
}
|
||||
else output.insert("resultCode", CDEV_NOTFOUND);
|
||||
}
|
||||
else if(!strncmp(message->getMessage(), "monitorOn ", 10))
|
||||
{
|
||||
saveMessageFlag = 1;
|
||||
sendMessageFlag = 0;
|
||||
|
||||
sprintf(key, "%s %s",
|
||||
message->getDeviceList()[0],
|
||||
&message->getMessage()[10]);
|
||||
|
||||
if((attrib = (MonitorTestAttrib *)attribHash.find(key))!=NULL)
|
||||
{
|
||||
attrib->insertMonitor(this, message);
|
||||
}
|
||||
}
|
||||
else if(!strncmp(message->getMessage(), "monitorOff ", 11))
|
||||
{
|
||||
saveMessageFlag = 0;
|
||||
sendMessageFlag = 1;
|
||||
|
||||
sprintf(key, "%s %s",
|
||||
message->getDeviceList()[0],
|
||||
&message->getMessage()[11]);
|
||||
|
||||
if((attrib = (MonitorTestAttrib *)attribHash.find(key))!=NULL)
|
||||
{
|
||||
attrib->removeMonitor(this, message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
saveMessageFlag = 0;
|
||||
sendMessageFlag = 1;
|
||||
output.insert("resultCode", CDEV_NOTFOUND);
|
||||
}
|
||||
|
||||
if(sendMessageFlag)
|
||||
{
|
||||
message->setData(&output, 1);
|
||||
enqueue(message);
|
||||
}
|
||||
if(!saveMessageFlag) delete message;
|
||||
}
|
||||
}
|
||||
|
||||
int MonitorTestServer::fireCallback ( cdevMessage * message )
|
||||
{
|
||||
int result = CDEV_SUCCESS;
|
||||
cdevData * data = NULL;
|
||||
|
||||
if(message && (data = message->getData())!=NULL)
|
||||
{
|
||||
data->insert("resultCode", CDEV_SUCCESS);
|
||||
result = enqueue(message);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
fprintf(stdout, "\n\
|
||||
=> **********************************************************************\n\
|
||||
=> * This is a test server that is used to test the Monitoring *\n\
|
||||
=> * capabilities of the cdevGenericServer engine. This server will be *\n\
|
||||
=> * contacted with a list of monitor requests to which it will respond *\n\
|
||||
=> **********************************************************************\n\n");
|
||||
fflush(stdout);
|
||||
|
||||
char * name = "MonitorTestServer";
|
||||
|
||||
if(argc>1) name = argv[1];
|
||||
|
||||
MonitorTestServer server("MONITOR_TEST", name, 0, 60);
|
||||
cdevServer::runServer();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef _VIRTUAL_SERVER_H_
|
||||
#define _VIRTUAL_SERVER_H_ 1
|
||||
|
||||
#include <cdevServer.h>
|
||||
#include <StringHash.h>
|
||||
#include <cdevMonitorTable.h>
|
||||
|
||||
// *****************************************************************************
|
||||
// * class MonitorTestServer :
|
||||
// * This is the server class for the MonitorTestDevice. It simply receives
|
||||
// * messages from a client and immediately returns them.
|
||||
// *
|
||||
// * The constructor passes the domain, server, port and rate to the
|
||||
// * underlying cdevServer class to be processed. The cdevServer constructor
|
||||
// * will add this server to the Name Server and will begin processing
|
||||
// * messages when the cdevServer::runServer() method is executed.
|
||||
// *
|
||||
// * The processMessages method is the servers interface to the world... Each
|
||||
// * time a complete message is received or the time specified in rate
|
||||
// * expires, that method will be called.
|
||||
// *****************************************************************************
|
||||
class MonitorTestServer : public cdevServer, public cdevMonitorTable
|
||||
{
|
||||
private:
|
||||
StringHash attribHash;
|
||||
|
||||
public:
|
||||
MonitorTestServer ( char * domain, char * server, unsigned int port, double pulse )
|
||||
: cdevServer(domain, server, port, pulse), attribHash()
|
||||
{
|
||||
populateTable();
|
||||
}
|
||||
|
||||
virtual ~MonitorTestServer ( void );
|
||||
virtual void processMessages ( void );
|
||||
void populateTable ( void );
|
||||
virtual int fireCallback ( cdevMessage * message );
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,60 @@
|
||||
#include <MonitorTestService.h>
|
||||
|
||||
// *****************************************************************************
|
||||
// * newMonitorTestService:
|
||||
// * This function will be called by the cdevSystem object to create an
|
||||
// * initial instance of the MonitorTestService.
|
||||
// *****************************************************************************
|
||||
extern "C" cdevService * newMonitorTestService (char * name, cdevSystem * system)
|
||||
{
|
||||
return new MonitorTestService(name, *system);
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * MonitorTestService::MonitorTestService :
|
||||
// * This is teh constructor for the MonitorTestService. It initializes the
|
||||
// * underlying cdevClientService by specifying that it is in the domain of
|
||||
// * VIRTUAL.
|
||||
// *****************************************************************************
|
||||
MonitorTestService::MonitorTestService ( char * name, cdevSystem & system)
|
||||
: cdevClientService("MONITOR_TEST", name, system)
|
||||
{
|
||||
// *********************************************************************
|
||||
// * Install the RESULT_CODE_TAG at a location of 30 or higher if it
|
||||
// * does not already exist.
|
||||
// *********************************************************************
|
||||
RESULT_CODE_TAG = 0;
|
||||
cdevData::tagC2I("resultCode", &RESULT_CODE_TAG);
|
||||
|
||||
for(int i=30; RESULT_CODE_TAG==0 && i<65534; i++)
|
||||
{
|
||||
cdevData::insertTag(i, "resultCode");
|
||||
cdevData::tagC2I("resultCode", &RESULT_CODE_TAG);
|
||||
}
|
||||
|
||||
system.reportError(CDEV_SEVERITY_INFO, "MonitorTestService", NULL,
|
||||
"Constructing a new MonitorTestService");
|
||||
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * MonitorTestService::fireCallback :
|
||||
// * This is the method that will be called to dispatch the callback methods
|
||||
// * that are associated with the calls to the MonitorTest Server. If the
|
||||
// * message has been processed successfully, then the method will remove
|
||||
// * the resultCode from the outbound data and use that as the status.
|
||||
// *****************************************************************************
|
||||
void MonitorTestService::fireCallback ( int status, cdevTranObj &xobj, cdevData *resultData, int partialTransaction )
|
||||
{
|
||||
// *********************************************************************
|
||||
// * If the message was transmitted successfully, get the result code
|
||||
// * from the data that was returned and use that as the status.
|
||||
// *********************************************************************
|
||||
if(status==CDEV_SUCCESS && resultData!=NULL)
|
||||
{
|
||||
resultData->get(RESULT_CODE_TAG, &status);
|
||||
resultData->remove(RESULT_CODE_TAG);
|
||||
}
|
||||
|
||||
cdevClientService::fireCallback(status, xobj, resultData, partialTransaction);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#include <cdevClientService.h>
|
||||
|
||||
#ifndef MONITOR_TEST_SERVICE_API
|
||||
#define MONITOR_TEST_SERVICE_API
|
||||
#endif
|
||||
|
||||
// *****************************************************************************
|
||||
// * newMonitorTestService :
|
||||
// * This function will be called by the cdevSystem object to create an
|
||||
// * initial instance of the MonitorTestService.
|
||||
// *****************************************************************************
|
||||
extern "C" MONITOR_TEST_SERVICE_API cdevService * newMonitorTestService ( char * name, cdevSystem * system );
|
||||
|
||||
// *****************************************************************************
|
||||
// * class MonitorTestService :
|
||||
// * This class simply inherits from the cdevClientService and must define
|
||||
// * only a constructor and destructor.
|
||||
// *****************************************************************************
|
||||
class MonitorTestService : public cdevClientService
|
||||
{
|
||||
public:
|
||||
MonitorTestService ( char * name, cdevSystem & system = cdevSystem::defaultSystem());
|
||||
|
||||
protected:
|
||||
int RESULT_CODE_TAG;
|
||||
|
||||
virtual ~MonitorTestService ( void ) {};
|
||||
virtual void fireCallback ( int status, cdevTranObj &xobj, cdevData *resultData, int partialTransaction = 0 );
|
||||
};
|
||||
@@ -0,0 +1,65 @@
|
||||
#include <cdevPlatforms.h>
|
||||
#include <cdevSystem.h>
|
||||
#include <cdevRequestObject.h>
|
||||
#include <cdevDevice.h>
|
||||
#include <cdevGroup.h>
|
||||
#include <cdevCommon.h>
|
||||
|
||||
int callbackCount = 0;
|
||||
|
||||
const int DEVICE_COUNT = 9;
|
||||
const int MESSAGE_COUNT = 9;
|
||||
|
||||
int main ( )
|
||||
{
|
||||
fprintf(stdout, "\n\
|
||||
=> **********************************************************************\n\
|
||||
=> * This is the writing side of a two part monitoring test program. *\n\
|
||||
=> * This program will set up a list of devices and attributes and *\n\
|
||||
=> * will modify them at a regular rate. *\n\
|
||||
=> **********************************************************************\n\n");
|
||||
fflush(stdout);
|
||||
cdevDevice * deviceList[DEVICE_COUNT];
|
||||
cdevRequestObject * reqList[DEVICE_COUNT*MESSAGE_COUNT];
|
||||
cdevData data;
|
||||
float values[DEVICE_COUNT*MESSAGE_COUNT];
|
||||
char msg[255];
|
||||
int deviceCnt;
|
||||
int msgCnt;
|
||||
|
||||
// *********************************************************************
|
||||
// * First get all of the values from the devices.
|
||||
// *********************************************************************
|
||||
for(deviceCnt=0; deviceCnt<DEVICE_COUNT; deviceCnt++)
|
||||
{
|
||||
sprintf(msg, "device%i", deviceCnt);
|
||||
deviceList[deviceCnt] = cdevDevice::attachPtr(msg);
|
||||
|
||||
for(msgCnt=0; msgCnt<MESSAGE_COUNT; msgCnt++)
|
||||
{
|
||||
sprintf(msg, "get attrib%i", msgCnt);
|
||||
if(deviceList[deviceCnt]->send(msg, NULL, data)==CDEV_SUCCESS)
|
||||
{
|
||||
data.get("value", &values[deviceCnt*MESSAGE_COUNT+msgCnt]);
|
||||
}
|
||||
else {
|
||||
values[deviceCnt*MESSAGE_COUNT+msgCnt] = 0;
|
||||
fprintf(stdout, "ERROR : device %s : %s failed\n", deviceList[deviceCnt]->name(), msg);
|
||||
}
|
||||
sprintf(msg, "set attrib%i", msgCnt);
|
||||
reqList[deviceCnt*MESSAGE_COUNT+msgCnt] = deviceList[deviceCnt]->getRequestObject(msg);
|
||||
}
|
||||
}
|
||||
|
||||
while(1)
|
||||
{
|
||||
for(int i=0; i<DEVICE_COUNT*MESSAGE_COUNT; i++)
|
||||
{
|
||||
values[i]+=1.0;
|
||||
data.insert("value", values[i]);
|
||||
reqList[i]->sendNoBlock(data, NULL);
|
||||
}
|
||||
cdevSystem::defaultSystem().pend();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
.SUFFIXES: .cc .obj
|
||||
|
||||
APPNAME = Client/Server Monitor Test
|
||||
ARCH = WINNT-4.0
|
||||
SHOBJ = YES
|
||||
|
||||
BINARIES = $(BASEBIN)\MonitorTestServer.exe \
|
||||
$(CDEVLIB)\MonitorTestService.dll \
|
||||
$(CDEVLIB)\MonitorTestService.lib \
|
||||
$(BASEBIN)\MonitorTest.exe \
|
||||
$(BASEBIN)\MonitorReader.exe \
|
||||
$(BASEBIN)\MonitorOffTest.exe \
|
||||
$(BASEBIN)\MonitorWriter.exe \
|
||||
$(BASEBIN)\DefaultServerTest.exe
|
||||
|
||||
include ..\..\include\makeinclude\Makefile.WINNT-4.0
|
||||
|
||||
CXXINCLUDES = /I .\\
|
||||
CXXEXTRA_DLL = /D "MONITOR_TEST_SERVICE_API=__declspec(dllexport)"
|
||||
CXXEXTRA_LIB = /D "MONITOR_TEST_SERVICE_API="
|
||||
|
||||
!IF "$(SHOBJ)" == "YES"
|
||||
TARGETS = $(BASEBIN)\MonitorTestServer.exe \
|
||||
$(CDEVLIB)\MonitorTestService.dll \
|
||||
$(BASEBIN)\MonitorTest.exe \
|
||||
$(BASEBIN)\MonitorReader.exe \
|
||||
$(BASEBIN)\MonitorOffTest.exe \
|
||||
$(BASEBIN)\MonitorWriter.exe \
|
||||
$(BASEBIN)\DefaultServerTest.exe
|
||||
!ELSE
|
||||
TARGETS = $(BASEBIN)\MonitorTestServer.exe \
|
||||
$(CDEVLIB)\MonitorTestService.lib \
|
||||
$(BASEBIN)\MonitorTest.exe \
|
||||
$(BASEBIN)\MonitorReader.exe \
|
||||
$(BASEBIN)\MonitorOffTest.exe \
|
||||
$(BASEBIN)\MonitorWriter.exe \
|
||||
$(BASEBIN)\DefaultServerTest.exe
|
||||
!ENDIF
|
||||
|
||||
targets : $(TARGETS)
|
||||
|
||||
$(CDEVLIB)\MonitorTestService.dll : $(OBJDIR)\MonitorTestService.obj
|
||||
@echo ^ ^ ^ =^> Linking $(@F)
|
||||
-@if exist $@ erase $@
|
||||
-@if not exist $(@D) mkdir $(@D)
|
||||
@$(LIB32) $(CDEVLIB)\cdev.lib $(CDEVLIB)\cdevGenericServer.lib\
|
||||
$(LINK_DLL_FLAGS) /out:$@ /implib:$(@D)\$(@B).lib $?
|
||||
-@copy $@ $(CDEVSHOBJ)\$(CDEVVERSION)\$(@F) > nul
|
||||
@echo ^ ^ ^ ^ ^ ^ Done...
|
||||
|
||||
$(CDEVLIB)\MonitorTestService.lib : $(OBJDIR)\MonitorTestService.obj
|
||||
@echo ^ ^ ^ =^> Linking $(@F)
|
||||
-@if exist $@ erase $@
|
||||
-@if not exist $(@D) mkdir $(@D)
|
||||
@$(LIB32) $(CDEVLIB)\cdev.lib $(CDEVLIB)\cdevGenericServer.lib\
|
||||
$(LINK_LIB_FLAGS) /out:$@ $?
|
||||
@echo ^ ^ ^ ^ ^ ^ Done...
|
||||
|
||||
$(BASEBIN)\MonitorTestServer.exe : .exec\$(TARGETDIR)\MonitorTestServer.obj $(OBJDIR)\MonitorTestAttrib.obj
|
||||
-@if exist $@ erase $@
|
||||
@echo ^ ^ ^ ^ ^ ^ =^> Linking $(@F)
|
||||
$(LINK) $(CDEVLIB)\cdev.lib $(CDEVLIB)\cdevGenericServer.lib \
|
||||
$(LINK_EXE_FLAGS) /out:$@ $?
|
||||
@echo ^ ^ ^ ^ ^ ^ ^ ^ ^ Done...
|
||||
|
||||
$(BASEBIN)\MonitorTest.exe : .exec\$(TARGETDIR)\MonitorTest.obj
|
||||
-@if exist $@ erase $@
|
||||
@echo ^ ^ ^ ^ ^ ^ =^> Linking $(@F)
|
||||
$(LINK) $(CDEVLIB)\cdev.lib $(CDEVLIB)\cdevGenericServer.lib \
|
||||
$(LINK_EXE_FLAGS) /out:$@ $?
|
||||
@echo ^ ^ ^ ^ ^ ^ ^ ^ ^ Done...
|
||||
|
||||
$(BASEBIN)\MonitorReader.exe : .exec\$(TARGETDIR)\MonitorReader.obj
|
||||
-@if exist $@ erase $@
|
||||
@echo ^ ^ ^ ^ ^ ^ =^> Linking $(@F)
|
||||
$(LINK) $(CDEVLIB)\cdev.lib $(CDEVLIB)\cdevGenericServer.lib \
|
||||
$(LINK_EXE_FLAGS) /out:$@ $?
|
||||
@echo ^ ^ ^ ^ ^ ^ ^ ^ ^ Done...
|
||||
|
||||
$(BASEBIN)\MonitorOffTest.exe : .exec\$(TARGETDIR)\MonitorOffTest.obj
|
||||
-@if exist $@ erase $@
|
||||
@echo ^ ^ ^ ^ ^ ^ =^> Linking $(@F)
|
||||
$(LINK) $(CDEVLIB)\cdev.lib $(CDEVLIB)\cdevGenericServer.lib \
|
||||
$(LINK_EXE_FLAGS) /out:$@ $?
|
||||
@echo ^ ^ ^ ^ ^ ^ ^ ^ ^ Done...
|
||||
|
||||
$(BASEBIN)\MonitorWriter.exe : .exec\$(TARGETDIR)\MonitorWriter.obj
|
||||
-@if exist $@ erase $@
|
||||
@echo ^ ^ ^ ^ ^ ^ =^> Linking $(@F)
|
||||
$(LINK) $(CDEVLIB)\cdev.lib $(CDEVLIB)\cdevGenericServer.lib \
|
||||
$(LINK_EXE_FLAGS) /out:$@ $?
|
||||
@echo ^ ^ ^ ^ ^ ^ ^ ^ ^ Done...
|
||||
|
||||
$(BASEBIN)\DefaultServerTest.exe : .exec\$(TARGETDIR)\DefaultServerTest.obj
|
||||
-@if exist $@ erase $@
|
||||
@echo ^ ^ ^ ^ ^ ^ =^> Linking $(@F)
|
||||
$(LINK) $(CDEVLIB)\cdev.lib $(CDEVLIB)\cdevGenericServer.lib \
|
||||
$(LINK_EXE_FLAGS) /out:$@ $?
|
||||
@echo ^ ^ ^ ^ ^ ^ ^ ^ ^ Done...
|
||||
|
||||
Reference in New Issue
Block a user