Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

FlowManager.h

00001 // See the file LICENSE in the some directory as this file for legal
00002 // notices about this software.   
00003 // $Id: FlowManager_8h-source.html,v 1.6 2001/10/10 20:40:58 sandro Exp $
00004 #ifndef DEV_W3_ORG__2001_BLINDFOLD_SRC_FLOWMANAGER_H
00005 #define DEV_W3_ORG__2001_BLINDFOLD_SRC_FLOWMANAGER_H
00006 #include "config.h"
00007 
00008 #include "ByteFIFO.h"
00009 #include <string>
00010 #include <vector>
00011 #include <sstream>
00012 
00019 class FlowManager {
00020       
00021 public:
00022 
00023     // STANDARD MEMBER FUNCTIONS
00024     FlowManager();
00025     FlowManager(const FlowManager& other);
00026     const FlowManager& operator=(const FlowManager& other);
00027     bool operator==(const FlowManager& other) const;
00028     bool operator<(const FlowManager& other) const;
00029     size_t hash() const;
00030     friend std::ostream& operator<<(std::ostream& s, const FlowManager& me);
00031     std::ostream& print_to(std::ostream& stream) const; 
00032     ~FlowManager();       
00033 
00034     // (RE)IMPLEMENTATION OF INHERITED MEMBERS
00035 
00036     // CLASS-SPECIFIC PUBLIC INTERFACE
00037 
00041     void streamIn(const char* address, ByteSink& destination, 
00042           bool returnWhenDone=false)  {
00043     Stream* s = new Stream(address, &destination, READ, returnWhenDone);
00044     addStream(s);
00045     }
00046 
00050     std::ostream* streamOut(const char* address)  {
00051     Stream* s = new Stream(address, 0, WRITE);
00052     addStream(s);
00053     return &s->streamFrom;
00054     }
00055 
00060     std::ostream* streamThrough(const char* address, ByteSink& destination, bool f=false) {
00061     Stream* s = new Stream(address, &destination, READWRITE, f);
00062     addStream(s);
00063     return &s->streamFrom;
00064     }
00065 
00066     // a vector of Runnable* 
00067     
00071     void run();
00072 
00076     void runPending();
00077 
00081     void returnFromRun() { keepRunning = false; }
00082 
00083     enum Direction { READ=1, WRITE=2, READWRITE=3 };
00084 
00085     static FlowManager main;
00086 
00087 private:
00088 
00089     struct Stream {
00090     Stream(const char* address, ByteSink* streamTo, Direction direction,
00091            bool returnWhenDone = false);
00092     std::string address;
00093     ByteSink* streamTo;
00094     std::stringstream streamFrom;
00095     Direction direction;
00096     int fd;
00097     int wfd;  // when the write fd is different
00098     bool returnWhenDone;
00099     };
00100 
00101     void addStream(Stream* stream);
00102 
00103     std::vector<Stream*> streams;
00104 
00105     bool keepRunning;
00106     bool runOnlyPending;
00107     int maxfd;
00108 };     
00109 
00110 
00111 STANDARD_EXTERNAL(FlowManager)
00112 
00113 #endif   /* FLOWMANAGER */  // -*-C++-*-

Home to blindfold. This page generated via doxygen 1.2.11.1 Wed Oct 10 16:40:33 2001.