00001 #ifndef _STR_EchoModule_H_ // -*-c++-*-
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifdef __GNUG__
00022 #pragma interface
00023 #endif
00024
00025
00026
00027
00028
00029
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
00049
00050
00051
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
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
00140 return(&eplug_);
00141
00142 }
00143
00144
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 }
00165 }
00166
00167 #endif