Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

asciinet.H

Go to the documentation of this file.
00001 /*
00002  * Copyright 2000, Brown University, Providence, RI.
00003  *
00004  *                         All Rights Reserved
00005  *
00006  * Permission to use, copy, modify, and distribute this software and its
00007  * documentation for any purpose other than its incorporation into a
00008  * commercial product is hereby granted without fee, provided that the
00009  * above copyright notice appear in all copies and that both that
00010  * copyright notice and this permission notice appear in supporting
00011  * documentation, and that the name of Brown University not be used in
00012  * advertising or publicity pertaining to distribution of the software
00013  * without specific, written prior permission.
00014  *
00015  * BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
00016  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ANY
00017  * PARTICULAR PURPOSE.  IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR
00018  * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00019  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00020  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00021  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
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 {  // this is a command line pattern: ie, DELETE <str> 
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 // EVENTascii - is a generic ASCII text EVENT
00062 //   EVENTascii's are used to send text strings through the EVENT
00063 // distribution mechanism.
00064 //
00065 MAKE_PTR_SUBC(EVENTascii, EVENT);
00066 class EVENTascii : public EVENT {
00067   protected:
00068    ostream *_ostr;
00069    Cstr_ptr _msg;
00070 
00071        /* ------- EVENT methods ----------- */ 
00072    virtual bool compare(cEVENTptr &/*e*/) 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        /* ------- TYPEDOBJ methods ----------- */ 
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 // EVENTpattern - the event of a command line that matches a lexical pattern
00094 //   EVENTpattern's are used to indicate that a lexical pattern has been
00095 // matched.  These patterns are part of an extensible command line grammar.
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        /* ------- EVENT methods ----------- */ 
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        /* ------- TYPEDOBJ methods ----------- */ 
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);  // (allow only one 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 

Generated on Mon Sep 15 16:25:56 2003 for gluebase by doxygen1.2.18