cdev-1.7.2n

This commit is contained in:
2022-12-13 12:44:04 +01:00
commit b3b88fc333
1357 changed files with 338883 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
DIRS = Reflector VirtualService
all:
@for dir in $(DIRS); \
do \
$(MAKE) -C $$dir; \
done
clean:
@for dir in $(DIRS); \
do \
$(MAKE) -C $$dir clean; \
done
purge:
@for dir in $(DIRS); \
do \
$(MAKE) -C $$dir purge; \
done

View File

@@ -0,0 +1,8 @@
BASEDIR = $(MAKEDIR)
DIRS = $(BASEDIR)\Reflector\
$(BASEDIR)\VirtualService
notarget: all
all clean purge:
@for %d in ($(DIRS)) do @if exist %d cd %d & $(MAKE) /NOLOGO $@ /f NMakefile.mak

View File

@@ -0,0 +1,32 @@
ARCH = OS
SHOBJ = YES
include ../../include/makeinclude/Makefile.$(ARCH)
APPNAME = "Reflector Client/Server Example"
CXXINCLUDES = -I./
SO_SRCS = ReflectorService.cc
SO_LIBS = -L$(CDEVLIB) -lcdevGenericServer $(OSLIBS)
LIBS = -L$(CDEVLIB) -lcdevGenericServer $(CDEVLIBS) $(ACELIBS) $(OSLIBS)
ifeq ($(SHOBJ), YES)
TARGETS = $(BASELIB)/ReflectorService.so $(BASEBIN)/ReflectorServer
else
TARGETS = $(BASELIB)/libReflectorService.a $(BASEBIN)/ReflectorServer
endif
targets : $(TARGETS)
$(BASEBIN)/ReflectorServer : $(OBJDIR)/ReflectorServer.o
$(LINK.cc) $^ $(LIBS) -o $@
$(BASELIB)/ReflectorService.so : $(OBJDIR)/ReflectorService.o
$(LINK.so) -o $@ $^ -L$(CDEVLIB) -lcdevGenericServer $(OSLIBS)
@mkdir -p $(CDEVSHOBJ)/$(CDEVVERSION)
@cp $@ $(CDEVSHOBJ)/$(CDEVVERSION)/$(@F)
$(BASELIB)/libReflectorService.a : $(OBJDIR)/ReflectorService.o
$(LINK.a) $@ $(OBJDIR)/ReflectorService.o
@$(RANLIB) $@ > /dev/null

View File

@@ -0,0 +1,51 @@
.SUFFIXES: .cc .obj
APPNAME = Reflector Client/Server Example
ARCH = WINNT-4.0
SHOBJ = YES
BINARIES = $(BASEBIN)\ReflectorServer.exe \
$(CDEVLIB)\ReflectorService.dll \
$(CDEVLIB)\ReflectorService.lib
include ..\..\include\makeinclude\Makefile.WINNT-4.0
CXXINCLUDES = /I .\\
CXXEXTRA_DLL = /D "REFLECTOR_SERVICE_API=__declspec(dllexport)"
CXXEXTRA_LIB = /D "REFLECTOR_SERVICE_API="
!IF "$(SHOBJ)" == "YES"
TARGETS = $(BASEBIN)\ReflectorServer.exe \
$(CDEVLIB)\ReflectorService.dll
!ELSE
TARGETS = $(BASEBIN)\ReflectorServer.exe \
$(CDEVLIB)\ReflectorService.lib
!ENDIF
targets : $(TARGETS)
$(CDEVLIB)\ReflectorService.dll : $(OBJDIR)\ReflectorService.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)\ReflectorService.lib : $(OBJDIR)\ReflectorService.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)\ReflectorServer.exe : .exec\$(TARGETDIR)\ReflectorServer.obj
-@if exist $@ erase $@
@echo ^ ^ ^ ^ ^ ^ =^> Linking $(@F)
$(LINK) $(CDEVLIB)\cdev.lib $(CDEVLIB)\cdevGenericServer.lib \
$(LINK_EXE_FLAGS) /out:$@ $?
@echo ^ ^ ^ ^ ^ ^ ^ ^ ^ Done...

View File

