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

EchoModule.h

00001 #ifndef _STR_EchoModule_H_  // -*-c++-*-
00002 
00003 /*
00004  * Copyright 1991-2002 Eric M. Hopper <hopper@omnifarious.org>
00005  * 
00006  *     This program is free software; you can redistribute it and/or modify it
00007  *     under the terms of the GNU Lesser General Public License as published
00008  *     by the Free Software Foundation; either version 2 of the License, or
00009  *     (at your option) any later version.
00010  * 
00011  *     This program is distributed in the hope that it will be useful, but
00012  *     WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *     Lesser General Public License for more details.
00015  * 
00016  *     You should have received a copy of the GNU Lesser General Public
00017  *     License along with this program; if not, write to the Free Software
00018  *     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #ifdef __GNUG__
00022 #pragma interface
00023 #endif
00024 
00025 /* $Header: /home/hopper/src/cvs/C++/StrMod/StrMod/EchoModule.h,v 1.13 2002/11/25 05:40:05 hopper Exp $ */
00026 
00027 // For log information, see ../ChangeLog
00028 
00029 // $Revision: 1.13 $
00030 
00031 #ifndef _STR_StreamModule_H_
00032 #   include <StrMod/StreamModule.h>
00033 #endif
00034 
00035 #ifndef _STR_StrChunkPtr_H_
00036 #   include <StrMod/StrChunkPtr.h>
00037 #endif
00038 
00039 #include <cassert>
00040 
00041 #define _STR_EchoModule_H_
00042 
00043 namespace strmod {
00044 namespace strmod {
00045 
00046 class StrChunk;
00047 
00048 /** \class EchoModule EchoModule.h StrMod/EchoModule.h
00049  * This module echoes everything that comes in.
00050  *
00051  * Everything that is written to its one plug is read from that same plug.
00052 */
00053 class EchoModule : public StreamModule
00054 {
00055    class EPlug;
00056    friend class EPlug;
00057  public:
00058    static const STR_ClassIdent identifier;
00059 
00060    EchoModule();
00061    virtual ~EchoModule();
00062 
00063    inline virtual int AreYouA(const lcore::ClassIdent &cid) const;
00064 
00065    inline virtual bool canCreate(int side = 0) const;
00066    inline Plug *makePlug(int side = 0);
00067    virtual bool ownsPlug(const Plug *plug) const   { return i_OwnsPlug(plug); }
00068    virtual bool deletePlug(Plug *plug);
00069 
00070  protected:
00071    virtual const lcore::ClassIdent *i_GetIdent() const  { return &identifier; }
00072 
00073    virtual void plugDisconnected(Plug *plug);
00074 
00075    inline virtual Plug *i_MakePlug(int side);
00076 
00077  private:
00078    class EPlug : public Plug {
00079       friend class EchoModule;
00080     public:
00081       static const STR_ClassIdent identifier;
00082 
00083       inline virtual int AreYouA(const lcore::ClassIdent &cid) const;
00084 
00085       inline EchoModule &getParent() const;
00086 
00087       virtual int side() const                          { return(0); }
00088 
00089     protected:
00090       inline EPlug(EchoModule &parnt);
00091       inline virtual ~EPlug();
00092 
00093       virtual const lcore::ClassIdent *i_GetIdent() const {
00094          return &identifier;
00095       }
00096 
00097       virtual bool needsNotifyReadable() const          { return(true); }
00098       virtual bool needsNotifyWriteable() const         { return(true); }
00099 
00100       virtual void otherIsReadable();
00101       virtual void otherIsWriteable();
00102 
00103       virtual const StrChunkPtr i_Read();
00104       virtual void i_Write(const StrChunkPtr &ptr);
00105    };
00106 
00107    bool plugcreated_;
00108    EPlug eplug_;
00109 
00110    inline bool i_OwnsPlug(const Plug *plug) const;
00111 };
00112 
00113 //-------------------------------inline functions------------------------------
00114 
00115 inline int EchoModule::AreYouA(const lcore::ClassIdent &cid) const
00116 {
00117    return((identifier == cid) || StreamModule::AreYouA(cid));
00118 }
00119 
00120 bool EchoModule::canCreate(int side) const
00121 {
00122    return(side == 0 && !plugcreated_);
00123 }
00124 
00125 inline StreamModule::Plug *EchoModule::makePlug(int side)
00126 {
00127    return(StreamModule::makePlug(side));
00128 }
00129 
00130 inline bool EchoModule::i_OwnsPlug(const Plug *plug) const
00131 {
00132    return(plugcreated_ && (plug == &eplug_));
00133 }
00134 
00135 inline EchoModule::Plug *EchoModule::i_MakePlug(int side)
00136 {
00137    assert(side == 0 && !plugcreated_);
00138    plugcreated_ = true;
00139    //lint -save -e1536
00140    return(&eplug_);
00141    //lint -restore
00142 }
00143 
00144 //=========EchoModule::EPlug inlines========
00145 
00146 inline EchoModule::EPlug::EPlug(EchoModule &parnt) : Plug(parnt)
00147 {
00148 }
00149 
00150 inline EchoModule::EPlug::~EPlug()
00151 {
00152 }
00153 
00154 inline int EchoModule::EPlug::AreYouA(const lcore::ClassIdent &cid) const
00155 {
00156    return((identifier == cid) || Plug::AreYouA(cid));
00157 }
00158 
00159 inline EchoModule &EchoModule::EPlug::getParent() const
00160 {
00161    return(static_cast<EchoModule &>(Plug::getParent()));
00162 }
00163 
00164 }  // namespace strmod
00165 }  // namespace strmod
00166 
00167 #endif

Generated on Wed Jan 29 00:32:43 2003 for libNet by doxygen1.3-rc1