cdev-1.7.2n
This commit is contained in:
+171
@@ -0,0 +1,171 @@
|
||||
#include <BadMagic.h>
|
||||
#include <cdevMessage.h>
|
||||
#include <clipMagicNumber.h>
|
||||
#include <xdrClass.h>
|
||||
|
||||
int GlobalDone = 0;
|
||||
cdevReactor GlobalReactor;
|
||||
|
||||
// *****************************************************************************
|
||||
// * BadMagicHandler::BadMagicHandler
|
||||
// * Default constructor for the BadMagicHandler class
|
||||
// *****************************************************************************
|
||||
BadMagicHandler::BadMagicHandler ( void )
|
||||
: stream()
|
||||
{
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * open:
|
||||
// * Established a connection with the host specified by remote_sap
|
||||
// *****************************************************************************
|
||||
int BadMagicHandler::open ( const cdevAddr & addr )
|
||||
{
|
||||
int result = stream.connect (addr);
|
||||
if (result != -1)
|
||||
{
|
||||
if((result = GlobalReactor.registerHandler(this, READ_MASK|WRITE_MASK|EXCEPT_MASK))==-1)
|
||||
{
|
||||
handleClose();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * ~BadMagicHandler:
|
||||
// * Default destructor for the BadMagicHandler object.
|
||||
// *****************************************************************************
|
||||
BadMagicHandler::~BadMagicHandler (void)
|
||||
{
|
||||
GlobalReactor.extractHandler(this);
|
||||
handleClose();
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * BadMagicHandler::getHandle
|
||||
// * Allows the caller to obtain the file identifier of the socket.
|
||||
// *****************************************************************************
|
||||
int BadMagicHandler::getHandle (void) const
|
||||
{
|
||||
return stream.getHandle();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * handleClose:
|
||||
// * Closes the stream.
|
||||
// *****************************************************************************
|
||||
int BadMagicHandler::handleClose (void)
|
||||
{
|
||||
stream.close();
|
||||
fprintf(stdout, "=> Closing the BadMagic handler\n");
|
||||
fflush(stdout);
|
||||
GlobalDone = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * handleInput :
|
||||
// * This function is called when data is ready to be read from a connected
|
||||
// * socket. This function will read the data from the socket, and will then
|
||||
// * submit the buffer to the ServerInterface class for processing.
|
||||
// *****************************************************************************
|
||||
int BadMagicHandler::handleInput (void)
|
||||
{
|
||||
char buf[1000];
|
||||
|
||||
fprintf(stdout, "=> Receiving unwanted input\n");
|
||||
fflush(stdout);
|
||||
|
||||
while(stream.recv(buf, 1000)>0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * handleOutput :
|
||||
// * This function is called when data is ready to be transmitted to a
|
||||
// * connected socket. This function will read the data from the queue,
|
||||
// * translate it to XDR, and then transmit it to the client.
|
||||
// *****************************************************************************
|
||||
int BadMagicHandler::handleOutput ( void )
|
||||
{
|
||||
static int count = 0;
|
||||
|
||||
long length = 72;
|
||||
long packets = 1;
|
||||
long magic = CLIP_MAGIC_NUMBER;
|
||||
char * deviceList = "device1";
|
||||
cdevMessageBinary msg (1, 12, 0, 100, 200, 22, 14, 1, (char **)&deviceList, (char *)"get funky");
|
||||
XDR_Writer writer (2400);
|
||||
char * msgBuf = NULL;
|
||||
size_t msgLen = 0;
|
||||
|
||||
msg.streamOut(&msgBuf, &msgLen);
|
||||
|
||||
count++;
|
||||
if(count==50) magic++;
|
||||
fflush (stdout);
|
||||
writer.put(magic);
|
||||
writer.put(length);
|
||||
writer.put(packets);
|
||||
writer.put(msgLen);
|
||||
writer.put((void *)msgBuf, msgLen);
|
||||
|
||||
fprintf(stdout, "=> I have sent %i bytes...\n", stream.send(writer.buf, 80));
|
||||
fflush(stdout);
|
||||
|
||||
if(count>=100) GlobalDone = -1;
|
||||
return GlobalDone;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * handleExcept :
|
||||
// * This function is called when out of band data has been received from
|
||||
// * the server. It will terminate the connection with the server.
|
||||
// *****************************************************************************
|
||||
int BadMagicHandler::handleExcept ( void )
|
||||
{
|
||||
fprintf(stdout, "=> I have received a terminator from the server\n");
|
||||
fflush(stdout);
|
||||
stream.close();
|
||||
GlobalDone = 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int main ( int argc, char ** argv)
|
||||
{
|
||||
fprintf(stdout, "\n\
|
||||
=> **********************************************************************\n\
|
||||
=> * This is a test of the cdevGenericServer server-side software. *\n\
|
||||
=> * This application will transmit a group of packets to the server *\n\
|
||||
=> * and will then transmit a packet with a bad magic number. The *\n\
|
||||
=> * should immediately terminate the client connection as soon as the *\n\
|
||||
=> * packet with the invalid magic number is received. *\n\
|
||||
=> **********************************************************************\n\n");
|
||||
|
||||
if(argc<3)
|
||||
{
|
||||
fprintf(stdout, "\
|
||||
=> Insufficient parameters\n\
|
||||
=> Format is : %s host port\n\
|
||||
=> Terminating\n", argv[0]);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
BadMagicHandler handler;
|
||||
cdevInetAddr addr(atoi(argv[2]), argv[1]);
|
||||
handler.open(addr);
|
||||
while(!GlobalDone) GlobalReactor.handleEvents();
|
||||
|
||||
return 0;
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
#ifndef _BAD_MAGIC_H_
|
||||
#define _BAD_MAGIC_H_ 1
|
||||
|
||||
#include "cdevEventHandler.h"
|
||||
#include "cdevAddr.h"
|
||||
#include "cdevSocketConnector.h"
|
||||
#include "cdevReactor.h"
|
||||
#include "fifo.h"
|
||||
|
||||
// *****************************************************************************
|
||||
// * BadMagicHandler:
|
||||
// * This class provides the mechanisms that will be used to service the
|
||||
// * requests of a client.
|
||||
// *****************************************************************************
|
||||
class BadMagicHandler : public cdevEventHandler
|
||||
{
|
||||
protected:
|
||||
cdevSocketConnector stream;
|
||||
|
||||
public:
|
||||
BadMagicHandler (void);
|
||||
~BadMagicHandler (void);
|
||||
virtual int open (const cdevAddr &addr);
|
||||
virtual int getHandle (void) const;
|
||||
virtual int handleClose (void);
|
||||
virtual int handleInput (void);
|
||||
virtual int handleOutput (void);
|
||||
virtual int handleExcept (void);
|
||||
};
|
||||
|
||||
#endif /* _BAD_MAGIC_H_ */
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
ARCH = OS
|
||||
SHOBJ = YES
|
||||
|
||||
include ../../include/makeinclude/Makefile.$(ARCH)
|
||||
|
||||
APPNAME = "Server Bad Magic Number Test"
|
||||
OUTPUTDIR = $(BASEBIN)
|
||||
CXXINCLUDES = -I./
|
||||
LIBS = -L$(CDEVLIB) -lcdevGenericServer $(CDEVLIBS) $(OSLIBS)
|
||||
|
||||
TARGETS = $(OUTPUTDIR)/BadMagic
|
||||
BINARIES = $(TARGETS)
|
||||
|
||||
targets : $(TARGETS)
|
||||
|
||||
$(OUTPUTDIR)/BadMagic : $(OBJDIR)/BadMagic.o
|
||||
$(LINK.cc) $^ $(LIBS) -o $@
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
.SUFFIXES: .cc .obj
|
||||
|
||||
APPNAME = Server Bad Magic Number Test
|
||||
ARCH = WINNT-4.0
|
||||
SHOBJ = YES
|
||||
|
||||
BINARIES = $(BASEBIN)\BadMagic.exe
|
||||
|
||||
include ..\..\include\makeinclude\Makefile.WINNT-4.0
|
||||
|
||||
CXXINCLUDES = /I .\\
|
||||
|
||||
targets : $(BINARIES)
|
||||
|
||||
$(BASEBIN)\BadMagic.exe : .exec\$(TARGETDIR)\BadMagic.obj
|
||||
-@if exist $@ erase $@
|
||||
@echo ^ ^ ^ ^ ^ ^ =^> Linking $(@F)
|
||||
$(LINK) $(CDEVLIB)\cdev.lib $(CDEVLIB)\cdevGenericServer.lib \
|
||||
$(LINK_EXE_FLAGS) /out:$@ $?
|
||||
@echo ^ ^ ^ ^ ^ ^ ^ ^ ^ Done...
|
||||
+173
@@ -0,0 +1,173 @@
|
||||
#include <EarlyDeath.h>
|
||||
#include <cdevMessage.h>
|
||||
#include <clipMagicNumber.h>
|
||||
#include <xdrClass.h>
|
||||
|
||||
int GlobalDone = 0;
|
||||
cdevReactor GlobalReactor;
|
||||
|
||||
// *****************************************************************************
|
||||
// * EarlyDeathHandler::EarlyDeathHandler
|
||||
// * Default constructor for the EarlyDeathHandler class
|
||||
// *****************************************************************************
|
||||
EarlyDeathHandler::EarlyDeathHandler ( void )
|
||||
: stream()
|
||||
{
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * open:
|
||||
// * Established a connection with the host specified by remote_sap
|
||||
// *****************************************************************************
|
||||
int EarlyDeathHandler::open ( const cdevAddr & addr )
|
||||
{
|
||||
int result = stream.connect (addr);
|
||||
if (result != -1)
|
||||
{
|
||||
if((result = GlobalReactor.registerHandler(this, READ_MASK|WRITE_MASK|EXCEPT_MASK))==-1)
|
||||
{
|
||||
handleClose();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * ~EarlyDeathHandler:
|
||||
// * Default destructor for the EarlyDeathHandler object.
|
||||
// *****************************************************************************
|
||||
EarlyDeathHandler::~EarlyDeathHandler (void)
|
||||
{
|
||||
GlobalReactor.extractHandler(this);
|
||||
handleClose();
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * EarlyDeathHandler::getHandle
|
||||
// * Allows the caller to obtain the file identifier of the socket.
|
||||
// *****************************************************************************
|
||||
int EarlyDeathHandler::getHandle (void) const
|
||||
{
|
||||
return stream.getHandle();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * handleClose:
|
||||
// * Closes the stream.
|
||||
// *****************************************************************************
|
||||
int EarlyDeathHandler::handleClose (void)
|
||||
{
|
||||
stream.close();
|
||||
fprintf(stdout, "=> Closing the EarlyDeath handler\n");
|
||||
fflush(stdout);
|
||||
GlobalDone = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * handleInput :
|
||||
// * This function is called when data is ready to be read from a connected
|
||||
// * socket. This function will read the data from the socket, and will then
|
||||
// * submit the buffer to the ServerInterface class for processing.
|
||||
// *****************************************************************************
|
||||
int EarlyDeathHandler::handleInput (void)
|
||||
{
|
||||
char buf[1000];
|
||||
|
||||
fprintf(stdout, "=> Receiving unwanted input\n");
|
||||
fflush(stdout);
|
||||
|
||||
while(stream.recv(buf, 1000)>0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * handleOutput :
|
||||
// * This function is called when data is ready to be transmitted to a
|
||||
// * connected socket. This function will read the data from the queue,
|
||||
// * translate it to XDR, and then transmit it to the client.
|
||||
// *****************************************************************************
|
||||
int EarlyDeathHandler::handleOutput ( void )
|
||||
{
|
||||
static int count = 0;
|
||||
|
||||
long length = 72;
|
||||
long packets = 1;
|
||||
long magic = CLIP_MAGIC_NUMBER;
|
||||
char * deviceList = "device1";
|
||||
cdevMessageBinary msg (1, 12, 0, 100, 200, 22, 14, 1, (char **)&deviceList, (char *)"get funky");
|
||||
XDR_Writer writer (2400);
|
||||
char * msgBuf = NULL;
|
||||
size_t msgLen = 0;
|
||||
|
||||
msg.streamOut(&msgBuf, &msgLen);
|
||||
|
||||
fflush (stdout);
|
||||
writer.put(magic);
|
||||
writer.put(length);
|
||||
writer.put(packets);
|
||||
writer.put(msgLen);
|
||||
writer.put((void *)msgBuf, msgLen);
|
||||
|
||||
if(++count < 100) fprintf(stdout, "=> I have sent %i bytes...\n", stream.send(writer.buf, 80));
|
||||
else fprintf(stdout, "=> I have sent %i bytes and now I'm quitting\n", stream.send(writer.buf, 40));
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
if(count>=100) GlobalDone = -1;
|
||||
return GlobalDone;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * handleExcept :
|
||||
// * This function is called when out of band data has been received from
|
||||
// * the server. It will terminate the connection with the server.
|
||||
// *****************************************************************************
|
||||
int EarlyDeathHandler::handleExcept ( void )
|
||||
{
|
||||
fprintf(stdout, "=> I have received a terminator from the server\n");
|
||||
fflush(stdout);
|
||||
stream.close();
|
||||
GlobalDone = 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int main ( int argc, char ** argv)
|
||||
{
|
||||
fprintf(stdout, "\n\
|
||||
=> **********************************************************************\n\
|
||||
=> * This is a test of the cdevGenericServer server-side software. *\n\
|
||||
=> * This application will transmit a partial packet to the server *\n\
|
||||
=> * and will then immediately terminate. The developer should inspect *\n\
|
||||
=> * the behavior of the server and ensure that it responds properly. *\n\
|
||||
=> * *\n\
|
||||
=> * The correct response to this sort of event would be to terminate *\n\
|
||||
=> * the connection and remove the client from the server. *\n\
|
||||
=> **********************************************************************\n\n");
|
||||
|
||||
if(argc<3)
|
||||
{
|
||||
fprintf(stdout, "\
|
||||
=> Insufficient parameters\n\
|
||||
=> Format is : %s host port\n\
|
||||
=> Terminating\n", argv[0]);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
EarlyDeathHandler handler;
|
||||
cdevInetAddr addr(atoi(argv[2]), argv[1]);
|
||||
handler.open(addr);
|
||||
while(!GlobalDone) GlobalReactor.handleEvents();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef _EARLY_DEATH_H_
|
||||
#define _EARLY_DEATH_H_ 1
|
||||
|
||||
#include "cdevEventHandler.h"
|
||||
#include "cdevAddr.h"
|
||||
#include "cdevSocketConnector.h"
|
||||
#include "cdevReactor.h"
|
||||
#include "fifo.h"
|
||||
|
||||
// *****************************************************************************
|
||||
// * EarlyDeathHandler:
|
||||
// * This class provides the mechanisms that will be used to service the
|
||||
// * requests of a client.
|
||||
// *****************************************************************************
|
||||
class EarlyDeathHandler : public cdevEventHandler
|
||||
{
|
||||
protected:
|
||||
cdevSocketConnector stream;
|
||||
|
||||
public:
|
||||
EarlyDeathHandler (void);
|
||||
~EarlyDeathHandler (void);
|
||||
virtual int open (const cdevAddr &addr);
|
||||
virtual int getHandle (void) const;
|
||||
virtual int handleClose (void);
|
||||
virtual int handleInput (void);
|
||||
virtual int handleOutput (void);
|
||||
virtual int handleExcept (void);
|
||||
};
|
||||
|
||||
#endif /* _EARLY_DEATH_H_ */
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
ARCH = OS
|
||||
SHOBJ = YES
|
||||
|
||||
include ../../include/makeinclude/Makefile.$(ARCH)
|
||||
|
||||
APPNAME = "Server Early Death Test"
|
||||
OUTPUTDIR = $(BASEBIN)
|
||||
CXXINCLUDES = -I./
|
||||
LIBS = -L$(CDEVLIB) -lcdevGenericServer $(CDEVLIBS) $(OSLIBS)
|
||||
|
||||
TARGETS = $(OUTPUTDIR)/EarlyDeath
|
||||
BINARIES = $(TARGETS)
|
||||
|
||||
targets : $(TARGETS)
|
||||
|
||||
$(OUTPUTDIR)/EarlyDeath : $(OBJDIR)/EarlyDeath.o
|
||||
$(LINK.cc) $^ $(LIBS) -o $@
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
.SUFFIXES: .cc .obj
|
||||
|
||||
APPNAME = Server Early Death Test
|
||||
ARCH = WINNT-4.0
|
||||
SHOBJ = YES
|
||||
|
||||
BINARIES = $(BASEBIN)\EarlyDeath.exe
|
||||
|
||||
include ..\..\include\makeinclude\Makefile.WINNT-4.0
|
||||
|
||||
CXXINCLUDES = /I .\\
|
||||
|
||||
targets : $(BINARIES)
|
||||
|
||||
$(BASEBIN)\EarlyDeath.exe : .exec\$(TARGETDIR)\EarlyDeath.obj
|
||||
-@if exist $@ erase $@
|
||||
@echo ^ ^ ^ ^ ^ ^ =^> Linking $(@F)
|
||||
$(LINK) $(CDEVLIB)\cdev.lib $(CDEVLIB)\cdevGenericServer.lib \
|
||||
$(LINK_EXE_FLAGS) /out:$@ $?
|
||||
@echo ^ ^ ^ ^ ^ ^ ^ ^ ^ Done...
|
||||
@@ -0,0 +1,15 @@
|
||||
#include <cdevSystem.h>
|
||||
#include <cdevRequestObject.h>
|
||||
#include <cdevDevice.h>
|
||||
#include <cdevGroup.h>
|
||||
#include <cdevCommon.h>
|
||||
|
||||
int main( )
|
||||
{
|
||||
cdevData data;
|
||||
cdevDevice & device = cdevDevice::attachRef("device1");
|
||||
device.send("get servers", NULL, data);
|
||||
data.asciiDump();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
service Test
|
||||
{
|
||||
tags {server}
|
||||
}
|
||||
|
||||
class Tests
|
||||
{
|
||||
verbs {get, set}
|
||||
attributes
|
||||
{
|
||||
default Test;
|
||||
clientID Test;
|
||||
servers Test;
|
||||
connections Test;
|
||||
attrib Test {server=TestServer1};
|
||||
}
|
||||
messages
|
||||
{
|
||||
shutdown Test;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Tests :
|
||||
device1,
|
||||
device2,
|
||||
device3
|
||||
;
|
||||
@@ -0,0 +1,29 @@
|
||||
ARCH = OS
|
||||
SHOBJ = YES
|
||||
|
||||
include ../../include/makeinclude/Makefile.$(ARCH)
|
||||
|
||||
APPNAME = "Get Servers Test"
|
||||
CXXINCLUDES = -I./
|
||||
SO_SRCS = GetServers.cc
|
||||
SO_LIBS = -L$(CDEVLIB) -lcdevGenericServer $(NETLIBS)
|
||||
|
||||
# ******************************************************************************
|
||||
# * The BINARIES definition names all of the binary files that should be deleted
|
||||
# * whenever "make clean" is executed.
|
||||
# ******************************************************************************
|
||||
BINARIES = $(BASEBIN)/GetServers
|
||||
|
||||
ifeq ($(SHOBJ), YES)
|
||||
LIBS = -L$(CDEVLIB) -lcdevGenericServer $(CDEVLIBS) $(OSLIBS)
|
||||
TARGETS = $(BASEBIN)/GetServers
|
||||
else
|
||||
LIBS = -L$(CDEVLIB) -lcdevGenericServer $(CDEVLIBS) $(OSLIBS)
|
||||
TARGETS = $(BASEBIN)/GetServers
|
||||
endif
|
||||
|
||||
targets : $(TARGETS)
|
||||
|
||||
$(BASEBIN)/GetServers : $(OBJDIR)/GetServers.o
|
||||
$(LINK.cc) $^ -o $@ $(LIBS)
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
.SUFFIXES: .cc .obj
|
||||
|
||||
APPNAME = Get Servers Test
|
||||
ARCH = WINNT-4.0
|
||||
SHOBJ = YES
|
||||
|
||||
BINARIES = $(BASEBIN)\GetServers.exe
|
||||
|
||||
include ..\..\include\makeinclude\Makefile.WINNT-4.0
|
||||
|
||||
CXXINCLUDES = /I .\\
|
||||
|
||||
targets : $(BINARIES)
|
||||
|
||||
$(BASEBIN)\GetServers.exe : .exec\$(TARGETDIR)\GetServers.obj
|
||||
-@if exist $@ erase $@
|
||||
@echo ^ ^ ^ ^ ^ ^ =^> Linking $(@F)
|
||||
$(LINK) $(CDEVLIB)\cdev.lib $(CDEVLIB)\cdevGenericServer.lib \
|
||||
$(LINK_EXE_FLAGS) /out:$@ $?
|
||||
@echo ^ ^ ^ ^ ^ ^ ^ ^ ^ Done...
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
BASEDIR = $(shell pwd)
|
||||
DIRS = $(BASEDIR)/TransmissionTest \
|
||||
$(BASEDIR)/Performance \
|
||||
$(BASEDIR)/EarlyDeath \
|
||||
$(BASEDIR)/BadMagic \
|
||||
$(BASEDIR)/MonitorTest \
|
||||
$(BASEDIR)/GetServers \
|
||||
$(BASEDIR)/SyncSet
|
||||
|
||||
all commit clean purge:
|
||||
@for dir in $(DIRS); \
|
||||
do \
|
||||
$(MAKE) -C $$dir $@; \
|
||||
done
|
||||
|
||||
@@ -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...
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
BASEDIR = $(MAKEDIR)
|
||||
DIRS = $(BASEDIR)\TransmissionTest \
|
||||
$(BASEDIR)\PerformanceTest \
|
||||
$(BASEDIR)\EarlyDeath \
|
||||
$(BASEDIR)\BadMagic \
|
||||
$(BASEDIR)\MonitorTest \
|
||||
$(BASEDIR)\GetServers \
|
||||
$(BASEDIR)\SyncSet
|
||||
|
||||
notarget: all
|
||||
|
||||
all clean purge:
|
||||
@for %d in ($(DIRS)) do @if exist %d cd %d & $(MAKE) /NOLOGO $@ /f NMakefile.mak
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
ARCH = OS
|
||||
SHOBJ = YES
|
||||
|
||||
include ../../include/makeinclude/Makefile.$(ARCH)
|
||||
|
||||
APPNAME = "Performance Client/Server Test"
|
||||
CXXINCLUDES = -I./ -DMANUAL=TRUE
|
||||
SO_SRCS = PerformanceService.cc
|
||||
SO_LIBS = -L$(CDEVLIB) -lcdevGenericServer $(OSLIBS)
|
||||
LIBS = -L$(CDEVLIB) -lcdevGenericServer $(CDEVLIBS) $(OSLIBS)
|
||||
|
||||
ifeq ($(SHOBJ), YES)
|
||||
TARGETS = $(BASELIB)/PerformanceService.so $(BASEBIN)/PerformanceServer $(BASEBIN)/PerformanceTest $(BASEBIN)/PerformanceTest2
|
||||
else
|
||||
TARGETS = $(BASELIB)/libPerformanceService.a $(BASEBIN)/PerformanceServer $(BASEBIN)/PerformanceTest $(BASEBIN)/PerformanceTest2
|
||||
endif
|
||||
|
||||
targets : $(TARGETS)
|
||||
|
||||
$(BASEBIN)/PerformanceTest : $(OBJDIR)/PerformanceTest.o
|
||||
$(LINK.cc) $^ $(LIBS) -o $@
|
||||
|
||||
$(BASEBIN)/PerformanceTest2 : $(OBJDIR)/PerformanceTest2.o
|
||||
$(LINK.cc) $^ $(LIBS) -o $@
|
||||
|
||||
$(BASEBIN)/PerformanceServer : $(OBJDIR)/PerformanceServer.o
|
||||
$(LINK.cc) $^ $(LIBS) -o $@
|
||||
|
||||
$(BASELIB)/PerformanceService.so : $(OBJDIR)/PerformanceService.o
|
||||
$(LINK.so) -o $@ $^ -L$(CDEVLIB) -lcdevGenericServer $(OSLIBS)
|
||||
@mkdir -p $(CDEVSHOBJ)/$(CDEVVERSION)
|
||||
@cp $@ $(CDEVSHOBJ)/$(CDEVVERSION)/$(@F)
|
||||
|
||||
|
||||
$(BASELIB)/libPerformanceService.a : $(OBJDIR)/PerformanceService.o
|
||||
$(LINK.a) $@ $(OBJDIR)/PerformanceService.o
|
||||
@$(RANLIB) $@ > /dev/null
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
.SUFFIXES: .cc .obj
|
||||
|
||||
APPNAME = Client/Server Performance Test
|
||||
ARCH = WINNT-4.0
|
||||
SHOBJ = YES
|
||||
|
||||
BINARIES = $(BASEBIN)\PerformanceServer.exe \
|
||||
$(BASEBIN)\PerformanceTest.exe \
|
||||
$(CDEVLIB)\PerformanceService.dll \
|
||||
$(CDEVLIB)\PerformanceService.lib
|
||||
|
||||
include ..\..\include\makeinclude\Makefile.WINNT-4.0
|
||||
|
||||
CXXINCLUDES = /I .\\ /D "MANUAL=TRUE"
|
||||
CXXEXTRA_DLL = /D "PERFORMANCE_SERVICE_API=__declspec(dllexport)"
|
||||
CXXEXTRA_LIB = /D "PERFORMANCE_SERVICE_API="
|
||||
|
||||
!IF "$(SHOBJ)" == "YES"
|
||||
TARGETS = $(BASEBIN)\PerformanceServer.exe \
|
||||
$(BASEBIN)\PerformanceTest.exe \
|
||||
$(CDEVLIB)\PerformanceService.dll
|
||||
!ELSE
|
||||
TARGETS = $(BASEBIN)\PerformanceServer.exe \
|
||||
$(BASEBIN)\PerformanceTest.exe \
|
||||
$(CDEVLIB)\PerformanceService.lib
|
||||
!ENDIF
|
||||
|
||||
targets : $(TARGETS)
|
||||
|
||||
$(CDEVLIB)\PerformanceService.dll : $(OBJDIR)\PerformanceService.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)\PerformanceService.lib : $(OBJDIR)\PerformanceService.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)\PerformanceServer.exe : .exec\$(TARGETDIR)\PerformanceServer.obj
|
||||
-@if exist $@ erase $@
|
||||
@echo ^ ^ ^ ^ ^ ^ =^> Linking $(@F)
|
||||
$(LINK) $(CDEVLIB)\cdev.lib $(CDEVLIB)\cdevGenericServer.lib \
|
||||
$(LINK_EXE_FLAGS) /out:$@ $?
|
||||
@echo ^ ^ ^ ^ ^ ^ ^ ^ ^ Done...
|
||||
|
||||
$(BASEBIN)\PerformanceTest.exe : .exec\$(TARGETDIR)\PerformanceTest.obj
|
||||
-@if exist $@ erase $@
|
||||
@echo ^ ^ ^ ^ ^ ^ =^> Linking $(@F)
|
||||
$(LINK) $(CDEVLIB)\cdev.lib $(CDEVLIB)\cdevGenericServer.lib \
|
||||
$(LINK_EXE_FLAGS) /out:$@ $?
|
||||
@echo ^ ^ ^ ^ ^ ^ ^ ^ ^ Done...
|
||||
@@ -0,0 +1,26 @@
|
||||
service Performance
|
||||
{
|
||||
tags {server}
|
||||
}
|
||||
|
||||
class Performances
|
||||
{
|
||||
verbs {get, set}
|
||||
attributes
|
||||
{
|
||||
default Performance;
|
||||
servers Performance;
|
||||
attrib0 Performance {server=Performance1};
|
||||
attrib1 Performance {server=Performance1};
|
||||
}
|
||||
messages
|
||||
{
|
||||
disconnect Performance;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Performances :
|
||||
device0;
|
||||
|
||||
alias device1 device0
|
||||
@@ -0,0 +1,51 @@
|
||||
#include <cdevServer.h>
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * class PerformanceServer :
|
||||
// * This is a performance test server. 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 PerformanceServer : public cdevServer
|
||||
{
|
||||
cdevMessage * pmMessage;
|
||||
|
||||
public:
|
||||
PerformanceServer ( char * domain, char * server, unsigned int port, double pulse )
|
||||
: cdevServer(domain, server, port, pulse)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void processMessages ( void )
|
||||
{
|
||||
while(dequeue(pmMessage)==0)
|
||||
{
|
||||
enqueue(pmMessage);
|
||||
delete pmMessage;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
char * serverName;
|
||||
|
||||
if(argc>1) serverName = argv[1];
|
||||
else serverName = strdup("Performance1");
|
||||
|
||||
PerformanceServer server("PERFORMANCE", serverName, 0, 5);
|
||||
cdevServer::runServer();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#include <PerformanceService.h>
|
||||
|
||||
// *****************************************************************************
|
||||
// * newPerformanceService:
|
||||
// * This function will be called by the cdevSystem object to create an
|
||||
// * initial instance of the PerformanceService.
|
||||
// *****************************************************************************
|
||||
extern "C" cdevService * newPerformanceService (char * name, cdevSystem * system)
|
||||
{
|
||||
return new PerformanceService(name, *system);
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * PerformanceService::PerformanceService :
|
||||
// * This is teh constructor for the PerformanceService. It initializes the
|
||||
// * underlying cdevClientService by specifying that it is in the domain of
|
||||
// * PERFORMANCE.
|
||||
// *****************************************************************************
|
||||
PerformanceService::PerformanceService ( char * name, cdevSystem & system)
|
||||
: cdevClientService("PERFORMANCE", name, system)
|
||||
{
|
||||
system.reportError(CDEV_SEVERITY_INFO, "PerformanceService", NULL,
|
||||
"Constructing a new PerformanceService");
|
||||
}
|
||||
|
||||
PerformanceService::~PerformanceService ( void )
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#include <cdevClientService.h>
|
||||
|
||||
#ifndef PERFORMANCE_SERVICE_API
|
||||
#define PERFORMANCE_SERVICE_API
|
||||
#endif
|
||||
|
||||
// *****************************************************************************
|
||||
// * newPerformanceService :
|
||||
// * This function will be called by the cdevSystem object to create an
|
||||
// * initial instance of the PerformanceService.
|
||||
// *****************************************************************************
|
||||
extern "C" PERFORMANCE_SERVICE_API cdevService * newPerformanceService ( char * name, cdevSystem * system );
|
||||
|
||||
// *****************************************************************************
|
||||
// * class PerformanceService :
|
||||
// * This class simply inherits from the cdevClientService and must define
|
||||
// * only a constructor and destructor.
|
||||
// *****************************************************************************
|
||||
class PerformanceService : public cdevClientService
|
||||
{
|
||||
public:
|
||||
PerformanceService ( char * name, cdevSystem & system = cdevSystem::defaultSystem());
|
||||
|
||||
protected:
|
||||
~PerformanceService ( void );
|
||||
|
||||
};
|
||||
@@ -0,0 +1,383 @@
|
||||
#include <cdevPlatforms.h>
|
||||
#include <cdevSystem.h>
|
||||
#include <cdevRequestObject.h>
|
||||
#include <cdevDevice.h>
|
||||
#include <cdevGroup.h>
|
||||
#include <cdevCommon.h>
|
||||
#include <cdevMessage.h>
|
||||
|
||||
struct timeval first;
|
||||
int callbackCount = 0;
|
||||
int reportCount = 0;
|
||||
int reportFrequency = 0;
|
||||
int bunchSize = 0;
|
||||
char * deviceName = "device0";
|
||||
char * messageStr = "set attrib0";
|
||||
double PerformanceRate = 0.0;
|
||||
double * performanceRatePtr = &PerformanceRate;
|
||||
size_t PacketSize = 0;
|
||||
size_t * packetSizePtr = &PacketSize;
|
||||
int synchroValue = 0;
|
||||
int synchroFound = 0;
|
||||
|
||||
void synchroCallback (int status, void *, cdevRequestObject &, cdevData & data)
|
||||
{
|
||||
if(status==CDEV_SUCCESS)
|
||||
{
|
||||
int value;
|
||||
data.get("value", &value);
|
||||
if(value==synchroValue) synchroFound = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void callback ( int status, void *, cdevRequestObject &, cdevData & )
|
||||
{
|
||||
if(status==CDEV_SUCCESS)
|
||||
{
|
||||
callbackCount++;
|
||||
reportCount++;
|
||||
|
||||
if(reportCount==reportFrequency)
|
||||
{
|
||||
reportCount = 0;
|
||||
struct timeval second, lapsed;
|
||||
|
||||
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;
|
||||
|
||||
if(lapsed.tv_sec)
|
||||
{
|
||||
*performanceRatePtr = (double)callbackCount/(double)lapsed.tv_sec;
|
||||
fprintf(stdout, "Average rate is %lf pkts/sec after %ld packets\n", *performanceRatePtr, callbackCount);
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cdevData * createPayload1 ( int )
|
||||
{
|
||||
char * binary = 0;
|
||||
cdevMessage msg(1, 1, 0, 0, 0, 0, 0, 1, &deviceName, messageStr);
|
||||
msg.streamOut(&binary, packetSizePtr);
|
||||
delete binary;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cdevData * createPayload2 ( int cnt )
|
||||
{
|
||||
cdevData * data = new cdevData;
|
||||
if(cnt>1)
|
||||
{
|
||||
int * x = new int[cnt];
|
||||
for(int i=0; i<cnt; i++) x[i] = (int)i;
|
||||
data->insert("value", x, cnt);
|
||||
delete x;
|
||||
}
|
||||
else data->insert("value", 1);
|
||||
|
||||
char * binary = 0;
|
||||
cdevMessage msg(1, 1, 0, 0, 0, 0, 0, 1, &deviceName, messageStr, data);
|
||||
msg.streamOut(&binary, packetSizePtr);
|
||||
delete binary;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
cdevData * createPayload3 ( int cnt )
|
||||
{
|
||||
cdevData * data = new cdevData;
|
||||
if(cnt>1)
|
||||
{
|
||||
float * x = new float[cnt];
|
||||
for(int i=0; i<cnt; i++) x[i] = (float)i;
|
||||
data->insert("value", x, cnt);
|
||||
delete x;
|
||||
}
|
||||
else data->insert("value", (float)1.0);
|
||||
|
||||
char * binary = 0;
|
||||
cdevMessage msg(1, 1, 0, 0, 0, 0, 0, 1, &deviceName, messageStr, data);
|
||||
msg.streamOut(&binary, packetSizePtr);
|
||||
delete binary;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
cdevData * createPayload4 ( int cnt )
|
||||
{
|
||||
cdevData * data = new cdevData;
|
||||
if(cnt>1)
|
||||
{
|
||||
double * x = new double[cnt];
|
||||
for(int i=0; i<cnt; i++) x[i] = (double)i;
|
||||
data->insert("value", x, cnt);
|
||||
delete x;
|
||||
}
|
||||
else data->insert("value", (double)1.0);
|
||||
|
||||
char * binary = 0;
|
||||
cdevMessage msg(1, 1, 0, 0, 0, 0, 0, 1, &deviceName, messageStr, data);
|
||||
msg.streamOut(&binary, packetSizePtr);
|
||||
delete binary;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
cdevData * createPayload5 ( int cnt )
|
||||
{
|
||||
cdevData * data = new cdevData;
|
||||
char buf[64];
|
||||
|
||||
if(cnt>1)
|
||||
{
|
||||
char ** x = new char *[cnt];
|
||||
int i;
|
||||
for(i=0; i<cnt; i++)
|
||||
{
|
||||
sprintf(buf, "This is string %i", i);
|
||||
x[i] = strdup(buf);
|
||||
}
|
||||
data->insert("value", x, cnt);
|
||||
for(i=0; i<cnt; i++)
|
||||
{
|
||||
free(x[i]);
|
||||
}
|
||||
delete x;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(buf, "This is string 0");
|
||||
data->insert("value", buf);
|
||||
}
|
||||
|
||||
char * binary = 0;
|
||||
cdevMessage msg(1, 1, 0, 0, 0, 0, 0, 1, &deviceName, messageStr, data);
|
||||
|
||||
msg.streamOut(&binary, packetSizePtr);
|
||||
delete binary;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
const int payloadCount = 10;
|
||||
|
||||
char * payloadType[payloadCount] =
|
||||
{
|
||||
"None",
|
||||
"1 - Barebones cdevMessage",
|
||||
"2 - cdevMessage with one integer value",
|
||||
"3 - cdevMessage with one float value",
|
||||
"4 - cdevMessage with one double value",
|
||||
"5 - cdevMessage with a character string",
|
||||
"6 - cdevMessage with an array of integers",
|
||||
"7 - cdevMessage with an array of floats",
|
||||
"8 - cdevMessage with an array of doubles",
|
||||
"9 - cdevMessage with an array of strings"
|
||||
};
|
||||
|
||||
typedef cdevData * (*PayloadFunc)(int cnt);
|
||||
|
||||
PayloadFunc payloadFunc[payloadCount] =
|
||||
{
|
||||
NULL,
|
||||
createPayload1,
|
||||
createPayload2,
|
||||
createPayload3,
|
||||
createPayload4,
|
||||
createPayload5,
|
||||
createPayload2,
|
||||
createPayload3,
|
||||
createPayload4,
|
||||
createPayload5
|
||||
};
|
||||
|
||||
int main ( int argc, char ** argv )
|
||||
{
|
||||
int i;
|
||||
int payload = 0;
|
||||
int payloadItems = 0;
|
||||
int count = -1;
|
||||
|
||||
if(argc>1) for(i=1; i<argc; i++)
|
||||
{
|
||||
if(*argv[i]!='-') goto QUIT_LABEL;
|
||||
else {
|
||||
if((i+1)>=argc) goto QUIT_LABEL;
|
||||
|
||||
switch (argv[i][1])
|
||||
{
|
||||
case 'd': // (d)evice
|
||||
deviceName = strdup(argv[++i]);
|
||||
break;
|
||||
|
||||
case 'm': // (m)essage
|
||||
messageStr = strdup(argv[++i]);
|
||||
break;
|
||||
|
||||
case 't': // payload (t)ype
|
||||
payload = atoi(argv[++i]);
|
||||
break;
|
||||
|
||||
case 'e': // payload (e)lements
|
||||
payloadItems = atoi(argv[++i]);
|
||||
break;
|
||||
|
||||
case 'b': // (b)unch size
|
||||
bunchSize = atoi(argv[++i]);
|
||||
break;
|
||||
|
||||
case 'f': // report (f)requency
|
||||
reportFrequency = atoi(argv[++i]);
|
||||
break;
|
||||
|
||||
case 'c': // packet (c)ount
|
||||
count = atoi(argv[++i]);
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
default:
|
||||
QUIT_LABEL:
|
||||
printf("\nFormat is: PerformanceTest -d dev -m msg -t type -e elements -b bunch -f freq -c count\n");
|
||||
printf(" -d dev ... where dev is the name of the cdev device\n");
|
||||
printf(" -m msg ... where msg is the cdev message string\n");
|
||||
printf(" -t type ... where type is the outbound data's payload type\n");
|
||||
for(int x=1; x<payloadCount; x++)
|
||||
{
|
||||
printf(" %s\n", payloadType[x]);
|
||||
}
|
||||
printf(" -e elements ... where elements is the number of array elements\n");
|
||||
printf(" -b bunch ... where bunch is the number to send before waiting\n");
|
||||
printf(" -f freq ... where freq is the report frequency\n");
|
||||
printf(" -c count ... where count is the number of messages to send\n\n");
|
||||
fflush(stdout);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cdevCallback sb(synchroCallback, NULL);
|
||||
cdevCallback cb(callback, NULL);
|
||||
cdevData * data = NULL;
|
||||
cdevData syncData;
|
||||
|
||||
if(payload<1 || payload>=payloadCount)
|
||||
{
|
||||
fprintf(stdout, "Payload type specifies the type of data that will\n");
|
||||
fprintf(stdout, "transmitted in each message...\n");
|
||||
for(i=1; i<payloadCount; i++)
|
||||
{
|
||||
fprintf(stdout, " %s\n", payloadType[i]);
|
||||
}
|
||||
fprintf(stdout, "\n");
|
||||
|
||||
while(payload<1 || payload>=payloadCount)
|
||||
{
|
||||
fprintf(stdout, "Enter payload type (1 - %i): ", payloadCount-1);
|
||||
fscanf (stdin, "%ld", &payload);
|
||||
}
|
||||
}
|
||||
|
||||
if(payload>5)
|
||||
{
|
||||
if(payloadItems<1)
|
||||
{
|
||||
for(payloadItems = 0; payloadItems<1; )
|
||||
{
|
||||
fprintf(stdout, "Enter the number of array elements: ");
|
||||
fscanf(stdin, "%ld", &payloadItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
else payloadItems = 1;
|
||||
|
||||
data = payloadFunc[payload](payloadItems);
|
||||
|
||||
if(bunchSize<1 || bunchSize>500)
|
||||
{
|
||||
fprintf(stdout, "\nBunch size is the number of packets that will be\n");
|
||||
fprintf(stdout, "transmitted TO the server before the application\n");
|
||||
fprintf(stdout, "pauses to listen for replies FROM the server.\n\n");
|
||||
while(bunchSize<1 || bunchSize>500)
|
||||
{
|
||||
fprintf(stdout, "Enter bunch size (1-500): ");
|
||||
fscanf (stdin, "%ld", &bunchSize);
|
||||
}
|
||||
}
|
||||
|
||||
if(reportFrequency<1)
|
||||
{
|
||||
fprintf(stdout, "\nReport frequency is the number of packets that\n");
|
||||
fprintf(stdout, "should be received from the server before the application\n");
|
||||
fprintf(stdout, "pauses to calculate and report performance information.\n\n");
|
||||
while(reportFrequency<1)
|
||||
{
|
||||
fprintf(stdout, "Enter report frequency (1 - Infinity): ");
|
||||
fscanf (stdin, "%ld", &reportFrequency);
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stdout, "\nStarting Test:\n=> Device : %s\n=> Message : %s\n=> Payload : %s\n=> Packet size : %ld\n=> Bunch size : %ld\n=> Frequency : %ld\n", deviceName, messageStr, payloadType[payload], *packetSizePtr, bunchSize, reportFrequency);
|
||||
if(payloadItems>1) fprintf(stdout, "=> Array Size : %ld\n", payloadItems);
|
||||
if(count>0) fprintf(stdout, "=> Test Length : %ld Packets\n", count);
|
||||
|
||||
cdevRequestObject & req = cdevRequestObject::attachRef(deviceName, messageStr);
|
||||
if(req.send(NULL, NULL)!=CDEV_SUCCESS)
|
||||
{
|
||||
fprintf(stdout, "\nPerformanceTest Error: Request %s %s appears to be invalid\nExiting...\n\n", deviceName, messageStr);
|
||||
fflush(stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
gettimeofday(&first);
|
||||
|
||||
int sendCount = 0;
|
||||
cdevData recvData;
|
||||
|
||||
while(count<0 || sendCount<count )
|
||||
{
|
||||
if(bunchSize==1)
|
||||
{
|
||||
callback(req.send(data, recvData), NULL, req, recvData);
|
||||
sendCount++;
|
||||
}
|
||||
else {
|
||||
for(i=0; i<bunchSize; i++)
|
||||
{
|
||||
req.sendCallback(data, cb);
|
||||
sendCount++;
|
||||
}
|
||||
|
||||
int dryPollCount = 1;
|
||||
do {
|
||||
if(dryPollCount>1000)
|
||||
{
|
||||
fprintf(stdout, "Attempting to resynchronize after polling timeout (%i)\n", dryPollCount);
|
||||
fflush (stdout);
|
||||
}
|
||||
|
||||
synchroFound = 0;
|
||||
synchroValue++;
|
||||
syncData.insert("value", synchroValue);
|
||||
req.sendCallback(syncData, sb);
|
||||
|
||||
while(!synchroFound && dryPollCount%10!=0)
|
||||
{
|
||||
if(cdevSystem::defaultSystem().poll()<=0) dryPollCount++;
|
||||
else dryPollCount=0;
|
||||
}
|
||||
dryPollCount++;
|
||||
} while(!synchroFound);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,347 @@
|
||||
#include <cdevPlatforms.h>
|
||||
#include <cdevSystem.h>
|
||||
#include <cdevRequestObject.h>
|
||||
#include <cdevDevice.h>
|
||||
#include <cdevGroup.h>
|
||||
#include <cdevCommon.h>
|
||||
#include <cdevMessage.h>
|
||||
|
||||
void callback ( int status, void *, cdevRequestObject & req, cdevData & data );
|
||||
|
||||
struct timeval first;
|
||||
int testLength = 0x0FFFFFFF;
|
||||
int callbackCount = 0;
|
||||
int reportCount = 0;
|
||||
int reportFrequency = 0;
|
||||
int bunchSize = 0;
|
||||
char * deviceName = "device0";
|
||||
char * messageStr = "set attrib0";
|
||||
double PerformanceRate = 0.0;
|
||||
double * performanceRatePtr = &PerformanceRate;
|
||||
size_t PacketSize = 0;
|
||||
size_t * packetSizePtr = &PacketSize;
|
||||
cdevCallback cb(callback, NULL);
|
||||
|
||||
void callback ( int status, void *, cdevRequestObject & req, cdevData & data )
|
||||
{
|
||||
if(status==CDEV_SUCCESS)
|
||||
{
|
||||
callbackCount++;
|
||||
reportCount++;
|
||||
|
||||
if(reportCount==reportFrequency)
|
||||
{
|
||||
reportCount = 0;
|
||||
struct timeval second, lapsed;
|
||||
|
||||
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;
|
||||
|
||||
if(lapsed.tv_sec)
|
||||
{
|
||||
*performanceRatePtr = (double)callbackCount/(double)lapsed.tv_sec;
|
||||
fprintf(stdout, "Average rate is %lf pkts/sec after %ld packets\n", *performanceRatePtr, callbackCount);
|
||||
}
|
||||
fflush(stdout);
|
||||
|
||||
if(callbackCount>=testLength)
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
req.sendCallback(data, cb);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cdevData * createPayload1 ( int )
|
||||
{
|
||||
char * binary = 0;
|
||||
cdevMessage msg(1, 1, 0, 0, 0, 0, 0, 1, &deviceName, messageStr);
|
||||
msg.streamOut(&binary, packetSizePtr);
|
||||
delete binary;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cdevData * createPayload2 ( int cnt )
|
||||
{
|
||||
cdevData * data = new cdevData;
|
||||
if(cnt>1)
|
||||
{
|
||||
int * x = new int[cnt];
|
||||
for(int i=0; i<cnt; i++) x[i] = (int)i;
|
||||
data->insert("value", x, cnt);
|
||||
delete x;
|
||||
}
|
||||
else data->insert("value", 1);
|
||||
|
||||
char * binary = 0;
|
||||
cdevMessage msg(1, 1, 0, 0, 0, 0, 0, 1, &deviceName, messageStr, data);
|
||||
msg.streamOut(&binary, packetSizePtr);
|
||||
delete binary;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
cdevData * createPayload3 ( int cnt )
|
||||
{
|
||||
cdevData * data = new cdevData;
|
||||
if(cnt>1)
|
||||
{
|
||||
float * x = new float[cnt];
|
||||
for(int i=0; i<cnt; i++) x[i] = (float)i;
|
||||
data->insert("value", x, cnt);
|
||||
delete x;
|
||||
}
|
||||
else data->insert("value", (float)1.0);
|
||||
|
||||
char * binary = 0;
|
||||
cdevMessage msg(1, 1, 0, 0, 0, 0, 0, 1, &deviceName, messageStr, data);
|
||||
msg.streamOut(&binary, packetSizePtr);
|
||||
delete binary;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
cdevData * createPayload4 ( int cnt )
|
||||
{
|
||||
cdevData * data = new cdevData;
|
||||
if(cnt>1)
|
||||
{
|
||||
double * x = new double[cnt];
|
||||
for(int i=0; i<cnt; i++) x[i] = (double)i;
|
||||
data->insert("value", x, cnt);
|
||||
delete x;
|
||||
}
|
||||
else data->insert("value", (double)1.0);
|
||||
|
||||
char * binary = 0;
|
||||
cdevMessage msg(1, 1, 0, 0, 0, 0, 0, 1, &deviceName, messageStr, data);
|
||||
msg.streamOut(&binary, packetSizePtr);
|
||||
delete binary;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
cdevData * createPayload5 ( int cnt )
|
||||
{
|
||||
cdevData * data = new cdevData;
|
||||
char buf[64];
|
||||
|
||||
if(cnt>1)
|
||||
{
|
||||
char ** x = new char *[cnt];
|
||||
int i;
|
||||
for(i=0; i<cnt; i++)
|
||||
{
|
||||
sprintf(buf, "This is string %i", i);
|
||||
x[i] = strdup(buf);
|
||||
}
|
||||
data->insert("value", x, cnt);
|
||||
for(i=0; i<cnt; i++)
|
||||
{
|
||||
free(x[i]);
|
||||
}
|
||||
delete x;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(buf, "This is string 0");
|
||||
data->insert("value", buf);
|
||||
}
|
||||
|
||||
char * binary = 0;
|
||||
cdevMessage msg(1, 1, 0, 0, 0, 0, 0, 1, &deviceName, messageStr, data);
|
||||
|
||||
msg.streamOut(&binary, packetSizePtr);
|
||||
delete binary;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
const int payloadCount = 10;
|
||||
|
||||
char * payloadType[payloadCount] =
|
||||
{
|
||||
"None",
|
||||
"1 - Barebones cdevMessage",
|
||||
"2 - cdevMessage with one integer value",
|
||||
"3 - cdevMessage with one float value",
|
||||
"4 - cdevMessage with one double value",
|
||||
"5 - cdevMessage with a character string",
|
||||
"6 - cdevMessage with an array of integers",
|
||||
"7 - cdevMessage with an array of floats",
|
||||
"8 - cdevMessage with an array of doubles",
|
||||
"9 - cdevMessage with an array of strings"
|
||||
};
|
||||
|
||||
typedef cdevData * (*PayloadFunc)(int cnt);
|
||||
|
||||
PayloadFunc payloadFunc[payloadCount] =
|
||||
{
|
||||
NULL,
|
||||
createPayload1,
|
||||
createPayload2,
|
||||
createPayload3,
|
||||
createPayload4,
|
||||
createPayload5,
|
||||
createPayload2,
|
||||
createPayload3,
|
||||
createPayload4,
|
||||
createPayload5
|
||||
};
|
||||
|
||||
int main ( int argc, char ** argv )
|
||||
{
|
||||
int i;
|
||||
int payload = 0;
|
||||
int payloadItems = 0;
|
||||
|
||||
if(argc>1) for(i=1; i<argc; i++)
|
||||
{
|
||||
if(*argv[i]!='-') goto QUIT_LABEL;
|
||||
else {
|
||||
if((i+1)>=argc) goto QUIT_LABEL;
|
||||
|
||||
switch (argv[i][1])
|
||||
{
|
||||
case 'd': // (d)evice
|
||||
deviceName = strdup(argv[++i]);
|
||||
break;
|
||||
|
||||
case 'm': // (m)essage
|
||||
messageStr = strdup(argv[++i]);
|
||||
break;
|
||||
|
||||
case 't': // payload (t)ype
|
||||
payload = atoi(argv[++i]);
|
||||
break;
|
||||
|
||||
case 'e': // payload (e)lements
|
||||
payloadItems = atoi(argv[++i]);
|
||||
break;
|
||||
|
||||
case 'b': // (b)unch size
|
||||
bunchSize = atoi(argv[++i]);
|
||||
break;
|
||||
|
||||
case 'f': // report (f)requency
|
||||
reportFrequency = atoi(argv[++i]);
|
||||
break;
|
||||
|
||||
case 'c': // packet (c)ount
|
||||
testLength = atoi(argv[++i]);
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
default:
|
||||
QUIT_LABEL:
|
||||
printf("\nFormat is: PerformanceTest -d dev -m msg -t type -e elements -b bunch -f freq -c count\n");
|
||||
printf(" -d dev ... where dev is the name of the cdev device\n");
|
||||
printf(" -m msg ... where msg is the cdev message string\n");
|
||||
printf(" -t type ... where type is the outbound data's payload type\n");
|
||||
for(int x=1; x<payloadCount; x++)
|
||||
{
|
||||
printf(" %s\n", payloadType[x]);
|
||||
}
|
||||
printf(" -e elements ... where elements is the number of array elements\n");
|
||||
printf(" -b bunch ... where bunch is the number to send before waiting\n");
|
||||
printf(" -f freq ... where freq is the report frequency\n");
|
||||
printf(" -c count ... where count is the number of messages to send\n\n");
|
||||
fflush(stdout);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cdevData * data = NULL;
|
||||
|
||||
if(payload<1 || payload>=payloadCount)
|
||||
{
|
||||
fprintf(stdout, "Payload type specifies the type of data that will\n");
|
||||
fprintf(stdout, "transmitted in each message...\n");
|
||||
for(i=1; i<payloadCount; i++)
|
||||
{
|
||||
fprintf(stdout, " %s\n", payloadType[i]);
|
||||
}
|
||||
fprintf(stdout, "\n");
|
||||
|
||||
while(payload<1 || payload>=payloadCount)
|
||||
{
|
||||
fprintf(stdout, "Enter payload type (1 - %i): ", payloadCount-1);
|
||||
fscanf (stdin, "%ld", &payload);
|
||||
}
|
||||
}
|
||||
|
||||
if(payload>5)
|
||||
{
|
||||
if(payloadItems<1)
|
||||
{
|
||||
for(payloadItems = 0; payloadItems<1; )
|
||||
{
|
||||
fprintf(stdout, "Enter the number of array elements: ");
|
||||
fscanf(stdin, "%ld", &payloadItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
else payloadItems = 1;
|
||||
|
||||
data = payloadFunc[payload](payloadItems);
|
||||
|
||||
if(bunchSize<1 || bunchSize>500)
|
||||
{
|
||||
fprintf(stdout, "\nBunch size is the number of packets that will be\n");
|
||||
fprintf(stdout, "transmitted TO the server before the application\n");
|
||||
fprintf(stdout, "pauses to listen for replies FROM the server.\n\n");
|
||||
while(bunchSize<1 || bunchSize>500)
|
||||
{
|
||||
fprintf(stdout, "Enter bunch size (1-500): ");
|
||||
fscanf (stdin, "%ld", &bunchSize);
|
||||
}
|
||||
}
|
||||
|
||||
if(reportFrequency<1)
|
||||
{
|
||||
fprintf(stdout, "\nReport frequency is the number of packets that\n");
|
||||
fprintf(stdout, "should be received from the server before the application\n");
|
||||
fprintf(stdout, "pauses to calculate and report performance information.\n\n");
|
||||
while(reportFrequency<1)
|
||||
{
|
||||
fprintf(stdout, "Enter report frequency (1 - Infinity): ");
|
||||
fscanf (stdin, "%ld", &reportFrequency);
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stdout, "\nStarting Test:\n=> Device : %s\n=> Message : %s\n=> Payload : %s\n=> Packet size : %ld\n=> Bunch size : %ld\n=> Frequency : %ld\n", deviceName, messageStr, payloadType[payload], *packetSizePtr, bunchSize, reportFrequency);
|
||||
if(payloadItems>1) fprintf(stdout, "=> Array Size : %ld\n", payloadItems);
|
||||
fprintf(stdout, "=> Test Length : %ld Packets\n", testLength);
|
||||
|
||||
cdevRequestObject & req = cdevRequestObject::attachRef(deviceName, messageStr);
|
||||
if(req.send(NULL, NULL)!=CDEV_SUCCESS)
|
||||
{
|
||||
fprintf(stdout, "\nPerformanceTest Error: Request %s %s appears to be invalid\nExiting...\n\n", deviceName, messageStr);
|
||||
fflush(stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
gettimeofday(&first);
|
||||
|
||||
for(i=0; i<bunchSize; i++) req.sendCallback(data, cb);
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
cdevSystem::defaultSystem().pend(10.0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#! /bin/tcsh
|
||||
setenv CDEVDDL ${PWD}/Performance.ddl
|
||||
|
||||
if ( $?CDEV_NAME_SERVER == 0 ) then
|
||||
echo '/nCDEV_NAME_SERVER must be specified/n'
|
||||
exit
|
||||
endif
|
||||
|
||||
if ( $?CDEV_ARCH == 0 ) then
|
||||
echo '/nCDEV_ARCH must be specified (Linux, ${CDEV_ARCH}, hpux-10.20, ...)/n'
|
||||
exit
|
||||
endif
|
||||
|
||||
../../bin/${CDEV_ARCH}/PerformanceTest2 -d device0 -m "set attrib0" -t 6 -e 262144 -b 10 -f 50 -c 1000
|
||||
../../bin/${CDEV_ARCH}/PerformanceTest2 -d device0 -m "set attrib0" -t 6 -e 65536 -b 10 -f 50 -c 1000
|
||||
../../bin/${CDEV_ARCH}/PerformanceTest2 -d device0 -m "set attrib0" -t 6 -e 32768 -b 10 -f 50 -c 1000
|
||||
../../bin/${CDEV_ARCH}/PerformanceTest2 -d device0 -m "set attrib0" -t 6 -e 16384 -b 10 -f 50 -c 1000
|
||||
../../bin/${CDEV_ARCH}/PerformanceTest2 -d device0 -m "set attrib0" -t 6 -e 8192 -b 50 -f 50 -c 1000
|
||||
../../bin/${CDEV_ARCH}/PerformanceTest2 -d device0 -m "set attrib0" -t 6 -e 4096 -b 100 -f 100 -c 1000
|
||||
../../bin/${CDEV_ARCH}/PerformanceTest2 -d device0 -m "set attrib0" -t 6 -e 1024 -b 500 -f 500 -c 3000
|
||||
../../bin/${CDEV_ARCH}/PerformanceTest2 -d device0 -m "set attrib0" -t 6 -e 256 -b 500 -f 1000 -c 10000
|
||||
../../bin/${CDEV_ARCH}/PerformanceTest2 -d device0 -m "set attrib0" -t 6 -e 64 -b 500 -f 4000 -c 40000
|
||||
../../bin/${CDEV_ARCH}/PerformanceTest2 -d device0 -m "set attrib0" -t 2 -e 1 -b 500 -f 10000 -c 100000
|
||||
../../bin/${CDEV_ARCH}/PerformanceTest2 -d device0 -m "set attrib0" -t 1 -e 1 -b 500 -f 10000 -c 100000
|
||||
@@ -0,0 +1,12 @@
|
||||
@echo off
|
||||
..\..\bin\WINNT-4.0\PerformanceTest -d device0 -m "set attrib0" -t 1 -e 1 -b 500 -f 100000 -c 100000
|
||||
..\..\bin\WINNT-4.0\PerformanceTest -d device0 -m "set attrib0" -t 2 -e 1 -b 500 -f 100000 -c 100000
|
||||
..\..\bin\WINNT-4.0\PerformanceTest -d device0 -m "set attrib0" -t 6 -e 64 -b 500 -f 40000 -c 40000
|
||||
..\..\bin\WINNT-4.0\PerformanceTest -d device0 -m "set attrib0" -t 6 -e 256 -b 500 -f 11000 -c 11000
|
||||
..\..\bin\WINNT-4.0\PerformanceTest -d device0 -m "set attrib0" -t 6 -e 1024 -b 500 -f 3000 -c 3000
|
||||
..\..\bin\WINNT-4.0\PerformanceTest -d device0 -m "set attrib0" -t 6 -e 4096 -b 100 -f 800 -c 800
|
||||
..\..\bin\WINNT-4.0\PerformanceTest -d device0 -m "set attrib0" -t 6 -e 8192 -b 50 -f 400 -c 400
|
||||
..\..\bin\WINNT-4.0\PerformanceTest -d device0 -m "set attrib0" -t 6 -e 16384 -b 1 -f 200 -c 200
|
||||
..\..\bin\WINNT-4.0\PerformanceTest -d device0 -m "set attrib0" -t 6 -e 32768 -b 1 -f 100 -c 100
|
||||
..\..\bin\WINNT-4.0\PerformanceTest -d device0 -m "set attrib0" -t 6 -e 65536 -b 1 -f 50 -c 50
|
||||
..\..\bin\WINNT-4.0\PerformanceTest -d device0 -m "set attrib0" -t 6 -e 262144 -b 1 -f 12 -c 12
|
||||
@@ -0,0 +1,29 @@
|
||||
#include <cdevPlatforms.h>
|
||||
#include <cdevSystem.h>
|
||||
#include <cdevRequestObject.h>
|
||||
#include <cdevDevice.h>
|
||||
|
||||
void callback (int status, void * arg, cdevRequestObject &req, cdevData & data)
|
||||
{
|
||||
fprintf(stdout, "Received callback with status %i\n", status);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
int main ( )
|
||||
{
|
||||
cdevRequestObject & setReq = cdevRequestObject::attachRef("device0", "set attrib1");
|
||||
cdevCallback cb (callback, NULL);
|
||||
cdevData data;
|
||||
|
||||
data.insert("value", 1);
|
||||
|
||||
setReq.sendCallback(data, cb);
|
||||
cdevSystem::defaultSystem().pend();
|
||||
|
||||
fprintf(stdout, "Enter a character after you stop and restart the server\n");
|
||||
getc(stdin);
|
||||
|
||||
setReq.sendCallback(data, cb);
|
||||
cdevSystem::defaultSystem().pend();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
ARCH = OS
|
||||
SHOBJ = YES
|
||||
|
||||
include ../../include/makeinclude/Makefile.$(ARCH)
|
||||
|
||||
APPNAME = "Sync/Async Test Client"
|
||||
CXXINCLUDES = -I./
|
||||
|
||||
ifeq ($(SHOBJ), YES)
|
||||
LIBS = -L$(CDEVLIB) -lcdevGenericServer $(CDEVLIBS) $(OSLIBS)
|
||||
TARGETS = $(BASEBIN)/SyncSet $(BASEBIN)/AsyncSet
|
||||
else
|
||||
LIBS = -L$(CDEVLIB) -lcdevGenericServer $(CDEVLIBS) $(OSLIBS)
|
||||
TARGETS = $(BASEBIN)/SyncSet $(BASEBIN)/AsyncSet
|
||||
endif
|
||||
|
||||
|
||||
targets : $(TARGETS)
|
||||
|
||||
$(BASEBIN)/AsyncSet : $(OBJDIR)/AsyncSet.o
|
||||
$(LINK.cc) $^ -o $@ $(LIBS)
|
||||
|
||||
$(BASEBIN)/SyncSet : $(OBJDIR)/SyncSet.o
|
||||
$(LINK.cc) $^ -o $@ $(LIBS)
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
.SUFFIXES: .cc .obj
|
||||
|
||||
APPNAME = Sync/Async Test Client
|
||||
ARCH = WINNT-4.0
|
||||
SHOBJ = YES
|
||||
|
||||
BINARIES = $(BASEBIN)\AsyncSet.exe $(BASEBIN)\SyncSet.exe
|
||||
|
||||
include ..\..\include\makeinclude\Makefile.WINNT-4.0
|
||||
|
||||
CXXINCLUDES = /I .\\
|
||||
|
||||
targets : $(BINARIES)
|
||||
|
||||
$(BASEBIN)\AsyncSet.exe : .exec\$(TARGETDIR)\AsyncSet.obj
|
||||
-@if exist $@ erase $@
|
||||
@echo ^ ^ ^ ^ ^ ^ =^> Linking $(@F)
|
||||
$(LINK) $(CDEVLIB)\cdev.lib $(CDEVLIB)\cdevGenericServer.lib \
|
||||
$(LINK_EXE_FLAGS) /out:$@ $?
|
||||
@echo ^ ^ ^ ^ ^ ^ ^ ^ ^ Done...
|
||||
|
||||
$(BASEBIN)\SyncSet.exe : .exec\$(TARGETDIR)\SyncSet.obj
|
||||
-@if exist $@ erase $@
|
||||
@echo ^ ^ ^ ^ ^ ^ =^> Linking $(@F)
|
||||
$(LINK) $(CDEVLIB)\cdev.lib $(CDEVLIB)\cdevGenericServer.lib \
|
||||
$(LINK_EXE_FLAGS) /out:$@ $?
|
||||
@echo ^ ^ ^ ^ ^ ^ ^ ^ ^ Done...
|
||||
@@ -0,0 +1,21 @@
|
||||
#include <cdevPlatforms.h>
|
||||
#include <cdevSystem.h>
|
||||
#include <cdevRequestObject.h>
|
||||
#include <cdevDevice.h>
|
||||
|
||||
|
||||
int main ( )
|
||||
{
|
||||
cdevRequestObject & setReq = cdevRequestObject::attachRef("device0", "set attrib1");
|
||||
cdevData data;
|
||||
|
||||
data.insert("value", 1);
|
||||
|
||||
setReq.send(data, NULL);
|
||||
|
||||
fprintf(stdout, "Enter a character after you stop and restart the server\n");
|
||||
getc(stdin);
|
||||
|
||||
setReq.send(data, NULL);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
service Gateway
|
||||
{
|
||||
tags {server}
|
||||
}
|
||||
|
||||
class Tests
|
||||
{
|
||||
verbs {get, set}
|
||||
attributes
|
||||
{
|
||||
default Gateway;
|
||||
clientID Gateway;
|
||||
servers Gateway;
|
||||
connections Gateway;
|
||||
attrib Gateway {server=Gateway1};
|
||||
ClientInfo Gateway {server=Gateway1};
|
||||
ServerInfo Gateway {server=Gateway1};
|
||||
}
|
||||
messages
|
||||
{
|
||||
shutdown Gateway;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Tests :
|
||||
device1,
|
||||
device2,
|
||||
device3
|
||||
;
|
||||
@@ -0,0 +1,4 @@
|
||||
all commit clean purge:
|
||||
@$(MAKE) $@ -f Makefile.service
|
||||
@$(MAKE) $@ -f Makefile.server
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
ARCH = OS
|
||||
SHOBJ = YES
|
||||
|
||||
include ../../include/makeinclude/Makefile.$(ARCH)
|
||||
|
||||
APPNAME = "Transmission Test Server"
|
||||
OUTPUTDIR = $(BASEBIN)
|
||||
CXXINCLUDES = -I./
|
||||
LIBS = -L$(CDEVLIB) -lcdevGenericServer $(CDEVLIBS) $(OSLIBS)
|
||||
|
||||
TARGETS = $(OUTPUTDIR)/TestServer
|
||||
|
||||
targets : $(TARGETS)
|
||||
|
||||
$(OUTPUTDIR)/TestServer : $(OBJDIR)/TestServer.o
|
||||
$(LINK.cc) $^ $(LIBS) -o $@
|
||||
@@ -0,0 +1,37 @@
|
||||
ARCH = OS
|
||||
SHOBJ = YES
|
||||
|
||||
include ../../include/makeinclude/Makefile.$(ARCH)
|
||||
|
||||
APPNAME = "Transmission Test Client"
|
||||
CXXINCLUDES = -I./
|
||||
|
||||
# ******************************************************************************
|
||||
# * The BINARIES definition names all of the binary files that should be deleted
|
||||
# * whenever "make clean" is executed.
|
||||
# ******************************************************************************
|
||||
BINARIES = $(BASELIB)/libTestService.a \
|
||||
$(BASELIB)/TestService.so \
|
||||
$(BASEBIN)/TestProgram
|
||||
|
||||
ifeq ($(SHOBJ), YES)
|
||||
LIBS = -L$(CDEVLIB) -lcdevGenericServer $(CDEVLIBS) $(OSLIBS)
|
||||
TARGETS = $(BASELIB)/TestService.so $(BASEBIN)/TestProgram
|
||||
else
|
||||
LIBS = -L$(CDEVLIB) -lcdevGenericServer $(CDEVLIBS) $(OSLIBS)
|
||||
TARGETS = $(BASELIB)/libTestService.a $(BASEBIN)/TestProgram
|
||||
endif
|
||||
|
||||
targets : $(TARGETS)
|
||||
|
||||
$(BASELIB)/TestService.so : $(OBJDIR)/TestService.o
|
||||
$(LINK.so) -o $@ $^ -L$(CDEVLIB) -lcdevGenericServer $(NETLIBS)
|
||||
@mkdir -p $(CDEVSHOBJ)/$(CDEVVERSION)
|
||||
@cp $@ $(CDEVSHOBJ)/$(CDEVVERSION)/$(@F)
|
||||
|
||||
$(BASELIB)/libTestService.a : $(OBJDIR)/TestService.o
|
||||
$(LINK.a) $@ $^
|
||||
@$(RANLIB) $@ > /dev/null
|
||||
|
||||
$(BASEBIN)/TestProgram : $(OBJDIR)/TestProgram.o
|
||||
$(LINK.cc) $^ -o $@ $(LIBS)
|
||||
@@ -0,0 +1,6 @@
|
||||
notarget : all
|
||||
|
||||
all clean purge:
|
||||
@$(MAKE) /NOLOGO $@ -f NMakefile.service
|
||||
@$(MAKE) /NOLOGO $@ -f NMakefile.server
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
.SUFFIXES: .cc .obj
|
||||
|
||||
APPNAME = Transmission Test Server
|
||||
ARCH = WINNT-4.0
|
||||
SHOBJ = YES
|
||||
|
||||
BINARIES = $(BASEBIN)\TestServer.exe
|
||||
|
||||
include ..\..\include\makeinclude\Makefile.WINNT-4.0
|
||||
|
||||
CXXINCLUDES = /I .\\
|
||||
|
||||
targets : $(BINARIES)
|
||||
|
||||
$(BASEBIN)\TestServer.exe : .exec\$(TARGETDIR)\TestServer.obj
|
||||
-@if exist $@ erase $@
|
||||
@echo ^ ^ ^ ^ ^ ^ =^> Linking $(@F)
|
||||
$(LINK) $(CDEVLIB)\cdev.lib $(CDEVLIB)\cdevGenericServer.lib \
|
||||
$(LINK_EXE_FLAGS) /out:$@ $?
|
||||
@echo ^ ^ ^ ^ ^ ^ ^ ^ ^ Done...
|
||||
@@ -0,0 +1,49 @@
|
||||
.SUFFIXES: .cc .obj
|
||||
|
||||
|
||||
APPNAME = Transmission Test Client
|
||||
ARCH = WINNT-4.0
|
||||
SHOBJ = YES
|
||||
|
||||
BINARIES = $(CDEVLIB)\TestService.lib \
|
||||
$(CDEVLIB)\TestService.dll \
|
||||
$(BASEBIN)\TestProgram.exe
|
||||
|
||||
include ..\..\include\makeinclude\Makefile.WINNT-4.0
|
||||
|
||||
CXXINCLUDES = /I .\\
|
||||
CXXEXTRA_DLL = /D "TEST_SERVICE_API=__declspec(dllexport)"
|
||||
CXXEXTRA_LIB = /D "TEST_SERVICE_API="
|
||||
|
||||
!IF "$(SHOBJ)" == "YES"
|
||||
TARGETS = $(CDEVLIB)\TestService.dll $(BASEBIN)\TestProgram.exe
|
||||
!ELSE
|
||||
TARGETS = $(CDEVLIB)\TestService.lib $(BASEBIN)\TestProgram.exe
|
||||
!ENDIF
|
||||
|
||||
targets : $(TARGETS)
|
||||
|
||||
$(CDEVLIB)\TestService.dll : $(OBJDIR)\TestService.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)\TestService.lib : $(OBJDIR)\TestService.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)\TestProgram.exe : .exec\$(TARGETDIR)\TestProgram.obj
|
||||
-@if exist $@ erase $@
|
||||
@echo ^ ^ ^ ^ ^ ^ =^> Linking $(@F)
|
||||
$(LINK) $(CDEVLIB)\cdev.lib $(CDEVLIB)\cdevGenericServer.lib\
|
||||
$(LINK_EXE_FLAGS) /out:$@ $?
|
||||
@echo ^ ^ ^ ^ ^ ^ ^ ^ ^ Done...
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
#include <ctype.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <cdevSystem.h>
|
||||
#include <cdevRequestObject.h>
|
||||
#include <cdevDevice.h>
|
||||
#include <cdevGroup.h>
|
||||
#include <cdevCommon.h>
|
||||
#include <testMessages.cc>
|
||||
|
||||
int fouled = 0;
|
||||
int expectedHits = 0;
|
||||
int hits = 0;
|
||||
unsigned totalCount = 0;
|
||||
|
||||
void callback ( int status, void * arg, cdevRequestObject &, cdevData & data)
|
||||
{
|
||||
hits++;
|
||||
if(status!=CDEV_SUCCESS)
|
||||
{
|
||||
printf("ERROR: Transmission failure of %i\n", (int)arg);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(data!=*TestMessage[(int)arg].getData())
|
||||
{
|
||||
fouled = 1;
|
||||
printf("ERROR: Mismatch on entry %i - Inbound data differs from expected\n",
|
||||
(int)arg);
|
||||
printf("----------------------------- INBOUND DATA -----------------------------\n");
|
||||
data.asciiDump();
|
||||
printf("----------------------------- EXPECTED DATA ----------------------------\n");
|
||||
TestMessage[(int)arg].getData()->asciiDump();
|
||||
}
|
||||
else
|
||||
{
|
||||
totalCount++;
|
||||
if(totalCount%100==0)
|
||||
{
|
||||
printf("Transmission %i still matches correctly\n", totalCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
createTestMessages();
|
||||
int maxCount = 0;
|
||||
int group1 = TestMessageCount/3;
|
||||
int group2 = group1+group1;
|
||||
|
||||
cdevRequestObject &tReq = cdevRequestObject::attachRef(TestMessage[TestMessageIndex].getDeviceList()[0], TestMessage[TestMessageIndex].getMessage());
|
||||
tReq.setContext(*TestMessage[0].getContext());
|
||||
|
||||
if(argc>1) maxCount = atoi(argv[1]);
|
||||
|
||||
while(!fouled && (!maxCount || maxCount<totalCount))
|
||||
{
|
||||
hits = 0;
|
||||
expectedHits = 0;
|
||||
|
||||
for(TestMessageIndex = 0; TestMessageIndex<group1; TestMessageIndex++)
|
||||
{
|
||||
int mismatch = 0;
|
||||
cdevData data;
|
||||
cdevRequestObject * req = cdevRequestObject::attachPtr(TestMessage[TestMessageIndex].getDeviceList()[0], TestMessage[TestMessageIndex].getMessage());
|
||||
req->setContext(*TestMessage[TestMessageIndex].getContext());
|
||||
|
||||
if(req->send(TestMessage[TestMessageIndex].getData(), &data)==CDEV_SUCCESS)
|
||||
{
|
||||
if(data!=*TestMessage[TestMessageIndex].getData())
|
||||
{
|
||||
fouled = -1;
|
||||
printf("ERROR: Mismatch on entry %i - Inbound data differs from expected\n",
|
||||
TestMessageIndex);
|
||||
printf("----------------------------- INBOUND DATA -----------------------------\n");
|
||||
data.asciiDump();
|
||||
printf("----------------------------- EXPECTED DATA ----------------------------\n");
|
||||
TestMessage[TestMessageIndex].getData()->asciiDump();
|
||||
}
|
||||
else
|
||||
{
|
||||
totalCount++;
|
||||
if(totalCount%100==0)
|
||||
{
|
||||
printf("Transmission %i still matches correctly\n", totalCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("ERROR: Transmission failure of %i\n",
|
||||
TestMessageIndex);
|
||||
}
|
||||
}
|
||||
|
||||
for( ; TestMessageIndex<group2; TestMessageIndex++)
|
||||
{
|
||||
cdevCallback cb(callback, (void *)TestMessageIndex);
|
||||
int mismatch = 0;
|
||||
cdevData data;
|
||||
cdevRequestObject * req = cdevRequestObject::attachPtr(TestMessage[TestMessageIndex].getDeviceList()[0], TestMessage[TestMessageIndex].getMessage());
|
||||
req->setContext(*TestMessage[TestMessageIndex].getContext());
|
||||
|
||||
if(req->sendCallback(TestMessage[TestMessageIndex].getData(), cb)!=CDEV_SUCCESS)
|
||||
{
|
||||
fouled = -1;
|
||||
printf("ERROR: Transmission failure of %i\n",
|
||||
TestMessageIndex);
|
||||
}
|
||||
else expectedHits++;
|
||||
}
|
||||
|
||||
for(int retryCnt=0; hits<expectedHits && retryCnt<1000; retryCnt++)
|
||||
{
|
||||
cdevSystem::defaultSystem().poll();
|
||||
}
|
||||
|
||||
if(hits<expectedHits)
|
||||
{
|
||||
printf("ERROR: Processed only %i of %i callback requests after %i attempts\n", hits, expectedHits, retryCnt);
|
||||
}
|
||||
|
||||
cdevData * outputData = new cdevData[TestMessageCount - (group2)];
|
||||
cdevGroup group;
|
||||
|
||||
group.start();
|
||||
for(int dataIdx=0; TestMessageIndex<TestMessageCount; TestMessageIndex++, dataIdx++)
|
||||
{
|
||||
int mismatch = 0;
|
||||
cdevData data;
|
||||
cdevRequestObject * req = cdevRequestObject::attachPtr(TestMessage[TestMessageIndex].getDeviceList()[0], TestMessage[TestMessageIndex].getMessage());
|
||||
req->setContext(*TestMessage[TestMessageIndex].getContext());
|
||||
|
||||
if(req->sendNoBlock(TestMessage[TestMessageIndex].getData(), outputData[dataIdx])!=CDEV_SUCCESS)
|
||||
{
|
||||
fouled = -1;
|
||||
printf("ERROR: Transmission failure of %i\n",
|
||||
TestMessageIndex);
|
||||
}
|
||||
}
|
||||
group.end();
|
||||
|
||||
for(int grpRetryCnt=0; !group.allFinished() && grpRetryCnt<1000; grpRetryCnt++)
|
||||
{
|
||||
group.poll();
|
||||
}
|
||||
|
||||
if(!group.allFinished())
|
||||
{
|
||||
printf("ERROR: Failed to process all group requests after %i attempts\n", grpRetryCnt);
|
||||
}
|
||||
|
||||
for(dataIdx=0, TestMessageIndex=group2; TestMessageIndex<TestMessageCount; TestMessageIndex++, dataIdx++)
|
||||
{
|
||||
if(outputData[dataIdx]!=*TestMessage[TestMessageIndex].getData())
|
||||
{
|
||||
fouled = -1;
|
||||
printf("ERROR: Mismatch on entry %i - Inbound data differs from expected\n",
|
||||
TestMessageIndex);
|
||||
printf("----------------------------- INBOUND DATA -----------------------------\n");
|
||||
outputData[dataIdx].asciiDump();
|
||||
printf("----------------------------- EXPECTED DATA ----------------------------\n");
|
||||
TestMessage[TestMessageIndex].getData()->asciiDump();
|
||||
}
|
||||
else
|
||||
{
|
||||
totalCount++;
|
||||
if(totalCount%100==0)
|
||||
{
|
||||
printf("Transmission %i still matches correctly\n", totalCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
delete [] outputData;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
#include <cdevServer.h>
|
||||
#include <testMessages.cc>
|
||||
|
||||
class myServer : public cdevServer
|
||||
{
|
||||
private:
|
||||
IntHash TestIndexes;
|
||||
unsigned totalCount;
|
||||
|
||||
public:
|
||||
myServer ( void )
|
||||
: cdevServer(), totalCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
myServer ( char * domain, char * server, unsigned int port, double pulse )
|
||||
: cdevServer(domain, server, port, pulse), totalCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void processMessages ( void )
|
||||
{
|
||||
cdevMessage * message;
|
||||
while(dequeue(message)==0)
|
||||
{
|
||||
if(!strcmp(message->getMessage(), "register"))
|
||||
{
|
||||
int * ptr = new int;
|
||||
TestIndexes.insert((int)message->getClientID(), (void *)ptr);
|
||||
printf("Starting Testing on Client %i\n", message->getClientID());
|
||||
}
|
||||
else if(!strcmp(message->getMessage(), "unregister"))
|
||||
{
|
||||
int * ptr = NULL;
|
||||
if((ptr = (int *)TestIndexes.find((int)message->getClientID()))!=NULL)
|
||||
{
|
||||
TestIndexes.remove((int)message->getClientID());
|
||||
delete ptr;
|
||||
}
|
||||
printf("Finishing Testing on Client %i\n", message->getClientID());
|
||||
}
|
||||
else
|
||||
{
|
||||
int ptr = 0;
|
||||
int *idxPtr = (int *)TestIndexes.find((int)message->getClientID());
|
||||
int curPtr = 0;
|
||||
|
||||
if(idxPtr == NULL)
|
||||
{
|
||||
printf("ERROR: Failed to retrieve the index for client %i\n", message->getClientID());
|
||||
idxPtr = &ptr;
|
||||
}
|
||||
if(*idxPtr >= TestMessageCount) *idxPtr = 0;
|
||||
|
||||
if(message->getData()==NULL)
|
||||
{
|
||||
printf("ERROR: NULL data received from client %i\n", message->getClientID());
|
||||
}
|
||||
else
|
||||
{
|
||||
message->getData()->get("packetNumber", &curPtr);
|
||||
if(curPtr!=*idxPtr)
|
||||
{
|
||||
printf("Mismatch between packet number %i and expected %i\n", curPtr, *idxPtr);
|
||||
*idxPtr = curPtr;
|
||||
}
|
||||
|
||||
int mismatch = 0;
|
||||
|
||||
if(strcmp(message->getDeviceList()[0], TestMessage[*idxPtr].getDeviceList()[0]))
|
||||
{
|
||||
printf("ERROR: Client %i mismatch on entry %i - Device \"%s\" not equal to \"%s\"\n",
|
||||
message->getClientID(),
|
||||
*idxPtr,
|
||||
message->getDeviceList()[0],
|
||||
TestMessage[*idxPtr].getDeviceList()[0]);
|
||||
mismatch++;
|
||||
}
|
||||
|
||||
if(strcmp(message->getMessage(), TestMessage[*idxPtr].getMessage()))
|
||||
{
|
||||
printf("ERROR: Client %i mismatch on entry %i - Message \"%s\" not equal to \"%s\"\n",
|
||||
message->getClientID(),
|
||||
*idxPtr,
|
||||
message->getMessage(),
|
||||
TestMessage[*idxPtr].getMessage());
|
||||
mismatch++;
|
||||
}
|
||||
|
||||
if(message->getData()==NULL)
|
||||
{
|
||||
printf("ERROR: Client %i mismatch on entry %i - Inbound data is NULL\n",
|
||||
message->getClientID(),
|
||||
*idxPtr);
|
||||
mismatch++;
|
||||
}
|
||||
else if(*message->getData()!=*TestMessage[*idxPtr].getData())
|
||||
{
|
||||
printf("ERROR: Client %i mismatch on entry %i - Inbound data differs from expected\n",
|
||||
message->getClientID(),
|
||||
*idxPtr);
|
||||
printf("----------------------------- INBOUND DATA -----------------------------\n");
|
||||
message->getData()->asciiDump();
|
||||
printf("----------------------------- EXPECTED DATA ----------------------------\n");
|
||||
TestMessage[*idxPtr].getData()->asciiDump();
|
||||
mismatch++;
|
||||
}
|
||||
|
||||
if(message->getContext()==NULL && TestMessage[*idxPtr].getContext()!=NULL)
|
||||
{
|
||||
printf("ERROR: Client %i mismatch on entry %i - Inbound context is NULL\n",
|
||||
message->getClientID(),
|
||||
*idxPtr);
|
||||
mismatch++;
|
||||
}
|
||||
else if(TestMessage[*idxPtr].getContext()==NULL)
|
||||
{
|
||||
}
|
||||
else if(*message->getContext()!=*TestMessage[*idxPtr].getContext())
|
||||
{
|
||||
printf("ERROR: Client %i mismatch on entry %i - Inbound context differs from expected\n",
|
||||
message->getClientID(),
|
||||
*idxPtr);
|
||||
printf("---------------------------- INBOUND CONTEXT ---------------------------\n");
|
||||
message->getContext()->asciiDump();
|
||||
printf("---------------------------- EXPECTED CONTEXT --------------------------\n");
|
||||
TestMessage[*idxPtr].getContext()->asciiDump();
|
||||
mismatch++;
|
||||
}
|
||||
|
||||
if(mismatch) printf("\n\n");
|
||||
else {
|
||||
totalCount++;
|
||||
if(totalCount%1000==0) printf("Transmission %i still matches correctly\n", totalCount);
|
||||
}
|
||||
(*idxPtr)++;
|
||||
}
|
||||
}
|
||||
enqueue(message);
|
||||
delete message;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
char * name;
|
||||
short port;
|
||||
|
||||
name = (argc>1)?argv[1]:(char *)"TestServer1";
|
||||
port = 0;
|
||||
|
||||
cdevSystem::defaultSystem().setThreshold(CDEV_SEVERITY_INFO);
|
||||
myServer *server = new myServer();
|
||||
server->startServer("TEST", name, port, 60.0, 1);
|
||||
createTestMessages();
|
||||
cdevServer::runServer();
|
||||
delete server;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#include <TestService.h>
|
||||
|
||||
extern "C" cdevService * newTestService ( char * name, cdevSystem * system )
|
||||
{
|
||||
return new TestService(name, *system);
|
||||
}
|
||||
|
||||
TestService::TestService ( char * name, cdevSystem & system)
|
||||
: cdevClientService("TEST", name, system)
|
||||
{
|
||||
system.reportError(CDEV_SEVERITY_INFO, "TestService", NULL,
|
||||
"Constructing a new TestService");
|
||||
}
|
||||
|
||||
TestService::~TestService ( void )
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
service Test
|
||||
{
|
||||
tags {server}
|
||||
}
|
||||
|
||||
class Tests
|
||||
{
|
||||
verbs {get, set}
|
||||
attributes
|
||||
{
|
||||
default Test;
|
||||
clientID Test;
|
||||
servers Test;
|
||||
connections Test;
|
||||
attrib Test {server=TestServer1};
|
||||
ClientInfo Test {server=TestServer1};
|
||||
ServerInfo Test {server=TestServer1};
|
||||
}
|
||||
messages
|
||||
{
|
||||
shutdown Test;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Tests :
|
||||
device1,
|
||||
device2,
|
||||
device3
|
||||
;
|
||||
@@ -0,0 +1,17 @@
|
||||
#include <cdevClientService.h>
|
||||
|
||||
#ifndef TEST_SERVICE_API
|
||||
#define TEST_SERVICE_API
|
||||
#endif
|
||||
|
||||
|
||||
extern "C" TEST_SERVICE_API cdevService * newTestService ( char * name, cdevSystem * system );
|
||||
|
||||
class TestService : public cdevClientService
|
||||
{
|
||||
public:
|
||||
TestService ( char * name, cdevSystem & system = cdevSystem::defaultSystem());
|
||||
|
||||
protected:
|
||||
virtual ~TestService ( void );
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
21 value
|
||||
20 status
|
||||
19 severity
|
||||
18 time
|
||||
17 units
|
||||
16 displayHigh
|
||||
15 displayLow
|
||||
14 alarmHigh
|
||||
13 alarmLow
|
||||
12 warningHigh
|
||||
11 warningLow
|
||||
10 controlHigh
|
||||
9 controlLow
|
||||
8 bitMask
|
||||
7 file
|
||||
6 class
|
||||
5 device
|
||||
4 message
|
||||
3 verb
|
||||
2 attribute
|
||||
1 collection
|
||||
@@ -0,0 +1,45 @@
|
||||
#include <IntHash.h>
|
||||
#include <cdevMessage.h>
|
||||
|
||||
const size_t TestMessageCount = 1000;
|
||||
cdevMessage TestMessage[TestMessageCount];
|
||||
char *TestDeviceName = "device1";
|
||||
int TestMessageIndex = 0;
|
||||
|
||||
void createTestMessages ( void )
|
||||
{
|
||||
cdevData data;
|
||||
cdevData context;
|
||||
|
||||
for(int i=0; i<TestMessageCount; i++)
|
||||
{
|
||||
data.addTag("packetNumber");
|
||||
data.insert("packetNumber", i);
|
||||
data.insert("value", i*18+0);
|
||||
data.insert("status", i*18+1);
|
||||
data.insert("time", i*18+2);
|
||||
data.insert("controlHigh", i*18+3);
|
||||
data.insert("controlLow", i*18+4);
|
||||
data.insert("alarmHigh", i*18+5);
|
||||
data.insert("alarmLow", i*18+6);
|
||||
data.insert("displayHigh", i*18+7);
|
||||
data.insert("displayLow", i*18+8);
|
||||
data.insert("resultCode", 0);
|
||||
|
||||
context.insert("value", i*18+9);
|
||||
context.insert("status", i*18+10);
|
||||
context.insert("time", i*18+11);
|
||||
context.insert("controlHigh", i*18+12);
|
||||
context.insert("controlLow", i*18+13);
|
||||
context.insert("alarmHigh", i*18+14);
|
||||
context.insert("alarmLow", i*18+15);
|
||||
context.insert("displayHigh", i*18+16);
|
||||
context.insert("displayLow", i*18+17);
|
||||
|
||||
TestMessage[i].setClientID (1);
|
||||
TestMessage[i].setDeviceList (&TestDeviceName, 1, 1);
|
||||
TestMessage[i].setMessage ("get attrib", 1);
|
||||
TestMessage[i].setData (new cdevData(data));
|
||||
TestMessage[i].setContext (new cdevData(context));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user