@@ -0,0 +1,33 @@
service Reflector
{
tags {server}
}
class Reflectors
{
verbs {get, set}
attributes
{
default Reflector;
clientID Reflector;
servers Reflector;
connections Reflector;
attrib1 Reflector {server=TestServerX};
attrib2 Reflector {server=TestServerX};
attrib3 Reflector {server=TestServerX};
attrib4 Reflector {server=TestServerX};
attrib5 Reflector {server=TestServerX};
attrib6 Reflector {server=TestServerX};
}
messages
{
shutdown Reflector;
}
}
Reflectors :
device1,
device2,
device3
;

View File

@@ -0,0 +1,45 @@
#include <cdevServer.h>
// *****************************************************************************
// * class ReflectorServer :
// * This is the server class for the reflector. 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 ReflectorServer : public cdevServer
{
public:
ReflectorServer ( char * domain, char * server, unsigned int port, double pulse )
: cdevServer(domain, server, port, pulse)
{
}
virtual void processMessages ( void )
{
cdevMessage * message;
while(dequeue(message)==0)
{
// message->asciiDump();
enqueue(message);
delete message;
}
}
};
int main()
{
ReflectorServer server("REFLECTOR", "TestServerX", 0, 60);
cdevServer::runServer();
return 0;
}

View File

@@ -0,0 +1,24 @@
#include <ReflectorService.h>
// *****************************************************************************
// * newReflectorService:
// * This function will be called by the cdevSystem object to create an
// * initial instance of the ReflectorService.
// *****************************************************************************
extern "C" cdevService * newReflectorService (char * name, cdevSystem * system)
{
return new ReflectorService(name, *system);
}
// *****************************************************************************
// * ReflectorService::ReflectorService :
// * This is teh constructor for the ReflectorService. It initializes the
// * underlying cdevClientService by specifying that it is in the domain of
// * REFLECTOR.
// *****************************************************************************
ReflectorService::ReflectorService ( char * name, cdevSystem & system)
: cdevClientService("REFLECTOR", name, system)
{
system.reportError(CDEV_SEVERITY_INFO, "ReflectorService", NULL,
"Constructing a new ReflectorService");
}

View File

@@ -0,0 +1,26 @@
#include <cdevClientService.h>
#ifndef REFLECTOR_SERVICE_API
#define REFLECTOR_SERVICE_API
#endif
// *****************************************************************************
// * newReflectorService :
// * This function will be called by the cdevSystem object to create an
// * initial instance of the ReflectorService.
// *****************************************************************************
extern "C" REFLECTOR_SERVICE_API cdevService * newReflectorService ( char * name, cdevSystem * system );
// *****************************************************************************
// * class ReflectorService :
// * This class simply inherits from the cdevClientService and must define
// * only a constructor and destructor.
// *****************************************************************************
class ReflectorService : public cdevClientService
{
public:
ReflectorService ( char * name, cdevSystem & system = cdevSystem::defaultSystem());
protected:
virtual ~ReflectorService ( void ) {};
};

View File

@@ -0,0 +1,46 @@
#! /bin/csh
if ( $?CDEV == 0 ) then
echo "CDEV Environment Variable is NOT Defined"
exit 0
endif
if ( $?CDEVDDL ) then
setenv OLDCDEVDDL $CDEVDDL
endif
setenv CDEVDDL `pwd`/Reflector.ddl
echo "-------------------------------------------------------------------------"
echo " This test will send a collection of packets to the Reflector Server... "
echo " The Server should return the same data to the client unmodified. "
echo "-------------------------------------------------------------------------"
cdevUtil "debug on" \
"device1 get attrib1 value=0 status=1 controlHigh=2 controlLow=3 alarmHigh=4 alarmLow=5" \
"device1 get attrib2 value=10 status=11 controlHigh=12 controlLow=13 alarmHigh=14 alarmLow=15" \
"device1 get attrib3 value=20 status=21 controlHigh=22 controlLow=23 alarmHigh=24 alarmLow=25" \
"device1 get attrib4 value=30 status=31 controlHigh=32 controlLow=33 alarmHigh=34 alarmLow=35" \
"device1 get attrib5 value=40 status=41 controlHigh=42 controlLow=43 alarmHigh=44 alarmLow=45" \
"device1 get attrib6 value=50 status=51 controlHigh=52 controlLow=53 alarmHigh=54 alarmLow=55" \
"device2 get attrib1 value=0 status=1 controlHigh=2 controlLow=3 alarmHigh=4 alarmLow=5" \
"device2 get attrib2 value=10 status=11 controlHigh=12 controlLow=13 alarmHigh=14 alarmLow=15" \
"device2 get attrib3 value=20 status=21 controlHigh=22 controlLow=23 alarmHigh=24 alarmLow=25" \
"device2 get attrib4 value=30 status=31 controlHigh=32 controlLow=33 alarmHigh=34 alarmLow=35" \
"device2 get attrib5 value=40 status=41 controlHigh=42 controlLow=43 alarmHigh=44 alarmLow=45" \
"device2 get attrib6 value=50 status=51 controlHigh=52 controlLow=53 alarmHigh=54 alarmLow=55" \
"device3 get attrib1 value=0 status=1 controlHigh=2 controlLow=3 alarmHigh=4 alarmLow=5" \
"device3 get attrib2 value=10 status=11 controlHigh=12 controlLow=13 alarmHigh=14 alarmLow=15" \
"device3 get attrib3 value=20 status=21 controlHigh=22 controlLow=23 alarmHigh=24 alarmLow=25" \
"device3 get attrib4 value=30 status=31 controlHigh=32 controlLow=33 alarmHigh=34 alarmLow=35" \
"device3 get attrib5 value=40 status=41 controlHigh=42 controlLow=43 alarmHigh=44 alarmLow=45" \
"device3 get attrib6 value=50 status=51 controlHigh=52 controlLow=53 alarmHigh=54 alarmLow=55" \
"quit"
if ( $?OLDCDEVDDL ) then
setenv CDEVDDL $OLDCDEVDDL
endif
echo "-------------------------------------------------------------------------"
echo " End of test..."
echo "-------------------------------------------------------------------------"

