• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

epics/apps/crucible/stream/src/StreamBusInterface.h (r4864/r2310)

Go to the documentation of this file.
00001 /***************************************************************
00002 * StreamDevice Support                                         *
00003 *                                                              *
00004 * (C) 2005 Dirk Zimoch (dirk.zimoch@psi.ch)                    *
00005 *                                                              *
00006 * This is the interface to bus drivers for StreamDevice.       *
00007 * Please refer to the HTML files in ../doc/ for a detailed     *
00008 * documentation.                                               *
00009 *                                                              *
00010 * If you do any changes in this file, you are not allowed to   *
00011 * redistribute it any more. If there is a bug or a missing     *
00012 * feature, send me an email and/or your patch. If I accept     *
00013 * your changes, they will go to the next release.              *
00014 *                                                              *
00015 * DISCLAIMER: If this software breaks something or harms       *
00016 * someone, it's your problem.                                  *
00017 *                                                              *
00018 ***************************************************************/
00019 
00020 #ifndef StreamBusInterface_h
00021 #define StreamBusInterface_h
00022 
00023 #include <stddef.h>
00024 
00025 enum StreamIoStatus {
00026     StreamIoSuccess, StreamIoTimeout, StreamIoNoReply,
00027     StreamIoEnd, StreamIoFault
00028 };
00029 
00030 extern const char* StreamIoStatusStr[];
00031 
00032 class StreamBusInterface
00033 {
00034 public:
00035 
00036     class Client
00037     {
00038         friend class StreamBusInterface;
00039         virtual void lockCallback(StreamIoStatus status) = 0;
00040         virtual void writeCallback(StreamIoStatus status);
00041         virtual long readCallback(StreamIoStatus status,
00042             const void* input, long size);
00043         virtual void eventCallback(StreamIoStatus status);
00044         virtual void connectCallback(StreamIoStatus status);
00045         virtual void disconnectCallback(StreamIoStatus status);
00046         virtual long priority();
00047         virtual const char* name() = 0;
00048         virtual const char* getInTerminator(size_t& length) = 0;
00049         virtual const char* getOutTerminator(size_t& length) = 0;
00050     public:
00051         virtual ~Client();
00052     protected:
00053         StreamBusInterface* businterface;
00054         bool busSupportsEvent() {
00055             return businterface->supportsEvent();
00056         }
00057         bool busSupportsAsyncRead() {
00058             return businterface->supportsAsyncRead();
00059         }
00060         bool busAcceptEvent(unsigned long mask,
00061             unsigned long replytimeout_ms) {
00062             return businterface->acceptEvent(mask, replytimeout_ms);
00063         }
00064         void busRelease() {
00065             businterface->release();
00066         }
00067         bool busLockRequest(unsigned long timeout_ms) {
00068             return businterface->lockRequest(timeout_ms);
00069         }
00070         bool busUnlock() {
00071             return businterface->unlock();
00072         }
00073         bool busWriteRequest(const void* output, size_t size,
00074             unsigned long timeout_ms) {
00075             return businterface->writeRequest(output, size, timeout_ms);
00076         }
00077         bool busReadRequest(unsigned long replytimeout_ms,
00078             unsigned long readtimeout_ms, long expectedLength,
00079             bool async) {
00080             return businterface->readRequest(replytimeout_ms,
00081                 readtimeout_ms, expectedLength, async);
00082         }
00083         void busFinish() {
00084             businterface->finish();
00085         }
00086         bool busConnectRequest(unsigned long timeout_ms) {
00087             return businterface->connectRequest(timeout_ms);
00088         }
00089         bool busDisconnect() {
00090             return businterface->disconnectRequest();
00091         }
00092     };
00093 
00094 private:
00095     friend class StreamBusInterfaceClass; // the iterator
00096     friend class Client;
00097 
00098 public:
00099     Client* client;
00100     virtual ~StreamBusInterface() {};
00101 
00102 protected:
00103     StreamBusInterface(Client* client);
00104     
00105 // map client functions into StreamBusInterface namespace
00106     void lockCallback(StreamIoStatus status)
00107         { client->lockCallback(status); }
00108     void writeCallback(StreamIoStatus status)
00109         { client->writeCallback(status); }
00110     long readCallback(StreamIoStatus status,
00111         const void* input = NULL, long size = 0)
00112         { return client->readCallback(status, input, size); }
00113     void eventCallback(StreamIoStatus status)
00114         { client->eventCallback(status); }
00115     void connectCallback(StreamIoStatus status)
00116         { client->connectCallback(status); }
00117     void disconnectCallback(StreamIoStatus status)
00118         { client->disconnectCallback(status); }
00119     const char* getInTerminator(size_t& length)
00120         { return client->getInTerminator(length); }
00121     const char* getOutTerminator(size_t& length)
00122         { return client->getOutTerminator(length); }
00123     long priority() { return client->priority(); }
00124     const char* clientName() { return client->name(); }
00125 
00126 // default implementations
00127     virtual bool writeRequest(const void* output, size_t size,
00128         unsigned long timeout_ms);
00129     virtual bool readRequest(unsigned long replytimeout_ms,
00130         unsigned long readtimeout_ms, long expectedLength,
00131         bool async);
00132     virtual bool supportsEvent(); // defaults to false
00133     virtual bool supportsAsyncRead(); // defaults to false
00134     virtual bool acceptEvent(unsigned long mask, // implement if
00135         unsigned long replytimeout_ms);     // supportsEvents() returns true
00136     virtual void release();
00137     virtual bool connectRequest(unsigned long connecttimeout_ms);
00138     virtual bool disconnectRequest();
00139     virtual void finish();
00140 
00141 // pure virtual
00142     virtual bool lockRequest(unsigned long timeout_ms) = 0;
00143     virtual bool unlock() = 0;
00144 
00145 public:
00146 // static methods
00147     static StreamBusInterface* find(Client*, const char* busname,
00148         int addr, const char* param);
00149 };
00150 
00151 class StreamBusInterfaceRegistrarBase
00152 {
00153     friend class StreamBusInterfaceClass; // the iterator
00154     friend class StreamBusInterface;      // the implementation
00155     static StreamBusInterfaceRegistrarBase* first;
00156     StreamBusInterfaceRegistrarBase* next;
00157     virtual StreamBusInterface* find(StreamBusInterface::Client* client,
00158         const char* busname, int addr, const char* param) = 0;
00159 protected:
00160     const char* name;
00161     StreamBusInterfaceRegistrarBase(const char* name);
00162     virtual ~StreamBusInterfaceRegistrarBase();
00163 };
00164     
00165 template <class C>
00166 class StreamBusInterfaceRegistrar : protected StreamBusInterfaceRegistrarBase
00167 {
00168     StreamBusInterface* find(StreamBusInterface::Client* client,
00169         const char* busname, int addr, const char* param)
00170         { return C::getBusInterface(client, busname, addr, param); }
00171 public:
00172     StreamBusInterfaceRegistrar(const char* name) :
00173         StreamBusInterfaceRegistrarBase(name) {};
00174 };
00175 
00176 
00177 #define RegisterStreamBusInterface(interface) \
00178 template class StreamBusInterfaceRegistrar<interface>; \
00179 StreamBusInterfaceRegistrar<interface> \
00180 registrar_##interface(#interface); \
00181 void* ref_##interface = &registrar_##interface\
00182 
00183 // Interface class iterator
00184 
00185 class StreamBusInterfaceClass
00186 {
00187     StreamBusInterfaceRegistrarBase* ptr;
00188 public:
00189     StreamBusInterfaceClass () {
00190         ptr = StreamBusInterfaceRegistrarBase::first;
00191     }
00192     StreamBusInterfaceClass& operator ++ () {
00193         ptr = ptr->next; return *this;
00194     }
00195     const char* name() {
00196         return ptr->name;
00197     }
00198     operator bool () {
00199         return ptr != NULL;
00200     }
00201 };
00202 
00203 #endif

Generated on Tue Dec 10 2013 04:52:22 for ROCsoft by  doxygen 1.7.1