ZG  "1.00
 All Classes Namespaces Files Functions Variables Enumerator Friends Macros Pages
ZGStdinSession.h
Go to the documentation of this file.
1 #ifndef ZGStdinSession_h
2 #define ZGStdinSession_h
3 
4 #include "reflector/AbstractReflectSession.h"
5 
6 #include "zg/ZGNameSpace.h"
7 
8 namespace zg
9 {
10 
16 {
17 public:
18  ITextCommandReceiver() {/* empty */}
19  virtual ~ITextCommandReceiver() {/* empty */}
20 
25  virtual bool IsReadyForTextCommands() const = 0;
26 
31  virtual bool TextCommandReceived(const String & text) = 0;
32 
33 protected:
42  bool ParseGenericTextCommand(const String & cmd);
43 };
44 
52 class ZGStdinSession : public AbstractReflectSession
53 {
54 public:
59  ZGStdinSession(ITextCommandReceiver & target, bool endServerOnClose);
60 
62  virtual ConstSocketRef CreateDefaultSocket() {return GetInvalidSocket();}
63 
65  virtual DataIORef CreateDataIO(const ConstSocketRef &);
66 
68  virtual bool ClientConnectionClosed();
69 
71  virtual bool IsReadyForInput() const;
72 
74  virtual AbstractMessageIOGatewayRef CreateGateway();
75 
80  virtual void MessageReceivedFromGateway(const MessageRef & msg, void * ptr);
81 
83  virtual const char * GetTypeName() const {return "ZGStdin";}
84 
86  bool IsEndServerOnClose() const {return _endServerOnClose;}
87 
89  void SetEndServerOnClose(bool esoc) {_endServerOnClose = esoc;}
90 
92  const ITextCommandReceiver & GetTextCommandReceiver() const {return _target;}
93 
96 
98  bool EndServerRequested() const {return _calledEndServer;}
99 
100 private:
101  bool IsReallyStdin() const;
102 
103  ITextCommandReceiver & _target;
104  bool _endServerOnClose;
105  bool _calledEndServer;
106 };
107 DECLARE_REFTYPES(ZGStdinSession);
108 
109 
110 }; // end namespace zg
111 
112 #endif
virtual bool IsReadyForTextCommands() const =0
Should be implemented to true iff this object is ready to have its TextCommandReceived() method calle...
const ITextCommandReceiver & GetTextCommandReceiver() const
Returns the ITextCommandReceiver object that was passed into our ctor.
bool IsEndServerOnClose() const
Returns true iff we will call EndServer() if stdin is closed.
Interface for an object that can receive text commands from the user.
ITextCommandReceiver & GetTextCommandReceiver()
Returns the ITextCommandReceiver object that was passed into our ctor.
The zg namespace contains the public API of the ZG library.
bool EndServerRequested() const
Returns true iff this object called EndServer() already.
This is a utility class that knows how to read from the process's stdin and hand any received text co...
virtual AbstractMessageIOGatewayRef CreateGateway()
Overridden to create and return a PlainTextMessageIOGateway, since stdin input will be in the form of...
virtual ConstSocketRef CreateDefaultSocket()
Overridden to return an invalid socket.
void SetEndServerOnClose(bool esoc)
Sets whether or not we should call EndServer when stdin is closed.
virtual void MessageReceivedFromGateway(const MessageRef &msg, void *ptr)
Overridden to handle incoming text from the PlainTextMessageIOGateway.
virtual bool ClientConnectionClosed()
Overridden to quit the ReflectServer event-loop when stdin is closed (if that behavior was specified ...
virtual const char * GetTypeName() const
Implemented to return "ZGStdin".
virtual bool IsReadyForInput() const
Returns true iff our (target)'s IsReadyForInput() method returns true.
virtual bool TextCommandReceived(const String &text)=0
Called whenever the user types in a text command.
virtual DataIORef CreateDataIO(const ConstSocketRef &)
Overridden to create and return a StdinDataIO object.
ZGStdinSession(ITextCommandReceiver &target, bool endServerOnClose)
Constructor.
bool ParseGenericTextCommand(const String &cmd)
Tries to handle any text commands that can be handled generically; that is, any commands that can be ...