View File

@@ -0,0 +1,34 @@
ARCH = OS
SHOBJ = YES
include ../../include/makeinclude/Makefile.$(ARCH)
APPNAME = "Virtual Client/Server Example"
CXXINCLUDES = -I./
SERVER_LIBS = -L$(CDEVLIB) -lcdevGenericServer $(CDEVLIBS) $(ACELIBS) $(OSLIBS)
ifeq ($(SHOBJ), YES)
LIBS = -L$(CDEVLIB) -lcdevGenericServer $(CDEVLIBS) $(OSLIBS)
TARGETS = $(BASELIB)/VirtualService.so $(BASEBIN)/VirtualServer $(BASEBIN)/monitorTest
else
LIBS = -L$(CDEVLIB) -lcdevGenericServer $(CDEVLIBS) $(ACELIBS) $(OSLIBS)
TARGETS = $(BASELIB)/libVirtualService.a $(BASEBIN)/VirtualServer $(BASEBIN)/monitorTest
endif
targets : $(TARGETS)
$(BASEBIN)/VirtualServer : $(OBJDIR)/VirtualServer.o $(OBJDIR)/VirtualAttrib.o
$(LINK.cc) $^ $(SERVER_LIBS) -o $@
$(BASELIB)/VirtualService.so : $(OBJDIR)/VirtualService.o
$(LINK.so) -o $@ $^ -L$(CDEVLIB) -lcdevGenericServer $(OSLIBS)
@mkdir -p $(CDEVSHOBJ)/$(CDEVVERSION)
@cp $@ $(CDEVSHOBJ)/$(CDEVVERSION)/$(@F)
$(BASELIB)/libVirtualService.a : $(OBJDIR)/VirtualService.o
$(LINK.a) $@ $^
@$(RANLIB) $@ > /dev/null
$(BASEBIN)/monitorTest : $(OBJDIR)/monitorTest.o
$(LINK.cc) $^ -o $@ $(LIBS)

View File

@@ -0,0 +1,61 @@
.SUFFIXES: .cc .obj
APPNAME = Virtual Client/Server Example
ARCH = WINNT-4.0
SHOBJ = YES
BINARIES = $(BASEBIN)\VirtualServer.exe \
$(CDEVLIB)\VirtualService.dll \
$(CDEVLIB)\VirtualService.lib \
$(BASEBIN)\monitorTest.exe
include ..\..\include\makeinclude\Makefile.WINNT-4.0
CXXINCLUDES = /I .\\
CXXEXTRA_DLL = /D "VIRTUAL_SERVICE_API=__declspec(dllexport)"
CXXEXTRA_LIB = /D "VIRTUAL_SERVICE_API="
!IF "$(SHOBJ)" == "YES"
TARGETS = $(BASEBIN)\VirtualServer.exe \
$(CDEVLIB)\VirtualService.dll \
$(BASEBIN)\monitorTest.exe
!ELSE
TARGETS = $(BASEBIN)\VirtualServer.exe \
$(CDEVLIB)\VirtualService.lib \
$(BASEBIN)\monitorTest.exe
!ENDIF
targets : $(TARGETS)
$(CDEVLIB)\VirtualService.dll : $(OBJDIR)\VirtualService.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)\VirtualService.lib : $(OBJDIR)\VirtualService.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)\VirtualServer.exe : .exec\$(TARGETDIR)\VirtualServer.obj .exec\$(TARGETDIR)\VirtualAttrib.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...

