cdev-1.7.2n
This commit is contained in:
31
extensions/cdevGenericServer/cdevMonitorTable/Makefile
Executable file
31
extensions/cdevGenericServer/cdevMonitorTable/Makefile
Executable file
@@ -0,0 +1,31 @@
|
||||
ARCH = OS
|
||||
SHOBJ = NO
|
||||
|
||||
include ../include/makeinclude/Makefile.$(ARCH)
|
||||
|
||||
APPNAME = "Monitor Table Source"
|
||||
TEMPLINKS = cdevMessage.cc cdevMessageBinary.cc cdevPacket.cc cdevTagMap.cc
|
||||
CXXINCLUDES = -I./
|
||||
LIBS = $(CDEVLIBS) $(OSLIBS)
|
||||
TARGETS = $(TEMPLINKS) $(BASEBIN)/cdevMonitorTableTest
|
||||
OBJS = $(OBJDIR)/cdevMonitorTable.o\
|
||||
$(OBJDIR)/cdevMessage.o\
|
||||
$(OBJDIR)/cdevMessageBinary.o\
|
||||
$(OBJDIR)/cdevPacket.o\
|
||||
$(OBJDIR)/cdevTagMap.o\
|
||||
$(OBJDIR)/test.o
|
||||
|
||||
targets: $(TARGETS)
|
||||
@rm -rf $(TEMPLINKS)
|
||||
|
||||
$(TEMPLINKS) :
|
||||
@cp $^ $@
|
||||
|
||||
$(BASEBIN)/cdevMonitorTableTest: $(OBJS)
|
||||
$(LINK.cc) $^ -o $@ $(LIBS)
|
||||
|
||||
cdevPacket.cc : ../cdevPacket/cdevPacket.cc
|
||||
cdevMessage.cc : ../cdevPacket/cdevMessage.cc
|
||||
cdevMessageBinary.cc : ../cdevPacket/cdevMessageBinary.cc
|
||||
cdevTagMap.cc : ../cdevTagMap/cdevTagMap.cc
|
||||
|
||||
44
extensions/cdevGenericServer/cdevMonitorTable/NMakefile.mak
Normal file
44
extensions/cdevGenericServer/cdevMonitorTable/NMakefile.mak
Normal file
@@ -0,0 +1,44 @@
|
||||
.SUFFIXES: .cc .obj
|
||||
|
||||
APPNAME = Monitor Table Source
|
||||
ARCH = WINNT-4.0
|
||||
TEMPLINKS = cdevMessage.cc\
|
||||
cdevMessageBinary.cc\
|
||||
cdevPacket.cc\
|
||||
cdevTagMap.cc
|
||||
|
||||
BINARIES = $(BASEBIN)\cdevMonitorTableTest.exe $(TEMPLINKS)
|
||||
|
||||
include ..\include\makeinclude\Makefile.WINNT-4.0
|
||||
|
||||
CXXEXTRA = /D "GENERIC_SERVER_API= "
|
||||
CXXINCLUDES = /I .\ /I ..\cdevPacket /I ..\cdevTagMap
|
||||
TARGETS = $(BASEBIN)\cdevMonitorTableTest.exe
|
||||
OBJS = .exec\$(TARGETDIR)\cdevMonitorTable.obj\
|
||||
.exec\$(TARGETDIR)\cdevMessage.obj\
|
||||
.exec\$(TARGETDIR)\cdevMessageBinary.obj\
|
||||
.exec\$(TARGETDIR)\cdevPacket.obj\
|
||||
.exec\$(TARGETDIR)\cdevTagMap.obj\
|
||||
.exec\$(TARGETDIR)\test.obj
|
||||
|
||||
targets : $(TEMPLINKS) $(BASEBIN)\cdevMonitorTableTest.exe
|
||||
@erase $(TEMPLINKS)
|
||||
|
||||
$(BASEBIN)\cdevMonitorTableTest.exe : $(OBJS)
|
||||
-@if exist $@ erase $@
|
||||
@echo ^ ^ ^ ^ ^ ^ =^> Linking $(@F)
|
||||
$(LINK) $(CDEVLIB)\cdev.lib\
|
||||
$(LINK_EXE_FLAGS) /out:$@ $?
|
||||
@echo ^ ^ ^ ^ ^ ^ ^ ^ ^ Done...
|
||||
|
||||
cdevMessage.cc : ..\cdevPacket\cdevMessage.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevMessageBinary.cc : ..\cdevPacket\cdevMessageBinary.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevPacket.cc : ..\cdevPacket\cdevPacket.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevTagMap.cc : ..\cdevTagMap\cdevTagMap.cc
|
||||
-@$(CREATE_LINK)
|
||||
1022
extensions/cdevGenericServer/cdevMonitorTable/cdevMonitorTable.cc
Executable file
1022
extensions/cdevGenericServer/cdevMonitorTable/cdevMonitorTable.cc
Executable file
File diff suppressed because it is too large
Load Diff
136
extensions/cdevGenericServer/cdevMonitorTable/cdevMonitorTable.h
Executable file
136
extensions/cdevGenericServer/cdevMonitorTable/cdevMonitorTable.h
Executable file
@@ -0,0 +1,136 @@
|
||||
#ifndef _CDEV_MONITOR_TABLE_H_
|
||||
#define _CDEV_MONITOR_TABLE_H_ 1
|
||||
|
||||
#include <cdevMessage.h>
|
||||
#include <StringHash.h>
|
||||
#include <cdevData.h>
|
||||
#include <xdrClass.h>
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * class cdevMonitorData :
|
||||
// * This class gives a cdevData object the capacity to selectively place
|
||||
// * its tagged data items into an XDR stream.
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API cdevMonitorData : public cdevData
|
||||
{
|
||||
protected:
|
||||
int * criticalTags;
|
||||
int criticalTagCnt;
|
||||
|
||||
virtual int isTagCritical ( int tag );
|
||||
|
||||
public:
|
||||
cdevMonitorData (void );
|
||||
cdevMonitorData (const cdevData & data);
|
||||
cdevMonitorData (const cdevMonitorData & data);
|
||||
|
||||
virtual void setCriticalTags ( int * tags, int tagCnt );
|
||||
virtual int changeTag ( int oldTag, int newTag );
|
||||
virtual int xdrExport ( char ** buf, size_t * bufLen );
|
||||
virtual int xdrExport ( char * buf, size_t bufLen, size_t count);
|
||||
virtual int xdrSize ( size_t * bufLen, size_t * elementCount );
|
||||
};
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * class cdevMonitorNode :
|
||||
// * This class is used to store the list of monitors associated with a
|
||||
// * device / attribute pair. It maintains a back-pointer to the
|
||||
// * cdevMonitorTable object to allow it to call the fireCallback method of
|
||||
// * the parent in order to submit the reply.
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API cdevMonitorNode
|
||||
{
|
||||
friend class cdevMonitorTable;
|
||||
|
||||
protected:
|
||||
// **********************************************************************
|
||||
// * class cdevMonitorEntry :
|
||||
// * This is an individual monitor transaction that has been installed
|
||||
// * in a cdevMonitorNode.
|
||||
// **********************************************************************
|
||||
class cdevMonitorEntry
|
||||
{
|
||||
friend class cdevMonitorNode;
|
||||
private:
|
||||
static int VALUE_TAG;
|
||||
static int STATUS_TAG;
|
||||
static int TIME_TAG;
|
||||
static int DEVICE_TAG; // *** Added for multi-device
|
||||
|
||||
cdevMonitorEntry * next;
|
||||
cdevMessage * message;
|
||||
int * triggers;
|
||||
int * trigType;
|
||||
int trigCnt;
|
||||
int * properties;
|
||||
int propCnt;
|
||||
|
||||
int deviceIdx; // *** Added for multi-device
|
||||
|
||||
cdevMonitorEntry ( cdevMessage * Message, int deviceIdx );
|
||||
~cdevMonitorEntry ( void );
|
||||
};
|
||||
|
||||
class cdevMonitorTable * parent;
|
||||
cdevMonitorEntry * nodes;
|
||||
cdevMonitorData mData;
|
||||
char * hashString;
|
||||
|
||||
virtual int fireMonitor ( cdevMonitorEntry *entry,
|
||||
int property,
|
||||
cdevMonitorData * data,
|
||||
int endOfTransaction = 0);
|
||||
|
||||
virtual int insertMonitor ( cdevMessage * request,
|
||||
cdevData * data,
|
||||
int deviceIdx );
|
||||
|
||||
virtual int removeMonitor ( cdevMessage * request );
|
||||
virtual int removeMonitor ( unsigned transIndex );
|
||||
virtual int removeClientMonitors ( short clientID, int fire = 1 );
|
||||
char * getHashString ( void ) { return hashString; }
|
||||
|
||||
public:
|
||||
cdevMonitorNode ( cdevMonitorTable * Parent,
|
||||
char * Device,
|
||||
char * Attrib );
|
||||
virtual ~cdevMonitorNode ( void );
|
||||
|
||||
virtual int fireMonitor ( char * property, cdevData * data );
|
||||
virtual int fireMonitor ( int property, cdevData * data );
|
||||
int isMonitored ( void ) { return nodes==NULL?0:1; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * class cdevMonitorTable :
|
||||
// * This class is used to store the list of all monitors for all device /
|
||||
// * attribute pairs in the system. The developer must provide the
|
||||
// * fireCallback method which will be used to submit the callback to the
|
||||
// * client.
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API cdevMonitorTable
|
||||
{
|
||||
protected:
|
||||
StringHash monitors;
|
||||
|
||||
public:
|
||||
cdevMonitorTable ( void );
|
||||
virtual ~cdevMonitorTable ( void );
|
||||
|
||||
virtual int insertMonitor ( cdevMessage * request, cdevData * data );
|
||||
virtual int insertMonitor ( cdevMessage * request, cdevData ** data, size_t dataCnt );
|
||||
virtual int removeMonitor ( cdevMessage * request );
|
||||
virtual int removeClientMonitors( short clientID, int fire = 1 );
|
||||
virtual cdevMonitorNode * findMonitor ( char * device, char * attrib );
|
||||
virtual int fireMonitor ( char * device, char * attrib,
|
||||
char * property, cdevData * data );
|
||||
virtual int fireMonitor ( char * device, char * attrib,
|
||||
int property, cdevData * data );
|
||||
virtual int fireCallback ( cdevMessage * message );
|
||||
};
|
||||
|
||||
#endif
|
||||
133
extensions/cdevGenericServer/cdevMonitorTable/test.cc
Executable file
133
extensions/cdevGenericServer/cdevMonitorTable/test.cc
Executable file
@@ -0,0 +1,133 @@
|
||||
#include "cdevMonitorTable.h"
|
||||
#include "cdevTagMap.h"
|
||||
|
||||
cdevTagMap myMap;
|
||||
|
||||
class myMonitorTable : public cdevMonitorTable
|
||||
{
|
||||
public :
|
||||
int fireCallback (cdevMessage * message )
|
||||
{
|
||||
char * str;
|
||||
size_t len;
|
||||
cdevMessage message2;
|
||||
cdevData *data = message->getData();
|
||||
if(data) myMap.localToRemote(*data);
|
||||
|
||||
message->streamOut(&str, &len);
|
||||
message2.streamIn(str, len);
|
||||
message2.asciiDump();
|
||||
if(str!=NULL) delete str;
|
||||
|
||||
if(data) myMap.remoteToLocal(*data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
myMonitorTable mTbl;
|
||||
|
||||
|
||||
char * tagNames[7]=
|
||||
{
|
||||
"value",
|
||||
"status",
|
||||
"controlHigh",
|
||||
"controlLow",
|
||||
"time",
|
||||
"alarmHigh",
|
||||
"alarmLow"
|
||||
};
|
||||
|
||||
int tagValues[7]=
|
||||
{
|
||||
9001,
|
||||
9002,
|
||||
9003,
|
||||
9004,
|
||||
9005,
|
||||
9006,
|
||||
9007
|
||||
};
|
||||
|
||||
char * deviceList[10] =
|
||||
{
|
||||
"device1",
|
||||
"device2",
|
||||
"device3",
|
||||
"device4",
|
||||
"device5",
|
||||
"device6",
|
||||
"device7",
|
||||
"device8",
|
||||
"device9",
|
||||
"device10"
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
cdevMessage * message;
|
||||
cdevData context;
|
||||
cdevData * triggers[10];
|
||||
cdevData trigger;
|
||||
|
||||
myMap.updateTagMap(tagNames, tagValues, 7);
|
||||
|
||||
cdevData::insertTag(9001, "value1");
|
||||
cdevData::insertTag(9002, "status1");
|
||||
cdevData::insertTag(9003, "controlHigh1");
|
||||
cdevData::insertTag(9004, "controlLow1");
|
||||
cdevData::insertTag(9005, "time1");
|
||||
cdevData::insertTag(9006, "alarmHigh1");
|
||||
cdevData::insertTag(9007, "alarmLow1");
|
||||
|
||||
context.insert("value", 3);
|
||||
context.insert("status", 3);
|
||||
context.insert("controlHigh", 2);
|
||||
context.insert("controlLow", 2);
|
||||
context.insert("time", 1);
|
||||
context.insert("alarmHigh", 1);
|
||||
context.insert("alarmLow", 1);
|
||||
|
||||
trigger.insert("value", 100);
|
||||
trigger.insert("status", 0);
|
||||
trigger.insert("controlHigh", 1000);
|
||||
trigger.insert("controlLow", 0);
|
||||
trigger.insert("time", 100);
|
||||
trigger.insert("alarmHigh", 999);
|
||||
trigger.insert("alarmLow", 1);
|
||||
|
||||
for(int i=0; i<10; i++) triggers[i] = &trigger;
|
||||
message = new cdevMessage(1, 1, 0, 0, 0, 0, 0, 10, deviceList, "monitorOn attrib", NULL, &context);
|
||||
cdevMessage message2(*message);
|
||||
|
||||
message2.setCancelTransIndex(message2.getTransIndex());
|
||||
mTbl.insertMonitor(message, triggers, 10);
|
||||
|
||||
fprintf(stdout, "***************** Firing a monitor *****************\n");
|
||||
mTbl.fireMonitor ("device1", "attrib", "controlHigh", &trigger);
|
||||
|
||||
mTbl.removeMonitor(&message2);
|
||||
|
||||
fprintf(stdout, "*************** Firing Four Monitors ***************\n");
|
||||
mTbl.fireMonitor ("device1", "attrib", "controlHigh", &trigger);
|
||||
mTbl.fireMonitor ("device2", "attrib", "controlHigh", &trigger);
|
||||
mTbl.fireMonitor ("device3", "attrib", "controlHigh", &trigger);
|
||||
mTbl.fireMonitor ("device10", "attrib", "controlHigh", &trigger);
|
||||
|
||||
context.remove();
|
||||
context.insert("value", 3);
|
||||
|
||||
cdevMessage *message3 = new cdevMessage(2, 2, 0, 0, 0, 0, 0, 10, deviceList, "monitorOn attrib", NULL, &context);
|
||||
mTbl.insertMonitor(message3, &trigger);
|
||||
|
||||
for(i=0; i<100; i++)
|
||||
{
|
||||
trigger.insert("value", i);
|
||||
mTbl.fireMonitor("device1", "attrib", "value", &trigger);
|
||||
}
|
||||
|
||||
mTbl.removeClientMonitors(2);
|
||||
mTbl.fireMonitor("device1", "attrib", "value", &trigger);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user