00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 #ifndef ASCII_NET_H
00024 #define ASCII_NET_H
00025 
00026 #include "event/event.H"
00027 #include "net/network.H"
00028 
00029 class token;
00030 class DllImpExp cmd_line_pattern {  
00031     str_ptr       _name;
00032     ARRAY<token*> _tokens;
00033     static ARRAY<cmd_line_pattern *> *_pats;
00034 
00035    public:
00036     static ARRAY<cmd_line_pattern *> &patterns()   { if (!_pats) 
00037                           _pats = new ARRAY<cmd_line_pattern *>;
00038                         return *_pats; }
00039                      cmd_line_pattern(Cstr_ptr &n):_name(n) { patterns() += this; }
00040 
00041      void            operator+=(token *t) { _tokens += t; }
00042      void            add_int    (Cstr_ptr &);
00043      void            add_str    (Cstr_ptr &);
00044      void            add_strlist(Cstr_ptr &);
00045      void            add_real   (Cstr_ptr &);
00046 
00047      token          *get_token  (Cstr_ptr &n);
00048      int             get_int    (Cstr_ptr &);
00049      Cstr_ptr       &get_str    (Cstr_ptr &);
00050      Cstr_list      &get_strlist(Cstr_ptr &);
00051      double          get_real   (Cstr_ptr &);
00052 
00053 
00054      Cstr_ptr       &name()         const { return _name; }
00055 const ARRAY<token*> &tokens()       const { return _tokens; }
00056      bool            convert(str_list &t);
00057 };
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 MAKE_PTR_SUBC(EVENTascii, EVENT);
00066 class EVENTascii : public EVENT {
00067   protected:
00068    ostream *_ostr;
00069    Cstr_ptr _msg;
00070 
00071         
00072    virtual bool compare(cEVENTptr &) const { return true; }
00073 
00074   public:
00075                 EVENTascii(Cstr_ptr &m,
00076                            ostream *ostr= 0,
00077                            cEVENTsource *s=0)
00078                    :EVENT(s), _ostr(ostr), _msg(m) { }
00079 
00080    virtual void debug(ostream &o)     const { o << class_name() 
00081                                                 << "(" << _msg << ")"; }
00082          Cstr_ptr &text()             const { return _msg; }
00083          ostream *ostr()                 { return _ostr; }
00084 
00085         
00086    DEFINE_DERIVED_TYPE(EVENTascii, EVENT, cEVENTptr);
00087    static EVENTasciiptr cast(cEVENTptr &e) { return EVENTascii::isa(e) ? 
00088                                                  (EVENTascii *)&*e : 0; }
00089 };
00090 
00091 
00092 
00093 
00094 
00095 
00096 
00097 MAKE_PTR_SUBC(EVENTpattern, EVENT);
00098 class DllImpExp EVENTpattern : public EVENT {
00099   protected:
00100    ostream          *_ostr;
00101    cmd_line_pattern *_pat;
00102 
00103         
00104    virtual bool compare(cEVENTptr &e) const;
00105 
00106   public:
00107                 EVENTpattern(cmd_line_pattern *p,
00108                              ostream          *ostr = 0,
00109                              cEVENTsource     *s=0)
00110                    : EVENT(s), _ostr(ostr), _pat(p){}
00111 
00112    cmd_line_pattern *pattern()             const { return _pat; }
00113             ostream *ostr()                      { return _ostr; }
00114    virtual void debug(ostream &o)     const;
00115 
00116         
00117    DEFINE_DERIVED_TYPE(EVENTpattern, EVENT, cEVENTptr);
00118    static EVENTpatternptr cast(cEVENTptr &e) { return EVENTpattern::isa(e) ? 
00119                                                  (EVENTpattern *)&*e : 0; }
00120 };
00121 
00122 
00123 class DllImpExp ASCIIstream : public NetStream {
00124   public:
00125    ASCIIstream(int port, const char *name) : NetStream(port, name) {}
00126    ASCIIstream(int fd, struct sockaddr_in *a):NetStream(fd, a) {}
00127 
00128    virtual void sample();
00129    virtual void flush_data (void) { flush(); }
00130 };
00131 
00132 class ASCIInet : public Network {
00133    protected:
00134       static ASCIInet *_instance;
00135       NetStream *new_stream(int fd, struct sockaddr_in *a) {
00136          return new ASCIIstream(fd, a); 
00137       }
00138       NetStream *new_stream(int port, const char *host) {
00139     return Network::new_stream(port, host);
00140       }
00141    public:
00142       ASCIInet() {
00143     assert(!_instance);  
00144     _instance = this;
00145       }
00146   
00147   static ASCIInet *instance() { return _instance; }
00148 };
00149 
00150 #include "event/event.H"
00151 #include "std/main_obs.H"
00152 #include "config/config.H"
00153 #include "fsa/fsa.H"
00154 
00155 
00156 class ASCIInet_creator : public MAINobs {
00157 public:
00158 
00159   ASCIInet_creator() { MAINobservers().obs(this); }
00160 
00161   void notify(const MAINobs::data &) {
00162     int port = CONFIGval("GLUE_ASCII_PORT", 8888, false);
00163     cerr << "... ASCIInet_creator: starting on port: " << port << endl;
00164     (new ASCIInet)->start(port); }
00165 };
00166 
00167 #endif // for the legacy option
00168 
00169 
00170