View File

@@ -0,0 +1,34 @@
service Virtual
{
tags {server}
}
class Virtuals
{
verbs {get, set, monitorOn, monitorOff}
attributes
{
default Virtual;
servers Virtual;
attrib0 Virtual {server=TestServerX};
attrib1 Virtual {server=TestServerX};
attrib2 Virtual {server=TestServerX};
attrib3 Virtual {server=TestServerX};
attrib4 Virtual {server=TestServerX};
attrib5 Virtual {server=TestServerX};
attrib6 Virtual {server=TestServerX};
attrib7 Virtual {server=TestServerX};
attrib8 Virtual {server=TestServerX};
attrib9 Virtual {server=TestServerX};
}
messages
{
disconnect Virtual;
}
}
Virtuals :
device0, device1, device2, device3, device4,
device5, device6, device7, device8, device9
;

View File

@@ -0,0 +1,445 @@
#include <VirtualAttrib.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)
// *****************************************************************************
// * VirtualAttrib::VirtualAttrib :
// * This is the constructor for the VirtualAttrib class. It initializes the
// * internal mechanisms to 0.
// *****************************************************************************
VirtualAttrib::VirtualAttrib ( 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");
}
// *****************************************************************************
// * VirtualAttrib::~VirtualAttrib :
// * This is the destructor for the VirtualAttrib class. It must free the
// * memory associated with the device and attribute names.
// *****************************************************************************
VirtualAttrib::~VirtualAttrib ( void )
{
delete device;
delete attrib;
}
// *****************************************************************************
// * VirtualAttrib::setFromData :
// * This method will populate the VirtualAttrib object with the data contained in
// * the cdevData object.
// *****************************************************************************
int VirtualAttrib::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;
}
// *****************************************************************************
// * VirtualAttrib::getToData :
// * This method will populate the VirtualAttrib object with the data contained in
// * the cdevData object.
// *****************************************************************************
void VirtualAttrib::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());
}
}
}
// *****************************************************************************
// * VirtualAttrib::getAllToData :
// * This method will populate the VirtualAttrib object with the data contained in
// * the cdevData object.
// *****************************************************************************
void VirtualAttrib::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());
}
}
// *****************************************************************************
// * VirtualAttrib::setValue :
// * This method allows the caller to set the value of the Virtual Attrib.
// * This call will fail if the specified value is outside of the legal
// * range.
// *****************************************************************************
int VirtualAttrib::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;
}
// *****************************************************************************
// * VirtualAttrib::setStatus :
// * This method allows the caller to set the status of the device.
// *****************************************************************************
int VirtualAttrib::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;
}
// *****************************************************************************
// * VirtualAttrib::setSeverity :
// * This method allows the caller to set the severity flag for the device.
// *****************************************************************************
int VirtualAttrib::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;
}
// *****************************************************************************
// * VirtualAttrib::setUnits :
// * This method allows the caller to set the units for the device.
// *****************************************************************************
int VirtualAttrib::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;
}
// *****************************************************************************
// * VirtualAttrib::setAlarmHigh :
// * This method allows the caller to set the high alarm value of the device.
// *****************************************************************************
int VirtualAttrib::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;
}
// *****************************************************************************
// * VirtualAttrib::setAlarmLow :
// * This method allows the caller to set the low alarm value of the device.
// *****************************************************************************
int VirtualAttrib::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;
}
// *****************************************************************************
// * VirtualAttrib::setWarningHigh :
// * This method allows the caller to set the high warning value of a device.
// *****************************************************************************
int VirtualAttrib::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;
}
// *****************************************************************************
// * VirtualAttrib::setWarningLow :
// * This method allows the caller to set the low warning value of a device.
// *****************************************************************************
int VirtualAttrib::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;
}
// *****************************************************************************
// * VirtualAttrib::setControlHigh :
// * This method allows the caller to set the maximum value for a device.
// *****************************************************************************
int VirtualAttrib::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;
}
// *****************************************************************************
// * VirtualAttrib::setControlLow :
// * This method allows the caller to set the minimum value of a device.
// *****************************************************************************
int VirtualAttrib::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;
}
// *****************************************************************************
// * VirtualAttrib::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 VirtualAttrib::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");
}
}
// *****************************************************************************
// * VirtualAttrib::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 VirtualAttrib::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;
}
// *****************************************************************************
// * VirtualAttrib::removeMonitor:
// * This method uses the cancelTransIdx to locate and delete a monitor
// * that was previously posted using that transaction index.
// *****************************************************************************
void VirtualAttrib::removeMonitor (cdevMonitorTable * table, cdevMessage * message )
{
if(table!=NULL && message!=NULL)
{
table->removeMonitor(message);
if(monitors && !monitors->isMonitored()) monitors = NULL;
}
}

