faio_asyncio.hpp

00001 #line 353 "./lpsrc/flx_faio.pak"
00002 #ifndef __ASYNCIO__
00003 #define __ASYNCIO__
00004 #include <flx_faio_config.hpp>
00005 
00006 // this file acts as go-between for my asynchronous interface for felix
00007 // programmes.
00008 
00009 // portable. Not that asynchronous.
00010 
00011 #include "demux_demuxer.hpp"        // sel_param, demuxer base
00012 #include "faio_drv.hpp"
00013 
00014 namespace flx { namespace faio {
00015 
00016 class FAIO_EXTERN flx_driver_request_base {
00017 public:
00018     virtual ~flx_driver_request_base() {}       // so destructors work
00019     // returns finished flag (async may fail or immediately finish)
00020     virtual bool start_async_op(demux::demuxer& demux, flx_drv* drv, void* f) = 0;
00021 };
00022 
00023 // not actually asynchronous as such since the threads are woken synchronously
00024 // definitely portable. look out for this shared structure when flx threads
00025 // are run pre-emptively. start_async_op will need to be serialised.
00026 class FAIO_EXTERN async_copipe : public flx_driver_request_base {
00027 public:
00028     enum { WINDWARD, LEEWARD, NUM_CHANNELS };
00029 
00030     virtual bool start_async_op(demux::demuxer& demux, flx_drv* drv, void* f);
00031     void connect(void* f, demux::sel_param* pb, bool reading, int channel);
00032     void close_channel(int which);      // WINDWARD or LEEWARD
00033     void disconnect();                  // will be used by close
00034 
00035     static async_copipe* create_copipe() { return new async_copipe; }
00036     bool debug;
00037     void set_debug(bool);
00038 
00039 private:
00040     enum { READER, WRITER, NUM_CNXNS };
00041 
00042     // if there's a thread here, it's sleeping
00043     void*   thread[NUM_CNXNS];
00044     demux::sel_param*  pb[NUM_CNXNS];
00045     int         num_users;
00046 
00047     bool        channel_open[NUM_CHANNELS];
00048     int         current_channel;
00049     void wake_thread(int n, flx_drv* drv);
00050     void wake_all_threads(flx_drv* drv);
00051 
00052     async_copipe();                     // to control alloc/dealloc
00053 };
00054 
00055 class FAIO_EXTERN copipe_endpt {
00056     int             read_channel;       // the channel this endpt reads on
00057 
00058     copipe_endpt(async_copipe* p, int rchan) :
00059       read_channel(rchan), pipe(p), debug(false)
00060     {}
00061 
00062 public:
00063     async_copipe*   pipe;               // endpt's copy (flx accessible)
00064 
00065     // 0 = no reads, 1 = no writes, 2 = no nothing (! = close, however)
00066     void shutdown(int how);
00067     int get_channel(bool reading);
00068     bool debug;
00069     void set_debug(bool d) { debug = d; }
00070 
00071     ~copipe_endpt() { pipe->disconnect(); }
00072     static void pipe_pair(copipe_endpt* pair[2]);
00073 };
00074 
00075 // sleeping
00076 class FAIO_EXTERN sleep_request
00077   : public flx_driver_request_base, public demux::sleep_task
00078 {
00079   thread_wakeup fw;
00080   double      delta;
00081 public:
00082   sleep_request() {}        // flx linkage
00083 
00084   sleep_request(double d) : delta(d) {}
00085 
00086   // from driver request
00087   virtual bool start_async_op(demux::demuxer& demux, flx_drv* drv, void* f);
00088 
00089   // from sleep_task
00090   virtual void fire();
00091 };
00092 
00093 }} // namespace faio, flx
00094 #endif  // __ASYNCIO__
00095 

Generated on Mon Dec 11 17:08:15 2006 for Felix by  doxygen 1.5.1