cdev-1.7.2n
This commit is contained in:
417
extensions/cdevGenericServer/include/AddressIndex.h
Normal file
417
extensions/cdevGenericServer/include/AddressIndex.h
Normal file
@@ -0,0 +1,417 @@
|
||||
#ifndef ADDRESS_INDEX_H_
|
||||
#define ADDRESS_INDEX_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// *****************************************************************************
|
||||
// * union AddressReference :
|
||||
// * This union contains all of the components that are necessary to locate
|
||||
// * and validate a memory address from within an AddressIndex object.
|
||||
// *
|
||||
// * The index entry contains the location of the pointer within the address
|
||||
// * array.
|
||||
// *
|
||||
// * The checksum entry contains the checksum value that should be located
|
||||
// * at the specified index within the checksum array.
|
||||
// *
|
||||
// *****************************************************************************
|
||||
typedef union
|
||||
{
|
||||
unsigned rawData;
|
||||
struct {
|
||||
unsigned index : 24;
|
||||
unsigned checksum : 8;
|
||||
} value;
|
||||
} AddressReference;
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * class AddressIndex:
|
||||
// * This class is used to allow an array to be dereferenced using an integer
|
||||
// * code that contains an array index and a checksum value. Both of these
|
||||
// * values are validated before the user is allowed to access the data.
|
||||
// *****************************************************************************
|
||||
class AddressIndex
|
||||
{
|
||||
friend class AddressIndexIterator;
|
||||
|
||||
private:
|
||||
enum {START_ARRAY_SIZE=1024};
|
||||
|
||||
// *********************************************************************
|
||||
// * population : this integer identifies the exact number of data items
|
||||
// * that currently exist in the list.
|
||||
// *********************************************************************
|
||||
int population;
|
||||
|
||||
// *********************************************************************
|
||||
// * maxEntries : this integer identifies the maximum number of entries
|
||||
// * that this object can contain.
|
||||
// *********************************************************************
|
||||
int maxEntries;
|
||||
|
||||
// *********************************************************************
|
||||
// * curEntry : this integer identifies the currently selected entry.
|
||||
// *********************************************************************
|
||||
int curEntry;
|
||||
|
||||
// *********************************************************************
|
||||
// * checksum : this is an array of bytes that are used to identify the
|
||||
// * checksum for a specific address. This checksum is used to validate
|
||||
// * that the address has not been changed externally.
|
||||
// *********************************************************************
|
||||
unsigned char * checksum;
|
||||
|
||||
// *********************************************************************
|
||||
// * address : this is the array of addresses that will be stored and
|
||||
// * retrieved using this object.
|
||||
// *********************************************************************
|
||||
void ** address;
|
||||
|
||||
|
||||
public:
|
||||
inline AddressIndex ( void );
|
||||
inline ~AddressIndex ( void );
|
||||
|
||||
inline unsigned insert( void * ptr );
|
||||
|
||||
inline void remove( void * ptr );
|
||||
inline void remove( unsigned idx );
|
||||
|
||||
inline unsigned find ( void * ptr );
|
||||
inline void * find ( unsigned idx );
|
||||
};
|
||||
|
||||
|
||||
class AddressIndexIterator
|
||||
{
|
||||
private:
|
||||
AddressIndex * index;
|
||||
int current;
|
||||
|
||||
public:
|
||||
inline AddressIndexIterator (AddressIndex * Index);
|
||||
inline ~AddressIndexIterator( void );
|
||||
|
||||
inline void * first ( void );
|
||||
inline void * operator ++ ( void );
|
||||
inline void * operator ++ ( int x );
|
||||
inline unsigned key ( void );
|
||||
inline void * data ( void );
|
||||
};
|
||||
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * AddressIndex::AddressIndex :
|
||||
// * This is the constructor for the AddressIndex class. It is allocates a
|
||||
// * default number of entries in the checksum and address arrays and then
|
||||
// * initializes the data values to 0.
|
||||
// *
|
||||
// * Note that these arrays must be allocated using malloc because we will
|
||||
// * use realloc later to expand there size if necessary.
|
||||
// *****************************************************************************
|
||||
inline AddressIndex::AddressIndex ( void )
|
||||
: population(0),maxEntries(0),curEntry(0),checksum(NULL),address(NULL)
|
||||
{
|
||||
maxEntries = START_ARRAY_SIZE;
|
||||
checksum = (unsigned char *)malloc(sizeof(unsigned char)*maxEntries);
|
||||
address = (void **) malloc(sizeof(void *) *maxEntries);
|
||||
memset(checksum, 1, sizeof(unsigned char)*maxEntries);
|
||||
memset(address, 0, sizeof(void *) *maxEntries);
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * AddressIndex::~AddressIndex :
|
||||
// * This is the destructor for the object. It will deallocate any memory
|
||||
// * that has been assigned to the checksum or address objects.
|
||||
// *
|
||||
// * Note that these arrays must be deallocated using the free library call
|
||||
// * because they were allocated using either malloc or realloc.
|
||||
// *****************************************************************************
|
||||
inline AddressIndex::~AddressIndex ( void )
|
||||
{
|
||||
if(checksum!=NULL) free(checksum);
|
||||
if(address!=NULL) free(address);
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * AddressIndex::insert :
|
||||
// * This method is used to insert a void * pointer into the AddressIndex
|
||||
// * object. It returns an unsigned integer result which is the rawData
|
||||
// * component of an AddressReference object.
|
||||
// *****************************************************************************
|
||||
inline unsigned AddressIndex::insert ( void * ptr )
|
||||
{
|
||||
AddressReference result;
|
||||
|
||||
// *********************************************************************
|
||||
// * Initial all entries within the AddressReference object before
|
||||
// * starting.
|
||||
// *********************************************************************
|
||||
result.rawData = 0U;
|
||||
|
||||
// *********************************************************************
|
||||
// * If the pointer provided by the user is NULL, then it cannot be
|
||||
// * inserted into the list... Otherwise,
|
||||
// *
|
||||
// * From the current position in the array, we are going to walk
|
||||
// * forward until we find an empty slot. An empty slot is indicated
|
||||
// * by the value NULL in its address.
|
||||
// *
|
||||
// * If the end of the list is reached before an empty slot can be found
|
||||
// * then special considerations will be made as described below.
|
||||
// *********************************************************************
|
||||
if(ptr!=NULL)
|
||||
{
|
||||
while(curEntry<maxEntries && address[curEntry]!=NULL) curEntry++;
|
||||
|
||||
// *************************************************************
|
||||
// * If curEntry>=maxEntries then an empty slot was not located.
|
||||
// * The following options should be considered...
|
||||
// *************************************************************
|
||||
|
||||
// *************************************************************
|
||||
// * 1) If the population of the table is less than half of the
|
||||
// * maximum number of entries... go back to the beginning
|
||||
// * and search the table for an empty slot.
|
||||
// *************************************************************
|
||||
if(curEntry>=maxEntries && population<(maxEntries/2))
|
||||
{
|
||||
curEntry = 0;
|
||||
while(curEntry<maxEntries && address[curEntry]!=NULL)
|
||||
{
|
||||
curEntry++;
|
||||
}
|
||||
}
|
||||
|
||||
// *************************************************************
|
||||
// * 2) If the population of the table is more than half of the
|
||||
// * maximum number of entries... double the size of the
|
||||
// * table and continue from the current cursor position.
|
||||
// * Note: the newly allocated data at the end of the buffer
|
||||
// * must be initialized to 0.
|
||||
// *************************************************************
|
||||
else if(curEntry>=maxEntries)
|
||||
{
|
||||
curEntry = maxEntries;
|
||||
maxEntries*=2;
|
||||
checksum = (unsigned char *)realloc(checksum, sizeof(char *)*maxEntries);
|
||||
address = (void **) realloc(address, sizeof(void *)*maxEntries);
|
||||
memset(&checksum[curEntry], 0, sizeof(char *)*curEntry);
|
||||
memset(&address [curEntry], 0, sizeof(void *)*curEntry);
|
||||
}
|
||||
|
||||
// *************************************************************
|
||||
// * At this time the curEntry index points to the insertion
|
||||
// * point that should be used. Place the index and checksum
|
||||
// * information into the result object and update the
|
||||
// * population count.
|
||||
// *************************************************************
|
||||
checksum[curEntry] = (checksum[curEntry]==255?1:(checksum[curEntry]+1));
|
||||
address [curEntry] = ptr;
|
||||
|
||||
result.value.index = curEntry;
|
||||
result.value.checksum = checksum[curEntry];
|
||||
|
||||
population++;
|
||||
}
|
||||
|
||||
// *********************************************************************
|
||||
// * Return the rawData portion of the AddressReference to the caller
|
||||
// * as an unsigned integer.
|
||||
// *********************************************************************
|
||||
return result.rawData;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * AddressIndex::remove :
|
||||
// * This function will locate an entry by searching the array for a
|
||||
// * specific pointer. If the entry is found it will be deleted. Direct
|
||||
// * searching is one of the most time consuming approaches to locating
|
||||
// * data, therefore the remove function that uses an unsigned integer
|
||||
// * identifier should be used whenever possible.
|
||||
// *****************************************************************************
|
||||
inline void AddressIndex::remove ( void * ptr)
|
||||
{
|
||||
if(ptr!=NULL)
|
||||
{
|
||||
for(int idx=0; idx<maxEntries && address[idx]!=ptr; idx++);
|
||||
if(idx<maxEntries)
|
||||
{
|
||||
address[idx]=NULL;
|
||||
population--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * AddressIndex::remove :
|
||||
// * This function will locate a specific entry based on the long integer
|
||||
// * identifier. If the entry is valid and has a matching checksum, then
|
||||
// * it will be removed from the list.
|
||||
// *****************************************************************************
|
||||
inline void AddressIndex::remove ( unsigned idx )
|
||||
{
|
||||
AddressReference ref;
|
||||
ref.rawData = idx;
|
||||
|
||||
if(ref.value.index<maxEntries &&
|
||||
ref.value.checksum==checksum[ref.value.index])
|
||||
{
|
||||
address[ref.value.index] = NULL;
|
||||
population--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * AddressIndex::find :
|
||||
// * This function will locate an entry within the list using a pointer to
|
||||
// * its memory address and will return an unsigned integer indicating its
|
||||
// * location. If the returned bvalue is 0, then the ptr was not found...
|
||||
// *****************************************************************************
|
||||
inline unsigned AddressIndex::find ( void * ptr )
|
||||
{
|
||||
AddressReference result;
|
||||
int idx;
|
||||
result.rawData = 0U;
|
||||
|
||||
for(idx=0; idx<maxEntries && address[idx]!=ptr; idx++);
|
||||
if(idx<maxEntries)
|
||||
{
|
||||
result.value.index =idx;
|
||||
result.value.checksum = checksum[idx];
|
||||
}
|
||||
|
||||
return result.rawData;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * AddressIndex::find :
|
||||
// * This function will obtain a pointer to the data item using the user
|
||||
// * provided unsigned index. A value of NULL will be returned if the
|
||||
// * data item could not be located or if the unsigned index was invalid.
|
||||
// *****************************************************************************
|
||||
inline void * AddressIndex::find ( unsigned idx )
|
||||
{
|
||||
void * result = NULL;
|
||||
AddressReference ref;
|
||||
|
||||
ref.rawData = idx;
|
||||
|
||||
if(ref.value.index<maxEntries &&
|
||||
ref.value.checksum==checksum[ref.value.index])
|
||||
{
|
||||
result = address[ref.value.index];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * AddressIndexIterator::AddressIndexIterator:
|
||||
// * Simple constructor for the AddressIndexIterator class.
|
||||
// *****************************************************************************
|
||||
inline AddressIndexIterator::AddressIndexIterator (AddressIndex * Index)
|
||||
: index(Index), current (0)
|
||||
{}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * AddressIndexIterator::~AddressIndexIterator :
|
||||
// * Destructor for the AddressIndexIterator... does nothing.
|
||||
// *****************************************************************************
|
||||
inline AddressIndexIterator::~AddressIndexIterator( void ) {}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * AddressIndexIterator::first :
|
||||
// * Repositions to the first entry in the AddressIndex.
|
||||
// *****************************************************************************
|
||||
inline void * AddressIndexIterator::first( void )
|
||||
{
|
||||
current = 0;
|
||||
|
||||
while(index->population &&
|
||||
current<index->maxEntries &&
|
||||
index->address[current]==NULL)
|
||||
{
|
||||
current++;
|
||||
}
|
||||
return (index->population && current<index->maxEntries)?index->address[current]:NULL;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * AddressIndexIterator::operator ++ :
|
||||
// * Repositions to the next entry in the AddressIndex.
|
||||
// *****************************************************************************
|
||||
inline void * AddressIndexIterator::operator ++ ( void )
|
||||
{
|
||||
current++;
|
||||
|
||||
while(index->population &&
|
||||
current<index->maxEntries &&
|
||||
index->address[current]==NULL)
|
||||
{
|
||||
current++;
|
||||
}
|
||||
return (index->population && current<index->maxEntries)?index->address[current]:NULL;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * AddressIndexIterator::operator ++ :
|
||||
// * Repositions to the next entry in the AddressIndex.
|
||||
// *****************************************************************************
|
||||
inline void * AddressIndexIterator::operator ++ ( int x )
|
||||
{
|
||||
current++;
|
||||
|
||||
while(x==0 &&
|
||||
index->population &&
|
||||
current<index->maxEntries &&
|
||||
index->address[current]==NULL)
|
||||
{
|
||||
current++;
|
||||
}
|
||||
return (x==0 && index->population && current<index->maxEntries)?index->address[current]:NULL;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * AddressIndexIterator::key :
|
||||
// * This method will return the AddressIndex key value of the current entry.
|
||||
// *****************************************************************************
|
||||
inline unsigned AddressIndexIterator::key ( void )
|
||||
{
|
||||
AddressReference result;
|
||||
|
||||
result.rawData = 0;
|
||||
if(current<index->maxEntries && index->address[current]!=NULL)
|
||||
{
|
||||
result.value.index = current;
|
||||
result.value.checksum = index->checksum[current];
|
||||
}
|
||||
return result.rawData;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * AddressIndexIterator::data :
|
||||
// * This method will return the data value of the current entry.
|
||||
// *****************************************************************************
|
||||
inline void * AddressIndexIterator::data ( void )
|
||||
{
|
||||
return(current<index->maxEntries)?index->address[current]:NULL;
|
||||
}
|
||||
|
||||
|
||||
#endif /* ADDRESS_INDEX_H_ */
|
||||
34
extensions/cdevGenericServer/include/ClientAcceptor.h
Normal file
34
extensions/cdevGenericServer/include/ClientAcceptor.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#if !defined (_CLIENT_ACCEPTOR_H)
|
||||
#define _CLIENT_ACCEPTOR_H
|
||||
|
||||
#include "cdevSessionManager.h"
|
||||
|
||||
#include "cdevSocketAcceptor.h"
|
||||
|
||||
// *****************************************************************************
|
||||
// * class ClientAcceptor:
|
||||
// * This class provdies the cdevEventHandler that accepts connections through
|
||||
// * the reactor on the listening port. Once accepted, these new connections
|
||||
// * are serviced by the ClientHandler.
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API ClientAcceptor : public cdevEventHandler, public ErrorReporter
|
||||
{
|
||||
friend class ClientHandler;
|
||||
public:
|
||||
ClientAcceptor (cdevSessionManager &s);
|
||||
~ClientAcceptor (void);
|
||||
|
||||
const char *getName (void) { return "ClientAcceptor"; }
|
||||
int getLocalAddress (cdevAddr &addr) { return acceptor.getLocalAddress(addr); }
|
||||
int open (const cdevInetAddr &addr);
|
||||
|
||||
virtual int getHandle (void) const;
|
||||
virtual int handleInput (void);
|
||||
virtual int handleClose (void);
|
||||
|
||||
private:
|
||||
cdevSocketAcceptor acceptor;
|
||||
cdevSessionManager & server;
|
||||
};
|
||||
|
||||
#endif
|
||||
43
extensions/cdevGenericServer/include/ClientHandler.h
Normal file
43
extensions/cdevGenericServer/include/ClientHandler.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#if !defined (_CLIENT_HANDLER_H)
|
||||
#define _CLIENT_HANDLER_H
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "cdevSessionManager.h"
|
||||
#include "SocketUtil.h"
|
||||
|
||||
#include "cdevSocketStream.h"
|
||||
|
||||
class GENERIC_SERVER_API ClientHandler : public cdevEventHandler, public SocketReader, public SocketWriter
|
||||
{
|
||||
public:
|
||||
ClientHandler (cdevSessionManager & s);
|
||||
~ClientHandler (void);
|
||||
|
||||
char * getHostName (void);
|
||||
const char * getName (void) { return "ClientHandler"; }
|
||||
virtual int open (class ClientAcceptor * acc);
|
||||
virtual int getHandle (void) const;
|
||||
operator cdevSocketStream & (void) { return stream; }
|
||||
|
||||
virtual int handleClose (void);
|
||||
virtual int handleInput (void);
|
||||
virtual int handleOutput (void);
|
||||
virtual int handleExcept (void);
|
||||
|
||||
size_t getPacketsSent (void) { return packetsSent; }
|
||||
size_t getPacketsRecv (void) { return packetsRecv; }
|
||||
|
||||
protected:
|
||||
char hostName[MAXHOSTNAMELEN + 1];
|
||||
cdevSocketStream stream;
|
||||
cdevSessionManager & server;
|
||||
SocketSession * queue;
|
||||
int clientQuitFlag;
|
||||
size_t packetsSent;
|
||||
size_t packetsRecv;
|
||||
};
|
||||
|
||||
#endif /* _CLIENT_HANDLER_H */
|
||||
355
extensions/cdevGenericServer/include/ClientInfo.h
Normal file
355
extensions/cdevGenericServer/include/ClientInfo.h
Normal file
@@ -0,0 +1,355 @@
|
||||
#include <cdevPlatforms.h>
|
||||
#include <cdevData.h>
|
||||
#include <time.h>
|
||||
|
||||
class ClientInfoStruct
|
||||
{
|
||||
private:
|
||||
char unknown[8];
|
||||
char * username;
|
||||
char * group;
|
||||
unsigned uid;
|
||||
unsigned gid;
|
||||
unsigned pid;
|
||||
char * program;
|
||||
char * commandline;
|
||||
time_t starttime;
|
||||
time_t connecttime;
|
||||
char * host;
|
||||
char * os;
|
||||
char * osrelease;
|
||||
char * osversion;
|
||||
char * machine;
|
||||
char * shell;
|
||||
|
||||
private:
|
||||
void updateDataString ( cdevData & data, char * tag, char * &item )
|
||||
{
|
||||
size_t nelems = 0;
|
||||
|
||||
if(data.getElems(tag, &nelems)==CDEV_SUCCESS &&
|
||||
nelems==1 && data.getType(tag)==CDEV_STRING)
|
||||
{
|
||||
if(item!=NULL) delete item;
|
||||
item = NULL;
|
||||
data.get(tag, &item);
|
||||
}
|
||||
}
|
||||
|
||||
void updateDataInt ( cdevData & data, char * tag, unsigned &item )
|
||||
{
|
||||
size_t nelems = 0;
|
||||
if(data.getElems(tag, &nelems)==CDEV_SUCCESS && nelems==1)
|
||||
{
|
||||
data.get(tag, &item);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
ClientInfoStruct ( void )
|
||||
: username(NULL), group(NULL), uid(0), gid(0), pid(0),
|
||||
program(NULL), commandline(NULL), starttime(0),
|
||||
connecttime(0), host(NULL), os(NULL), osrelease(NULL),
|
||||
osversion(NULL), machine(NULL), shell(NULL)
|
||||
{
|
||||
strcpy(unknown, "UNKNOWN");
|
||||
}
|
||||
|
||||
~ClientInfoStruct ( void )
|
||||
{
|
||||
if(username) delete username;
|
||||
if(group) delete group;
|
||||
if(program) delete program;
|
||||
if(commandline) delete commandline;
|
||||
if(host) delete host;
|
||||
if(os) delete os;
|
||||
if(osrelease) delete osrelease;
|
||||
if(osversion) delete osversion;
|
||||
if(machine) delete machine;
|
||||
if(shell) delete shell;
|
||||
}
|
||||
|
||||
void updateClientInfo ( cdevData & data )
|
||||
{
|
||||
updateDataString(data, "username", username);
|
||||
updateDataString(data, "group", group);
|
||||
updateDataInt (data, "uid", uid);
|
||||
updateDataInt (data, "gid", gid);
|
||||
updateDataInt (data, "pid", pid);
|
||||
updateDataString(data, "program", program);
|
||||
updateDataString(data, "commandline", commandline);
|
||||
updateDataInt (data, "starttime", (unsigned &)starttime);
|
||||
updateDataInt (data, "connecttime", (unsigned &)connecttime);
|
||||
updateDataString(data, "host", host);
|
||||
updateDataString(data, "os", os);
|
||||
updateDataString(data, "osrelease", osrelease);
|
||||
updateDataString(data, "osversion", osversion);
|
||||
updateDataString(data, "machine", machine);
|
||||
updateDataString(data, "shell", shell);
|
||||
connecttime = time(NULL);
|
||||
}
|
||||
|
||||
char * getUsername ( void ) { return username?username:unknown; }
|
||||
char * getGroup ( void ) { return group?group:unknown; }
|
||||
unsigned getUid ( void ) { return uid; }
|
||||
unsigned getGid ( void ) { return gid; }
|
||||
unsigned getPid ( void ) { return pid; }
|
||||
char * getProgram ( void ) { return program?program:unknown; }
|
||||
char * getCommandLine ( void ) { return commandline?commandline:unknown; }
|
||||
time_t getStartTime ( void ) { return starttime; }
|
||||
time_t getConnectTime ( void ) { return connecttime; }
|
||||
char * getHost ( void ) { return host?host:unknown; }
|
||||
char * getOs ( void ) { return os?os:unknown; }
|
||||
char * getOsRelease ( void ) { return osrelease?osrelease:unknown; }
|
||||
char * getOsVersion ( void ) { return osversion?osversion:unknown; }
|
||||
char * getMachine ( void ) { return machine?machine:unknown; }
|
||||
char * getShell ( void ) { return shell?shell:unknown; }
|
||||
|
||||
void asciiDump ( FILE * fp = stdout )
|
||||
{
|
||||
fprintf(fp, "--------------------------------------------------------\n");
|
||||
fprintf(fp, " Printing Client Information\n");
|
||||
fprintf(fp, "--------------------------------------------------------\n");
|
||||
fprintf(fp, "=> USERNAME : %s\n", username?username:"UNDEFINED");
|
||||
fprintf(fp, "=> GROUP : %s\n", group?group:"UNDEFINED");
|
||||
fprintf(fp, "=> USER ID : %s\n", uid?ltoa(uid):"UNDEFINED");
|
||||
fprintf(fp, "=> GROUP ID : %s\n", gid?ltoa(gid):"UNDEFINED");
|
||||
fprintf(fp, "=> PROCESS ID : %s\n", pid?ltoa(pid):"UNDEFINED");
|
||||
fprintf(fp, "=> APPLICATION : %s\n", program?program:"UNDEFINED");
|
||||
fprintf(fp, "=> COMMAND LINE : %s\n", commandline?commandline:"UNDEFINED");
|
||||
fprintf(fp, "=> START TIME : %s", starttime?ctime(&starttime):"UNKNOWN\n");
|
||||
fprintf(fp, "=> CONNECT TIME : %s", connecttime?ctime(&connecttime):"UNKNOWN\n");
|
||||
fprintf(fp, "=> HOST NAME : %s\n", host?host:"UNKNOWN");
|
||||
fprintf(fp, "=> OS : %s\n", os?os:"UNKNOWN");
|
||||
fprintf(fp, "=> OS VERSION : %s\n", osversion?osversion:"UNKNOWN");
|
||||
fprintf(fp, "=> OS RELEASE : %s\n", osrelease?osrelease:"UNKNOWN");
|
||||
fprintf(fp, "=> HARDWARE ID : %s\n", machine?machine:"UNKNOWN");
|
||||
fprintf(fp, "--------------------------------------------------------\n");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class ClientInfo
|
||||
{
|
||||
private:
|
||||
cdevData data;
|
||||
|
||||
public:
|
||||
ClientInfo ( void )
|
||||
{
|
||||
cdevData::addTag("username");
|
||||
cdevData::addTag("group");
|
||||
cdevData::addTag("uid");
|
||||
cdevData::addTag("gid");
|
||||
cdevData::addTag("pid");
|
||||
cdevData::addTag("program");
|
||||
cdevData::addTag("commandline");
|
||||
cdevData::addTag("starttime");
|
||||
cdevData::addTag("connecttime");
|
||||
cdevData::addTag("host");
|
||||
cdevData::addTag("os");
|
||||
cdevData::addTag("osrelease");
|
||||
cdevData::addTag("osversion");
|
||||
cdevData::addTag("machine");
|
||||
cdevData::addTag("shell");
|
||||
cdevData::addTag("sendPktCnt");
|
||||
cdevData::addTag("recvPktCnt");
|
||||
cdevData::addTag("socket");
|
||||
|
||||
#ifndef _WIN32
|
||||
struct utsname hostinfo;
|
||||
struct group * grp;
|
||||
char * shell = getenv("SHELL");
|
||||
|
||||
uname(&hostinfo);
|
||||
grp = getgrgid(getgid());
|
||||
|
||||
data.insert("username", getlogin());
|
||||
data.insert("group", grp?grp->gr_name:(char *)"UNDEFINED");
|
||||
data.insert("uid", (unsigned)getuid());
|
||||
data.insert("gid", (unsigned)getgid());
|
||||
data.insert("pid", (unsigned)getpid());
|
||||
data.insert("host", hostinfo.nodename);
|
||||
data.insert("os", hostinfo.sysname);
|
||||
data.insert("osrelease", hostinfo.release);
|
||||
data.insert("osversion", hostinfo.version);
|
||||
data.insert("machine", hostinfo.machine);
|
||||
data.insert("shell", shell?shell:(char *)"UNDEFINED");
|
||||
|
||||
#if defined(__hpux)
|
||||
struct pst_status pstatData;
|
||||
pstat_getproc(&pstatData, sizeof(pstatData), 0, (int)getpid());
|
||||
data.insert("program", pstatData.pst_ucomm);
|
||||
data.insert("commandline", pstatData.pst_cmd);
|
||||
data.insert("starttime", pstatData.pst_start);
|
||||
#endif
|
||||
#else
|
||||
char userNameBuf[UNLEN+1];
|
||||
unsigned long userNameLen = UNLEN;
|
||||
char hostNameBuf[MAXHOSTNAMELEN+1];
|
||||
unsigned long hostNameLen = MAXHOSTNAMELEN;
|
||||
|
||||
*userNameBuf = 0;
|
||||
*hostNameBuf = 0;
|
||||
|
||||
data.insert("pid", GetCurrentProcessId());
|
||||
if(GetUserName (userNameBuf, &userNameLen)) data.insert("username", userNameBuf);
|
||||
if(GetComputerName(hostNameBuf, &hostNameLen)) data.insert("host", hostNameBuf);
|
||||
|
||||
if(userNameBuf && hostNameBuf)
|
||||
{
|
||||
char grpNameBuf[GNLEN+1];
|
||||
unsigned long grpNameLen = GNLEN;
|
||||
char sidBuf[256];
|
||||
unsigned long sidLen = 256;
|
||||
SID_NAME_USE sidType;
|
||||
|
||||
*grpNameBuf = 0;
|
||||
if(LookupAccountName(hostNameBuf, userNameBuf,
|
||||
sidBuf, &sidLen, grpNameBuf,
|
||||
&grpNameLen, &sidType))
|
||||
{
|
||||
data.insert("group", grpNameBuf);
|
||||
}
|
||||
}
|
||||
|
||||
OSVERSIONINFO osv;
|
||||
osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
||||
if(GetVersionEx (&osv))
|
||||
{
|
||||
char osVersionBuf[64];
|
||||
switch(osv.dwPlatformId)
|
||||
{
|
||||
case VER_PLATFORM_WIN32s:
|
||||
data.insert("os", "WINDOWS");
|
||||
break;
|
||||
|
||||
case VER_PLATFORM_WIN32_WINDOWS:
|
||||
if(osv.dwMinorVersion == 0)
|
||||
data.insert("os", "WINDOWS 95");
|
||||
else data.insert("os", "WINDOWS 98");
|
||||
break;
|
||||
|
||||
case VER_PLATFORM_WIN32_NT:
|
||||
data.insert("os", "WINDOWS NT");
|
||||
break;
|
||||
|
||||
default:
|
||||
data.insert("os", "WIN32");
|
||||
break;
|
||||
}
|
||||
sprintf(osVersionBuf, "%d.%d", osv.dwMajorVersion, osv.dwMinorVersion);
|
||||
data.insert("osversion", osVersionBuf);
|
||||
data.insert("osrelease", ltoa(osv.dwBuildNumber));
|
||||
}
|
||||
|
||||
SYSTEM_INFO sysinfo;
|
||||
GetSystemInfo(&sysinfo);
|
||||
switch(sysinfo.wProcessorArchitecture)
|
||||
{
|
||||
case PROCESSOR_ARCHITECTURE_INTEL:
|
||||
data.insert("machine", "PROCESSOR_ARCHITECTURE_INTEL");
|
||||
break;
|
||||
|
||||
case PROCESSOR_ARCHITECTURE_MIPS:
|
||||
data.insert("machine", "PROCESSOR_ARCHITECTURE_MIPS");
|
||||
break;
|
||||
|
||||
case PROCESSOR_ARCHITECTURE_ALPHA:
|
||||
data.insert("machine", "PROCESSOR_ARCHITECTURE_ALPHA");
|
||||
break;
|
||||
|
||||
case PROCESSOR_ARCHITECTURE_PPC:
|
||||
data.insert("machine", "PROCESSOR_ARCHITECTURE_PPC");
|
||||
break;
|
||||
|
||||
case PROCESSOR_ARCHITECTURE_UNKNOWN:
|
||||
default:
|
||||
data.insert("machine", "PROCESSOR_ARCHITECTURE_UNKNOWN");
|
||||
break;
|
||||
}
|
||||
|
||||
if(__argc>0)
|
||||
{
|
||||
int i;
|
||||
char * cmdLine = NULL;
|
||||
size_t cmdLineLen = 0;
|
||||
|
||||
data.insert("program", __argv[0]);
|
||||
for(i=0; i<__argc; i++) cmdLineLen+=strlen(__argv[i])+1;
|
||||
cmdLine = new char [cmdLineLen];
|
||||
*cmdLine = 0;
|
||||
for(i=0; i<__argc; i++)
|
||||
{
|
||||
strcat(cmdLine, __argv[i]);
|
||||
if(i+1<__argc) strcat(cmdLine, " ");
|
||||
}
|
||||
data.insert("commandline", cmdLine);
|
||||
}
|
||||
FILETIME startTime;
|
||||
FILETIME exitTime;
|
||||
FILETIME kernelTime;
|
||||
FILETIME userTime;
|
||||
if(GetProcessTimes(GetCurrentProcess(), &startTime, &exitTime, &kernelTime, &userTime))
|
||||
{
|
||||
struct timeval tv;
|
||||
FileTimeToTimeVal(&startTime, &tv);
|
||||
data.insert("starttime", tv.tv_sec);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
cdevData & getClientData ( void ) { return data; }
|
||||
|
||||
void asciiDump ( FILE * fp = stdout )
|
||||
{
|
||||
fprintf(fp, "--------------------------------------------------------\n");
|
||||
fprintf(fp, " Printing Client Information\n");
|
||||
fprintf(fp, "--------------------------------------------------------\n");
|
||||
|
||||
char * username;
|
||||
char * group;
|
||||
unsigned pid;
|
||||
unsigned gid;
|
||||
unsigned uid;
|
||||
char * host;
|
||||
char * os;
|
||||
char * osrelease;
|
||||
char * osversion;
|
||||
char * machine;
|
||||
char * shell;
|
||||
char * program;
|
||||
char * commandline;
|
||||
long starttime;
|
||||
|
||||
if(data.find("username", (void * &)username)!=CDEV_SUCCESS) username = NULL;
|
||||
if(data.find("group", (void * &)group)!=CDEV_SUCCESS) group = NULL;
|
||||
if(data.find("host", (void * &)host)!=CDEV_SUCCESS) host = NULL;
|
||||
if(data.find("os", (void * &)os)!=CDEV_SUCCESS) os = NULL;
|
||||
if(data.find("osrelease", (void * &)osrelease)!=CDEV_SUCCESS) osrelease = NULL;
|
||||
if(data.find("osversion", (void * &)osversion)!=CDEV_SUCCESS) osversion = NULL;
|
||||
if(data.find("machine", (void * &)machine)!=CDEV_SUCCESS) machine = NULL;
|
||||
if(data.find("shell", (void * &)shell)!=CDEV_SUCCESS) shell=NULL;
|
||||
if(data.find("program", (void * &)program)!=CDEV_SUCCESS) program=NULL;
|
||||
if(data.find("commandline", (void * &)commandline)!=CDEV_SUCCESS) commandline=NULL;
|
||||
if(data.get("starttime", &starttime)!=CDEV_SUCCESS) starttime = 0;
|
||||
if(data.get("pid", &pid)!=CDEV_SUCCESS) pid = 0;
|
||||
if(data.get("gid", &gid)!=CDEV_SUCCESS) gid = 0;
|
||||
if(data.get("uid", &uid)!=CDEV_SUCCESS) uid = 0;
|
||||
|
||||
fprintf(fp, "=> USERNAME : %s\n", username?username:"UNDEFINED");
|
||||
fprintf(fp, "=> GROUP : %s\n", group?group:"UNDEFINED");
|
||||
fprintf(fp, "=> USER ID : %s\n", uid?ltoa(uid):"UNDEFINED");
|
||||
fprintf(fp, "=> GROUP ID : %s\n", gid?ltoa(gid):"UNDEFINED");
|
||||
fprintf(fp, "=> PROCESS ID : %s\n", pid?ltoa(pid):"UNDEFINED");
|
||||
fprintf(fp, "=> APPLICATION : %s\n", program?program:"UNDEFINED");
|
||||
fprintf(fp, "=> COMMAND LINE : %s\n", commandline?commandline:"UNDEFINED");
|
||||
fprintf(fp, "=> START TIME : %s", starttime?ctime(&starttime):"UNKNOWN\n");
|
||||
fprintf(fp, "=> HOST NAME : %s\n", host?host:"UNKNOWN");
|
||||
fprintf(fp, "=> OS : %s\n", os?os:"UNKNOWN");
|
||||
fprintf(fp, "=> OS VERSION : %s\n", osversion?osversion:"UNKNOWN");
|
||||
fprintf(fp, "=> OS RELEASE : %s\n", osrelease?osrelease:"UNKNOWN");
|
||||
fprintf(fp, "=> HARDWARE ID : %s\n", machine?machine:"UNKNOWN");
|
||||
fprintf(fp, "--------------------------------------------------------\n");
|
||||
}
|
||||
};
|
||||
49
extensions/cdevGenericServer/include/ErrorReporter.h
Normal file
49
extensions/cdevGenericServer/include/ErrorReporter.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef _ERROR_REPORTER_H_
|
||||
#define _ERROR_REPORTER_H_ 1
|
||||
|
||||
#include <cdevPlatforms.h>
|
||||
|
||||
#ifndef _NO_CDEV_SYSTEM_
|
||||
#include <cdevSystem.h>
|
||||
#include <cdevErrCode.h>
|
||||
#else
|
||||
#include <stdarg.h>
|
||||
#ifndef CDEV_SEVERITY_INFO /* cdevError class severity codes */
|
||||
#define CDEV_SEVERITY_INFO 0 /* informative message */
|
||||
#define CDEV_SEVERITY_WARN 1 /* warning message */
|
||||
#define CDEV_SEVERITY_ERROR 2 /* error message */
|
||||
#define CDEV_SEVERITY_SEVERE 3 /* severe or fatal error message */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
class GENERIC_SERVER_API ErrorReporter
|
||||
{
|
||||
public:
|
||||
ErrorReporter ( void ) {}
|
||||
virtual ~ErrorReporter ( void ) {}
|
||||
virtual int outputError ( int severity, char *name, char *formatString, ... )
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
va_list argp;
|
||||
va_start (argp, formatString);
|
||||
|
||||
#ifndef _NO_CDEV_SYSTEM_
|
||||
result = cdevSystem::defaultSystem().vreportError(severity, name, NULL, formatString, argp);
|
||||
#else
|
||||
fprintf(stdout,"%s %s: ",
|
||||
name,
|
||||
(severity==CDEV_SEVERITY_INFO?"Information":
|
||||
(severity==CDEV_SEVERITY_WARN?"Warning":
|
||||
(severity==CDEV_SEVERITY_ERROR?"Error":
|
||||
(severity==CDEV_SEVERITY_SEVERE?"Severe Error":
|
||||
"Event")))));
|
||||
vfprintf(stdout, formatString, argp);
|
||||
fprintf (stdout, "\n");
|
||||
#endif
|
||||
va_end(argp);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* _ERROR_REPORTER_H_ */
|
||||
192
extensions/cdevGenericServer/include/FD_Trigger.h
Normal file
192
extensions/cdevGenericServer/include/FD_Trigger.h
Normal file
@@ -0,0 +1,192 @@
|
||||
#ifndef _FD_TRIGGER_H_
|
||||
#define _FD_TRIGGER_H_ 1
|
||||
|
||||
#include <cdevPlatforms.h>
|
||||
|
||||
// *****************************************************************************
|
||||
// * FD_Trigger :
|
||||
// * This class provides a method for triggering events based on file
|
||||
// * descriptor activity.
|
||||
// *****************************************************************************
|
||||
class FD_Trigger
|
||||
{
|
||||
private:
|
||||
enum {READ=0, WRITE=1};
|
||||
int sockPair[2];
|
||||
|
||||
#ifndef _WIN32
|
||||
char cbuf[100];
|
||||
#endif
|
||||
|
||||
public:
|
||||
FD_Trigger ( void );
|
||||
~FD_Trigger ( void );
|
||||
int insertEvent ( int numEvents = 1 );
|
||||
int removeEvent ( int numEvents = 1 );
|
||||
void purge ( void );
|
||||
int writefd ( void ) const;
|
||||
int readfd ( void ) const;
|
||||
};
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * FD_Trigger::FD_Trigger :
|
||||
// * Constructor for the FD_Trigger class.
|
||||
// *****************************************************************************
|
||||
inline FD_Trigger::FD_Trigger ( void )
|
||||
{
|
||||
if(pipe(sockPair)!=0)
|
||||
{
|
||||
sockPair[READ] = -1;
|
||||
sockPair[WRITE] = -1;
|
||||
}
|
||||
#ifndef _WIN32
|
||||
else
|
||||
{
|
||||
int val;
|
||||
|
||||
val = ::fcntl(sockPair[READ], F_GETFL, 0);
|
||||
if(val>0) ::fcntl(sockPair[READ], F_SETFL, val|O_NONBLOCK);
|
||||
|
||||
val = ::fcntl(sockPair[WRITE], F_GETFL, 0);
|
||||
if(val>0) ::fcntl(sockPair[WRITE], F_SETFL, val|O_NONBLOCK);
|
||||
|
||||
memset(cbuf, '1', 100);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * FD_Trigger::~FD_Trigger :
|
||||
// * Destructor for the FD_Trigger class.
|
||||
// *****************************************************************************
|
||||
inline FD_Trigger::~FD_Trigger ( void )
|
||||
{
|
||||
if(sockPair[READ] != -1) close(sockPair[READ]);
|
||||
if(sockPair[WRITE] != -1) close(sockPair[WRITE]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * FD_Trigger::insertEvent :
|
||||
// * Adds one or more bytes (indicating events) to the pipe
|
||||
// *****************************************************************************
|
||||
inline int FD_Trigger::insertEvent ( int numEvents )
|
||||
{
|
||||
if(sockPair[WRITE]>0)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
#ifdef _WIN32
|
||||
char cptr = 1;
|
||||
|
||||
while(count++<numEvents) send(sockPair[WRITE], &cptr, 1, 0);
|
||||
#else
|
||||
count = numEvents;
|
||||
while(count>0)
|
||||
{
|
||||
write(sockPair[WRITE], cbuf, min(100, count));
|
||||
count-=100;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return (sockPair[WRITE]>0)?0:-1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * FD_Trigger::removeEvent :
|
||||
// * Removes one or more bytes (indicating events) from the pipe.
|
||||
// *****************************************************************************
|
||||
inline int FD_Trigger::removeEvent ( int numEvents )
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
if(sockPair[READ]>0)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
#ifdef _WIN32
|
||||
char cptr = 0;
|
||||
|
||||
while(count<numEvents &&
|
||||
(recv(sockPair[READ], &cptr, 1, 0)>0 ||
|
||||
WSAGetLastError()==WSAEMSGSIZE))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
if(count==0) retval = -1;
|
||||
|
||||
#else
|
||||
if(ioctl(sockPair[READ], FIONREAD, &count)<0 || count==0)
|
||||
{
|
||||
retval = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(numEvents>count) numEvents = count;
|
||||
while(numEvents>0)
|
||||
{
|
||||
read(sockPair[READ], cbuf, min(100, numEvents));
|
||||
numEvents-=100;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else retval = -1;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * FD_Trigger::purge :
|
||||
// * This function removes all bytes from the pipe.
|
||||
// *****************************************************************************
|
||||
inline void FD_Trigger::purge ( void )
|
||||
{
|
||||
if(sockPair[READ]>0)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
char cptr = 0;
|
||||
while(recv(sockPair[READ], &cptr, 1, 0)>0 || WSAGetLastError()==WSAEMSGSIZE);
|
||||
#else
|
||||
int count = 0;
|
||||
ioctl(sockPair[READ], FIONREAD, &count);
|
||||
while(count>0)
|
||||
{
|
||||
read(sockPair[READ], cbuf, min(100, count));
|
||||
count-=100;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * FD_Trigger::writefd
|
||||
// * Returns the write file descriptor associated with the pipe.
|
||||
// *****************************************************************************
|
||||
inline int FD_Trigger::writefd ( void ) const
|
||||
{
|
||||
return sockPair[WRITE];
|
||||
}
|
||||
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * FD_Trigger::readfd
|
||||
// * Returns the read file descriptor associated with the pipe.
|
||||
// *****************************************************************************
|
||||
inline int FD_Trigger::readfd ( void ) const
|
||||
{
|
||||
return sockPair[READ];
|
||||
}
|
||||
|
||||
#endif /* _FD_TRIGGER_H_ */
|
||||
204
extensions/cdevGenericServer/include/IntHash.h
Normal file
204
extensions/cdevGenericServer/include/IntHash.h
Normal file
@@ -0,0 +1,204 @@
|
||||
#ifndef _INT_HASH_H_
|
||||
#define _INT_HASH_H_ 1
|
||||
|
||||
#include <cdevPlatforms.h>
|
||||
|
||||
class GENERIC_SERVER_API IntHashNode
|
||||
{
|
||||
friend class IntHash;
|
||||
friend class IntHashIterator;
|
||||
|
||||
private:
|
||||
int hashInt;
|
||||
void * hashData;
|
||||
IntHashNode * next;
|
||||
|
||||
IntHashNode ( int HashInt, void * HashData);
|
||||
~IntHashNode ( void );
|
||||
};
|
||||
|
||||
|
||||
class GENERIC_SERVER_API IntHash
|
||||
{
|
||||
friend class IntHashIterator;
|
||||
|
||||
private:
|
||||
enum { HASH_CNT=256, HASH_NO=256 };
|
||||
|
||||
IntHashNode * nodes[HASH_CNT];
|
||||
|
||||
public:
|
||||
IntHash ( void );
|
||||
~IntHash ( void );
|
||||
|
||||
inline unsigned char hash ( int hashInt );
|
||||
|
||||
inline void insert ( int hashInt, void * hashData );
|
||||
inline void remove ( int hashInt );
|
||||
inline void * find ( int hashInt );
|
||||
};
|
||||
|
||||
|
||||
class GENERIC_SERVER_API IntHashIterator
|
||||
{
|
||||
private:
|
||||
IntHash * hashTbl;
|
||||
IntHashNode * node;
|
||||
int idx;
|
||||
|
||||
public:
|
||||
IntHashIterator( IntHash * HashTbl );
|
||||
~IntHashIterator( void );
|
||||
|
||||
inline void * first ( void );
|
||||
inline void * operator ++ ( void );
|
||||
inline void * operator ++ ( int x );
|
||||
inline int key ( void );
|
||||
inline void * data ( void );
|
||||
};
|
||||
|
||||
|
||||
|
||||
inline IntHash::IntHash ( void )
|
||||
{
|
||||
memset(nodes, 0, sizeof(nodes));
|
||||
}
|
||||
|
||||
|
||||
inline IntHash::~IntHash ( void )
|
||||
{
|
||||
for(int i=0; i<HASH_CNT; i++)
|
||||
{
|
||||
while(nodes[i]!=NULL)
|
||||
{
|
||||
IntHashNode * node = nodes[i];
|
||||
nodes[i] = node->next;
|
||||
delete node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned char IntHash::hash ( int hashInt )
|
||||
{
|
||||
return (hashInt%HASH_NO);
|
||||
}
|
||||
|
||||
inline void IntHash::insert (int hashInt, void * hashData )
|
||||
{
|
||||
unsigned char idx = hash(hashInt);
|
||||
IntHashNode * prev = NULL, * node = nodes[idx];
|
||||
IntHashNode * newNode = new IntHashNode(hashInt, hashData);
|
||||
|
||||
while(node!=NULL && node->hashInt!=hashInt)
|
||||
{
|
||||
prev = node;
|
||||
node = prev->next;
|
||||
}
|
||||
if(node!=NULL)
|
||||
{
|
||||
newNode->next = node->next;
|
||||
delete node;
|
||||
}
|
||||
if(prev!=NULL) prev->next = newNode;
|
||||
else nodes[idx] = newNode;
|
||||
}
|
||||
|
||||
inline void IntHash::remove ( int hashInt )
|
||||
{
|
||||
unsigned char idx = hash(hashInt);
|
||||
IntHashNode * prev = NULL, * node = nodes[idx];
|
||||
while(node!=NULL && node->hashInt!=hashInt)
|
||||
{
|
||||
prev = node;
|
||||
node = prev->next;
|
||||
}
|
||||
if(node!=NULL)
|
||||
{
|
||||
if(prev!=NULL) prev->next = node->next;
|
||||
else nodes[idx] = node->next;
|
||||
delete node;
|
||||
}
|
||||
}
|
||||
|
||||
inline void * IntHash::find ( int hashInt )
|
||||
{
|
||||
unsigned char idx = hash(hashInt);
|
||||
IntHashNode * prev = NULL, * node = nodes[idx];
|
||||
while(node!=NULL && node->hashInt!=hashInt)
|
||||
{
|
||||
prev = node;
|
||||
node = prev->next;
|
||||
}
|
||||
return node!=NULL?node->hashData:NULL;
|
||||
}
|
||||
|
||||
|
||||
inline IntHashIterator::IntHashIterator(IntHash * HashTbl)
|
||||
: hashTbl(HashTbl), idx(0), node(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
inline IntHashIterator::~IntHashIterator( void )
|
||||
{
|
||||
}
|
||||
|
||||
inline void * IntHashIterator::first ( void )
|
||||
{
|
||||
if(hashTbl!=NULL)
|
||||
{
|
||||
for(idx = 0; idx<IntHash::HASH_CNT &&
|
||||
(node = hashTbl->nodes[idx])==NULL; idx++);
|
||||
}
|
||||
else node = NULL;
|
||||
return (node!=NULL)?node->hashData:NULL;
|
||||
}
|
||||
|
||||
inline void * IntHashIterator::operator ++ ( void )
|
||||
{
|
||||
if(hashTbl!=NULL)
|
||||
{
|
||||
if(node==NULL) first();
|
||||
else if(node->next!=NULL) node = node->next;
|
||||
else
|
||||
{
|
||||
node = NULL;
|
||||
do {
|
||||
idx++;
|
||||
} while(idx<IntHash::HASH_CNT &&
|
||||
(node = hashTbl->nodes[idx])==NULL);
|
||||
}
|
||||
}
|
||||
else node = NULL;
|
||||
return (node!=NULL)?node->hashData:NULL;
|
||||
}
|
||||
|
||||
inline void * IntHashIterator::operator ++ ( int x )
|
||||
{
|
||||
if(hashTbl!=NULL && x==0)
|
||||
{
|
||||
if(node==NULL) first();
|
||||
else if(node->next!=NULL) node = node->next;
|
||||
else
|
||||
{
|
||||
node = NULL;
|
||||
do {
|
||||
idx++;
|
||||
} while(idx<IntHash::HASH_CNT &&
|
||||
(node = hashTbl->nodes[idx])==NULL);
|
||||
}
|
||||
}
|
||||
else node = NULL;
|
||||
return (node!=NULL)?node->hashData:NULL;
|
||||
}
|
||||
|
||||
inline int IntHashIterator::key ( void )
|
||||
{
|
||||
return (node!=NULL)?node->hashInt:0;
|
||||
}
|
||||
|
||||
inline void * IntHashIterator::data ( void )
|
||||
{
|
||||
return (node!=NULL)?node->hashData:NULL;
|
||||
}
|
||||
|
||||
#endif /* _INT_HASH_H_ */
|
||||
1091
extensions/cdevGenericServer/include/LinkList.h
Normal file
1091
extensions/cdevGenericServer/include/LinkList.h
Normal file
File diff suppressed because it is too large
Load Diff
192
extensions/cdevGenericServer/include/MultiQueue.h
Normal file
192
extensions/cdevGenericServer/include/MultiQueue.h
Normal file
@@ -0,0 +1,192 @@
|
||||
#ifndef __MULTIQUEUE_H_
|
||||
#define __MULTIQUEUE_H_ 1
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
class MultiQueueBase
|
||||
{
|
||||
private:
|
||||
int nodeCount;
|
||||
|
||||
public:
|
||||
MultiQueueBase ( void ) { nodeCount = 0; }
|
||||
|
||||
virtual void setTail ( void *tail ) = 0;
|
||||
virtual int getCount ( void ) { return nodeCount; }
|
||||
virtual int setCount ( int cnt ) { return (nodeCount = (cnt>=0?cnt:0)); }
|
||||
virtual int incCount ( void ) { return (++nodeCount); }
|
||||
virtual int decCount ( void ) { return (nodeCount=(nodeCount>0?nodeCount-1:0)); }
|
||||
};
|
||||
|
||||
|
||||
template <unsigned queueCount> class MultiQueueNode
|
||||
{
|
||||
private:
|
||||
char * binary;
|
||||
unsigned binaryLen;
|
||||
|
||||
public:
|
||||
class MultiQueueBase *queue[queueCount];
|
||||
class MultiQueueNode<queueCount> *prev [queueCount];
|
||||
class MultiQueueNode<queueCount> *next [queueCount];
|
||||
|
||||
MultiQueueNode(char * Binary=NULL, size_t BinaryLen=0)
|
||||
: binary(Binary), binaryLen(BinaryLen)
|
||||
{
|
||||
memset(queue, 0, sizeof(class MultiQueueBase *)*queueCount);
|
||||
memset(prev, 0, sizeof(class MultiQueueNode<queueCount> *)*queueCount);
|
||||
memset(next, 0, sizeof(class MultiQueueNode<queueCount> *)*queueCount);
|
||||
}
|
||||
|
||||
virtual ~MultiQueueNode(void)
|
||||
{
|
||||
binary = NULL;
|
||||
binaryLen = 0;
|
||||
clear();
|
||||
}
|
||||
|
||||
virtual void set ( char * Binary, size_t BinaryLen )
|
||||
{
|
||||
binary = Binary;
|
||||
binaryLen = BinaryLen;
|
||||
}
|
||||
|
||||
virtual void get ( char ** Binary, size_t * BinaryLen )
|
||||
{
|
||||
*Binary = binary;
|
||||
*BinaryLen = binaryLen;
|
||||
}
|
||||
|
||||
virtual void clear ( void )
|
||||
{
|
||||
for(int i=0; i<queueCount; i++)
|
||||
{
|
||||
if(prev[i]) prev [i]->next[i] = next[i];
|
||||
if(next[i]) next [i]->prev[i] = prev[i];
|
||||
else if(queue[i]) queue[i]->setTail(prev[i]);
|
||||
|
||||
if(queue[i]) queue[i]->decCount();
|
||||
|
||||
queue[i]=NULL;
|
||||
prev[i] =NULL;
|
||||
next[i] =NULL;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <unsigned queueIndex, unsigned queueCount> class MultiQueue
|
||||
: public MultiQueueBase
|
||||
{
|
||||
private:
|
||||
MultiQueueNode<queueCount> head;
|
||||
MultiQueueNode<queueCount> * tail;
|
||||
|
||||
public:
|
||||
MultiQueue ( void )
|
||||
{
|
||||
tail = NULL;
|
||||
}
|
||||
|
||||
virtual ~MultiQueue ( void )
|
||||
{
|
||||
MultiQueueNode<queueCount> * node;
|
||||
while((node=dequeue())!=NULL) delete node;
|
||||
}
|
||||
|
||||
virtual void setTail ( void * Tail )
|
||||
{
|
||||
tail = (MultiQueueNode<queueCount> *)Tail;
|
||||
}
|
||||
|
||||
virtual int empty ( void ) { return (head.next[queueIndex]==NULL?1:0); }
|
||||
|
||||
virtual void enqueue ( MultiQueueNode<queueCount> * node )
|
||||
{
|
||||
if(node!=NULL)
|
||||
{
|
||||
if(head.next[queueIndex]==NULL)
|
||||
{
|
||||
head.next[queueIndex] = node;
|
||||
node->prev[queueIndex] = &head;
|
||||
}
|
||||
else
|
||||
{
|
||||
tail->next[queueIndex] = node;
|
||||
node->prev[queueIndex] = tail;
|
||||
}
|
||||
tail = node;
|
||||
node->queue[queueIndex] = this;
|
||||
node->queue[queueIndex]->incCount();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
virtual MultiQueueNode<queueCount> * peek ( void )
|
||||
{
|
||||
return head.next[queueIndex];
|
||||
}
|
||||
|
||||
virtual MultiQueueNode<queueCount> * dequeue ( void )
|
||||
{
|
||||
MultiQueueNode<queueCount> * node = head.next[queueIndex];
|
||||
if(node!=NULL) node->clear();
|
||||
return node;
|
||||
}
|
||||
|
||||
virtual int peek ( char ** binary, size_t * binaryLen )
|
||||
{
|
||||
int result = -1;
|
||||
MultiQueueNode<queueCount> * node;
|
||||
|
||||
if((node = peek())!=NULL)
|
||||
{
|
||||
node->get(binary, binaryLen);
|
||||
if(*binary!=NULL && *binaryLen!=0) result = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual int dequeue ( char ** binary, size_t * binaryLen )
|
||||
{
|
||||
int result = -1;
|
||||
MultiQueueNode<queueCount> * node;
|
||||
|
||||
*binary = NULL;
|
||||
*binaryLen = 0;
|
||||
|
||||
if((node = dequeue())!=NULL)
|
||||
{
|
||||
node->get(binary, binaryLen);
|
||||
if(*binary!=NULL && *binaryLen!=0) result = 0;
|
||||
delete node;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual MultiQueueNode<queueCount> * localDequeue ( void )
|
||||
{
|
||||
MultiQueueNode<queueCount> * node = head.next[queueIndex];
|
||||
if(node!=NULL)
|
||||
{
|
||||
if(node->prev[queueIndex]!=NULL)
|
||||
node->prev[queueIndex]->next[queueIndex] = node->next[queueIndex];
|
||||
if(node->next[queueIndex]!=NULL)
|
||||
node->next[queueIndex]->prev[queueIndex] = node->prev[queueIndex];
|
||||
else if(node->queue[queueIndex]!=NULL)
|
||||
{
|
||||
node->queue[queueIndex]->setTail(node->prev);
|
||||
node->queue[queueIndex]->decCount();
|
||||
}
|
||||
node->queue[queueIndex]=NULL;
|
||||
node->next [queueIndex]=NULL;
|
||||
node->prev [queueIndex]=NULL;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* __MULTIQUEUE_H_ */
|
||||
|
||||
97
extensions/cdevGenericServer/include/ServerHandler.h
Normal file
97
extensions/cdevGenericServer/include/ServerHandler.h
Normal file
@@ -0,0 +1,97 @@
|
||||
#if !defined (_SERVER_HANDLER_H_)
|
||||
#define _SERVER_HANDLER_H_
|
||||
|
||||
// *****************************************************************************
|
||||
// * SIG_PIPE_HANDLED:
|
||||
// * This definition tells the SocketWriter class not to independently
|
||||
// * handle the SIGPIPE signal.
|
||||
// *****************************************************************************
|
||||
#define SIG_PIPE_HANDLED 1
|
||||
|
||||
#include "cdevEventHandler.h"
|
||||
#include "cdevAddr.h"
|
||||
#include "cdevSocketConnector.h"
|
||||
#include "cdevReactor.h"
|
||||
|
||||
#include "SocketUtil.h"
|
||||
#include "fifo.h"
|
||||
|
||||
class ServerInterface;
|
||||
class ServerHandlerCallbackNode;
|
||||
class SignalManager;
|
||||
|
||||
// *****************************************************************************
|
||||
// * ServerHandlerCallback :
|
||||
// * This class is used by other classes to register to be informed when the
|
||||
// * ServerHandler is destroyed.
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API ServerHandlerCallback
|
||||
{
|
||||
public:
|
||||
ServerHandlerCallback ( void ) {}
|
||||
virtual ~ServerHandlerCallback ( void ) {}
|
||||
virtual void executeServerHandlerCallback (class ServerHandler * handler) = 0;
|
||||
};
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * ServerHandler:
|
||||
// * This class provides the mechanisms that will be used to service the
|
||||
// * requests of a client.
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API ServerHandler : public cdevEventHandler,
|
||||
public SocketReader,
|
||||
public SocketWriter
|
||||
{
|
||||
protected:
|
||||
static SignalManager signalManager;
|
||||
static int signalManagerInit;
|
||||
|
||||
char hostName [MAXHOSTNAMELEN + 1];
|
||||
char server [256];
|
||||
FifoQueue & queue;
|
||||
cdevSocketConnector stream;
|
||||
ServerInterface * serverface;
|
||||
ServerHandlerCallbackNode * callbacks;
|
||||
size_t enqueuedPackets;
|
||||
size_t enqueuedBytes;
|
||||
short clientID;
|
||||
int contextID;
|
||||
int tagChanged;
|
||||
int serverQuitFlag;
|
||||
|
||||
public:
|
||||
ServerHandler (char * Server, ServerInterface * Interface);
|
||||
~ServerHandler (void);
|
||||
virtual int outputError (int severity, char *name, char *formatString, ...);
|
||||
|
||||
virtual int open (const cdevAddr &addr);
|
||||
|
||||
char * getHostName (void);
|
||||
char * getName (void) const;
|
||||
virtual int getHandle (void) const;
|
||||
virtual char * getServer (void) const;
|
||||
|
||||
virtual int handleClose (void);
|
||||
virtual int handleInput (void);
|
||||
virtual int handleOutput (void);
|
||||
virtual int handleExcept (void);
|
||||
|
||||
virtual void registerServerCallback (ServerHandlerCallback *);
|
||||
virtual void unregisterServerCallback (ServerHandlerCallback *);
|
||||
|
||||
void enqueue (char * buf, size_t len);
|
||||
void undequeue (char * buf, size_t len) { queue.undequeue(buf, len); }
|
||||
int dequeue (char **buf, size_t *len) { return queue.dequeue(buf, len); }
|
||||
int empty (void) { return queue.empty(); }
|
||||
|
||||
static short getNextClientID ( void );
|
||||
short getClientID ( void ) { return clientID; }
|
||||
void setClientID ( short ClientID ) { clientID=ClientID; }
|
||||
int getContextID ( void ) { return contextID; }
|
||||
void setContextID ( int ContextID ) { contextID = ContextID; }
|
||||
int getTagChangeFlag ( void ) { return tagChanged; }
|
||||
void setTagChangeFlag ( int flag ) { tagChanged = flag; }
|
||||
};
|
||||
|
||||
#endif /* _SERVER_HANDLER_H_ */
|
||||
280
extensions/cdevGenericServer/include/ServerInfo.h
Normal file
280
extensions/cdevGenericServer/include/ServerInfo.h
Normal file
@@ -0,0 +1,280 @@
|
||||
#include <cdevPlatforms.h>
|
||||
#include <cdevData.h>
|
||||
|
||||
class ServerInfo
|
||||
{
|
||||
friend class cdevServer;
|
||||
|
||||
private:
|
||||
cdevData data;
|
||||
size_t sendPktCnt;
|
||||
size_t recvPktCnt;
|
||||
size_t clientCnt;
|
||||
long pageSize;
|
||||
|
||||
public:
|
||||
ServerInfo ( char * domain, char * server, unsigned short port )
|
||||
: sendPktCnt(0), recvPktCnt(0), clientCnt(0), pageSize(0)
|
||||
{
|
||||
cdevData::addTag("username");
|
||||
cdevData::addTag("group");
|
||||
cdevData::addTag("uid");
|
||||
cdevData::addTag("gid");
|
||||
cdevData::addTag("pid");
|
||||
cdevData::addTag("program");
|
||||
cdevData::addTag("commandline");
|
||||
cdevData::addTag("starttime");
|
||||
cdevData::addTag("host");
|
||||
cdevData::addTag("server");
|
||||
cdevData::addTag("domain");
|
||||
cdevData::addTag("port");
|
||||
cdevData::addTag("os");
|
||||
cdevData::addTag("osrelease");
|
||||
cdevData::addTag("osversion");
|
||||
cdevData::addTag("machine");
|
||||
cdevData::addTag("shell");
|
||||
cdevData::addTag("sendPktCnt");
|
||||
cdevData::addTag("recvPktCnt");
|
||||
cdevData::addTag("clientCnt");
|
||||
cdevData::addTag("pctcpu");
|
||||
cdevData::addTag("datasize");
|
||||
cdevData::addTag("socket");
|
||||
|
||||
data.insert("server", server);
|
||||
data.insert("domain", domain);
|
||||
data.insert("port", port);
|
||||
|
||||
#ifndef _WIN32
|
||||
struct utsname hostinfo;
|
||||
struct group * grp;
|
||||
char * shell = getenv("SHELL");
|
||||
|
||||
uname(&hostinfo);
|
||||
grp = getgrgid(getgid());
|
||||
|
||||
data.insert("username", getlogin());
|
||||
data.insert("group", grp?grp->gr_name:(char *)"UNDEFINED");
|
||||
data.insert("uid", (unsigned)getuid());
|
||||
data.insert("gid", (unsigned)getgid());
|
||||
data.insert("pid", (unsigned)getpid());
|
||||
data.insert("host", hostinfo.nodename);
|
||||
data.insert("os", hostinfo.sysname);
|
||||
data.insert("osrelease", hostinfo.release);
|
||||
data.insert("osversion", hostinfo.version);
|
||||
data.insert("machine", hostinfo.machine);
|
||||
data.insert("shell", shell?shell:(char *)"UNDEFINED");
|
||||
|
||||
#if defined(__hpux)
|
||||
struct pst_status pstatData;
|
||||
pstat_getproc(&pstatData, sizeof(pstatData), 0, (int)getpid());
|
||||
data.insert("program", pstatData.pst_ucomm);
|
||||
data.insert("commandline", pstatData.pst_cmd);
|
||||
data.insert("starttime", pstatData.pst_start);
|
||||
|
||||
struct pst_static pstatStatic;
|
||||
pstat_getstatic(&pstatStatic, sizeof(pstatStatic), 1, 0);
|
||||
pageSize = pstatStatic.page_size;
|
||||
#endif
|
||||
#else
|
||||
char userNameBuf[UNLEN+1];
|
||||
unsigned long userNameLen = UNLEN;
|
||||
char hostNameBuf[MAXHOSTNAMELEN+1];
|
||||
unsigned long hostNameLen = MAXHOSTNAMELEN;
|
||||
|
||||
*userNameBuf = 0;
|
||||
*hostNameBuf = 0;
|
||||
|
||||
data.insert("pid", getpid());
|
||||
if(GetUserName (userNameBuf, &userNameLen)) data.insert("username", userNameBuf);
|
||||
if(GetComputerName(hostNameBuf, &hostNameLen)) data.insert("host", hostNameBuf);
|
||||
|
||||
if(userNameBuf && hostNameBuf)
|
||||
{
|
||||
char grpNameBuf[GNLEN+1];
|
||||
unsigned long grpNameLen = GNLEN;
|
||||
char sidBuf[256];
|
||||
unsigned long sidLen = 256;
|
||||
SID_NAME_USE sidType;
|
||||
|
||||
*grpNameBuf = 0;
|
||||
if(LookupAccountName(hostNameBuf, userNameBuf,
|
||||
sidBuf, &sidLen, grpNameBuf,
|
||||
&grpNameLen, &sidType))
|
||||
{
|
||||
data.insert("group", grpNameBuf);
|
||||
}
|
||||
}
|
||||
|
||||
OSVERSIONINFO osv;
|
||||
osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
||||
if(GetVersionEx (&osv))
|
||||
{
|
||||
char osVersionBuf[64];
|
||||
switch(osv.dwPlatformId)
|
||||
{
|
||||
case VER_PLATFORM_WIN32s:
|
||||
data.insert("os", "WINDOWS");
|
||||
break;
|
||||
|
||||
case VER_PLATFORM_WIN32_WINDOWS:
|
||||
if(osv.dwMinorVersion == 0)
|
||||
data.insert("os", "WINDOWS 95");
|
||||
else data.insert("os", "WINDOWS 98");
|
||||
break;
|
||||
|
||||
case VER_PLATFORM_WIN32_NT:
|
||||
data.insert("os", "WINDOWS NT");
|
||||
break;
|
||||
|
||||
default:
|
||||
data.insert("os", "WIN32");
|
||||
break;
|
||||
}
|
||||
sprintf(osVersionBuf, "%d.%d", osv.dwMajorVersion, osv.dwMinorVersion);
|
||||
data.insert("osversion", osVersionBuf);
|
||||
data.insert("osrelease", ltoa(osv.dwBuildNumber));
|
||||
}
|
||||
|
||||
SYSTEM_INFO sysinfo;
|
||||
GetSystemInfo(&sysinfo);
|
||||
switch(sysinfo.wProcessorArchitecture)
|
||||
{
|
||||
case PROCESSOR_ARCHITECTURE_INTEL:
|
||||
data.insert("machine", "PROCESSOR_ARCHITECTURE_INTEL");
|
||||
break;
|
||||
|
||||
case PROCESSOR_ARCHITECTURE_MIPS:
|
||||
data.insert("machine", "PROCESSOR_ARCHITECTURE_MIPS");
|
||||
break;
|
||||
|
||||
case PROCESSOR_ARCHITECTURE_ALPHA:
|
||||
data.insert("machine", "PROCESSOR_ARCHITECTURE_ALPHA");
|
||||
break;
|
||||
|
||||
case PROCESSOR_ARCHITECTURE_PPC:
|
||||
data.insert("machine", "PROCESSOR_ARCHITECTURE_PPC");
|
||||
break;
|
||||
|
||||
case PROCESSOR_ARCHITECTURE_UNKNOWN:
|
||||
default:
|
||||
data.insert("machine", "PROCESSOR_ARCHITECTURE_UNKNOWN");
|
||||
break;
|
||||
}
|
||||
|
||||
if(__argc>0)
|
||||
{
|
||||
int i;
|
||||
char * cmdLine = NULL;
|
||||
size_t cmdLineLen = 0;
|
||||
|
||||
data.insert("program", __argv[0]);
|
||||
for(i=0; i<__argc; i++) cmdLineLen+=strlen(__argv[i])+1;
|
||||
cmdLine = new char [cmdLineLen];
|
||||
*cmdLine = 0;
|
||||
for(i=0; i<__argc; i++)
|
||||
{
|
||||
strcat(cmdLine, __argv[i]);
|
||||
if(i+1<__argc) strcat(cmdLine, " ");
|
||||
}
|
||||
data.insert("commandline", cmdLine);
|
||||
}
|
||||
|
||||
FILETIME startTime;
|
||||
FILETIME exitTime;
|
||||
FILETIME kernelTime;
|
||||
FILETIME userTime;
|
||||
if(GetProcessTimes(GetCurrentProcess(), &startTime, &exitTime, &kernelTime, &userTime))
|
||||
{
|
||||
struct timeval tv;
|
||||
FileTimeToTimeVal(&startTime, &tv);
|
||||
data.insert("starttime", tv.tv_sec);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
cdevData & getServerData ( void )
|
||||
{
|
||||
#if defined(__hpux)
|
||||
struct pst_status pstatData;
|
||||
pstat_getproc(&pstatData, sizeof(pstatData), 0, (int)getpid());
|
||||
data.insert("pctcpu", pstatData.pst_pctcpu);
|
||||
data.insert("datasize", pageSize*(pstatData.pst_dsize+pstatData.pst_tsize+pstatData.pst_ssize));
|
||||
data.insert("sendPktCnt", sendPktCnt);
|
||||
data.insert("recvPktCnt", recvPktCnt);
|
||||
#endif
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void asciiDump ( FILE * fp = stdout )
|
||||
{
|
||||
fprintf(fp, "--------------------------------------------------------\n");
|
||||
fprintf(fp, " Printing Server Information\n");
|
||||
fprintf(fp, "--------------------------------------------------------\n");
|
||||
|
||||
char * server;
|
||||
char * domain;
|
||||
unsigned short port;
|
||||
char * username;
|
||||
char * group;
|
||||
unsigned pid;
|
||||
unsigned gid;
|
||||
unsigned uid;
|
||||
char * host;
|
||||
char * os;
|
||||
char * osrelease;
|
||||
char * osversion;
|
||||
char * machine;
|
||||
char * shell;
|
||||
char * program;
|
||||
char * commandline;
|
||||
long starttime;
|
||||
size_t datasize;
|
||||
float pctcpu;
|
||||
|
||||
getServerData();
|
||||
|
||||
if(data.find("domain", (void *&)domain)!=CDEV_SUCCESS) host = NULL;
|
||||
if(data.find("server", (void *&)server)!=CDEV_SUCCESS) server = NULL;
|
||||
if(data.find("username", (void * &)username)!=CDEV_SUCCESS) username = NULL;
|
||||
if(data.find("group", (void * &)group)!=CDEV_SUCCESS) group = NULL;
|
||||
if(data.find("host", (void * &)host)!=CDEV_SUCCESS) host = NULL;
|
||||
if(data.find("os", (void * &)os)!=CDEV_SUCCESS) os = NULL;
|
||||
if(data.find("osrelease", (void * &)osrelease)!=CDEV_SUCCESS) osrelease = NULL;
|
||||
if(data.find("osversion", (void * &)osversion)!=CDEV_SUCCESS) osversion = NULL;
|
||||
if(data.find("machine", (void * &)machine)!=CDEV_SUCCESS) machine = NULL;
|
||||
if(data.find("shell", (void * &)shell)!=CDEV_SUCCESS) shell=NULL;
|
||||
if(data.find("program", (void * &)program)!=CDEV_SUCCESS) program=NULL;
|
||||
if(data.find("commandline", (void * &)commandline)!=CDEV_SUCCESS) commandline=NULL;
|
||||
if(data.get("port", &port)!=CDEV_SUCCESS) port = 0;
|
||||
if(data.get("starttime", &starttime)!=CDEV_SUCCESS) starttime = 0;
|
||||
if(data.get("pid", &pid)!=CDEV_SUCCESS) pid = 0;
|
||||
if(data.get("gid", &gid)!=CDEV_SUCCESS) gid = 0;
|
||||
if(data.get("uid", &uid)!=CDEV_SUCCESS) uid = 0;
|
||||
if(data.get("datasize", &datasize)!=CDEV_SUCCESS) datasize = 0;
|
||||
if(data.get("pctcpu", &pctcpu)!=CDEV_SUCCESS) pctcpu = (float)0.0;
|
||||
|
||||
fprintf(fp, "=> DOMAIN : %s\n", domain?domain:"UNDEFINED");
|
||||
fprintf(fp, "=> SERVER : %s\n", server?server:"UNDEFINED");
|
||||
fprintf(fp, "=> LISTENING PORT : %s\n", port?ltoa(port):"UNDEFINED");
|
||||
fprintf(fp, "=> USERNAME : %s\n", username?username:"UNDEFINED");
|
||||
fprintf(fp, "=> GROUP : %s\n", group?group:"UNDEFINED");
|
||||
fprintf(fp, "=> USER ID : %s\n", uid?ltoa(uid):"UNDEFINED");
|
||||
fprintf(fp, "=> GROUP ID : %s\n", gid?ltoa(gid):"UNDEFINED");
|
||||
fprintf(fp, "=> PROCESS ID : %s\n", pid?ltoa(pid):"UNDEFINED");
|
||||
fprintf(fp, "=> APPLICATION : %s\n", program?program:"UNDEFINED");
|
||||
fprintf(fp, "=> COMMAND LINE : %s\n", commandline?commandline:"UNDEFINED");
|
||||
fprintf(fp, "=> START TIME : %s", starttime?ctime(&starttime):"UNKNOWN\n");
|
||||
fprintf(fp, "=> HOST NAME : %s\n", host?host:"UNKNOWN");
|
||||
fprintf(fp, "=> OS : %s\n", os?os:"UNKNOWN");
|
||||
fprintf(fp, "=> OS VERSION : %s\n", osversion?osversion:"UNKNOWN");
|
||||
fprintf(fp, "=> OS RELEASE : %s\n", osrelease?osrelease:"UNKNOWN");
|
||||
fprintf(fp, "=> HARDWARE ID : %s\n", machine?machine:"UNKNOWN");
|
||||
fprintf(fp, "=> PERCENT CPU : %f\n", pctcpu);
|
||||
fprintf(fp, "=> RESIDENT SIZE : %i\n", datasize);
|
||||
fprintf(fp, "=> PACKETS SENT : %i\n", sendPktCnt);
|
||||
fprintf(fp, "=> PACKETS RECV : %i\n", recvPktCnt);
|
||||
fprintf(fp, "=> ACTIVE CLIENTS : %i\n", clientCnt);
|
||||
fprintf(fp, "--------------------------------------------------------\n");
|
||||
}
|
||||
};
|
||||
71
extensions/cdevGenericServer/include/ServerInterface.h
Normal file
71
extensions/cdevGenericServer/include/ServerInterface.h
Normal file
@@ -0,0 +1,71 @@
|
||||
#ifndef _SERVER_INTERFACE_H_
|
||||
#define _SERVER_INTERFACE_H_
|
||||
|
||||
#include "cdevErrCode.h"
|
||||
#include "ServerHandler.h"
|
||||
#include "ErrorReporter.h"
|
||||
#include "StringHash.h"
|
||||
#include "fifo.h"
|
||||
#include "cdevReactor.h"
|
||||
#include "cdevEventHandler.h"
|
||||
#include "cdevAddr.h"
|
||||
|
||||
class GENERIC_SERVER_API ServerConnectionList
|
||||
{
|
||||
private:
|
||||
enum { ALLOCATION_COUNT = 32 };
|
||||
ServerHandler ** items;
|
||||
int maxItems;
|
||||
|
||||
public:
|
||||
ServerConnectionList ( void );
|
||||
virtual ~ServerConnectionList ( void );
|
||||
|
||||
ServerHandler * find ( char * server );
|
||||
int insert ( ServerHandler * handler );
|
||||
int remove ( ServerHandler * handler );
|
||||
ServerHandler * remove ( char * server );
|
||||
|
||||
ServerHandler * operator [] ( int idx )
|
||||
{ return (idx<maxItems)?items[idx]:(ServerHandler *)NULL; }
|
||||
};
|
||||
|
||||
|
||||
class GENERIC_SERVER_API ServerInterface : public ErrorReporter
|
||||
{
|
||||
protected:
|
||||
ServerConnectionList connections;
|
||||
StringHash connectionQueues;
|
||||
char * defaultServer;
|
||||
ServerHandler * defaultServerHandler;
|
||||
int maxFd;
|
||||
int * fdList;
|
||||
|
||||
public:
|
||||
enum { FAILED_TO_SEND = -1, COMPLETED = 0};
|
||||
|
||||
static cdevReactor Reactor;
|
||||
|
||||
ServerInterface ( void );
|
||||
~ServerInterface ( void );
|
||||
|
||||
virtual char * getDefault ( void );
|
||||
virtual void setDefault ( char * Default );
|
||||
|
||||
virtual ServerHandler * connect ( char * server, char * host=NULL, unsigned short port=0 );
|
||||
virtual ServerHandler * disconnect ( char * server );
|
||||
|
||||
int enqueue ( ServerHandler * handler, char * binary, size_t binaryLen );
|
||||
FifoQueue * getQueue ( char * server );
|
||||
virtual int enqueue ( int status, ServerHandler * handler, char * binary, size_t binaryLen ) = 0;
|
||||
virtual int isPacketValid ( char * binary, size_t binaryLen );
|
||||
|
||||
virtual int getFd ( int * &fd, int &numFd );
|
||||
virtual int flush ( void );
|
||||
int flush ( int fd );
|
||||
virtual int poll ( void );
|
||||
virtual int pend ( double seconds, int fd = -1 );
|
||||
};
|
||||
|
||||
|
||||
#endif /* _SERVER_INTERFACE_H_ */
|
||||
41
extensions/cdevGenericServer/include/SignalManager.h
Normal file
41
extensions/cdevGenericServer/include/SignalManager.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef _SIGNAL_MANAGER_H_
|
||||
#define _SIGNAL_MANAGER_H_
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <cdevPlatforms.h>
|
||||
#include <ErrorReporter.h>
|
||||
|
||||
typedef void (*SignalHandlerFunc)( int );
|
||||
|
||||
class GENERIC_SERVER_API _SignalHandler_
|
||||
{
|
||||
public:
|
||||
_SignalHandler_ ( void );
|
||||
~_SignalHandler_ ( void );
|
||||
void install ( int, SignalHandlerFunc);
|
||||
void uninstall ( void );
|
||||
|
||||
private:
|
||||
int signo;
|
||||
SignalHandlerFunc handler;
|
||||
SignalHandlerFunc oldHandler;
|
||||
};
|
||||
|
||||
class GENERIC_SERVER_API SignalManager
|
||||
{
|
||||
public:
|
||||
static ErrorReporter reporter;
|
||||
|
||||
void installHandler ( int, SignalHandlerFunc );
|
||||
void uninstallHandler ( int );
|
||||
void installDefaults ( void );
|
||||
|
||||
static void defaultHandler ( int );
|
||||
|
||||
private:
|
||||
enum { MAXSIGNAL = 34 };
|
||||
_SignalHandler_ signals[MAXSIGNAL];
|
||||
};
|
||||
|
||||
#endif /* _SIGNAL_MANAGER_H_ */
|
||||
545
extensions/cdevGenericServer/include/SocketUtil.h
Normal file
545
extensions/cdevGenericServer/include/SocketUtil.h
Normal file
@@ -0,0 +1,545 @@
|
||||
#if !defined (_SOCKET_UTIL_H)
|
||||
#define _SOCKET_UTIL_H
|
||||
|
||||
#include <cdevPlatforms.h>
|
||||
#include <ErrorReporter.h>
|
||||
#include <cdevHandleSet.h>
|
||||
|
||||
class SocketReader : virtual public ErrorReporter
|
||||
{
|
||||
public:
|
||||
enum { SHUTDOWN_CODE = -128};
|
||||
enum { MAX_RETRIES = 1000 };
|
||||
enum { READBUF_INITIAL_SIZE = 56000 };
|
||||
|
||||
virtual int getHandle ( void ) const = 0;
|
||||
|
||||
SocketReader ( long MagicNumber = 0L );
|
||||
~SocketReader ( void );
|
||||
|
||||
int read ( char ** buf, int * len );
|
||||
virtual int readNextPacket ( char ** buf, int * len );
|
||||
virtual int reading ( void );
|
||||
virtual int readReset ( void );
|
||||
|
||||
private:
|
||||
char * readBuf;
|
||||
char * readNextPktPtr;
|
||||
int readBufMax;
|
||||
int readPktCnt;
|
||||
int readPktXfrCnt;
|
||||
|
||||
int readBufLen;
|
||||
int readXfrLen;
|
||||
int readPktXfrLen;
|
||||
int readRetries;
|
||||
|
||||
// ***************************
|
||||
// * This section added to
|
||||
// * optionally support magic
|
||||
// * number for buffer
|
||||
// * validation.
|
||||
// ***************************
|
||||
const long readMagicNumber;
|
||||
int readMagicLen;
|
||||
long readMagicVal;
|
||||
};
|
||||
|
||||
|
||||
class SocketWriter : virtual public ErrorReporter
|
||||
{
|
||||
public:
|
||||
enum { WRITEBUF_INITIAL_SIZE = 56000 };
|
||||
enum { WRITEBUF_PAD_SIZE = 32 };
|
||||
|
||||
virtual int getHandle ( void ) const = 0;
|
||||
|
||||
SocketWriter ( long MagicNumber = 0L );
|
||||
~SocketWriter ( void );
|
||||
|
||||
int write ( char * buf, int buflen);
|
||||
int writeEnqueue ( char * buf, int buflen);
|
||||
virtual int writing ( void );
|
||||
virtual int writeContinue ( void );
|
||||
virtual int writeReset ( void );
|
||||
virtual int writeGoodbye ( void );
|
||||
|
||||
private:
|
||||
char * writeBuf;
|
||||
char * writeNextPktPtr;
|
||||
int writeBufMax;
|
||||
int writePktCnt;
|
||||
|
||||
int writeBufLen;
|
||||
int writeXfrLen;
|
||||
int writePktXfrLen;
|
||||
|
||||
// ***************************
|
||||
// * This section added to
|
||||
// * optionally support magic
|
||||
// * number for buffer
|
||||
// * validation.
|
||||
// ***************************
|
||||
const long writeMagicNumber;
|
||||
int writeMagicLen;
|
||||
};
|
||||
|
||||
|
||||
inline SocketReader::SocketReader ( long MagicNumber )
|
||||
: readBuf(NULL), readNextPktPtr(NULL), readBufMax(READBUF_INITIAL_SIZE),
|
||||
readPktCnt(0), readPktXfrCnt(0), readBufLen(0), readXfrLen(0),
|
||||
readPktXfrLen(0), readRetries(0),
|
||||
// *************************
|
||||
// * Magic number support.
|
||||
// *************************
|
||||
readMagicNumber(MagicNumber), readMagicLen(0), readMagicVal(0L)
|
||||
{
|
||||
readBuf = (char *)malloc(readBufMax);
|
||||
readNextPktPtr = readBuf+RNDUP(sizeof(long));
|
||||
}
|
||||
|
||||
inline SocketReader::~SocketReader ( void )
|
||||
{
|
||||
if(readBuf!=NULL) free(readBuf);
|
||||
}
|
||||
|
||||
inline int SocketReader::reading ( void )
|
||||
{
|
||||
return (readPktCnt>readPktXfrCnt)?1:0;
|
||||
}
|
||||
|
||||
inline int SocketReader::readReset ( void )
|
||||
{
|
||||
readNextPktPtr = readBuf+RNDUP(sizeof(long));
|
||||
readBufLen = 0;
|
||||
readXfrLen = 0;
|
||||
readPktCnt = 0;
|
||||
readPktXfrCnt = 0;
|
||||
readPktXfrLen = 0;
|
||||
readMagicLen = 0;
|
||||
readMagicVal = 0L;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * This method causes the next available packet to be dequeued from the
|
||||
// * already read buffer.
|
||||
// *****************************************************************************
|
||||
inline int SocketReader::readNextPacket (char ** buf, int *buflen)
|
||||
{
|
||||
if(readPktCnt>readPktXfrCnt)
|
||||
{
|
||||
*buflen = (int)ntohl(*(long *)readNextPktPtr);
|
||||
readNextPktPtr+=RNDUP(sizeof(long));
|
||||
*buf = readNextPktPtr;
|
||||
readNextPktPtr+=RNDUP(*buflen);
|
||||
readPktXfrCnt++;
|
||||
}
|
||||
else {
|
||||
*buf = NULL;
|
||||
*buflen = 0;
|
||||
}
|
||||
if(readPktXfrCnt>=readPktCnt) readReset();
|
||||
return *buflen;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * This method will get the next available packet from the socket. The caller
|
||||
// * is responsible for transfering this data to a new location immediately.
|
||||
// * The caller should not delete the pointer provided by this method, or rely
|
||||
// * on it to remain valid between calls.
|
||||
// *****************************************************************************
|
||||
inline int SocketReader::read(char ** buf, int * buflen)
|
||||
{
|
||||
int handle = getHandle();
|
||||
int result = 0;
|
||||
int shutdown = 0;
|
||||
int error = 0;
|
||||
*buf = NULL;
|
||||
*buflen = 0;
|
||||
|
||||
// *********************************************************************
|
||||
// * First test to ensure that the socket is allocated and that the
|
||||
// * device descriptor is valid.
|
||||
// *********************************************************************
|
||||
if(handle<=0) result = -1;
|
||||
// *********************************************************************
|
||||
// * If the handle is valid attempt to read the next packet of a
|
||||
// * multi-packet set from an already existing buffer.
|
||||
// *********************************************************************
|
||||
else if(reading()) result = readNextPacket(buf, buflen);
|
||||
// *********************************************************************
|
||||
// * If all packets in the most recent multi-packet set have already
|
||||
// * been read... Then attempt to read a new block from the socket.
|
||||
// *********************************************************************
|
||||
else {
|
||||
int amntread = 0;
|
||||
char *readPtr = NULL;
|
||||
|
||||
// *************************************************************
|
||||
// * Optionally read the magic number from the socket.
|
||||
// *************************************************************
|
||||
readPtr = (char *)&readMagicVal;
|
||||
while(readMagicNumber && readMagicLen<sizeof(long) &&
|
||||
(amntread = recv(handle,
|
||||
readPtr+readMagicLen,
|
||||
sizeof(long)-readMagicLen, 0))>0)
|
||||
{
|
||||
// *****************************************************
|
||||
// * Anytime a read is successful, set the readRetries
|
||||
// * variable to 0.
|
||||
// *****************************************************
|
||||
readRetries = 0;
|
||||
// *****************************************************
|
||||
// * Once an entire long integer is read from the socket
|
||||
// * validate that against the Magic Number that is
|
||||
// * expected.
|
||||
// *****************************************************
|
||||
if((readMagicLen += amntread)>=sizeof(long))
|
||||
{
|
||||
readMagicVal = ntohl(readMagicVal);
|
||||
|
||||
// *********************************************
|
||||
// * If the Magic Number received is not the
|
||||
// * same as the Magic Number expected, set the
|
||||
// * shutdown flag and kill the connection.
|
||||
// *********************************************
|
||||
if(readMagicVal!=readMagicNumber)
|
||||
{
|
||||
outputError (CDEV_SEVERITY_ERROR, "SocketReader",
|
||||
"Invalid magic number read from socket\n\t=> Expected %lX - received %lX",
|
||||
readMagicNumber, readMagicVal);
|
||||
shutdown = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// *************************************************************
|
||||
// * Read the size of the packet from the socket... note, this
|
||||
// * code will not be executed until the Magic Number has been
|
||||
// * successfully read.
|
||||
// *************************************************************
|
||||
readPtr = (char *)&readBufLen;
|
||||
while(!shutdown && readPktXfrLen<sizeof(long) &&
|
||||
(!readMagicNumber || readMagicLen>=sizeof(long)) &&
|
||||
(amntread = recv(handle,
|
||||
readPtr+readPktXfrLen,
|
||||
sizeof(long)-readPktXfrLen, 0))>0)
|
||||
{
|
||||
// *****************************************************
|
||||
// * Anytime a read is successful, set the readRetries
|
||||
// * variable to 0.
|
||||
// *****************************************************
|
||||
readRetries = 0;
|
||||
// *****************************************************
|
||||
// * Once an entire long integer is read from the socket
|
||||
// * use that variable as the expected packet length,
|
||||
// * and allocate a buffer of sufficient size to hold
|
||||
// * the incoming packet.
|
||||
// *****************************************************
|
||||
if((readPktXfrLen += amntread)>=sizeof(long))
|
||||
{
|
||||
readBufLen = ntohl(readBufLen);
|
||||
// *********************************************
|
||||
// * A length of -1 indicates that the socket
|
||||
// * should be shutdown.
|
||||
// *********************************************
|
||||
if(readBufLen == -1) shutdown = 1;
|
||||
if(readBufLen <= 0) readReset();
|
||||
else {
|
||||
if(readBufLen>readBufMax)
|
||||
{
|
||||
readBufMax = readBufLen;
|
||||
readBuf = (char *)realloc(readBuf, readBufMax);
|
||||
readNextPktPtr = readBuf+RNDUP(sizeof(long));
|
||||
}
|
||||
readXfrLen = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// *************************************************************
|
||||
// * Continue reading from the socket into the new buffer until
|
||||
// * the amount of data specified by the readBufLen variable
|
||||
// * has been obtained, or no further data is available.
|
||||
// *************************************************************
|
||||
while(!shutdown &&
|
||||
readPktXfrLen>=sizeof(long) &&
|
||||
readXfrLen < readBufLen &&
|
||||
(amntread = recv(handle, readBuf+readXfrLen, readBufLen-readXfrLen, 0))>0)
|
||||
{
|
||||
// *****************************************************
|
||||
// * Anytime a read is successful, set the readRetries
|
||||
// * variable to 0.
|
||||
// *****************************************************
|
||||
readRetries = 0;
|
||||
|
||||
// *****************************************************
|
||||
// * Once a complete buffer of data has been read from
|
||||
// * the socket, use the readNextPacket method to set
|
||||
// * the user pointer to the appropriate position within
|
||||
// * the data buffer.
|
||||
// *****************************************************
|
||||
if((readXfrLen+=amntread)>=readBufLen)
|
||||
{
|
||||
readPktCnt = (int)ntohl(*(long *)readBuf);
|
||||
result = readNextPacket(buf, buflen);
|
||||
}
|
||||
}
|
||||
|
||||
// *************************************************************
|
||||
// * If an error occurred, or the function failed to read
|
||||
// * data from the socket, then this section of code will be
|
||||
// * executed.
|
||||
// *************************************************************
|
||||
if(!shutdown && amntread<=0)
|
||||
{
|
||||
int errCode = GetSocketErrno();
|
||||
|
||||
// *****************************************************
|
||||
// * Increment the readRetries to count the number of
|
||||
// * empty receives. Once this variable reaches the
|
||||
// * MAX_RETRIES value, a -1 will be returned to delete
|
||||
// * the socket.
|
||||
// *****************************************************
|
||||
readRetries++;
|
||||
|
||||
// *****************************************************
|
||||
// * If the amntread is 0 or -1 (and any error was
|
||||
// * caused by blocking), and the maximum number of
|
||||
// * retries has not been reached, do the following
|
||||
// *****************************************************
|
||||
if(readRetries < MAX_RETRIES &&
|
||||
((amntread==0 && readPktXfrLen>0) ||
|
||||
(amntread==-1 && (errCode == EWOULDBLOCK || errCode == EAGAIN))))
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
// *****************************************************
|
||||
// * Otherwise, if the maximum number of retries have
|
||||
// * been reached, do the following
|
||||
// *****************************************************
|
||||
else if(readRetries >= MAX_RETRIES)
|
||||
{
|
||||
outputError (CDEV_SEVERITY_WARN, "SocketReader",
|
||||
"Have exceeded maximum retries on socket");
|
||||
result = -1;
|
||||
}
|
||||
// *****************************************************
|
||||
// * Otherwise, if the error was not due to blocking,
|
||||
// * do the following
|
||||
// ******************************************************
|
||||
else if(amntread==-1)
|
||||
{
|
||||
outputError (CDEV_SEVERITY_ERROR, "SocketReader",
|
||||
"Error number %i while reading from socket",
|
||||
errCode);
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(shutdown) result = SHUTDOWN_CODE;
|
||||
if(result==-1) readReset();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
inline SocketWriter::SocketWriter ( long MagicNumber )
|
||||
: writeBuf(NULL), writeNextPktPtr(NULL), writeBufMax(WRITEBUF_INITIAL_SIZE),
|
||||
writePktCnt(0), writeBufLen(RNDUP(sizeof(long))), writeXfrLen(0), writePktXfrLen(0),
|
||||
// *************************
|
||||
// * Magic number support.
|
||||
// *************************
|
||||
writeMagicNumber(MagicNumber), writeMagicLen(0)
|
||||
{
|
||||
writeBuf = (char *)malloc(writeBufMax);
|
||||
writeNextPktPtr = writeBuf+writeBufLen;
|
||||
}
|
||||
|
||||
inline SocketWriter::~SocketWriter ( void )
|
||||
{
|
||||
if(writeBuf!=NULL) free(writeBuf);
|
||||
}
|
||||
|
||||
inline int SocketWriter::writing ( void )
|
||||
{
|
||||
return (writePktCnt>0)?1:0;
|
||||
}
|
||||
|
||||
inline int SocketWriter::writeReset ( void )
|
||||
{
|
||||
writeBufLen = RNDUP(sizeof(long));
|
||||
writeNextPktPtr = writeBuf+writeBufLen;
|
||||
writePktCnt = 0;
|
||||
writeXfrLen = 0;
|
||||
writePktXfrLen = 0;
|
||||
|
||||
// *************************
|
||||
// * Magic number support.
|
||||
// *************************
|
||||
writeMagicLen = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline int SocketWriter::writeContinue ( void )
|
||||
{
|
||||
int handle = getHandle();
|
||||
int result = 0;
|
||||
|
||||
// *********************************************************************
|
||||
// * The following variable has been added to allow the SocketWriter
|
||||
// * to poll the file descriptor for validity prior to writing to it.
|
||||
// *********************************************************************
|
||||
#ifdef SYSV
|
||||
struct pollfd fds;
|
||||
fds.fd = handle;
|
||||
fds.events = POLLERR|POLLNVAL|POLLHUP;
|
||||
fds.revents = 0;
|
||||
|
||||
// *********************************************************************
|
||||
// * First test to ensure that the socket is allocated and that the
|
||||
// * device descriptor is valid.
|
||||
// *********************************************************************
|
||||
if( handle<=0 ) result = -1;
|
||||
// *********************************************************************
|
||||
// * Execute poll to ensure that the handle is still valid and writable.
|
||||
// *********************************************************************
|
||||
else if(poll(&fds, 1, 0)>0 && (fds.revents&(POLLERR|POLLNVAL|POLLHUP))!=0)
|
||||
{
|
||||
result = -1;
|
||||
}
|
||||
#else
|
||||
cdevHandleSet readfd;
|
||||
struct timeval tv;
|
||||
|
||||
readfd.set_bit(handle);
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
if (handle<=0) result = -1;
|
||||
else if (cdevSelect (handle+1,readfd,0,0,&tv)<0) result = -1;
|
||||
#endif
|
||||
// *********************************************************************
|
||||
// * If all is well, continue writing data.
|
||||
// *********************************************************************
|
||||
else if( writing() )
|
||||
{
|
||||
int amntsent = 0;
|
||||
char *sendPtr = NULL;
|
||||
long magicNumber = htonl(writeMagicNumber);
|
||||
long packetSize = htonl(writeBufLen);
|
||||
|
||||
sendPtr = (char *)&magicNumber;
|
||||
while(writeMagicNumber && writeMagicLen<sizeof(long) &&
|
||||
(amntsent = send(handle, sendPtr+writeMagicLen, sizeof(long)-writeMagicLen, 0))>0)
|
||||
{
|
||||
writeMagicLen += amntsent;
|
||||
}
|
||||
|
||||
sendPtr = (char *)&packetSize;
|
||||
while((!writeMagicNumber || writeMagicLen>=sizeof(long)) && writePktXfrLen<sizeof(long) &&
|
||||
(amntsent = send(handle, sendPtr+writePktXfrLen, sizeof(long)-writePktXfrLen, 0))>0)
|
||||
{
|
||||
writePktXfrLen += amntsent;
|
||||
}
|
||||
|
||||
while(writePktXfrLen>=sizeof(long) &&
|
||||
writeXfrLen < writeBufLen &&
|
||||
(amntsent = send(handle, writeBuf+writeXfrLen, writeBufLen-writeXfrLen, 0))>0)
|
||||
{
|
||||
if((writeXfrLen+=amntsent)>=writeBufLen)
|
||||
{
|
||||
result = writeBufLen;
|
||||
writeReset();
|
||||
}
|
||||
}
|
||||
|
||||
if(amntsent<=0)
|
||||
{
|
||||
int errCode = GetSocketErrno();
|
||||
|
||||
if((amntsent==0 && writePktXfrLen>0) ||
|
||||
(amntsent==-1 && (errCode == EWOULDBLOCK || errCode == EAGAIN)))
|
||||
{
|
||||
// *********************************************
|
||||
// * Do Nothing
|
||||
// *********************************************
|
||||
}
|
||||
else if(amntsent==-1)
|
||||
{
|
||||
outputError (CDEV_SEVERITY_ERROR, "SocketWriter",
|
||||
"Error number %i while writing to socket",
|
||||
errCode);
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(result==-1) writeReset();
|
||||
return result;
|
||||
}
|
||||
|
||||
inline int SocketWriter::writeGoodbye ( void )
|
||||
{
|
||||
int handle = getHandle();
|
||||
int result = 0;
|
||||
|
||||
if( handle<=0 ) result = -1;
|
||||
else
|
||||
{
|
||||
char val = -1;
|
||||
result=(send(handle, &val, 1, MSG_OOB)==1)?0:-1;
|
||||
}
|
||||
|
||||
if(result==-1) writeReset();
|
||||
return result;
|
||||
}
|
||||
|
||||
inline int SocketWriter::writeEnqueue ( char * buf, int buflen )
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
// *********************************************************************
|
||||
// * If data has already been transmitted, then it is impossible to
|
||||
// * add more data to the outbound buffer because it would invalidate
|
||||
// * the packet length and packet count variables.
|
||||
// *********************************************************************
|
||||
if(writePktXfrLen>0) result = -1;
|
||||
else
|
||||
{
|
||||
if(writePktCnt==0 &&
|
||||
(RNDUP(sizeof(long))+RNDUP(buflen)+RNDUP(sizeof(long))) > writeBufMax)
|
||||
{
|
||||
writeBufMax = (RNDUP(sizeof(long))+RNDUP(buflen)+RNDUP(sizeof(long))+WRITEBUF_PAD_SIZE);
|
||||
writeBuf = (char *)realloc(writeBuf, writeBufMax);
|
||||
writeBufLen = RNDUP(sizeof(long));
|
||||
writeNextPktPtr = writeBuf+writeBufLen;
|
||||
}
|
||||
if(writeBufLen+RNDUP(buflen)+RNDUP(sizeof(long)) < writeBufMax)
|
||||
{
|
||||
writePktCnt++;
|
||||
long tpktCnt = htonl(writePktCnt);
|
||||
memcpy(writeBuf, &tpktCnt, sizeof(long));
|
||||
|
||||
long tbuflen = htonl(buflen);
|
||||
memcpy(writeNextPktPtr, &tbuflen, sizeof(long));
|
||||
writeNextPktPtr+=RNDUP(sizeof(long));
|
||||
memcpy(writeNextPktPtr, buf, buflen);
|
||||
writeNextPktPtr+=RNDUP(buflen);
|
||||
writeBufLen = (int)(writeNextPktPtr-writeBuf);
|
||||
result = 0;
|
||||
}
|
||||
else result = -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
inline int SocketWriter::write(char * buf, int buflen)
|
||||
{
|
||||
writeEnqueue(buf, buflen);
|
||||
return writeContinue();
|
||||
}
|
||||
|
||||
#endif /* _SOCKET_UTIL_H */
|
||||
235
extensions/cdevGenericServer/include/StringHash.h
Normal file
235
extensions/cdevGenericServer/include/StringHash.h
Normal file
@@ -0,0 +1,235 @@
|
||||
#ifndef _VAR_STRING_HASH_H_
|
||||
#define _VAR_STRING_HASH_H_ 1
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
class StringHashNode
|
||||
{
|
||||
friend class StringHash;
|
||||
friend class StringHashIterator;
|
||||
|
||||
private:
|
||||
int copyKeyFlag;
|
||||
char * hashString;
|
||||
void * hashData;
|
||||
StringHashNode * next;
|
||||
|
||||
StringHashNode ( char * HashString, void * HashData, int copyKey=1);
|
||||
~StringHashNode ( void );
|
||||
};
|
||||
|
||||
|
||||
class StringHash
|
||||
{
|
||||
friend class StringHashIterator;
|
||||
|
||||
private:
|
||||
int tableSize;
|
||||
int copyKeyFlag;
|
||||
StringHashNode ** nodes;
|
||||
|
||||
public:
|
||||
StringHash (int copyKey = 1, int TableSize = 255 );
|
||||
~StringHash ( void );
|
||||
|
||||
inline unsigned int stringHash ( char * hashString );
|
||||
|
||||
inline void insert ( char * hashString, void * hashData );
|
||||
inline void remove ( char * hashString );
|
||||
inline void * find ( char * hashString );
|
||||
};
|
||||
|
||||
|
||||
class StringHashIterator
|
||||
{
|
||||
private:
|
||||
StringHash * hashTbl;
|
||||
StringHashNode * node;
|
||||
int idx;
|
||||
|
||||
public:
|
||||
StringHashIterator( StringHash * HashTbl );
|
||||
~StringHashIterator( void );
|
||||
|
||||
inline void * first ( void );
|
||||
inline void * operator ++ ( void );
|
||||
inline void * operator ++ ( int x );
|
||||
inline char * key ( void );
|
||||
inline void * data ( void );
|
||||
};
|
||||
|
||||
|
||||
inline StringHashNode::StringHashNode ( char * HashString, void * HashData, int copyKey )
|
||||
: next(NULL), copyKeyFlag(copyKey)
|
||||
{
|
||||
if(copyKeyFlag) hashString = strdup(HashString);
|
||||
else hashString = HashString;
|
||||
hashData = HashData;
|
||||
}
|
||||
|
||||
|
||||
inline StringHashNode::~StringHashNode ( void )
|
||||
{
|
||||
if(copyKeyFlag) delete hashString;
|
||||
}
|
||||
|
||||
|
||||
inline StringHash::StringHash ( int copyKey, int TableSize )
|
||||
: copyKeyFlag(copyKey), tableSize (TableSize)
|
||||
{
|
||||
nodes = new StringHashNode * [tableSize];
|
||||
memset(nodes, 0, sizeof(StringHashNode *) * tableSize );
|
||||
}
|
||||
|
||||
|
||||
inline StringHash::~StringHash ( void )
|
||||
{
|
||||
for(int i=0; i<tableSize; i++)
|
||||
{
|
||||
while(nodes[i]!=NULL)
|
||||
{
|
||||
StringHashNode * node = nodes[i];
|
||||
nodes[i] = node->next;
|
||||
delete node;
|
||||
}
|
||||
}
|
||||
delete nodes;
|
||||
}
|
||||
|
||||
inline unsigned int StringHash::stringHash ( char * hashString )
|
||||
{
|
||||
unsigned int hash = 0, g;
|
||||
|
||||
for (int i = 0; hashString[i] != '\0'; i++)
|
||||
{
|
||||
hash = (hash << 4) + hashString[i];
|
||||
if (g = hash & 0xf0000000)
|
||||
{
|
||||
hash ^= g >> 24;
|
||||
hash ^= g;
|
||||
}
|
||||
}
|
||||
return (hash % tableSize);
|
||||
}
|
||||
|
||||
inline void StringHash::insert (char * hashString, void * hashData )
|
||||
{
|
||||
unsigned int idx = stringHash(hashString);
|
||||
StringHashNode * prev = NULL, * node = nodes[idx];
|
||||
StringHashNode * newNode = new StringHashNode(hashString, hashData, copyKeyFlag);
|
||||
|
||||
while(node!=NULL && strcmp(node->hashString, hashString))
|
||||
{
|
||||
prev = node;
|
||||
node = prev->next;
|
||||
}
|
||||
if(node!=NULL)
|
||||
{
|
||||
newNode->next = node->next;
|
||||
delete node;
|
||||
}
|
||||
if(prev!=NULL) prev->next = newNode;
|
||||
else nodes[idx] = newNode;
|
||||
}
|
||||
|
||||
inline void StringHash::remove ( char * hashString )
|
||||
{
|
||||
unsigned int idx = stringHash(hashString);
|
||||
StringHashNode * prev = NULL, * node = nodes[idx];
|
||||
while(node!=NULL && strcmp(node->hashString, hashString))
|
||||
{
|
||||
prev = node;
|
||||
node = prev->next;
|
||||
}
|
||||
if(node!=NULL)
|
||||
{
|
||||
if(prev!=NULL) prev->next = node->next;
|
||||
else nodes[idx] = node->next;
|
||||
delete node;
|
||||
}
|
||||
}
|
||||
|
||||
inline void * StringHash::find ( char * hashString )
|
||||
{
|
||||
unsigned int idx = stringHash(hashString);
|
||||
StringHashNode * prev = NULL, * node = nodes[idx];
|
||||
while(node!=NULL && strcmp(node->hashString, hashString))
|
||||
{
|
||||
prev = node;
|
||||
node = prev->next;
|
||||
}
|
||||
return node!=NULL?node->hashData:NULL;
|
||||
}
|
||||
|
||||
|
||||
inline StringHashIterator::StringHashIterator(StringHash * HashTbl)
|
||||
: hashTbl(HashTbl), idx(0), node(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
inline StringHashIterator::~StringHashIterator( void )
|
||||
{
|
||||
}
|
||||
|
||||
inline void * StringHashIterator::first ( void )
|
||||
{
|
||||
if(hashTbl!=NULL)
|
||||
{
|
||||
for(idx = 0; idx<hashTbl->tableSize &&
|
||||
(node = hashTbl->nodes[idx])==NULL; idx++);
|
||||
}
|
||||
else node = NULL;
|
||||
return (node!=NULL)?node->hashData:NULL;
|
||||
}
|
||||
|
||||
inline void * StringHashIterator::operator ++ ( void )
|
||||
{
|
||||
if(hashTbl!=NULL)
|
||||
{
|
||||
if(node==NULL) first();
|
||||
else if(node->next!=NULL) node = node->next;
|
||||
else
|
||||
{
|
||||
node = NULL;
|
||||
do {
|
||||
idx++;
|
||||
} while(idx<hashTbl->tableSize &&
|
||||
(node = hashTbl->nodes[idx])==NULL);
|
||||
}
|
||||
}
|
||||
else node = NULL;
|
||||
return (node!=NULL)?node->hashData:NULL;
|
||||
}
|
||||
|
||||
inline void * StringHashIterator::operator ++ ( int x )
|
||||
{
|
||||
if(hashTbl!=NULL && x==0)
|
||||
{
|
||||
if(node==NULL) first();
|
||||
else if(node->next!=NULL) node = node->next;
|
||||
else
|
||||
{
|
||||
node = NULL;
|
||||
do {
|
||||
idx++;
|
||||
} while(idx<hashTbl->tableSize &&
|
||||
(node = hashTbl->nodes[idx])==NULL);
|
||||
}
|
||||
}
|
||||
else node = NULL;
|
||||
return (node!=NULL)?node->hashData:NULL;
|
||||
}
|
||||
|
||||
inline char * StringHashIterator::key ( void )
|
||||
{
|
||||
return (node!=NULL)?node->hashString:(char *)NULL;
|
||||
}
|
||||
|
||||
inline void * StringHashIterator::data ( void )
|
||||
{
|
||||
return (node!=NULL)?node->hashData:NULL;
|
||||
}
|
||||
|
||||
#endif /* _VAR_STRING_HASH_H_ */
|
||||
235
extensions/cdevGenericServer/include/VarStrHash.h
Normal file
235
extensions/cdevGenericServer/include/VarStrHash.h
Normal file
@@ -0,0 +1,235 @@
|
||||
#ifndef _VAR_STRING_HASH_H_
|
||||
#define _VAR_STRING_HASH_H_ 1
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
class VarStrHashNode
|
||||
{
|
||||
friend class VarStrHash;
|
||||
friend class VarStrHashIterator;
|
||||
|
||||
private:
|
||||
int copyKeyFlag;
|
||||
char * hashString;
|
||||
void * hashData;
|
||||
VarStrHashNode * next;
|
||||
|
||||
VarStrHashNode ( char * HashString, void * HashData, int copyKey=1);
|
||||
~VarStrHashNode ( void );
|
||||
};
|
||||
|
||||
|
||||
class VarStrHash
|
||||
{
|
||||
friend class VarStrHashIterator;
|
||||
|
||||
private:
|
||||
int tableSize;
|
||||
int copyKeyFlag;
|
||||
VarStrHashNode ** nodes;
|
||||
|
||||
public:
|
||||
VarStrHash (int copyKey = 1, int TableSize = 255 );
|
||||
~VarStrHash ( void );
|
||||
|
||||
inline unsigned char stringHash ( char * hashString );
|
||||
|
||||
inline void insert ( char * hashString, void * hashData );
|
||||
inline void remove ( char * hashString );
|
||||
inline void * find ( char * hashString );
|
||||
};
|
||||
|
||||
|
||||
class VarStrHashIterator
|
||||
{
|
||||
private:
|
||||
VarStrHash * hashTbl;
|
||||
VarStrHashNode * node;
|
||||
int idx;
|
||||
|
||||
public:
|
||||
VarStrHashIterator( VarStrHash * HashTbl );
|
||||
~VarStrHashIterator( void );
|
||||
|
||||
inline void * first ( void );
|
||||
inline void * operator ++ ( void );
|
||||
inline void * operator ++ ( int x );
|
||||
inline char * key ( void );
|
||||
inline void * data ( void );
|
||||
};
|
||||
|
||||
|
||||
inline VarStrHashNode::VarStrHashNode ( char * HashString, void * HashData, int copyKey )
|
||||
: next(NULL), copyKeyFlag(copyKey)
|
||||
{
|
||||
if(copyKeyFlag) hashString = strdup(HashString);
|
||||
else hashString = HashString;
|
||||
hashData = HashData;
|
||||
}
|
||||
|
||||
|
||||
inline VarStrHashNode::~VarStrHashNode ( void )
|
||||
{
|
||||
if(copyKeyFlag) delete hashString;
|
||||
}
|
||||
|
||||
|
||||
inline VarStrHash::VarStrHash ( int copyKey, int TableSize )
|
||||
: copyKeyFlag(copyKey), tableSize (TableSize)
|
||||
{
|
||||
nodes = new VarStrHashNode * [tableSize];
|
||||
memset(nodes, 0, sizeof(VarStrHashNode *) * tableSize );
|
||||
}
|
||||
|
||||
|
||||
inline VarStrHash::~VarStrHash ( void )
|
||||
{
|
||||
for(int i=0; i<tableSize; i++)
|
||||
{
|
||||
while(nodes[i]!=NULL)
|
||||
{
|
||||
VarStrHashNode * node = nodes[i];
|
||||
nodes[i] = node->next;
|
||||
delete node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned char VarStrHash::stringHash ( char * hashString )
|
||||
{
|
||||
unsigned char idx=0;
|
||||
unsigned int hash = 0, g;
|
||||
|
||||
for (int i = 0; hashString[i] != '\0'; i++)
|
||||
{
|
||||
hash = (hash << 4) + hashString[i];
|
||||
if (g = hash & 0xf0000000)
|
||||
{
|
||||
hash ^= g >> 24;
|
||||
hash ^= g;
|
||||
}
|
||||
}
|
||||
return (hash % tableSize);
|
||||
}
|
||||
|
||||
inline void VarStrHash::insert (char * hashString, void * hashData )
|
||||
{
|
||||
unsigned char idx = stringHash(hashString);
|
||||
VarStrHashNode * prev = NULL, * node = nodes[idx];
|
||||
VarStrHashNode * newNode = new VarStrHashNode(hashString, hashData, copyKeyFlag);
|
||||
|
||||
while(node!=NULL && strcmp(node->hashString, hashString))
|
||||
{
|
||||
prev = node;
|
||||
node = prev->next;
|
||||
}
|
||||
if(node!=NULL)
|
||||
{
|
||||
newNode->next = node->next;
|
||||
delete node;
|
||||
}
|
||||
if(prev!=NULL) prev->next = newNode;
|
||||
else nodes[idx] = newNode;
|
||||
}
|
||||
|
||||
inline void VarStrHash::remove ( char * hashString )
|
||||
{
|
||||
unsigned char idx = stringHash(hashString);
|
||||
VarStrHashNode * prev = NULL, * node = nodes[idx];
|
||||
while(node!=NULL && strcmp(node->hashString, hashString))
|
||||
{
|
||||
prev = node;
|
||||
node = prev->next;
|
||||
}
|
||||
if(node!=NULL)
|
||||
{
|
||||
if(prev!=NULL) prev->next = node->next;
|
||||
else nodes[idx] = node->next;
|
||||
delete node;
|
||||
}
|
||||
}
|
||||
|
||||
inline void * VarStrHash::find ( char * hashString )
|
||||
{
|
||||
unsigned char idx = stringHash(hashString);
|
||||
VarStrHashNode * prev = NULL, * node = nodes[idx];
|
||||
while(node!=NULL && strcmp(node->hashString, hashString))
|
||||
{
|
||||
prev = node;
|
||||
node = prev->next;
|
||||
}
|
||||
return node!=NULL?node->hashData:NULL;
|
||||
}
|
||||
|
||||
|
||||
inline VarStrHashIterator::VarStrHashIterator(VarStrHash * HashTbl)
|
||||
: hashTbl(HashTbl), idx(0), node(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
inline VarStrHashIterator::~VarStrHashIterator( void )
|
||||
{
|
||||
}
|
||||
|
||||
inline void * VarStrHashIterator::first ( void )
|
||||
{
|
||||
if(hashTbl!=NULL)
|
||||
{
|
||||
for(idx = 0; idx<hashTbl->tableSize &&
|
||||
(node = hashTbl->nodes[idx])==NULL; idx++);
|
||||
}
|
||||
else node = NULL;
|
||||
return (node!=NULL)?node->hashData:NULL;
|
||||
}
|
||||
|
||||
inline void * VarStrHashIterator::operator ++ ( void )
|
||||
{
|
||||
if(hashTbl!=NULL)
|
||||
{
|
||||
if(node==NULL) first();
|
||||
else if(node->next!=NULL) node = node->next;
|
||||
else
|
||||
{
|
||||
node = NULL;
|
||||
do {
|
||||
idx++;
|
||||
} while(idx<hashTbl->tableSize &&
|
||||
(node = hashTbl->nodes[idx])==NULL);
|
||||
}
|
||||
}
|
||||
else node = NULL;
|
||||
return (node!=NULL)?node->hashData:NULL;
|
||||
}
|
||||
|
||||
inline void * VarStrHashIterator::operator ++ ( int x )
|
||||
{
|
||||
if(hashTbl!=NULL && x==0)
|
||||
{
|
||||
if(node==NULL) first();
|
||||
else if(node->next!=NULL) node = node->next;
|
||||
else
|
||||
{
|
||||
node = NULL;
|
||||
do {
|
||||
idx++;
|
||||
} while(idx<hashTbl->tableSize &&
|
||||
(node = hashTbl->nodes[idx])==NULL);
|
||||
}
|
||||
}
|
||||
else node = NULL;
|
||||
return (node!=NULL)?node->hashData:NULL;
|
||||
}
|
||||
|
||||
inline char * VarStrHashIterator::key ( void )
|
||||
{
|
||||
return (node!=NULL)?node->hashString:NULL;
|
||||
}
|
||||
|
||||
inline void * VarStrHashIterator::data ( void )
|
||||
{
|
||||
return (node!=NULL)?node->hashData:NULL;
|
||||
}
|
||||
|
||||
#endif /* _VAR_STRING_HASH_H_ */
|
||||
48
extensions/cdevGenericServer/include/cdevAddr.h
Normal file
48
extensions/cdevGenericServer/include/cdevAddr.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef _CDEV_ADDR_H_
|
||||
#define _CDEV_ADDR_H_
|
||||
|
||||
#include "cdevPlatforms.h"
|
||||
|
||||
class CDEV_REACTOR_API cdevAddr
|
||||
{
|
||||
protected:
|
||||
int addr_type;
|
||||
int addr_size;
|
||||
|
||||
public:
|
||||
cdevAddr ( void ) : addr_type(0), addr_size(0) {}
|
||||
cdevAddr ( int type, int size ) : addr_type(type), addr_size(size) {}
|
||||
int getSize ( void ) const { return addr_size; }
|
||||
void setSize ( int size ) { addr_size = size; }
|
||||
int getType ( void ) const { return addr_type; }
|
||||
void setType ( int type ) { addr_type = type; }
|
||||
|
||||
virtual void * getAddress ( void ) const { return NULL; }
|
||||
|
||||
};
|
||||
|
||||
|
||||
class CDEV_REACTOR_API cdevInetAddr : public cdevAddr
|
||||
{
|
||||
protected:
|
||||
sockaddr_in inet_addr;
|
||||
|
||||
public:
|
||||
cdevInetAddr (void);
|
||||
cdevInetAddr (const cdevInetAddr & addr);
|
||||
cdevInetAddr (const sockaddr_in *, int len);
|
||||
cdevInetAddr (unsigned short portnum, char hostname[]);
|
||||
cdevInetAddr (unsigned short portnum, long ip_addr=INADDR_ANY);
|
||||
|
||||
int set (unsigned short portnum, const char hostname[]);
|
||||
int set (unsigned short portnum, long ip_addr=INADDR_ANY);
|
||||
int set (const sockaddr_in *, int len);
|
||||
|
||||
const char * getHostName ( void ) const;
|
||||
const char * getHostAddr ( void ) const;
|
||||
unsigned long getInetAddr ( void ) const;
|
||||
unsigned short getPortNum ( void ) const;
|
||||
void * getAddress ( void ) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
114
extensions/cdevGenericServer/include/cdevBufferedSocket.h
Normal file
114
extensions/cdevGenericServer/include/cdevBufferedSocket.h
Normal file
@@ -0,0 +1,114 @@
|
||||
#ifndef _CDEV_BUFFERED_SOCKET_H_
|
||||
#define _CDEV_BUFFERED_SOCKET_H_
|
||||
|
||||
#include "cdevSocketConnector.h"
|
||||
#include "cdevStreamQueue.h"
|
||||
|
||||
class cdevBufferedSocket : public cdevSocketConnector, public cdevNodeFactory
|
||||
{
|
||||
private:
|
||||
cdevNodeFactory * nodeFactory;
|
||||
|
||||
int magicNumber;
|
||||
int deleteFlag;
|
||||
|
||||
cdevStreamQueue activeOut;
|
||||
cdevStreamQueue waitingOut;
|
||||
int outboundHeader[3];
|
||||
size_t headerXfrLen;
|
||||
size_t dataXfrLen;
|
||||
|
||||
cdevStreamQueue waitingIn;
|
||||
cdevStreamNode * rcvNode;
|
||||
int inboundHeader[3];
|
||||
size_t headerRcvLen;
|
||||
size_t dataRcvLen;
|
||||
size_t subPacketLen;
|
||||
|
||||
static void sigPipeHandler (int);
|
||||
|
||||
public:
|
||||
enum {RETRYCNT = 1000 };
|
||||
|
||||
inline cdevBufferedSocket ( int MagicNumber=0, int deleteNodes = 1, cdevNodeFactory * factory=NULL );
|
||||
|
||||
inline int outboundReady ( void );
|
||||
inline int inboundReady ( void );
|
||||
inline void enqueueOutbound ( cdevStreamNode * node );
|
||||
inline cdevStreamNode * dequeueInbound ( void );
|
||||
|
||||
cdevStreamNode * newNode ( ssize_t size );
|
||||
ssize_t transmit ( void );
|
||||
ssize_t receive ( void );
|
||||
|
||||
int getBlockingSemantics ( void ) const;
|
||||
int getRcvBufferSize ( void ) const;
|
||||
int getSndBufferSize ( void ) const;
|
||||
};
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * cdevBufferedSocket::cdevBufferedSocket :
|
||||
// * This is the constructor for the cdevBufferedSocket, it will initialize
|
||||
// * all internal variables and sub-classes.
|
||||
// *****************************************************************************
|
||||
inline cdevBufferedSocket::cdevBufferedSocket ( int MagicNumber, int deleteNodes, cdevNodeFactory * factory )
|
||||
: nodeFactory(factory),
|
||||
magicNumber(MagicNumber),
|
||||
deleteFlag (deleteNodes),
|
||||
activeOut(deleteNodes),
|
||||
waitingOut(deleteNodes),
|
||||
headerXfrLen(0),
|
||||
dataXfrLen(0),
|
||||
waitingIn(),
|
||||
rcvNode(NULL),
|
||||
headerRcvLen(0),
|
||||
dataRcvLen(0),
|
||||
subPacketLen(0)
|
||||
{
|
||||
if(nodeFactory==NULL) nodeFactory=this;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * cdevBufferedSocket::outboundReady :
|
||||
// * This method returns an integer value indicating that outbound data is
|
||||
// * ready for transmission.
|
||||
// *****************************************************************************
|
||||
inline int cdevBufferedSocket::outboundReady ( void )
|
||||
{
|
||||
return !(activeOut.isEmpty() && waitingOut.isEmpty());
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * cdevBufferedSocket::inboundReady :
|
||||
// * This method returns a flag indicating that inbound data is ready to be
|
||||
// * dequeued and processed.
|
||||
// *****************************************************************************
|
||||
inline int cdevBufferedSocket::inboundReady ( void )
|
||||
{
|
||||
return !(waitingIn.isEmpty() && headerRcvLen==0);
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * cdevBufferedSocket::enqueueOutbound :
|
||||
// * This method places the user defined cdevStreamNode pointer into the
|
||||
// * waitingOut object.
|
||||
// *****************************************************************************
|
||||
inline void cdevBufferedSocket::enqueueOutbound ( cdevStreamNode * node )
|
||||
{
|
||||
waitingOut.enqueue(node);
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * cdevBufferedSocket::dequeueInbound :
|
||||
// * This method dequeues the next available cdevStreamNode object from the
|
||||
// * waitingIn object.
|
||||
// *****************************************************************************
|
||||
inline cdevStreamNode * cdevBufferedSocket::dequeueInbound ( void )
|
||||
{
|
||||
return waitingIn.dequeue();
|
||||
}
|
||||
|
||||
|
||||
#endif /* _CDEV_BUFFERED_SOCKET_H_ */
|
||||
223
extensions/cdevGenericServer/include/cdevClientRequestObject.h
Normal file
223
extensions/cdevGenericServer/include/cdevClientRequestObject.h
Normal file
@@ -0,0 +1,223 @@
|
||||
#if !defined (_CDEV_CLIENT_REQUEST_OBJECT_H_)
|
||||
#define _CDEV_CLIENT_REQUEST_OBJECT_H_
|
||||
|
||||
#include <cdevGroup.h>
|
||||
#include <cdevErrCode.h>
|
||||
#include <cdevClientService.h>
|
||||
|
||||
// *****************************************************************************
|
||||
// * cdevClientRequestObject:
|
||||
// * The cdevClientRequestObject class provides the interface for sending
|
||||
// * messages to a server. All device/message commands are routed
|
||||
// * through a cdevClientRequestObject either directly or indirectly.
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API cdevClientRequestObject : public cdevRequestObject, public ServerHandlerCallback
|
||||
{
|
||||
protected:
|
||||
typedef struct
|
||||
{
|
||||
int completionCode;
|
||||
int finished;
|
||||
} SendStatus;
|
||||
|
||||
SendStatus sendStatus;
|
||||
char server [256];
|
||||
char DDL_server[256];
|
||||
cdevCallback syncCallback;
|
||||
ServerHandler * handler;
|
||||
int contextID;
|
||||
|
||||
int commandCode;
|
||||
int messageCode;
|
||||
|
||||
public:
|
||||
// *********************************************************************
|
||||
// * These enumerated type are used to identify the basic four commands
|
||||
// * that might be represented by a cdevClientRequestObject... By using
|
||||
// * these identifiers the cdevService does not have to perform a
|
||||
// * string compare in order to identify the nature of the request
|
||||
// * object.
|
||||
// *
|
||||
// * At construction the cdevClientRequestObject will set the
|
||||
// * commandCode to contain the correct value, the developer may
|
||||
// * override this setting in the constructor for an inherited class.
|
||||
// *
|
||||
// * Enumerated list extensions created by developers should begin at
|
||||
// * value cdevClientRequestObject::MONITOR_OFF_COMMAND+1.
|
||||
// *
|
||||
// * The current setting of the commandCode may be obtained by calling
|
||||
// * the getCommandCode method of the class.
|
||||
// *********************************************************************
|
||||
enum {OTHER_COMMAND = 0,
|
||||
GET_COMMAND,
|
||||
SET_COMMAND,
|
||||
MONITOR_ON_COMMAND,
|
||||
MONITOR_OFF_COMMAND};
|
||||
|
||||
// *********************************************************************
|
||||
// * These enumerated type are used to identify the messages that are
|
||||
// * intrinisicly supported by the cdevService... By using
|
||||
// * these identifiers the cdevService does not have to perform a
|
||||
// * string compare in order to identify the nature of the request
|
||||
// * object.
|
||||
// *
|
||||
// * At construction the cdevClientRequestObject will set the
|
||||
// * messageCode to contain the correct value, the developer may
|
||||
// * override this setting in the constructor for an inherited class.
|
||||
// *
|
||||
// * Enumerated list extensions created by developers should begin at
|
||||
// * value cdevClientRequestObject::SET_DEFAULT_MESSAGE+1
|
||||
// *
|
||||
// * The current setting of the commandCode may be obtained by calling
|
||||
// * the getMessageCode method of the class.
|
||||
// *********************************************************************
|
||||
enum {OTHER_MESSAGE = 0,
|
||||
GET_SERVERS_MESSAGE,
|
||||
GET_DEFAULT_MESSAGE,
|
||||
SET_DEFAULT_MESSAGE,
|
||||
DISCONNECT_MESSAGE,
|
||||
GET_CLIENTINFO_MESSAGE,
|
||||
GET_SERVERINFO_MESSAGE};
|
||||
|
||||
cdevClientRequestObject ( char * device, char * message,
|
||||
cdevSystem & system = cdevSystem::defaultSystem());
|
||||
|
||||
virtual ~cdevClientRequestObject ( void );
|
||||
|
||||
// *********************************************************************
|
||||
// * cdevClientRequestObject::getState :
|
||||
// * Returns the connection state of the cdevClientRequestObject.
|
||||
// *********************************************************************
|
||||
virtual int getState ( void );
|
||||
|
||||
// *********************************************************************
|
||||
// * cdevClientRequestObject::setContext :
|
||||
// * This mechanism is used to specify the default server that will
|
||||
// * be used for the request.
|
||||
// *********************************************************************
|
||||
virtual int setContext ( cdevData & ctx);
|
||||
|
||||
// *********************************************************************
|
||||
// * cdevClientRequestObject::send :
|
||||
// * The send interface is used to provide synchronous I/O with the
|
||||
// * service.
|
||||
// *
|
||||
// * Returns CDEV_SUCCESS on success or CDEV_ERROR on error.
|
||||
// *********************************************************************
|
||||
virtual int send ( cdevData & in, cdevData & out );
|
||||
virtual int send ( cdevData * in, cdevData & out );
|
||||
virtual int send ( cdevData & in, cdevData * out );
|
||||
virtual int send ( cdevData * in, cdevData * out );
|
||||
|
||||
// *********************************************************************
|
||||
// * cdevClientRequestObject::sendNoBlock :
|
||||
// * The sendNoBlock interface is used in conjunction with cdevGroup
|
||||
// * or cdevSystem to execute a series of operations. During the
|
||||
// * early implementation of this product, these functions will be
|
||||
// * linked directly to the send call.
|
||||
// *
|
||||
// * Returns CDEV_SUCCESS on success or CDEV_ERROR on error.
|
||||
// *********************************************************************
|
||||
virtual int sendNoBlock (cdevData & in, cdevData & out);
|
||||
virtual int sendNoBlock (cdevData * in, cdevData & out);
|
||||
virtual int sendNoBlock (cdevData & in, cdevData * out);
|
||||
virtual int sendNoBlock (cdevData * in, cdevData * out);
|
||||
|
||||
// *********************************************************************
|
||||
// * cdevClientRequestObject::sendCallback :
|
||||
// * The sendCallback interface provides asynchronous communications
|
||||
// * with the server. During the early implementation of this
|
||||
// * product, these functions will be linked directly to the send
|
||||
// * call.
|
||||
// *
|
||||
// * Returns CDEV_SUCCESS on success or CDEV_ERROR on error.
|
||||
// *********************************************************************
|
||||
virtual int sendCallback (cdevData & in, cdevCallback & callback);
|
||||
virtual int sendCallback (cdevData * in, cdevCallback & callback);
|
||||
|
||||
virtual const char * className ( void ) const;
|
||||
|
||||
// *********************************************************************
|
||||
// * cdevClientRequestObject::deafultCallback :
|
||||
// * This is the callback function that is used by the object to
|
||||
// * receive callbacks for send operations.
|
||||
// *********************************************************************
|
||||
static void defaultCallback (int status, void * user, cdevRequestObject &, cdevData &);
|
||||
|
||||
// *********************************************************************
|
||||
// * The requestObject registers itself with the ServerHandler when it
|
||||
// * attaches to it... If the Serverhandler is destroyed, it will
|
||||
// * call this method on all of the registered request objects in order
|
||||
// * to notify them that it is going away. This allows the request
|
||||
// * object to clear the pointer to the ServerHandler.
|
||||
// *********************************************************************
|
||||
virtual void executeServerHandlerCallback (ServerHandler * Handler);
|
||||
|
||||
// *********************************************************************
|
||||
// * This method is used to obtain the ServerHandler for this request
|
||||
// * object...
|
||||
// *
|
||||
// * The following rules will be followed:
|
||||
// * 1) If a server has been specified in the context, then that
|
||||
// * server will be used.
|
||||
// *
|
||||
// * - otherwise -
|
||||
// *
|
||||
// * 2) If a server has been specified in the service data of the
|
||||
// * DDL file, then that server will be used.
|
||||
// *
|
||||
// * - otherwise -
|
||||
// *
|
||||
// * 3) The default server as specified at the cdevClientService will
|
||||
// * be used.
|
||||
// *********************************************************************
|
||||
virtual int getServerHandler (ServerHandler ** Handler);
|
||||
|
||||
// *********************************************************************
|
||||
// * This method allows the caller to determine if the request object
|
||||
// * is restartable. If a server goes down and then a new server comes
|
||||
// * up in its place, this method will be called for each request object
|
||||
// * that has an outstanding request that has not been serviced.
|
||||
// * If the isRequestRestartable method returns 1, the request will be
|
||||
// * sent to the new server - otherwise, the request will be terminated.
|
||||
// *********************************************************************
|
||||
virtual int isRequestRestartable ( void );
|
||||
|
||||
// *********************************************************************
|
||||
// * getContextID :
|
||||
// * This method will retrieve the identifier of the context that
|
||||
// * is currently in use by this object.
|
||||
// *********************************************************************
|
||||
int getContextID ( void );
|
||||
|
||||
// *********************************************************************
|
||||
// * getCommandCode :
|
||||
// * This method will return the current value of the commandCode
|
||||
// * variable. This variable is used to identify the VERB that is
|
||||
// * utilized by this cdevRequestObject. The default set of verbs
|
||||
// * are "get", "set", "monitorOn", and "monitorOff".
|
||||
// *********************************************************************
|
||||
int getCommandCode ( void );
|
||||
|
||||
// *********************************************************************
|
||||
// * getMessageCode :
|
||||
// * This method will return the current value of the messageCode
|
||||
// * variable. This variable is used to identify the message that is
|
||||
// * utilized by this cdevRequestObject. The default set of
|
||||
// * supported messages are "get servers", "get default",
|
||||
// * "set default", and "disconnect".
|
||||
// *********************************************************************
|
||||
int getMessageCode ( void );
|
||||
|
||||
|
||||
// *********************************************************************
|
||||
// * waitPeriod :
|
||||
// * This method returns a double that indicates the maximum amount
|
||||
// * of time that the service should wait for a synchronous result to
|
||||
// * be returned.
|
||||
// *********************************************************************
|
||||
virtual double waitPeriod ( void ) { return 10.0; }
|
||||
};
|
||||
|
||||
|
||||
#endif /* _CDEV_CLIENT_REQUEST_OBJECT_H_ */
|
||||
140
extensions/cdevGenericServer/include/cdevClientService.h
Normal file
140
extensions/cdevGenericServer/include/cdevClientService.h
Normal file
@@ -0,0 +1,140 @@
|
||||
#if !defined (_CDEV_CLIENT_SERVICE_H_)
|
||||
#define _CDEV_CLIENT_SERVICE_H_
|
||||
|
||||
#include <cdevService.h>
|
||||
#include <cdevRequestObject.h>
|
||||
#include <cdevTranObj.h>
|
||||
#include <ServerInterface.h>
|
||||
#include <AddressIndex.h>
|
||||
#include <cdevContextMap.h>
|
||||
#include <ClientInfo.h>
|
||||
#include <cdevGenericServerTags.h>
|
||||
#include <StringHash.h>
|
||||
|
||||
// *****************************************************************************
|
||||
// * class NSCallbackArg :
|
||||
// * This class is provided as a technique for allowing the name server
|
||||
// * to differentiate when making monitorOn requests between two servers that
|
||||
// * use the same service.
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API NSCallbackArg
|
||||
{
|
||||
friend class cdevClientService;
|
||||
|
||||
private:
|
||||
char * server;
|
||||
cdevClientService * service;
|
||||
|
||||
NSCallbackArg ( char * Server, cdevClientService * Service )
|
||||
: server(strdup(Server)), service(Service)
|
||||
{
|
||||
}
|
||||
|
||||
~NSCallbackArg ( void )
|
||||
{
|
||||
if(server) delete server;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * cdevClientService:
|
||||
// * This is class provides the mechanisms that the cdev system will use
|
||||
// * to communicate with the model service.
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API cdevClientService : public cdevService,
|
||||
public ServerInterface,
|
||||
public cdevTagTableCallback
|
||||
{
|
||||
friend class cdevClientRequestObject;
|
||||
friend class cdevClientTransaction;
|
||||
|
||||
public:
|
||||
enum { ServiceTagBase=511 };
|
||||
|
||||
static int ServerTag;
|
||||
static int HostTag;
|
||||
static int PortTag;
|
||||
|
||||
cdevClientService ( char * domain, char * name, cdevSystem & system = cdevSystem::defaultSystem());
|
||||
static void defaultCallback (int, void *, cdevRequestObject &, cdevData &);
|
||||
static void nameServerCallback(int, void *, cdevRequestObject &, cdevData &);
|
||||
virtual int outputError (int severity, char *name, char *formatString, ...);
|
||||
ServerHandler * connect ( char * server, char * host=NULL, unsigned short port = 0);
|
||||
ServerHandler * disconnect ( char * server );
|
||||
|
||||
int flush ( void );
|
||||
int pend ( double seconds, int fd = -1 );
|
||||
int getFd ( int * &fd, int & numFd );
|
||||
|
||||
int poll ( void );
|
||||
int pend ( int fd = -1 );
|
||||
int getNameServer ( cdevDevice * &ns );
|
||||
int getRequestObject ( char * device, char * message, cdevRequestObject * &req);
|
||||
|
||||
int enqueue ( char * server, cdevData * in, cdevTranObj & xobj );
|
||||
int enqueue ( ServerHandler * handler, cdevData * in, cdevTranObj & xobj );
|
||||
int enqueue ( ServerHandler * handler, class cdevClientTransaction &, unsigned);
|
||||
int cancel ( cdevTranObj & xobj );
|
||||
int enqueue ( int status, ServerHandler * handler, char * binary, size_t binaryLen );
|
||||
int isPacketValid ( char * binary, size_t binaryLen );
|
||||
void callback ( int newTag, char * newName );
|
||||
char * getDomain ( void ) const { return domain; }
|
||||
|
||||
protected:
|
||||
virtual ~cdevClientService ( void );
|
||||
virtual void fireCallback ( int status, cdevTranObj &xobj, cdevData *resultData, int partialTransaction = 0 );
|
||||
virtual int processLocal ( cdevData * in, cdevTranObj & xobj );
|
||||
|
||||
char * domain;
|
||||
AddressIndex transactions;
|
||||
cdevCallback syncCallback;
|
||||
cdevContextMap contexts;
|
||||
int quitFlag;
|
||||
StringHash nsCallbackArgs;
|
||||
static ClientInfo clientInfo;
|
||||
static cdevGenericServerTagDef tags;
|
||||
|
||||
NSCallbackArg * getCallbackArg ( char * server );
|
||||
};
|
||||
|
||||
class GENERIC_SERVER_API cdevClientTransaction
|
||||
{
|
||||
private:
|
||||
// *********************************************************************
|
||||
// * Free list data elements and private array constructor.
|
||||
// *********************************************************************
|
||||
enum {ALLOCATION_COUNT = 16 };
|
||||
static cdevClientTransaction * freeList_;
|
||||
cdevClientTransaction * freeListNext_;
|
||||
cdevClientTransaction ( void );
|
||||
|
||||
public:
|
||||
// *********************************************************************
|
||||
// * Public free list interface.
|
||||
// *********************************************************************
|
||||
void * operator new ( size_t size );
|
||||
void operator delete ( void * ptr );
|
||||
|
||||
char server[256];
|
||||
cdevTranObj * xobj;
|
||||
int permanent;
|
||||
int statusCode;
|
||||
|
||||
// *********************************************************************
|
||||
// * Data elements used for restartable transactions.
|
||||
// *********************************************************************
|
||||
int restartable;
|
||||
int contextID;
|
||||
cdevData * userData;
|
||||
|
||||
cdevClientTransaction ( cdevTranObj & XObj, ServerHandler &handler,
|
||||
int Restartable=0, cdevData *data=NULL,
|
||||
unsigned ContextID=0 );
|
||||
virtual ~cdevClientTransaction ( void );
|
||||
void reconnect (char * host=NULL, unsigned short port=0, unsigned key=0);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* _CDEV_CLIENT_SERVICE_H_ */
|
||||
33
extensions/cdevGenericServer/include/cdevContextMap.h
Normal file
33
extensions/cdevGenericServer/include/cdevContextMap.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef _CDEV_CONTEXT_MAP_H_
|
||||
#define _CDEV_CONTEXT_MAP_H_ 1
|
||||
#include <cdevPlatforms.h>
|
||||
#include <cdevData.h>
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * class cdevContextMap :
|
||||
// * The purpose of this class is to allow the user to store a list of
|
||||
// * commonly used context cdevData items. This will allow the caller to
|
||||
// * pass the context to maintain a list of contexts that are identifiable
|
||||
// * by a unique integer identifier...
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API cdevContextMap
|
||||
{
|
||||
protected:
|
||||
cdevData ** entries;
|
||||
size_t maximum;
|
||||
size_t cnt;
|
||||
|
||||
void resize ( void );
|
||||
|
||||
public:
|
||||
cdevContextMap ( void );
|
||||
~cdevContextMap ( void );
|
||||
int insert ( cdevData & context );
|
||||
int find ( cdevData & context );
|
||||
cdevData * find ( int idx ) { return (idx>cnt || idx<0)?(cdevData *)NULL:entries[idx]; }
|
||||
void asciiDump ( FILE * fp = stdout );
|
||||
};
|
||||
|
||||
#endif /* _CDEV_CONTEXT_MAP_H_ */
|
||||
|
||||
54
extensions/cdevGenericServer/include/cdevEventHandler.h
Normal file
54
extensions/cdevGenericServer/include/cdevEventHandler.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#ifndef _CDEV_EVENT_HANDLER_H_
|
||||
#define _CDEV_EVENT_HANDLER_H_ 1
|
||||
|
||||
#include "cdevTime.h"
|
||||
|
||||
class CDEV_REACTOR_API cdevEventHandler
|
||||
{
|
||||
friend class cdevReactor;
|
||||
|
||||
public:
|
||||
enum {
|
||||
READ_MASK = 0x01,
|
||||
EXCEPT_MASK = 0x02,
|
||||
WRITE_MASK = 0x04,
|
||||
DONT_CALL = 0x100
|
||||
} REACTOR_MASK;
|
||||
|
||||
private:
|
||||
void setReactor (cdevReactor * r);
|
||||
cdevEventHandler * getNext (void );
|
||||
void setNext (cdevEventHandler * n);
|
||||
cdevTime & getNextTimeout (void);
|
||||
|
||||
protected:
|
||||
cdevEventHandler * next;
|
||||
cdevTime nextTimeout;
|
||||
cdevReactor * reactor;
|
||||
cdevTime timeoutRate;
|
||||
int mask;
|
||||
|
||||
public:
|
||||
cdevEventHandler ( void );
|
||||
virtual ~cdevEventHandler ( void );
|
||||
|
||||
virtual void setMask ( unsigned Mask );
|
||||
virtual void setHandle ( int handle );
|
||||
virtual int getHandle ( void ) const;
|
||||
virtual int getMask ( void );
|
||||
virtual cdevReactor * getReactor ( void );
|
||||
|
||||
virtual cdevTime & getTimeoutRate ( void );
|
||||
virtual void setTimeoutRate ( cdevTime time );
|
||||
virtual void resetTimer ( void );
|
||||
|
||||
virtual int handleInput ( void );
|
||||
virtual int handleOutput ( void );
|
||||
virtual int handleExcept ( void );
|
||||
virtual int handleTimeout ( void );
|
||||
virtual int handleSignal ( void );
|
||||
virtual int handleClose ( void );
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
66
extensions/cdevGenericServer/include/cdevGenericServerTags.h
Normal file
66
extensions/cdevGenericServer/include/cdevGenericServerTags.h
Normal file
@@ -0,0 +1,66 @@
|
||||
static char * cdevGenericServerTags[] =
|
||||
{
|
||||
"client",
|
||||
"clientCnt",
|
||||
"commandline",
|
||||
"connecttime",
|
||||
"datasize",
|
||||
"domain",
|
||||
"gid",
|
||||
"group",
|
||||
"host",
|
||||
"key",
|
||||
"keyExp",
|
||||
"keyType",
|
||||
"machine",
|
||||
"name",
|
||||
"os",
|
||||
"osrelease",
|
||||
"osversion",
|
||||
"owner",
|
||||
"pctcpu",
|
||||
"pid",
|
||||
"ping",
|
||||
"port",
|
||||
"program",
|
||||
"queryMsg",
|
||||
"recvPktCnt",
|
||||
"resultCode",
|
||||
"sendPktCnt",
|
||||
"server",
|
||||
"shell",
|
||||
"socket",
|
||||
"starttime",
|
||||
"table",
|
||||
"time",
|
||||
"uid",
|
||||
"username",
|
||||
NULL
|
||||
};
|
||||
|
||||
class cdevGenericServerTagDef
|
||||
{
|
||||
public:
|
||||
enum {GENERIC_BASE_TAG=900};
|
||||
|
||||
cdevGenericServerTagDef ( void )
|
||||
{
|
||||
installTags();
|
||||
}
|
||||
|
||||
void installTags ( void )
|
||||
{
|
||||
|
||||
for(int i=0; cdevGenericServerTags[i]!=NULL; i++)
|
||||
{
|
||||
int tagVal;
|
||||
|
||||
cdevData::insertTag(GENERIC_BASE_TAG+i, cdevGenericServerTags[i]);
|
||||
if(cdevData::tagC2I(cdevGenericServerTags[i], &tagVal)!=CDEV_SUCCESS)
|
||||
{
|
||||
cdevData::addTag(cdevGenericServerTags[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
87
extensions/cdevGenericServer/include/cdevHandleSet.h
Normal file
87
extensions/cdevGenericServer/include/cdevHandleSet.h
Normal file
@@ -0,0 +1,87 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// File Descriptor Mask Class (Based On ACE Handler_Set)
|
||||
|
||||
#ifndef _CDEV_HANDLE_SET_H_
|
||||
#define _CDEV_HANDLE_SET_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "cdevPlatforms.h"
|
||||
|
||||
class CDEV_REACTOR_API cdevHandleSet
|
||||
{
|
||||
friend class cdevHandleSetIterator;
|
||||
friend class cdevReactor;
|
||||
|
||||
public:
|
||||
cdevHandleSet (void);
|
||||
cdevHandleSet (const fd_set &mask);
|
||||
|
||||
void reset (void);
|
||||
int is_set (int) const;
|
||||
void set_bit (int);
|
||||
void clr_bit (int);
|
||||
int num_set (void) const;
|
||||
int max_set (void) const;
|
||||
int asciiDump (FILE * fp = stdout);
|
||||
void sync (int max = FD_SETSIZE);
|
||||
|
||||
operator fd_set *( void ) { return &mask_; }
|
||||
|
||||
private:
|
||||
int size_;
|
||||
int max_handle_;
|
||||
fd_set mask_;
|
||||
|
||||
enum {
|
||||
#ifdef _WIN32
|
||||
MAX_SIZE = FD_SETSIZE,
|
||||
#else
|
||||
MAX_SIZE = NOFILE,
|
||||
WORD_SIZE = NFDBITS,
|
||||
NUM_WORDS = howmany (NOFILE, NFDBITS),
|
||||
#ifdef __DECCXX
|
||||
MSB_MASK = ~(1U << (NFDBITS - 1))
|
||||
#elif defined(CDEV_HAS_64BIT_LONGS)
|
||||
MSB_MASK = ~(1UL << (NFDBITS - 1))
|
||||
#else
|
||||
MSB_MASK = ~(1 << (NFDBITS - 1))
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
int count_bits (unsigned long n) const;
|
||||
void set_max (int max);
|
||||
|
||||
static const char nbits_[256];
|
||||
};
|
||||
|
||||
class CDEV_REACTOR_API cdevHandleSetIterator
|
||||
{
|
||||
public:
|
||||
cdevHandleSetIterator (cdevHandleSet &);
|
||||
int operator ()(void);
|
||||
void operator++ (void);
|
||||
|
||||
private:
|
||||
cdevHandleSet &fds_;
|
||||
int num_;
|
||||
|
||||
#ifdef _WIN32
|
||||
unsigned int index_;
|
||||
#else
|
||||
int index_;
|
||||
fd_mask val_;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif /* _CDEV_HANDLE_SET_H_ */
|
||||
129
extensions/cdevGenericServer/include/cdevMessage.h
Normal file
129
extensions/cdevGenericServer/include/cdevMessage.h
Normal file
@@ -0,0 +1,129 @@
|
||||
#ifndef _CDEV_MESSAGE_H_
|
||||
#define _CDEV_MESSAGE_H_ 1
|
||||
|
||||
#include <cdevData.h>
|
||||
#include <cdevPacket.h>
|
||||
#include <cdevMessageBinary.h>
|
||||
|
||||
class GENERIC_SERVER_API cdevMessage : public cdevPacket
|
||||
{
|
||||
private:
|
||||
typedef union
|
||||
{
|
||||
unsigned char rawData;
|
||||
struct {
|
||||
unsigned char saveDeviceList : 1;
|
||||
unsigned char saveMessage : 1;
|
||||
unsigned char saveData : 1;
|
||||
unsigned char saveContext : 1;
|
||||
unsigned char saveTagMap : 1;
|
||||
unsigned pad : 3;
|
||||
} value;
|
||||
} SaveTable;
|
||||
|
||||
SaveTable saveTbl;
|
||||
|
||||
short clientID;
|
||||
unsigned transIndex;
|
||||
unsigned cancelTransIndex;
|
||||
unsigned localDataIndex;
|
||||
unsigned foreignDataIndex;
|
||||
unsigned operationCode;
|
||||
int completionCode;
|
||||
unsigned deviceCount;
|
||||
char ** deviceList;
|
||||
char * message;
|
||||
cdevData * data;
|
||||
cdevData * context;
|
||||
cdevData * tagMap;
|
||||
|
||||
public:
|
||||
enum { CDEV_PACKET_VERSION = cdevMessageBinary::CDEV_PACKET_VERSION };
|
||||
|
||||
static cdevPacket *import( cdevPacketBinary & );
|
||||
|
||||
cdevMessage ( short ClientID = -1,
|
||||
unsigned TransIndex = 0,
|
||||
unsigned CancelTransIndex = 0,
|
||||
unsigned LocalDataIndex = 0,
|
||||
unsigned ForeignDataIndex = 0,
|
||||
unsigned OperationCode = 0,
|
||||
int CompletionCode = 0,
|
||||
unsigned DeviceCount = 0,
|
||||
char ** DeviceList = NULL,
|
||||
char * Message = NULL,
|
||||
cdevData * Data = NULL,
|
||||
cdevData * Context = NULL,
|
||||
cdevData * TagMap = NULL);
|
||||
|
||||
cdevMessage ( char * binary, size_t binaryLen );
|
||||
cdevMessage ( class cdevMessage & message );
|
||||
virtual ~cdevMessage ( void );
|
||||
virtual void clear ( void );
|
||||
virtual int streamIn ( char * binary, size_t binaryLen );
|
||||
virtual int streamOut ( char ** binary, size_t * binaryLen );
|
||||
virtual void asciiDump ( FILE * fp = stdout );
|
||||
|
||||
virtual short getVersion ( void ) { return CDEV_PACKET_VERSION; }
|
||||
virtual short getClientID ( void ) { return clientID; }
|
||||
virtual unsigned getTransIndex ( void ) { return transIndex; }
|
||||
|
||||
unsigned getCancelTransIndex ( void ) { return cancelTransIndex; }
|
||||
unsigned getLocalDataIndex ( void ) { return localDataIndex; }
|
||||
unsigned getForeignDataIndex ( void ) { return foreignDataIndex; }
|
||||
unsigned getOperationCode ( void ) { return operationCode; }
|
||||
int getCompletionCode ( void ) { return completionCode; }
|
||||
unsigned getDeviceCount ( void ) { return deviceCount; }
|
||||
char ** getDeviceList ( void ) { return deviceList; }
|
||||
char * getMessage ( void ) { return message; }
|
||||
cdevData * getData ( void ) { return data; }
|
||||
cdevData * getContext ( void ) { return context; }
|
||||
cdevData * getTagMap ( void ) { return tagMap; }
|
||||
|
||||
virtual void setClientID ( short ClientID ) { clientID = ClientID; }
|
||||
virtual void setTransIndex( unsigned TransIndex ) { transIndex = TransIndex; }
|
||||
|
||||
void setCancelTransIndex ( unsigned CancelTransIndex ) { cancelTransIndex = CancelTransIndex; }
|
||||
void setLocalDataIndex ( unsigned LocalDataIndex ) { localDataIndex = LocalDataIndex; }
|
||||
void setForeignDataIndex ( unsigned ForeignDataIndex ) { foreignDataIndex = ForeignDataIndex; }
|
||||
void setOperationCode ( unsigned OperationCode ) { operationCode = OperationCode; }
|
||||
void setCompletionCode ( int CompletionCode ) { completionCode = CompletionCode; }
|
||||
void setDeviceList ( char ** DeviceList, int DeviceCount, int permanent = 0 )
|
||||
{
|
||||
if(deviceList!=NULL && !saveTbl.value.saveDeviceList)
|
||||
{
|
||||
for(int i=0; i<deviceCount; i++) delete deviceList[i];
|
||||
delete deviceList;
|
||||
}
|
||||
deviceList = DeviceList;
|
||||
deviceCount = DeviceCount;
|
||||
saveTbl.value.saveDeviceList = permanent;
|
||||
}
|
||||
void setMessage ( char * Message, int permanent = 0 )
|
||||
{
|
||||
if(message!=NULL && !saveTbl.value.saveMessage) delete message;
|
||||
message = Message;
|
||||
saveTbl.value.saveMessage = permanent;
|
||||
}
|
||||
void setData ( cdevData * Data, int permanent = 0 )
|
||||
{
|
||||
if(data!=NULL && !saveTbl.value.saveData) delete data;
|
||||
data = Data;
|
||||
saveTbl.value.saveData = permanent;
|
||||
}
|
||||
void setContext ( cdevData * Context, int permanent = 0 )
|
||||
{
|
||||
if(context!=NULL && !saveTbl.value.saveContext) delete context;
|
||||
context = Context;
|
||||
saveTbl.value.saveContext = permanent;
|
||||
}
|
||||
void setTagMap ( cdevData * TagMap, int permanent = 0 )
|
||||
{
|
||||
if(tagMap!=NULL && !saveTbl.value.saveTagMap) delete tagMap;
|
||||
tagMap = TagMap;
|
||||
saveTbl.value.saveTagMap = permanent;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* _CDEV_MESSAGE_H_ */
|
||||
|
||||
277
extensions/cdevGenericServer/include/cdevMessageBinary.h
Normal file
277
extensions/cdevGenericServer/include/cdevMessageBinary.h
Normal file
@@ -0,0 +1,277 @@
|
||||
#ifndef _CDEV_PACKET_BINARY_H_
|
||||
#define _CDEV_PACKET_BINARY_H_
|
||||
|
||||
#include <cdevPacketBinary.h>
|
||||
|
||||
// *****************************************************************************
|
||||
// * OperationCode Definitions :
|
||||
// * CDEV_NORMAL_OP = 0 : This is a message that is to be processed by the
|
||||
// * developer's server interface.
|
||||
// * CDEV_SERVER_OP = 1 : This is a message that is to be processed by the
|
||||
// * Generic Server Interface.
|
||||
// *****************************************************************************
|
||||
enum {
|
||||
CDEV_NORMAL_OP = 0,
|
||||
CDEV_SERVER_OP = 1
|
||||
};
|
||||
|
||||
// *****************************************************************************
|
||||
// * struct cdevMessageBinaryMap :
|
||||
// * This is the first 32 bit integer that is passed through the socket. It
|
||||
// * contains a bitmap that identifies the version of the packet, as well as
|
||||
// * a bit field that indicates the contents of the packet. This bitfield
|
||||
// * simplifies the process of decoding the packet and results in a smaller
|
||||
// * transmission size.
|
||||
// *****************************************************************************
|
||||
typedef union
|
||||
{
|
||||
unsigned rawData;
|
||||
struct {
|
||||
unsigned version : 16;
|
||||
unsigned clientIDSet : 1;
|
||||
unsigned transIndexSet : 1;
|
||||
unsigned cancelTransIndexSet : 1;
|
||||
unsigned localDataIndexSet : 1;
|
||||
unsigned foreignDataIndexSet : 1;
|
||||
unsigned operationCodeSet : 1;
|
||||
unsigned completionCodeSet : 1;
|
||||
unsigned deviceListSet : 1;
|
||||
unsigned messageSet : 1;
|
||||
unsigned dataSet : 1;
|
||||
unsigned contextSet : 1;
|
||||
unsigned tagMapSet : 1;
|
||||
unsigned pad : 4;
|
||||
} value;
|
||||
} cdevMessageBinaryMap;
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * The following elements are contained within a cdevMessageBinary binary
|
||||
// * object.
|
||||
// *
|
||||
// * short version : This is the version of the cdevPacketBinary
|
||||
// * that is being constructed. The format and
|
||||
// * structure of the remainder of the data is
|
||||
// * based on version 1.
|
||||
// *
|
||||
// * short clientID : **** REQUIRED ****
|
||||
// * This is the clientID that the server will use
|
||||
// * to uniquely identify this client.
|
||||
// *
|
||||
// * unsigned transIndex : **** REQUIRED ****
|
||||
// * This is the index that will be used on the
|
||||
// * client side to locate the transaction object
|
||||
// * associated with this request.
|
||||
// *
|
||||
// *
|
||||
// * unsigned cancelTransIndex : This is the transaction index of a transaction
|
||||
// * that should be canceled. This field is
|
||||
// * typically used to terminate a monitor.
|
||||
// *
|
||||
// * unsigned localDataIndex : This is the index that will be used on the
|
||||
// * ~packet senders~ side to identify a list
|
||||
// * of devices.
|
||||
// *
|
||||
// * unsigned foreignDataIndex : This is the index that will be used on the
|
||||
// * ~packet receivers~ side to identify a list
|
||||
// * of devices.
|
||||
// *
|
||||
// *
|
||||
// * unsigned operationCode : This is a user defined operation code that
|
||||
// * may be used to reduce the size of the data
|
||||
// * that is transmitted between the client and
|
||||
// * the server by using integer operation codes
|
||||
// * rather than character strings.
|
||||
// *
|
||||
// * int completionCode : This is the result of the operation on the
|
||||
// * server side.
|
||||
// *
|
||||
// * unsigned deviceCount : This is the number of device names that will
|
||||
// * be contained in the following list.
|
||||
// *
|
||||
// * char ** deviceList : This is a list of character strings that
|
||||
// * identify cdevDevices.
|
||||
// *
|
||||
// * char * message : This is the message text.
|
||||
// *
|
||||
// * cdevData data : This is a cdevData object containing the
|
||||
// * data associated with the request or
|
||||
// * the result of the request if this packet
|
||||
// * is a response from a server.
|
||||
// *
|
||||
// * cdevData context : This is a cdevData object specifying the
|
||||
// * context of the request.
|
||||
// *
|
||||
// * cdevData tagMap : This is a cdevData object that contains the
|
||||
// * mapping of the cdevData tag table for the
|
||||
// * client. By virtue of the fact that this table
|
||||
// * cannot rely on any of the known tags to exist
|
||||
// * of be the same... the following integer values
|
||||
// * will be used.
|
||||
// *
|
||||
// * 1) An array of integers that identify the
|
||||
// * tag numbers.
|
||||
// *
|
||||
// * 2) An array of strings that identify the
|
||||
// * tag names.
|
||||
// *
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API cdevMessageBinary : public cdevPacketBinary
|
||||
{
|
||||
private:
|
||||
cdevMessageBinaryMap map;
|
||||
XDR_Reader reader;
|
||||
|
||||
|
||||
protected:
|
||||
typedef enum
|
||||
{
|
||||
GOTO_CLIENTID=1,
|
||||
GOTO_TRANSINDEX,
|
||||
GOTO_CANCELTRANSINDEX,
|
||||
GOTO_LOCALDATAINDEX,
|
||||
GOTO_FOREIGNDATAINDEX,
|
||||
GOTO_OPERATIONCODE,
|
||||
GOTO_COMPLETIONCODE,
|
||||
GOTO_DEVICELIST,
|
||||
GOTO_MESSAGE,
|
||||
GOTO_DATA,
|
||||
GOTO_CONTEXT,
|
||||
GOTO_TAGMAP} POSITION_FLAG;
|
||||
|
||||
// *********************************************************************
|
||||
// * cdevMessageBinary::setBinaryPosition :
|
||||
// * This method will set the position of the binary stream within an
|
||||
// * XDR_Reader to the specified data object.
|
||||
// * This method returns 0 on success, or -1 if the data object could
|
||||
// * not be selected.
|
||||
// *********************************************************************
|
||||
int setBinaryPosition (XDR_Reader & reader, POSITION_FLAG flag );
|
||||
|
||||
public:
|
||||
enum { CDEV_PACKET_VERSION = 2 };
|
||||
|
||||
cdevMessageBinary ( cdevMessageBinary &packet );
|
||||
cdevMessageBinary ( short clientID = -1,
|
||||
unsigned transIndex = 0,
|
||||
unsigned cancelTransIndex = 0,
|
||||
unsigned localDataIndex = 0,
|
||||
unsigned foreignDataIndex = 0,
|
||||
unsigned operationCode = 0,
|
||||
int completionCode = 0,
|
||||
unsigned deviceCount = 0,
|
||||
char ** deviceList = NULL,
|
||||
char * message = NULL,
|
||||
cdevData * data = NULL,
|
||||
cdevData * context = NULL,
|
||||
cdevData * tagMap = NULL );
|
||||
|
||||
virtual ~cdevMessageBinary ( void );
|
||||
|
||||
// *********************************************************************
|
||||
// * map2int ( void )
|
||||
// * This method will convert the cdevMessageBinaryMap to an unsigned
|
||||
// *********************************************************************
|
||||
unsigned map2int ( cdevMessageBinaryMap map, unsigned & value);
|
||||
|
||||
// *********************************************************************
|
||||
// * int2map ( void )
|
||||
// * This method will convert an unsigned to a cdevMessageBinaryMap.
|
||||
// *********************************************************************
|
||||
cdevMessageBinaryMap int2map ( cdevMessageBinaryMap &map, unsigned value);
|
||||
|
||||
// *********************************************************************
|
||||
// * The streamIn function will populate the cdevMessageBinary using the
|
||||
// * data that is specified in the stream. The stream remains the
|
||||
// * property of the caller, who must delete it when it is no longer
|
||||
// * needed.
|
||||
// *********************************************************************
|
||||
virtual int streamIn ( char * stream, size_t len );
|
||||
|
||||
// *********************************************************************
|
||||
// * attachData :
|
||||
// * This method allows the caller to assign a preallocated binary
|
||||
// * buffer to this object. This prevents the cdevMessageBinary class
|
||||
// * from having to allocate the data.
|
||||
// *********************************************************************
|
||||
int attachData ( char * stream, size_t len );
|
||||
|
||||
// *********************************************************************
|
||||
// * Performs a diagnostic dump of the object.
|
||||
// *********************************************************************
|
||||
virtual void asciiDump ( FILE * fp = stdout );
|
||||
|
||||
// *********************************************************************
|
||||
// * The set mechanism:
|
||||
// * Allows the caller to dynamically change the contents of the
|
||||
// * binary structure.
|
||||
// *********************************************************************
|
||||
void set ( short clientID = -1,
|
||||
unsigned transIndex = 0,
|
||||
unsigned cancelTransIndex = 0,
|
||||
unsigned localDataIndex = 0,
|
||||
unsigned foreignDataIndex = 0,
|
||||
unsigned operationCode = 0,
|
||||
int completionCode = 0,
|
||||
unsigned deviceCount = 0,
|
||||
char ** deviceList = NULL,
|
||||
char * message = NULL,
|
||||
cdevData * data = NULL,
|
||||
cdevData * context = NULL,
|
||||
cdevData * tagMap = NULL );
|
||||
|
||||
// *********************************************************************
|
||||
// * The get mechanisms:
|
||||
// * The pointers that are retrieved by these functions are the
|
||||
// * actual pointers that are used within the class. They should not
|
||||
// * be altered by the caller. The caller may alter the contents of
|
||||
// * these objects by using the set mechanisms.
|
||||
// *********************************************************************
|
||||
virtual int getVersion ( short & version );
|
||||
virtual int getClientID ( short & clientID );
|
||||
int getTransIndex ( unsigned & transIndex );
|
||||
int getCancelTransIndex ( unsigned & cancelTransIndex );
|
||||
int getLocalDataIndex ( unsigned & localDataIndex );
|
||||
int getForeignDataIndex ( unsigned & foreignDataIndex );
|
||||
int getOperationCode ( unsigned & operationCode );
|
||||
int getCompletionCode ( int & completionCode );
|
||||
int getDeviceList ( char ** & deviceList, unsigned & deviceCount );
|
||||
int getMessage ( char * & message );
|
||||
int getData ( cdevData & data );
|
||||
int getContext ( cdevData & context );
|
||||
int getTagMap ( cdevData & tagMap );
|
||||
int get ( short & clientID,
|
||||
unsigned & transIndex,
|
||||
unsigned & cancelTransIndex,
|
||||
unsigned & localDataIndex,
|
||||
unsigned & foreignDataIndex,
|
||||
unsigned & operationCode,
|
||||
int & completionCode,
|
||||
unsigned & deviceCount,
|
||||
char ** & deviceList,
|
||||
char * & message,
|
||||
cdevData & data,
|
||||
cdevData & context,
|
||||
cdevData & tagMap);
|
||||
|
||||
// *********************************************************************
|
||||
// * The has mechanisms:
|
||||
// * This collection of functions allows the caller to determine if
|
||||
// * certain components of the packet are present.
|
||||
// *********************************************************************
|
||||
int hasClientID ( void ) { return map.value.clientIDSet; }
|
||||
int hasTransIndex ( void ) { return map.value.transIndexSet; }
|
||||
int hasCancelTransIndex ( void ) { return map.value.cancelTransIndexSet; }
|
||||
int hasLocalDataIndex ( void ) { return map.value.localDataIndexSet; }
|
||||
int hasForeignDataIndex ( void ) { return map.value.foreignDataIndexSet; }
|
||||
int hasOperationCode ( void ) { return map.value.operationCodeSet; }
|
||||
int hasCompletionCode ( void ) { return map.value.completionCodeSet; }
|
||||
int hasDeviceList ( void ) { return map.value.deviceListSet; }
|
||||
int hasMessage ( void ) { return map.value.messageSet; }
|
||||
int hasData ( void ) { return map.value.dataSet; }
|
||||
int hasContext ( void ) { return map.value.contextSet; }
|
||||
int hasTagMap ( void ) { return map.value.tagMapSet; }
|
||||
};
|
||||
|
||||
|
||||
#endif /* CDEV_PACKET_BINARY_H_ */
|
||||
136
extensions/cdevGenericServer/include/cdevMonitorTable.h
Normal file
136
extensions/cdevGenericServer/include/cdevMonitorTable.h
Normal file
@@ -0,0 +1,136 @@
|
||||
#ifndef _CDEV_MONITOR_TABLE_H_
|
||||
#define _CDEV_MONITOR_TABLE_H_ 1
|
||||
|
||||
#include <cdevMessage.h>
|
||||
#include <StringHash.h>
|
||||
#include <cdevData.h>
|
||||
#include <xdrClass.h>
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * class cdevMonitorData :
|
||||
// * This class gives a cdevData object the capacity to selectively place
|
||||
// * its tagged data items into an XDR stream.
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API cdevMonitorData : public cdevData
|
||||
{
|
||||
protected:
|
||||
int * criticalTags;
|
||||
int criticalTagCnt;
|
||||
|
||||
virtual int isTagCritical ( int tag );
|
||||
|
||||
public:
|
||||
cdevMonitorData (void );
|
||||
cdevMonitorData (const cdevData & data);
|
||||
cdevMonitorData (const cdevMonitorData & data);
|
||||
|
||||
virtual void setCriticalTags ( int * tags, int tagCnt );
|
||||
virtual int changeTag ( int oldTag, int newTag );
|
||||
virtual int xdrExport ( char ** buf, size_t * bufLen );
|
||||
virtual int xdrExport ( char * buf, size_t bufLen, size_t count);
|
||||
virtual int xdrSize ( size_t * bufLen, size_t * elementCount );
|
||||
};
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * class cdevMonitorNode :
|
||||
// * This class is used to store the list of monitors associated with a
|
||||
// * device / attribute pair. It maintains a back-pointer to the
|
||||
// * cdevMonitorTable object to allow it to call the fireCallback method of
|
||||
// * the parent in order to submit the reply.
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API cdevMonitorNode
|
||||
{
|
||||
friend class cdevMonitorTable;
|
||||
|
||||
protected:
|
||||
// **********************************************************************
|
||||
// * class cdevMonitorEntry :
|
||||
// * This is an individual monitor transaction that has been installed
|
||||
// * in a cdevMonitorNode.
|
||||
// **********************************************************************
|
||||
class cdevMonitorEntry
|
||||
{
|
||||
friend class cdevMonitorNode;
|
||||
private:
|
||||
static int VALUE_TAG;
|
||||
static int STATUS_TAG;
|
||||
static int TIME_TAG;
|
||||
static int DEVICE_TAG; // *** Added for multi-device
|
||||
|
||||
cdevMonitorEntry * next;
|
||||
cdevMessage * message;
|
||||
int * triggers;
|
||||
int * trigType;
|
||||
int trigCnt;
|
||||
int * properties;
|
||||
int propCnt;
|
||||
|
||||
int deviceIdx; // *** Added for multi-device
|
||||
|
||||
cdevMonitorEntry ( cdevMessage * Message, int deviceIdx );
|
||||
~cdevMonitorEntry ( void );
|
||||
};
|
||||
|
||||
class cdevMonitorTable * parent;
|
||||
cdevMonitorEntry * nodes;
|
||||
cdevMonitorData mData;
|
||||
char * hashString;
|
||||
|
||||
virtual int fireMonitor ( cdevMonitorEntry *entry,
|
||||
int property,
|
||||
cdevMonitorData * data,
|
||||
int endOfTransaction = 0);
|
||||
|
||||
virtual int insertMonitor ( cdevMessage * request,
|
||||
cdevData * data,
|
||||
int deviceIdx );
|
||||
|
||||
virtual int removeMonitor ( cdevMessage * request );
|
||||
virtual int removeMonitor ( unsigned transIndex );
|
||||
virtual int removeClientMonitors ( short clientID, int fire = 1 );
|
||||
char * getHashString ( void ) { return hashString; }
|
||||
|
||||
public:
|
||||
cdevMonitorNode ( cdevMonitorTable * Parent,
|
||||
char * Device,
|
||||
char * Attrib );
|
||||
virtual ~cdevMonitorNode ( void );
|
||||
|
||||
virtual int fireMonitor ( char * property, cdevData * data );
|
||||
virtual int fireMonitor ( int property, cdevData * data );
|
||||
int isMonitored ( void ) { return nodes==NULL?0:1; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * class cdevMonitorTable :
|
||||
// * This class is used to store the list of all monitors for all device /
|
||||
// * attribute pairs in the system. The developer must provide the
|
||||
// * fireCallback method which will be used to submit the callback to the
|
||||
// * client.
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API cdevMonitorTable
|
||||
{
|
||||
protected:
|
||||
StringHash monitors;
|
||||
|
||||
public:
|
||||
cdevMonitorTable ( void );
|
||||
virtual ~cdevMonitorTable ( void );
|
||||
|
||||
virtual int insertMonitor ( cdevMessage * request, cdevData * data );
|
||||
virtual int insertMonitor ( cdevMessage * request, cdevData ** data, size_t dataCnt );
|
||||
virtual int removeMonitor ( cdevMessage * request );
|
||||
virtual int removeClientMonitors( short clientID, int fire = 1 );
|
||||
virtual cdevMonitorNode * findMonitor ( char * device, char * attrib );
|
||||
virtual int fireMonitor ( char * device, char * attrib,
|
||||
char * property, cdevData * data );
|
||||
virtual int fireMonitor ( char * device, char * attrib,
|
||||
int property, cdevData * data );
|
||||
virtual int fireCallback ( cdevMessage * message );
|
||||
};
|
||||
|
||||
#endif
|
||||
35
extensions/cdevGenericServer/include/cdevPacket.h
Normal file
35
extensions/cdevGenericServer/include/cdevPacket.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef _CDEV_PACKET_
|
||||
#define _CDEV_PACKET_
|
||||
|
||||
#include <cdevPacketBinary.h>
|
||||
|
||||
class GENERIC_SERVER_API cdevPacket
|
||||
{
|
||||
public:
|
||||
typedef cdevPacket * (*ImportMethod)(cdevPacketBinary &);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
short packetVersion;
|
||||
ImportMethod importMethod;
|
||||
} ImportTable;
|
||||
|
||||
static cdevPacket * import ( cdevPacketBinary & );
|
||||
static void registerImportMethod ( short, ImportMethod );
|
||||
|
||||
cdevPacket ( void ) {}
|
||||
virtual ~cdevPacket ( void ) {}
|
||||
|
||||
virtual int streamIn ( char * binary, size_t binaryLen ) = 0;
|
||||
virtual int streamOut ( char ** binary, size_t * binaryLen ) = 0;
|
||||
virtual void asciiDump ( FILE * fp = stdout ) = 0;
|
||||
|
||||
virtual short getVersion ( void ) = 0;
|
||||
virtual short getClientID ( void ) = 0;
|
||||
virtual void setClientID ( short ClientID ) = 0;
|
||||
|
||||
private:
|
||||
static ImportTable * importTables;
|
||||
static int maxTables;
|
||||
};
|
||||
#endif
|
||||
322
extensions/cdevGenericServer/include/cdevPacketBinary.h
Normal file
322
extensions/cdevGenericServer/include/cdevPacketBinary.h
Normal file
@@ -0,0 +1,322 @@
|
||||
#ifndef _CDEV_PACKET_H_
|
||||
#define _CDEV_PACKET_H_
|
||||
|
||||
#include <cdevPlatforms.h>
|
||||
#include <cdevData.h>
|
||||
#include <xdrClass.h>
|
||||
|
||||
// *****************************************************************************
|
||||
// * struct cdevPacketBinaryMap :
|
||||
// * This is the first 32 bit integer that is passed through the socket. It
|
||||
// * contains a bitmap that identifies the version of the packet, as well as
|
||||
// * a bit field that indicates the contents of the packet. This bitfield
|
||||
// * simplifies the process of decoding the packet and results in a smaller
|
||||
// * transmission size.
|
||||
// *****************************************************************************
|
||||
typedef union
|
||||
{
|
||||
unsigned rawData;
|
||||
struct {
|
||||
unsigned version : 16;
|
||||
unsigned pad : 16;
|
||||
} value;
|
||||
} cdevPacketBinaryMap;
|
||||
|
||||
// *****************************************************************************
|
||||
// * class cdevPacketBinary :
|
||||
// * This is the base class for all cdevPacketBinary classes. It is a pure
|
||||
// * virtual class that defines the mechanisms necessary for identifying
|
||||
// * the version of a class as well as reading or generating a binary
|
||||
// * stream.
|
||||
// *
|
||||
// * Enforced structural contraints...
|
||||
// *
|
||||
// * 1) Every packet that inherits from the cdevPacketBinary must have an
|
||||
// * XDR encoded 4 byte integer at the beginning...
|
||||
// *
|
||||
// * a) The first two bytes of that 4 byte integer is the packet version.
|
||||
// *
|
||||
// * b) The second two bytes of that 4 byte integer is user defined data.
|
||||
// *
|
||||
// * 2) The next four bytes of the packet contains a XDR encoded short
|
||||
// * integer that contains a 16 bit client identifier.
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API cdevPacketBinary
|
||||
{
|
||||
protected:
|
||||
// *********************************************************************
|
||||
// * These are the data storage variables.
|
||||
// *********************************************************************
|
||||
char * binary;
|
||||
size_t binaryLen;
|
||||
|
||||
public:
|
||||
cdevPacketBinary ( void );
|
||||
cdevPacketBinary ( cdevPacketBinary & packet );
|
||||
virtual ~cdevPacketBinary ( void );
|
||||
|
||||
unsigned map2int ( cdevPacketBinaryMap map, unsigned & value);
|
||||
cdevPacketBinaryMap int2map ( cdevPacketBinaryMap &map, unsigned value);
|
||||
|
||||
virtual int getVersion ( short & version );
|
||||
virtual int getPad ( short & pad );
|
||||
virtual int getClientID ( short & clientID );
|
||||
virtual int setClientID ( short clientID );
|
||||
virtual int streamOut ( char ** stream, size_t * len );
|
||||
virtual int streamIn ( char * stream, size_t len );
|
||||
virtual void detachData ( void );
|
||||
virtual int attachData ( char * stream, size_t len );
|
||||
};
|
||||
|
||||
// *****************************************************************************
|
||||
// * cdevPacketBinary::map2int ( void )
|
||||
// * This method will convert the cdevPacketBinaryMap to a long integer.
|
||||
// *****************************************************************************
|
||||
inline unsigned cdevPacketBinary::map2int ( cdevPacketBinaryMap map, unsigned & value)
|
||||
{
|
||||
value = (map.value.version << 16);
|
||||
value |= (map.value.pad & 0xFFFF);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * cdevPacketBinary::int2map ( void )
|
||||
// * This method will convert a long integer to a cdevPacketBinaryMap.
|
||||
// *****************************************************************************
|
||||
inline cdevPacketBinaryMap cdevPacketBinary::int2map ( cdevPacketBinaryMap &map, unsigned value)
|
||||
{
|
||||
map.rawData = 0;
|
||||
map.value.version = (value >> 16);
|
||||
map.value.pad = (value & 0xFFFF);
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * cdevPacketBinary::getVersion :
|
||||
// * This method is used to obtain the version number of the packet.
|
||||
// *
|
||||
// * Returns 0 on Success or -1 on Error
|
||||
// *****************************************************************************
|
||||
inline int cdevPacketBinary::getVersion ( short & version )
|
||||
{
|
||||
int result=-1;
|
||||
XDR_Reader reader;
|
||||
cdevPacketBinaryMap map;
|
||||
|
||||
version = -1;
|
||||
|
||||
if(binary!=NULL && binaryLen>0)
|
||||
{
|
||||
unsigned packetMap = 0;
|
||||
reader.attachData(binary, binaryLen);
|
||||
map.rawData = 0;
|
||||
if((result = !reader.get(packetMap))==0)
|
||||
{
|
||||
int2map(map, packetMap);
|
||||
version = map.value.version;
|
||||
}
|
||||
reader.detachData();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * cdevPacketBinary::getPad :
|
||||
// * This method is used to obtain the 16 bit integer that follows the
|
||||
// * packet version.
|
||||
// *****************************************************************************
|
||||
inline int cdevPacketBinary::getPad ( short & pad )
|
||||
{
|
||||
int result=-1;
|
||||
XDR_Reader reader;
|
||||
cdevPacketBinaryMap map;
|
||||
|
||||
pad = -1;
|
||||
|
||||
if(binary!=NULL && binaryLen>0)
|
||||
{
|
||||
unsigned packetMap = 0;
|
||||
reader.attachData(binary, binaryLen);
|
||||
map.rawData = 0;
|
||||
if((result = !reader.get(packetMap))==0)
|
||||
{
|
||||
int2map(map, packetMap);
|
||||
pad = map.value.pad;
|
||||
}
|
||||
reader.detachData();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * cdevPacketBinary::getClientID :
|
||||
// * This method is used to obtain the 16 bit integer that contains the
|
||||
// * client identifier.
|
||||
// *****************************************************************************
|
||||
inline int cdevPacketBinary::getClientID ( short & clientID )
|
||||
{
|
||||
int result = -1;
|
||||
XDR_Reader reader;
|
||||
|
||||
clientID = -1;
|
||||
|
||||
if(binary!=NULL && binaryLen>0)
|
||||
{
|
||||
reader.attachData(binary, binaryLen);
|
||||
if((result = !xdr_setpos(reader.xdr(), XDR_Sizeof((unsigned)1)))==0)
|
||||
{
|
||||
result = !reader.get(clientID);
|
||||
}
|
||||
reader.detachData();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * cdevPacketBinary::getClientID :
|
||||
// * This method is used to insert the 16 bit integer that contains the
|
||||
// * client identifier.
|
||||
// *****************************************************************************
|
||||
inline int cdevPacketBinary::setClientID ( short clientID )
|
||||
{
|
||||
int result = -1;
|
||||
XDR_Writer writer;
|
||||
|
||||
if(binary!=NULL && binaryLen>0)
|
||||
{
|
||||
writer.attachData(binary, binaryLen);
|
||||
if((result = !xdr_setpos(writer.xdr(), XDR_Sizeof((unsigned)1)))==0)
|
||||
{
|
||||
result = !writer.put(clientID);
|
||||
}
|
||||
writer.detachData();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * cdevPacketBinary::streamIn :
|
||||
// * The streamIn function will read a memory buffer provided by the caller
|
||||
// * and then populate the class with these values. This stream remains the
|
||||
// * property of the caller and he is responsible for deleting it.
|
||||
// *
|
||||
// * Returns 0 on Success
|
||||
// *****************************************************************************
|
||||
inline int cdevPacketBinary::streamIn ( char * stream, size_t len )
|
||||
{
|
||||
if(binary!=NULL)
|
||||
{
|
||||
delete binary;
|
||||
binary = NULL;
|
||||
}
|
||||
binaryLen = 0;
|
||||
|
||||
if(len>0 && stream!=NULL)
|
||||
{
|
||||
binary = new char[len];
|
||||
binaryLen = len;
|
||||
memcpy(binary, stream, binaryLen);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * cdevPacketBinary::streamOut :
|
||||
// * The streamOut and streamIn functions are the bread and butter of the
|
||||
// * cdevPacketBinary classes. They allow the class to convert itself into a
|
||||
// * binary stream for transmission and then be reconstructed into a class
|
||||
// * when they are received on the other side.
|
||||
// *
|
||||
// * The streamOut function will allocate a memory buffer to the stream
|
||||
// * variable that is sufficient to store the binary representation of
|
||||
// * the data that is to be transmitted. This stream remains the
|
||||
// * property of the cdevPacketBinary class and should not be deleted by the
|
||||
// * caller.
|
||||
// *
|
||||
// * Returns 0 on Success
|
||||
// *****************************************************************************
|
||||
inline int cdevPacketBinary::streamOut ( char ** stream, size_t * len )
|
||||
{
|
||||
*stream = binary;
|
||||
*len = binaryLen;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// *********************************************************************
|
||||
// * cdevPacketBinary::detachData :
|
||||
// * This method allows the caller to obtain a copy of the binary
|
||||
// * image that is stored in the cdevPacketBinary object (using
|
||||
// * streamOut), and then force the cdevPacket object to detach it
|
||||
// * (preventing it from being deleted when the object is destroyed.)
|
||||
// *
|
||||
// * Returns nothing.
|
||||
// *********************************************************************
|
||||
inline void cdevPacketBinary::detachData ( void )
|
||||
{
|
||||
binary = NULL;
|
||||
binaryLen = 0;
|
||||
}
|
||||
|
||||
// *********************************************************************
|
||||
// * cdevPacketBinary::attachData :
|
||||
// * This method allows the caller to assign a preallocated binary
|
||||
// * buffer to this object. This prevents the cdevPacketBinary class
|
||||
// * from having to allocate the data.
|
||||
// *
|
||||
// * Returns 0 on Success
|
||||
// *********************************************************************
|
||||
inline int cdevPacketBinary::attachData ( char * stream, size_t len )
|
||||
{
|
||||
if(binary!=NULL)
|
||||
{
|
||||
delete binary;
|
||||
binary = NULL;
|
||||
}
|
||||
binaryLen = 0;
|
||||
|
||||
if(stream!=NULL && len>0)
|
||||
{
|
||||
binary = stream;
|
||||
binaryLen = len;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * cdevPacketBinary::cdevPacketBinary :
|
||||
// * This is the default constructor for the class.
|
||||
// *****************************************************************************
|
||||
inline cdevPacketBinary::cdevPacketBinary ( void )
|
||||
: binary(NULL), binaryLen(0)
|
||||
{}
|
||||
|
||||
// *****************************************************************************
|
||||
// * cdevPacketBinary::cdevPacketBinary :
|
||||
// * This is the copy constructor for the class.
|
||||
// *****************************************************************************
|
||||
inline cdevPacketBinary::cdevPacketBinary ( cdevPacketBinary & packet )
|
||||
: binary(NULL), binaryLen(0)
|
||||
{
|
||||
streamIn(packet.binary, packet.binaryLen);
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * cdevPacketBinary::~cdevPacketBinary :
|
||||
// * This is the destructor for the object.
|
||||
// *****************************************************************************
|
||||
inline cdevPacketBinary::~cdevPacketBinary ( void )
|
||||
{
|
||||
if(binary!=NULL)
|
||||
{
|
||||
delete binary;
|
||||
binary = NULL;
|
||||
}
|
||||
binaryLen = 0;
|
||||
}
|
||||
|
||||
#endif /* _CDEV_PACKET_H_ */
|
||||
334
extensions/cdevGenericServer/include/cdevPlatforms.h
Normal file
334
extensions/cdevGenericServer/include/cdevPlatforms.h
Normal file
@@ -0,0 +1,334 @@
|
||||
#ifndef _CDEV_PLATFORMS_H_
|
||||
#define _CDEV_PLATFORMS_H_
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <math.h>
|
||||
#include <signal.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <time.h>
|
||||
|
||||
#ifndef CDEV_REACTOR_API
|
||||
// *********************************************************************
|
||||
// * _CDEV_REACTOR_EXPORTS :
|
||||
// * This definition allows cdevReactor DLL components to be imported
|
||||
// * and exported by other applications and libraries.
|
||||
// *********************************************************************
|
||||
#ifdef _CDEV_REACTOR_EXPORTS_
|
||||
#define CDEV_REACTOR_API __declspec(dllexport)
|
||||
#else
|
||||
#define CDEV_REACTOR_API __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef GENERIC_SERVER_API
|
||||
// *********************************************************************
|
||||
// * _GENERIC_SERVER_EXPORTS :
|
||||
// * This definition allows Generic Server DLL components to be imported
|
||||
// * and exported by other applications and libraries.
|
||||
// *********************************************************************
|
||||
#ifdef _GENERIC_SERVER_EXPORTS_
|
||||
#define GENERIC_SERVER_API __declspec(dllexport)
|
||||
#else
|
||||
#define GENERIC_SERVER_API __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <WinSock2.h>
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#include <WinBase.h>
|
||||
#include <lmcons.h>
|
||||
#include <process.h>
|
||||
#include <sys/types.h>
|
||||
#include <xdr.h>
|
||||
|
||||
typedef signed long ssize_t;
|
||||
|
||||
#define MAXHOSTNAMELEN 128
|
||||
#define EWOULDBLOCK WSAEWOULDBLOCK
|
||||
#define EINPROGRESS WSAEINPROGRESS
|
||||
#define EISCONN WSAEISCONN
|
||||
#define SELECT_PARM fd_set *
|
||||
|
||||
#ifndef O_NONBLOCK
|
||||
#define O_NONBLOCK 1
|
||||
#endif
|
||||
|
||||
// *********************************************************************
|
||||
// * SOCKOPT_SIZE_PARM :
|
||||
// * This is the datatype of the parameter that is sent to getsockopt,
|
||||
// * setsockopt, and getsockname.
|
||||
// *********************************************************************
|
||||
typedef int SOCKOPT_SIZE_PARM;
|
||||
|
||||
inline int GetSocketErrno ( void )
|
||||
{
|
||||
return WSAGetLastError();
|
||||
}
|
||||
|
||||
inline int GetSelectErrno ( void )
|
||||
{
|
||||
return WSAGetLastError();
|
||||
}
|
||||
|
||||
inline int InitializeNetwork ( void )
|
||||
{
|
||||
WORD version_requested = MAKEWORD (2, 0);
|
||||
WSADATA wsa_data;
|
||||
return WSAStartup(version_requested, &wsa_data);
|
||||
}
|
||||
|
||||
inline int TerminateNetwork ( void )
|
||||
{
|
||||
return WSACleanup();
|
||||
}
|
||||
|
||||
inline char * ultoa ( unsigned long val )
|
||||
{
|
||||
static char buf[64];
|
||||
return _ultoa(val, buf, 10);
|
||||
}
|
||||
|
||||
inline char * ltoa ( long val )
|
||||
{
|
||||
static char buf[64];
|
||||
return _ltoa(val, buf, 10);
|
||||
}
|
||||
|
||||
inline int usleep ( unsigned int useconds )
|
||||
{
|
||||
int retval = 0;
|
||||
if(useconds<100000) Sleep(useconds/1000);
|
||||
else retval = -1;
|
||||
return retval;
|
||||
}
|
||||
|
||||
inline unsigned int sleep ( unsigned int seconds )
|
||||
{
|
||||
Sleep(seconds*1000);
|
||||
return seconds;
|
||||
}
|
||||
|
||||
// *********************************************************************
|
||||
// * This version of pipe is provided because the file descriptors
|
||||
// * generated by the Windows NT version of pipe cannot be used with the
|
||||
// * select system call.
|
||||
// *********************************************************************
|
||||
inline int pipe ( int fd[2] )
|
||||
{
|
||||
int retval = 0;
|
||||
sockaddr_in addr[2];
|
||||
hostent * hostptr;
|
||||
char hostname[MAXHOSTNAMELEN];
|
||||
unsigned long ipAddr;
|
||||
unsigned long blockFlag = 1;
|
||||
|
||||
gethostname(hostname, MAXHOSTNAMELEN);
|
||||
hostptr = ::gethostbyname(hostname);
|
||||
ipAddr = *(unsigned long *)hostptr->h_addr;
|
||||
|
||||
for(int i=0; i<2; i++)
|
||||
{
|
||||
addr[i].sin_family = AF_INET;
|
||||
addr[i].sin_port = htons(0);
|
||||
*(unsigned long *)&addr[i].sin_addr = ipAddr;
|
||||
if((fd[i] = socket(PF_INET, SOCK_DGRAM,0))>0 &&
|
||||
bind(fd[i], (sockaddr *)&addr[i], sizeof(addr[i]))==0)
|
||||
{
|
||||
int addrLen = sizeof(addr[i]);
|
||||
getsockname(fd[i], (sockaddr *)&addr[i], &addrLen);
|
||||
ioctlsocket(fd[i], FIONBIO, &blockFlag);
|
||||
}
|
||||
else fd[i] = -1;
|
||||
}
|
||||
if(fd[0]>0 && fd[1]>0)
|
||||
{
|
||||
::connect(fd[0], (sockaddr *)&addr[1], sizeof(addr[1]));
|
||||
::connect(fd[1], (sockaddr *)&addr[0], sizeof(addr[0]));
|
||||
}
|
||||
else
|
||||
{
|
||||
if(fd[0]>0) close(fd[0]);
|
||||
if(fd[1]>0) close(fd[1]);
|
||||
fd[0] = (fd[1] = (retval = -1));
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
inline int FileTimeToTimeVal ( FILETIME * tfile, struct timeval * tv )
|
||||
{
|
||||
if(tfile && tv)
|
||||
{
|
||||
ULARGE_INTEGER _100ns = {tfile->dwLowDateTime,
|
||||
tfile->dwHighDateTime};
|
||||
|
||||
_100ns.QuadPart -= 0x19db1ded53e8000i64;
|
||||
|
||||
tv->tv_sec = long (_100ns.QuadPart / (10000 * 1000));
|
||||
tv->tv_usec = long ((_100ns.QuadPart % (10000 * 1000)) / 10);
|
||||
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline int gettimeofday (struct timeval *tv)
|
||||
{
|
||||
FILETIME tfile;
|
||||
|
||||
GetSystemTimeAsFileTime(&tfile);
|
||||
|
||||
return FileTimeToTimeVal(&tfile, tv);
|
||||
}
|
||||
|
||||
inline int cdevSelect (
|
||||
int size,
|
||||
fd_set * read_set,
|
||||
fd_set * write_set,
|
||||
fd_set * except_set,
|
||||
struct timeval * timeout )
|
||||
{
|
||||
int result = select(size, read_set, write_set, except_set, timeout);
|
||||
|
||||
if(result<0 && GetSelectErrno()==WSAEINVAL)
|
||||
{
|
||||
if(timeout)
|
||||
{
|
||||
unsigned long millisec = timeout->tv_sec*1000+timeout->tv_usec/1000;
|
||||
Sleep(millisec);
|
||||
}
|
||||
result = 0;
|
||||
}
|
||||
else if (result<0 && GetSelectErrno()==WSAEINPROGRESS)
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
|
||||
#define CDEV_REACTOR_API
|
||||
#define GENERIC_SERVER_API
|
||||
|
||||
#ifdef __VMS
|
||||
#ifdef _TGV_MULTINET
|
||||
// *****************************************************
|
||||
// * Under TGV multinet and VMS, if you want sys/types.h
|
||||
// * you need to have types.h already pulled in because
|
||||
// * sys/types.h makes it look like types.h is loaded.
|
||||
// * Then when types.h does get loaded, it is ignored
|
||||
// * because it looks like it is already loaded --
|
||||
// * Mr. Danial Van Olst
|
||||
// *****************************************************
|
||||
#include <types.h>
|
||||
|
||||
// *****************************************************
|
||||
// * Under TGV Multinet and VMS, the file sys/param.h
|
||||
// * does not define NOFILE (max number of open files
|
||||
// * per process). FD_SETSIZE seems to be the correct
|
||||
// * value for NOFILE.
|
||||
// * See Multinet's sys/types.h file for more info on
|
||||
// * FD_SETSIZE. - Daniel Van Olst
|
||||
// *****************************************************
|
||||
#ifndef NOFILE
|
||||
#define NOFILE FD_SETSIZE
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef SYSV
|
||||
#include <poll.h>
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <grp.h>
|
||||
#include <rpc/rpc.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
|
||||
#if defined (__hpux)
|
||||
#include <sys/pstat.h>
|
||||
#endif
|
||||
|
||||
#if defined (AIX)
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
|
||||
#if defined(solaris) || defined(SunOS)
|
||||
#include <sys/filio.h>
|
||||
extern "C" { int gethostname(char *name, int namelen); }
|
||||
#endif
|
||||
|
||||
#ifdef _SELECT_USES_INT_
|
||||
#define SELECT_PARM int *
|
||||
#else
|
||||
#define SELECT_PARM fd_set *
|
||||
#endif
|
||||
|
||||
#ifndef min
|
||||
#define min(a,b) ((a<b)?a:b)
|
||||
#endif
|
||||
|
||||
#ifndef max
|
||||
#define max(a,b) ((a>b)?a:b)
|
||||
#endif
|
||||
|
||||
// *********************************************************************
|
||||
// * SOCKOPT_SIZE_PARM :
|
||||
// * This is the datatype of the parameter that is sent to getsockopt,
|
||||
// * setsockopt, and getsockname.
|
||||
// *********************************************************************
|
||||
#if defined(AIX) || defined(__linux)
|
||||
typedef unsigned int SOCKOPT_SIZE_PARM;
|
||||
#else
|
||||
typedef int SOCKOPT_SIZE_PARM;
|
||||
#endif
|
||||
|
||||
inline int GetSocketErrno ( void )
|
||||
{
|
||||
return errno;
|
||||
}
|
||||
|
||||
inline int GetSelectErrno ( void )
|
||||
{
|
||||
return errno;
|
||||
}
|
||||
|
||||
inline int InitializeNetwork ( void )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline int TerminateNetwork ( void )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline int gettimeofday (struct timeval * tv)
|
||||
{
|
||||
struct timezone tz;
|
||||
|
||||
return ::gettimeofday(tv, &tz);
|
||||
}
|
||||
|
||||
inline int cdevSelect (int nfds, fd_set *r, fd_set *w, fd_set *e, struct timeval *t)
|
||||
{
|
||||
return ::select(nfds, (SELECT_PARM)r, (SELECT_PARM)w, (SELECT_PARM)e, t);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _CDEV_PLATFORMS_H_ */
|
||||
65
extensions/cdevGenericServer/include/cdevReactor.h
Normal file
65
extensions/cdevGenericServer/include/cdevReactor.h
Normal file
@@ -0,0 +1,65 @@
|
||||
#ifndef _CDEV_REACTOR_H_
|
||||
#define _CDEV_REACTOR_H_ 1
|
||||
|
||||
#include "cdevTime.h"
|
||||
#include "cdevHandleSet.h"
|
||||
#include "cdevEventHandler.h"
|
||||
|
||||
class CDEV_REACTOR_API cdevReactor
|
||||
{
|
||||
public:
|
||||
typedef enum {
|
||||
INPUT = 0,
|
||||
OUTPUT = 1,
|
||||
EXCEPTION = 2,
|
||||
SIGNAL = 3
|
||||
} REACTOR_EVENT;
|
||||
|
||||
typedef enum {
|
||||
REACTOR_ERROR = -1,
|
||||
SUCCESS = 0,
|
||||
INVALID_HANDLE = 1,
|
||||
INVALID_HANDLER = 2,
|
||||
HANDLE_EXISTS = 3,
|
||||
UNKNOWN_HANDLER = 4,
|
||||
INVALID_TIMEOUT = 5
|
||||
} REACTOR_RESULT;
|
||||
|
||||
typedef enum {
|
||||
UNTIL_TIMEOUT = 0,
|
||||
UNTIL_EVENT = 1
|
||||
} HANDLE_EVENT_FLAG;
|
||||
|
||||
protected:
|
||||
static int netInitCount;
|
||||
|
||||
int maxEntries;
|
||||
int size;
|
||||
cdevHandleSet read_set;
|
||||
cdevHandleSet write_set;
|
||||
cdevHandleSet except_set;
|
||||
cdevEventHandler ** handlers;
|
||||
cdevEventHandler * timers;
|
||||
|
||||
private:
|
||||
void calculateMask ( void );
|
||||
int calculateTimeout ( cdevTime defaultPeriod, struct timeval &timeout );
|
||||
int handleFileEvent ( cdevHandleSet * fds, REACTOR_EVENT event);
|
||||
public:
|
||||
cdevReactor ( void );
|
||||
virtual ~cdevReactor ( void );
|
||||
|
||||
virtual int checkHandlers ( void );
|
||||
virtual int registerHandler ( cdevEventHandler * handler, unsigned mask );
|
||||
virtual int removeHandler ( cdevEventHandler * handler );
|
||||
virtual int removeHandler ( int fd );
|
||||
virtual int extractHandler ( cdevEventHandler * handler );
|
||||
virtual int getHandler ( int fd, cdevEventHandler * &handler );
|
||||
|
||||
virtual int registerTimer ( cdevEventHandler * timer );
|
||||
virtual int cancelTimer ( cdevEventHandler * timer );
|
||||
|
||||
virtual int handleEvents ( cdevTime period = -1.0, int flags = UNTIL_TIMEOUT );
|
||||
};
|
||||
|
||||
#endif
|
||||
120
extensions/cdevGenericServer/include/cdevServer.h
Normal file
120
extensions/cdevGenericServer/include/cdevServer.h
Normal file
@@ -0,0 +1,120 @@
|
||||
#if !defined (_CDEV_SERVER_H_)
|
||||
#define _CDEV_SERVER_H_
|
||||
|
||||
#include "SignalManager.h"
|
||||
#include "cdevServerTools.h"
|
||||
#include "cdevMessage.h"
|
||||
#include "cdevContextMap.h"
|
||||
#include "cdevTagMap.h"
|
||||
#include "ClientInfo.h"
|
||||
#include "ServerInfo.h"
|
||||
#include "cdevGenericServerTags.h"
|
||||
|
||||
// *****************************************************************************
|
||||
// * class CLIPClientSession :
|
||||
// *
|
||||
// * This class also allows the server to associate certain data with a
|
||||
// * specific client...
|
||||
// *
|
||||
// * context: This is a pointer to the most recently used context from the
|
||||
// * cdevContextMap.
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API CLIPClientSession : public ClientSession
|
||||
{
|
||||
private:
|
||||
cdevData *context;
|
||||
|
||||
public:
|
||||
CLIPClientSession ( int SocketID, int ClientID, int LocalID )
|
||||
: ClientSession(SocketID, ClientID, LocalID),
|
||||
context(NULL)
|
||||
{
|
||||
}
|
||||
virtual ~CLIPClientSession ( void ) { }
|
||||
cdevData * getContext ( void ) { return context; }
|
||||
void setContext ( cdevData * cxt ) { context = cxt; }
|
||||
};
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * class CLIPSocketSession :
|
||||
// *
|
||||
// * This class allows the developer to associate additional information with
|
||||
// * a particular socket...
|
||||
// *
|
||||
// * contextMap : a table of cdevData contexts that can be retrieved by index
|
||||
// *
|
||||
// * tagMap : the table for mapping cdevData tags from the remote system
|
||||
// * to the tag table associated with this system.
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API CLIPSocketSession : public SocketSession, public ClientInfoStruct
|
||||
{
|
||||
private:
|
||||
cdevContextMap contextMap;
|
||||
cdevTagMap tagMap;
|
||||
|
||||
public:
|
||||
CLIPSocketSession ( int SocketID )
|
||||
: SocketSession ( SocketID )
|
||||
{
|
||||
}
|
||||
virtual ~CLIPSocketSession ( void ) { }
|
||||
cdevContextMap & ContextMap ( void ) { return contextMap; }
|
||||
cdevTagMap & TagMap ( void ) { return tagMap; }
|
||||
};
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * cdevServer :
|
||||
// * This is the cdevServer class. It is responsible for establishing a
|
||||
// * listening socket, and then responding to all incoming and outgoing
|
||||
// * messages.
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API cdevServer : public cdevSessionManager
|
||||
{
|
||||
public:
|
||||
typedef enum { SUCCESS = 0,
|
||||
UNINITIALIZED,
|
||||
CANT_OPEN_SOCKET,
|
||||
CANT_REGISTER_LISTENER,
|
||||
CANT_REGISTER_SERVER,
|
||||
CANT_REGISTER_TIMER
|
||||
} ServerInitStatus;
|
||||
|
||||
protected:
|
||||
char * serverName;
|
||||
class ClientAcceptor * acceptor;
|
||||
cdevNameServerManager * timer;
|
||||
ServerInitStatus status;
|
||||
ServerInfo * serverInfo;
|
||||
|
||||
public:
|
||||
static cdevGenericServerTagDef tags;
|
||||
static SignalManager SigManager;
|
||||
static sig_atomic_t Finished;
|
||||
|
||||
static void runServer (void);
|
||||
|
||||
cdevServer (char * DomainName, char * ServerName, unsigned short Port, double Rate);
|
||||
cdevServer (void);
|
||||
virtual ~cdevServer (void);
|
||||
int startServer (char * DomainName, char * ServerName, unsigned short Port, double Rate, int searchForPort=0);
|
||||
|
||||
virtual void registerClient ( short localID );
|
||||
virtual void unregisterClient ( short localID );
|
||||
|
||||
virtual ClientSession * newClientSession ( int SocketID, int ClientID, int LocalID );
|
||||
virtual SocketSession * newSocketSession ( int SocketID );
|
||||
virtual void deleteSocketSession ( SocketSession *socket );
|
||||
|
||||
virtual int dequeue (cdevMessage * &message);
|
||||
void processLocal (cdevMessage * &message);
|
||||
virtual cdevPacket * decodePacket (cdevPacketBinary * input);
|
||||
virtual cdevPacket * decodePacket (cdevMessage * message);
|
||||
virtual cdevPacketBinary * encodePacket (cdevPacket * input);
|
||||
virtual cdevPacketBinary * encodePacket (cdevMessage * message);
|
||||
virtual int operational (void) { return (status==0)?1:0; }
|
||||
virtual ServerInitStatus getInitStatus(void) { return status; }
|
||||
};
|
||||
|
||||
#endif /* _CDEV_SERVER_H_ */
|
||||
113
extensions/cdevGenericServer/include/cdevServerTools.h
Normal file
113
extensions/cdevGenericServer/include/cdevServerTools.h
Normal file
@@ -0,0 +1,113 @@
|
||||
#if !defined (_CDEV_SERVER_TOOLS_H_)
|
||||
#define _CDEV_SERVER_TOOLS_H_
|
||||
|
||||
#ifndef DONT_SUPPORT_CDEV_CALLS
|
||||
#include "cdevSystemEventHandler.h"
|
||||
#endif
|
||||
|
||||
#include "cdevSessionManager.h"
|
||||
#include "cdevMessage.h"
|
||||
#include "rsvcClient.h"
|
||||
#include "rsvcUdpClient.h"
|
||||
|
||||
// *****************************************************************************
|
||||
// * This is the cdevSimpleTimer class. The user specifies a function, a rate
|
||||
// * and a void * data pointer. The ACE_Reactor will then call the function
|
||||
// * each time the period of time expires.
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API cdevSimpleTimer : public cdevEventHandler, public ErrorReporter
|
||||
{
|
||||
public:
|
||||
cdevSimpleTimer ( cdevReactor & Reactor, double Rate = 1.0 );
|
||||
~cdevSimpleTimer ( void );
|
||||
virtual int handleTimeout (void);
|
||||
virtual int execute (void) = 0;
|
||||
};
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * class cdevNameServerManager:
|
||||
// * This class will extract the list of cdev Name Servers from the
|
||||
// * CDEV_NAME_SERVER environment variable and will create a collection
|
||||
// * of cdevNameServerHandler objects that will manage the connections
|
||||
// * to them. These cdevNameServerHandler objects will register the
|
||||
// * server with the name server and will send updates every five seconds.
|
||||
// * If the connection to the specific name server is lost, the
|
||||
// * cdevNameServer handler will call the unregisterHandler method to
|
||||
// * terminate the connection and before being deleted. This object
|
||||
// * will then attempt to reestablish the connection periodically.
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API cdevNameServerManager : public cdevEventHandler, public ErrorReporter
|
||||
{
|
||||
protected:
|
||||
char ** nameServerList;
|
||||
class cdevNameServerHandler ** nameServerHandlers;
|
||||
size_t nameServerCnt;
|
||||
rsvcData serverInfo;
|
||||
rsvcData updateInfo;
|
||||
char * serverName;
|
||||
char * domainName;
|
||||
unsigned short serverPort;
|
||||
|
||||
public:
|
||||
cdevNameServerManager ( cdevReactor & Reactor, char * DomainName, char * ServerName, unsigned short port);
|
||||
~cdevNameServerManager ( void );
|
||||
|
||||
static void rsvcCallback (int status, void* arg, rsvcData* data);
|
||||
|
||||
virtual int handleTimeout ( void );
|
||||
void unregisterHandler ( size_t index );
|
||||
rsvcData * getServerInfo ( void ) { return &serverInfo; }
|
||||
rsvcData * getUpdateInfo ( void ) { return &updateInfo; }
|
||||
char * getHostName ( size_t index ) { return (index<nameServerCnt)?nameServerList[index]:(char *)"UNKNOWN"; }
|
||||
};
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * class cdevNameServerHandler :
|
||||
// * This class will establish a connection with a specific cdev Name
|
||||
// * Server and will send period updates to let the name server know that
|
||||
// * the process is still alive and operational. If the handler loses its
|
||||
// * connection to the name server, it will notify the cdevNameServerManager
|
||||
// * prior to being deleted. The cdevNameServer manager will then attempt
|
||||
// * to recreate the connection at a later time.
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API cdevNameServerHandler : public cdevEventHandler, public ErrorReporter
|
||||
{
|
||||
protected:
|
||||
int nameServerIndex;
|
||||
rsvcClient * nameServerTCP;
|
||||
rsvcUdpClient * nameServerUDP;
|
||||
cdevNameServerManager & nameServerManager;
|
||||
|
||||
public:
|
||||
cdevNameServerHandler ( cdevNameServerManager & Manager, cdevReactor & Reactor, int index, rsvcClient *tcp, rsvcUdpClient *udp );
|
||||
~cdevNameServerHandler ( void );
|
||||
virtual int handleInput ( void );
|
||||
virtual int handleOutput ( void );
|
||||
virtual int handleTimeout ( void );
|
||||
virtual int getHandle ( void ) const;
|
||||
};
|
||||
|
||||
|
||||
#ifndef DONT_SUPPORT_CDEV_CALLS
|
||||
// *********************************************************************
|
||||
// * class cdevSystemHandler:
|
||||
// * This class causes the specified cdevReactor to periodically
|
||||
// * poll the cdevSystem for activity (by default 5 times per second).
|
||||
// *********************************************************************
|
||||
class GENERIC_SERVER_API cdevSystemHandler : public cdevSimpleTimer
|
||||
{
|
||||
protected:
|
||||
cdevSystem & system;
|
||||
|
||||
public:
|
||||
cdevSystemHandler (cdevReactor & Reactor,
|
||||
double pollRate = 0.2,
|
||||
cdevSystem & System = cdevSystem::defaultSystem());
|
||||
virtual ~cdevSystemHandler ( void );
|
||||
int execute ( void );
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* _CDEV_SERVER_TOOLS_H_ */
|
||||
222
extensions/cdevGenericServer/include/cdevSessionManager.h
Normal file
222
extensions/cdevGenericServer/include/cdevSessionManager.h
Normal file
@@ -0,0 +1,222 @@
|
||||
#if !defined (_CDEV_SESSION_MANAGER_H_)
|
||||
#define _CDEV_SESSION_MANAGER_H_
|
||||
|
||||
#include "cdevReactor.h"
|
||||
#include "cdevEventHandler.h"
|
||||
#include "cdevAddr.h"
|
||||
#include "cdevSocketStream.h"
|
||||
|
||||
#include "ErrorReporter.h"
|
||||
#include "FD_Trigger.h"
|
||||
#include "fifo.h"
|
||||
#include "IntHash.h"
|
||||
#include "cdevPacket.h"
|
||||
|
||||
// *****************************************************************************
|
||||
// * class ClientSession :
|
||||
// *
|
||||
// * The ClientSession allows the server to associate certain data
|
||||
// * with a specific client...
|
||||
// *
|
||||
// * The ClientSession object may be sub-classed later in order to allow the
|
||||
// * developer to attach additional information to a particular client id.
|
||||
// *
|
||||
// * localID : This is the short integer that uniquely identifies the
|
||||
// * client on the server side of the connection.
|
||||
// *
|
||||
// * clientID : This is an integer that uniquely identifies the client
|
||||
// * within the context of the socket... That is to say...
|
||||
// *
|
||||
// * The high-order short integer is the socketID - AND -
|
||||
// * the low-order short integer is a clientID that uniquely
|
||||
// * identifies the client on the client side of the connection.
|
||||
// *
|
||||
// * Even though both the clientID and the localID uniquely
|
||||
// * identify the client... both are maintained in order to
|
||||
// * perform bi-directional routing of packets between multiple
|
||||
// * repeaters.
|
||||
// *
|
||||
// * socketID : This is the socket number that the client is attached on.
|
||||
// *
|
||||
// * context: This is a pointer to the most recently used context from the
|
||||
// * cdevContextMap.
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API ClientSession
|
||||
{
|
||||
private:
|
||||
short localID;
|
||||
int clientID;
|
||||
int socketID;
|
||||
|
||||
public:
|
||||
ClientSession ( int SocketID, int ClientID, int LocalID );
|
||||
virtual ~ClientSession ( void );
|
||||
int getSocketID ( void ) { return socketID; }
|
||||
void setSocketID ( int SocketID ) { socketID = SocketID; }
|
||||
int getClientID ( void ) { return clientID; }
|
||||
void setClientID ( int ClientID ) { clientID = ClientID; }
|
||||
short getLocalID ( void ) { return localID; }
|
||||
void setLocalID ( short LocalID ) { localID = LocalID; }
|
||||
};
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * class SocketSession :
|
||||
// * This class is a queue that will feed to a specific socket in that is
|
||||
// * connected to a remote client. The class contains the following variables.
|
||||
// *
|
||||
// * The SocketSession object may be sub-classed later in order to allow the
|
||||
// * developer to attach additional information to a particular socket.
|
||||
// *
|
||||
// * socketID : the integer identifier of the socket
|
||||
// *
|
||||
// * contextMap : a table of cdevData contexts that can be retrieved by index
|
||||
// *
|
||||
// * tagMap : the table for mapping cdevData tags from the remote system
|
||||
// * to the tag table associated with this system.
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API SocketSession : public FifoQueue
|
||||
{
|
||||
private:
|
||||
int socketID;
|
||||
|
||||
public:
|
||||
SocketSession ( int SocketID );
|
||||
virtual ~SocketSession ( void );
|
||||
int getSocketID ( void ) { return socketID; }
|
||||
void setSocketID ( int SocketID ) { socketID = SocketID; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * class cdevSessionManager:
|
||||
// * The cdevSessionManager class is used to manage the queues that are
|
||||
// * associated with the operation of a server. It maintains the following
|
||||
// * variables.
|
||||
// *
|
||||
// * Reactor : This is the cdevReactor that will be used to manage the client
|
||||
// * connections.
|
||||
// *
|
||||
// * localIdx : This is the next available local index. This value will be
|
||||
// * used to populate the localID variable in each ClientSession.
|
||||
// *
|
||||
// *
|
||||
// * trigger : This is the file descriptor mechanism that is used to
|
||||
// * notify the cdevEventHandler mechanisms when a packet
|
||||
// * is available to be dequeued.
|
||||
// *
|
||||
// * rate : This is the rate at which the handleTimeout mechanism will
|
||||
// * be periodically called in order to process time oriented
|
||||
// * events.
|
||||
// *
|
||||
// * inbound : This is the inbound message queue. Since all messages will
|
||||
// * go to the same method to be processed, they can be enqueued
|
||||
// * in the same queue for storage.
|
||||
// *
|
||||
// * clients : This is a hash table that contains the queues for each
|
||||
// * client that is attached to the server. Since multiple
|
||||
// * clients can be routed through the same socket, these
|
||||
// * classes are used to determine which socket to send the
|
||||
// * outbound message to.
|
||||
// *
|
||||
// * sockets : This is the hash table that contains the queues for each
|
||||
// * socket. After the cdevSessionManager determines the clientID
|
||||
// * associated with an outbound message, that value will be used
|
||||
// * to locate the SocketSession - where the outbound message will
|
||||
// * be enqueued.
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API cdevSessionManager : public ErrorReporter, public cdevEventHandler
|
||||
{
|
||||
public:
|
||||
static cdevReactor Reactor;
|
||||
|
||||
protected:
|
||||
static IntHash localIdx;
|
||||
|
||||
FD_Trigger trigger;
|
||||
FifoQueue inbound;
|
||||
IntHash clients;
|
||||
IntHash sockets;
|
||||
|
||||
public:
|
||||
cdevSessionManager ( void ) {}
|
||||
virtual ~cdevSessionManager ( void );
|
||||
|
||||
static short getNextLocalID ( void );
|
||||
|
||||
// *********************************************************************
|
||||
// * These mechanisms are used to obtain new ClientSession and
|
||||
// * SocketSession objects. This design allows the developer to affix
|
||||
// * addition socket specific or client specific components to his
|
||||
// * classes later in order to have an easily accessable data point.
|
||||
// *********************************************************************
|
||||
virtual ClientSession * newClientSession ( int SocketID, int ClientID, int LocalID );
|
||||
virtual SocketSession * newSocketSession ( int SocketID );
|
||||
virtual void deleteSocketSession ( SocketSession * session );
|
||||
// *********************************************************************
|
||||
// * These mechanisms are used to add, locate and remove client and
|
||||
// * socket sessions.
|
||||
// *********************************************************************
|
||||
virtual ClientSession * findLocalClient ( short localID );
|
||||
virtual ClientSession * findClient ( int clientID );
|
||||
virtual SocketSession * findSocket ( int socketID );
|
||||
virtual ClientSession * addClient ( int socketID, int clientID );
|
||||
virtual SocketSession * addSocket ( int socketID );
|
||||
virtual void removeClient ( int clientID, int unregisterFlag=1);
|
||||
virtual void removeSocket ( int socketID );
|
||||
|
||||
// *********************************************************************
|
||||
// * This mechanism is used by the ClientHandler class to enqueue binary
|
||||
// * information incoming from the socket.
|
||||
// *********************************************************************
|
||||
virtual int enqueue ( int socketID, char * binary, unsigned binaryLen );
|
||||
|
||||
// *********************************************************************
|
||||
// * This method is used by the developer to send a packet to a specific
|
||||
// * client. The client is specified by the clientID in the cdevPacket.
|
||||
// *********************************************************************
|
||||
virtual int enqueue ( cdevPacket * packet );
|
||||
|
||||
// *********************************************************************
|
||||
// * This method is used by the developer to extract a packet from the
|
||||
// * inbound queue for processing.
|
||||
// *********************************************************************
|
||||
int dequeue ( cdevPacket * &packet );
|
||||
|
||||
// *********************************************************************
|
||||
// * This method is used by the developer to dequeue, process and then
|
||||
// * enqueue messages to a client.
|
||||
// *********************************************************************
|
||||
virtual void processMessages ( void );
|
||||
|
||||
// *********************************************************************
|
||||
// * This method formats packets when they are being enqueued or
|
||||
// * dequeued.
|
||||
// *********************************************************************
|
||||
virtual cdevPacket * decodePacket (cdevPacketBinary * input);
|
||||
virtual cdevPacketBinary * encodePacket (cdevPacket * input);
|
||||
|
||||
// *********************************************************************
|
||||
// * These are the ACE_Event_Handler methods that are called whenever
|
||||
// * a timeout, input or output event occur.
|
||||
// *********************************************************************
|
||||
virtual int getHandle (void) const;
|
||||
virtual int handleInput (void);
|
||||
virtual int handleClose (void);
|
||||
virtual int handleTimeout (void);
|
||||
|
||||
// *********************************************************************
|
||||
// * These are developer defined functions which are used to announce
|
||||
// * the creation of a new client or the destruction of an existing
|
||||
// * client to the main processing loop.
|
||||
// *
|
||||
// * Typically, they will only enqueue a message in the server specific
|
||||
// * packet format that specifies either "register" or "unregister" and
|
||||
// * the local client identifier.
|
||||
// *********************************************************************
|
||||
virtual void registerClient ( short localID ) = 0;
|
||||
virtual void unregisterClient ( short localID ) = 0;
|
||||
};
|
||||
|
||||
#endif /* _CDEV_SESSION_MANAGER_H_ */
|
||||
34
extensions/cdevGenericServer/include/cdevSocket.h
Normal file
34
extensions/cdevGenericServer/include/cdevSocket.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef _CDEV_SOCKET_H_
|
||||
#define _CDEV_SOCKET_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include "cdevAddr.h"
|
||||
|
||||
class CDEV_REACTOR_API cdevSocket
|
||||
{
|
||||
protected:
|
||||
int handle;
|
||||
sockaddr_in sa;
|
||||
|
||||
cdevSocket(void);
|
||||
cdevSocket(int type, int protocol_family, int protocol=0);
|
||||
|
||||
public:
|
||||
enum {INVALID_HANDLE=-1};
|
||||
|
||||
void setHandle (int fd);
|
||||
int getHandle (void) const;
|
||||
int open (int type, int protocol_family, int protocol);
|
||||
int close (void);
|
||||
int unsetFlags (int flags);
|
||||
int setFlags (int flags);
|
||||
int getFlags (void);
|
||||
int setOption (int level, int option, void *optval, int optlen) const;
|
||||
int getOption (int level, int option, void *optval, int *optlen) const;
|
||||
int getLocalAddress (cdevAddr & address);
|
||||
int getRemoteAddress (cdevAddr & address);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
32
extensions/cdevGenericServer/include/cdevSocketAcceptor.h
Normal file
32
extensions/cdevGenericServer/include/cdevSocketAcceptor.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef _CDEV_SOCKET_ACCEPTOR_H_
|
||||
#define _CDEV_SOCKET_ACCEPTOR_H_
|
||||
|
||||
#include "cdevSocketStream.h"
|
||||
|
||||
class CDEV_REACTOR_API cdevSocketAcceptor : public cdevSocket
|
||||
{
|
||||
public:
|
||||
cdevSocketAcceptor(void);
|
||||
cdevSocketAcceptor(
|
||||
const cdevAddr &addr,
|
||||
int reuse_addr = 0,
|
||||
int protocol_family = PF_INET,
|
||||
int backlog = 5,
|
||||
int protocol = 0);
|
||||
|
||||
int open(const cdevAddr &addr,
|
||||
int reuse_addr = 0,
|
||||
int protocol_family = PF_INET,
|
||||
int backlog = 5,
|
||||
int protocol = 0,
|
||||
int reopen = 1);
|
||||
|
||||
int accept(
|
||||
cdevSocketStream &new_stream,
|
||||
cdevAddr *remote_addr=0) const;
|
||||
|
||||
private:
|
||||
int getRemoteAddress(cdevAddr &) const;
|
||||
};
|
||||
|
||||
#endif /* _CDEV_SOCKET_ACCEPTOR_H */
|
||||
12
extensions/cdevGenericServer/include/cdevSocketConnector.h
Normal file
12
extensions/cdevGenericServer/include/cdevSocketConnector.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef _CDEV_SOCKET_CONNECTOR_H_
|
||||
#define _CDEV_SOCKET_CONNECTOR_H_
|
||||
|
||||
#include "cdevSocketStream.h"
|
||||
|
||||
class CDEV_REACTOR_API cdevSocketConnector : public cdevSocketStream
|
||||
{
|
||||
public:
|
||||
int connect (const cdevAddr & remote_addr );
|
||||
};
|
||||
|
||||
#endif /* _CDEV_SOCK_CONNECTOR_H */
|
||||
18
extensions/cdevGenericServer/include/cdevSocketDatagram.h
Normal file
18
extensions/cdevGenericServer/include/cdevSocketDatagram.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#if !defined (_CDEV_SOCKET_DATAGRAM_H_)
|
||||
#define _CDEV_SOCKET_DATAGRAM_H
|
||||
|
||||
#include "cdevSocket.h"
|
||||
#include "cdevAddr.h"
|
||||
|
||||
class CDEV_REACTOR_API cdevSocketDatagram : public cdevSocket
|
||||
{
|
||||
public:
|
||||
cdevSocketDatagram (void);
|
||||
cdevSocketDatagram (const cdevAddr &addr, int protocol_family = PF_INET, int protocol = 0);
|
||||
int open (const cdevAddr &addr, int protocol_family = PF_INET, int protocol = 0);
|
||||
ssize_t send (const void *buf, size_t n, const cdevAddr &addr, int flags = 0) const;
|
||||
ssize_t recv (void *buf, size_t n, cdevAddr &addr, int flags = 0) const;
|
||||
|
||||
};
|
||||
|
||||
#endif /* _CDEV_SOCKET_DATAGRAM_H_ */
|
||||
29
extensions/cdevGenericServer/include/cdevSocketStream.h
Normal file
29
extensions/cdevGenericServer/include/cdevSocketStream.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#if !defined (_CDEV_SOCKET_STREAM_H)
|
||||
#define _CDEV_SOCKET_STREAM_H
|
||||
|
||||
#include "cdevSocket.h"
|
||||
#include <signal.h>
|
||||
|
||||
|
||||
class CDEV_REACTOR_API cdevSocketStream : public cdevSocket
|
||||
{
|
||||
public:
|
||||
cdevSocketStream (void);
|
||||
ssize_t send (const void *buf, size_t n, int flags=0) const;
|
||||
ssize_t recv (void *buf, size_t n, int flags=0);
|
||||
ssize_t send_n (const void *buf, size_t n, int flags=0) const;
|
||||
ssize_t recv_n (void * buf, size_t n, int flags=0);
|
||||
|
||||
int closeReader (void);
|
||||
int closeWriter (void);
|
||||
|
||||
virtual int getBlockingSemantics ( void ) const;
|
||||
virtual int getRcvLowWaterMark ( void ) const;
|
||||
virtual int getSndLowWaterMark ( void ) const;
|
||||
virtual int getRcvBufferSize ( void ) const;
|
||||
virtual int getSndBufferSize ( void ) const;
|
||||
virtual int configureHandle ( void );
|
||||
};
|
||||
|
||||
#endif /* _CDEV_SOCKET_STREAM_H_ */
|
||||
|
||||
33
extensions/cdevGenericServer/include/cdevStreamNode.h
Normal file
33
extensions/cdevGenericServer/include/cdevStreamNode.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef _CDEV_STREAM_NODE_H_
|
||||
#define _CDEV_STREAM_NODE_H_
|
||||
|
||||
#include "cdevPlatforms.h"
|
||||
|
||||
// *****************************************************************************
|
||||
// * class cdevStreamNode :
|
||||
// * This is a virtual base class that defines the functionality that will
|
||||
// * be required for data nodes that are inserted into the
|
||||
// * cdevBufferedSocket.
|
||||
// *****************************************************************************
|
||||
class CDEV_REACTOR_API cdevStreamNode
|
||||
{
|
||||
friend class cdevStreamQueue;
|
||||
|
||||
public:
|
||||
virtual ~cdevStreamNode ( void );
|
||||
|
||||
virtual size_t getLen(void) const = 0;
|
||||
virtual void setLen(size_t size) = 0;
|
||||
virtual char * getBuf(void) const = 0;
|
||||
virtual void setBuf(char * buf, size_t len) = 0;
|
||||
|
||||
protected:
|
||||
cdevStreamNode * nextStreamNode;
|
||||
|
||||
cdevStreamNode ( void );
|
||||
|
||||
cdevStreamNode * getNext( void ) const;
|
||||
void setNext(cdevStreamNode * node);
|
||||
};
|
||||
|
||||
#endif /* _CDEV_STREAM_NODE_H_ */
|
||||
126
extensions/cdevGenericServer/include/cdevStreamQueue.h
Normal file
126
extensions/cdevGenericServer/include/cdevStreamQueue.h
Normal file
@@ -0,0 +1,126 @@
|
||||
#ifndef _CDEV_STREAM_QUEUE_H_
|
||||
#define _CDEV_STREAM_QUEUE_H_
|
||||
|
||||
#include "cdevStreamNode.h"
|
||||
|
||||
// *****************************************************************************
|
||||
// * class cdevSimpleStreamNode :
|
||||
// * This is a simple implementation class of the cdevStreamNode. It will
|
||||
// * be used if the developer does not provide his own implementation class.
|
||||
// *****************************************************************************
|
||||
class CDEV_REACTOR_API cdevSimpleStreamNode : public cdevStreamNode
|
||||
{
|
||||
protected:
|
||||
char * buf;
|
||||
size_t len;
|
||||
|
||||
public:
|
||||
cdevSimpleStreamNode ( char * buffer=NULL, size_t size=0);
|
||||
~cdevSimpleStreamNode ( void );
|
||||
|
||||
size_t getLen (void) const;
|
||||
void setLen (size_t size);
|
||||
char * getBuf (void) const;
|
||||
void setBuf (char * buffer, size_t size);
|
||||
};
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * class cdevNodeFactory :
|
||||
// * This class will generate a user defined instance of a cdevStreamNode
|
||||
// * sub-class. This class is used within the cdevBufferedSocket to
|
||||
// * convert incoming binary packets into a user defined structure.
|
||||
// *****************************************************************************
|
||||
class CDEV_REACTOR_API cdevNodeFactory
|
||||
{
|
||||
public:
|
||||
virtual ~cdevNodeFactory ( void );
|
||||
|
||||
virtual cdevStreamNode * newNode ( ssize_t size ) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * class cdevStreamQueue :
|
||||
// * This is a class that will store the data items that are being enqueued
|
||||
// * by the cdevBufferedSocket.
|
||||
// *****************************************************************************
|
||||
class CDEV_REACTOR_API cdevStreamQueue
|
||||
{
|
||||
private:
|
||||
cdevStreamNode * head;
|
||||
cdevStreamNode * tail;
|
||||
int deleteFlag;
|
||||
size_t nEntries;
|
||||
size_t totalLen;
|
||||
|
||||
public:
|
||||
cdevStreamQueue ( int deleteNodesFlag = 1 )
|
||||
: head(NULL), tail(NULL), deleteFlag(deleteNodesFlag),
|
||||
nEntries(0), totalLen(0)
|
||||
{
|
||||
}
|
||||
|
||||
~cdevStreamQueue ( void )
|
||||
{
|
||||
if(deleteFlag) while(!isEmpty()) delete dequeue();
|
||||
}
|
||||
|
||||
void enqueue( cdevStreamQueue & queue )
|
||||
{
|
||||
head = queue.head;
|
||||
tail = queue.tail;
|
||||
nEntries = queue.nEntries;
|
||||
totalLen = queue.totalLen;
|
||||
queue.head = NULL;
|
||||
queue.tail = NULL;
|
||||
queue.nEntries = 0;
|
||||
queue.totalLen = 0;
|
||||
}
|
||||
|
||||
void enqueue ( cdevStreamNode * node )
|
||||
{
|
||||
if(node)
|
||||
{
|
||||
if(tail!=NULL) tail->setNext(node);
|
||||
else head = node;
|
||||
tail = node;
|
||||
totalLen+=(node->getLen()+sizeof(node->getLen()));
|
||||
nEntries++;
|
||||
}
|
||||
}
|
||||
|
||||
cdevStreamNode * dequeue ( void )
|
||||
{
|
||||
cdevStreamNode * node = NULL;
|
||||
if(head!=NULL)
|
||||
{
|
||||
node = head;
|
||||
head = node->getNext();
|
||||
node->setNext(NULL);
|
||||
if(head==NULL) tail = NULL;
|
||||
totalLen-=(node->getLen()+sizeof(node->getLen()));
|
||||
nEntries--;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
cdevStreamNode * peek ( void )
|
||||
{
|
||||
return head;
|
||||
}
|
||||
|
||||
void poke ( cdevStreamNode * node )
|
||||
{
|
||||
node->setNext(head);
|
||||
head = node;
|
||||
if(tail==NULL) tail = head;
|
||||
}
|
||||
|
||||
int isEmpty ( void ) const { return head==NULL?1:0; }
|
||||
size_t getCount ( void ) const { return nEntries; }
|
||||
size_t getSize ( void ) const { return totalLen; }
|
||||
};
|
||||
|
||||
#endif /* _CDEV_STREAM_QUEUE_H */
|
||||
@@ -0,0 +1,90 @@
|
||||
#include "cdevSystem.h"
|
||||
#include "cdevSessionManager.h"
|
||||
|
||||
class GENERIC_SERVER_API cdevSystemEventHandler : public cdevEventHandler
|
||||
{
|
||||
private:
|
||||
int cdevfd;
|
||||
|
||||
public:
|
||||
cdevSystemEventHandler ( cdevReactor & Reactor, int fd )
|
||||
: cdevfd(fd)
|
||||
{
|
||||
Reactor.registerHandler(this, READ_MASK|WRITE_MASK|EXCEPT_MASK);
|
||||
}
|
||||
|
||||
~cdevSystemEventHandler ( void )
|
||||
{
|
||||
if(reactor) reactor->extractHandler(this);
|
||||
handleClose();
|
||||
}
|
||||
|
||||
int handleInput ( void )
|
||||
{
|
||||
cdevSystem::defaultSystem().poll();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handleOutput ( void )
|
||||
{
|
||||
cdevSystem::defaultSystem().flush();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handleExcept ( void )
|
||||
{
|
||||
cdevSystem::defaultSystem().poll();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getHandle ( void ) const
|
||||
{
|
||||
return cdevfd;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
class GENERIC_SERVER_API cdevSystemEventManager : public cdevEventHandler
|
||||
{
|
||||
public:
|
||||
cdevSystemEventManager ( cdevReactor &Reactor=cdevSessionManager::Reactor, double Rate = 30.0 )
|
||||
{
|
||||
setTimeoutRate(Rate);
|
||||
Reactor.registerTimer(this);
|
||||
cdevSystem::defaultSystem().addFdChangedCallback
|
||||
(cdevSystemEventManager::fdChangedCallback, this);
|
||||
}
|
||||
|
||||
~cdevSystemEventManager ( void )
|
||||
{
|
||||
if(reactor) reactor->extractHandler(this);
|
||||
handleClose();
|
||||
}
|
||||
|
||||
int handleTimeout ( void )
|
||||
{
|
||||
cdevSystem::defaultSystem().pend(0.0001);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void fdChangedCallback ( int fd, int opened, void * arg )
|
||||
{
|
||||
cdevSystemEventManager *manager = (cdevSystemEventManager *)arg;
|
||||
cdevEventHandler *handler;
|
||||
cdevReactor *reactor = manager->reactor;
|
||||
|
||||
if(reactor)
|
||||
{
|
||||
if(opened && reactor->getHandler(fd, handler)!=0)
|
||||
{
|
||||
handler = new cdevSystemEventHandler(*reactor, fd);
|
||||
}
|
||||
else if(!opened && reactor->getHandler(fd, handler)==0)
|
||||
{
|
||||
delete handler;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
31
extensions/cdevGenericServer/include/cdevTagMap.h
Normal file
31
extensions/cdevGenericServer/include/cdevTagMap.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <cdevPlatforms.h>
|
||||
#include <cdevData.h>
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * class cdevTagMap:
|
||||
// * The purpose of the cdevTagMap is to allow rapid translation between
|
||||
// * the cdev tag tables that within different processes.
|
||||
// *
|
||||
// * This class provides the capability to switch back and forth from the
|
||||
// * local tag values to the remote tag values.
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API cdevTagMap
|
||||
{
|
||||
private:
|
||||
int cnt;
|
||||
int maximum;
|
||||
int * local;
|
||||
int * remote;
|
||||
|
||||
public:
|
||||
cdevTagMap ( void );
|
||||
~cdevTagMap ( void );
|
||||
void updateTagMap ( cdevData & data );
|
||||
void updateTagMap ( char ** names, int * tags, int count );
|
||||
void swapTags ( cdevData & data, int *inTags, int *outTags, int count);
|
||||
void localToRemote ( cdevData & data ) { if(cnt) swapTags(data, remote, local, cnt); }
|
||||
void remoteToLocal ( cdevData & data ) { if(cnt) swapTags(data, local, remote, cnt); }
|
||||
void asciiDump ( FILE * fp = stdout );
|
||||
};
|
||||
|
||||
51
extensions/cdevGenericServer/include/cdevTime.h
Normal file
51
extensions/cdevGenericServer/include/cdevTime.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef _CDEV_TIME_H_
|
||||
#define _CDEV_TIME_H_ 1
|
||||
|
||||
#include "cdevPlatforms.h"
|
||||
|
||||
#define ONE_SECOND 1000000
|
||||
|
||||
typedef struct timeval timeval;
|
||||
|
||||
class CDEV_REACTOR_API cdevTime
|
||||
{
|
||||
private:
|
||||
long tv_sec;
|
||||
long tv_usec;
|
||||
|
||||
public:
|
||||
cdevTime ( long sec=0, long usec=0 );
|
||||
cdevTime ( double t );
|
||||
cdevTime ( timeval &t );
|
||||
cdevTime ( const cdevTime &t );
|
||||
|
||||
void getTime ( double * t ) const;
|
||||
void getTime ( long *sec, long *usec) const;
|
||||
void getTime ( timeval * t ) const;
|
||||
|
||||
void setTime ( void );
|
||||
void setTime ( double t );
|
||||
void setTime ( long sec, long usec);
|
||||
void setTime ( timeval &t );
|
||||
void setTime ( const cdevTime &t );
|
||||
|
||||
void clear ( void );
|
||||
int isSet ( void ) const;
|
||||
int normalize ( void );
|
||||
|
||||
operator double ( void );
|
||||
operator timeval ( void );
|
||||
|
||||
cdevTime & operator = (const cdevTime& t);
|
||||
|
||||
friend cdevTime operator + (cdevTime t1, cdevTime t2);
|
||||
friend cdevTime operator - (cdevTime t1, cdevTime t2);
|
||||
friend int operator < (cdevTime t1, cdevTime t2);
|
||||
friend int operator > (cdevTime t1, cdevTime t2);
|
||||
friend int operator <= (cdevTime t1, cdevTime t2);
|
||||
friend int operator >= (cdevTime t1, cdevTime t2);
|
||||
friend int operator == (cdevTime t1, cdevTime t2);
|
||||
friend int operator != (cdevTime t1, cdevTime t2);
|
||||
};
|
||||
|
||||
#endif
|
||||
8
extensions/cdevGenericServer/include/clipMagicNumber.h
Normal file
8
extensions/cdevGenericServer/include/clipMagicNumber.h
Normal file
@@ -0,0 +1,8 @@
|
||||
// *****************************************************************************
|
||||
// * CLIP_MAGIC_NUMBER :
|
||||
// * The magic number was added to the CLIP Protocol beginning with version
|
||||
// * 1.6 of CDEV. This magic number will preceed the buffer length in
|
||||
// * a clip buffer and will be used to validate that the client is using the
|
||||
// * same protocol as the server.
|
||||
// *****************************************************************************
|
||||
#define CLIP_MAGIC_NUMBER 0x434C4950
|
||||
315
extensions/cdevGenericServer/include/fifo.h
Normal file
315
extensions/cdevGenericServer/include/fifo.h
Normal file
@@ -0,0 +1,315 @@
|
||||
/*-----------------------------------------------------------------------------
|
||||
* Copyright (c) 1991,1992 Southeastern Universities Research Association,
|
||||
* Continuous Electron Beam Accelerator Facility
|
||||
*
|
||||
* This software was developed under a United States Government license
|
||||
* described in the NOTICE file included as part of this distribution.
|
||||
*
|
||||
*-----------------------------------------------------------------------------
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
* Author: Walt Akers
|
||||
*
|
||||
* Revision History:
|
||||
* fifo.h,v
|
||||
* Revision 1.4 1997/12/22 15:15:45 akers
|
||||
* Ongoing development with new cdevReactor
|
||||
*
|
||||
* Revision 1.3 1996/09/13 18:47:18 akers
|
||||
* Installed free list for node objects
|
||||
*
|
||||
* Revision 1.2 1996/07/16 15:48:55 akers
|
||||
* Ongoing Modifications
|
||||
*
|
||||
*-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef __FIFO_H_
|
||||
#define __FIFO_H_ 1
|
||||
|
||||
#include <cdevPlatforms.h>
|
||||
|
||||
class GENERIC_SERVER_API QueueBase
|
||||
{
|
||||
public:
|
||||
class node
|
||||
{
|
||||
friend class QueueBase;
|
||||
private:
|
||||
node ( void ) : binary(NULL), binaryLen(0), next(NULL) { }
|
||||
~node ( void ) { }
|
||||
public:
|
||||
void * binary;
|
||||
size_t binaryLen;
|
||||
class node * next;
|
||||
};
|
||||
|
||||
protected:
|
||||
node * head;
|
||||
node * tail;
|
||||
|
||||
private:
|
||||
enum { NEWCNT = 32 };
|
||||
static node * freeList_;
|
||||
|
||||
public:
|
||||
QueueBase ( void )
|
||||
: head(NULL), tail(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~QueueBase ( void )
|
||||
{
|
||||
}
|
||||
|
||||
static node * newNode ( void )
|
||||
{
|
||||
node * result;
|
||||
if(freeList_==NULL)
|
||||
{
|
||||
freeList_ = new node[NEWCNT];
|
||||
for(int i=0; i<NEWCNT; i++)
|
||||
{
|
||||
freeList_[i].binary = NULL;
|
||||
freeList_[i].binaryLen = 0;
|
||||
freeList_[i].next = (i<(NEWCNT-1))?&freeList_[i+1]:(node *)NULL;
|
||||
}
|
||||
}
|
||||
result = &freeList_[0];
|
||||
freeList_ = result->next;
|
||||
result->binary = NULL;
|
||||
result->binaryLen = 0;
|
||||
result->next = NULL;
|
||||
return result;
|
||||
}
|
||||
|
||||
static void deleteNode ( node * ptr)
|
||||
{
|
||||
if(ptr->next!=NULL) deleteNode(ptr->next);
|
||||
ptr->next = freeList_;
|
||||
freeList_ = ptr;
|
||||
}
|
||||
};
|
||||
|
||||
class GENERIC_SERVER_API FifoQueue : public QueueBase
|
||||
{
|
||||
private:
|
||||
int nodeCnt;
|
||||
|
||||
public:
|
||||
FifoQueue ( void ) : QueueBase(), nodeCnt(0) {}
|
||||
|
||||
virtual ~FifoQueue ( void )
|
||||
{
|
||||
while(dequeue()!=NULL);
|
||||
}
|
||||
|
||||
int empty ( void )
|
||||
{
|
||||
return head==NULL?1:0;
|
||||
}
|
||||
|
||||
void enqueue ( void * ptr )
|
||||
{
|
||||
if(ptr != NULL)
|
||||
{
|
||||
if(tail==NULL) tail = newNode();
|
||||
else
|
||||
{
|
||||
tail->next = newNode();
|
||||
tail = tail->next;
|
||||
}
|
||||
tail->binary = ptr;
|
||||
if(head==NULL) head = tail;
|
||||
nodeCnt++;
|
||||
}
|
||||
}
|
||||
|
||||
void enqueue ( char * ptr, size_t len )
|
||||
{
|
||||
if(ptr != NULL && len > 0 )
|
||||
{
|
||||
if(tail==NULL) tail = newNode();
|
||||
else {
|
||||
tail->next = newNode();
|
||||
tail = tail->next;
|
||||
}
|
||||
tail->binary = ptr;
|
||||
tail->binaryLen = len;
|
||||
if(head==NULL) head = tail;
|
||||
nodeCnt++;
|
||||
}
|
||||
}
|
||||
|
||||
void * dequeue ( void )
|
||||
{
|
||||
void * result = NULL;
|
||||
if(head!=NULL)
|
||||
{
|
||||
node * next = head->next;
|
||||
result = head->binary;
|
||||
head->next = NULL;
|
||||
deleteNode(head);
|
||||
head = next;
|
||||
if(head==NULL) tail = NULL;
|
||||
nodeCnt--;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int dequeue ( char ** ptr, size_t * len )
|
||||
{
|
||||
int result = -1;
|
||||
*ptr = NULL;
|
||||
*len = 0;
|
||||
if(head!=NULL)
|
||||
{
|
||||
node * next = head->next;
|
||||
result = 0;
|
||||
*ptr = (char *)head->binary;
|
||||
*len = head->binaryLen;
|
||||
head->next = NULL;
|
||||
deleteNode(head);
|
||||
head = next;
|
||||
if(head==NULL) tail = NULL;
|
||||
nodeCnt--;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int peek ( char ** ptr, size_t *len )
|
||||
{
|
||||
int result = -1;
|
||||
if(head!=NULL)
|
||||
{
|
||||
*ptr = (char *)head->binary;
|
||||
*len = head->binaryLen;
|
||||
result = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void undequeue ( void * ptr )
|
||||
{
|
||||
if(ptr != NULL)
|
||||
{
|
||||
if(tail==NULL) enqueue(ptr);
|
||||
else {
|
||||
node * headnode = newNode();
|
||||
headnode->binary = ptr;
|
||||
headnode->next = head;
|
||||
head = headnode;
|
||||
nodeCnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void undequeue ( char *ptr, size_t len)
|
||||
{
|
||||
if(ptr != NULL && len > 0)
|
||||
{
|
||||
if(tail==NULL) enqueue(ptr, len);
|
||||
else {
|
||||
node * headnode = newNode();
|
||||
headnode->binary = ptr;
|
||||
headnode->binaryLen = len;
|
||||
headnode->next = head;
|
||||
head = headnode;
|
||||
nodeCnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int getCount ( void ) { return nodeCnt; }
|
||||
};
|
||||
|
||||
|
||||
class GENERIC_SERVER_API ListQueue : public QueueBase
|
||||
{
|
||||
protected:
|
||||
node * prev;
|
||||
node * bookmark;
|
||||
|
||||
public:
|
||||
ListQueue ( void ) : QueueBase ()
|
||||
{
|
||||
prev = NULL;
|
||||
bookmark = NULL;
|
||||
}
|
||||
virtual ~ListQueue ( void )
|
||||
{
|
||||
while(first()==0) remove();
|
||||
}
|
||||
int first ( void )
|
||||
{
|
||||
prev = NULL;
|
||||
bookmark = head;
|
||||
return (bookmark==NULL?-1:0);
|
||||
}
|
||||
int next ( void )
|
||||
{
|
||||
if(bookmark!=NULL)
|
||||
{
|
||||
prev = bookmark;
|
||||
bookmark = bookmark->next;
|
||||
}
|
||||
return (bookmark==NULL?-1:0);
|
||||
}
|
||||
void * dequeue ( void )
|
||||
{
|
||||
return (bookmark==NULL?NULL:bookmark->binary);
|
||||
}
|
||||
void enqueue ( void * ptr )
|
||||
{
|
||||
if(ptr != NULL)
|
||||
{
|
||||
prev = tail;
|
||||
if(tail==NULL) tail = newNode();
|
||||
else
|
||||
{
|
||||
tail->next = newNode();
|
||||
tail = tail->next;
|
||||
}
|
||||
tail->binary = ptr;
|
||||
bookmark = tail;
|
||||
if(head==NULL) head = tail;
|
||||
}
|
||||
}
|
||||
int remove ( void )
|
||||
{
|
||||
int retval = -1;
|
||||
if(bookmark != NULL)
|
||||
{
|
||||
if(prev!=NULL) prev->next = bookmark->next;
|
||||
else head = bookmark->next;
|
||||
|
||||
bookmark->next = NULL;
|
||||
deleteNode(bookmark);
|
||||
|
||||
if(prev!=NULL) {
|
||||
bookmark = prev->next;
|
||||
}
|
||||
else if(head!=NULL && head->next!=NULL) {
|
||||
bookmark = head->next;
|
||||
}
|
||||
else bookmark = head;
|
||||
|
||||
for( tail=head;
|
||||
tail!=NULL && tail->next!=NULL;
|
||||
tail=tail->next);
|
||||
retval = 0;
|
||||
}
|
||||
else if(head!=NULL) first();
|
||||
else tail = NULL;
|
||||
return retval;
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef _FIFO_QUEUE_MASTER_
|
||||
QueueBase::node * QueueBase::freeList_ = NULL;
|
||||
#endif
|
||||
|
||||
#endif // __FIFO_H_
|
||||
|
||||
16
extensions/cdevGenericServer/include/header.h
Normal file
16
extensions/cdevGenericServer/include/header.h
Normal file
@@ -0,0 +1,16 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
93
extensions/cdevGenericServer/include/makeinclude/Makefile.OS
Normal file
93
extensions/cdevGenericServer/include/makeinclude/Makefile.OS
Normal file
@@ -0,0 +1,93 @@
|
||||
# ******************************************************************************
|
||||
# * Makefile.Linux : This is the platform specific Makefile for Linux.
|
||||
# *
|
||||
# * Externals : This Makefile relies on the developer defining the
|
||||
# * following external definitions...
|
||||
# *
|
||||
# * CDEV : The base directory of the CDEV distribution
|
||||
# ******************************************************************************
|
||||
TARGET = Linux
|
||||
|
||||
include $(CDEV)/extensions/cdevGenericServer/include/makeinclude/Makefile.common
|
||||
include $(CDEV)/include/makeinclude/Makefile.archive
|
||||
|
||||
# ******************************************************************************
|
||||
# * Platform specific compile and link options.
|
||||
# ******************************************************************************
|
||||
|
||||
# ******************************************************************************
|
||||
# * Only specify the DEBUGFLAG if the DEBUG variable has been set.
|
||||
# ******************************************************************************
|
||||
ifdef DEBUG
|
||||
DEBUGFLAG = -g
|
||||
else
|
||||
DEBUGFLAG = -O2
|
||||
endif
|
||||
|
||||
CXX = g++
|
||||
CC = gcc
|
||||
CXXFLAGS = -DLinux -fno-for-scope $(DEBUGFLAG) $(CXXEXTRA) $(CXXINCLUDES) \
|
||||
$(CDEVINCLUDES) $(BASEINCLUDES)
|
||||
CFLAGS = -DLinux $(DEBUGFLAG) $(CEXTRA) $(CXXINCLUDES) $(CDEVINCLUDES) $(BASEINCLUDES)
|
||||
AR = ar
|
||||
ARFLAGS = ruv
|
||||
RANLIB = ranlib
|
||||
DLD = $(CXX)
|
||||
SOFLAGS = -shared
|
||||
PIC = -fpic
|
||||
SHARED_EXT = so
|
||||
NETLIBS =
|
||||
OSLIBS = $(NETLIBS) -lm -ldl
|
||||
|
||||
|
||||
# ******************************************************************************
|
||||
# * These definitions define the names and locations of libraries that are
|
||||
# * required by CDEV for a shared and archive applications. The developer
|
||||
# * is required to add the list of service specific libraries.
|
||||
# ******************************************************************************
|
||||
ifeq ($(SHOBJ), NO)
|
||||
CDEVLIBS = $(CDEVLIB)/libcdev.a $(ARCHIVELIBS)
|
||||
else
|
||||
CDEVLIBS = -L$(CDEVLIB) -lcdev
|
||||
endif
|
||||
|
||||
|
||||
# ******************************************************************************
|
||||
# * Platform specific compile and link macros.
|
||||
# ******************************************************************************
|
||||
COMPILE.cc = $(QUIET)$(CXX_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) -c $(CXXFLAGS) $^ -o $@
|
||||
COMPILE.cc.so = $(QUIET)$(CXX_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) $(CXXFLAGS) $(PIC) -c -o $@ $^
|
||||
COMPILE.c = $(QUIET)$(CC_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CC) -c $(CFLAGS) $^ -o $@
|
||||
COMPILE.c.so = $(QUIET)$(CC_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CC) -c $(CFLAGS) $(PIC) $^ -o $@
|
||||
LINK.cc = $(QUIET)$(LINK_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) $(CXXFLAGS) -Xlinker -rpath -Xlinker $(BASELIB) -Xlinker -rpath -Xlinker $(CDEVLIB)
|
||||
LINK.a = $(QUIET)$(AR_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(AR) $(ARFLAGS)
|
||||
LINK.so = $(QUIET)$(SO_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(DLD) $(SOFLAGS)
|
||||
|
||||
# ******************************************************************************
|
||||
# * This is the macro to build a shared object/library.... it requires the
|
||||
# * following variables to be defined...
|
||||
# *
|
||||
# * SO_SRCS : Names of the component source files
|
||||
# * SO_LIBS : Names of the dependent libraries
|
||||
# * LIBS : All libraries necessary to compile the dummy application
|
||||
# ******************************************************************************
|
||||
SOBUILD = rm -f $@;\
|
||||
mkdir -p $(@D);\
|
||||
echo "=> Building shared object $(@F)";\
|
||||
$(LINK.so) -o $@ $^ -R $(CDEVLIB) -L$(CDEVLIB) -L./ $(NETLIBS)
|
||||
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
!IF "$(VERBOSE)" != "YES"
|
||||
!CMDSWITCHES +S
|
||||
!ELSE
|
||||
!CMDSWITCHES -S
|
||||
!ENDIF
|
||||
|
||||
TARGET = WINNT
|
||||
OS_MAJOR = 4
|
||||
OS_MINOR = 0
|
||||
OS_VERSION_DEF = /D "_OS_MAJOR_=$(OS_MAJOR)" /D "_OS_MINOR_=$(OS_MINOR)"
|
||||
|
||||
!IF "$(DEBUG)" == ""
|
||||
TARGETDIR = $(TARGET)-$(OS_MAJOR).$(OS_MINOR)
|
||||
!ELSE
|
||||
TARGETDIR = $(TARGET)-$(OS_MAJOR).$(OS_MINOR)-DEBUG
|
||||
!ENDIF
|
||||
|
||||
CDEVVERSION = 1.7.2
|
||||
CDEVINCLUDES = /I $(CDEV)\include
|
||||
CDEVLIB = $(CDEV)\lib\$(TARGETDIR)
|
||||
CDEVBIN = $(CDEV)\bin\$(TARGETDIR)
|
||||
CREATE_LINK = copy $** $@ > nul
|
||||
|
||||
BASEDIR = $(CDEV)\extensions\cdevGenericServer
|
||||
BASEINCLUDES = /I $(BASEDIR)\include
|
||||
|
||||
!IF "$(BASELIB)" == ""
|
||||
BASELIB = $(BASEDIR)\lib\$(TARGETDIR)
|
||||
!ENDIF
|
||||
|
||||
!IF "$(BASEBIN)" == ""
|
||||
BASEBIN = $(BASEDIR)\bin\$(TARGETDIR)
|
||||
!ENDIF
|
||||
|
||||
!IF "$(CDEVSHOBJ)" == ""
|
||||
CDEVSHOBJ = $(CDEVLIB)
|
||||
!ENDIF
|
||||
|
||||
!IF "$(SHOBJ)" == "NO"
|
||||
OBJDIR = .obj\$(TARGETDIR)
|
||||
!ELSE
|
||||
SHOBJ = YES
|
||||
OBJDIR = .shobj\$(TARGETDIR)
|
||||
!ENDIF
|
||||
|
||||
CC = cl
|
||||
CXX = cl
|
||||
LIB32 = link
|
||||
LINK = link
|
||||
|
||||
CC_ALL_EXE = /nologo /D "WIN32" /D "_WINDOWS" /D "_MBCS" /Fo".exec\$(TARGETDIR)/"\
|
||||
$(CXXEXTRA) $(CXXEXTRA_EXE) $(CXXINCLUDES) $(CDEVINCLUDES) $(BASEINCLUDES) $(OS_VERSION_DEF) /TC /c
|
||||
CXX_ALL_EXE = /nologo /D "WIN32" /D "_WINDOWS" /D "_MBCS" /Fo".exec\$(TARGETDIR)/"\
|
||||
$(CXXEXTRA) $(CXXEXTRA_EXE) $(CXXINCLUDES) $(CDEVINCLUDES) $(BASEINCLUDES) $(OS_VERSION_DEF) /TP /c
|
||||
CXX_DEBUG_EXE = /MDd /Z7 /Od /D "_DEBUG" /GZ
|
||||
CXX_RELEASE_EXE = /MD /O2 /D "NDEBUG"
|
||||
LINK_ALL_EXE = kernel32.lib user32.lib gdi32.lib winspool.lib \
|
||||
comdlg32.lib advapi32.lib shell32.lib ole32.lib \
|
||||
oleaut32.lib uuid.lib odbc32.lib odbccp32.lib \
|
||||
ws2_32.lib /nologo /subsystem:console /pdb:NONE
|
||||
LINK_DEBUG_EXE = /debug
|
||||
LINK_RELEASE_EXE =
|
||||
|
||||
CC_ALL_LIB = /nologo /D "WIN32" /D "_MBCS" /D "_LIB" /Fo"$(OBJDIR)/"\
|
||||
$(CXXEXTRA) $(CXXEXTRA_LIB) $(CXXINCLUDES) $(CDEVINCLUDES) $(BASEINCLUDES) $(OS_VERSION_DEF) /TC /c
|
||||
CXX_ALL_LIB = /nologo /D "WIN32" /D "_MBCS" /D "_LIB" /Fo"$(OBJDIR)/"\
|
||||
$(CXXEXTRA) $(CXXEXTRA_LIB) $(CXXINCLUDES) $(CDEVINCLUDES) $(BASEINCLUDES) $(OS_VERSION_DEF) /TP /c
|
||||
CXX_DEBUG_LIB = /MDd /Z7 /Od /D "_DEBUG" /GZ
|
||||
CXX_RELEASE_LIB = /MD /O2 /D "NDEBUG"
|
||||
LINK_ALL_LIB = -lib /nologo
|
||||
LINK_DEBUG_LIB =
|
||||
LINK_RELEASE_LIB =
|
||||
|
||||
CC_ALL_DLL = /nologo /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /Fo"$(OBJDIR)/"\
|
||||
$(CXXEXTRA) $(CXXEXTRA_DLL) $(CXXINCLUDES) $(CDEVINCLUDES) $(BASEINCLUDES) $(OS_VERSION_DEF) /TC /c
|
||||
CXX_ALL_DLL = /nologo /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /Fo"$(OBJDIR)/"\
|
||||
$(CXXEXTRA) $(CXXEXTRA_DLL) $(CXXINCLUDES) $(CDEVINCLUDES) $(BASEINCLUDES) $(OS_VERSION_DEF) /TP /c
|
||||
CXX_DEBUG_DLL = /MDd /Z7 /Od /D "_DEBUG" /GZ
|
||||
CXX_RELEASE_DLL = /MD /O2 /D "NDEBUG"
|
||||
LINK_ALL_DLL = kernel32.lib user32.lib gdi32.lib winspool.lib \
|
||||
comdlg32.lib advapi32.lib shell32.lib ole32.lib \
|
||||
oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib \
|
||||
/nologo /dll /pdb:NONE
|
||||
LINK_DEBUG_DLL = /debug
|
||||
LINK_RELEASE_DLL =
|
||||
|
||||
!IF "$(DEBUG)" != ""
|
||||
CC_EXE_FLAGS = $(CC_ALL_EXE) $(CXX_DEBUG_EXE)
|
||||
CC_LIB_FLAGS = $(CC_ALL_LIB) $(CXX_DEBUG_LIB)
|
||||
CC_DLL_FLAGS = $(CC_ALL_DLL) $(CXX_DEBUG_DLL)
|
||||
CXX_EXE_FLAGS = $(CXX_ALL_EXE) $(CXX_DEBUG_EXE)
|
||||
CXX_LIB_FLAGS = $(CXX_ALL_LIB) $(CXX_DEBUG_LIB)
|
||||
CXX_DLL_FLAGS = $(CXX_ALL_DLL) $(CXX_DEBUG_DLL)
|
||||
LINK_EXE_FLAGS = $(LINK_ALL_EXE) $(LINK_DEBUG_EXE)
|
||||
LINK_LIB_FLAGS = $(LINK_ALL_LIB) $(LINK_DEBUG_LIB)
|
||||
LINK_DLL_FLAGS = $(LINK_ALL_DLL) $(LINK_DEBUG_DLL)
|
||||
!ELSE
|
||||
CC_EXE_FLAGS = $(CC_ALL_EXE) $(CXX_RELEASE_EXE)
|
||||
CC_LIB_FLAGS = $(CC_ALL_LIB) $(CXX_RELEASE_LIB)
|
||||
CC_DLL_FLAGS = $(CC_ALL_DLL) $(CXX_RELEASE_DLL)
|
||||
CXX_EXE_FLAGS = $(CXX_ALL_EXE) $(CXX_RELEASE_EXE)
|
||||
CXX_LIB_FLAGS = $(CXX_ALL_LIB) $(CXX_RELEASE_LIB)
|
||||
CXX_DLL_FLAGS = $(CXX_ALL_DLL) $(CXX_RELEASE_DLL)
|
||||
LINK_EXE_FLAGS = $(LINK_ALL_EXE) $(LINK_RELEASE_EXE)
|
||||
LINK_LIB_FLAGS = $(LINK_ALL_LIB) $(LINK_RELEASE_LIB)
|
||||
LINK_DLL_FLAGS = $(LINK_ALL_DLL) $(LINK_RELEASE_DLL)
|
||||
!ENDIF
|
||||
|
||||
!IF "$(HAIL)" != "NO"
|
||||
HAILTARGET = hail
|
||||
!ENDIF
|
||||
|
||||
!IF "$(FAIRWELL)" != "NO"
|
||||
BYETARGET = fairwell
|
||||
!ENDIF
|
||||
|
||||
# ******************************************************************************
|
||||
# * Master rules for building cdevGenericServer objects
|
||||
# ******************************************************************************
|
||||
all : $(HAILTARGET) targets $(BYETARGET)
|
||||
|
||||
hail:
|
||||
@echo ^ ^ ^ =^> Building $(APPNAME) for Target: $(TARGETDIR)
|
||||
|
||||
fairwell:
|
||||
@echo ^ ^ ^ ^ ^ ^ Done...
|
||||
|
||||
clean:
|
||||
!IF "$(HAIL)" != "NO"
|
||||
@echo ^ ^ ^ =^> Cleaning $(APPNAME) for Target: $(TARGETDIR)
|
||||
!ENDIF
|
||||
-@for %x in (.obj\$(TARGET)-$(OS_MAJOR).$(OS_MINOR)-DEBUG \
|
||||
.obj\$(TARGET)-$(OS_MAJOR).$(OS_MINOR) \
|
||||
.shobj\$(TARGET)-$(OS_MAJOR).$(OS_MINOR)-DEBUG \
|
||||
.shobj\$(TARGET)-$(OS_MAJOR).$(OS_MINOR) \
|
||||
.exec\$(TARGET)-$(OS_MAJOR).$(OS_MINOR)-DEBUG \
|
||||
.exec\$(TARGET)-$(OS_MAJOR).$(OS_MINOR)) DO \
|
||||
@if exist %x rmdir /s /q %x
|
||||
-@for %x in ($(BINARIES) $(TARGETS)) DO @if exist %x erase %x
|
||||
!IF "$(FAIRWELL)" != "NO"
|
||||
@echo ^ ^ ^ ^ ^ ^ Done...
|
||||
!ENDIF
|
||||
|
||||
purge:
|
||||
!IF "$(HAIL)" != "NO"
|
||||
@echo ^ ^ ^ =^> Purging $(APPNAME) for Target: $(TARGETDIR)
|
||||
!ENDIF
|
||||
-@for %x in (.shobj .obj .exec) DO @if exist %x rmdir /s /q %x
|
||||
-@for %x in ($(BINARIES) $(TARGETS) $(TEMPLINKS)) DO @if exist %x erase %x
|
||||
!IF "$(FAIRWELL)" != "NO"
|
||||
@echo ^ ^ ^ ^ ^ ^ Done...
|
||||
!ENDIF
|
||||
|
||||
|
||||
.cc{.obj\$(TARGETDIR)}.obj::
|
||||
@echo ^ ^ ^ ^ ^ ^ =^> Compiling $<
|
||||
-@if not exist .obj\$(TARGETDIR) mkdir .obj\$(TARGETDIR)
|
||||
-@if not exist $(BASEBIN) mkdir $(BASEBIN)
|
||||
-@if not exist $(BASELIB) mkdir $(BASELIB)
|
||||
$(CXX) $(CXX_LIB_FLAGS) $<
|
||||
|
||||
.cc{.shobj\$(TARGETDIR)}.obj::
|
||||
@echo ^ ^ ^ ^ ^ ^ =^> Compiling $<
|
||||
-@if not exist .shobj\$(TARGETDIR) mkdir .shobj\$(TARGETDIR)
|
||||
-@if not exist $(BASEBIN) mkdir $(BASEBIN)
|
||||
-@if not exist $(BASELIB) mkdir $(BASELIB)
|
||||
$(CXX) $(CXX_DLL_FLAGS) $<
|
||||
|
||||
.cc{.exec\$(TARGETDIR)}.obj::
|
||||
@echo ^ ^ ^ ^ ^ ^ =^> Compiling $<
|
||||
-@if not exist .exec\$(TARGETDIR) mkdir .exec\$(TARGETDIR)
|
||||
-@if not exist $(BASEBIN) mkdir $(BASEBIN)
|
||||
-@if not exist $(BASELIB) mkdir $(BASELIB)
|
||||
$(CXX) $(CXX_EXE_FLAGS) $<
|
||||
|
||||
.c{.obj\$(TARGETDIR)}.obj::
|
||||
@echo ^ ^ ^ ^ ^ ^ =^> Compiling $<
|
||||
-@if not exist .obj\$(TARGETDIR) mkdir .obj\$(TARGETDIR)
|
||||
-@if not exist $(BASEBIN) mkdir $(BASEBIN)
|
||||
-@if not exist $(BASELIB) mkdir $(BASELIB)
|
||||
$(CC) $(CC_LIB_FLAGS) $<
|
||||
|
||||
.c{.shobj\$(TARGETDIR)}.obj::
|
||||
@echo ^ ^ ^ ^ ^ ^ =^> Compiling $<
|
||||
-@if not exist .shobj\$(TARGETDIR) mkdir .shobj\$(TARGETDIR)
|
||||
-@if not exist $(BASEBIN) mkdir $(BASEBIN)
|
||||
-@if not exist $(BASELIB) mkdir $(BASELIB)
|
||||
$(CC) $(CC_DLL_FLAGS) $<
|
||||
|
||||
.c{.exec\$(TARGETDIR)}.obj::
|
||||
@echo ^ ^ ^ ^ ^ ^ =^> Compiling $<
|
||||
-@if not exist .exec\$(TARGETDIR) mkdir .exec\$(TARGETDIR)
|
||||
-@if not exist $(BASEBIN) mkdir $(BASEBIN)
|
||||
-@if not exist $(BASELIB) mkdir $(BASELIB)
|
||||
$(CC) $(CC_EXE_FLAGS) $<
|
||||
68
extensions/cdevGenericServer/include/makeinclude/Makefile.aix
Executable file
68
extensions/cdevGenericServer/include/makeinclude/Makefile.aix
Executable file
@@ -0,0 +1,68 @@
|
||||
# ******************************************************************************
|
||||
# * Makefile.aix : This is the platform specific Makefile for aix.
|
||||
# *
|
||||
# * Externals : This Makefile relies on the developer defining the
|
||||
# * following external definitions...
|
||||
# *
|
||||
# * CDEV : The base directory of the CDEV distribution
|
||||
# ******************************************************************************
|
||||
TARGET = aix
|
||||
OS_MAJOR := $(shell uname -v)
|
||||
OS_MAJOR_NUM := $(shell awk 'BEGIN {VAL=$(OS_MAJOR); print VAL; exit; }')
|
||||
OS_MINOR := $(shell uname -r)
|
||||
OS_MINOR_NUM := $(shell awk 'BEGIN {VAL=$(OS_MINOR); print VAL; exit; }')
|
||||
OS_VERSION_DEF := -D_OS_MAJOR_=$(OS_MAJOR_NUM) -D_OS_MINOR_=$(OS_MINOR_NUM)
|
||||
|
||||
include $(CDEV)/extensions/cdevGenericServer/include/makeinclude/Makefile.common
|
||||
|
||||
# ******************************************************************************
|
||||
# * Platform specific compile and link options.
|
||||
# ******************************************************************************
|
||||
|
||||
# ******************************************************************************
|
||||
# * Only specify the DEBUGFLAG if the DEBUG variable has been set.
|
||||
# ******************************************************************************
|
||||
ifdef DEBUG
|
||||
DEBUGFLAG = -g
|
||||
endif
|
||||
|
||||
CXX = xlC
|
||||
CC = xlC
|
||||
CXXFLAGS = $(CXXEXTRA) $(CXXINCLUDES) $(CDEVINCLUDES) \
|
||||
$(BASEINCLUDES) $(OS_VERSION_DEF) $(DEBUGFLAG) -DAIX -qNOro
|
||||
CFLAGS = $(CCEXTRA) $(CXXINCLUDES) $(CDEVINCLUDES) \
|
||||
$(BASEINCLUDES) $(OS_VERSION_DEF) $(DEBUGFLAG) -DAIX -qNOro
|
||||
AR = ar
|
||||
ARFLAGS = ruv
|
||||
RANLIB = true
|
||||
OSLIBS = -L/lib -lm
|
||||
|
||||
# ******************************************************************************
|
||||
# * Platform specific compile and link macros.
|
||||
# ******************************************************************************
|
||||
COMPILE.cc = $(QUIET)$(CXX_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) -c $(CXXFLAGS) $^ -o $@
|
||||
COMPILE.cc.so = $(QUIET)$(CXX_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
@echo "Shared objects not supported on AIX"
|
||||
COMPILE.c = $(QUIET)$(CC_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CC) -c $(CFLAGS) $^ -o $@
|
||||
COMPILE.c.so = $(QUIET)$(CC_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
@echo "Shared objects not supported on AIX"
|
||||
LINK.cc = $(QUIET)$(LINK_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) $(CXXFLAGS)
|
||||
LINK.a = $(QUIET)$(AR_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(AR) $(ARFLAGS)
|
||||
|
||||
|
||||
#Note on the -qNOro option
|
||||
|
||||
# The AIX compiler by default allocates memory for string literals in the
|
||||
# read only area. As result, CLIP clients crash with segmentation fault
|
||||
# when cdevClientRequestObj cleans up constant message strings passed by
|
||||
# the user (in the code below "message" points directly to the user string)
|
||||
123
extensions/cdevGenericServer/include/makeinclude/Makefile.common
Executable file
123
extensions/cdevGenericServer/include/makeinclude/Makefile.common
Executable file
@@ -0,0 +1,123 @@
|
||||
# ******************************************************************************
|
||||
# * Makefile.common : This is the community makefile for the cdevGenericServer
|
||||
# * distribution. It contains the definitions that are common
|
||||
# * for all Makefiles in this distribution.
|
||||
# *
|
||||
# * Externals : This Makefile relies on the developer defining the
|
||||
# * following external definitions...
|
||||
# *
|
||||
# * CDEV : The base directory of the CDEV distribution
|
||||
# * CDEVVERSION : The version of cdev being used
|
||||
# * TARGET : The name of the target platform
|
||||
# * OS_MAJOR : The major version number of the target OS
|
||||
# ******************************************************************************
|
||||
ifdef OS_MAJOR
|
||||
TARGETDIR = $(TARGET)-$(OS_MAJOR).$(OS_MINOR)
|
||||
else
|
||||
TARGETDIR = $(TARGET)
|
||||
endif
|
||||
|
||||
CDEVVERSION = 1.7.2
|
||||
CDEVINCLUDES = -I$(CDEV)/include
|
||||
CDEVLIB = $(CDEV)/lib/$(TARGETDIR)
|
||||
CDEVBIN = $(CDEV)/bin/$(TARGETDIR)
|
||||
|
||||
BASEDIR = $(CDEV)/extensions/cdevGenericServer
|
||||
BASEINCLUDES = -I$(BASEDIR)/include
|
||||
BASELIB = $(BASEDIR)/lib/$(TARGETDIR)
|
||||
BASEBIN = $(BASEDIR)/bin/$(TARGETDIR)
|
||||
|
||||
# ******************************************************************************
|
||||
# * This is the compressed command echo mechanism
|
||||
# ******************************************************************************
|
||||
ifeq ("$(VERBOSE)", "")
|
||||
VERBOSE = NO
|
||||
MAKE := $(MAKE) -s VERBOSE=NO
|
||||
endif
|
||||
|
||||
ifeq ("$(VERBOSE)", "NO")
|
||||
QUIET = @
|
||||
CXX_CMD_ECHO = @echo " => $(CXX) -c $(<F) -o $(@F)";
|
||||
CC_CMD_ECHO = @echo " => $(CC) -c $(<F) -o $(@F)";
|
||||
AR_CMD_ECHO = @echo " => $(AR) $(@F)";
|
||||
SO_CMD_ECHO = @echo " => $(DLD) -o $(@F)";
|
||||
LINK_CMD_ECHO = @echo " => $(CXX) -o $(@F)";
|
||||
COPY_CMD_ECHO = @echo " => Copying $(@F) to $^";
|
||||
LEX_CMD_ECHO = @echo " => lex -o $(@F) $(^F)";
|
||||
YACC_CMD_ECHO = @echo " => yacc -o $(@F) $(^F)";
|
||||
else
|
||||
EMPTY_ECHO =
|
||||
CXX_CMD_ECHO = $(EMPTY_ECHO)
|
||||
CC_CMD_ECHO = $(EMPTY_ECHO)
|
||||
AR_CMD_ECHO = $(EMPTY_ECHO)
|
||||
SO_CMD_ECHO = $(EMPTY_ECHO)
|
||||
LINK_CMD_ECHO = $(EMPTY_ECHO)
|
||||
COPY_CMD_ECHO = $(EMPTY_ECHO)
|
||||
LEX_CMD_ECHO = $(EMPTY_ECHO)
|
||||
YACC_CMD_ECHO = $(EMPTY_ECHO)
|
||||
endif
|
||||
|
||||
# ******************************************************************************
|
||||
# * Set the CDEV shared object directory to a default location if not specified.
|
||||
# ******************************************************************************
|
||||
ifeq ($(CDEVSHOBJ), )
|
||||
CDEVSHOBJ = $(CDEVLIB)
|
||||
endif
|
||||
|
||||
|
||||
# ******************************************************************************
|
||||
# * Set the object directory appropriately to the SHOBJ flag (default YES)
|
||||
# ******************************************************************************
|
||||
ifeq ($(SHOBJ), NO)
|
||||
OBJDIR = .obj/$(TARGETDIR)
|
||||
else
|
||||
SHOBJ = YES
|
||||
OBJDIR = .shobj/$(TARGETDIR)
|
||||
endif
|
||||
|
||||
|
||||
# ******************************************************************************
|
||||
# * Rule for compiling archive C++ files.
|
||||
# ******************************************************************************
|
||||
.obj/$(TARGETDIR)/%.o : %.cc
|
||||
$(COMPILE.cc)
|
||||
|
||||
|
||||
# ******************************************************************************
|
||||
# * Rule for compiling shared C++ files.
|
||||
# ******************************************************************************
|
||||
.shobj/$(TARGETDIR)/%.o : %.cc
|
||||
$(COMPILE.cc.so)
|
||||
|
||||
# ******************************************************************************
|
||||
# * Rule for compiling archive C files.
|
||||
# ******************************************************************************
|
||||
.obj/$(TARGETDIR)/%.o : %.c
|
||||
$(COMPILE.c)
|
||||
|
||||
|
||||
# ******************************************************************************
|
||||
# * Rule for compiling shared C files.
|
||||
# ******************************************************************************
|
||||
.shobj/$(TARGETDIR)/%.o : %.c
|
||||
$(COMPILE.c.so)
|
||||
|
||||
# ******************************************************************************
|
||||
# * Generic rules for makefiles.
|
||||
# ******************************************************************************
|
||||
all: hail targets fairwell
|
||||
|
||||
hail:
|
||||
@echo " => Building [$(TARGETDIR)] in $(APPNAME)"
|
||||
|
||||
fairwell:
|
||||
@echo " Done..."
|
||||
|
||||
clean:
|
||||
@echo " => Cleaning [$(TARGETDIR)] in $(APPNAME)"
|
||||
@rm -rf .o .a core .obj/$(TARGETDIR) .shobj/$(TARGETDIR) *.?.? TC.Cache $(BINARIES) $(TARGETS) ./ptrepository
|
||||
@echo " Done..."
|
||||
purge:
|
||||
@echo " => Purging [All] in $(APPNAME)"
|
||||
@rm -rf .shobj .obj .exec $(BINARIES) $(TARGETS) $(TEMPLINKS) .o .a core *.?.? TC.Cache ./ptrepository
|
||||
@echo " Done..."
|
||||
131
extensions/cdevGenericServer/include/makeinclude/Makefile.hpux
Executable file
131
extensions/cdevGenericServer/include/makeinclude/Makefile.hpux
Executable file
@@ -0,0 +1,131 @@
|
||||
# ******************************************************************************
|
||||
# * Makefile.hpux : This is the platform specific Makefile for HPUX.
|
||||
# *
|
||||
# * Externals : This Makefile relies on the developer defining the
|
||||
# * following external definitions...
|
||||
# *
|
||||
# * CDEV : The base directory of the CDEV distribution
|
||||
# ******************************************************************************
|
||||
TARGET = hpux
|
||||
OS_MAJOR := $(shell uname -r | awk -F "." '{print $$2; exit}')
|
||||
OS_MAJOR_NUM := $(shell awk 'BEGIN {VAL=$(OS_MAJOR); print VAL; exit; }')
|
||||
OS_MINOR := $(shell uname -r | awk -F "." '{print $$3; exit}')
|
||||
OS_MINOR_NUM := $(shell awk 'BEGIN {VAL=$(OS_MINOR); print VAL; exit; }')
|
||||
OS_VERSION_DEF := -D_OS_MAJOR_=$(OS_MAJOR_NUM) -D_OS_MINOR_=$(OS_MINOR_NUM)
|
||||
|
||||
include $(CDEV)/extensions/cdevGenericServer/include/makeinclude/Makefile.common
|
||||
include $(CDEV)/include/makeinclude/Makefile.archive
|
||||
|
||||
# ******************************************************************************
|
||||
# * Due to a change in the operating system, the CXX compiler for HP-UX may
|
||||
# * be different depending on which platform is used.
|
||||
# ******************************************************************************
|
||||
ifeq ($(OS_MAJOR), 09)
|
||||
CXX := /usr/bin/CC
|
||||
HP_FLAGS = -Aa -pta -ptb -D_SELECT_USES_INT_
|
||||
endif
|
||||
|
||||
ifeq ($(OS_MAJOR).$(OS_MINOR), 10.10)
|
||||
CXX := /opt/CC/bin/CC
|
||||
HP_FLAGS = -Aa -pta -ptb -Dvolatile=""
|
||||
NETLIBS = -lxti
|
||||
endif
|
||||
|
||||
ifeq ($(OS_MAJOR).$(OS_MINOR), 10.20)
|
||||
CXX := /opt/aCC/bin/aCC
|
||||
HP_FLAGS = +W302,749,829
|
||||
NETLIBS = -lxti
|
||||
endif
|
||||
|
||||
# ******************************************************************************
|
||||
# * Platform specific compile and link options.
|
||||
# ******************************************************************************
|
||||
|
||||
# ******************************************************************************
|
||||
# * Only specify the DEBUGFLAG if the DEBUG variable has been set.
|
||||
# ******************************************************************************
|
||||
ifdef DEBUG
|
||||
DEBUGFLAG = -g
|
||||
else
|
||||
DEBUGFLAG = +O2
|
||||
endif
|
||||
|
||||
CC = cc
|
||||
CXXFLAGS = -z $(CXXEXTRA) $(CXXINCLUDES) $(CDEVINCLUDES) \
|
||||
$(BASEINCLUDES) $(OS_VERSION_DEF) $(DEBUGFLAG) $(HP_FLAGS) -DSYSV
|
||||
CFLAGS = -Aa $(CCEXTRA) $(CXXINCLUDES) $(CDEVINCLUDES) \
|
||||
$(BASEINCLUDES) $(OS_VERSION_DEF) $(DEBUGFLAG) -DSYSV
|
||||
LDFLAGS = -L$(CDEVLIB) -Wl,+s
|
||||
AR = ar
|
||||
ARFLAGS = ruv
|
||||
RANLIB = true
|
||||
DLD = $(CXX)
|
||||
SOFLAGS = -b -Wl,+s
|
||||
PIC = +z
|
||||
SHARED_EXT = sl
|
||||
OSLIBS = -L/lib -lm
|
||||
|
||||
|
||||
# ******************************************************************************
|
||||
# * These definitions define the names and locations of libraries that are
|
||||
# * required by CDEV for a shared and archive applications. The developer
|
||||
# * is required to add the list of service specific libraries.
|
||||
# ******************************************************************************
|
||||
ifeq ($(SHOBJ), NO)
|
||||
CDEVLIBS = $(CDEVLIB)/libcdev.a $(ARCHIVELIBS)
|
||||
else
|
||||
CDEVLIBS = -L$(CDEVLIB) -lcdev
|
||||
endif
|
||||
|
||||
|
||||
# ******************************************************************************
|
||||
# * Platform specific compile and link macros.
|
||||
# ******************************************************************************
|
||||
COMPILE.cc = $(QUIET)$(CXX_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(PURIFY) $(CXX) -c $(CXXFLAGS) $^ -o $@
|
||||
COMPILE.cc.so = $(QUIET)$(CXX_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(PURIFY) $(CXX) -c $(CXXFLAGS) $(PIC) $^ -o $@
|
||||
COMPILE.c = $(QUIET)$(CC_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CC) -c $(CFLAGS) $^ -o $@
|
||||
COMPILE.c.so = $(QUIET)$(CC_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CC) -c $(CFLAGS) $(PIC) $^ -o $@
|
||||
LINK.cc = $(QUIET)$(LINK_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(PURIFY) $(CXX) $(CXXFLAGS)
|
||||
LINK.a = $(QUIET)$(AR_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(AR) $(ARFLAGS)
|
||||
LINK.so = $(QUIET)$(SO_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(PURIFY) $(DLD) $(SOFLAGS)
|
||||
|
||||
# ******************************************************************************
|
||||
# * This is the macro to build a shared object/library.... it requires the
|
||||
# * following variables to be defined...
|
||||
# *
|
||||
# * SO_SRCS : Names of the component source files
|
||||
# * SO_LIBS : Names of the dependent libraries
|
||||
# * LIBS : All libraries necessary to compile the dummy application
|
||||
# ******************************************************************************
|
||||
SOBUILD = rm -f $@;\
|
||||
mkdir -p $(@D);\
|
||||
echo "=> Building shared object $(@F)";\
|
||||
echo " => Instanciating templates for $(@F)";\
|
||||
echo "int main() {return 0;}" >dummy.cc;\
|
||||
$(CXX) -c $(CXXFLAGS) $(PIC) dummy.cc $(SO_SRCS) $(LDFLAGS) -ptr./pt$(@F) -ptr./ptrepository $(LIBS);\
|
||||
rm -rf a.out dummy.*;\
|
||||
if test -f ./pt$(@F)/*.o;\
|
||||
then\
|
||||
echo " => Linking $(@F) from objects and template objects";\
|
||||
$(LINK.so) -o $@ $^ ./pt$(@F)/*.o $(SO_LIBS);\
|
||||
else\
|
||||
echo " => Linking $(@F) from objects";\
|
||||
$(LINK.so) -o $@ $^ $(SO_LIBS);\
|
||||
fi;\
|
||||
rm -rf *.o ./pt$(@F)
|
||||
|
||||
|
||||
121
extensions/cdevGenericServer/include/makeinclude/Makefile.hpux-cl
Executable file
121
extensions/cdevGenericServer/include/makeinclude/Makefile.hpux-cl
Executable file
@@ -0,0 +1,121 @@
|
||||
# ******************************************************************************
|
||||
# * Makefile.hpux-cl: This is the platform specific Makefile for HPUX using
|
||||
# * the CenterLine C++ compiler.
|
||||
# *
|
||||
# * Externals : This Makefile relies on the developer defining the
|
||||
# * following external definitions...
|
||||
# *
|
||||
# * CDEV : The base directory of the CDEV distribution
|
||||
# ******************************************************************************
|
||||
TARGET = hpux-cl
|
||||
SHOBJ = NO
|
||||
OS_MAJOR := $(shell uname -r | awk -F "." '{print $$2; exit}')
|
||||
OS_MAJOR_NUM := $(shell awk 'BEGIN {VAL=$(OS_MAJOR); print VAL; exit; }')
|
||||
OS_MINOR := $(shell uname -r | awk -F "." '{print $$3; exit}')
|
||||
OS_MINOR_NUM := $(shell awk 'BEGIN {VAL=$(OS_MINOR); print VAL; exit; }')
|
||||
OS_VERSION_DEF := -D_OS_MAJOR_=$(OS_MAJOR_NUM) -D_OS_MINOR_=$(OS_MINOR_NUM)
|
||||
|
||||
include $(CDEV)/extensions/cdevGenericServer/include/makeinclude/Makefile.common
|
||||
include $(CDEV)/include/makeinclude/Makefile.archive
|
||||
|
||||
ifeq ($(OS_MAJOR_NUM), 9)
|
||||
HP_FLAGS = -D_SELECT_USES_INT_
|
||||
endif
|
||||
|
||||
ifeq ($(OS_MAJOR_NUM), 10)
|
||||
HP_FLAGS = -Dvolatile=""
|
||||
NETLIBS = -lxti
|
||||
endif
|
||||
|
||||
# ******************************************************************************
|
||||
# * Platform specific compile and link options.
|
||||
# ******************************************************************************
|
||||
|
||||
# ******************************************************************************
|
||||
# * Only specify the DEBUGFLAG if the DEBUG variable has been set.
|
||||
# ******************************************************************************
|
||||
ifdef DEBUG
|
||||
DEBUGFLAG = -g
|
||||
endif
|
||||
|
||||
CXX = /usr/csite4/CenterLine/bin/CC
|
||||
CC = cc
|
||||
CXXFLAGS = -z -pta -D__CENTERLINE__ $(CXXEXTRA) $(CXXINCLUDES) $(CDEVINCLUDES) \
|
||||
$(BASEINCLUDES) $(OS_VERSION_DEF) $(DEBUGFLAG) $(HP_FLAGS) -DSYSV
|
||||
CFLAGS = -Aa $(CCEXTRA) $(CXXINCLUDES) $(CDEVINCLUDES) \
|
||||
$(BASEINCLUDES) $(OS_VERSION_DEF) $(DEBUGFLAG) -DSYSV
|
||||
LDFLAGS = -Wl,+s
|
||||
AR = ar
|
||||
ARFLAGS = ruv
|
||||
RANLIB = true
|
||||
DLD = $(CXX)
|
||||
SOFLAGS = -b
|
||||
PIC =
|
||||
SHARED_EXT = sl
|
||||
OSLIBS = -lm
|
||||
|
||||
|
||||
# ******************************************************************************
|
||||
# * These definitions define the names and locations of libraries that are
|
||||
# * required by CDEV for a shared and archive applications. The developer
|
||||
# * is required to add the list of service specific libraries.
|
||||
# ******************************************************************************
|
||||
ifeq ($(SHOBJ), NO)
|
||||
CDEVLIBS = $(CDEVLIB)/libcdev.a $(ARCHIVELIBS)
|
||||
else
|
||||
CDEVLIBS = -L$(CDEVLIB) -lcdev
|
||||
endif
|
||||
|
||||
|
||||
# ******************************************************************************
|
||||
# * Platform specific compile and link macros.
|
||||
# ******************************************************************************
|
||||
COMPILE.cc = $(QUIET)$(CXX_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) -c $(CXXFLAGS) $^ -o $@
|
||||
COMPILE.cc.so = $(QUIET)$(CXX_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) -c $(CXXFLAGS) $(PIC) $^ -o $@
|
||||
COMPILE.c = $(QUIET)$(CC_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CC) -c $(CFLAGS) $^ -o $@
|
||||
COMPILE.c.so = $(QUIET)$(CC_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CC) -c $(CFLAGS) $(PIC) $^ -o $@
|
||||
LINK.cc = $(QUIET)$(LINK_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(PROOF) $(CXX) $(CXXFLAGS)
|
||||
LINK.a = $(QUIET)$(AR_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(AR) $(ARFLAGS)
|
||||
LINK.so = $(QUIET)$(SO_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(DLD) $(SOFLAGS)
|
||||
|
||||
|
||||
# ******************************************************************************
|
||||
# * This is the macro to build a shared object/library.... it requires the
|
||||
# * following variables to be defined...
|
||||
# *
|
||||
# * SO_SRCS : Names of the component source files
|
||||
# * SO_LIBS : Names of the dependent libraries
|
||||
# * LIBS : All libraries necessary to compile the dummy application
|
||||
# ******************************************************************************
|
||||
SOBUILD = rm -f $@;\
|
||||
mkdir -p $(@D);\
|
||||
echo "=> Building shared object $(@F)";\
|
||||
echo " => Instanciating templates for $(@F)";\
|
||||
echo "int main() {return 0;}" >dummy.cc;\
|
||||
$(CXX) -c $(CXXFLAGS) $(PIC) dummy.cc $(SO_SRCS) $(LDFLAGS) -ptr./pt$(@F) -ptr./ptrepository $(SO_LIBS);\
|
||||
rm -rf a.out dummy.*;\
|
||||
if test -f ./pt$(@F)/*.o;\
|
||||
then\
|
||||
echo " => Linking $(@F) from objects and template objects";\
|
||||
$(LINK.so) -o $@ $^ ./pt$(@F)/*.o $(LIBS);\
|
||||
else\
|
||||
echo " => Linking $(@F) from objects";\
|
||||
$(LINK.so) -o $@ $^ $(SO_LIBS);\
|
||||
fi;\
|
||||
rm -rf *.o ./pt$(@F)
|
||||
|
||||
|
||||
148
extensions/cdevGenericServer/include/makeinclude/Makefile.lib
Executable file
148
extensions/cdevGenericServer/include/makeinclude/Makefile.lib
Executable file
@@ -0,0 +1,148 @@
|
||||
ARCH = OS
|
||||
SHOBJ = YES
|
||||
|
||||
#include ../include/makeinclude/Makefile.$(ARCH)
|
||||
include ../include/makeinclude/Makefile.linux
|
||||
|
||||
APPNAME = "CDEV Generic Client/Server Engine"
|
||||
TEMPLINKS = ClientAcceptor.cc\
|
||||
ClientHandler.cc\
|
||||
cdevServer.cc\
|
||||
cdevServerTools.cc\
|
||||
cdevSessionManager.cc\
|
||||
ServerInterface.cc\
|
||||
ServerHandler.cc\
|
||||
cdevClientRequestObject.cc\
|
||||
cdevClientService.cc\
|
||||
cdevMessage.cc\
|
||||
cdevMessageBinary.cc\
|
||||
cdevPacket.cc\
|
||||
cdevContextMap.cc\
|
||||
cdevMonitorTable.cc\
|
||||
cdevTagMap.cc\
|
||||
SignalManager.cc\
|
||||
cdevAddr.cc\
|
||||
cdevEventHandler.cc\
|
||||
cdevHandleSet.cc\
|
||||
cdevReactor.cc\
|
||||
cdevSocket.cc\
|
||||
cdevSocketAcceptor.cc\
|
||||
cdevSocketConnector.cc\
|
||||
cdevSocketDatagram.cc\
|
||||
cdevSocketStream.cc\
|
||||
cdevStreamNode.cc\
|
||||
cdevStreamQueue.cc\
|
||||
cdevTime.cc\
|
||||
fifo.cc\
|
||||
IntHash.cc
|
||||
|
||||
|
||||
LIBS = $(CDEVLIBS) $(OSLIBS)
|
||||
|
||||
SERVER_OBJS = $(OBJDIR)/cdevServer.o\
|
||||
$(OBJDIR)/cdevServerTools.o\
|
||||
$(OBJDIR)/cdevSessionManager.o\
|
||||
$(OBJDIR)/ClientHandler.o\
|
||||
$(OBJDIR)/ClientAcceptor.o\
|
||||
$(OBJDIR)/cdevTagMap.o\
|
||||
$(OBJDIR)/cdevMonitorTable.o
|
||||
|
||||
CLIENT_OBJS = $(OBJDIR)/cdevClientService.o\
|
||||
$(OBJDIR)/cdevClientRequestObject.o\
|
||||
$(OBJDIR)/ServerInterface.o\
|
||||
$(OBJDIR)/ServerHandler.o
|
||||
|
||||
COMMON_OBJS = $(OBJDIR)/cdevPacket.o\
|
||||
$(OBJDIR)/cdevMessageBinary.o\
|
||||
$(OBJDIR)/cdevMessage.o\
|
||||
$(OBJDIR)/cdevContextMap.o\
|
||||
$(OBJDIR)/SignalManager.o\
|
||||
$(OBJDIR)/fifo.o\
|
||||
$(OBJDIR)/IntHash.o
|
||||
|
||||
ACE_OBJS = $(OBJDIR)/cdevAddr.o\
|
||||
$(OBJDIR)/cdevEventHandler.o\
|
||||
$(OBJDIR)/cdevHandleSet.o\
|
||||
$(OBJDIR)/cdevReactor.o\
|
||||
$(OBJDIR)/cdevSocket.o\
|
||||
$(OBJDIR)/cdevSocketAcceptor.o\
|
||||
$(OBJDIR)/cdevSocketConnector.o\
|
||||
$(OBJDIR)/cdevSocketDatagram.o\
|
||||
$(OBJDIR)/cdevSocketStream.o\
|
||||
$(OBJDIR)/cdevStreamNode.o\
|
||||
$(OBJDIR)/cdevStreamQueue.o\
|
||||
$(OBJDIR)/cdevTime.o
|
||||
|
||||
OBJS = $(SERVER_OBJS) $(CLIENT_OBJS) $(COMMON_OBJS) $(ACE_OBJS)
|
||||
|
||||
# ******************************************************************************
|
||||
# * The BINARIES definition names all of the binary files that should be deleted
|
||||
# * whenever "make clean" is executed.
|
||||
# ******************************************************************************
|
||||
BINARIES = $(CDEVLIB)/libcdevGenericServer.$(SHARED_EXT) \
|
||||
$(CDEVLIB)/libcdevGenericServer.a
|
||||
|
||||
ifeq ($(SHOBJ),YES)
|
||||
TARGETS = $(TEMPLINKS) \
|
||||
$(CDEVLIB)/libcdevGenericServer.$(SHARED_EXT)
|
||||
else
|
||||
TARGETS = $(TEMPLINKS) \
|
||||
$(CDEVLIB)/libcdevGenericServer.a
|
||||
endif
|
||||
|
||||
targets : $(TARGETS)
|
||||
|
||||
$(TEMPLINKS) :
|
||||
@cp $^ $@
|
||||
|
||||
$(CDEVLIB)/libcdevGenericServer.a : $(OBJS)
|
||||
$(LINK.a) $@ $^
|
||||
@$(RANLIB) $@ > /dev/null
|
||||
|
||||
$(CDEVLIB)/libcdevGenericServer.$(SHARED_EXT) : $(OBJS)
|
||||
$(LINK.so) -o $@ $^ -L$(CDEVLIB) -lrsvc $(NETLIBS)
|
||||
|
||||
$(CDEVLIB)/libcdevServer.a : $(SERVER_OBJS) $(COMMON_OBJS) $(ACE_OBJS)
|
||||
$(LINK.a) $@ $^
|
||||
@$(RANLIB) $@ > /dev/null
|
||||
|
||||
$(CDEVLIB)/libcdevServer.$(SHARED_EXT) : $(SERVER_OBJS) $(COMMON_OBJS) $(ACE_OBJS)
|
||||
$(LINK.so) -o $@ $^ -L$(CDEVLIB) -lrsvc $(NETLIBS)
|
||||
|
||||
$(CDEVLIB)/libcdevClient.a : $(CLIENT_OBJS) $(COMMON_OBJS) $(ACE_OBJS)
|
||||
$(LINK.a) $@ $^
|
||||
@$(RANLIB) $@ > /dev/null
|
||||
|
||||
$(CDEVLIB)/libcdevClient.$(SHARED_EXT) : $(CLIENT_OBJS) $(COMMON_OBJS) $(ACE_OBJS)
|
||||
$(LINK.so) -o $@ $^ -L$(CDEVLIB) -lrsvc $(NETLIBS)
|
||||
|
||||
ClientAcceptor.cc : ../cdevServer/ClientAcceptor.cc
|
||||
ClientHandler.cc : ../cdevServer/ClientHandler.cc
|
||||
cdevServer.cc : ../cdevServer/cdevServer.cc
|
||||
cdevServerTools.cc : ../cdevServer/cdevServerTools.cc
|
||||
cdevSessionManager.cc : ../cdevServer/cdevSessionManager.cc
|
||||
ServerHandler.cc : ../cdevClient/ServerHandler.cc
|
||||
ServerInterface.cc : ../cdevClient/ServerInterface.cc
|
||||
cdevClientRequestObject.cc : ../cdevClient/cdevClientRequestObject.cc
|
||||
cdevClientService.cc : ../cdevClient/cdevClientService.cc
|
||||
cdevMessage.cc : ../cdevPacket/cdevMessage.cc
|
||||
cdevMessageBinary.cc : ../cdevPacket/cdevMessageBinary.cc
|
||||
cdevPacket.cc : ../cdevPacket/cdevPacket.cc
|
||||
cdevContextMap.cc : ../cdevContextMap/cdevContextMap.cc
|
||||
cdevMonitorTable.cc : ../cdevMonitorTable/cdevMonitorTable.cc
|
||||
cdevTagMap.cc : ../cdevTagMap/cdevTagMap.cc
|
||||
SignalManager.cc : ../common/SignalManager.cc
|
||||
cdevAddr.cc : ../cdevReactor/cdevAddr.cc
|
||||
cdevEventHandler.cc : ../cdevReactor/cdevEventHandler.cc
|
||||
cdevHandleSet.cc : ../cdevReactor/cdevHandleSet.cc
|
||||
cdevReactor.cc : ../cdevReactor/cdevReactor.cc
|
||||
cdevSocket.cc : ../cdevReactor/cdevSocket.cc
|
||||
cdevSocketAcceptor.cc : ../cdevReactor/cdevSocketAcceptor.cc
|
||||
cdevSocketConnector.cc : ../cdevReactor/cdevSocketConnector.cc
|
||||
cdevSocketDatagram.cc : ../cdevReactor/cdevSocketDatagram.cc
|
||||
cdevSocketStream.cc : ../cdevReactor/cdevSocketStream.cc
|
||||
cdevStreamNode.cc : ../cdevReactor/cdevStreamNode.cc
|
||||
cdevStreamQueue.cc : ../cdevReactor/cdevStreamQueue.cc
|
||||
cdevTime.cc : ../cdevReactor/cdevTime.cc
|
||||
fifo.cc : ../common/fifo.cc
|
||||
IntHash.cc : ../common/IntHash.cc
|
||||
@@ -0,0 +1,94 @@
|
||||
# ******************************************************************************
|
||||
# * Makefile.Linux : This is the platform specific Makefile for Linux.
|
||||
# *
|
||||
# * Externals : This Makefile relies on the developer defining the
|
||||
# * following external definitions...
|
||||
# *
|
||||
# * CDEV : The base directory of the CDEV distribution
|
||||
# ******************************************************************************
|
||||
TARGET = Linux
|
||||
|
||||
include $(CDEV)/extensions/cdevGenericServer/include/makeinclude/Makefile.common
|
||||
include $(CDEV)/include/makeinclude/Makefile.archive
|
||||
|
||||
# ******************************************************************************
|
||||
# * Platform specific compile and link options.
|
||||
# ******************************************************************************
|
||||
|
||||
# ******************************************************************************
|
||||
# * Only specify the DEBUGFLAG if the DEBUG variable has been set.
|
||||
# ******************************************************************************
|
||||
ifdef DEBUG
|
||||
DEBUGFLAG = -g
|
||||
else
|
||||
DEBUGFLAG = -O2
|
||||
endif
|
||||
|
||||
CXX = g++
|
||||
CC = gcc
|
||||
CXXFLAGS = -DLinux -DCDEV_HAS_UNDERSCORE_FDBITS -fno-for-scope $(DEBUGFLAG) $(CXXEXTRA) $(CXXINCLUDES) \
|
||||
$(CDEVINCLUDES) $(BASEINCLUDES)
|
||||
CFLAGS = -DLinux -DCDEV_HAS_UNDERSCORE_FDBITS $(DEBUGFLAG) $(CEXTRA) $(CXXINCLUDES) $(CDEVINCLUDES) $(BASEINCLUDES)
|
||||
AR = ar
|
||||
ARFLAGS = ruv
|
||||
RANLIB = ranlib
|
||||
DLD = $(CXX)
|
||||
SOFLAGS = -shared
|
||||
PIC = -fpic
|
||||
SHARED_EXT = so
|
||||
NETLIBS =
|
||||
OSLIBS = $(NETLIBS) -lm -ldl
|
||||
|
||||
|
||||
# ******************************************************************************
|
||||
# * These definitions define the names and locations of libraries that are
|
||||
# * required by CDEV for a shared and archive applications. The developer
|
||||
# * is required to add the list of service specific libraries.
|
||||
# ******************************************************************************
|
||||
ifeq ($(SHOBJ), NO)
|
||||
CDEVLIBS = $(CDEVLIB)/libcdev.a $(ARCHIVELIBS)
|
||||
else
|
||||
CDEVLIBS = -L$(CDEVLIB) -lcdev
|
||||
endif
|
||||
|
||||
|
||||
# ******************************************************************************
|
||||
# * Platform specific compile and link macros.
|
||||
# ******************************************************************************
|
||||
COMPILE.cc = $(QUIET)$(CXX_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) -c $(CXXFLAGS) $^ -o $@
|
||||
COMPILE.cc.so = $(QUIET)$(CXX_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) $(CXXFLAGS) $(PIC) -c -o $@ $^
|
||||
COMPILE.c = $(QUIET)$(CC_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CC) -c $(CFLAGS) $^ -o $@
|
||||
COMPILE.c.so = $(QUIET)$(CC_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CC) -c $(CFLAGS) $(PIC) $^ -o $@
|
||||
LINK.cc = $(QUIET)$(LINK_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) $(CXXFLAGS)
|
||||
#$(CXX) $(CXXFLAGS) -Xlinker -rpath -Xlinker $(BASELIB) -Xlinker -rpath -Xlinker $(CDEVLIB)
|
||||
LINK.a = $(QUIET)$(AR_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(AR) $(ARFLAGS)
|
||||
LINK.so = $(QUIET)$(SO_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(DLD) $(SOFLAGS)
|
||||
|
||||
# ******************************************************************************
|
||||
# * This is the macro to build a shared object/library.... it requires the
|
||||
# * following variables to be defined...
|
||||
# *
|
||||
# * SO_SRCS : Names of the component source files
|
||||
# * SO_LIBS : Names of the dependent libraries
|
||||
# * LIBS : All libraries necessary to compile the dummy application
|
||||
# ******************************************************************************
|
||||
SOBUILD = rm -f $@;\
|
||||
mkdir -p $(@D);\
|
||||
echo "=> Building shared object $(@F)";\
|
||||
$(LINK.so) -o $@ $^ -R $(CDEVLIB) -L$(CDEVLIB) -L./ $(NETLIBS)
|
||||
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
# ******************************************************************************
|
||||
# * Makefile.Linux : This is the platform specific Makefile for Linux.
|
||||
# *
|
||||
# * Externals : This Makefile relies on the developer defining the
|
||||
# * following external definitions...
|
||||
# *
|
||||
# * CDEV : The base directory of the CDEV distribution
|
||||
# ******************************************************************************
|
||||
TARGET = Linux
|
||||
|
||||
include $(CDEV)/extensions/cdevGenericServer/include/makeinclude/Makefile.common
|
||||
include $(CDEV)/include/makeinclude/Makefile.archive
|
||||
|
||||
# ******************************************************************************
|
||||
# * Platform specific compile and link options.
|
||||
# ******************************************************************************
|
||||
|
||||
# ******************************************************************************
|
||||
# * Only specify the DEBUGFLAG if the DEBUG variable has been set.
|
||||
# ******************************************************************************
|
||||
ifdef DEBUG
|
||||
DEBUGFLAG = -g
|
||||
else
|
||||
DEBUGFLAG = -O2
|
||||
endif
|
||||
|
||||
CXX = g++
|
||||
CC = gcc
|
||||
CXXFLAGS = -DLinux -DCDEV_HAS_64BIT_LONGS -fno-for-scope $(DEBUGFLAG) $(CXXEXTRA) $(CXXINCLUDES) \
|
||||
$(CDEVINCLUDES) $(BASEINCLUDES)
|
||||
CFLAGS = -DLinux -DCDEV_HAS_64BIT_LONGS $(DEBUGFLAG) $(CEXTRA) $(CXXINCLUDES) $(CDEVINCLUDES) $(BASEINCLUDES)
|
||||
AR = ar
|
||||
ARFLAGS = ruv
|
||||
RANLIB = ranlib
|
||||
DLD = $(CXX)
|
||||
SOFLAGS = -shared
|
||||
PIC = -fpic
|
||||
SHARED_EXT = so
|
||||
NETLIBS =
|
||||
OSLIBS = $(NETLIBS) -lm -ldl
|
||||
|
||||
|
||||
# ******************************************************************************
|
||||
# * These definitions define the names and locations of libraries that are
|
||||
# * required by CDEV for a shared and archive applications. The developer
|
||||
# * is required to add the list of service specific libraries.
|
||||
# ******************************************************************************
|
||||
ifeq ($(SHOBJ), NO)
|
||||
CDEVLIBS = $(CDEVLIB)/libcdev.a $(ARCHIVELIBS)
|
||||
else
|
||||
CDEVLIBS = -L$(CDEVLIB) -lcdev
|
||||
endif
|
||||
|
||||
|
||||
# ******************************************************************************
|
||||
# * Platform specific compile and link macros.
|
||||
# ******************************************************************************
|
||||
COMPILE.cc = $(QUIET)$(CXX_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) -c $(CXXFLAGS) $^ -o $@
|
||||
COMPILE.cc.so = $(QUIET)$(CXX_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) $(CXXFLAGS) $(PIC) -c -o $@ $^
|
||||
COMPILE.c = $(QUIET)$(CC_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CC) -c $(CFLAGS) $^ -o $@
|
||||
COMPILE.c.so = $(QUIET)$(CC_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CC) -c $(CFLAGS) $(PIC) $^ -o $@
|
||||
LINK.cc = $(QUIET)$(LINK_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) $(CXXFLAGS) -Xlinker -rpath -Xlinker $(BASELIB) -Xlinker -rpath -Xlinker $(CDEVLIB)
|
||||
LINK.a = $(QUIET)$(AR_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(AR) $(ARFLAGS)
|
||||
LINK.so = $(QUIET)$(SO_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(DLD) $(SOFLAGS)
|
||||
|
||||
# ******************************************************************************
|
||||
# * This is the macro to build a shared object/library.... it requires the
|
||||
# * following variables to be defined...
|
||||
# *
|
||||
# * SO_SRCS : Names of the component source files
|
||||
# * SO_LIBS : Names of the dependent libraries
|
||||
# * LIBS : All libraries necessary to compile the dummy application
|
||||
# ******************************************************************************
|
||||
SOBUILD = rm -f $@;\
|
||||
mkdir -p $(@D);\
|
||||
echo "=> Building shared object $(@F)";\
|
||||
$(LINK.so) -o $@ $^ -R $(CDEVLIB) -L$(CDEVLIB) -L./ $(NETLIBS)
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
# ******************************************************************************
|
||||
# * Makefile.Linux : This is the platform specific Makefile for Linux.
|
||||
# *
|
||||
# * Externals : This Makefile relies on the developer defining the
|
||||
# * following external definitions...
|
||||
# *
|
||||
# * CDEV : The base directory of the CDEV distribution
|
||||
# ******************************************************************************
|
||||
TARGET = Linux
|
||||
|
||||
include $(CDEV)/extensions/cdevGenericServer/include/makeinclude/Makefile.common
|
||||
include $(CDEV)/include/makeinclude/Makefile.archive
|
||||
|
||||
# ******************************************************************************
|
||||
# * Platform specific compile and link options.
|
||||
# ******************************************************************************
|
||||
|
||||
# ******************************************************************************
|
||||
# * Only specify the DEBUGFLAG if the DEBUG variable has been set.
|
||||
# ******************************************************************************
|
||||
ifdef DEBUG
|
||||
DEBUGFLAG = -g
|
||||
else
|
||||
DEBUGFLAG = -O2
|
||||
endif
|
||||
|
||||
CXX = g++
|
||||
CC = gcc
|
||||
CXXFLAGS = -DLinux -fno-for-scope $(DEBUGFLAG) $(CXXEXTRA) $(CXXINCLUDES) \
|
||||
$(CDEVINCLUDES) $(BASEINCLUDES)
|
||||
CFLAGS = -DLinux $(DEBUGFLAG) $(CEXTRA) $(CXXINCLUDES) $(CDEVINCLUDES) $(BASEINCLUDES)
|
||||
AR = ar
|
||||
ARFLAGS = ruv
|
||||
RANLIB = ranlib
|
||||
DLD = $(CXX)
|
||||
SOFLAGS = -shared
|
||||
PIC = -fpic
|
||||
SHARED_EXT = so
|
||||
NETLIBS =
|
||||
OSLIBS = $(NETLIBS) -lm -ldl
|
||||
|
||||
|
||||
# ******************************************************************************
|
||||
# * These definitions define the names and locations of libraries that are
|
||||
# * required by CDEV for a shared and archive applications. The developer
|
||||
# * is required to add the list of service specific libraries.
|
||||
# ******************************************************************************
|
||||
ifeq ($(SHOBJ), NO)
|
||||
CDEVLIBS = $(CDEVLIB)/libcdev.a $(ARCHIVELIBS)
|
||||
else
|
||||
CDEVLIBS = -L$(CDEVLIB) -lcdev
|
||||
endif
|
||||
|
||||
|
||||
# ******************************************************************************
|
||||
# * Platform specific compile and link macros.
|
||||
# ******************************************************************************
|
||||
COMPILE.cc = $(QUIET)$(CXX_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) -c $(CXXFLAGS) $^ -o $@
|
||||
COMPILE.cc.so = $(QUIET)$(CXX_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) $(CXXFLAGS) $(PIC) -c -o $@ $^
|
||||
COMPILE.c = $(QUIET)$(CC_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CC) -c $(CFLAGS) $^ -o $@
|
||||
COMPILE.c.so = $(QUIET)$(CC_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CC) -c $(CFLAGS) $(PIC) $^ -o $@
|
||||
LINK.cc = $(QUIET)$(LINK_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) $(CXXFLAGS)
|
||||
#$(CXX) $(CXXFLAGS) -Xlinker -rpath -Xlinker $(BASELIB) -Xlinker -rpath -Xlinker $(CDEVLIB)
|
||||
LINK.a = $(QUIET)$(AR_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(AR) $(ARFLAGS)
|
||||
LINK.so = $(QUIET)$(SO_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(DLD) $(SOFLAGS)
|
||||
|
||||
# ******************************************************************************
|
||||
# * This is the macro to build a shared object/library.... it requires the
|
||||
# * following variables to be defined...
|
||||
# *
|
||||
# * SO_SRCS : Names of the component source files
|
||||
# * SO_LIBS : Names of the dependent libraries
|
||||
# * LIBS : All libraries necessary to compile the dummy application
|
||||
# ******************************************************************************
|
||||
SOBUILD = rm -f $@;\
|
||||
mkdir -p $(@D);\
|
||||
echo "=> Building shared object $(@F)";\
|
||||
$(LINK.so) -o $@ $^ -R $(CDEVLIB) -L$(CDEVLIB) -L./ $(NETLIBS)
|
||||
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
# ******************************************************************************
|
||||
# * Makefile.Linux : This is the platform specific Makefile for Linux.
|
||||
# *
|
||||
# * Externals : This Makefile relies on the developer defining the
|
||||
# * following external definitions...
|
||||
# *
|
||||
# * CDEV : The base directory of the CDEV distribution
|
||||
# ******************************************************************************
|
||||
TARGET = Linux
|
||||
|
||||
include $(CDEV)/extensions/cdevGenericServer/include/makeinclude/Makefile.common
|
||||
include $(CDEV)/include/makeinclude/Makefile.archive
|
||||
|
||||
# ******************************************************************************
|
||||
# * Platform specific compile and link options.
|
||||
# ******************************************************************************
|
||||
|
||||
# ******************************************************************************
|
||||
# * Only specify the DEBUGFLAG if the DEBUG variable has been set.
|
||||
# ******************************************************************************
|
||||
ifdef DEBUG
|
||||
DEBUGFLAG = -g
|
||||
else
|
||||
DEBUGFLAG = -O2
|
||||
endif
|
||||
|
||||
CXX = g++
|
||||
CC = gcc
|
||||
CXXFLAGS = -DLinux -DCDEV_HAS_UNDERSCORE_FDBITS -DCDEV_HAS_64BIT_LONGS -fno-for-scope $(DEBUGFLAG) $(CXXEXTRA) $(CXXINCLUDES) \
|
||||
$(CDEVINCLUDES) $(BASEINCLUDES)
|
||||
CFLAGS = -DLinux -DCDEV_HAS_UNDERSCORE_FDBITS -DCDEV_HAS_64BIT_LONGS $(DEBUGFLAG) $(CEXTRA) $(CXXINCLUDES) $(CDEVINCLUDES) $(BASEINCLUDES)
|
||||
AR = ar
|
||||
ARFLAGS = ruv
|
||||
RANLIB = ranlib
|
||||
DLD = $(CXX)
|
||||
SOFLAGS = -shared
|
||||
PIC = -fpic
|
||||
SHARED_EXT = so
|
||||
NETLIBS =
|
||||
OSLIBS = $(NETLIBS) -lm -ldl
|
||||
|
||||
|
||||
# ******************************************************************************
|
||||
# * These definitions define the names and locations of libraries that are
|
||||
# * required by CDEV for a shared and archive applications. The developer
|
||||
# * is required to add the list of service specific libraries.
|
||||
# ******************************************************************************
|
||||
ifeq ($(SHOBJ), NO)
|
||||
CDEVLIBS = $(CDEVLIB)/libcdev.a $(ARCHIVELIBS)
|
||||
else
|
||||
CDEVLIBS = -L$(CDEVLIB) -lcdev
|
||||
endif
|
||||
|
||||
|
||||
# ******************************************************************************
|
||||
# * Platform specific compile and link macros.
|
||||
# ******************************************************************************
|
||||
COMPILE.cc = $(QUIET)$(CXX_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) -c $(CXXFLAGS) $^ -o $@
|
||||
COMPILE.cc.so = $(QUIET)$(CXX_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) $(CXXFLAGS) $(PIC) -c -o $@ $^
|
||||
COMPILE.c = $(QUIET)$(CC_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CC) -c $(CFLAGS) $^ -o $@
|
||||
COMPILE.c.so = $(QUIET)$(CC_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CC) -c $(CFLAGS) $(PIC) $^ -o $@
|
||||
LINK.cc = $(QUIET)$(LINK_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) $(CXXFLAGS) -Xlinker -rpath -Xlinker $(BASELIB) -Xlinker -rpath -Xlinker $(CDEVLIB)
|
||||
LINK.a = $(QUIET)$(AR_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(AR) $(ARFLAGS)
|
||||
LINK.so = $(QUIET)$(SO_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(DLD) $(SOFLAGS)
|
||||
|
||||
# ******************************************************************************
|
||||
# * This is the macro to build a shared object/library.... it requires the
|
||||
# * following variables to be defined...
|
||||
# *
|
||||
# * SO_SRCS : Names of the component source files
|
||||
# * SO_LIBS : Names of the dependent libraries
|
||||
# * LIBS : All libraries necessary to compile the dummy application
|
||||
# ******************************************************************************
|
||||
SOBUILD = rm -f $@;\
|
||||
mkdir -p $(@D);\
|
||||
echo "=> Building shared object $(@F)";\
|
||||
$(LINK.so) -o $@ $^ -R $(CDEVLIB) -L$(CDEVLIB) -L./ $(NETLIBS)
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
# ******************************************************************************
|
||||
# * Makefile.Linux : This is the platform specific Makefile for Linux.
|
||||
# *
|
||||
# * Externals : This Makefile relies on the developer defining the
|
||||
# * following external definitions...
|
||||
# *
|
||||
# * CDEV : The base directory of the CDEV distribution
|
||||
# ******************************************************************************
|
||||
TARGET = Linux
|
||||
|
||||
include $(CDEV)/extensions/cdevGenericServer/include/makeinclude/Makefile.common
|
||||
include $(CDEV)/include/makeinclude/Makefile.archive
|
||||
|
||||
# ******************************************************************************
|
||||
# * Platform specific compile and link options.
|
||||
# ******************************************************************************
|
||||
|
||||
# ******************************************************************************
|
||||
# * Only specify the DEBUGFLAG if the DEBUG variable has been set.
|
||||
# ******************************************************************************
|
||||
ifdef DEBUG
|
||||
DEBUGFLAG = -g
|
||||
else
|
||||
DEBUGFLAG = -O2
|
||||
endif
|
||||
|
||||
CXX = g++
|
||||
CC = gcc
|
||||
CXXFLAGS = -DLinux -DCDEV_HAS_UNDERSCORE_FDBITS -fno-for-scope $(DEBUGFLAG) $(CXXEXTRA) $(CXXINCLUDES) \
|
||||
$(CDEVINCLUDES) $(BASEINCLUDES)
|
||||
CFLAGS = -DLinux -DCDEV_HAS_UNDERSCORE_FDBITS $(DEBUGFLAG) $(CEXTRA) $(CXXINCLUDES) $(CDEVINCLUDES) $(BASEINCLUDES)
|
||||
AR = ar
|
||||
ARFLAGS = ruv
|
||||
RANLIB = ranlib
|
||||
DLD = $(CXX)
|
||||
SOFLAGS = -shared
|
||||
PIC = -fpic
|
||||
SHARED_EXT = so
|
||||
NETLIBS =
|
||||
OSLIBS = $(NETLIBS) -lm -ldl
|
||||
|
||||
|
||||
# ******************************************************************************
|
||||
# * These definitions define the names and locations of libraries that are
|
||||
# * required by CDEV for a shared and archive applications. The developer
|
||||
# * is required to add the list of service specific libraries.
|
||||
# ******************************************************************************
|
||||
ifeq ($(SHOBJ), NO)
|
||||
CDEVLIBS = $(CDEVLIB)/libcdev.a $(ARCHIVELIBS)
|
||||
else
|
||||
CDEVLIBS = -L$(CDEVLIB) -lcdev
|
||||
endif
|
||||
|
||||
|
||||
# ******************************************************************************
|
||||
# * Platform specific compile and link macros.
|
||||
# ******************************************************************************
|
||||
COMPILE.cc = $(QUIET)$(CXX_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) -c $(CXXFLAGS) $^ -o $@
|
||||
COMPILE.cc.so = $(QUIET)$(CXX_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) $(CXXFLAGS) $(PIC) -c -o $@ $^
|
||||
COMPILE.c = $(QUIET)$(CC_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CC) -c $(CFLAGS) $^ -o $@
|
||||
COMPILE.c.so = $(QUIET)$(CC_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CC) -c $(CFLAGS) $(PIC) $^ -o $@
|
||||
LINK.cc = $(QUIET)$(LINK_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) $(CXXFLAGS)
|
||||
#$(CXX) $(CXXFLAGS) -Xlinker -rpath -Xlinker $(BASELIB) -Xlinker -rpath -Xlinker $(CDEVLIB)
|
||||
LINK.a = $(QUIET)$(AR_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(AR) $(ARFLAGS)
|
||||
LINK.so = $(QUIET)$(SO_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(DLD) $(SOFLAGS)
|
||||
|
||||
# ******************************************************************************
|
||||
# * This is the macro to build a shared object/library.... it requires the
|
||||
# * following variables to be defined...
|
||||
# *
|
||||
# * SO_SRCS : Names of the component source files
|
||||
# * SO_LIBS : Names of the dependent libraries
|
||||
# * LIBS : All libraries necessary to compile the dummy application
|
||||
# ******************************************************************************
|
||||
SOBUILD = rm -f $@;\
|
||||
mkdir -p $(@D);\
|
||||
echo "=> Building shared object $(@F)";\
|
||||
$(LINK.so) -o $@ $^ -R $(CDEVLIB) -L$(CDEVLIB) -L./ $(NETLIBS)
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
# ******************************************************************************
|
||||
# * Makefile.Linux : This is the platform specific Makefile for Linux.
|
||||
# *
|
||||
# * Externals : This Makefile relies on the developer defining the
|
||||
# * following external definitions...
|
||||
# *
|
||||
# * CDEV : The base directory of the CDEV distribution
|
||||
# ******************************************************************************
|
||||
TARGET = Linux
|
||||
|
||||
include $(CDEV)/extensions/cdevGenericServer/include/makeinclude/Makefile.common
|
||||
include $(CDEV)/include/makeinclude/Makefile.archive
|
||||
|
||||
# ******************************************************************************
|
||||
# * Platform specific compile and link options.
|
||||
# ******************************************************************************
|
||||
|
||||
# ******************************************************************************
|
||||
# * Only specify the DEBUGFLAG if the DEBUG variable has been set.
|
||||
# ******************************************************************************
|
||||
ifdef DEBUG
|
||||
DEBUGFLAG = -g
|
||||
else
|
||||
DEBUGFLAG = -O2
|
||||
endif
|
||||
|
||||
CXX = g++
|
||||
CC = gcc
|
||||
CXXFLAGS = -DLinux -DCDEV_HAS_UNDERSCORE_FDBITS -fno-for-scope $(DEBUGFLAG) $(CXXEXTRA) $(CXXINCLUDES) \
|
||||
$(CDEVINCLUDES) $(BASEINCLUDES)
|
||||
CFLAGS = -DLinux -DCDEV_HAS_UNDERSCORE_FDBITS $(DEBUGFLAG) $(CEXTRA) $(CXXINCLUDES) $(CDEVINCLUDES) $(BASEINCLUDES)
|
||||
AR = ar
|
||||
ARFLAGS = ruv
|
||||
RANLIB = ranlib
|
||||
DLD = $(CXX)
|
||||
SOFLAGS = -shared
|
||||
PIC = -fpic
|
||||
SHARED_EXT = so
|
||||
NETLIBS =
|
||||
OSLIBS = $(NETLIBS) -lm -ldl
|
||||
|
||||
|
||||
# ******************************************************************************
|
||||
# * These definitions define the names and locations of libraries that are
|
||||
# * required by CDEV for a shared and archive applications. The developer
|
||||
# * is required to add the list of service specific libraries.
|
||||
# ******************************************************************************
|
||||
ifeq ($(SHOBJ), NO)
|
||||
CDEVLIBS = $(CDEVLIB)/libcdev.a $(ARCHIVELIBS)
|
||||
else
|
||||
CDEVLIBS = -L$(CDEVLIB) -lcdev
|
||||
endif
|
||||
|
||||
|
||||
# ******************************************************************************
|
||||
# * Platform specific compile and link macros.
|
||||
# ******************************************************************************
|
||||
COMPILE.cc = $(QUIET)$(CXX_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) -c $(CXXFLAGS) $^ -o $@
|
||||
COMPILE.cc.so = $(QUIET)$(CXX_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) $(CXXFLAGS) $(PIC) -c -o $@ $^
|
||||
COMPILE.c = $(QUIET)$(CC_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CC) -c $(CFLAGS) $^ -o $@
|
||||
COMPILE.c.so = $(QUIET)$(CC_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CC) -c $(CFLAGS) $(PIC) $^ -o $@
|
||||
LINK.cc = $(QUIET)$(LINK_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) $(CXXFLAGS)
|
||||
#$(CXX) $(CXXFLAGS) -Xlinker -rpath -Xlinker $(BASELIB) -Xlinker -rpath -Xlinker $(CDEVLIB)
|
||||
LINK.a = $(QUIET)$(AR_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(AR) $(ARFLAGS)
|
||||
LINK.so = $(QUIET)$(SO_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(DLD) $(SOFLAGS)
|
||||
|
||||
# ******************************************************************************
|
||||
# * This is the macro to build a shared object/library.... it requires the
|
||||
# * following variables to be defined...
|
||||
# *
|
||||
# * SO_SRCS : Names of the component source files
|
||||
# * SO_LIBS : Names of the dependent libraries
|
||||
# * LIBS : All libraries necessary to compile the dummy application
|
||||
# ******************************************************************************
|
||||
SOBUILD = rm -f $@;\
|
||||
mkdir -p $(@D);\
|
||||
echo "=> Building shared object $(@F)";\
|
||||
$(LINK.so) -o $@ $^ -R $(CDEVLIB) -L$(CDEVLIB) -L./ $(NETLIBS)
|
||||
|
||||
|
||||
93
extensions/cdevGenericServer/include/makeinclude/Makefile.solaris
Executable file
93
extensions/cdevGenericServer/include/makeinclude/Makefile.solaris
Executable file
@@ -0,0 +1,93 @@
|
||||
# ******************************************************************************
|
||||
# * Makefile.solaris : This is the platform specific Makefile for solaris.
|
||||
# *
|
||||
# * Externals : This Makefile relies on the developer defining the
|
||||
# * following external definitions...
|
||||
# *
|
||||
# * CDEV : The base directory of the CDEV distribution
|
||||
# ******************************************************************************
|
||||
TARGET = solaris
|
||||
|
||||
include $(CDEV)/extensions/cdevGenericServer/include/makeinclude/Makefile.common
|
||||
include $(CDEV)/include/makeinclude/Makefile.archive
|
||||
|
||||
# ******************************************************************************
|
||||
# * Platform specific compile and link options.
|
||||
# ******************************************************************************
|
||||
|
||||
# ******************************************************************************
|
||||
# * Only specify the DEBUGFLAG if the DEBUG variable has been set.
|
||||
# ******************************************************************************
|
||||
ifdef DEBUG
|
||||
DEBUGFLAG = -g
|
||||
endif
|
||||
|
||||
CXX = CC
|
||||
CC = cc
|
||||
CXXFLAGS = -Dsolaris $(DEBUGFLAG) $(CXXEXTRA) $(CXXINCLUDES) \
|
||||
$(CDEVINCLUDES) $(BASEINCLUDES) -DSYSV
|
||||
CFLAGS = -Dsolaris $(DEBUGFLAG) $(CEXTRA) $(CXXINCLUDES) $(CDEVINCLUDES) $(BASEINCLUDES) -DSYSV
|
||||
AR = $(CXX)
|
||||
ARFLAGS = -xar -o
|
||||
RANLIB = ranlib
|
||||
DLD = $(CXX)
|
||||
SOFLAGS = -G $(CXXFLAGS)
|
||||
PIC = -Kpic
|
||||
SHARED_EXT = so
|
||||
NETLIBS = -lsocket -lnsl -ldl -lgen
|
||||
OSLIBS = $(NETLIBS) -ll -ly -lm
|
||||
|
||||
|
||||
# ******************************************************************************
|
||||
# * These definitions define the names and locations of libraries that are
|
||||
# * required by CDEV for a shared and archive applications. The developer
|
||||
# * is required to add the list of service specific libraries.
|
||||
# ******************************************************************************
|
||||
ifeq ($(SHOBJ), NO)
|
||||
CDEVLIBS = $(CDEVLIB)/libcdev.a $(ARCHIVELIBS)
|
||||
else
|
||||
CDEVLIBS = -L$(CDEVLIB) -lcdev
|
||||
endif
|
||||
|
||||
|
||||
# ******************************************************************************
|
||||
# * Platform specific compile and link macros.
|
||||
# ******************************************************************************
|
||||
COMPILE.cc = $(QUIET)$(CXX_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) -c $(CXXFLAGS) $^ -o $@
|
||||
COMPILE.cc.so = $(QUIET)$(CXX_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) $(CXXFLAGS) $(PIC) -c -o $@ $^;\
|
||||
$(CXX) $(CXXFLAGS) -G -o $(@D)/$(*F).so -h $(@D)/$(*F).so \
|
||||
-R $(CDEVLIB) -L$(CDEVLIB) -L./ $@
|
||||
COMPILE.c = $(QUIET)$(CC_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CC) -c $(CFLAGS) $^ -o $@
|
||||
COMPILE.c.so = $(QUIET)$(CC_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CC) -c $(CFLAGS) $(PIC) $^ -o $@
|
||||
LINK.cc = $(QUIET)$(CXX_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(CXX) $(CXXFLAGS)
|
||||
LINK.a = $(QUIET)$(AR_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(AR) $(ARFLAGS)
|
||||
LINK.so = $(QUIET)$(SO_CMD_ECHO)rm -rf $@;\
|
||||
mkdir -p $(@D);\
|
||||
$(DLD) $(SOFLAGS)
|
||||
|
||||
# ******************************************************************************
|
||||
# * This is the macro to build a shared object/library.... it requires the
|
||||
# * following variables to be defined...
|
||||
# *
|
||||
# * SO_SRCS : Names of the component source files
|
||||
# * SO_LIBS : Names of the dependent libraries
|
||||
# * LIBS : All libraries necessary to compile the dummy application
|
||||
# ******************************************************************************
|
||||
SOBUILD = rm -f $@;\
|
||||
mkdir -p $(@D);\
|
||||
echo "=> Building shared object $(@F)";\
|
||||
$(LINK.so) -o $@ $^ -R $(CDEVLIB) -L$(CDEVLIB) -L./ $(NETLIBS)
|
||||
|
||||
|
||||
204
extensions/cdevGenericServer/include/makeinclude/NMakefile.lib
Normal file
204
extensions/cdevGenericServer/include/makeinclude/NMakefile.lib
Normal file
@@ -0,0 +1,204 @@
|
||||
.SUFFIXES: .cc .obj
|
||||
|
||||
APPNAME = CDEV Generic Client/Server Engine
|
||||
ARCH = WINNT-4.0
|
||||
|
||||
BINARIES = $(CDEVLIB)\cdevGenericServer.dll \
|
||||
$(CDEVLIB)\cdevGenericServer.lib
|
||||
|
||||
include ..\include\makeinclude\Makefile.WINNT-4.0
|
||||
|
||||
TEMPLINKS = ClientAcceptor.cc\
|
||||
ClientHandler.cc\
|
||||
cdevServer.cc\
|
||||
cdevServerTools.cc\
|
||||
cdevSessionManager.cc\
|
||||
ServerInterface.cc\
|
||||
ServerHandler.cc\
|
||||
cdevClientRequestObject.cc\
|
||||
cdevClientService.cc\
|
||||
cdevMessage.cc\
|
||||
cdevMessageBinary.cc\
|
||||
cdevPacket.cc\
|
||||
cdevContextMap.cc\
|
||||
cdevMonitorTable.cc\
|
||||
cdevTagMap.cc\
|
||||
SignalManager.cc\
|
||||
cdevAddr.cc\
|
||||
cdevEventHandler.cc\
|
||||
cdevHandleSet.cc\
|
||||
cdevReactor.cc\
|
||||
cdevSocket.cc\
|
||||
cdevSocketAcceptor.cc\
|
||||
cdevSocketConnector.cc\
|
||||
cdevSocketDatagram.cc\
|
||||
cdevSocketStream.cc\
|
||||
cdevStreamNode.cc\
|
||||
cdevStreamQueue.cc\
|
||||
cdevTime.cc\
|
||||
fifo.cc\
|
||||
IntHash.cc
|
||||
|
||||
|
||||
LIBS = $(CDEVLIBS) $(OSLIBS)
|
||||
|
||||
SERVER_OBJS = $(OBJDIR)\cdevServer.obj\
|
||||
$(OBJDIR)\cdevServerTools.obj\
|
||||
$(OBJDIR)\cdevSessionManager.obj\
|
||||
$(OBJDIR)\ClientHandler.obj\
|
||||
$(OBJDIR)\ClientAcceptor.obj\
|
||||
$(OBJDIR)\cdevTagMap.obj\
|
||||
$(OBJDIR)\cdevMonitorTable.obj
|
||||
|
||||
CLIENT_OBJS = $(OBJDIR)\cdevClientService.obj\
|
||||
$(OBJDIR)\cdevClientRequestObject.obj\
|
||||
$(OBJDIR)\ServerInterface.obj\
|
||||
$(OBJDIR)\ServerHandler.obj
|
||||
|
||||
COMMON_OBJS = $(OBJDIR)\cdevPacket.obj\
|
||||
$(OBJDIR)\cdevMessageBinary.obj\
|
||||
$(OBJDIR)\cdevMessage.obj\
|
||||
$(OBJDIR)\cdevContextMap.obj\
|
||||
$(OBJDIR)\SignalManager.obj\
|
||||
$(OBJDIR)\fifo.obj\
|
||||
$(OBJDIR)\IntHash.obj
|
||||
|
||||
ACE_OBJS = $(OBJDIR)\cdevAddr.obj\
|
||||
$(OBJDIR)\cdevEventHandler.obj\
|
||||
$(OBJDIR)\cdevHandleSet.obj\
|
||||
$(OBJDIR)\cdevReactor.obj\
|
||||
$(OBJDIR)\cdevSocket.obj\
|
||||
$(OBJDIR)\cdevSocketAcceptor.obj\
|
||||
$(OBJDIR)\cdevSocketConnector.obj\
|
||||
$(OBJDIR)\cdevSocketDatagram.obj\
|
||||
$(OBJDIR)\cdevSocketStream.obj\
|
||||
$(OBJDIR)\cdevStreamNode.obj\
|
||||
$(OBJDIR)\cdevStreamQueue.obj\
|
||||
$(OBJDIR)\cdevTime.obj
|
||||
|
||||
OBJS = $(SERVER_OBJS) $(CLIENT_OBJS) $(COMMON_OBJS) $(ACE_OBJS)
|
||||
|
||||
CXXEXTRA = /D "_CDEV_REACTOR_EXPORTS_=1" /D "_GENERIC_SERVER_EXPORTS_=1"
|
||||
|
||||
# ******************************************************************************
|
||||
# * The BINARIES definition names all of the binary files that should be deleted
|
||||
# * whenever "make clean" is executed.
|
||||
# ******************************************************************************
|
||||
BINARIES = $(CDEVLIB)\cdevGenericServer.dll \
|
||||
$(CDEVLIB)\cdevGenericServer.lib
|
||||
|
||||
!IF "$(SHOBJ)" == "YES"
|
||||
TARGETS = $(TEMPLINKS) $(CDEVLIB)\cdevGenericServer.dll
|
||||
!ELSE
|
||||
TARGETS = $(TEMPLINKS) $(CDEVLIB)\cdevGenericServer.lib
|
||||
!ENDIF
|
||||
|
||||
targets : $(TARGETS)
|
||||
@erase $(TEMPLINKS)
|
||||
|
||||
$(CDEVLIB)\cdevGenericServer.lib : $(OBJS)
|
||||
@echo ^ ^ ^ =^> Linking $(@F)
|
||||
-@if exist $@ erase $@
|
||||
-@if not exist $(@D) mkdir $(@D)
|
||||
@$(LIB32) $(CDEVLIB)\cdev.lib $(CDEVLIB)\rsvc.lib\
|
||||
$(LINK_LIB_FLAGS) /out:$@ $(OBJS)
|
||||
@echo ^ ^ ^ ^ ^ ^ Done...
|
||||
|
||||
$(CDEVLIB)\cdevGenericServer.dll : $(OBJS)
|
||||
@echo ^ ^ ^ =^> Linking $(@F)
|
||||
-@if exist $@ erase $@
|
||||
-@if not exist $(@D) mkdir $(@D)
|
||||
@$(LIB32) $(CDEVLIB)\cdev.lib $(CDEVLIB)\rsvc.lib\
|
||||
$(LINK_DLL_FLAGS) /out:$@ /implib:$(@D)\$(@B).lib $(OBJS)
|
||||
@echo ^ ^ ^ ^ ^ ^ Done...
|
||||
|
||||
ClientAcceptor.cc : ..\cdevServer\ClientAcceptor.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
ClientHandler.cc : ..\cdevServer\ClientHandler.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevServer.cc : ..\cdevServer\cdevServer.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevServerTools.cc : ..\cdevServer\cdevServerTools.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevSessionManager.cc : ..\cdevServer\cdevSessionManager.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
ServerHandler.cc : ..\cdevClient\ServerHandler.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
ServerInterface.cc : ..\cdevClient\ServerInterface.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevClientRequestObject.cc : ..\cdevClient\cdevClientRequestObject.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevClientService.cc : ..\cdevClient\cdevClientService.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevMessage.cc : ..\cdevPacket\cdevMessage.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevMessageBinary.cc : ..\cdevPacket\cdevMessageBinary.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevPacket.cc : ..\cdevPacket\cdevPacket.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevContextMap.cc : ..\cdevContextMap\cdevContextMap.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevMonitorTable.cc : ..\cdevMonitorTable\cdevMonitorTable.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevTagMap.cc : ..\cdevTagMap\cdevTagMap.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
SignalManager.cc : ..\common\SignalManager.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevAddr.cc : ..\cdevReactor\cdevAddr.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevEventHandler.cc : ..\cdevReactor\cdevEventHandler.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevHandleSet.cc : ..\cdevReactor\cdevHandleSet.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevReactor.cc : ..\cdevReactor\cdevReactor.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevSocket.cc : ..\cdevReactor\cdevSocket.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevSocketAcceptor.cc : ..\cdevReactor\cdevSocketAcceptor.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevSocketConnector.cc : ..\cdevReactor\cdevSocketConnector.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevSocketDatagram.cc : ..\cdevReactor\cdevSocketDatagram.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevSocketStream.cc : ..\cdevReactor\cdevSocketStream.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevStreamNode.cc : ..\cdevReactor\cdevStreamNode.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevStreamQueue.cc : ..\cdevReactor\cdevStreamQueue.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
cdevTime.cc : ..\cdevReactor\cdevTime.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
fifo.cc : ..\common\fifo.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
IntHash.cc : ..\common\IntHash.cc
|
||||
-@$(CREATE_LINK)
|
||||
|
||||
54
extensions/cdevGenericServer/include/rnsMonitorObj.h
Normal file
54
extensions/cdevGenericServer/include/rnsMonitorObj.h
Normal file
@@ -0,0 +1,54 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// Name Server Monitor Object
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RNS_MONITOR_OBJ_H
|
||||
#define _RNS_MONITOR_OBJ_H
|
||||
|
||||
#include <cdevMonitorObj.h>
|
||||
|
||||
class rnsRequestObject;
|
||||
|
||||
class rnsMonitorObj : public cdevMonitorObj
|
||||
{
|
||||
public:
|
||||
// constructor and destructor
|
||||
rnsMonitorObj (cdevTranObj& tranObj)
|
||||
:cdevMonitorObj (tranObj), out_ (0), started_ (1)
|
||||
{
|
||||
#ifdef _TRACE_OBJECTS
|
||||
printf (" Create rnsMonitorObj Class Object\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
~rnsMonitorObj (void)
|
||||
{
|
||||
#ifdef _TRACE_OBJECTS
|
||||
printf (" Delete rnsMonitorObj Class Object\n");
|
||||
#endif
|
||||
if (out_)
|
||||
delete out_;
|
||||
}
|
||||
|
||||
const char* className (void) const {return "rnsMonitorObj";}
|
||||
|
||||
// out bound cdevdata
|
||||
cdevData* out_;
|
||||
|
||||
// whether this monitor callback is restarted or not
|
||||
int started_;
|
||||
};
|
||||
#endif
|
||||
|
||||
439
extensions/cdevGenericServer/include/rnsQueryCollector.h
Normal file
439
extensions/cdevGenericServer/include/rnsQueryCollector.h
Normal file
@@ -0,0 +1,439 @@
|
||||
#include <cdevSystem.h>
|
||||
#include <cdevRequestObject.h>
|
||||
#include <cdevData.h>
|
||||
#include <cdevCallback.h>
|
||||
|
||||
class rnsQueryCollector
|
||||
{
|
||||
private:
|
||||
cdevData * data;
|
||||
int deleteFlag;
|
||||
unsigned char * byteData;
|
||||
short * shortData;
|
||||
unsigned short * ushortData;
|
||||
long * longData;
|
||||
unsigned long * ulongData;
|
||||
float * floatData;
|
||||
double * doubleData;
|
||||
cdev_TS_STAMP * tsData;
|
||||
size_t byteCnt;
|
||||
size_t shortCnt;
|
||||
size_t ushortCnt;
|
||||
size_t longCnt;
|
||||
size_t ulongCnt;
|
||||
size_t floatCnt;
|
||||
size_t doubleCnt;
|
||||
size_t tsCnt;
|
||||
|
||||
public:
|
||||
rnsQueryCollector ( cdevData & userData, int deleteData = 0 )
|
||||
: data(&userData), deleteFlag(deleteData),
|
||||
byteData(NULL), shortData(NULL), ushortData(NULL),
|
||||
longData(NULL), ulongData(NULL), floatData(NULL),
|
||||
doubleData(NULL), tsData(NULL), byteCnt(0),
|
||||
shortCnt(0), ushortCnt(0), longCnt(0), ulongCnt(0),
|
||||
floatCnt(0), doubleCnt(0), tsCnt(0)
|
||||
{
|
||||
data->remove();
|
||||
}
|
||||
|
||||
~rnsQueryCollector ( void )
|
||||
{
|
||||
if(deleteFlag) delete data;
|
||||
if(byteData) delete byteData;
|
||||
if(shortData) delete shortData;
|
||||
if(ushortData) delete ushortData;
|
||||
if(longData) delete longData;
|
||||
if(ulongData) delete ulongData;
|
||||
if(floatData) delete floatData;
|
||||
if(doubleData) delete doubleData;
|
||||
if(tsData) delete tsData;
|
||||
}
|
||||
|
||||
cdevData * getData ( void ) { return data; }
|
||||
void clearData ( void ) { data->remove(); }
|
||||
inline int collect ( cdevData & userData );
|
||||
|
||||
private:
|
||||
inline int collectAttribute ( cdevData & userData, int tag, int position );
|
||||
inline void collectByteAttribute ( cdevData & userData, int tag, int position );
|
||||
inline void collectShortAttribute ( cdevData & userData, int tag, int position );
|
||||
inline void collectUShortAttribute ( cdevData & userData, int tag, int position );
|
||||
inline void collectLongAttribute ( cdevData & userData, int tag, int position );
|
||||
inline void collectULongAttribute ( cdevData & userData, int tag, int position );
|
||||
inline void collectFloatAttribute ( cdevData & userData, int tag, int position );
|
||||
inline void collectDoubleAttribute ( cdevData & userData, int tag, int position );
|
||||
inline void collectStringAttribute ( cdevData & userData, int tag, int position );
|
||||
inline void collectTimestampAttribute ( cdevData & userData, int tag, int position );
|
||||
};
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * class rnsQueryCallback :
|
||||
// * This class provides the methods to allow a rnsQueryCollector to be
|
||||
// * incorporated into a cdevCallback. The localCallback function will
|
||||
// * be called with results until the data has been completely collected,
|
||||
// * and only then will the user callback be executed - providing full
|
||||
// * data.
|
||||
// *****************************************************************************
|
||||
class rnsQueryCallback : public cdevCallback
|
||||
{
|
||||
private:
|
||||
rnsQueryCollector collector;
|
||||
cdevCallback callback;
|
||||
|
||||
public:
|
||||
rnsQueryCallback ( cdevCallback & Callback )
|
||||
: cdevCallback(), callback(Callback), collector(*(new cdevData), 1)
|
||||
{
|
||||
userarg_ = this;
|
||||
function_ = rnsQueryCallback::localCallback;
|
||||
}
|
||||
|
||||
virtual ~rnsQueryCallback ( void )
|
||||
{
|
||||
}
|
||||
|
||||
static void localCallback ( int status, void * arg, cdevRequestObject & req, cdevData & data)
|
||||
{
|
||||
rnsQueryCallback * qCallback;
|
||||
|
||||
if((qCallback = (rnsQueryCallback *)arg)!=NULL)
|
||||
{
|
||||
if(status==CDEV_SUCCESS ||
|
||||
status==CDEV_INCOMPLETE)
|
||||
{
|
||||
qCallback->collector.collect(data);
|
||||
}
|
||||
|
||||
if(status==CDEV_SUCCESS ||
|
||||
status==CDEV_ERROR ||
|
||||
status==CDEV_NOTFOUND ||
|
||||
status==CDEV_MSG_ERR)
|
||||
{
|
||||
qCallback->callback.fireCallback(status, qCallback->callback.userarg(),
|
||||
req, *qCallback->collector.getData(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * rnsQueryCollector::collect :
|
||||
// * This method is called when a cdevData object needs to be appended to
|
||||
// * the cdevData object that is serving as a collection. This method will
|
||||
// * transfer each of the data items in the userData object to the proper
|
||||
// * position in the local data object.
|
||||
// *****************************************************************************
|
||||
int rnsQueryCollector::collect ( cdevData & userData )
|
||||
{
|
||||
int cnt = 0;
|
||||
size_t size = 0;
|
||||
cdevDataIterator iter(&userData);
|
||||
cdevDataIterator dIter(data);
|
||||
|
||||
// *********************************************************************
|
||||
// * Look through the existing data and determine the largest number
|
||||
// * of items that exist in a single tagged item. This value will be
|
||||
// * used to specify the position of the data that is being added to the
|
||||
// * array.
|
||||
// *********************************************************************
|
||||
dIter.init();
|
||||
while(dIter.tag()!=0)
|
||||
{
|
||||
size_t elems = 0;
|
||||
data->getElems(dIter.tag(), &elems);
|
||||
if(elems>size) size = elems;
|
||||
++dIter;
|
||||
}
|
||||
|
||||
// *********************************************************************
|
||||
// * Walk through the list of tagged data items that are stored in the
|
||||
// * inbound data object. Call the collectAttribute method for each
|
||||
// * data item. This method will copy the contents of the inbound
|
||||
// * data object to the correct position in the local data object.
|
||||
// *********************************************************************
|
||||
iter.init();
|
||||
while(iter.tag()!=0)
|
||||
{
|
||||
cnt+=(collectAttribute(userData, iter.tag(), size)==0)?1:0;
|
||||
++iter;
|
||||
}
|
||||
|
||||
// *********************************************************************
|
||||
// * Return the count of data items that were assimilated into the
|
||||
// * local data object.
|
||||
// *********************************************************************
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * rnsQueryCollector::collectAttribute :
|
||||
// * This method will assimilate a single attribute from the specified
|
||||
// * userData object into the local cdevData object at the specified
|
||||
// * position.
|
||||
// *****************************************************************************
|
||||
int rnsQueryCollector::collectAttribute ( cdevData & userData, int tag, int position )
|
||||
{
|
||||
cdevSystem & sys = cdevSystem::defaultSystem();
|
||||
int result = 0;
|
||||
size_t dim = 0;
|
||||
size_t userDim = 0;
|
||||
cdevDataTypes type = data->getType(tag);
|
||||
cdevDataTypes userType = userData.getType(tag);
|
||||
|
||||
if(userData.getDim(tag, &dim)==CDEV_NOTFOUND || dim > 0)
|
||||
{
|
||||
sys.reportError(CDEV_SEVERITY_ERROR, "Name Server", NULL,
|
||||
"Cannot add array data to query reply");
|
||||
result = -1;
|
||||
}
|
||||
else if(data->getDim(tag, &dim)!=CDEV_NOTFOUND && dim > 1)
|
||||
{
|
||||
sys.reportError(CDEV_SEVERITY_ERROR, "Name Server", NULL,
|
||||
"Cannot assemble a query with multi-dimensional data");
|
||||
result = -1;
|
||||
}
|
||||
else if (userType == CDEV_INVALID)
|
||||
{
|
||||
sys.reportError(CDEV_SEVERITY_ERROR, "Name Server", NULL,
|
||||
"Inbound query data object has invalid data type");
|
||||
result = -1;
|
||||
}
|
||||
else {
|
||||
if(type!=CDEV_INVALID)
|
||||
{
|
||||
if(type<CDEV_TIMESTAMP && userType<CDEV_TIMESTAMP)
|
||||
{
|
||||
type = (type>userType)?type:userType;
|
||||
}
|
||||
else if(type==CDEV_TIMESTAMP) type = userType;
|
||||
}
|
||||
else type = userType;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case CDEV_BYTE:
|
||||
collectByteAttribute(userData, tag, position);
|
||||
break;
|
||||
case CDEV_INT16:
|
||||
collectShortAttribute(userData, tag, position);
|
||||
break;
|
||||
case CDEV_UINT16:
|
||||
collectUShortAttribute(userData, tag, position);
|
||||
break;
|
||||
case CDEV_INT32:
|
||||
collectLongAttribute(userData, tag, position);
|
||||
break;
|
||||
case CDEV_UINT32:
|
||||
collectULongAttribute(userData, tag, position);
|
||||
break;
|
||||
case CDEV_FLOAT:
|
||||
collectFloatAttribute(userData, tag, position);
|
||||
break;
|
||||
case CDEV_DOUBLE:
|
||||
collectDoubleAttribute(userData, tag, position);
|
||||
break;
|
||||
case CDEV_STRING:
|
||||
collectStringAttribute(userData, tag, position);
|
||||
break;
|
||||
case CDEV_TIMESTAMP:
|
||||
collectTimestampAttribute(userData, tag, position);
|
||||
break;
|
||||
default:
|
||||
result = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * rnsQueryCollector::collectByteAttribute :
|
||||
// * This method will transfer the byte attribute stored in the userData
|
||||
// * object into the local cdevData object at the specified position.
|
||||
// *****************************************************************************
|
||||
void rnsQueryCollector::collectByteAttribute (cdevData & userData, int tag, int position )
|
||||
{
|
||||
if((position+1)>byteCnt)
|
||||
{
|
||||
if(byteData!=NULL) delete byteData;
|
||||
byteCnt = ((position+1)>100)?(position+100):100;
|
||||
byteData = new unsigned char [byteCnt];
|
||||
}
|
||||
memset(byteData, 0, byteCnt*sizeof(unsigned char));
|
||||
data->get(tag, byteData);
|
||||
userData.get(tag, &byteData[position]);
|
||||
data->insert(tag, byteData, position+1);
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * rnsQueryCollector::collectShortAttribute :
|
||||
// * This method will transfer the short attribute stored in the userData
|
||||
// * object into the local cdevData object at the specified position.
|
||||
// *****************************************************************************
|
||||
void rnsQueryCollector::collectShortAttribute (cdevData & userData, int tag, int position )
|
||||
{
|
||||
if((position+1)>shortCnt)
|
||||
{
|
||||
if(shortData!=NULL) delete shortData;
|
||||
shortCnt = ((position+1)>100)?(position+100):100;
|
||||
shortData = new short [shortCnt];
|
||||
}
|
||||
memset(shortData, 0, shortCnt*sizeof(short));
|
||||
data->get(tag, shortData);
|
||||
userData.get(tag, &shortData[position]);
|
||||
data->insert(tag, shortData, position+1);
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * rnsQueryCollector::collectUShortAttribute :
|
||||
// * This method will transfer the unsigned short attribute stored in the
|
||||
// * userData object into the local cdevData object at the specified
|
||||
// * position.
|
||||
// *****************************************************************************
|
||||
void rnsQueryCollector::collectUShortAttribute (cdevData & userData, int tag, int position )
|
||||
{
|
||||
if((position+1)>ushortCnt)
|
||||
{
|
||||
if(ushortData!=NULL) delete ushortData;
|
||||
ushortCnt = ((position+1)>100)?(position+100):100;
|
||||
ushortData = new unsigned short [ushortCnt];
|
||||
}
|
||||
memset(ushortData, 0, ushortCnt*sizeof(unsigned short));
|
||||
data->get(tag, ushortData);
|
||||
userData.get(tag, &ushortData[position]);
|
||||
data->insert(tag, ushortData, position+1);
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * rnsQueryCollector::collectLongAttribute :
|
||||
// * This method will transfer the long attribute stored in the
|
||||
// * userData object into the local cdevData object at the specified
|
||||
// * position.
|
||||
// *****************************************************************************
|
||||
void rnsQueryCollector::collectLongAttribute (cdevData & userData, int tag, int position )
|
||||
{
|
||||
if((position+1)>longCnt)
|
||||
{
|
||||
if(longData!=NULL) delete longData;
|
||||
longCnt = ((position+1)>100)?(position+100):100;
|
||||
longData = new long [longCnt];
|
||||
}
|
||||
memset(longData, 0, longCnt*sizeof(long));
|
||||
data->get(tag, longData);
|
||||
userData.get(tag, &longData[position]);
|
||||
data->insert(tag, longData, position+1);
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * rnsQueryCollector::collectULongAttribute :
|
||||
// * This method will transfer the unsigned long attribute stored in the
|
||||
// * userData object into the local cdevData object at the specified
|
||||
// * position.
|
||||
// *****************************************************************************
|
||||
void rnsQueryCollector::collectULongAttribute (cdevData & userData, int tag, int position )
|
||||
{
|
||||
if((position+1)>ulongCnt)
|
||||
{
|
||||
if(ulongData!=NULL) delete ulongData;
|
||||
ulongCnt = ((position+1)>100)?(position+100):100;
|
||||
ulongData = new unsigned long [ulongCnt];
|
||||
}
|
||||
memset(ulongData, 0, ulongCnt*sizeof(unsigned long));
|
||||
data->get(tag, ulongData);
|
||||
userData.get(tag, &ulongData[position]);
|
||||
data->insert(tag, ulongData, position+1);
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * rnsQueryCollector::collectFloatAttribute :
|
||||
// * This method will transfer the float attribute stored in the
|
||||
// * userData object into the local cdevData object at the specified
|
||||
// * position.
|
||||
// *****************************************************************************
|
||||
void rnsQueryCollector::collectFloatAttribute (cdevData & userData, int tag, int position )
|
||||
{
|
||||
if((position+1)>floatCnt)
|
||||
{
|
||||
if(floatData!=NULL) delete floatData;
|
||||
floatCnt = ((position+1)>100)?(position+100):100;
|
||||
floatData = new float [floatCnt];
|
||||
}
|
||||
memset(floatData, 0, floatCnt*sizeof(float));
|
||||
data->get(tag, floatData);
|
||||
userData.get(tag, &floatData[position]);
|
||||
data->insert(tag, floatData, position+1);
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * rnsQueryCollector::collectDoubleAttribute :
|
||||
// * This method will transfer the double attribute stored in the
|
||||
// * userData object into the local cdevData object at the specified
|
||||
// * position.
|
||||
// *****************************************************************************
|
||||
void rnsQueryCollector::collectDoubleAttribute (cdevData & userData, int tag, int position )
|
||||
{
|
||||
if((position+1)>doubleCnt)
|
||||
{
|
||||
if(doubleData!=NULL) delete doubleData;
|
||||
doubleCnt = ((position+1)>100)?(position+100):100;
|
||||
doubleData = new double [doubleCnt];
|
||||
}
|
||||
memset(doubleData, 0, doubleCnt*sizeof(double));
|
||||
data->get(tag, doubleData);
|
||||
userData.get(tag, &doubleData[position]);
|
||||
data->insert(tag, doubleData, position+1);
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * rnsQueryCollector::collectStringAttribute :
|
||||
// * This method will transfer the string attribute stored in the
|
||||
// * userData object into the local cdevData object at the specified
|
||||
// * position.
|
||||
// *****************************************************************************
|
||||
void rnsQueryCollector::collectStringAttribute (cdevData & userData, int tag, int position )
|
||||
{
|
||||
int i;
|
||||
char blank = 0;
|
||||
|
||||
char ** stringData = new char * [ position+1 ];
|
||||
memset(stringData, 0, (position+1)*sizeof(char *));
|
||||
data->get(tag, stringData);
|
||||
userData.get(tag, &stringData[position]);
|
||||
|
||||
for(i=0; i<position+1; i++)
|
||||
{
|
||||
if(stringData[i] == NULL) stringData[i] = ␣
|
||||
}
|
||||
data->insert(tag, stringData, position+1);
|
||||
|
||||
for(i=0; i<position+1; i++)
|
||||
{
|
||||
if(stringData[i]!=&blank) delete stringData[i];
|
||||
}
|
||||
delete stringData;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * rnsQueryCollector::collectTimestampAttribute :
|
||||
// * This method will transfer the time stamp attribute stored in the
|
||||
// * userData object into the local cdevData object at the specified
|
||||
// * position.
|
||||
// *****************************************************************************
|
||||
void rnsQueryCollector::collectTimestampAttribute (cdevData & userData, int tag, int position )
|
||||
{
|
||||
if((position+1)>tsCnt)
|
||||
{
|
||||
if(tsData!=NULL) delete tsData;
|
||||
tsCnt = ((position+1)>100)?(position+100):100;
|
||||
tsData = new cdev_TS_STAMP [tsCnt];
|
||||
}
|
||||
memset(tsData, 0, tsCnt);
|
||||
data->get(tag, tsData);
|
||||
userData.get(tag, &tsData[position]);
|
||||
data->insert(tag, tsData, position+1);
|
||||
}
|
||||
130
extensions/cdevGenericServer/include/rnsRequestObject.h
Normal file
130
extensions/cdevGenericServer/include/rnsRequestObject.h
Normal file
@@ -0,0 +1,130 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// CDEV Resource Name Service Request Object
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RNS_REQUEST_OBJECT_H
|
||||
#define _RNS_REQUEST_OBJECT_H
|
||||
|
||||
#include <cdevSystem.h>
|
||||
#include <cdevRequestObject.h>
|
||||
|
||||
class rsvcClient;
|
||||
class rnsService;
|
||||
class rnsMonitorObj;
|
||||
|
||||
class rnsRequestObject: public cdevRequestObject
|
||||
{
|
||||
public:
|
||||
// constructor and destructor
|
||||
rnsRequestObject (char* device,
|
||||
char* msg,
|
||||
rnsService* svc,
|
||||
cdevSystem& system = cdevSystem::defaultSystem());
|
||||
~rnsRequestObject (void);
|
||||
|
||||
int send (cdevData& out, cdevData& result);
|
||||
int send (cdevData *out, cdevData& result);
|
||||
int send (cdevData& out, cdevData* result);
|
||||
int send (cdevData *out, cdevData* result);
|
||||
// PURPOSE: Synchronous IO operations
|
||||
// REQUIRE: When do query and get, result must be provided
|
||||
// PROMISE: return CDEV_SUCCESS: success.
|
||||
|
||||
int sendNoBlock (cdevData& out, cdevData& result);
|
||||
int sendNoBlock (cdevData* out, cdevData& result);
|
||||
int sendNoBlock (cdevData& out, cdevData* result);
|
||||
int sendNoBlock (cdevData* out, cdevData* result);
|
||||
// PURPOSE: Asynchronous IO operations used in conjunction with
|
||||
// cdevGroup or system
|
||||
// REQUIRE:
|
||||
// PROMISE: return CDEV_SUCCESS: requests have been sent out.
|
||||
|
||||
int sendCallback (cdevData& out, cdevCallback& callback);
|
||||
int sendCallback (cdevData* out, cdevCallback& callback);
|
||||
// PURPOSE: Asynchromous IO operations with a user supplied callback function
|
||||
// REQUIRE:
|
||||
// PROMISE: User callback function will be called with status information
|
||||
// status = CDEV_DISCONNECTED: channel discconected
|
||||
// status = CDEV_SUCCESS : everything is OK
|
||||
// status = CDEV_ERROR : something fishy.
|
||||
// status = CDEV_INCOMPLETE : data flow will coming (88)
|
||||
// status = CDEV_CBK_FINISHED: query callback finished (89)
|
||||
// status = CDEV_QUERYMSG_ERR: query message syntax erro (91)
|
||||
|
||||
int getState (void);
|
||||
// PURPOSE: get connection state
|
||||
// REQUIRE: none
|
||||
// PROMISE: CDEV_CONNECTED or CDEV_NOTCONNECTED
|
||||
|
||||
const char *className (void) const {return "rnsRequestObject";}
|
||||
|
||||
protected:
|
||||
// find out action from message
|
||||
static int findAction (char* msg, int& action);
|
||||
|
||||
// action value
|
||||
typedef enum {GET = 0x2000,QUERY,MONITORON,MONITOROFF,
|
||||
MONITORENTRY, MONITORENTRYOFF, UNKNOWN} RNSENUMVERB;
|
||||
|
||||
// get value callback
|
||||
static void getCallback (int status, void* arg, rsvcData* data);
|
||||
|
||||
// query value callback
|
||||
static void queryCallback (int status, void* arg, rsvcData* data);
|
||||
|
||||
// monitor value callback
|
||||
static void monitorCallback (int status, void* arg, rsvcData* data);
|
||||
|
||||
// monitor entry callback
|
||||
static void entryCallback (int status, void* arg, rsvcData* data);
|
||||
|
||||
// data conversion from rsvc to cdev
|
||||
static int dataRsvcToCdev (rsvcData& data, cdevData& result);
|
||||
|
||||
// data conversion from cdev to rsvc
|
||||
static int dataCdevToRsvc (cdevData& data, rsvcData& result);
|
||||
|
||||
// remove a monitor object
|
||||
int removeMonitorObject (rnsMonitorObj* mobj);
|
||||
|
||||
// monitor off a callback
|
||||
int monitorOff (rsvcData& data, rnsMonitorObj* obj);
|
||||
|
||||
// monitor off entry callback
|
||||
int monitorEntryOff (rnsMonitorObj* obj);
|
||||
|
||||
// resend a monitor callback
|
||||
int sendMonitor (rnsMonitorObj* mobj);
|
||||
|
||||
// resend a monitor entry callback
|
||||
int sendEntryMonitor (rnsMonitorObj* mobj);
|
||||
|
||||
private:
|
||||
|
||||
// two tags are needed for all serachs
|
||||
static char* stags_[];
|
||||
static int numstags_;
|
||||
|
||||
// action type
|
||||
int action_;
|
||||
|
||||
// pointer of underlying client connection
|
||||
rsvcClient* client_;
|
||||
|
||||
// friend class
|
||||
friend class rnsService;
|
||||
|
||||
};
|
||||
#endif
|
||||
128
extensions/cdevGenericServer/include/rnsService.h
Normal file
128
extensions/cdevGenericServer/include/rnsService.h
Normal file
@@ -0,0 +1,128 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// Implementation of cdev interface to resouce service client
|
||||
//
|
||||
// This is only a subset of whole APIs of rsvc client
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _NS_SERVICE_H
|
||||
#define _NS_SERVICE_H
|
||||
|
||||
#ifndef _CDEV_MANAGE_SERVERS
|
||||
#define _CDEV_MANAGE_SERVERS
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <cdevService.h>
|
||||
#include <cdevRequestObject.h>
|
||||
#include <cdevSlist.h>
|
||||
#include <rsvcClient.h>
|
||||
#include <rsvcSpec.h>
|
||||
|
||||
extern "C" RSVCAPI cdevService * newRnsService (char* name, cdevSystem* system);
|
||||
|
||||
class rnsMonitorObj;
|
||||
class rnsRequestObject;
|
||||
|
||||
class rnsService: public cdevService
|
||||
{
|
||||
public:
|
||||
// cornstructor
|
||||
rnsService (char* name, cdevSystem& system = cdevSystem::defaultSystem ());
|
||||
|
||||
int getFd (int * &fd, int &numFd);
|
||||
// PURPOSE: return channel access network file descriptors
|
||||
// REQUIRE: callers provide pointer only and don't free memory
|
||||
// PROMISE: numFd will be real number of file descriptors of the
|
||||
// channel access client. return 0: always
|
||||
|
||||
int flush (void);
|
||||
// PURPOSE: flush network requests
|
||||
// REQUIRE: nothing
|
||||
// PROMISE: return CDEV_SUCCESS: success
|
||||
|
||||
int poll (void);
|
||||
// PURPOSE: polling method
|
||||
// REQUIRE: nothing
|
||||
// PROMISE: return CDEV_SUCCESS: success. Else error
|
||||
|
||||
int pend (int fd = -1);
|
||||
// PURPOSE: handle network pending
|
||||
// REQUIRE: nothing
|
||||
// PROMISE: return CDEV_SUCCESS: success, else error
|
||||
|
||||
int pend (double seconds, int fd = -1);
|
||||
// PURPOSE: handle network pending for 'seconds'
|
||||
// REQUIRE: nothing
|
||||
// PROMISE: return 0: success. return CDEV_TIMEOUT for timeout
|
||||
|
||||
int getRequestObject (char *deviceName, char *msg,
|
||||
cdevRequestObject * &req);
|
||||
// PURPOSE: return a rnsRequestObject (called from attachPtr function
|
||||
// of cdevRequestObject class)
|
||||
// REQUIRE: right pair of deviceName and msg.
|
||||
// PROMISE: a rnsRequestObject
|
||||
|
||||
int getNameServer (cdevDevice* &rns);
|
||||
// PURPOSE: retrieve ca name server in case of missing DDL
|
||||
// REQUIRE: nothing
|
||||
// PROMISE:
|
||||
|
||||
int monitorsRestarted (void);
|
||||
// PURPOSE: check whether all monitors have been restarted or not
|
||||
// REQUIRE: nothing
|
||||
// PROMISE: 1: yes, 0: no
|
||||
|
||||
int reconnect (void);
|
||||
// PURPOSE: reconnect to name server
|
||||
// REQUIRE: nothing
|
||||
// PROMISE: CDEV_SUCCESS on sucessful connection
|
||||
|
||||
const char* className (void) const {return "rnsService";}
|
||||
|
||||
protected:
|
||||
|
||||
// deny direct access to destructor
|
||||
~rnsService (void);
|
||||
|
||||
// add a monitor object
|
||||
int addMonitorObject (rnsMonitorObj* obj);
|
||||
// remove a monitor object
|
||||
int removeMonitorObject (rnsMonitorObj* obj);
|
||||
// check whether this callback is in the list
|
||||
rnsMonitorObj* hasCallback (cdevCallback& cbk);
|
||||
|
||||
// server disconnection callback
|
||||
static void discCallback (int status, void* arg, rsvcData* data);
|
||||
|
||||
private:
|
||||
rsvcClient client_;
|
||||
int *fds_;
|
||||
int numFds_;
|
||||
|
||||
// list of monitor object
|
||||
cdevSlist monobjs_;
|
||||
|
||||
// all tags needed for this service
|
||||
static char* tags_[];
|
||||
|
||||
// number of tags needed for this service
|
||||
static int numtags_;
|
||||
|
||||
// friend class
|
||||
friend class rnsRequestObject;
|
||||
};
|
||||
#endif
|
||||
|
||||
90
extensions/cdevGenericServer/include/rsvcAcceptor.h
Normal file
90
extensions/cdevGenericServer/include/rsvcAcceptor.h
Normal file
@@ -0,0 +1,90 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// RSVC TCP Connection Acceptor
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_ACCEPTOR_H
|
||||
#define _RSVC_ACCEPTOR_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <rsvcConfig.h>
|
||||
#include <rsvcServerConfig.h>
|
||||
#include <rsvcData.h>
|
||||
#include <rsvcNetData.h>
|
||||
#include <rsvcSlist.h>
|
||||
#include <rsvcDataStoreTable.h>
|
||||
|
||||
#include <cdevAddr.h>
|
||||
#include <cdevSocketAcceptor.h>
|
||||
#include <cdevReactor.h>
|
||||
|
||||
class rsvcIO;
|
||||
|
||||
class rsvcAcceptor : public cdevEventHandler
|
||||
{
|
||||
public:
|
||||
// constructor: deny direct instantiation
|
||||
rsvcAcceptor (cdevReactor& reactor,
|
||||
rsvcDataStoreTable& table);
|
||||
|
||||
// destructor
|
||||
~rsvcAcceptor (void);
|
||||
|
||||
// open local address
|
||||
int open (unsigned short port);
|
||||
// return number of IO connections
|
||||
int numberConnections (void);
|
||||
// remove a connection from the list
|
||||
int remove (rsvcIO* channel);
|
||||
// check whether a rsvcIO is in this list
|
||||
int includes (rsvcIO* channel);
|
||||
|
||||
|
||||
// send a result to all clients
|
||||
int sendToAllConnections (rsvcNetData* data);
|
||||
|
||||
// return port number
|
||||
unsigned short port_number (void);
|
||||
|
||||
// return all connection list
|
||||
rsvcSlist& connectionList (void);
|
||||
|
||||
protected:
|
||||
// inherited operations
|
||||
int getHandle (void) const;
|
||||
int handleClose (void);
|
||||
|
||||
// inherited operations
|
||||
int handleInput (void);
|
||||
|
||||
// delete all clients : only used in the destructor
|
||||
void deleteAllConnections (void);
|
||||
|
||||
// data area
|
||||
|
||||
cdevSocketAcceptor listener_;
|
||||
cdevReactor & reactor_;
|
||||
rsvcSlist connectionList_;
|
||||
int listLock_;
|
||||
|
||||
// global data store table
|
||||
rsvcDataStoreTable& storeTable_;
|
||||
|
||||
// friend class
|
||||
friend class rsvcIO;
|
||||
};
|
||||
#endif
|
||||
|
||||
126
extensions/cdevGenericServer/include/rsvcCacheData.h
Normal file
126
extensions/cdevGenericServer/include/rsvcCacheData.h
Normal file
@@ -0,0 +1,126 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// RSVC Server Cached Data Class
|
||||
//
|
||||
// This Class models the data objects that are stored inside
|
||||
// cache information of a database
|
||||
//
|
||||
// Data always stored with key value
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_CACHE_DATA
|
||||
#define _RSVC_CACHE_DATA
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <rsvcHashable.h>
|
||||
#include <rsvcHash.h>
|
||||
#include <rsvcData.h>
|
||||
#include <rsvcNetData.h>
|
||||
|
||||
class rsvcVirtualDbase;
|
||||
class rsvcTableDef;
|
||||
class rsvcCacheDataAttr;
|
||||
|
||||
class rsvcCacheData : public rsvcHashable
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
|
||||
// construct a cache data with a rsvcData which is transmitted
|
||||
// over from network or database with key tag specified
|
||||
rsvcCacheData (rsvcData& data, rsvcVirtualDbase* dbase,
|
||||
rsvcTableDef* table);
|
||||
|
||||
// destructor
|
||||
virtual ~rsvcCacheData (void);
|
||||
|
||||
// return hash code : inherited operation from rsvcHashable
|
||||
unsigned int hash (void);
|
||||
|
||||
// monitor on/off methods for the whole data
|
||||
virtual int monitorOn (rsvcCbk& cbk);
|
||||
virtual int monitorOff (rsvcCbk& cbk);
|
||||
|
||||
// monitor on/off a single attribute
|
||||
virtual int monitorAttr (char* attr, rsvcCbk& cbk);
|
||||
virtual int monitorOffAttr (char* attr, rsvcCbk& cbk);
|
||||
|
||||
// remove monitor specified by a io ptr
|
||||
virtual int monitorOff (void* ioptr);
|
||||
|
||||
// remove all monitors and attributes
|
||||
void removeAllMonitors (void);
|
||||
|
||||
// remove all attributes
|
||||
void removeAllAttrs (void);
|
||||
|
||||
// create all attributes
|
||||
void createAllAttrs (void);
|
||||
|
||||
// check whether this data or any attributes are being monitored
|
||||
int monitored (void);
|
||||
|
||||
// assignment or update method
|
||||
int assign (rsvcData& value);
|
||||
|
||||
// in case of any change in value. send new value to all interested
|
||||
// parties
|
||||
virtual void notifyChannels (int status = RSVC_SUCCESS);
|
||||
|
||||
// notify channels with a particular attribute name
|
||||
virtual void notifyChannels (char* attr);
|
||||
|
||||
// retrieve internal data
|
||||
rsvcData& data (void);
|
||||
|
||||
// return attribute data
|
||||
rsvcCacheDataAttr* attribute (char* attr);
|
||||
|
||||
// check whether data has the same key value as data 'key'
|
||||
int sameKey (rsvcCacheData* key);
|
||||
|
||||
protected:
|
||||
|
||||
// notify a single channel denoted by a cbk pointer
|
||||
virtual void notifySingleChannel (rsvcCbk* cbk);
|
||||
|
||||
// real data
|
||||
rsvcData data_;
|
||||
|
||||
// all monitor callback list: callback pointers
|
||||
rsvcHash monitorTable_;
|
||||
|
||||
// all data for attributes
|
||||
rsvcHash attributes_;
|
||||
|
||||
// assocaited database
|
||||
rsvcVirtualDbase* database_;
|
||||
|
||||
// assocaited table definition
|
||||
rsvcTableDef* table_;
|
||||
|
||||
// friend class
|
||||
friend class rsvcCacheDataAttr;
|
||||
|
||||
|
||||
// deny copy and assignment operations
|
||||
rsvcCacheData (const rsvcCacheData& data);
|
||||
rsvcCacheData& operator = (const rsvcCacheData& data);
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
73
extensions/cdevGenericServer/include/rsvcCacheDataAttr.h
Normal file
73
extensions/cdevGenericServer/include/rsvcCacheDataAttr.h
Normal file
@@ -0,0 +1,73 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// RSVC Server Cache Data Attributes
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_CACHE_DATA_ATTR_H
|
||||
#define _RSVC_CACHE_DATA_ATTR_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <rsvcNetData.h>
|
||||
#include <rsvcHashable.h>
|
||||
#include <rsvcHash.h>
|
||||
#include <rsvcCacheData.h>
|
||||
|
||||
class rsvcCbk;
|
||||
|
||||
class rsvcCacheDataAttr : public rsvcHashable
|
||||
{
|
||||
public:
|
||||
// constructor and destructor
|
||||
rsvcCacheDataAttr (char* attr, rsvcCacheData& cache);
|
||||
virtual ~rsvcCacheDataAttr (void);
|
||||
|
||||
// return hash code
|
||||
unsigned int hash (void);
|
||||
|
||||
// monitor on/off
|
||||
// outdata's are newly allocated data.
|
||||
// remember to free those
|
||||
virtual int monitorOn (rsvcCbk& cbk);
|
||||
virtual int monitorOff (rsvcCbk& cbk);
|
||||
// monitor off all with same ioptr
|
||||
virtual int monitorOff (void* ioptr);
|
||||
virtual int getValue (rsvcCbk& cbk);
|
||||
|
||||
// return attribute name
|
||||
char* attrName (void) const;
|
||||
|
||||
// notify channels
|
||||
void notifyChannels (void);
|
||||
|
||||
protected:
|
||||
|
||||
// remove all callbacks from the lists
|
||||
void removeAllCbks (void);
|
||||
|
||||
// attribute name
|
||||
char* name_;
|
||||
|
||||
// all callback list : (with all cbk pointers)
|
||||
rsvcHash monitorList_;
|
||||
|
||||
// whole cached data storage
|
||||
rsvcCacheData& cache_;
|
||||
|
||||
// deny access to copy and assignment operations
|
||||
rsvcCacheDataAttr (const rsvcCacheDataAttr& attr);
|
||||
rsvcCacheDataAttr& operator = (const rsvcCacheDataAttr& attr);
|
||||
};
|
||||
#endif
|
||||
50
extensions/cdevGenericServer/include/rsvcCallback.h
Normal file
50
extensions/cdevGenericServer/include/rsvcCallback.h
Normal file
@@ -0,0 +1,50 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// RSVC Callback Class for Client
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_CALLBACK_H
|
||||
#define _RSVC_CALLBACK_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <rsvcData.h>
|
||||
|
||||
typedef void (*rsvcCbkFunc) (int status, void* arg, rsvcData* data);
|
||||
|
||||
class RSVC_CLASS_SPEC rsvcCallback
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
rsvcCallback (void);
|
||||
rsvcCallback (rsvcCbkFunc func, void* arg);
|
||||
rsvcCallback (const rsvcCallback& cbk);
|
||||
rsvcCallback& operator = (const rsvcCallback& cbk);
|
||||
// destructor
|
||||
~rsvcCallback (void);
|
||||
|
||||
int operator == (const rsvcCallback& cbk);
|
||||
int operator != (const rsvcCallback& cbk);
|
||||
|
||||
virtual rsvcCbkFunc cbkFunc (void) const;
|
||||
virtual void* userarg (void) const;
|
||||
|
||||
// return whether this callback is empty
|
||||
int empty (void);
|
||||
|
||||
private:
|
||||
rsvcCbkFunc cbk_;
|
||||
void* arg_;
|
||||
};
|
||||
#endif
|
||||
105
extensions/cdevGenericServer/include/rsvcCbk.h
Normal file
105
extensions/cdevGenericServer/include/rsvcCbk.h
Normal file
@@ -0,0 +1,105 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// RSVC Callback Class (Used on Server/Client Side)
|
||||
//
|
||||
// This class contains protocol information related to callbacks
|
||||
// 1. operation code
|
||||
// 2. request id
|
||||
// 3. socket id -->for server only
|
||||
// 4. client id
|
||||
// 5. callback id -->from client to server
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_CBK_H
|
||||
#define _RSVC_CBK_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <rsvcErr.h>
|
||||
#include <rsvcStreamable.h>
|
||||
#include <rsvcHashable.h>
|
||||
|
||||
class rsvcCbk : public rsvcStreamable, public rsvcHashable
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
rsvcCbk (void);
|
||||
rsvcCbk (int opcode, int cbkid, int reqid, int clientid,
|
||||
int socketid = 0, int status = RSVC_SUCCESS,
|
||||
void* usrptr = 0);
|
||||
rsvcCbk (const rsvcCbk& cbk);
|
||||
rsvcCbk& operator = (const rsvcCbk& cbk);
|
||||
~rsvcCbk (void);
|
||||
|
||||
// clean up all values
|
||||
void cleanup (void);
|
||||
|
||||
void socketid (int id);
|
||||
int socketid (void) const;
|
||||
|
||||
void cbkstatus (int st);
|
||||
int cbkstatus (void) const;
|
||||
|
||||
int reqid (void) const;
|
||||
void reqid (int req);
|
||||
int opcode (void) const;
|
||||
void opcode (int op);
|
||||
int cbkid (void) const;
|
||||
void cbkid (int id);
|
||||
int clientid (void) const;
|
||||
void clientid (int cid);
|
||||
|
||||
// use by local only , not transmitted through wire
|
||||
void* userptr (void) const;
|
||||
void userptr (void* ptr);
|
||||
|
||||
// inherited operation
|
||||
unsigned int hash (void);
|
||||
|
||||
size_t streamSize (void);
|
||||
// stream out to a newly allocated buffer with size 'size'
|
||||
int streamOut (char** buf, size_t* size);
|
||||
// stream out to a preallocate buffer with buffer size 'size'
|
||||
int streamOut (char* buf, size_t len);
|
||||
// stream in from a buffer
|
||||
int streamIn (char* buf, size_t len);
|
||||
|
||||
// check whether two callbacks are the same.
|
||||
// if checkreq == 1, check reqid otherwise no
|
||||
// this function is used by server side to check
|
||||
// whether a monitoroff callback is inside the callback table
|
||||
// on the server.
|
||||
static int sameCallback (rsvcCbk* cbk1, rsvcCbk* callback2,
|
||||
int checkreq = 1);
|
||||
|
||||
// check whether a callback coming back from the server
|
||||
// match a callback in the table
|
||||
int match (rsvcCbk* scbk);
|
||||
|
||||
private:
|
||||
// all data
|
||||
int opcode_;
|
||||
int cbkid_;
|
||||
int reqid_;
|
||||
int clientid_;
|
||||
int socketid_;
|
||||
int status_;
|
||||
|
||||
// used by local only, not transmitted on wire
|
||||
void* private_;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
290
extensions/cdevGenericServer/include/rsvcClient.h
Normal file
290
extensions/cdevGenericServer/include/rsvcClient.h
Normal file
@@ -0,0 +1,290 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// RSVC Client Handler Class
|
||||
//
|
||||
// Limitation on monitor: Callers cannot use same function with same user
|
||||
// argument to monitor on different pieces
|
||||
// of database
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_CLIENT_H
|
||||
#define _RSVC_CLIENT_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <time.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include <rsvcErr.h>
|
||||
#include <rsvcNetData.h>
|
||||
#include <rsvcSlist.h>
|
||||
#include <rsvcHash.h>
|
||||
#include <rsvcCallback.h>
|
||||
#include <rsvcConfig.h>
|
||||
|
||||
class rsvcClientLocker;
|
||||
|
||||
class RSVC_CLASS_SPEC rsvcClient
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
rsvcClient (void);
|
||||
~rsvcClient (void);
|
||||
|
||||
// connect to a rsvc server
|
||||
// if timeout is zero, blocked connect will be used
|
||||
int connect (char* host, unsigned short port,
|
||||
double timeout = 0.0);
|
||||
|
||||
// disconnect from the server
|
||||
int disconnect (void);
|
||||
|
||||
// return whether this client is connected
|
||||
int connected (void);
|
||||
|
||||
// register a disconnect callback
|
||||
int disconnectCallback (rsvcCbkFunc func, void* arg);
|
||||
|
||||
// get tcp file descriptor
|
||||
int getFd (void) const;
|
||||
|
||||
// pend io on this connected client
|
||||
// Wait until outstanding events occur
|
||||
// seconds = 0.0 polling
|
||||
int pendIO (double seconds);
|
||||
|
||||
// wait on this connection forever
|
||||
int pendIO (void);
|
||||
|
||||
// operations
|
||||
|
||||
// create a table with definition defined in the data object
|
||||
// the data object has to contain the following tags
|
||||
// "key" "name"
|
||||
// "keyExp" "attributename" or "attr0+attr1"
|
||||
// "keyType" anything
|
||||
// followed by taged values
|
||||
|
||||
// data return from server inside callback is the database definition
|
||||
int createMemDbase (char* tablename, rsvcData& data,
|
||||
rsvcCbkFunc func, void* arg);
|
||||
|
||||
// open a database
|
||||
// data return from server inside callback is the database definition
|
||||
int openDatabase (char* tablename, rsvcData& data,
|
||||
rsvcCbkFunc func, void* arg);
|
||||
|
||||
// insert data into database
|
||||
// data must be match table definition
|
||||
int insertValue (char* name, rsvcData& data,
|
||||
rsvcCbkFunc func, void* arg,
|
||||
int overwrite = 0);
|
||||
|
||||
// get data out from database
|
||||
// data either contain a tagged value to denote a index value
|
||||
// Example: "id", "model+gold"
|
||||
// or contains multiple tagged values which can be constructed
|
||||
// into a key value
|
||||
int getValue (char* name, rsvcData& data,
|
||||
rsvcCbkFunc func, void* arg);
|
||||
|
||||
// delete data from database
|
||||
// data either contain a tagged value to denote a index value
|
||||
// Example: "id", "model+gold"
|
||||
// or contains multiple tagged values which can be constructed
|
||||
// into a key value
|
||||
int delValue (char* name, rsvcData& data,
|
||||
rsvcCbkFunc func, void* arg);
|
||||
|
||||
|
||||
// set value for a datum inside database
|
||||
// data either contain a tagged value to denote a index value
|
||||
// Example: "id", "model+gold"
|
||||
// or contains multiple tagged values which can be constructed
|
||||
// into a key value
|
||||
// plus a subset of tagged values defined in the table definition
|
||||
int setValue (char* name, rsvcData& data,
|
||||
rsvcCbkFunc func, void* arg);
|
||||
|
||||
// monitor incoming entries inside database
|
||||
// any insertion to a database will trigger a callback
|
||||
int monitorIncomingEntries (char* name, rsvcData& data,
|
||||
rsvcCbkFunc func, void* arg);
|
||||
|
||||
// stop monitoring the incoming entries inside database
|
||||
int monitorOffIncomingEntries (char* name, rsvcData& data,
|
||||
rsvcCbkFunc func, void* arg);
|
||||
|
||||
|
||||
// monitor on a data inside a database
|
||||
// any changes to this data will trigger a callback
|
||||
// data either contain a tagged value to denote a index value
|
||||
// Example: "id", "model+gold"
|
||||
// or contains multiple tagged values which can be constructed
|
||||
// into a key value
|
||||
int monitorValue (char* name, rsvcData& data,
|
||||
rsvcCbkFunc func, void* arg);
|
||||
|
||||
|
||||
// monitor off on a data inside a database
|
||||
// data either contain a tagged value to denote a index value
|
||||
// Example: "id", "model+gold"
|
||||
// or contains multiple tagged values which can be constructed
|
||||
// into a key value
|
||||
int monitorOffValue (char* name, rsvcData& data,
|
||||
rsvcCbkFunc func, void* arg);
|
||||
|
||||
// monitor a single attribute of a data inside a database
|
||||
// any changes to this attribute will trigger a callback containing a whole data
|
||||
// data either contain a tagged value to denote a index value
|
||||
// Example: "id", "model+gold"
|
||||
// or contains multiple tagged values which can be constructed
|
||||
// into a key value
|
||||
int monitorAttr (char* name, char* attrname,
|
||||
rsvcData& data, rsvcCbkFunc func, void* arg);
|
||||
|
||||
|
||||
// monitor a single attribute of a data inside a database
|
||||
// any changes to this attribute will trigger a callback containing a whole data
|
||||
// data either contain a tagged value to denote a index value
|
||||
// Example: "id", "model+gold"
|
||||
// or contains multiple tagged values which can be constructed
|
||||
// into a key value
|
||||
int monitorOffAttr (char* name, char* attrname,
|
||||
rsvcData& data, rsvcCbkFunc func, void* arg);
|
||||
|
||||
// query a particular database 'name'
|
||||
// query msg can be like regular C logic expression for all
|
||||
// attributes
|
||||
int query (char* name, char* qmsg,
|
||||
rsvcCbkFunc func, void* arg);
|
||||
|
||||
// test purpose only
|
||||
void shutdownServer (void);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// non block tcp connect
|
||||
static int connect_nonblock (int fd, struct sockaddr* addr,
|
||||
size_t addrlen,
|
||||
struct timeval* timeout);
|
||||
|
||||
// cleanup all callbacks
|
||||
void cleanupCallbacks (void);
|
||||
|
||||
// call all disconnection callbacks
|
||||
void callAllDiscCbks (void);
|
||||
|
||||
// stream out a network data and return actual number of bytes
|
||||
int streamData (rsvcNetData& data);
|
||||
|
||||
// low level handle input and handle close
|
||||
int handle_input (int fd);
|
||||
int handle_close (int fd);
|
||||
|
||||
// read and write for block socket
|
||||
static int read_n (int fd, char* buffer, size_t len);
|
||||
static int write_n (int fd, const char* buffer, size_t len);
|
||||
|
||||
// real processing function
|
||||
int processData (rsvcNetData& data);
|
||||
|
||||
// real command callback
|
||||
int commandCallback (int opcode, rsvcData& data,
|
||||
rsvcCbkFunc func, void* arg);
|
||||
|
||||
|
||||
// monitor command callback
|
||||
int monitorCallback (int opcode, rsvcData& data,
|
||||
rsvcCbkFunc func, void* arg);
|
||||
|
||||
// monitoroff command callback
|
||||
int monitorOffCallback (int opcode, rsvcData& data,
|
||||
rsvcCbkFunc func, void* arg);
|
||||
|
||||
// handle callbacks from server
|
||||
int cmdCbkFromServer (int status, rsvcData& data, rsvcCbk& cbk);
|
||||
int monitorCbkFromServer (int status, rsvcData& data, rsvcCbk& cbk);
|
||||
|
||||
// check a monitor callback is in the table
|
||||
rsvcCbk* monitorCbkInTable (rsvcCbkFunc func, void* arg);
|
||||
|
||||
|
||||
private:
|
||||
// flag of connection
|
||||
int connected_;
|
||||
|
||||
// tcp socket to the server
|
||||
int tcp_fd_;
|
||||
|
||||
// server information
|
||||
char* server_host_;
|
||||
unsigned short server_port_;
|
||||
|
||||
// lock for client object to prevent from this object being called
|
||||
// recursivly
|
||||
int lock_;
|
||||
void lock (void);
|
||||
void unlock (void);
|
||||
|
||||
// request id
|
||||
int reqid_;
|
||||
// unique callback id
|
||||
int cbkid_;
|
||||
|
||||
|
||||
// disconnection callback list
|
||||
rsvcSlist discCbkList_;
|
||||
|
||||
// all send/get command callback list
|
||||
rsvcSlist cmdCbkList_;
|
||||
// all monitor callback list
|
||||
rsvcHash monitorCbkTable_;
|
||||
|
||||
// data convertion buffer
|
||||
char* cbuffer_;
|
||||
size_t cbuflen_;
|
||||
|
||||
// friend class
|
||||
friend class rsvcClientLocker;
|
||||
friend class rsvcDBHandler;
|
||||
|
||||
// deny copy and assignment operator
|
||||
rsvcClient (const rsvcClient& client);
|
||||
rsvcClient& operator = (const rsvcClient& client);
|
||||
|
||||
};
|
||||
|
||||
class rsvcClientLocker
|
||||
{
|
||||
public:
|
||||
rsvcClientLocker (rsvcClient* client);
|
||||
~rsvcClientLocker (void);
|
||||
|
||||
private:
|
||||
rsvcClient* cl_;
|
||||
|
||||
// deny copy and assignment operations
|
||||
rsvcClientLocker (const rsvcClientLocker& locker);
|
||||
rsvcClientLocker& operator = (const rsvcClientLocker& locker);
|
||||
};
|
||||
|
||||
#endif
|
||||
62
extensions/cdevGenericServer/include/rsvcConfig.h
Normal file
62
extensions/cdevGenericServer/include/rsvcConfig.h
Normal file
@@ -0,0 +1,62 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// RSVC Configuration Header
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_CONFIG_H
|
||||
#define _RSVC_CONFIG_H
|
||||
|
||||
#define RSVC_SERVER_PORT 10932
|
||||
#define RSVC_MAX_KEY_LEN (unsigned int)256
|
||||
#define RSVC_KEY_NAME "key"
|
||||
#define RSVC_TABLE_NAME "table"
|
||||
#define RSVC_TABLE_NAME_EXT ".def"
|
||||
#define RSVC_KEY_TYPE_NAME "keyType"
|
||||
#define RSVC_KEY_EXP_NAME "keyExp"
|
||||
#define RSVC_MONITOR_TAG "monitorOn"
|
||||
#define RSVC_QUERY_TAG "query"
|
||||
#define RSVC_CACHE_MAX 20 /* tuned for name server */
|
||||
#define RSVC_CACHE_LF 5
|
||||
#define RSVC_RLIMIT_NOFILE 256
|
||||
#define RSVC_UDP_BUFFER_SIZE 4096
|
||||
|
||||
|
||||
#define RSVC_OP_UNKNOWN (unsigned int)2000
|
||||
|
||||
#define RSVC_CREATE_TABLE (unsigned int)1000
|
||||
#define RSVC_CREATE_MEMTABLE (unsigned int)1001
|
||||
#define RSVC_OPEN_DBASE (unsigned int)1002
|
||||
#define RSVC_GET (unsigned int)1010
|
||||
#define RSVC_SET (unsigned int)1011
|
||||
#define RSVC_DEL (unsigned int)1012
|
||||
#define RSVC_INSERT (unsigned int)1013
|
||||
#define RSVC_OVERWRITE (unsigned int)1014
|
||||
#define RSVC_QUERY (unsigned int)1020
|
||||
|
||||
#define RSVC_MONITOR_ON (unsigned int)1500
|
||||
#define RSVC_MONITOR_ONATTR (unsigned int)1501
|
||||
#define RSVC_MONITOR_OFF (unsigned int)1600
|
||||
#define RSVC_MONITOR_OFFATTR (unsigned int)1601
|
||||
|
||||
#define RSVC_MONITOR_ENTRIES (unsigned int)1650
|
||||
#define RSVC_MONITOR_OFFENTRIES (unsigned int)1651
|
||||
|
||||
#define RSVC_SERVER_EXIT (unsigned int)1700
|
||||
|
||||
#define RSVC_DATA_IN_MEMORY 1
|
||||
#define RSVC_DATA_ON_DISK 2
|
||||
|
||||
#include <rsvcLocalConfig.h>
|
||||
|
||||
#endif
|
||||
46
extensions/cdevGenericServer/include/rsvcDBT.h
Normal file
46
extensions/cdevGenericServer/include/rsvcDBT.h
Normal file
@@ -0,0 +1,46 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// C++ wrapper class for DBT class with user allocated memory
|
||||
//
|
||||
// Reason: Enable automatic memory release
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_DBT_H
|
||||
#define _RSVC_DBT_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <db.h>
|
||||
|
||||
class rsvcDBT
|
||||
{
|
||||
public:
|
||||
rsvcDBT (void);
|
||||
~rsvcDBT (void);
|
||||
|
||||
void* data (void) const;
|
||||
void data (void *ptr, int dealloc = 1);
|
||||
size_t size (void) const;
|
||||
void size (size_t len);
|
||||
void datacpy (void* data);
|
||||
|
||||
// return data pointer to internal DBT
|
||||
DBT* dbt (void);
|
||||
|
||||
private:
|
||||
DBT data_;
|
||||
int dealloc_;
|
||||
};
|
||||
#endif
|
||||
316
extensions/cdevGenericServer/include/rsvcData.h
Normal file
316
extensions/cdevGenericServer/include/rsvcData.h
Normal file
@@ -0,0 +1,316 @@
|
||||
//---------------------------------------------------------------------------
|
||||
// Copyright (c) 1991,1992 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//----------------------------------------------------------------------------
|
||||
//
|
||||
// description: rsvcData.h
|
||||
// Self descibing data structure to manage the storage and transport
|
||||
// of data between local rsvc functions, as well as remote client and
|
||||
// server applications.
|
||||
//
|
||||
// Author: Walt Akers and Danjin Wu
|
||||
//
|
||||
//
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
#ifndef _RSVC_DATA_H
|
||||
#define _RSVC_DATA_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <time.h>
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include <rsvcErr.h>
|
||||
#include <rsvcSpec.h>
|
||||
#include <rsvcDataEntry.h>
|
||||
|
||||
#ifndef hpux
|
||||
char * ltoa (long val);
|
||||
char * ultoa (unsigned long val);
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
extern "C" char *ctime (__const time_t *__timer) __THROW;
|
||||
#endif
|
||||
|
||||
|
||||
class RSVC_CLASS_SPEC rsvcData
|
||||
{
|
||||
friend class rsvcDataIterator;
|
||||
protected:
|
||||
rsvcDataEntry *entries;
|
||||
|
||||
// *********************************************************************
|
||||
// * copy:
|
||||
// * This function copies the contents of the rsvcData object
|
||||
// * specified by data into this rsvcData object. It is used by
|
||||
// * both the copy constructor and by the assignment operator.
|
||||
// *********************************************************************
|
||||
rsvcData & copy (const rsvcData & data);
|
||||
|
||||
public:
|
||||
|
||||
// *********************************************************************
|
||||
// * Convert data from a floating point value to a string.
|
||||
// *********************************************************************
|
||||
static char * rsvc_gcvt(float value, size_t ndigit, char *buf);
|
||||
static char * rsvc_gcvt(double value, size_t ndigit, char * buf);
|
||||
|
||||
// *********************************************************************
|
||||
// * lookupTag:
|
||||
// * This function is for internal use and allows a cdevData object
|
||||
// * to locate and optionally create a tagged data item.
|
||||
// *********************************************************************
|
||||
rsvcDataEntry * lookupTag(char * ctag, int create = 0);
|
||||
|
||||
// *********************************************************************
|
||||
// * setupTag:
|
||||
// * This function is for internal use and is used to prepare a new
|
||||
// * rsvcDataEntry object prior to inserting data into it.
|
||||
// *********************************************************************
|
||||
rsvcDataEntry * setupTag (char* tag, rsvcDataTypes type, size_t elemSize,
|
||||
size_t numElems, size_t numDims );
|
||||
|
||||
// *********************************************************************
|
||||
// * insert:
|
||||
// * The following functions insert a data entry into this datan
|
||||
// *********************************************************************
|
||||
int insert (rsvcDataEntry* entry);
|
||||
|
||||
|
||||
|
||||
// *********************************************************************
|
||||
// * rsvcData:
|
||||
// * This is the default constructor, it simply initializes
|
||||
// * variables within the rsvcData object.
|
||||
// *********************************************************************
|
||||
rsvcData ( void );
|
||||
|
||||
// *********************************************************************
|
||||
// * rsvcData:
|
||||
// * Copy constructor. This constructor duplicates the rsvcData
|
||||
// * object that it has been passed as a parameter.
|
||||
// *********************************************************************
|
||||
rsvcData ( const rsvcData & data );
|
||||
|
||||
// *********************************************************************
|
||||
// * ~rsvcData:
|
||||
// * This is the default destructor for the rsvcData object. It
|
||||
// * frees any memory allocated for storage and deletes the object.
|
||||
// *********************************************************************
|
||||
~rsvcData( void );
|
||||
|
||||
// *********************************************************************
|
||||
// * Assignment operator:
|
||||
// * This function copies the contents of a rsvcData object to this
|
||||
// * object.
|
||||
// *********************************************************************
|
||||
rsvcData & operator = (const rsvcData & data);
|
||||
|
||||
// *********************************************************************
|
||||
// * Append operation:
|
||||
// * This operation will append a rsvcData onto an existing rsvcData
|
||||
// * and return this object. If there is confilicts among tags, the
|
||||
// * appended one wins
|
||||
// *********************************************************************
|
||||
rsvcData& operator += (const rsvcData& data);
|
||||
|
||||
// *********************************************************************
|
||||
// * asciiDump:
|
||||
// * Performs a diagnostic dump of the entire contents of the
|
||||
// * rsvcData object to the specified file pointer.
|
||||
// *********************************************************************
|
||||
#ifdef _WIN32
|
||||
inline void asciiDump (FILE* fp = stdout) {
|
||||
int fd = _fileno (fp);
|
||||
long osfHandle = _get_osfhandle (fd);
|
||||
asciiDump (osfHandle);
|
||||
_lseek(fd, 0L, SEEK_END);
|
||||
}
|
||||
void asciiDump (long osfHandle);
|
||||
#else
|
||||
void asciiDump ( FILE * fp = stdout );
|
||||
#endif
|
||||
|
||||
// *********************************************************************
|
||||
// * Stream Utilities
|
||||
// * These functions provide the mechanisms for converting a rsvcData
|
||||
// * object into a network portable bninary stream, and then
|
||||
// * reconstructing them after transport.
|
||||
// *********************************************************************
|
||||
|
||||
#define _RSVC_MAGIC_NUM 0x2c45da2a
|
||||
|
||||
virtual int streamSize (size_t * bufLen, size_t * elementCount);
|
||||
virtual int streamOut ( char ** buf, size_t * bufLen );
|
||||
virtual int streamOut ( char * buf, size_t bufLen, size_t count);
|
||||
virtual int streamIn ( char * buf, size_t bufLen);
|
||||
|
||||
// *********************************************************************
|
||||
// * remove:
|
||||
// * Removes rsvcDataEntry objects from the rsvcData object by tag
|
||||
// * integer or by tag string. If no tag is specified, then all
|
||||
// * rsvcDataEntry objects will be removed.
|
||||
// *********************************************************************
|
||||
void remove( void );
|
||||
void remove( char * ctag );
|
||||
|
||||
// *********************************************************************
|
||||
// * changeTag:
|
||||
// * Replace a new tag with the old one within the
|
||||
// * rsvcData object. If the old one can not be not found,
|
||||
// * RSVC_NOTFOUND is returned. If the new tag has already
|
||||
// * been found in that rsvcData object, RSVC_ERROR is returned.
|
||||
// *********************************************************************
|
||||
int changeTag(char *c_oldTag, char *c_newTag);
|
||||
|
||||
|
||||
// *********************************************************************
|
||||
// * dupWithTag:
|
||||
// * copy data with tag 'old_tag' to tag 'new_tag'.
|
||||
// * rsvcData object. If the old one can not be not found,
|
||||
// * RSVC_NOTFOUND is returned. If the new tag has already
|
||||
// * been found in that rsvcData object, RSVC_ERROR is returned.
|
||||
// *********************************************************************
|
||||
int dupWithTag (char* old_tag, char* new_tag);
|
||||
|
||||
// *********************************************************************
|
||||
// * getType:
|
||||
// * Retrieves the rsvcDataTypes of the referenced tagged data item.
|
||||
// * If no item with that tag is within the rsvcData object, then
|
||||
// * RSVC_INVALID is returned.
|
||||
// *********************************************************************
|
||||
rsvcDataTypes getType(char *ctag);
|
||||
|
||||
|
||||
// *********************************************************************
|
||||
// * getDim:
|
||||
// * Obtains the number of dimensions in the specified tagged data
|
||||
// * item. Returns RSVC_SUCCESS if the tagged item exists, otherwise,
|
||||
// * RSVC_NOTFOUND is returned.
|
||||
// **********************************************************************
|
||||
int getDim(char *ctag, size_t *dim);
|
||||
|
||||
// *********************************************************************
|
||||
// * getElems:
|
||||
// * Obtains the number of elements in the specified tagged data
|
||||
// * item. Returns RSVC_SUCCESS if the tagged item exists, otherwise,
|
||||
// * RSVC_NOTFOUND is returned.
|
||||
// **********************************************************************
|
||||
int getElems(char *ctag, size_t *elems);
|
||||
|
||||
// *********************************************************************
|
||||
// * insert:
|
||||
// * The following functions allow the insertion of scalar data into
|
||||
// * a rsvcData object.
|
||||
// *********************************************************************
|
||||
int insert ( char * ctag, BYTE data);
|
||||
int insert ( char * ctag, short data);
|
||||
int insert ( char * ctag, unsigned short data);
|
||||
int insert ( char * ctag, int data);
|
||||
int insert ( char * ctag, unsigned int data);
|
||||
int insert ( char * ctag, long data);
|
||||
int insert ( char * ctag, unsigned long data);
|
||||
int insert ( char * ctag, float data);
|
||||
int insert ( char * ctag, double data);
|
||||
int insert ( char * ctag, rsvc_TS_STAMP data);
|
||||
|
||||
// ********************************************************************
|
||||
// * insert:
|
||||
// * The following functions allow the insertion of arrays of data
|
||||
// * into a rsvcData object. The len variable contains the total
|
||||
// * number of elements to be inserted, the ndim variable indicates
|
||||
// * the number of dimensions in the array.
|
||||
// ********************************************************************
|
||||
int insert (char * ctag, BYTE * data, size_t len, size_t ndim = 1);
|
||||
int insert (char * ctag, short * data, size_t len, size_t ndim = 1);
|
||||
int insert (char * ctag, unsigned short * data, size_t len, size_t ndim = 1);
|
||||
int insert (char * ctag, int * data, size_t len, size_t ndim = 1);
|
||||
int insert (char * ctag, unsigned int * data, size_t len, size_t ndim = 1);
|
||||
int insert (char * ctag, long * data, size_t len, size_t ndim = 1);
|
||||
int insert (char * ctag, unsigned long * data, size_t len, size_t ndim = 1);
|
||||
int insert (char * ctag, float * data, size_t len, size_t ndim = 1);
|
||||
int insert (char * ctag, double * data, size_t len, size_t ndim = 1);
|
||||
int insert (char * ctag, rsvc_TS_STAMP *data, size_t len, size_t ndim =1 );
|
||||
|
||||
// *********************************************************************
|
||||
// * insert:
|
||||
// * The following functions insert character strings and arrays of
|
||||
// * character strings. Their treatment is different from the scalar
|
||||
// * data types.
|
||||
// *********************************************************************
|
||||
int insert ( char * ctag, char * data);
|
||||
int insert ( char * ctag, char ** data, size_t len = 0, size_t ndim = 1);
|
||||
|
||||
// *********************************************************************
|
||||
// * get:
|
||||
// * This group of functions allows the user to extract scalar and
|
||||
// * array data from the rsvcData object.
|
||||
// *********************************************************************
|
||||
int get(char * ctag, BYTE * data);
|
||||
int get(char * ctag, short * data);
|
||||
int get(char * ctag, unsigned short * data);
|
||||
int get(char * ctag, int * data);
|
||||
int get(char * ctag, unsigned int * data);
|
||||
int get(char * ctag, long * data);
|
||||
int get(char * ctag, unsigned long * data);
|
||||
int get(char * ctag, float * data);
|
||||
int get(char * ctag, double * data);
|
||||
int get(char * ctag, char * data, size_t len);
|
||||
int get(char * ctag, char ** data);
|
||||
int get(char * ctag, rsvc_TS_STAMP * data);
|
||||
|
||||
// *********************************************************************
|
||||
// * find:
|
||||
// * These functions allow the user to obtain a pointer to data
|
||||
// * within the actual data variables within the rsvcData object.
|
||||
// *********************************************************************
|
||||
int find(char * ctag, void* &data);
|
||||
|
||||
// *********************************************************************
|
||||
// * replace:
|
||||
// * This function allows part or all taged values being replaced
|
||||
// * by other taged values represented by a rsvcData
|
||||
// *********************************************************************
|
||||
int replace (const rsvcData& rep);
|
||||
|
||||
// *********************************************************************
|
||||
// * operator ==, operator !=:
|
||||
// * These methods provides a fast way for the caller to identify if two
|
||||
// * rsvcData objects contain the identical fields and values...
|
||||
// *********************************************************************
|
||||
int operator == (rsvcData & data);
|
||||
int operator != (rsvcData & data) { return !(operator == (data)); }
|
||||
};
|
||||
|
||||
|
||||
|
||||
class rsvcDataIterator
|
||||
{
|
||||
public:
|
||||
rsvcDataIterator (rsvcData* data);
|
||||
~rsvcDataIterator (void) {};
|
||||
int init (void);
|
||||
int operator ! (void);
|
||||
int operator ++(void);
|
||||
const char* tag (void);
|
||||
rsvcDataEntry* operator () (void);
|
||||
|
||||
protected:
|
||||
rsvcData *dataobj_;
|
||||
rsvcDataEntry *cur_;
|
||||
};
|
||||
|
||||
#endif
|
||||
335
extensions/cdevGenericServer/include/rsvcDataEntry.h
Normal file
335
extensions/cdevGenericServer/include/rsvcDataEntry.h
Normal file
@@ -0,0 +1,335 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 1991,1992 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// description: rsvcDataEntry.h
|
||||
// This file defines the classes necessary for storage of an individual
|
||||
// tagged data item within a rsvcData class object.
|
||||
//
|
||||
// Author: Walt Akers & Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _RSVC_DATA_ENTRY_H_
|
||||
#define _RSVC_DATA_ENTRY_H_
|
||||
|
||||
#include <string.h>
|
||||
#include <rsvcDataTypes.h>
|
||||
|
||||
// #############################################################################
|
||||
// # rsvcDataEntryStorage:
|
||||
// # This class contains the data elements and methods necessary to store data
|
||||
// # associated with one tagged data item.
|
||||
// #
|
||||
// # Note: Because the rsvcData object must actively manipulate the data in
|
||||
// # this structure - it has been made public to increase access speed
|
||||
// # and to allow the subclassing of the rsvcData object.
|
||||
// #############################################################################
|
||||
class rsvcDataEntryStorage
|
||||
{
|
||||
public:
|
||||
// *************************************************************
|
||||
// * tag_:
|
||||
// * This is char string value that is used to uniquely identify
|
||||
// * a data element within a rsvcData object.
|
||||
// *************************************************************
|
||||
char tag_[RSVC_TAG_MAX_LEN];
|
||||
|
||||
// *************************************************************
|
||||
// * dataType_:
|
||||
// * This is the data type of the tagged data item that is to be
|
||||
// * stored in this rsvcDataEntryStorage object.
|
||||
// *************************************************************
|
||||
rsvcDataTypes dataType_;
|
||||
|
||||
// *************************************************************
|
||||
// * size_:
|
||||
// * This variable is the allocated size of the buffer_ which is
|
||||
// * used to store both the array data and its associated bounds
|
||||
// * information.
|
||||
// *************************************************************
|
||||
size_t size_;
|
||||
|
||||
// *************************************************************
|
||||
// * dim_:
|
||||
// * This variable indicates the user specified number of
|
||||
// * dimensions that the array represents.
|
||||
// * either 0 or 1
|
||||
// *************************************************************
|
||||
size_t dim_;
|
||||
|
||||
// *************************************************************
|
||||
// * elems_:
|
||||
// * This variable contains the maximum number of elements that
|
||||
// * the array may contain.
|
||||
// *************************************************************
|
||||
size_t elems_;
|
||||
|
||||
// *************************************************************
|
||||
// * bytes_:
|
||||
// * This variable contains the number of bytes per element.
|
||||
// *************************************************************
|
||||
size_t bytes_;
|
||||
|
||||
// *************************************************************
|
||||
// * buffer_:
|
||||
// * This is the buffer that is allocated to store data and
|
||||
// * bounds information.
|
||||
// *************************************************************
|
||||
unsigned char * buffer_;
|
||||
|
||||
// *************************************************************
|
||||
// * data_:
|
||||
// * This is a union that is used to store scalar data and a
|
||||
// * pointer to the array data this is stored within this object
|
||||
// *************************************************************
|
||||
union dataUnion {
|
||||
BYTE cval;
|
||||
short sval;
|
||||
unsigned short usval;
|
||||
long lval;
|
||||
unsigned long ulval;
|
||||
float fval;
|
||||
double dval;
|
||||
void * vptr;
|
||||
BYTE * cptr;
|
||||
short * sptr;
|
||||
unsigned short * usptr;
|
||||
long * lptr;
|
||||
unsigned long * ulptr;
|
||||
float * fptr;
|
||||
double * dptr;
|
||||
char * str;
|
||||
char ** strarr;
|
||||
rsvc_TS_STAMP ts;
|
||||
rsvc_TS_STAMP * tsptr;
|
||||
} data_;
|
||||
|
||||
// *************************************************************
|
||||
// * rsvcDataEntryStorage:
|
||||
// * Default constructor for the rsvcDataEntryStorage class. It sets
|
||||
// * the buffer_ pointer to NULL to prevent deletion of non-
|
||||
// * allocated memory, and then calls the clear method to
|
||||
// * initialize all data variables.
|
||||
// *************************************************************
|
||||
rsvcDataEntryStorage ( void ) : buffer_(0) {
|
||||
clear();
|
||||
}
|
||||
|
||||
// *************************************************************
|
||||
// * ~rsvcDataEntryStorage:
|
||||
// * Default destructor for the rsvcDaaEntry class. It calls
|
||||
// * the clear method to release and reinitialize all data
|
||||
// * elements.
|
||||
// *************************************************************
|
||||
~rsvcDataEntryStorage ( void ) {
|
||||
clear();
|
||||
}
|
||||
|
||||
// *************************************************************
|
||||
// * clear:
|
||||
// * Releases and reinitializes all data variables.
|
||||
// *************************************************************
|
||||
void clear ( void ) {
|
||||
deallocate();
|
||||
tag_[0] = 0;
|
||||
dataType_ = RSVC_INVALID;
|
||||
}
|
||||
|
||||
// *************************************************************
|
||||
// * allocate:
|
||||
// * Allocates a block of memory sufficient to store a caller
|
||||
// * specified number of bytes. If sufficient space has already
|
||||
// * been allocated, then it will be used, otherwise, a new
|
||||
// * block will be created to service the request.
|
||||
// *************************************************************
|
||||
void allocate ( size_t dimensions, size_t elems, size_t bytesPerElem )
|
||||
{
|
||||
size_t newBlockSize = (elems * bytesPerElem);
|
||||
|
||||
if(buffer_==NULL || newBlockSize>size_)
|
||||
{
|
||||
deallocate();
|
||||
buffer_ = ::new unsigned char[newBlockSize];
|
||||
size_ = newBlockSize;
|
||||
}
|
||||
dim_ = dimensions;
|
||||
elems_ = elems;
|
||||
bytes_ = bytesPerElem;
|
||||
data_.vptr = &buffer_[0];
|
||||
memset (buffer_, 0, newBlockSize);
|
||||
}
|
||||
|
||||
// *************************************************************
|
||||
// * deallocate:
|
||||
// * Deallocates any memory previously allocated to the buffer
|
||||
// * and reinitializes the size_, dim_, bytes_ and buffer_
|
||||
// * variables. Any references to the previously allocated
|
||||
// * block is cleared.
|
||||
// *************************************************************
|
||||
void deallocate ( void )
|
||||
{
|
||||
if(buffer_ != 0) {
|
||||
delete []buffer_;
|
||||
buffer_ = 0;
|
||||
}
|
||||
size_ = 0;
|
||||
dim_ = 0;
|
||||
elems_ = 0;
|
||||
bytes_ = 0;
|
||||
data_.dval = 0.00;
|
||||
}
|
||||
|
||||
|
||||
// *************************************************************
|
||||
// * operator ==:
|
||||
// * This operator allows you to directly and rapidly
|
||||
// * compare two rsvcDataEntryStorage objects...
|
||||
// *************************************************************
|
||||
int operator == (rsvcDataEntryStorage & entry);
|
||||
|
||||
// *************************************************************
|
||||
// * operator !=:
|
||||
// * This operator allows the caller to directly and rapidly
|
||||
// * comapre two rsvcDataEntryStorage objects.
|
||||
// *************************************************************
|
||||
int operator != (rsvcDataEntryStorage & entry) {
|
||||
return !(operator == (entry));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
// #############################################################################
|
||||
// # rsvcDataEntry:
|
||||
// # This class is used to define the node attributes necessary to support
|
||||
// # linked lists of rsvcDataEntryStorage objects. It also provides an internal
|
||||
// # freelist of rsvcDataEntry objects.
|
||||
// #
|
||||
// # Note: Because the rsvcData object must actively manipulate the data in
|
||||
// # this structure - it has been made public to increase access speed
|
||||
// # and to allow the subclassing of the rsvcData object.
|
||||
// #############################################################################
|
||||
class rsvcDataEntry : public rsvcDataEntryStorage
|
||||
{
|
||||
public:
|
||||
// *************************************************************
|
||||
// * freeList_:
|
||||
// * This is a pointer to a list of currently allocated
|
||||
// * rsvcDataEntrys that will be provided to the user
|
||||
// * upon request. This technique should reduce the number of
|
||||
// * mallocs called to allocated rsvcDataEntrys.
|
||||
// *************************************************************
|
||||
static rsvcDataEntry * freeList_;
|
||||
|
||||
// *************************************************************
|
||||
// * ALLOCATION_COUNT:
|
||||
// * This is the minimum number of rsvcDataEntrys that will
|
||||
// * be allocated when the freeList_ becomes empty.
|
||||
// *************************************************************
|
||||
enum { ALLOCATION_COUNT = 16 };
|
||||
|
||||
// *************************************************************
|
||||
// * next_ :
|
||||
// * This is the pointer to the next element in the list of
|
||||
// * rsvcDataEntry objects.
|
||||
// *************************************************************
|
||||
rsvcDataEntry * next_;
|
||||
|
||||
// *************************************************************
|
||||
// * rsvcDataEntry:
|
||||
// * Constructor for the class. It serves only to set the next_
|
||||
// * pointer to NULL.
|
||||
// *************************************************************
|
||||
rsvcDataEntry ( void ) : next_(NULL), rsvcDataEntryStorage()
|
||||
{
|
||||
}
|
||||
|
||||
// *************************************************************
|
||||
// * ~rsvcDataEntry:
|
||||
// * Destructor for the class. It is a placeholder that
|
||||
// * does nothing when called.
|
||||
// *************************************************************
|
||||
~rsvcDataEntry ( void ) { }
|
||||
|
||||
// *************************************************************
|
||||
// * next:
|
||||
// * Retrieves a pointer to the next_ rsvcDataEntry object.
|
||||
// * Incorporation of this function into a list object is the
|
||||
// * responsibility of the caller.
|
||||
// *************************************************************
|
||||
rsvcDataEntry * &next ( void )
|
||||
{
|
||||
return next_;
|
||||
}
|
||||
|
||||
// *************************************************************
|
||||
// * new:
|
||||
// * Allocation function for the object. It will get the next
|
||||
// * preallocated rsvcDataEntry object from the freeList_,
|
||||
// * or, if none are available, refill the freeList_ and then
|
||||
// * return a new rsvcDataEntry object.
|
||||
// *************************************************************
|
||||
void * operator new ( size_t size );
|
||||
|
||||
// *************************************************************
|
||||
// * delete:
|
||||
// * Rather than deallocating the rsvcDataEntry object, this
|
||||
// * function returns it to the freeList_ where it may be
|
||||
// * retrieved by a later call of new.
|
||||
// *************************************************************
|
||||
void operator delete ( void * ptr )
|
||||
{
|
||||
rsvcDataEntry * node = (rsvcDataEntry *)ptr;
|
||||
if(node != NULL) {
|
||||
node->next_ = freeList_;
|
||||
freeList_ = node;
|
||||
}
|
||||
}
|
||||
|
||||
// *************************************************************
|
||||
// * Copy operation
|
||||
// * Copy an existing data entry to a new data entry
|
||||
// * this may allow new data entry to be inserted into data object
|
||||
// * quickly
|
||||
// *************************************************************
|
||||
rsvcDataEntry (const rsvcDataEntry& entry);
|
||||
|
||||
// *************************************************************
|
||||
// * Assignment operation
|
||||
// * Copy an existing data entry to a data entry
|
||||
// *************************************************************
|
||||
rsvcDataEntry& operator = (const rsvcDataEntry& entry);
|
||||
|
||||
// *************************************************************
|
||||
// * operator ==:
|
||||
// * This operator allows you to directly and rapidly
|
||||
// * compare two rsvcDataEntry objects...
|
||||
// *************************************************************
|
||||
int operator == (rsvcDataEntry & entry)
|
||||
{
|
||||
rsvcDataEntryStorage *storage = &entry;
|
||||
|
||||
return rsvcDataEntryStorage::operator == (*storage);
|
||||
}
|
||||
|
||||
// *************************************************************
|
||||
// * operator !=:
|
||||
// * This operator allows the caller to directly and rapidly
|
||||
// * comapre two rsvcDataEntry objects.
|
||||
// *************************************************************
|
||||
int operator != (rsvcDataEntry & entry)
|
||||
{
|
||||
rsvcDataEntryStorage *storage = &entry;
|
||||
return !(rsvcDataEntryStorage::operator == (*storage));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif /* __RSVC_DATA_ENTRY_H_ */
|
||||
174
extensions/cdevGenericServer/include/rsvcDataStore.h
Normal file
174
extensions/cdevGenericServer/include/rsvcDataStore.h
Normal file
@@ -0,0 +1,174 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// RSVC Server All Data Storage Class (Abstract Class)
|
||||
//
|
||||
// This class behaves like a wrapper class that direct
|
||||
// all actions to right components contained inside this class
|
||||
//
|
||||
// All member functions have 3 arguments. The first is the network
|
||||
// incoming data, the second is the result of the action in the
|
||||
// form of array of network data, and the 3rd argument is size
|
||||
// of the array. Callers must free memory for the elements
|
||||
// in the array
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_DATA_STORE_H
|
||||
#define _RSVC_DATA_STORE_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <rsvcData.h>
|
||||
#include <rsvcTableDef.h>
|
||||
#include <rsvcHashable.h>
|
||||
#include <rsvcNetData.h>
|
||||
#include <rsvcHash.h>
|
||||
|
||||
|
||||
class rsvcVirtualDbase;
|
||||
|
||||
class rsvcDataStore : public rsvcHashable
|
||||
{
|
||||
public:
|
||||
// destrcutor
|
||||
virtual ~rsvcDataStore (void);
|
||||
|
||||
// operations
|
||||
|
||||
// create table definition
|
||||
virtual int createDatabase (rsvcNetData& data,
|
||||
rsvcNetData* outdata[], size_t* num);
|
||||
|
||||
virtual int openDatabase (rsvcNetData& data,
|
||||
rsvcNetData* outdata[], size_t* num);
|
||||
|
||||
// retrieve table definition and store inside data
|
||||
virtual int getTableDef (rsvcNetData& data,
|
||||
rsvcNetData* outdata[], size_t* num);
|
||||
|
||||
// get data value
|
||||
// specified by a key
|
||||
virtual int getValue (rsvcNetData& incoming,
|
||||
rsvcNetData* outdata[], size_t* num) = 0;
|
||||
// insert a rsvcData which must have a key inside
|
||||
virtual int putValue (rsvcNetData& incoming,
|
||||
rsvcNetData* outdata[], size_t* num,
|
||||
int overwite = 0) = 0;
|
||||
// delete a data object pointed by key value
|
||||
virtual int delValue (rsvcNetData& incoming,
|
||||
rsvcNetData* outdata[], size_t* num) = 0;
|
||||
// flush all internal buffer to disk
|
||||
virtual int flush (void) = 0;
|
||||
|
||||
// set data value
|
||||
// specified either by a key
|
||||
virtual int setValue (rsvcNetData& incoming,
|
||||
rsvcNetData* outdata[], size_t* num) = 0;
|
||||
|
||||
// monitor on incoming database entries
|
||||
virtual int monitorIncomingEntries (rsvcNetData& incoming,
|
||||
rsvcNetData* outdata[], size_t* num) = 0;
|
||||
|
||||
// monitor off the above incoming database entries
|
||||
virtual int monitorOffIncomingEntries (rsvcNetData& incoming,
|
||||
rsvcNetData* outdata[], size_t* num) = 0;
|
||||
// monitor on data values
|
||||
// monitor on the whole data
|
||||
virtual int monitorValue (rsvcNetData& incoming,
|
||||
rsvcNetData* outdata[], size_t* num) = 0;
|
||||
|
||||
// monitor on attribute of a data
|
||||
virtual int monitorAttr (rsvcNetData& incoming,
|
||||
rsvcNetData* outdata[], size_t* num) = 0;
|
||||
|
||||
// monitor off data values
|
||||
virtual int monitorOffValue (rsvcNetData& incoming,
|
||||
rsvcNetData* outdata[], size_t* num) = 0;
|
||||
|
||||
// monitor off attribute of a data
|
||||
virtual int monitorOffAttr (rsvcNetData& incoming,
|
||||
rsvcNetData* outdata[], size_t* num) = 0;
|
||||
|
||||
// monitor off value for a single io channel
|
||||
virtual int monitorOff (void* io) = 0;
|
||||
|
||||
// query the data store
|
||||
virtual int query (rsvcNetData& data, char* msg,
|
||||
rsvcNetData* outdata[], size_t* num) = 0;
|
||||
|
||||
// get every entry in the store
|
||||
virtual int getAll (rsvcNetData& incoming,
|
||||
rsvcNetData* outdata[], size_t* num) = 0;
|
||||
|
||||
// inherited operation from hashable
|
||||
unsigned int hash (void);
|
||||
|
||||
// return name of this data store
|
||||
char* name (void) const;
|
||||
|
||||
// open and close data store operation
|
||||
virtual int openDatabase (void);
|
||||
virtual int closeDatabase (void);
|
||||
|
||||
// handle client close
|
||||
virtual void handleClose (void * /* client */) {}
|
||||
|
||||
// from existing table definition and files
|
||||
// to create a right dataStore object
|
||||
static rsvcDataStore* createDataStore (char* name);
|
||||
|
||||
protected:
|
||||
// constructor
|
||||
// construct data store with a unique name
|
||||
rsvcDataStore (char* name);
|
||||
|
||||
// remove all monitors on incoming data
|
||||
void removeAllMonitors (void);
|
||||
|
||||
|
||||
// update this data store time stamp which is the time when last
|
||||
// action was done on the store.
|
||||
void updateTimeStamp (void);
|
||||
|
||||
// notify interested parties about an incoming entry
|
||||
int notifyAnEntryToChannels (rsvcData& entry);
|
||||
|
||||
// data area
|
||||
char* name_;
|
||||
|
||||
// time stamp of this data store
|
||||
double timestamp_;
|
||||
|
||||
// table definition
|
||||
rsvcTableDef tableDef_;
|
||||
|
||||
// data cache handler
|
||||
rsvcHash cache_;
|
||||
|
||||
// insert/deleted data monitor
|
||||
rsvcHSlist idataMonitorList_;
|
||||
rsvcHSlist odataMonitorList_;
|
||||
|
||||
// database handler
|
||||
rsvcVirtualDbase* database_;
|
||||
};
|
||||
#endif
|
||||
|
||||
105
extensions/cdevGenericServer/include/rsvcDataStoreMem.h
Normal file
105
extensions/cdevGenericServer/include/rsvcDataStoreMem.h
Normal file
@@ -0,0 +1,105 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// RSVC Server In Memory Data Store
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_DATASTORE_MEM_H
|
||||
#define _RSVC_DATASTORE_MEM_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <rsvcErr.h>
|
||||
#include <rsvcDataStore.h>
|
||||
|
||||
class rsvcCacheData;
|
||||
|
||||
class rsvcDataStoreMem: public rsvcDataStore
|
||||
{
|
||||
public:
|
||||
// constructor and destructor
|
||||
rsvcDataStoreMem (char* name);
|
||||
~rsvcDataStoreMem (void);
|
||||
|
||||
// inherited operations
|
||||
// get data values
|
||||
// specified by a key
|
||||
virtual int getValue (rsvcNetData& incoming,
|
||||
rsvcNetData* outdata[], size_t* num);
|
||||
|
||||
// insert a rsvcData which may have a key inside or not
|
||||
virtual int putValue (rsvcNetData& incoming,
|
||||
rsvcNetData* outdata[], size_t* num,
|
||||
int overwrite = 0);
|
||||
|
||||
// delete a data object pointed by key value
|
||||
virtual int delValue (rsvcNetData& incoming,
|
||||
rsvcNetData* outdata[], size_t* num);
|
||||
// flush all internal buffer to disk
|
||||
virtual int flush (void);
|
||||
|
||||
// set data value
|
||||
// specified either by a key or a whole data
|
||||
virtual int setValue (rsvcNetData& incoming,
|
||||
rsvcNetData* outdata[], size_t* num);
|
||||
|
||||
// monitor on incoming database entries
|
||||
virtual int monitorIncomingEntries (rsvcNetData& incoming,
|
||||
rsvcNetData* outdata[], size_t* num);
|
||||
|
||||
// monitor off the above incoming database entries
|
||||
virtual int monitorOffIncomingEntries (rsvcNetData& incoming,
|
||||
rsvcNetData* outdata[], size_t* num);
|
||||
|
||||
// monitor on data values
|
||||
// monitor on either the whole data
|
||||
virtual int monitorValue (rsvcNetData& incoming,
|
||||
rsvcNetData* outdata[], size_t* num);
|
||||
|
||||
// monitor on attribute of a data
|
||||
virtual int monitorAttr (rsvcNetData& incoming,
|
||||
rsvcNetData* outdata[], size_t* num);
|
||||
|
||||
// monitor off data value
|
||||
virtual int monitorOffValue (rsvcNetData& incoming,
|
||||
rsvcNetData* outdata[], size_t* num);
|
||||
|
||||
// monitor off attribute of a data
|
||||
virtual int monitorOffAttr (rsvcNetData& incoming,
|
||||
rsvcNetData* outdata[], size_t* num);
|
||||
|
||||
|
||||
// monitor off data value for all monitors from same socket id
|
||||
virtual int monitorOff (void* io);
|
||||
|
||||
// query the data store
|
||||
virtual int query (rsvcNetData& data, char* msg,
|
||||
rsvcNetData* outdata[], size_t* num);
|
||||
|
||||
// get every entry in the store
|
||||
virtual int getAll (rsvcNetData& incoming,
|
||||
rsvcNetData* outdata[], size_t* num);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// find cached data item inside cache from a key data
|
||||
rsvcCacheData* cachedData (rsvcData& keydata);
|
||||
|
||||
// delete a cached data item inside cache from a key dta
|
||||
int deleteCachedData (rsvcData& key);
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
59
extensions/cdevGenericServer/include/rsvcDataStoreTable.h
Normal file
59
extensions/cdevGenericServer/include/rsvcDataStoreTable.h
Normal file
@@ -0,0 +1,59 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// RSVC Server All Data Store Table
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_DATA_STORE_TABLE_H
|
||||
#define _RSVC_DATA_STORE_TABLE_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <rsvcDataStore.h>
|
||||
#include <rsvcHash.h>
|
||||
|
||||
class rsvcDataStoreTable
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
rsvcDataStoreTable (unsigned int max = 100, unsigned int lf = 5);
|
||||
|
||||
// destructor
|
||||
~rsvcDataStoreTable (void);
|
||||
|
||||
// add a data store
|
||||
int add (rsvcDataStore* store);
|
||||
|
||||
// find a data store
|
||||
rsvcDataStore* find (char* name);
|
||||
|
||||
// open a datastore with name
|
||||
int openDatabase (char* name);
|
||||
|
||||
// monitor off all values for a client
|
||||
void monitorOff (void* io);
|
||||
|
||||
// handle close for a client
|
||||
void handleClose (void* io);
|
||||
|
||||
private:
|
||||
|
||||
// data area
|
||||
rsvcHash table_;
|
||||
|
||||
// deny access to copy and assignment operations
|
||||
rsvcDataStoreTable (const rsvcDataStoreTable& table);
|
||||
rsvcDataStoreTable operator = (const rsvcDataStoreTable& table);
|
||||
};
|
||||
#endif
|
||||
183
extensions/cdevGenericServer/include/rsvcDataStreamer.h
Normal file
183
extensions/cdevGenericServer/include/rsvcDataStreamer.h
Normal file
@@ -0,0 +1,183 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// rsvc data streamer class
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_DATA_STREAMER
|
||||
#define _RSVC_DATA_STREAMER
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef _WIN32
|
||||
#include <WinSock2.h>
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#include <rsvcDataTypes.h>
|
||||
|
||||
#define _RSVC_STREAM_BYTE_UNIT (sizeof (long))
|
||||
|
||||
inline int _RSVC_RNDUP (size_t x)
|
||||
{
|
||||
return ((x + _RSVC_STREAM_BYTE_UNIT - 1) / _RSVC_STREAM_BYTE_UNIT)
|
||||
* _RSVC_STREAM_BYTE_UNIT;
|
||||
}
|
||||
|
||||
inline size_t rsvcStreamSize (char c)
|
||||
{
|
||||
return _RSVC_RNDUP (sizeof (c));
|
||||
}
|
||||
|
||||
inline size_t rsvcStreamSize (unsigned char c)
|
||||
{
|
||||
return _RSVC_RNDUP (sizeof (c));
|
||||
}
|
||||
|
||||
inline size_t rsvcStreamSize (short c)
|
||||
{
|
||||
return _RSVC_RNDUP (sizeof (c));
|
||||
}
|
||||
|
||||
inline size_t rsvcStreamSize (unsigned short c)
|
||||
{
|
||||
return _RSVC_RNDUP (sizeof (c));
|
||||
}
|
||||
|
||||
inline size_t rsvcStreamSize (int c)
|
||||
{
|
||||
return _RSVC_RNDUP (sizeof (c));
|
||||
}
|
||||
|
||||
inline size_t rsvcStreamSize (unsigned int c)
|
||||
{
|
||||
return _RSVC_RNDUP (sizeof (c));
|
||||
}
|
||||
|
||||
inline size_t rsvcStreamSize (long c)
|
||||
{
|
||||
return sizeof (c);
|
||||
}
|
||||
|
||||
inline size_t rsvcStreamSize (unsigned long c)
|
||||
{
|
||||
return sizeof (c);
|
||||
}
|
||||
|
||||
inline size_t rsvcStreamSize (float c)
|
||||
{
|
||||
return sizeof (c);
|
||||
}
|
||||
|
||||
inline size_t rsvcStreamSize (double c)
|
||||
{
|
||||
return sizeof (c);
|
||||
}
|
||||
|
||||
inline size_t rsvcStreamSize (char* str)
|
||||
{
|
||||
return sizeof (long) + _RSVC_RNDUP (strlen (str) + 1);
|
||||
}
|
||||
|
||||
inline size_t rsvcStreamSize (void*, size_t size)
|
||||
{
|
||||
return sizeof (long) + _RSVC_RNDUP (size);
|
||||
}
|
||||
|
||||
inline size_t rsvcStreamSize (rsvc_TS_STAMP& ts)
|
||||
{
|
||||
return sizeof (ts);
|
||||
}
|
||||
|
||||
class rsvcDataStreamer
|
||||
{
|
||||
public:
|
||||
// destructor
|
||||
virtual ~rsvcDataStreamer (void);
|
||||
|
||||
char* buffer (void) const;
|
||||
size_t bufferLength (void) const;
|
||||
|
||||
int streamStatus (void) const;
|
||||
|
||||
protected:
|
||||
// constructor
|
||||
// attach to a stream buffer.
|
||||
// dealloc == 1 free buffer in the detrcutor.
|
||||
rsvcDataStreamer (char* buffer, size_t buflen, int dealloc = 1);
|
||||
|
||||
// binray stream buffer
|
||||
char* buffer_;
|
||||
size_t buflen_;
|
||||
|
||||
// free memory stratege
|
||||
int dealloc_;
|
||||
|
||||
// index pointing to current position
|
||||
int pos_;
|
||||
|
||||
// streaming status
|
||||
int err_;
|
||||
};
|
||||
|
||||
class rsvcDataStreamWriter : public rsvcDataStreamer
|
||||
{
|
||||
public:
|
||||
// constructor and destrcutor
|
||||
rsvcDataStreamWriter (char* buffer, size_t buflen, int dealloc = 1);
|
||||
~rsvcDataStreamWriter (void);
|
||||
|
||||
// operations
|
||||
int write (char c);
|
||||
int write (unsigned char c);
|
||||
int write (short c);
|
||||
int write (unsigned short c);
|
||||
int write (int c);
|
||||
int write (unsigned int c);
|
||||
int write (long c);
|
||||
int write (unsigned long c);
|
||||
int write (float c);
|
||||
int write (double c);
|
||||
int write (char* str);
|
||||
int write (void* data, size_t size);
|
||||
int write (rsvc_TS_STAMP& ts);
|
||||
};
|
||||
|
||||
class rsvcDataStreamReader : public rsvcDataStreamer
|
||||
{
|
||||
public:
|
||||
// constructor and destrcutor
|
||||
rsvcDataStreamReader (char* buffer, size_t buflen, int dealloc = 1);
|
||||
~rsvcDataStreamReader (void);
|
||||
|
||||
// operations
|
||||
int read (char& c);
|
||||
int read (unsigned char& c);
|
||||
int read (short& c);
|
||||
int read (unsigned short& c);
|
||||
int read (int& c);
|
||||
int read (unsigned int& c);
|
||||
int read (long& c);
|
||||
int read (unsigned long& c);
|
||||
int read (float& c);
|
||||
int read (double& c);
|
||||
int read (char* &str);
|
||||
int read (void* data, size_t size);
|
||||
int read (rsvc_TS_STAMP& ts);
|
||||
};
|
||||
|
||||
#endif
|
||||
43
extensions/cdevGenericServer/include/rsvcDataTypes.h
Normal file
43
extensions/cdevGenericServer/include/rsvcDataTypes.h
Normal file
@@ -0,0 +1,43 @@
|
||||
//---------------------------------------------------------------------------
|
||||
// Copyright (c) 1991,1992 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//----------------------------------------------------------------------------
|
||||
//
|
||||
// description: Data Type Definition
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
#ifndef _RSVC_TYPES_H
|
||||
#define _RSVC_TYPES_H
|
||||
|
||||
typedef unsigned char BYTE;
|
||||
|
||||
enum rsvcDataTypes
|
||||
{
|
||||
RSVC_BYTE,
|
||||
RSVC_INT16,
|
||||
RSVC_UINT16,
|
||||
RSVC_INT32,
|
||||
RSVC_UINT32,
|
||||
RSVC_FLOAT,
|
||||
RSVC_DOUBLE,
|
||||
RSVC_STRING,
|
||||
RSVC_TIMESTAMP,
|
||||
RSVC_INVALID
|
||||
};
|
||||
|
||||
// rsvc time struct
|
||||
typedef struct {
|
||||
unsigned long secPastEpoch; // seconds since Jan. 1, 1970
|
||||
unsigned long nsec; // nanoseconds within second
|
||||
} rsvc_TS_STAMP;
|
||||
|
||||
#define RSVC_TAG_MAX_LEN 16
|
||||
#endif
|
||||
205
extensions/cdevGenericServer/include/rsvcDatabase.h
Normal file
205
extensions/cdevGenericServer/include/rsvcDatabase.h
Normal file
@@ -0,0 +1,205 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// RSVC database interface to db library (Thread Safe)
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_DATABASE_H
|
||||
#define _RSVC_DATABASE_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/param.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <db.h>
|
||||
#include <rsvcData.h>
|
||||
#include <rsvcDBT.h>
|
||||
#include <rsvcServerConfig.h>
|
||||
#include <rsvcVirtualDbase.h>
|
||||
|
||||
#if defined (_RSVC_USE_THREAD) && defined (_REENTRANT)
|
||||
#include <cpSynch.h>
|
||||
#endif
|
||||
|
||||
// comparision function definition
|
||||
typedef int (*rsvcCompFunc) (const DBT* key1, const DBT* key2);
|
||||
|
||||
// this class will handle interface to btree based database implementation.
|
||||
// data/key are rsvcData/undefined. When caller insert a rsvc, the
|
||||
// rsvcData must have a key in this data with tag name 'key'.
|
||||
// when caller tries to get rsvcData, caller has to specify the key
|
||||
// which is in a rsvcData with tag name 'key'
|
||||
|
||||
// This interface will not provide two iterators at the same time.
|
||||
// This is the limitation by low level database library
|
||||
|
||||
// All pointers to key must be the memory location provided by callers
|
||||
|
||||
class rsvcDatabaseLocker;
|
||||
|
||||
class rsvcDatabase : public rsvcVirtualDbase
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
// default constructor, users have to call open explicitly
|
||||
rsvcDatabase (void);
|
||||
|
||||
// constructor: name is a file name, flags are the same flags as
|
||||
// standard open routine.
|
||||
// data_size is estimate of each data stored in the database
|
||||
rsvcDatabase (char* name, int flags, int keyType = RSVC_STRING,
|
||||
size_t data_size = 496,
|
||||
size_t cache_size = 0, size_t page_size = 0,
|
||||
int mode = 0666);
|
||||
// destructor
|
||||
~rsvcDatabase (void);
|
||||
|
||||
// operation
|
||||
|
||||
// open a database
|
||||
int open (char* name, int flags, int keyType = RSVC_STRING,
|
||||
size_t cache_size = 0,
|
||||
int mode = 0666);
|
||||
// create a database
|
||||
int create (char* name, int flags, int keyType = RSVC_STRING,
|
||||
size_t data_size = 496,
|
||||
size_t cache_size = 0, size_t page_size = 0,
|
||||
int mode = 0666);
|
||||
|
||||
// close connection to the database
|
||||
int close (void);
|
||||
|
||||
// get a rsvcData.
|
||||
int get (rsvcData& data, rsvcData& key);
|
||||
// insert a rsvcData which must have a key inside
|
||||
int put (rsvcData& data, rsvcData& key);
|
||||
// delete a data object pointed by key value
|
||||
int del (rsvcData& key);
|
||||
// flush all internal buffer to disk
|
||||
int flush (void);
|
||||
|
||||
// return database name
|
||||
char* database (void) const;
|
||||
// return file descriptor for the opened database
|
||||
int fd (void);
|
||||
// check to see the database is open or not
|
||||
int opened (void) const;
|
||||
|
||||
// iterator for sequential access to database
|
||||
int cursorInit (void);
|
||||
|
||||
// set cursor to the position pointed by key 'key',
|
||||
// and return data 'data' if successful
|
||||
int cursorSet (rsvcData& data, rsvcData& key);
|
||||
|
||||
// move cursor to the next position.
|
||||
// return CDEV_SUCCESS on success, CDEV_ERROR: check errno
|
||||
// return CDEV_INVALIDOBJ: no more
|
||||
int cursorNext (rsvcData& data, rsvcData& key);
|
||||
|
||||
// move cursor to the previous position
|
||||
// return CDEV_SUCCESS on success, CDEV_ERROR: check errno
|
||||
// return CDEV_INVALIDOBJ: no more
|
||||
int cursorPrev (rsvcData& data, rsvcData& key);
|
||||
|
||||
// merge current value pointed by cursor:
|
||||
// this routine can only used to update the data with the same
|
||||
// or smaller size than the exisiting data
|
||||
// If you like to update arbitrary size of data, use del and put
|
||||
int cursorUpdate (rsvcData& data);
|
||||
|
||||
// move cursor to the beginning of the database
|
||||
// no need to provide key
|
||||
int cursorFirst (rsvcData& data, rsvcData& key);
|
||||
|
||||
// move cursor to the end of the database
|
||||
// no need to provide key
|
||||
int cursorLast (rsvcData& data, rsvcData& key);
|
||||
|
||||
// close cursor operation
|
||||
int cursorFinish (void);
|
||||
|
||||
const char* className (void) const {return "rsvcDatabase";}
|
||||
|
||||
protected:
|
||||
// convert a DBT to rsvcData (database --> back to memory)
|
||||
static int convertData (rsvcData& data, const DBT* res);
|
||||
// convert rsvcData to rsvcDBT (memory --> to database )
|
||||
static int convertData (rsvcDBT* out, rsvcData& data);
|
||||
|
||||
// convert rsvcData to DBT and a key (memory --> to database)
|
||||
static int convertData (rsvcDBT* out, rsvcDBT* key,
|
||||
rsvcData & data, rsvcData& tkey, int keyType);
|
||||
// find key size
|
||||
static size_t keySize (rsvcData& key, void* tkey, int keyType);
|
||||
|
||||
// convert key from regular rsvcData to DBT format
|
||||
// using convertion buffer keybuf
|
||||
// used when convert memory -->to database
|
||||
static int convertKey (rsvcDBT* key, rsvcData& tkey, int keyType,
|
||||
char* keybuf);
|
||||
|
||||
// copy key data from database back to memory
|
||||
static int copyKeyData (rsvcData& key, DBT* data, int keyType);
|
||||
|
||||
private:
|
||||
#if defined (_RSVC_USE_THREAD) && defined (_REENTRANT)
|
||||
cpMutex mutex_;
|
||||
#endif
|
||||
|
||||
// database access option: different site can change option
|
||||
DB_INFO b_;
|
||||
// internal DB pointer
|
||||
DB* dbp_;
|
||||
|
||||
// Database cursor pointer
|
||||
DBC* dbc_;
|
||||
|
||||
// keep track of size of data that have been written to a database
|
||||
int wsize_;
|
||||
|
||||
// static buffer for key
|
||||
char keybuf_[RSVC_MAX_KEY_LEN];
|
||||
|
||||
// Function pointers to all comparision functions
|
||||
static rsvcCompFunc compFuncs_[];
|
||||
|
||||
// deny access to copy and assignment operator
|
||||
rsvcDatabase (const rsvcDatabase& dbase);
|
||||
rsvcDatabase& operator = (const rsvcDatabase& dbase);
|
||||
|
||||
// friend class
|
||||
friend class rsvcDatabaseLocker;
|
||||
};
|
||||
|
||||
class rsvcDatabaseLocker
|
||||
{
|
||||
public:
|
||||
// constructor and destructor
|
||||
rsvcDatabaseLocker (rsvcDatabase* dbase);
|
||||
~rsvcDatabaseLocker (void);
|
||||
|
||||
private:
|
||||
rsvcDatabase* dbase_;
|
||||
// deny access to assignment and copy operations
|
||||
rsvcDatabaseLocker (const rsvcDatabaseLocker& );
|
||||
rsvcDatabaseLocker& operator = (const rsvcDatabaseLocker& );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
49
extensions/cdevGenericServer/include/rsvcDatabaseEnv.h
Normal file
49
extensions/cdevGenericServer/include/rsvcDatabaseEnv.h
Normal file
@@ -0,0 +1,49 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// Database Environment Class
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_DATABASE_ENV_H
|
||||
#define _RSVC_DATABASE_ENV_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <db.h>
|
||||
|
||||
class rsvcDatabaseEnv
|
||||
{
|
||||
public:
|
||||
// destructor
|
||||
~rsvcDatabaseEnv (void);
|
||||
|
||||
// static access to pointer of this object
|
||||
static rsvcDatabaseEnv* dbaseEnv (void);
|
||||
|
||||
DB_ENV* dbenv (void) const;
|
||||
|
||||
// close all database actions, This is last one to call
|
||||
static void close (void);
|
||||
|
||||
protected:
|
||||
// constructor
|
||||
rsvcDatabaseEnv (void);
|
||||
|
||||
private:
|
||||
// single database environment
|
||||
static rsvcDatabaseEnv* env_;
|
||||
// real database stuff
|
||||
DB_ENV* dbenv_;
|
||||
};
|
||||
#endif
|
||||
78
extensions/cdevGenericServer/include/rsvcErr.h
Normal file
78
extensions/cdevGenericServer/include/rsvcErr.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// RSVC error codes
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
*/
|
||||
#ifndef _RSVC_ERROR_CODE_H
|
||||
#define _RSVC_ERROR_CODE_H
|
||||
|
||||
/* Error and status values */
|
||||
#define RSVC_WARNING -2 /* Failure of function is non-consequential */
|
||||
#define RSVC_ERROR -1 /* Errors that are not in any categories */
|
||||
#define RSVC_SUCCESS 0 /* RSVC success */
|
||||
#define RSVC_INVALIDOBJ 1 /* invalid RSVC objects */
|
||||
#define RSVC_INVALIDARG 2 /* invalid argument passed to RSVC calls */
|
||||
#define RSVC_INVALIDSVC 3 /* wrong service during dynamic loading */
|
||||
#define RSVC_INVALIDOP 4 /* operation is unsupported (collection) */
|
||||
|
||||
#define RSVC_NOTCONNECTED 5 /* not connected to low network service */
|
||||
#define RSVC_IOFAILED 6 /* low level network service IO failed */
|
||||
#define RSVC_CONFLICT 7 /* conflicts of data types or tags */
|
||||
#define RSVC_NOTFOUND 8 /* RSVC cannot find user request (RSVCData) */
|
||||
|
||||
#define RSVC_TIMEOUT 9 /* time out */
|
||||
#define RSVC_CONVERT 10 /* RSVCData conversion error */
|
||||
#define RSVC_OUTOFRANGE 11 /* value out of range for device attribute */
|
||||
#define RSVC_NOACCESS 12 /* insufficient access to perform request */
|
||||
#define RSVC_ACCESSCHANGED 13 /* change in access permission of device */
|
||||
|
||||
#define RSVC_DISCONNECTED 60 /* channel has been disconnected */
|
||||
#define RSVC_RECONNECTED 61 /* channel has been reconnected */
|
||||
#define RSVC_OVERFLOW 62 /* overflow existing data buffer */
|
||||
|
||||
#define RSVC_DELETE_CALLBACK 70 /* the callback object will be deleted */
|
||||
|
||||
#define RSVC_NOKEY 80 /* data has no key in the data */
|
||||
#define RSVC_CONN_TIMEOUT 82 /* connection timeout */
|
||||
#define RSVC_FILTERED 83 /* messages have been filtered */
|
||||
#define RSVC_NOFILTERING 84 /* no filtering applied */
|
||||
#define RSVC_DROPPED 85 /* message is dropped */
|
||||
#define RSVC_BADIO 86 /* TCP io is bad file descriptor */
|
||||
#define RSVC_INCOMPLETE 88 /* data flow will coming (unfinished) */
|
||||
#define RSVC_CBK_FINISHED 89 /* callback finished (monitor off) */
|
||||
#define RSVC_PAUSED 90 /* query callback is paused */
|
||||
#define RSVC_QUERYMSG_ERR 91 /* query message syntax error */
|
||||
|
||||
/* Request object state values */
|
||||
#define RSVC_STATE_CONNECTED 0 /* request object is connected to device */
|
||||
#define RSVC_STATE_NOTCONNECTED 1 /* request object is not connected */
|
||||
#define RSVC_STATE_INVALID 2 /* request object is invalid */
|
||||
|
||||
/* Request object access values */
|
||||
#define RSVC_ACCESS_NONE 0 /* no access to specified attribute */
|
||||
#define RSVC_ACCESS_READONLY 1 /* read-only access to attribute */
|
||||
#define RSVC_ACCESS_WRITE 2 /* read-write access to attribute */
|
||||
|
||||
/* RSVCError class severity codes */
|
||||
#define RSVC_SEVERITY_INFO 0 /* informative message */
|
||||
#define RSVC_SEVERITY_WARN 1 /* warning message */
|
||||
#define RSVC_SEVERITY_ERROR 2 /* error message */
|
||||
#define RSVC_SEVERITY_SEVERE 3 /* severe or fatal error message */
|
||||
|
||||
#define RSVC_IOERROR RSVC_IOFAILED
|
||||
|
||||
|
||||
#endif
|
||||
256
extensions/cdevGenericServer/include/rsvcHSlist.h
Normal file
256
extensions/cdevGenericServer/include/rsvcHSlist.h
Normal file
@@ -0,0 +1,256 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// Single Linked List for pointers rsvcHashable pointer
|
||||
// Primary used inside rsvcHash
|
||||
//
|
||||
// Note: remove and clean operations on the list
|
||||
// will only remove link nodes without removal of
|
||||
// the content inside the nodes. It is callers'
|
||||
// responsiblity to clean up those contents
|
||||
//
|
||||
//
|
||||
// Author: Jie Chen
|
||||
// CEBAF Data Acquisition Group
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_HSLIST_H
|
||||
#define _RSVC_HSLIST_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined (RSVC_USE_THREAD) && defined (_REENTRANT)
|
||||
#include <cpSynch.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
//======================================================================
|
||||
// class rsvcSlist
|
||||
// Single Linked List for void* pointer
|
||||
//======================================================================
|
||||
class rsvcHSlistLink;
|
||||
class rsvcHSlistIterator;
|
||||
class rsvcHSlistCursor;
|
||||
class rsvcHash;
|
||||
class rsvcHashable;
|
||||
|
||||
class rsvcHSlist
|
||||
{
|
||||
public:
|
||||
// constructors
|
||||
rsvcHSlist (void);
|
||||
rsvcHSlist (const rsvcHSlist & source);
|
||||
virtual ~rsvcHSlist (void);
|
||||
|
||||
// operations
|
||||
|
||||
// add list item to the beginning of the list
|
||||
virtual void add (rsvcHashable* value);
|
||||
// add item to the end of list
|
||||
virtual void addToEnd (rsvcHashable* value);
|
||||
|
||||
// remove a list item from the list
|
||||
// return 0: nothing to remove
|
||||
// return 1: remove success
|
||||
virtual int remove (rsvcHashable* value);
|
||||
|
||||
// clean up the list.
|
||||
virtual void deleteAllValues (void);
|
||||
|
||||
// return first element of the list
|
||||
virtual rsvcHashable* firstElement (void);
|
||||
|
||||
// return last element of the list
|
||||
virtual rsvcHashable* lastElement (void);
|
||||
|
||||
// duplicate ths whole list
|
||||
virtual rsvcHSlist* duplicate (void);
|
||||
|
||||
// check whether this list contains a particular item
|
||||
// return 1: yes. return 0: no
|
||||
virtual int includes (rsvcHashable* value);
|
||||
|
||||
// Is list empty
|
||||
// return 1: yes. return 0: no
|
||||
virtual int isEmpty (void);
|
||||
|
||||
// remove first element of the list
|
||||
virtual void removeFirst (void);
|
||||
|
||||
// return number of elements inside the list
|
||||
virtual int count (void);
|
||||
|
||||
protected:
|
||||
// data field
|
||||
rsvcHSlistLink* ptrToFirstLink;
|
||||
|
||||
// number elements in the list
|
||||
int count_;
|
||||
|
||||
#if defined (RSVC_USE_THREAD) && defined (_REENTRANT)
|
||||
cpMutex lock_;
|
||||
#endif
|
||||
|
||||
// some internal functions which must be called with lock held
|
||||
virtual void add_i (rsvcHashable* value);
|
||||
virtual int isEmpty_i (void) const;
|
||||
virtual void deleteAllValues_i (void);
|
||||
virtual void removeFirst_i (void);
|
||||
virtual rsvcHashable* firstElement_i (void);
|
||||
virtual rsvcHashable* lastElement_i (void);
|
||||
|
||||
// friends
|
||||
friend class rsvcHSlistIterator;
|
||||
// cannot modify list in anyways
|
||||
friend class rsvcHSlistCursor;
|
||||
friend class rsvcHash;
|
||||
|
||||
private:
|
||||
// deny access to assignment operation
|
||||
rsvcHSlist& operator = (const rsvcHSlist& list);
|
||||
};
|
||||
|
||||
//======================================================================
|
||||
// class rsvcHSlistLink
|
||||
// Single linked list link node
|
||||
//======================================================================
|
||||
class rsvcHSlistLink
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
rsvcHSlistLink (rsvcHashable* linkValue, rsvcHSlistLink * nextPtr);
|
||||
|
||||
// insert a new element following the current value
|
||||
rsvcHSlistLink* insert (rsvcHashable* val);
|
||||
// return data value
|
||||
rsvcHashable* data (void);
|
||||
|
||||
// return next data item
|
||||
rsvcHSlistLink* next (void);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// duplicate
|
||||
rsvcHSlistLink* duplicate (void);
|
||||
|
||||
// data areas
|
||||
rsvcHashable* value;
|
||||
rsvcHSlistLink* ptrToNextLink;
|
||||
|
||||
// friends
|
||||
friend class rsvcHSlist;
|
||||
friend class rsvcHSlistIterator;
|
||||
friend class rsvcHSlistCursor;
|
||||
};
|
||||
|
||||
//===================================================================
|
||||
// class rsvcHSlistIterator
|
||||
// implements iterator protocol for linked lists
|
||||
// also permits removal and addition of elements
|
||||
//===================================================================
|
||||
|
||||
class rsvcHashIterator;
|
||||
|
||||
class rsvcHSlistIterator
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
rsvcHSlistIterator (rsvcHSlist& aList);
|
||||
|
||||
// iterator protocol
|
||||
virtual int init (void);
|
||||
virtual rsvcHashable* operator () (void);
|
||||
virtual int operator ! (void);
|
||||
virtual int operator ++ (void);
|
||||
virtual void operator = (rsvcHashable* value);
|
||||
|
||||
// new methods specific to list iterators
|
||||
|
||||
// remove current item pointed by the iterator from the list
|
||||
void removeCurrent(void);
|
||||
|
||||
// add an item to the list before the position pointed by the iterator
|
||||
void addBefore(rsvcHashable* newValue);
|
||||
|
||||
// add an item to the list after the position pointed by the iterator
|
||||
void addAfter(rsvcHashable* newValue);
|
||||
|
||||
// search an item and move the iterator to that position
|
||||
int searchSame(rsvcHashable* &value);
|
||||
|
||||
protected:
|
||||
// some internal functions which must be called with lock held
|
||||
virtual int init_i (void);
|
||||
// move cursor forward
|
||||
virtual int forward_i (void);
|
||||
// internal remove current
|
||||
void removeCurrent_i (void);
|
||||
// data areas
|
||||
rsvcHSlistLink * currentLink;
|
||||
rsvcHSlistLink * previousLink;
|
||||
rsvcHSlist& theList;
|
||||
#if defined (RSVC_USE_THREAD) && defined (_REENTRANT)
|
||||
cpMutex lock_;
|
||||
#endif
|
||||
|
||||
private:
|
||||
// friend class
|
||||
friend class rsvcHashIterator;
|
||||
|
||||
// deny access of copy and assignment
|
||||
rsvcHSlistIterator (const rsvcHSlistIterator& ir);
|
||||
rsvcHSlistIterator& operator = (const rsvcHSlistIterator& ir);
|
||||
};
|
||||
|
||||
//===================================================================
|
||||
// class rsvcHSlistCursor
|
||||
// implements cursor protocol for linked lists
|
||||
//===================================================================
|
||||
class rsvcHSlistCursor
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
rsvcHSlistCursor (const rsvcHSlist& aList);
|
||||
|
||||
// iterator protocol
|
||||
virtual int init (void);
|
||||
virtual rsvcHashable* operator () (void);
|
||||
virtual int operator ! (void);
|
||||
virtual int operator ++ (void);
|
||||
virtual void operator = (rsvcHashable* value);
|
||||
|
||||
int searchSame (rsvcHashable* &value);
|
||||
|
||||
protected:
|
||||
// internal functions which must be called with lock
|
||||
virtual int init_i (void);
|
||||
// data areas
|
||||
rsvcHSlistLink * currentLink;
|
||||
rsvcHSlistLink * previousLink;
|
||||
const rsvcHSlist& theList;
|
||||
#if defined (RSVC_USE_THREAD) && defined (_REENTRANT)
|
||||
cpMutex lock_;
|
||||
#endif
|
||||
|
||||
private:
|
||||
// deny access to copy and assignment operations
|
||||
rsvcHSlistCursor (const rsvcHSlistCursor &);
|
||||
rsvcHSlistCursor& operator = (const rsvcHSlistCursor &);
|
||||
};
|
||||
#endif
|
||||
144
extensions/cdevGenericServer/include/rsvcHash.h
Normal file
144
extensions/cdevGenericServer/include/rsvcHash.h
Normal file
@@ -0,0 +1,144 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
// CEBAF Data Acquisition Group, 12000 Jefferson Ave., Newport News, VA 23606
|
||||
// Email: coda@cebaf.gov Tel: (804) 249-7101 Fax: (804) 249-7363
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// rsvcStrHash: rsvc hash table keyed by a variable length string
|
||||
// Open Hash with buckets implemented by single linked lists
|
||||
//
|
||||
// Note: void *s are stored inside the table. This class
|
||||
// will not manage these pointers. Callers have to
|
||||
// manage these pointers
|
||||
//
|
||||
// Note: this is unsafe C++ practice. Use at your own risk
|
||||
//
|
||||
// Reason: It is so difficult to use a template class inside
|
||||
// a shared library. (Cfront based C++ compiler cannot
|
||||
// instantiate a template class during compilation time
|
||||
//
|
||||
// Author: Jie Chen
|
||||
// CEBAF Data Acquisition Group
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_HASH_H
|
||||
#define _RSVC_HASH_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <rsvcHashable.h>
|
||||
#include <rsvcHSlist.h>
|
||||
|
||||
|
||||
//======================================================================
|
||||
// class rsvcHash
|
||||
// collection of buckets indexed by hashed values
|
||||
//======================================================================
|
||||
class rsvcHashIterator;
|
||||
|
||||
class rsvcHash
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
|
||||
// construct a hash table with estimate max entry and load fator
|
||||
rsvcHash (unsigned int estimatemax, unsigned int lf = 5);
|
||||
|
||||
// destructor
|
||||
virtual ~rsvcHash (void);
|
||||
|
||||
// operations
|
||||
|
||||
// is the table empty: return 1: yes. return 0: no
|
||||
virtual int isEmpty();
|
||||
|
||||
// clear the elements of the set
|
||||
virtual void deleteAllValues();
|
||||
|
||||
// add an element to the collection
|
||||
virtual void add (rsvcHashable* ele);
|
||||
|
||||
// dump all hash distribution
|
||||
void asciiDump (FILE* fd = stdout);
|
||||
|
||||
// return a reference to a particular bucket according to the key
|
||||
rsvcHSlist& bucketRef (rsvcHashable* ele);
|
||||
|
||||
// return a reference to a particular bucket according to a hash value
|
||||
rsvcHSlist& bucketRef (unsigned int hashcode);
|
||||
|
||||
// return a pointer to an array of linked list
|
||||
void bucketList (rsvcHSlist* &list, unsigned int& size);
|
||||
|
||||
protected:
|
||||
friend class rsvcHashIterator;
|
||||
|
||||
// the actual table itself is a vector of buckets
|
||||
unsigned int tablesize;
|
||||
unsigned int lf;
|
||||
// current index of prime number table
|
||||
int primeindex;
|
||||
// buckets
|
||||
rsvcHSlist* buckets;
|
||||
|
||||
// convert key into unsigned integer value in range
|
||||
unsigned int hash(rsvcHashable* ele) const;
|
||||
|
||||
// expand the hash table size to next prime number when
|
||||
// load factor reaches the preset value
|
||||
void rehash (void);
|
||||
|
||||
private:
|
||||
|
||||
#if defined (RSVC_USE_THREAD) && defined (_REENTRANT)
|
||||
cpMutex lock_;
|
||||
#endif
|
||||
};
|
||||
|
||||
//======================================================================
|
||||
// class rsvcHashIterator
|
||||
// iterator protocol for hash tables
|
||||
//======================================================================
|
||||
class rsvcHashIterator
|
||||
{
|
||||
public:
|
||||
// constructor and destructor
|
||||
rsvcHashIterator (rsvcHash& v);
|
||||
~rsvcHashIterator (void);
|
||||
|
||||
// iterator protocol
|
||||
int init (void);
|
||||
rsvcHashable* operator ()(void);
|
||||
int operator ! (void);
|
||||
int operator ++(void);
|
||||
|
||||
// change value at this position
|
||||
// make sure the hash key are the same inside the value
|
||||
void operator = (rsvcHashable* value);
|
||||
|
||||
// new operations
|
||||
// remove current item pointed by this cursor
|
||||
void removeCurrent (void);
|
||||
|
||||
protected:
|
||||
rsvcHash& base;
|
||||
unsigned int currentIndex;
|
||||
// Single iterator within a bucket
|
||||
rsvcHSlistIterator* itr;
|
||||
// getNextIterator used to set internal iterator pointer
|
||||
// return 1: got it. return 0: no more iterator
|
||||
int getNextIterator (void);
|
||||
|
||||
#if defined (RSVC_USE_THREAD) && defined (_REENTRANT)
|
||||
cpMutex lock_;
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
30
extensions/cdevGenericServer/include/rsvcHashable.h
Normal file
30
extensions/cdevGenericServer/include/rsvcHashable.h
Normal file
@@ -0,0 +1,30 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// Abstract class
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_HASHABLE_H
|
||||
#define _RSVC_HASHABLE_H
|
||||
|
||||
class rsvcHashable
|
||||
{
|
||||
public:
|
||||
// destructor
|
||||
virtual ~rsvcHashable (void);
|
||||
virtual unsigned int hash (void) = 0;
|
||||
|
||||
protected:
|
||||
rsvcHashable (void);
|
||||
};
|
||||
#endif
|
||||
146
extensions/cdevGenericServer/include/rsvcIO.h
Normal file
146
extensions/cdevGenericServer/include/rsvcIO.h
Normal file
@@ -0,0 +1,146 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// RSVC TCP IO handler (Generic Class)
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_IO_H
|
||||
#define _RSVC_IO_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <rsvcData.h>
|
||||
#include <rsvcNetData.h>
|
||||
#include <rsvcStreamMsg.h>
|
||||
#include <rsvcSlist.h>
|
||||
#include <rsvcDataStoreTable.h>
|
||||
|
||||
#include <cdevSocketStream.h>
|
||||
#include <cdevAddr.h>
|
||||
#include <cdevEventHandler.h>
|
||||
#include <cdevReactor.h>
|
||||
|
||||
class rsvcAcceptor;
|
||||
|
||||
class rsvcIO: public cdevEventHandler
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
rsvcIO (cdevReactor& r, rsvcAcceptor* acceptor,
|
||||
rsvcDataStoreTable& st);
|
||||
|
||||
// destructor
|
||||
virtual ~rsvcIO (void);
|
||||
|
||||
// remember connected peer address
|
||||
int peerAddr (const cdevInetAddr & addr);
|
||||
|
||||
// conversion operator for SOCK_Stream
|
||||
operator cdevSocketStream & (void);
|
||||
|
||||
// set socket options
|
||||
int setSockOption (int level, int option, void* optval,
|
||||
int optlen) const;
|
||||
|
||||
// send result to the connected peer
|
||||
int sendToPeer (rsvcNetData* data);
|
||||
|
||||
// return socket file descriptor
|
||||
int getHandle (void) const;
|
||||
|
||||
// enable/disable socket io options
|
||||
void enable (int num);
|
||||
void disable (int num);
|
||||
|
||||
protected:
|
||||
// handle socket close
|
||||
int handleClose ( void );
|
||||
|
||||
// handleOutput
|
||||
int handleOutput ( void );
|
||||
|
||||
// handleInput
|
||||
int handleInput ( void );
|
||||
|
||||
// write msg buffer
|
||||
int writeStreamBuffer (void);
|
||||
|
||||
// shutdown this io stream
|
||||
void shutdownIO (void);
|
||||
|
||||
// handle process data
|
||||
int processData (rsvcNetData& data);
|
||||
|
||||
// all those processing functions
|
||||
int createMemTable (rsvcNetData& ndata);
|
||||
|
||||
int openTable (rsvcNetData& ndata);
|
||||
|
||||
int insertValue (rsvcNetData& ndata, int overwrite = 0);
|
||||
|
||||
int getValue (rsvcNetData& ndata);
|
||||
|
||||
int delValue (rsvcNetData& ndata);
|
||||
|
||||
int setValue (rsvcNetData& ndata);
|
||||
|
||||
int monitorValue (rsvcNetData& ndata);
|
||||
|
||||
int monitorOffValue (rsvcNetData& ndata);
|
||||
|
||||
int monitorAttr (rsvcNetData& ndata);
|
||||
|
||||
int monitorOffAttr (rsvcNetData& ndata);
|
||||
|
||||
int monitorEntries (rsvcNetData& ndata);
|
||||
|
||||
int monitorOffEntries (rsvcNetData& ndata);
|
||||
|
||||
int query (rsvcNetData& ndata);
|
||||
|
||||
// connection to remote client
|
||||
cdevSocketStream sockStream_;
|
||||
// Reactor reference
|
||||
cdevReactor & reactor_;
|
||||
// client host address
|
||||
char* clientHost_;
|
||||
// acceptor that creates this IO
|
||||
rsvcAcceptor* acceptor_;
|
||||
|
||||
// data queue for writing
|
||||
rsvcQueue dataQueue_;
|
||||
|
||||
// current writing msg
|
||||
rsvcStreamMsg wmsg_;
|
||||
|
||||
// output data streaming buffer
|
||||
char* dbuffer_;
|
||||
size_t dbuflen_;
|
||||
|
||||
// input data convertion buffer
|
||||
char* ibuffer_;
|
||||
size_t ibuflen_;
|
||||
|
||||
// data store index table
|
||||
rsvcDataStoreTable& storeTable_;
|
||||
|
||||
// flag to tell whether write mask is set or not
|
||||
int wmaskSet_;
|
||||
|
||||
// deny copy and assignment operations
|
||||
rsvcIO (const rsvcIO& io);
|
||||
rsvcIO& operator = (const rsvcIO& io);
|
||||
};
|
||||
#endif
|
||||
30
extensions/cdevGenericServer/include/rsvcLocalConfig.h
Normal file
30
extensions/cdevGenericServer/include/rsvcLocalConfig.h
Normal file
@@ -0,0 +1,30 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// This a local configuration header file for JLAB use only
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_LOCAL_CONFIG_H
|
||||
#define _RSVC_LOCAL_CONFIG_H
|
||||
|
||||
#ifdef _CDEV_MANAGE_SERVERS
|
||||
|
||||
#define _RSVC_CDEV_SERVERS "cdevServers" // database name
|
||||
#define _RSVC_CDEV_SERVERS_KEY "svcid" // key name
|
||||
#define _RSVC_CDEV_SERVER_TKO 30 // if we do not see a server
|
||||
// for this long, it is dead
|
||||
#define _RSVC_CDEV_SCAN_PERIOD 10
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
128
extensions/cdevGenericServer/include/rsvcLogic.h
Normal file
128
extensions/cdevGenericServer/include/rsvcLogic.h
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
// CEBAF Data Acquisition Group, 12000 Jefferson Ave., Newport News, VA 23606
|
||||
// coda@cebaf.gov Tel: (804) 249-7030 Fax: (804) 249-5800
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// Header File for rsvcServer Query
|
||||
//
|
||||
// Author:
|
||||
// Jie Chen
|
||||
// CEBAF Data Acquisition Group
|
||||
//
|
||||
//
|
||||
//
|
||||
*/
|
||||
#ifndef _RSVC_LOGIC_H
|
||||
#define _RSVC_LOGIC_H
|
||||
|
||||
#define RSVC_LOGIC_UNK 200
|
||||
#define RSVC_LOGIC_INT 201
|
||||
#define RSVC_LOGIC_DBL 202
|
||||
#define RSVC_LOGIC_STR 203
|
||||
|
||||
/* data structure to hold all values on the stack */
|
||||
typedef struct _rsvc_logic_data
|
||||
{
|
||||
short type;
|
||||
union {
|
||||
int ival;
|
||||
double dval;
|
||||
char* string;
|
||||
}u;
|
||||
}rsvc_logic_data;
|
||||
|
||||
/* global input test string for parser */
|
||||
extern char* _logic_input_text;
|
||||
|
||||
/* global parsing engine */
|
||||
extern void* _logic_q_eng;
|
||||
|
||||
/* instruction set */
|
||||
typedef int (*rsvcLogicInst)(void* data);
|
||||
|
||||
#define RSVC_LOGIC_STOP (rsvcLogicInst) 0
|
||||
|
||||
/* function decleration of supporting functions */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined (__STDC__) || defined (__cplusplus)
|
||||
extern rsvc_logic_data* new_logic_data (void);
|
||||
extern rsvc_logic_data* logic_data_dup (rsvc_logic_data* data);
|
||||
extern void logic_data_assign_int (rsvc_logic_data* data, int val);
|
||||
extern void logic_data_assign_dbl (rsvc_logic_data* data, double val);
|
||||
extern void logic_data_assign_str (rsvc_logic_data* data, char* str);
|
||||
extern void free_logic_data (rsvc_logic_data* data);
|
||||
|
||||
extern void set_input_text (char* text);
|
||||
extern void set_query_engine (void* eng);
|
||||
|
||||
extern rsvcLogicInst* logic_code (rsvcLogicInst f);
|
||||
extern int logic_val_push (void* data);
|
||||
extern int rsvc_data_equal_int (void* data);
|
||||
extern int rsvc_data_equal_dbl (void* data);
|
||||
extern int rsvc_data_equal_str (void* data);
|
||||
extern int rsvc_data_has_str (void* data);
|
||||
extern int rsvc_data_less_int (void* data);
|
||||
extern int rsvc_data_less_dbl (void* data);
|
||||
extern int rsvc_data_greater_int (void* data);
|
||||
extern int rsvc_data_greater_dbl (void* data);
|
||||
extern int rsvc_data_lesseq_int (void* data);
|
||||
extern int rsvc_data_lesseq_dbl (void* data);
|
||||
extern int rsvc_data_greatereq_int (void* data);
|
||||
extern int rsvc_data_greatereq_dbl (void* data);
|
||||
extern int rsvc_data_noequal_int (void* data);
|
||||
extern int rsvc_data_noequal_dbl (void* data);
|
||||
extern int rsvc_data_noequal_str (void* data);
|
||||
extern int rsvc_logic_and (void* data);
|
||||
extern int rsvc_logic_or (void* data);
|
||||
extern int rsvc_logic_neg (void* data);
|
||||
extern int rsvc_logic_end (void* data);
|
||||
|
||||
#else
|
||||
extern rsvc_logic_data* new_logic_data ();
|
||||
extern rsvc_logic_data* logic_data_dup ();
|
||||
extern void logic_data_assign_int ();
|
||||
extern void logic_data_assign_dbl ();
|
||||
extern void logic_data_assign_str ();
|
||||
extern void free_logic_data ();
|
||||
extern void set_input_text ();
|
||||
extern void set_query_engine ();
|
||||
extern rsvcLogicInst* logic_code ();
|
||||
extern int logic_val_push ();
|
||||
extern int rsvc_data_equal_int ();
|
||||
extern int rsvc_data_equal_dbl ();
|
||||
extern int rsvc_data_equal_str ();
|
||||
extern int rsvc_data_has_str ();
|
||||
extern int rsvc_data_less_int ();
|
||||
extern int rsvc_data_less_dbl ();
|
||||
extern int rsvc_data_greater_int ();
|
||||
extern int rsvc_data_greater_dbl ();
|
||||
extern int rsvc_data_lesseq_int ();
|
||||
extern int rsvc_data_lesseq_dbl ();
|
||||
extern int rsvc_data_greatereq_int ();
|
||||
extern int rsvc_data_greatereq_dbl ();
|
||||
extern int rsvc_data_noequal_int ();
|
||||
extern int rsvc_data_noequal_dbl ();
|
||||
extern int rsvc_data_noequal_str ();
|
||||
extern int rsvc_logic_and ();
|
||||
extern int rsvc_logic_or ();
|
||||
extern int rsvc_logic_neg ();
|
||||
extern int rsvc_logic_end ();
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
84
extensions/cdevGenericServer/include/rsvcLogicQEng.h
Normal file
84
extensions/cdevGenericServer/include/rsvcLogicQEng.h
Normal file
@@ -0,0 +1,84 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
// CEBAF Data Acquisition Group, 12000 Jefferson Ave., Newport News, VA 23606
|
||||
// coda@cebaf.gov Tel: (804) 249-7030 Fax: (804) 249-5800
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// RSVC Server Query Simple Engine
|
||||
//
|
||||
// Author:
|
||||
// Jie Chen
|
||||
// CEBAF Data Acquisition Group
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_LOGIC_Q_ENG_H
|
||||
#define _RSVC_LOGIC_Q_ENG_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <rsvcData.h>
|
||||
#include <rsvcLogic.h>
|
||||
|
||||
/* stack size */
|
||||
#define RSVC_NSTACK 1024
|
||||
|
||||
/* program counter */
|
||||
#define RSVC_NPROG 4096
|
||||
|
||||
class rsvcLogicQEng
|
||||
{
|
||||
public:
|
||||
// constructor and destructor
|
||||
rsvcLogicQEng (char* qstring);
|
||||
~rsvcLogicQEng (void);
|
||||
|
||||
// operation
|
||||
|
||||
// parse string and produce simple engine
|
||||
// return 0 success, return -1 syntax error
|
||||
int parse (void);
|
||||
|
||||
// execute the engine
|
||||
int execute (rsvcData& data);
|
||||
|
||||
// clean the engine
|
||||
int clean (void);
|
||||
|
||||
// stack operation
|
||||
int push (rsvc_logic_data* data);
|
||||
rsvc_logic_data* pop (void);
|
||||
|
||||
private:
|
||||
// machine stack
|
||||
rsvc_logic_data* stack_[RSVC_NSTACK];
|
||||
// next free slot on the stack
|
||||
rsvc_logic_data** stackp_;
|
||||
|
||||
// simple computing machine
|
||||
rsvcLogicInst prog_[RSVC_NPROG];
|
||||
// next free spot for code
|
||||
rsvcLogicInst* progp_;
|
||||
// program counter
|
||||
rsvcLogicInst* pc_;
|
||||
|
||||
// parsing string
|
||||
char* qstr_;
|
||||
|
||||
// result of execution
|
||||
int result_;
|
||||
|
||||
friend rsvcLogicInst* logic_code (rsvcLogicInst f);
|
||||
friend int logic_val_push (void* d);
|
||||
friend int rsvc_logic_end (void* d);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
30
extensions/cdevGenericServer/include/rsvcLogicSup.h
Normal file
30
extensions/cdevGenericServer/include/rsvcLogicSup.h
Normal file
@@ -0,0 +1,30 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
// CEBAF Data Acquisition Group, 12000 Jefferson Ave., Newport News, VA 23606
|
||||
// coda@cebaf.gov Tel: (804) 249-7030 Fax: (804) 249-5800
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// Simple Header File for rsvc logic expression parser
|
||||
//
|
||||
// Author:
|
||||
// Jie Chen
|
||||
// CEBAF Data Acquisition Group
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_LOGIC_SUP_H
|
||||
#define _RSVC_LOGIC_SUP_H
|
||||
|
||||
// check whether a cdevData matches a logic expression
|
||||
// return -1: string has grammer error
|
||||
// return 0: not matching
|
||||
// return 1: yes
|
||||
extern int dataMatchLogic (rsvcData& data, char* string);
|
||||
|
||||
#endif
|
||||
124
extensions/cdevGenericServer/include/rsvcNetData.h
Normal file
124
extensions/cdevGenericServer/include/rsvcNetData.h
Normal file
@@ -0,0 +1,124 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// RSVC Network Protocol Data
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_NET_DATA_H
|
||||
#define _RSVC_NET_DATA_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <rsvcErr.h>
|
||||
#include <rsvcData.h>
|
||||
#include <rsvcCbk.h>
|
||||
#include <rsvcConfig.h>
|
||||
#include <rsvcStreamable.h>
|
||||
|
||||
class RSVC_CLASS_SPEC rsvcNetData : public rsvcStreamable
|
||||
{
|
||||
public:
|
||||
// constructors
|
||||
// create empty data
|
||||
rsvcNetData (void);
|
||||
|
||||
// create a data with operation code and reqid
|
||||
rsvcNetData (rsvcData& data, long opcode, long cbkid,
|
||||
long reqid = 0, long clientid = 0, long socketid = 0,
|
||||
long status = RSVC_SUCCESS);
|
||||
|
||||
// create a data with explicit callback data
|
||||
rsvcNetData (rsvcData& data, rsvcCbk& cbk);
|
||||
|
||||
// create a data with callback data only
|
||||
rsvcNetData (rsvcCbk& cbk);
|
||||
|
||||
// create a data with real data only
|
||||
rsvcNetData (rsvcData& data);
|
||||
|
||||
// copy operation
|
||||
rsvcNetData (const rsvcNetData& data);
|
||||
|
||||
// destructor
|
||||
~rsvcNetData (void);
|
||||
|
||||
// set method
|
||||
void set (rsvcData& data, rsvcCbk& cbk);
|
||||
void set (rsvcCbk& cbk);
|
||||
|
||||
// cleanup everything
|
||||
void cleanup (void);
|
||||
|
||||
// opcode
|
||||
long opcode (void) const;
|
||||
void opcode (long op);
|
||||
|
||||
// request id
|
||||
long reqid (void) const;
|
||||
void reqid (long id);
|
||||
|
||||
// client id
|
||||
long clientid (void) const;
|
||||
void clientid (long cid);
|
||||
|
||||
// callback id
|
||||
long cbkid (void) const;
|
||||
void cbkid (long cid);
|
||||
|
||||
// socket id
|
||||
long socketid (void) const;
|
||||
void socketid (long id);
|
||||
|
||||
// net operation status
|
||||
long cbkstatus (void) const;
|
||||
void cbkstatus (long status);
|
||||
|
||||
// return underlying data object
|
||||
rsvcData& data (void);
|
||||
// return underlying callback object
|
||||
rsvcCbk& cbk (void);
|
||||
|
||||
// stream in and out operation
|
||||
size_t streamSize (void);
|
||||
|
||||
// stream out to a newly allocated buffer with size 'size'
|
||||
int streamOut (char** buf, size_t* size);
|
||||
// stream out to a preallocate buffer with buffer size 'size'
|
||||
int streamOut (char* buf, size_t len);
|
||||
|
||||
// stream in from a buffer
|
||||
// this function is called after one has read in the header
|
||||
// information already
|
||||
int streamIn (char* buf, size_t len);
|
||||
|
||||
// stream out to a preallocate buffer with buffer size 'len'
|
||||
// and data size 'datasize'
|
||||
int streamOut (char* buf, size_t len, size_t datasize);
|
||||
|
||||
// retrieve header information
|
||||
static int readHeader (char* buf, size_t len, size_t* datasize);
|
||||
|
||||
// return header length
|
||||
static size_t headerLen (void);
|
||||
|
||||
private:
|
||||
// callback object
|
||||
rsvcCbk cbk_;
|
||||
|
||||
// data object
|
||||
rsvcData data_;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
68
extensions/cdevGenericServer/include/rsvcServerConfig.h
Normal file
68
extensions/cdevGenericServer/include/rsvcServerConfig.h
Normal file
@@ -0,0 +1,68 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// RSVC Configuration Class
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_SERVER_CONFIG_H
|
||||
#define _RSVC_SERVER_CONFIG_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <rsvcConfig.h>
|
||||
|
||||
#define RSVC_DBASE_HOME "/tmp/"
|
||||
#define RSVC_SERVER_ENV "RSVC_SERVER_CONFIG"
|
||||
|
||||
class rsvcServerConfig
|
||||
{
|
||||
public:
|
||||
static int configure (char* filename = 0);
|
||||
// this is the port all servers to connected to (udp)
|
||||
static unsigned short serverPort (void);
|
||||
// this is the port all client program to connect to
|
||||
static unsigned short port (void);
|
||||
static size_t dbasePageSize (void);
|
||||
static size_t dbaseCacheSize (void);
|
||||
static size_t dbaseCacheMax (void);
|
||||
static size_t dbaseCacheLf (void);
|
||||
static size_t maxNoFiles (void);
|
||||
static char* key (void);
|
||||
static char* table (void);
|
||||
static char* keyType (void);
|
||||
static char* keyExp (void);
|
||||
static char* dbaseHome (void);
|
||||
static char* tableNameExt (void);
|
||||
static char* monitorTag (void);
|
||||
static char* queryTag (void);
|
||||
static char** defaultDbases (void);
|
||||
|
||||
protected:
|
||||
static unsigned short port_;
|
||||
static size_t pageSize_;
|
||||
static size_t cacheSize_;
|
||||
static size_t cacheMax_;
|
||||
static size_t cacheLf_;
|
||||
static size_t maxnofiles_;
|
||||
static char* keyName_;
|
||||
static char* keyType_;
|
||||
static char* keyExp_;
|
||||
static char* tableName_;
|
||||
static char* dbaseHome_;
|
||||
static char* tableNameExt_;
|
||||
static char* monitorTag_;
|
||||
static char* queryTag_;
|
||||
static char** defaultDbases_;
|
||||
};
|
||||
#endif
|
||||
106
extensions/cdevGenericServer/include/rsvcServerStore.h
Normal file
106
extensions/cdevGenericServer/include/rsvcServerStore.h
Normal file
@@ -0,0 +1,106 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// rsvcServerStore Class for JLAB Control System Use Only
|
||||
//
|
||||
// This is a storage class for all network servers running
|
||||
// in the JLAB control system
|
||||
//
|
||||
// This database has a fixed definition as the following
|
||||
// "table" "cdevServers"
|
||||
// "key" "svid"
|
||||
// "keyExp" "name+domain"
|
||||
// "keyType" RSVC_STRING
|
||||
// "name" RSVC_STRING
|
||||
// "domain" RSVC_STRING
|
||||
// "host" RSVC_STRING
|
||||
// "owner" RSVC_STRING
|
||||
// "time" RSVC_LONG
|
||||
// "port" LONG
|
||||
// "pid" LONG
|
||||
//
|
||||
// the following are appended by this class
|
||||
// 0 --> active
|
||||
// "status" 1 --> dormant
|
||||
// 2 --> dead
|
||||
// 3 --> newserver
|
||||
//
|
||||
// 0 --> normal
|
||||
// "severity" 1 --> minor
|
||||
// 2 --> major
|
||||
//
|
||||
// "ping" RSVC_LONG
|
||||
// "client" RSVC_LONG
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_SERVER_STORE_H
|
||||
#define _RSVC_SERVER_STORE_H
|
||||
|
||||
#ifdef _CDEV_MANAGE_SERVERS
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <sys/types.h>
|
||||
#include <sys/timeb.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <rsvcDataStoreMem.h>
|
||||
|
||||
class rsvcCacheData;
|
||||
|
||||
class rsvcServerStore: public rsvcDataStoreMem
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
rsvcServerStore (void);
|
||||
~rsvcServerStore (void);
|
||||
|
||||
// inherited operations
|
||||
virtual int putValue (rsvcNetData& incoming,
|
||||
rsvcNetData* outdata[], size_t* num,
|
||||
int overwrite = 0);
|
||||
|
||||
virtual int setValue (rsvcNetData& incoming,
|
||||
rsvcNetData* outdata[], size_t* num);
|
||||
|
||||
virtual void handleClose (void* ptr);
|
||||
|
||||
// check all data inside table
|
||||
void checkAll (void);
|
||||
|
||||
protected:
|
||||
// check whether a data is valid or not by checking
|
||||
// status field of cached data
|
||||
int dataValid (rsvcCacheData* data);
|
||||
|
||||
// update ping number
|
||||
void ping (rsvcCacheData* data);
|
||||
|
||||
// check ping number
|
||||
void checkPing (rsvcCacheData* data);
|
||||
|
||||
private:
|
||||
// Fixed table definition
|
||||
rsvcData tdata_;
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
45
extensions/cdevGenericServer/include/rsvcSignal.h
Normal file
45
extensions/cdevGenericServer/include/rsvcSignal.h
Normal file
@@ -0,0 +1,45 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// rsvc server signal handler
|
||||
//
|
||||
// Author:
|
||||
// Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_SIGNAL_HANDLER_H
|
||||
#define _RSVC_SIGNAL_HANDLER_H
|
||||
|
||||
class cdevReactor;
|
||||
|
||||
extern int rsvc_finished;
|
||||
extern cdevReactor* rsvc_reactor;
|
||||
|
||||
class rsvcSignal
|
||||
{
|
||||
public:
|
||||
// operation
|
||||
static int registerSignalHandlers (void);
|
||||
|
||||
// all signal handlers
|
||||
static void signalFunc (int signo);
|
||||
|
||||
private:
|
||||
// all signals we want to catch
|
||||
static int signals[];
|
||||
static int numSignals;
|
||||
// deny direct access
|
||||
rsvcSignal (void);
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
304
extensions/cdevGenericServer/include/rsvcSlist.h
Normal file
304
extensions/cdevGenericServer/include/rsvcSlist.h
Normal file
@@ -0,0 +1,304 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// Single Linked List for pointers void *
|
||||
//
|
||||
// Note: remove and clean operations on the list
|
||||
// will only remove link nodes without removal of
|
||||
// the content inside the nodes. It is callers'
|
||||
// responsiblity to clean up those contents
|
||||
//
|
||||
// This is unsafe C++ practice, use this list at you own risk
|
||||
//
|
||||
// Reason for this list: It is very difficult to instantiate
|
||||
// a template class in a stand alone shared library
|
||||
//
|
||||
// Author: Jie Chen
|
||||
// CEBAF Data Acquisition Group
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_SLIST_H
|
||||
#define _RSVC_SLIST_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined (RSVC_USE_THREAD) && defined (_REENTRANT)
|
||||
#include <cpSynch.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
typedef void* rsvcSlistItem;
|
||||
|
||||
//======================================================================
|
||||
// class rsvcSlist
|
||||
// Single Linked List for void* pointer
|
||||
//======================================================================
|
||||
class rsvcSlistLink;
|
||||
class rsvcSlistIterator;
|
||||
class rsvcSlistCursor;
|
||||
class rsvcHash;
|
||||
|
||||
class rsvcSlist
|
||||
{
|
||||
public:
|
||||
// constructors
|
||||
rsvcSlist (void);
|
||||
rsvcSlist (const rsvcSlist & source);
|
||||
virtual ~rsvcSlist (void);
|
||||
|
||||
// operations
|
||||
|
||||
// add list item to the beginning of the list
|
||||
virtual void add (rsvcSlistItem value);
|
||||
// add item to the end of list
|
||||
virtual void addToEnd (rsvcSlistItem value);
|
||||
|
||||
// remove a list item from the list
|
||||
// return 0: nothing to remove
|
||||
// return 1: remove success
|
||||
virtual int remove (rsvcSlistItem value);
|
||||
|
||||
// clean up the list.
|
||||
virtual void deleteAllValues (void);
|
||||
|
||||
// return first element of the list
|
||||
virtual rsvcSlistItem firstElement (void);
|
||||
|
||||
// return last element of the list
|
||||
virtual rsvcSlistItem lastElement (void);
|
||||
|
||||
// duplicate ths whole list
|
||||
virtual rsvcSlist* duplicate (void);
|
||||
|
||||
// check whether this list contains a particular item
|
||||
// return 1: yes. return 0: no
|
||||
virtual int includes (rsvcSlistItem value);
|
||||
|
||||
// Is list empty
|
||||
// return 1: yes. return 0: no
|
||||
virtual int isEmpty (void);
|
||||
|
||||
// remove first element of the list
|
||||
virtual void removeFirst (void);
|
||||
|
||||
// return number of elements inside the list
|
||||
virtual int count (void);
|
||||
|
||||
protected:
|
||||
// data field
|
||||
rsvcSlistLink* ptrToFirstLink;
|
||||
|
||||
// number elements in the list
|
||||
int count_;
|
||||
|
||||
#if defined (RSVC_USE_THREAD) && defined (_REENTRANT)
|
||||
cpMutex lock_;
|
||||
#endif
|
||||
|
||||
// some internal functions which must be called with lock held
|
||||
virtual void add_i (rsvcSlistItem value);
|
||||
virtual int isEmpty_i (void) const;
|
||||
virtual void deleteAllValues_i (void);
|
||||
virtual void removeFirst_i (void);
|
||||
virtual rsvcSlistItem firstElement_i (void);
|
||||
virtual rsvcSlistItem lastElement_i (void);
|
||||
|
||||
// friends
|
||||
friend class rsvcSlistIterator;
|
||||
// cannot modify list in anyways
|
||||
friend class rsvcSlistCursor;
|
||||
friend class rsvcHash;
|
||||
|
||||
private:
|
||||
// deny access to assignment operation
|
||||
rsvcSlist& operator = (const rsvcSlist& list);
|
||||
};
|
||||
|
||||
//======================================================================
|
||||
// class rsvcSlistLink
|
||||
// Single linked list link node
|
||||
//======================================================================
|
||||
class rsvcSlistLink
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
rsvcSlistLink (rsvcSlistItem linkValue, rsvcSlistLink * nextPtr);
|
||||
|
||||
// insert a new element following the current value
|
||||
rsvcSlistLink* insert (rsvcSlistItem val);
|
||||
// return data value
|
||||
rsvcSlistItem data (void);
|
||||
|
||||
// return next data item
|
||||
rsvcSlistLink* next (void);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// duplicate
|
||||
rsvcSlistLink* duplicate (void);
|
||||
|
||||
// data areas
|
||||
rsvcSlistItem value;
|
||||
rsvcSlistLink* ptrToNextLink;
|
||||
|
||||
// friends
|
||||
friend class rsvcSlist;
|
||||
friend class rsvcSlistIterator;
|
||||
friend class rsvcSlistCursor;
|
||||
};
|
||||
|
||||
//===================================================================
|
||||
// class rsvcSlistIterator
|
||||
// implements iterator protocol for linked lists
|
||||
// also permits removal and addition of elements
|
||||
//===================================================================
|
||||
|
||||
class rsvcHashIterator;
|
||||
|
||||
class rsvcSlistIterator
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
rsvcSlistIterator (rsvcSlist& aList);
|
||||
|
||||
// iterator protocol
|
||||
virtual int init (void);
|
||||
virtual rsvcSlistItem operator () (void);
|
||||
virtual int operator ! (void);
|
||||
virtual int operator ++ (void);
|
||||
virtual void operator = (rsvcSlistItem value);
|
||||
|
||||
// new methods specific to list iterators
|
||||
|
||||
// remove current item pointed by the iterator from the list
|
||||
void removeCurrent(void);
|
||||
|
||||
// add an item to the list before the position pointed by the iterator
|
||||
void addBefore(rsvcSlistItem newValue);
|
||||
|
||||
// add an item to the list after the position pointed by the iterator
|
||||
void addAfter(rsvcSlistItem newValue);
|
||||
|
||||
// search an item and move the iterator to that position
|
||||
int searchSame(rsvcSlistItem &value);
|
||||
|
||||
protected:
|
||||
// some internal functions which must be called with lock held
|
||||
virtual int init_i (void);
|
||||
// move cursor forward
|
||||
virtual int forward_i (void);
|
||||
// internal remove current
|
||||
void removeCurrent_i (void);
|
||||
// data areas
|
||||
rsvcSlistLink * currentLink;
|
||||
rsvcSlistLink * previousLink;
|
||||
rsvcSlist& theList;
|
||||
#if defined (RSVC_USE_THREAD) && defined (_REENTRANT)
|
||||
cpMutex lock_;
|
||||
#endif
|
||||
|
||||
private:
|
||||
// friend class
|
||||
friend class rsvcHashIterator;
|
||||
|
||||
// deny access of copy and assignment
|
||||
rsvcSlistIterator (const rsvcSlistIterator& ir);
|
||||
rsvcSlistIterator& operator = (const rsvcSlistIterator& ir);
|
||||
};
|
||||
|
||||
//===================================================================
|
||||
// class rsvcSlistCursor
|
||||
// implements cursor protocol for linked lists
|
||||
//===================================================================
|
||||
class rsvcSlistCursor
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
rsvcSlistCursor (const rsvcSlist& aList);
|
||||
|
||||
// iterator protocol
|
||||
virtual int init (void);
|
||||
virtual rsvcSlistItem operator () (void);
|
||||
virtual int operator ! (void);
|
||||
virtual int operator ++ (void);
|
||||
virtual void operator = (rsvcSlistItem value);
|
||||
|
||||
int searchSame (rsvcSlistItem &value);
|
||||
|
||||
protected:
|
||||
// internal functions which must be called with lock
|
||||
virtual int init_i (void);
|
||||
// data areas
|
||||
rsvcSlistLink * currentLink;
|
||||
rsvcSlistLink * previousLink;
|
||||
const rsvcSlist& theList;
|
||||
#if defined (RSVC_USE_THREAD) && defined (_REENTRANT)
|
||||
cpMutex lock_;
|
||||
#endif
|
||||
|
||||
private:
|
||||
// deny access to copy and assignment operations
|
||||
rsvcSlistCursor (const rsvcSlistCursor &);
|
||||
rsvcSlistCursor& operator = (const rsvcSlistCursor &);
|
||||
};
|
||||
|
||||
//======================================================================
|
||||
// class doubleEndedList
|
||||
// Not only keeps a pointer to first node
|
||||
// but also keeps a pointer to last node
|
||||
//======================================================================
|
||||
class rsvcDoubleEndedSlist: public rsvcSlist{
|
||||
public:
|
||||
//constructor
|
||||
rsvcDoubleEndedSlist (void);
|
||||
rsvcDoubleEndedSlist (const rsvcDoubleEndedSlist &v);
|
||||
|
||||
// override the following methods from the rsvcSlist
|
||||
virtual void add (rsvcSlistItem value);
|
||||
virtual void deleteAllValues (void);
|
||||
virtual void removeFirst (void);
|
||||
|
||||
// add new element to the end of the list
|
||||
virtual void addToEnd (rsvcSlistItem value);
|
||||
|
||||
protected:
|
||||
rsvcSlistLink *ptrToLastLink;
|
||||
|
||||
private:
|
||||
// deny access to assignment operation
|
||||
rsvcDoubleEndedSlist& operator = (const rsvcDoubleEndedSlist);
|
||||
};
|
||||
|
||||
class rsvcQueue: public rsvcDoubleEndedSlist
|
||||
{
|
||||
public:
|
||||
// constructor and destructor
|
||||
rsvcQueue (void);
|
||||
|
||||
// operations
|
||||
rsvcSlistItem dequeue (void);
|
||||
void enqueue (rsvcSlistItem value);
|
||||
rsvcSlistItem front (void);
|
||||
|
||||
private:
|
||||
// deny access to assignment and copy operations
|
||||
rsvcQueue (const rsvcQueue& queue);
|
||||
rsvcQueue& operator = (const rsvcQueue& queue);
|
||||
};
|
||||
#endif
|
||||
62
extensions/cdevGenericServer/include/rsvcSpec.h
Normal file
62
extensions/cdevGenericServer/include/rsvcSpec.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/*-----------------------------------------------------------------------------
|
||||
* Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
* Continuous Electron Beam Accelerator Facility
|
||||
*
|
||||
* This software was developed under a United States Government license
|
||||
* described in the NOTICE file included as part of this distribution.
|
||||
*
|
||||
*-----------------------------------------------------------------------------
|
||||
*
|
||||
* Description:
|
||||
* RSVC and API Specification
|
||||
*
|
||||
* Every class header file and C interface header should include
|
||||
* this header
|
||||
*
|
||||
* Authors: Jie Chen
|
||||
*
|
||||
* Revision History:
|
||||
* $Log: rsvcSpec.h,v $
|
||||
* Revision 1.1.1.1 2000/05/23 15:12:51 pal
|
||||
* cdev_psi_1.7.2
|
||||
*
|
||||
* Revision 1.1 1999/03/15 16:40:09 chen
|
||||
* New file
|
||||
*
|
||||
*
|
||||
*/
|
||||
#ifndef _RSVC_SPEC_H
|
||||
#define _RSVC_SPEC_H
|
||||
|
||||
#if defined (_WIN32)
|
||||
|
||||
#if !defined (DLLIMPORT)
|
||||
#define DLLIMPORT __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
#if !defined (DLLEXPORT)
|
||||
#define DLLEXPORT __declspec(dllexport)
|
||||
#endif
|
||||
|
||||
#if defined (_RSVC_CORE_EXPORTS_)
|
||||
#define RSVCAPI DLLEXPORT
|
||||
#define RSVC_CLASS_SPEC DLLEXPORT
|
||||
#elif defined (_RSVC_BUILD_EXE)
|
||||
#define RSVCAPI
|
||||
#define RSVC_CLASS_SPEC
|
||||
#else
|
||||
#define RSVCAPI DLLIMPORT
|
||||
#define RSVC_CLASS_SPEC DLLIMPORT
|
||||
#endif
|
||||
|
||||
#else /* WIN32 */
|
||||
|
||||
#define RSVCAPI
|
||||
#define DLLIMPORT
|
||||
#define DLLEXPORT
|
||||
#define RSVC_CLASS_SPEC
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
98
extensions/cdevGenericServer/include/rsvcStreamMsg.h
Normal file
98
extensions/cdevGenericServer/include/rsvcStreamMsg.h
Normal file
@@ -0,0 +1,98 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// RSVC Server Streamed Message
|
||||
//
|
||||
// This class allows either partial read/write not both
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_STREAM_MSG_H
|
||||
#define _RSVC_STREAM_MSG_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
class rsvcNetData;
|
||||
|
||||
class rsvcStreamMsg
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
|
||||
// create an empty stream
|
||||
rsvcStreamMsg (void);
|
||||
|
||||
// create a stream with data buffer and size and flag denoting
|
||||
// whether we delete this data buffer we we are done
|
||||
rsvcStreamMsg (char* data, size_t size, int deleteit = 1);
|
||||
|
||||
// create a stream from rsvcNetData
|
||||
rsvcStreamMsg (rsvcNetData* data);
|
||||
|
||||
// destructor
|
||||
~rsvcStreamMsg (void);
|
||||
|
||||
// attach buffer
|
||||
void attach (char* data, size_t size, int deleteit = 1);
|
||||
|
||||
// check we are in the middle of action
|
||||
int active (void) const;
|
||||
|
||||
// set action pointer
|
||||
void actionPtr (char* ptr);
|
||||
// move ptr forward
|
||||
void actionPtr (size_t n);
|
||||
// return action pointer
|
||||
char* actionPtr (void) const;
|
||||
|
||||
// total message size
|
||||
size_t length (void) const;
|
||||
|
||||
// set msg length
|
||||
void length (size_t len);
|
||||
|
||||
// base pointer
|
||||
char* base (void) const;
|
||||
|
||||
// remaining message size (or space)
|
||||
size_t size (void);
|
||||
// check whether we have reached end of message buffer
|
||||
int endMsg (void);
|
||||
|
||||
// reset everything
|
||||
void reset (void);
|
||||
|
||||
// resize buffer to twice of current size
|
||||
void resize (void);
|
||||
|
||||
private:
|
||||
|
||||
// data area
|
||||
char* buffer_;
|
||||
size_t buflen_;
|
||||
|
||||
// pointer to current action ptr
|
||||
size_t cursor_;
|
||||
|
||||
// flag denoting whether we are deleting the buffer or not
|
||||
int deleteBuffer_;
|
||||
|
||||
// flag to denoting whether this stream is in the middle of read/write
|
||||
int active_;
|
||||
|
||||
// deny copy and assignment operations
|
||||
rsvcStreamMsg (const rsvcStreamMsg& msg);
|
||||
rsvcStreamMsg& operator = (const rsvcStreamMsg& msg);
|
||||
};
|
||||
#endif
|
||||
43
extensions/cdevGenericServer/include/rsvcStreamable.h
Normal file
43
extensions/cdevGenericServer/include/rsvcStreamable.h
Normal file
@@ -0,0 +1,43 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
|
||||
// Continuous Electron Beam Accelerator Facility
|
||||
//
|
||||
// This software was developed under a United States Government license
|
||||
// described in the NOTICE file included as part of this distribution.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Description:
|
||||
// Abstract class for network streamable class
|
||||
//
|
||||
// Author: Jie Chen
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef _RSVC_STREAMABLE_H
|
||||
#define _RSVC_STREAMABLE_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <rsvcErr.h>
|
||||
|
||||
class rsvcStreamable
|
||||
{
|
||||
public:
|
||||
// virtual destrcutor
|
||||
virtual ~rsvcStreamable (void);
|
||||
// return stream size
|
||||
virtual size_t streamSize (void) = 0;
|
||||
|
||||
// stream data object out into a newly allocated buffer
|
||||
virtual int streamOut (char** buffer, size_t* size) = 0;
|
||||
|
||||
// stream data object out into a preallocated buffer
|
||||
virtual int streamOut (char* buffer, size_t len) = 0;
|
||||
|
||||
// recreate data from incoming data buffer
|
||||
virtual int streamIn (char* buffer, size_t len) = 0;
|
||||
|
||||
protected:
|
||||
rsvcStreamable (void);
|
||||
};
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user