View File

@@ -0,0 +1,68 @@
#ifndef _VIRTUAL_ATTRIB_H_
#define _VIRTUAL_ATTRIB_H_ 1
#include <cdevData.h>
#include <VirtualServer.h>
// *****************************************************************************
// * class VirtualAttrib:
// * This class maintains a list of items that make-up a Virtual Attrib. And
// * access mechanisms.
// *****************************************************************************
class VirtualAttrib
{
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:
VirtualAttrib (char * Device, char * Attrib);
~VirtualAttrib ( 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

View File

@@ -0,0 +1,158 @@
#include <VirtualServer.h>
#include <VirtualAttrib.h>
// *****************************************************************************
// * This has to be added in order to support the CenterLine Compiler.
// *****************************************************************************
VirtualServer::~VirtualServer ( void )
{
StringHashIterator iter(&attribHash);
VirtualAttrib * attrib = NULL;
char * key = NULL;
iter.first();
while((key=iter.key())!=NULL)
{
attrib = (VirtualAttrib *)iter.data();
iter++;
attribHash.remove(key);
if(attrib!=NULL) delete attrib;
}
}
void VirtualServer::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 VirtualAttrib(device, attrib));
}
}
}
void VirtualServer::processMessages ( void )
{
char key[255];
int saveMessageFlag;
int sendMessageFlag;
cdevMessage * message;
VirtualAttrib * 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 = (VirtualAttrib *)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 = (VirtualAttrib *)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 = (VirtualAttrib *)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 = (VirtualAttrib *)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 VirtualServer::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()
{
VirtualServer server("VIRTUAL", "TestServerX", 0, 60);
cdevServer::runServer();
return 0;
}

View File

@@ -0,0 +1,40 @@
#ifndef _VIRTUAL_SERVER_H_
#define _VIRTUAL_SERVER_H_ 1
#include <cdevServer.h>
#include <StringHash.h>
#include <cdevMonitorTable.h>
// *****************************************************************************
// * class VirtualServer :
// * This is the server class for the VirtualDevice. 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 VirtualServer : public cdevServer, public cdevMonitorTable
{
private:
StringHash attribHash;
public:
VirtualServer ( char * domain, char * server, unsigned int port, double pulse )
: cdevServer(domain, server, port, pulse), attribHash()
{
populateTable();
}
virtual ~VirtualServer ( void );
virtual void processMessages ( void );
void populateTable ( void );
virtual int fireCallback ( cdevMessage * message );
};
#endif

View File

@@ -0,0 +1,60 @@
#include <VirtualService.h>
// *****************************************************************************
// * newVirtualService:
// * This function will be called by the cdevSystem object to create an
// * initial instance of the VirtualService.
// *****************************************************************************
extern "C" cdevService * newVirtualService (char * name, cdevSystem * system)
{
return new VirtualService(name, *system);
}
// *****************************************************************************
// * VirtualService::VirtualService :
// * This is teh constructor for the VirtualService. It initializes the
// * underlying cdevClientService by specifying that it is in the domain of
// * VIRTUAL.
// *****************************************************************************
VirtualService::VirtualService ( char * name, cdevSystem & system)
: cdevClientService("VIRTUAL", 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, "VirtualService", NULL,
"Constructing a new VirtualService");
}
// *****************************************************************************
// * VirtualService::fireCallback :
// * This is the method that will be called to dispatch the callback methods
// * that are associated with the calls to the Virtual 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 VirtualService::fireCallback ( int status, cdevTranObj &xobj, cdevData *resultData )
{
// *********************************************************************
// * 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);
}

