cdev-1.7.2n

This commit is contained in:
2022-12-13 12:44:04 +01:00
commit b3b88fc333
1357 changed files with 338883 additions and 0 deletions
Binary file not shown.
Binary file not shown.
+43
View File
@@ -0,0 +1,43 @@
ARCH=OS
include ../cdevGenericServer/include/makeinclude/Makefile.$(ARCH)
APPNAME = "CDEV Simple Generic Service"
BASEDIR = $(shell pwd)
INCDIR = $(CDEV)/extensions/cdevGenericServer/include
BINDIR = ./
LIBDIR = $(CDEV)/lib/$(TARGETDIR)
CDEV_INCLUDES = -I$(CDEV)/include
CDEV_LIBS = -lcdev
CDEV_LIBDIR = $(CDEV)/lib/$(TARGETDIR)
CLASS_INCLUDES = -I./ -I$(INCDIR)
CXXEXTRA = -g $(CDEV_INCLUDES) $(CLASS_INCLUDES)
ARLIB_OBJ = .obj/$(TARGETDIR)/cdevSimpleRequestObject.o \
.obj/$(TARGETDIR)/cdevSimpleService.o \
.obj/$(TARGETDIR)/cdevTranNode.o
SHLIB_OBJ = .shobj/$(TARGETDIR)/cdevSimpleRequestObject.o \
.shobj/$(TARGETDIR)/cdevSimpleService.o \
.shobj/$(TARGETDIR)/cdevTranNode.o
TARGETS = $(LIBDIR)/libSimpleService.a $(LIBDIR)/libSimpleService.sl
targets : $(TARGETS)
$(LIBDIR)/libSimpleService.a : $(ARLIB_OBJ)
@rm -f $@
@echo "=> ar ruv $@"
@mkdir -p $(LIBDIR)
@$(LINK.a) $@ $(ARLIB_OBJ)
@ranlib $@ > /dev/null
@echo "\n -------- Completed ----------\n"
$(LIBDIR)/libSimpleService.sl : $(SHLIB_OBJ)
@rm -f $@
@echo "=> $(LINK.so) $(@F)"
@mkdir -p $(LIBDIR)
@$(LINK.so) -o $@ $(SHLIB_OBJ)
@echo "\n -------- Completed ----------\n"
+145
View File
@@ -0,0 +1,145 @@
//-----------------------------------------------------------------------------
// Copyright (c) 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 header file contains the class definitions for the classes
// associated with the construction of a model request object.
//
// Author: Walt Akers
//
// Revision History:
// cdevSimpleRequestObject.cc,v
// Revision 1.1 1996/11/21 18:22:19 akers
// Non-Server Oriented Service
//
// Revision 1.1 1996/04/30 15:37:30 akers
// Simple CDEV Service
//
// Revision 1.1.1.1 1996/02/28 16:36:21 akers
// Initial release of support for ACE Services
//
//-----------------------------------------------------------------------------
//
#include <cdevSimpleService.h>
#include <cdevSimpleRequestObject.h>
#include <cdevClock.h>
#include <cdevTranNode.h>
// *********************************************************************
// * cdevSimpleRequestObject::cdevSimpleRequestObject :
// * This constructor initializes the internals of a device/message
// * pair associated with the model server.
// *
// * Returns nothing.
// *********************************************************************
cdevSimpleRequestObject::cdevSimpleRequestObject ( char * device, char * message, cdevSystem & system)
: cdevRequestObject(device, message, system)
{
cdevData::tagC2I("transaction", &TRANSACT_TAG);
cdevData::tagC2I("transobject", &TRANSOBJ_TAG);
}
// *****************************************************************************
// * cdevSimpleRequestObject::sendNoBlock :
// * This function allows the caller to submit an asynchronous message to the
// * server for processing.
// *****************************************************************************
int cdevSimpleRequestObject::sendNoBlock (cdevData * in, cdevData * out)
{
cdevSimpleService * svc = (cdevSimpleService *)service_;
cdevTranNode * xobj = new cdevTranNode(&system_, this, out, &svc->callback);
char * Device = strdup(deviceName_);
char * Message = strdup(message_);
cdevData * Data = ((in==NULL)?new cdevData:new cdevData(*in));
svc->submit(xobj, Device, Message, Data);
return CDEV_SUCCESS;
}
// *****************************************************************************
// * cdevSimpleRequestObject::sendCallback :
// * This function allows the caller to submit an asynchronous message to the
// * server for processing.
// *****************************************************************************
int cdevSimpleRequestObject::sendCallback (cdevData * in, cdevCallback & callback)
{
cdevSimpleService * svc = (cdevSimpleService *)service_;
cdevTranNode * xobj = new cdevTranNode(&system_, this, NULL, new cdevCallback(callback));
char * Device = strdup(deviceName_);
char * Message = strdup(message_);
cdevData * Data = ((in==NULL)?new cdevData:new cdevData(*in));
xobj->enableDeleteCbk();
svc->submit(xobj, Device, Message, Data);
return CDEV_SUCCESS;
}
// *****************************************************************************
// * cdevSimpleRequestObject::send :
// * The send interface is used to provide synchronous I/O with the service.
// *
// * Returns CDEV_SUCCESS on success or CDEV_ERROR on error.
// *****************************************************************************
int cdevSimpleRequestObject::send ( cdevData * in, cdevData * out )
{
int status = CDEV_SUCCESS;
cdevSimpleService * svc = (cdevSimpleService *)service_;
cdevTranNode * xobj = new cdevTranNode(&system_, this, out, &svc->callback);
char * Device = strdup(deviceName_);
char * Message = strdup(message_);
cdevData * Data = ((in==NULL)?new cdevData:new cdevData(*in));
xobj->permanent(1);
svc->submit(xobj, Device, Message, Data);
// *********************************************************************
// * I used to wait for a response here only if the outbound cdevData
// * object was non-null. However, that provided unexpected behavior
// * to the client. Now I wait whether output data is expected or not.
// *********************************************************************
cdevTimeValue t(30.0);
cdevClock timer;
timer.schedule(NULL,t);
// *********************************************************************
// * WAITING WITH system_.pend():
// * Previously I was using system_.pend() to process events while
// * waiting for the service to respond. This resulted in a lock-up
// * when the connection could not be established or if the
// * connection collapsed while in use.
// *
// * WAITING WITH system_.poll():
// * When in a heavy inbound traffic situation, the calls from other
// * services will trample all over the inbound data coming from the
// * model service. This results in unreliable delivery and
// * processing of messages from the model server.
// *
// * WAITING WITH service_.poll():
// * So far so good.
// *********************************************************************
while(!xobj->finished() && !timer.expired()) service_->poll();
if (!xobj->finished())
{
status = CDEV_ERROR;
system_.reportError(
CDEV_SEVERITY_ERROR,
"cdevRequestObject",
this,
"Transaction wasn't processed after 30 seconds");
}
delete xobj;
return status;
}
+110
View File
@@ -0,0 +1,110 @@
//-----------------------------------------------------------------------------
// Copyright (c) 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 header file contains the class definitions for the classes
// associated with the construction of a request object.
//
// Author: Walt Akers
//
//-----------------------------------------------------------------------------
#if !defined (_CDEV_SIMPLE_REQUEST_OBJECT_H_)
#define _CDEV_SIMPLE_REQUEST_OBJECT_H_
#include <cdevRequestObject.h>
#include <cdevTranObj.h>
#include <cdevGroup.h>
#include <cdevErrCode.h>
// *****************************************************************************
// * cdevSimpleRequestObject:
// * The cdevSimpleRequestObject class provides the interface for sending
// * messages to a server. All device/message commands are routed
// * through a cdevSimpleRequestObject either directly or indirectly.
// *****************************************************************************
class cdevSimpleRequestObject : public cdevRequestObject
{
public:
// *********************************************************************
// * cdevSimpleRequestObject::cdevSimpleRequestObject :
// * This constructor initializes the internals of a device/message
// * pair associated with the server.
// *
// * Returns nothing.
// *********************************************************************
cdevSimpleRequestObject ( char * device, char * message,
cdevSystem & system = cdevSystem::defaultSystem() );
// *********************************************************************
// * cdevSimpleRequestObject::~cdevSimpleRequestObject :
// * This destructor performs any deallocation or shutdown operations
// * necessary, prior to the destruction of the object.
// *
// * Returns nothing.
// *********************************************************************
~cdevSimpleRequestObject ( void ) {}
// *********************************************************************
// * cdevSimpleRequestObject::send :
// * The send interface is used to provide synchronous I/O with the
// * service.
// *
// * Returns CDEV_SUCCESS on success or CDEV_ERROR on error.
// *********************************************************************
int send ( cdevData & in, cdevData & out )
{ return send(&in, &out); }
int send ( cdevData * in, cdevData & out )
{ return send(in, &out); }
int send ( cdevData & in, cdevData * out )
{ return send(&in, out); }
int send ( cdevData * in, cdevData * out );
// *********************************************************************
// * cdevSimpleRequestObject::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.
// *********************************************************************
int sendNoBlock (cdevData & in, cdevData & out)
{ return sendNoBlock(&in, &out); }
int sendNoBlock (cdevData * in, cdevData & out)
{ return sendNoBlock(in, &out); }
int sendNoBlock (cdevData & in, cdevData * out)
{ return sendNoBlock(&in, out); }
int sendNoBlock (cdevData * in, cdevData * out);
// *********************************************************************
// * cdevSimpleRequestObject::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.
// *********************************************************************
int sendCallback (cdevData & in, cdevCallback & callback)
{ return sendCallback(&in, callback); }
int sendCallback (cdevData * in, cdevCallback & callback);
// *********************************************************************
// * cdevSimpleRequestObject::className :
// * This function returns the name of the class as a constant string
// *********************************************************************
const char * className ( void ) const { return "cdevSimpleRequestObject"; }
private:
int TRANSACT_TAG;
int TRANSOBJ_TAG;
};
#endif /* _CDEV_SIMPLE_REQUEST_OBJECT_H_ */
+419
View File
@@ -0,0 +1,419 @@
// -----------------------------------------------------------------------------
// Copyright (c) 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 header file contains the class definitions for the classes
// associated with the construction of a service.
//
// Author: Walt Akers
//
// Revision History:
// cdevSimpleService.cc,v
// Revision 1.1 1996/11/21 18:22:24 akers
// Non-Server Oriented Service
//
// Revision 1.1 1996/04/30 15:37:38 akers
// Simple CDEV Service
//
// Revision 1.2 1996/03/21 13:57:55 akers
// Major Modifications
//
// Revision 1.1.1.1 1996/02/28 16:36:21 akers
// Initial release of support for ACE Services
//
// -----------------------------------------------------------------------------
#include <cdevSimpleService.h>
#include <cdevSimpleRequestObject.h>
#include <cdevClock.h>
#include <ctype.h>
// *****************************************************************************
// * defaultCallback:
// * This static function is the default callback function that will be
// * utilized for send and sendNoBlock.
// *****************************************************************************
static void defaultCallback(int, void *, cdevRequestObject &, cdevData &)
{
}
// *****************************************************************************
// * trim :
// * This method is used to remove any extraneous spaces from a message.
// *****************************************************************************
static char * trim ( char * ptr )
{
char * s1 = ptr;
char * s2;
if(ptr!=NULL)
{
// *************************************************************
// * Remove leading space from the string.
// *************************************************************
for(s1=ptr; isspace(*s1) && s1!=0; s1++);
if(s1!=ptr) memmove(ptr, s1, strlen(s1)+1);
// *************************************************************
// * Remove any multi-space entries from the string.
// *************************************************************
for(s1=ptr; *s1; s1++) if(isspace(*s1))
{
for(s2=s1; *s2 && isspace(*s2); s2++);
if(s2>s1+1) memmove(s1+1, s2, strlen(s2)+1);
}
// *************************************************************
// * Remove trailing space from the string.
// *************************************************************
for(s1=&ptr[strlen(ptr)-1]; s1>=ptr && isspace(*s1); s1--) *s1=0;
}
return ptr;
}
// *****************************************************************************
// * cdevSimpleService::cdevSimpleService :
// * This constructor is responsible for performing all service
// * initialization.
// *****************************************************************************
cdevSimpleService::cdevSimpleService ( char * name, cdevSystem & system )
: serviceFD(-1),
queue(),
selector(),
callback(defaultCallback, NULL),
cdevService(name, system)
{
// *********************************************************************
// * Install the ACE_service specific flags
// *********************************************************************
installTags();
// *********************************************************************
// * Clear local variables
// *********************************************************************
memset(&serviceFD, 0, sizeof(serviceFD));
// *********************************************************************
// * Assign the value of the read file descriptor for the selector to
// * the serviceFD variable.
// *********************************************************************
serviceFD = selector.readfd();
}
// *****************************************************************************
// * cdevSimpleService::~cdevSimpleService :
// * The destructor is protected to prevent it from being called directly.
// * The destructor performs any clean-up or shutdown operations.
// *
// * Returns nothing.
// *****************************************************************************
cdevSimpleService::~cdevSimpleService ( void )
{
// *********************************************************************
// * Call flush to process all outbound messages.
// *********************************************************************
flush();
// *********************************************************************
// * Clear the file descriptors used by cdev for polling.
// *********************************************************************
memset(&serviceFD, 0, sizeof(serviceFD));
}
// *****************************************************************************
// * cdevSimpleService::installTags :
// * Installs the tags that the service and service applications
// * will use. This function is static to allow servers to setup
// * the necessary tags without having to instanciate a cdevSimpleService object.
// *****************************************************************************
void cdevSimpleService::installTags ( void )
{
}
// *********************************************************************
// * cdevSimpleService::getRequestObject :
// * This is the interface that cdev objects will use to obtain a
// * cdevSimpleRequestObject object. The cdevSimpleRequestObject
// * represents a combined device and message pair that is associated
// * with the cdevSimpleService.
// *
// * Returns CDEV_SUCCESS on success or CDEV_ERROR on error.
// *********************************************************************
int cdevSimpleService::getRequestObject ( char * device, char * message, cdevRequestObject * &req)
{
req = new cdevSimpleRequestObject (device, message, system_);
return (req ? CDEV_SUCCESS : CDEV_ERROR);
}
// *****************************************************************************
// * cdevSimpleService::getFd
// * This function will return the list of file descriptors that the
// * cdevSimpleService is using. This will allow the file descriptors to be
// * used in global select and poll calls performed at the cdevSystem class
// * level.
// *
// * Returns CDEV_SUCCESS on success or CDEV_ERROR on error.
// *****************************************************************************
int cdevSimpleService::getFd ( int * &fd, int & numFd )
{
fd = &serviceFD;
numFd = 1;
return CDEV_SUCCESS;
}
// *********************************************************************
// * cdevSimpleService::flush :
// * This function flushes all communications buffers that the
// * service may have open.
// *
// * Returns CDEV_SUCCESS on success or CDEV_ERROR on error.
// *********************************************************************
int cdevSimpleService::flush ( void )
{
return CDEV_SUCCESS;
}
// *****************************************************************************
// * cdevSimpleService::poll :
// * This function polls the file descriptors used by the service
// * until one of them becomes active or a discrete amount of time
// * has expired.
// *
// * Returns CDEV_SUCCESS on success or CDEV_ERROR on error.
// *****************************************************************************
int cdevSimpleService::poll ( void )
{
return pend(0.0001);
}
// *****************************************************************************
// * cdevSimpleService::pend :
// * Pends until the named file descriptor (or any file descriptor
// * if fd = -1) is ready. Will pend forever if the descriptor does
// * not become active.
// *
// * Returns CDEV_SUCCESS on success or CDEV_ERROR on error.
// *****************************************************************************
int cdevSimpleService::pend ( int )
{
while(!queue.empty()) handleOneEvent();
// *********************************************************************
// * Empty the contents of the cdevSelector object.
// *********************************************************************
selector.purge();
return CDEV_SUCCESS;
}
// *****************************************************************************
// * cdevSimpleService::pend :
// * Pends until the named file descriptor (or any file descriptor
// * if fd = -1) is ready. Will pend for no longer than the user
// * specified number of seconds.
// *
// * Returns CDEV_SUCCESS on success or CDEV_ERROR on error.
// *****************************************************************************
int cdevSimpleService::pend ( double seconds, int )
{
cdevTimeValue sec = seconds;
cdevClock timer;
timer.schedule(NULL, sec);
do {
handleOneEvent();
} while(!timer.expired() && !queue.empty());
// *********************************************************************
// * Empty the contents of the cdevSelector object.
// *********************************************************************
return CDEV_SUCCESS;
}
// *****************************************************************************
// * cdevSimpleService::submit :
// * This is the mechanism that the request object will use to submit a
// * message to the service. It is important to note that all of the
// * data provided to this object becomes the property of the service and
// * must not be accessed afterwords.
// *****************************************************************************
int cdevSimpleService::submit (cdevTranNode *node,
char *device,
char *message,
cdevData *data)
{
cdevTransaction * transaction = new cdevTransaction;
cdevServiceMessage * packet;
// *********************************************************************
// * Populate the cdevTransaction structure with data.
// *********************************************************************
transaction->transnum = node->transaction();
transaction->transobj = node;
// *********************************************************************
// * Call trim on the device and message to remove any extra spaces.
// *********************************************************************
trim(device);
trim(message);
// *********************************************************************
// * Populate the packet variable with the data.
// *********************************************************************
packet = new cdevServiceMessage(transaction, device, message, data);
// *********************************************************************
// * Place the cdevServiceMessage into the queue.
// *********************************************************************
queue.enqueue(packet);
// *********************************************************************
// * Add an event to the cdevSelector object in order to trigger polling
// *********************************************************************
selector.insertEvent();
return CDEV_SUCCESS;
}
// *****************************************************************************
// * cdevSimpleService::dequeue :
// * The handleOneEvent method uses this function to extract a single
// * message from the service and process it. All data objects obtained
// * through this function become the property of the caller and must
// * be deleted.
// *****************************************************************************
int cdevSimpleService::dequeue (cdevTransaction * &transaction,
char * &device,
char * &message,
cdevData * &data)
{
int result = CDEV_ERROR;
cdevServiceMessage * packet = (cdevServiceMessage *)queue.dequeue();
if(packet!=NULL)
{
transaction = packet->transaction;
device = packet->device;
message = packet->message;
data = packet->data;
result = CDEV_SUCCESS;
delete packet;
}
return result;
}
// *****************************************************************************
// * cdevSimpleService::enqueue :
// * The handleOneEvent method uses this function to dispatch callbacks
// * after the function has been processed.
// *****************************************************************************
int cdevSimpleService::enqueue (int status,
cdevTransaction * trans,
char * device,
char * message,
cdevData * data)
{
cdevTranNode * node = trans?trans->transobj:NULL;
if(node!=NULL && node->validate(trans->transnum)==CDEV_SUCCESS)
{
cdevData localData;
// *************************************************************
// * cdevData must be returned to the caller.
// *************************************************************
if(node->resultData_==NULL) node->resultData_ = (data?data:&localData);
else *(node->resultData_) = (data?*data:localData);
// *************************************************************
// * Call the user provided callback function.
// *************************************************************
(node->userCallback_->callbackFunction())
(status,
node->userCallback_->userarg(),
*node->reqObj_,
*node->resultData_);
// *************************************************************
// * Tag the transaction as finished
// *************************************************************
node->finished(1);
// *************************************************************
// * Delete the cdevTranNode if it is not permanent.
// *************************************************************
if(!node->permanent()) delete node;
// *************************************************************
// * Remove the event from the selector object.
// *************************************************************
selector.removeEvent();
}
// *********************************************************************
// * Delete the components of the message.
// *********************************************************************
if(trans != NULL) delete trans;
if(device != NULL) delete device;
if(message != NULL) delete message;
if(data != NULL) delete data;
return CDEV_SUCCESS;
}
// *****************************************************************************
// * cdevSimpleService::handleOneEvent :
// * This method allows the caller to handle individual events. This handler
// * only processes one event and then returns to the caller.
// *****************************************************************************
void cdevSimpleService::handleOneEvent ( void )
{
cdevTransaction * transaction;
char * device;
char * message;
cdevData * data;
if(dequeue(transaction, device, message, data)==CDEV_SUCCESS)
{
enqueue(CDEV_SUCCESS, transaction, device, message, data);
}
}
// *****************************************************************************
// * cdevSimpleService::getNameServer :
// * This function should obtain the default name server for this object.
// * It does nothing for now.
// *****************************************************************************
int cdevSimpleService::getNameServer(cdevDevice * &ns)
{
ns = 0;
return CDEV_SUCCESS;
}
+229
View File
@@ -0,0 +1,229 @@
// -----------------------------------------------------------------------------
// Copyright (c) 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 header file contains the class definitions for the classes
// associated with the construction of a model service.
//
// Author: Walt Akers
//
// -----------------------------------------------------------------------------
#if !defined (_CDEV_SIMPLE_SERVICE_H_)
#define _CDEV_SIMPLE_SERVICE_H_
#include <cdevService.h>
#include <cdevTranNode.h>
#include <cdevSelector.h>
#include <fifo.h>
// ****************************************************************************
// * Service Loader:
// * The first step in building a new service is to construct a service
// * loader function. This function will allow cdev to dynamically
// * initialize a service by name.
// *
// * The function should adhere to the following naming convention...
// * cdevService * newXXX (char * name, cdevSystem * system);
// *
// * The 'XXX' should be replaced with the name of the service
// * class.
// *
// * The function should also be declared as 'extern "C"' to allow it
// * to be called and loaded from within an external shared library module.
// *
// * This function serves only to construct a new instance of the
// * specified service, and return it to the instanciating mechanism.
// *****************************************************************************
// extern "C" cdevService *newcdevSimpleService ( char * name, cdevSystem * system );
// *****************************************************************************
// * This structure is used to maintain a cdevTranNode class and its matching
// * transaction number. The transaction number will be used to validate
// * the cdevTranNode later.
// *****************************************************************************
typedef struct
{
int transnum;
cdevTranNode * transobj;
} cdevTransaction;
// ******************************************************************************
// * This is a structure that is used to store the components that are placed in
// * the queues.
// ******************************************************************************
class cdevServiceMessage
{
public:
cdevTransaction * transaction;
char * device;
char * message;
cdevData * data;
cdevServiceMessage(cdevTransaction *Transaction=NULL,
char *Device=NULL,
char *Message=NULL,
cdevData *Data=NULL)
: transaction(Transaction),
device(Device),
message(Message),
data(Data)
{
}
};
// *****************************************************************************
// * cdevSimpleService:
// * This is class provides the mechanisms that the cdev system will use
// * to communicate with the model service.
// *****************************************************************************
class cdevSimpleService : public cdevService
{
friend class cdevSimpleRequestObject;
public:
// *********************************************************************
// * cdevSimpleService::cdevSimpleService :
// * This constructor is responsible for performing all service
// * initialization.
// *********************************************************************
cdevSimpleService ( char * name, cdevSystem & system );
// *********************************************************************
// * cdevSimpleService::~cdevSimpleService :
// * The destructor is protected to prevent it from being called
// * directly. The destructor performs any clean-up or shutdown
// * operations.
// *
// * Returns nothing.
// *********************************************************************
~cdevSimpleService ( void );
// *********************************************************************
// * cdevSimpleService::installTags :
// * Installs the tags that the service and service applications
// * will use. This function is static to allow servers to setup
// * the necessary tags without having to instanciate a
// * cdevSimpleService object.
// *********************************************************************
void installTags ( void );
// *********************************************************************
// * cdevSimpleService::getRequestObject :
// * This is the interface that cdev objects will use to obtain a
// * cdevSimpleRequestObject object. The cdevSimpleRequestObject
// * represents a combined device and message pair that is associated
// * with the cdevSimpleService.
// *
// * Returns CDEV_SUCCESS on success or CDEV_ERROR on error.
// *********************************************************************
int getRequestObject (char *, char *, cdevRequestObject * &);
// *********************************************************************
// * cdevSimpleService::getFd
// * This function will return the list of file descriptors that the
// * cdevSimpleService is using. This will allow the file
// * descriptors to be used in global select and poll calls performed
// * at the cdevSystem class level.
// *
// * Returns CDEV_SUCCESS on success or CDEV_ERROR on error.
// *********************************************************************
int getFd ( int * &fd, int & numFd );
// *********************************************************************
// * cdevSimpleService::flush :
// * This function flushes all communications buffers that the
// * service may have open.
// *
// * Returns CDEV_SUCCESS on success or CDEV_ERROR on error.
// *********************************************************************
int flush ( void );
// *********************************************************************
// * cdevSimpleService::poll :
// * This function polls the file descriptors used by the service
// * until one of them becomes active or a discrete amount of time
// * has expired.
// *
// * Returns CDEV_SUCCESS on success or CDEV_ERROR on error.
// *********************************************************************
int poll ( void );
// *********************************************************************
// * cdevSimpleService::pend :
// * Pends until the named file descriptor (or any file descriptor
// * if fd = -1) is ready. Will pend for no longer than the user
// * specified number of seconds.
// *
// * Returns CDEV_SUCCESS on success or CDEV_ERROR on error.
// *********************************************************************
int pend ( double seconds, int = -1);
// *********************************************************************
// * cdevSimpleService::pend :
// * Pends until the named file descriptor (or any file descriptor
// * if fd = -1) is ready. Will pend forever if the descriptor does
// * not become active.
// *
// * Returns CDEV_SUCCESS on success or CDEV_ERROR on error.
// *********************************************************************
int pend ( int = -1);
// *********************************************************************
// * cdevSimpleService::submit :
// * This is the mechanism that the request object will use to submit
// * a message to the service. It is important to note that all of
// * the data provided to this object becomes the property of the
// * service and must not be accessed afterwords.
// *********************************************************************
virtual int submit (cdevTranNode *, char *, char *, cdevData *);
// *********************************************************************
// * cdevSimpleService::dequeue :
// * The handleOneEvent method uses this function to extract a single
// * message from the service and process it. All data objects
// * obtained through this function become the property of the caller
// * and must be deleted.
// *********************************************************************
virtual int dequeue (cdevTransaction * &, char * &, char * &, cdevData * &);
// *********************************************************************
// * cdevSimpleService::enqueue :
// * The handleOneEvent method uses this function to dispatch
// * callbacks after the function has been processed.
// *********************************************************************
virtual int enqueue (int, cdevTransaction *, char *, char *, cdevData *);
// *********************************************************************
// * cdevSimpleService::handleOneEvent :
// * This method allows the caller to handle individual events. This
// * handler only processes one event and then returns to the caller.
// *********************************************************************
virtual void handleOneEvent ( void );
// *********************************************************************
// * cdevSimpleService::getNameServer :
// * This function should obtain the default name server for this
// * object. It does nothing for now.
// *********************************************************************
int getNameServer(cdevDevice * &ns);
private:
FifoQueue queue;
int serviceFD;
cdevSelector selector;
cdevCallback callback;
};
#endif /* _CDEV_SIMPLE_SERVICE_H_ */
+145
View File
@@ -0,0 +1,145 @@
//-----------------------------------------------------------------------------
// Copyright (c) 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 header file contains the class definitions for the classes
// associated with a cdevTranNode. The cdevTranNode is an extension
// of the cdevTranObj. It provides a mechanism for tracking allocated
// and unallocated cdevTranObj objects and prevents inadvertent writes
// to unallocated memory.
//
// Author: Walt Akers
//
// Revision History:
// cdevTranNode.cc,v
// Revision 1.1 1996/11/21 18:22:27 akers
// Non-Server Oriented Service
//
// Revision 1.1 1996/04/30 15:37:41 akers
// Simple CDEV Service
//
// Revision 1.1.1.1 1996/02/28 16:36:20 akers
// Initial release of support for ACE Services
//
// Revision 2.0 1995/10/04 19:21:37 withers
// New CVS repository
//
// Revision 1.1.1.1 1995/10/04 18:45:08 bickley
// CVS start of high-level apps
//
// Revision 1.1.1.1 1995/09/15 17:15:30 withers
// MODEL SERVICE SOURCE
//
//
#include <cdevTranNode.h>
// *****************************************************************************
// * Static class members requiring initialization.
// *****************************************************************************
int cdevTranNode::count = 0;
cdevTranNode * cdevTranNode::freeList = NULL;
cdevTranNode * cdevTranNode::activeList = NULL;
int cdevTranNode::initialized = 1;
// *****************************************************************************
// * cdevTranNode::new :
// * This is the internal mechanism that is used to allocate new cdevTranNode
// * objects. If an object is already available on the freelist, this
// * function will allocate from that list to the activeList. Otherwise, a
// * block of cdevTranNode objects will be allocated to repopulate the
// * freeList first.
// *****************************************************************************
void * cdevTranNode::operator new ( size_t )
{
cdevTranNode * node;
int i;
if(freeList==NULL)
{
freeList = ::new cdevTranNode[16];
for(i=0; i<16; i++)
{
freeList[i].next = (i<15) ? &freeList[i+1] : NULL;
freeList[i].allocated = FALSE;
freeList[i].finished_ = FALSE;
freeList[i].transaction_ = 0;
}
cdevTranNode::count-=16;
}
node = freeList;
freeList = node->next;
node->allocated = TRUE;
node->next = activeList;
activeList = node;
return node;
}
// *****************************************************************************
// * cdevTranNode::delete :
// * This function is used to return an allocated cdevTranNode to the
// * freeList for later allocation to another caller. This function will
// * clear the transaction flag and will clear the allocated flag.
// *****************************************************************************
void cdevTranNode::operator delete ( void * ptr )
{
cdevTranNode * node = activeList;
cdevTranNode * prev = NULL;
if(ptr != NULL)
{
while(node!=NULL && node!=(cdevTranNode *)ptr)
{
prev = node;
node = prev->next;
}
if(node!=NULL)
{
if(prev) prev->next = node->next;
else activeList = node->next;
}
node = (cdevTranNode *)ptr;
node->allocated = FALSE;
node->finished_ = FALSE;
node->transaction_ = 0;
node->next = freeList;
freeList = node;
}
}
// *****************************************************************************
// * cdevTranNode::find:
// * Allows the caller to locate a cdevTranNode using the transaction number.
// *****************************************************************************
cdevTranNode * cdevTranNode::find ( int Transaction )
{
cdevTranNode * node = activeList;
while(node!=NULL && node->transaction_ != Transaction)
{
node = node->next;
}
return node;
}
// *****************************************************************************
// * cdevTranNode::init:
// * Allows the caller to initialize static members of the cdevTranNode class
// *****************************************************************************
void cdevTranNode::init ( void )
{
if(!initialized)
{
count = 0;
freeList = NULL;
activeList = NULL;
initialized = 1;
}
}
+165
View File
@@ -0,0 +1,165 @@
//-----------------------------------------------------------------------------
// Copyright (c) 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 header file contains the class definitions for the classes
// associated with a cdevTranNode. The cdevTranNode is an extension
// of the cdevTranObj. It provides a mechanism for tracking allocated
// and unallocated cdevTranObj objects and prevents inadvertent writes
// to unallocated memory.
//
// Author: Walt Akers
//
//
//
#ifndef _CDEV_TRAN_NODE_H_
#define _CDEV_TRAN_NODE_H_
#include <cdevTranObj.h>
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
class cdevTranNode : public cdevTranObj
{
private:
static int count;
static cdevTranNode * freeList;
static cdevTranNode * activeList;
static int initialized;
cdevTranNode * next;
int allocated;
protected:
int finished_;
int permanent_;
int transaction_;
public:
cdevTranNode ( void );
cdevTranNode ( cdevSystem*, cdevRequestObject*, cdevData*, cdevCallback*);
~cdevTranNode( void );
void * operator new ( size_t size );
void operator delete ( void * ptr );
int validate ( int Transaction );
void transaction ( int Transaction );
int transaction ( void );
void finished ( int Finished );
int finished ( void );
void permanent ( int Permanent );
int permanent ( void );
static cdevTranNode * find ( int Transaction );
static void init ( void );
};
// *****************************************************************************
// * cdevTranNode :
// * Allocates a cdevTranNode with no contents.
// *****************************************************************************
inline cdevTranNode::cdevTranNode ( void )
: cdevTranObj(), finished_(FALSE), permanent_(FALSE)
{
if(!initialized) init();
transaction_ = count++;
disableDeleteCbk();
}
// *****************************************************************************
// * cdevTranNode :
// * Allocates a cdevTranNode populated with the required data values.
// *****************************************************************************
inline cdevTranNode::cdevTranNode ( cdevSystem * sys, cdevRequestObject *req,
cdevData * data, cdevCallback * callback )
: cdevTranObj(sys, req, data, callback), finished_(FALSE), permanent_(FALSE)
{
if(!initialized) init();
transaction_ = count++;
disableDeleteCbk();
}
// *****************************************************************************
// * ~cdevTranNode:
// * Deletes the cdevTranNode object.
// *****************************************************************************
inline cdevTranNode::~cdevTranNode ( void )
{
}
// *****************************************************************************
// * cdevTranNode::validate:
// * Allows the user to verify that the cdevTranNode that he has a pointer
// * to, corresponds to the specified Transaction number.
// *****************************************************************************
inline int cdevTranNode::validate ( int Transaction )
{
return (allocated==TRUE && transaction_==Transaction)?CDEV_SUCCESS:CDEV_NOTFOUND;
}
// *****************************************************************************
// * cdevTranNode::transaction:
// * Allows the caller to specify a new transaction number.
// *****************************************************************************
inline void cdevTranNode::transaction ( int Transaction )
{
transaction_ = Transaction;
}
// *****************************************************************************
// * cdevTranNode::transaction:
// * Allows the caller to obtain the transaction number.
// *****************************************************************************
inline int cdevTranNode::transaction ( void )
{
return transaction_;
}
// *****************************************************************************
// * cdevTranNode::finished:
// * Allows the caller to set the finished flag.
// *****************************************************************************
inline void cdevTranNode::finished ( int Finished )
{
finished_ = Finished?TRUE:FALSE;
}
// *****************************************************************************
// * cdevTranNode::finished:
// * Allows the caller to read the contents of the finished flag.
// *****************************************************************************
inline int cdevTranNode::finished ( void )
{
return finished_;
}
// *****************************************************************************
// * cdevTranNode::permanent:
// * Allows the caller to set the permanent flag.
// *****************************************************************************
inline void cdevTranNode::permanent ( int Permanent )
{
permanent_ = Permanent?TRUE:FALSE;
}
// *****************************************************************************
// * cdevTranNode::permanent:
// * Allows the caller to read the contents of the permanent flag.
// *****************************************************************************
inline int cdevTranNode::permanent ( void )
{
return permanent_;
}
#endif /* _CDEV_TRAN_NODE_H_ */
+76
View File
@@ -0,0 +1,76 @@
ARCH = hpux-sl
include $(CDEV)/examples/Makefile.common
SRCROOT = $(CDEV)/extensions/cdevGenericServer
CDEVSHOBJ = /usr/user4/mccops/lib/$(TARGETDIR)
APPNAME = "CDEV Sample Service"
LIBDIR = $(CDEVLIB)
INCDIR = $(SRCROOT)/include
LIBS = -L$(LIBDIR) -lSimpleService \
-L$(CDEVLIB) -lcdev \
-ly -ll -L/lib -lm
LINKLIBS = -L$(LIBDIR) -lSimpleService\
-ly -ll -L/lib -lm
CLASS_INCLUDES = -I./ -I$(INCDIR) -I$(CDEV)/extensions/SimpleService
CXXEXTRA = -pta $(EPICSINCLUDES) $(ACE_INCLUDES) $(CLASS_INCLUDES)
SRCS = SampleService.cc
OBJS = SampleService.o
% : %.cc
@rm -f $@
@echo "=> $(CXX) $< -o $@"
@$(CXX) $(CXXFLAGS) $(CXXEXTRA) $< -o $@ -L$(ACE_LIBDIR) $(ACE_LIBS)
ifeq ($(SHOBJ), YES)
OUTPUTLIB = SampleService.so
targets: buildingService $(CDEVSHOBJ)/$(CDEVVERSION)/SampleService.so
else
OUTPUTLIB = libSampleService.a
targets: buildingService $(CDEV)/lib/$(TARGETDIR)/libSampleService.a
endif
buildingService:
@echo "BUILDING LIBRARY \"$(OUTPUTLIB)\"..."
objClean :
@echo ""
@echo "=> Removing old object files prior to building library"
@rm -rf $(OBJS)
$(CDEVSHOBJ)/$(CDEVVERSION)/SampleService.so : $(OBJS) $(SRCS)
@rm -f $@
@echo "=> Building shared object $@"
@echo " => Pleasuring templates for $@"
@echo "int main() {return 0; }" >dummy.cc
@$(CXX) $(CXXFLAGS) $(CXXEXTRA) dummy.cc $(SRCS) -Wl,+s -ptr./ptSampleService -ptr./ptrepository $(LIBS)
@rm -rf a.out dummy.*
@if test -f ./ptSampleService/*.o; \
then \
echo " => Linking $@ from objects and template objects"; \
$(CXX) -b -o $@ $(OBJS) ptSampleService/*.o $(LINKLIBS); \
else \
echo " => Linking $@ from objects"; \
$(CXX) -b -o $@ $(OBJS) $(LINKLIBS); \
fi
@echo " => $@ finished"
$(CDEV)/lib/$(TARGETDIR)/libSampleService.a : hail buildingService objClean $(OBJS)
@rm -f $@
@echo "=> Building archive library $@"
@echo " => Linking $@ from objects"
@ar ruv libSampleService.a $(OBJS)
@chmod a+r libSampleService.a
@echo " => $@ finished"
clean:
@echo "=> Sample Service"
@echo " => Removing old objects and binaries"
@rm -rf $(OBJS) $(CDEVSHOBJ)/$(TARGETDIR)/SampleService.so a.out *.o *~ core ptrepository ptSampleService
@echo " => Done"
+62
View File
@@ -0,0 +1,62 @@
service ca
{
tags {PV, READONLY}
}
service Sample
{
tags {server}
}
class BPM
{
verbs {get, set, monitorOn, monitorOff}
attributes
{
attrib0 ca {PV = <>.VAL};
attrib1 ca {PV = <>.VAL};
attrib2 ca {PV = <>.VAL};
attrib3 ca {PV = <>.VAL};
attrib4 ca {PV = <>.VAL};
attrib5 ca {PV = <>.VAL};
attrib6 ca {PV = <>.VAL};
attrib7 ca {PV = <>.VAL};
attrib8 ca {PV = <>.VAL};
attrib9 ca {PV = <>.VAL};
}
}
class Samples
{
verbs {get, set, monitorOn, monitorOff}
attributes
{
default Sample;
servers Sample;
attrib0 Sample;
attrib1 Sample;
attrib2 Sample;
attrib3 Sample;
attrib4 Sample;
attrib5 Sample;
attrib6 Sample;
attrib7 Sample;
attrib8 Sample;
attrib9 Sample;
}
messages
{
disconnect Sample;
}
}
BPM :
IPM1S01, IPM1S02, IPM1S03, IPM1S05, IPM1S07,
IPM1S08, IPM1S09
;
Samples :
device0, device1, device2, device3, device4,
device5, device6, device7, device8, device9
;
+32
View File
@@ -0,0 +1,32 @@
#include "SampleService.h"
cdevService * newSampleService ( char * name, cdevSystem * system )
{
return new SampleService(name, *system);
}
SampleService::SampleService ( char * name, cdevSystem & system )
: cdevSimpleService(name, system), var(0)
{
}
SampleService::~SampleService ( void )
{
}
void SampleService::handleOneEvent ( void )
{
cdevTransaction * transaction;
char * device;
char * message;
cdevData * data;
if(dequeue(transaction, device, message, data)==CDEV_SUCCESS)
{
data->insert("device", device);
data->insert("message", message);
data->insert("value", var++);
enqueue(CDEV_SUCCESS, transaction, device, message, data);
}
}
+13
View File
@@ -0,0 +1,13 @@
#include <cdevSimpleService.h>
extern "C" cdevService *newSampleService ( char * name, cdevSystem * system );
class SampleService : public cdevSimpleService
{
int var;
public:
SampleService ( char * name, cdevSystem & system );
virtual ~SampleService ( void );
virtual void handleOneEvent( void );
};
+1
View File
@@ -0,0 +1 @@
=> @@echo = -o libSimpleService.sl;rm -rf /usr/local/i386-glibc22-linux/cdev-1.7.2/lib/Linux/libSimpleService.sl; mkdir -p /usr/local/i386-glibc22-linux/cdev-1.7.2/lib/Linux; g++ -shared libSimpleService.sl