From e3e2e33f287e0cf7dbb230d1dfe149f6c418560b Mon Sep 17 00:00:00 2001 From: chatty Date: Tue, 28 Nov 2000 17:07:44 +0000 Subject: * Smart(ies) removed by Stephane Sire * Removed ReadHandler and WriteHandler --- comm/Channel.cc | 82 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 43 insertions(+), 39 deletions(-) (limited to 'comm') diff --git a/comm/Channel.cc b/comm/Channel.cc index 9b559fc..75a6a33 100644 --- a/comm/Channel.cc +++ b/comm/Channel.cc @@ -3,7 +3,7 @@ * * by Michel Beaudouin-Lafon * - * Copyright 1990-1995 + * Copyright 1990-1997 * Laboratoire de Recherche en Informatique (LRI) * * File descriptors, channels @@ -16,6 +16,7 @@ #pragma implementation "Channel.h" #endif #include "Channel.h" +#include "Multiplexer.h" #include "MsgBuffer.h" #include "error.h" #include "ccu/String.h" @@ -25,9 +26,6 @@ #include #include -CH_HANDLER UchChannel::ReadHandler = 0; -CH_HANDLER UchChannel::WriteHandler = 0; - // // this section implements refcounts for file descriptors, so that they // are closed only when the last occurence is deleted @@ -171,11 +169,10 @@ are intended to give a channel the ability to automatically handle input/output, for instance for use with the \fun{select} system call. Such capabilities are used and thus illustrated in class \typ{UchMultiplexer}. -The class \typ{^{pUchChannel}} implements smart pointers to channels. -Smart pointers behave like pointers but they manage a reference count on the -pointed to objects for an automatic reclaim of dynamically allocated objects. -This is very useful especially in the class \typ{UchMultiplexer} because arrays of -(smart) pointers to buffers are used. +A \typ{UchChannel} can be associated with only one \typ{UchBaseMultiplexer} +at a time by using the functions \fun{Add} and \fun{Remove} of the Channel. +When it is added/removed from its Multiplexor, +virtual function \fun{Added/Removed} is called. ?*/ /*? @@ -237,70 +234,76 @@ UchChannel :: SetMode (IOMODE io) #endif /* DOC */ -/*?nodoc?*/ +/*? +Destroy the channel. It is removed from its multiplexor if necessary. +?*/ UchChannel :: ~UchChannel () { - // nothing special here + Remove (); } -/*?nodoc?*/ -UchChannel* -UchChannel :: Copy () const +/*?nextdoc?*/ +void +UchChannel :: Added () +{ +} + +/*? +These virtual functions are called whenever a channel is added to +(resp. removed from) a multiplexer. The default implementation does +nothing. +?*/ +void +UchChannel :: Removed () { - return new UchChannel (*this); } /*?nextdoc?*/ void -UchChannel :: Added (UchBaseMultiplexer& m) +UchChannel :: Add (UchBaseMultiplexer* m) { - Mpx = &m; + if (Mpx != m) { + if (Mpx != 0) + Remove (); + if (m->Add (this)) { + Mpx = m; + Added (); + } + } } /*? -These virtual functions are called whenever a channel is added to (resp. removed from) -a multiplexer. The default implementation only stores a pointer to the multiplexer (which -can be retrieved through \fun{Getmultiplexer}). +Add (resp. remove) a channel to a (resp. from its) multiplexer. +If the file descriptor of this channel is invalid, nothing is done. +If a channel with the same file descriptor as the one being added +is already in the multiplexor, the old channel is first removed. ?*/ void -UchChannel :: Removed (UchBaseMultiplexer& m) +UchChannel :: Remove () { - if (Mpx == &m) + if (Mpx && Mpx->Remove (*this)) { + Removed (); Mpx = 0; + } } /*?nextdoc?*/ void UchChannel :: HandleWrite () { - if (! UchChannel::WriteHandler) - ::Error (ErrFatal, "UchChannel::HandleWrite", ErrorTable [ErrShouldImplement]); - else - (* UchChannel::WriteHandler) (this); } /*? These virtual functions are called by a \typ{UchMultiplexer} when data can be written to the channel or read from the channel. -They are are normally redefined in derived classes. -The default implementation is the following: -if the static members \var{UchChannel::ReadHandler} (resp. \var{UchChannel::WriteHandler}) is set, -it is called by \fun{HandleRead} (resp. \fun{HandleWrite}); -else an error message is output. -These members are public so that they can be assigned directly at any time. -By default they are not set. -The type of these static members is \typ{^{CH\_HANDLER}}: -pointer to void function with one argument of type \typ{UchChannel*}. +The default implementation does nothing. ?*/ void UchChannel :: HandleRead () { - if (! UchChannel::ReadHandler) - ::Error (ErrFatal, "UchChannel::HandleRead", ErrorTable [ErrShouldImplement]); - else - (* UchChannel::ReadHandler) (this); } +#if 0 /*? This virtual function is called by a \typ{UchMultiplexer} before making a \fun{select} call. It is intended to handle any background task or buffered input/output associated to the channel. @@ -313,6 +316,7 @@ UchChannel :: HandleSelect () { return false; } +#endif #ifdef DOC -- cgit v1.1