summaryrefslogtreecommitdiff
path: root/comm/OLD/TextServer.h
blob: ad64b2a14949b5bc614b46804c258191083b1f63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 *	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 <UchTextClient>	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_*/