View File

@@ -0,0 +1,29 @@
#include <cdevClientService.h>
#ifndef VIRTUAL_SERVICE_API
#define VIRTUAL_SERVICE_API
#endif
// *****************************************************************************
// * newVirtualService :
// * This function will be called by the cdevSystem object to create an
// * initial instance of the VirtualService.
// *****************************************************************************
extern "C" VIRTUAL_SERVICE_API cdevService * newVirtualService ( char * name, cdevSystem * system );
// *****************************************************************************
// * class VirtualService :
// * This class simply inherits from the cdevClientService and must define
// * only a constructor and destructor.
// *****************************************************************************
class VirtualService : public cdevClientService
{
public:
VirtualService ( char * name, cdevSystem & system = cdevSystem::defaultSystem());
protected:
int RESULT_CODE_TAG;
virtual ~VirtualService ( void ) {};
virtual void fireCallback ( int status, cdevTranObj &xobj, cdevData *resultData );
};

View File

@@ -0,0 +1,124 @@
#include <cdevPlatforms.h>
#include <cdevSystem.h>
#include <cdevRequestObject.h>
#include <cdevDevice.h>
#include <cdevGroup.h>
#include <cdevCommon.h>
int lastHitReceived = 0;
int callbackCount = 0;
double totalPeriod = 0.0;
void myCallback1 (int status, void *, cdevRequestObject &, cdevData &)
{
if(status==CDEV_SUCCESS) callbackCount++;
}
void myCallback2 (int status, void *, cdevRequestObject &, cdevData &)
{
if(status==CDEV_SUCCESS)
{
callbackCount++;
lastHitReceived++;
}
}
#define POSTCOUNT 1
#define REPEATCOUNT 2
int main(void)
{
struct timeval first, second, lapsed;
cdevCallback cb1(myCallback1, NULL);
cdevCallback cb2(myCallback2, NULL);
cdevDevice * device[3];
device[0] = cdevDevice::attachPtr("device1");
device[1] = cdevDevice::attachPtr("device2");
device[2] = cdevDevice::attachPtr("device3");
cdevData data;
cdevData context;
int i,j,k;
int done = -2;
double deviceValue[3][3];
char message[255];
context.insert("value", 3);
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
sprintf(message, "get attrib%i", j+1);
device[i]->send(message, NULL, data);
deviceValue[i][j] = (double)data;
}
}
while(done<0)
{
fprintf(stdout, "Posting %i monitors\n", POSTCOUNT*9);
for(i=0; i<3; i++)
{
device[i]->setContext(context);
for(j=0; j<3; j++)
{
sprintf(message, "monitorOn attrib%i", j+1);
for(k=0; k<POSTCOUNT-1; k++)
{
device[i]->sendCallback(message, NULL, cb1);
}
device[i]->sendCallback(message, NULL, cb2);
}
}
for(k=0; k<REPEATCOUNT; k++)
{
gettimeofday(&first);
while(lastHitReceived<3) cdevSystem::defaultSystem().pend();
lastHitReceived = 0;
gettimeofday(&second);
if (first.tv_usec > second.tv_usec)
{
second.tv_usec += 1000000;
second.tv_sec--;
}
lapsed.tv_usec = second.tv_usec - first.tv_usec;
lapsed.tv_sec = second.tv_sec - first.tv_sec;
double period = (double)lapsed.tv_sec+(double)lapsed.tv_usec/1000000.00;
totalPeriod += period;
fprintf(stdout, "%i Callbacks in %f seconds (%i pkts/sec - %i pkts/sec cum)\n",
POSTCOUNT*9, period, (int)((double)POSTCOUNT*9.0/period), (int)((double)callbackCount/totalPeriod));
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
deviceValue[i][j]+=1.0;
data.insert("value", deviceValue[i][j]);
if(k<REPEATCOUNT-1)
{
sprintf(message, "set attrib%i", j+1);
device[i]->sendNoBlock(message, data, NULL);
}
}
}
}
fprintf(stdout, "Removing %i monitors\n", POSTCOUNT*9);
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
sprintf(message, "monitorOff attrib%i", j+1);
device[i]->sendCallback(message, NULL, cb1);
device[i]->sendCallback(message, NULL, cb2);
}
}
done++;
}
cdevSystem::defaultSystem().poll();
return 0;
}