/* * The Unix Channel * * by Michel Beaudouin-Lafon * * Copyright 1990-1993 * Laboratoire de Recherche en Informatique (LRI) * * Text-oriented servers * * $Id$ * $CurLog$ */ #ifndef TextServer_H_ #define TextServer_H_ #include "TextStream.h" #include "ccu/List.h" class UchTextClient; class UchTextServer; class UchBaseMultiplexer; /* a function that instantiates clients */ typedef UchTextClient* (*fNEW_CLIENT) (UchTextServer*); class UchTextServer : public UchStream { friend class UchTextClient; friend class UchTextServerTimer; protected: UchTextServerTimer* Timer; // periodic registration with port server bool ok; // true if initialized #ifndef CPLUS_BUG19 CcuListOf Clients; // Clients created by this server #else CcuList Clients; // Clients created by this server #endif const char* service; // name of service in portserv fNEW_CLIENT newClient; // function that creates the client void Remove (UchTextClient*); // called from UchTextClient void HandleRead (); public: UchTextServer (const char*, fNEW_CLIENT); ~UchTextServer (); bool Ok () const { return ok; } bool Init (UchBaseMultiplexer&); // initialize the communication stuff void Quit (); // close the server and its connections UchTextClient* CreateClient (int); }; PointerClass (pUchTextServer, UchTextServer) class UchTextClient : public UchTextStream { friend class UchTextServer; protected: pUchTextServer MyServer; // who created me bool sendToOut; // whether to use alternate output pUchChannel out; // alternate output UchTextClient (UchTextServer*); // called by UchTextServer::HandleRead ~UchTextClient (); // called by UchMultiplexer::Remove virtual void Starting (); // called by UchTextServer virtual void Closing (bool); // called by UchTextServer virtual void Quitting (); // called by UchTextServer void DoSend (); cmd_res Execute (const UchTextLine&) = 0; public: void Close (); // 'close' request void Quit (); // 'quit' request void SetOutput (UchChannel*); void ResetOutput (); UchChannel* GetOutput () { if (sendToOut) return out; else return this; } }; #endif /*TextServer_H_*/