summaryrefslogtreecommitdiff
path: root/comm/OLD/TextStream.h
diff options
context:
space:
mode:
Diffstat (limited to 'comm/OLD/TextStream.h')
-rw-r--r--comm/OLD/TextStream.h137
1 files changed, 75 insertions, 62 deletions
diff --git a/comm/OLD/TextStream.h b/comm/OLD/TextStream.h
index d7527ad..3c919f7 100644
--- a/comm/OLD/TextStream.h
+++ b/comm/OLD/TextStream.h
@@ -18,56 +18,12 @@
#include "cplus_bugs.h"
#include "Stream.h"
#include "MsgBuffer.h"
+#include "MsgStream.h"
#include "ccu/String.h"
-class UchTextWord {
-protected:
- const char* Sval;
- int Ival;
-public:
-inline UchTextWord () : Sval (0), Ival (0) {}
-inline UchTextWord (const char* s) { SetVal (s); }
-inline UchTextWord (int i) { SetVal (i); }
- void SetVal (const char*);
-inline void SetVal (int i) { Sval = 0; Ival = i; }
-inline bool IsInt () const { return (Sval == 0) ? TRUE : FALSE; }
-inline bool IsString () const { return (Sval != 0) ? TRUE : FALSE; }
- const char* GetQuotes () const;
-inline operator int () const { return Ival; }
-inline operator const char* () const { return Sval; }
-};
-
-
-class UchTextLine {
-protected:
- int Num;
- int Max;
- UchTextWord* Words;
-void NewWord (const char* s, int i);
+class UchTextLine;
-public:
- UchTextLine ();
- ~UchTextLine ();
-inline UchTextWord& operator [] (int i) const { return Words [i]; }
-inline int NumWords () const { return Num; }
-inline void AddWord (const char* s) { NewWord (s, 0); }
-inline void AddWord (int i) { NewWord (0, i); }
- void AddTrailer (const UchTextLine&, int);
-inline UchTextLine& operator << (int i) { AddWord (i); return *this; }
-inline UchTextLine& operator << (const char* s) { AddWord (s); return *this; }
-inline UchTextLine& operator << (const UchTextLine& l) { AddTrailer (l, 0); return *this; }
- bool Parse (char*);
- char* Unparse (char* dest, int len) const;
- char* Unparse (UchMsgBuffer*) const;
- bool Match (const char*, const char* = 0) const;
- int Index (const char*) const;
- int Index (int) const;
-inline bool Contains (const char* w) const { return (Index (w) == -1) ? FALSE : TRUE; }
-inline bool Contains (int i) const { return (Index (i) == -1) ? FALSE : TRUE; }
-inline void Reset () { Num = 0; }
-};
-
-class UchTextStream : public UchStream {
+class UchTextStream : public UchBufStream {
public:
enum cmd_res {
isCmdSyntax, // syntax error when parsing command
@@ -80,31 +36,40 @@ enum cmd_res {
isCmdAbort, // abort multiplexer
isCmdExit // call exit
};
-protected:
- UchMsgBuffer InBuffer;
- UchMsgBuffer OutBuffer;
-virtual void Closing (bool);
+protected:
+ void Closing (bool);
void HandleRead ();
+ void Process (UchMsgBuffer&);
+ void Flush ();
+
void ProcessCmdResult (cmd_res, const UchTextLine&);
cmd_res TryPredefined (const UchTextLine&);
virtual cmd_res Execute (const UchTextLine&) = 0;
-virtual void DoSend ();
+
+ void Emit (lword);
+ void Emit (sword);
+ void Emit (byte);
+ void Emit (char);
+ void Emit (const char*);
+
+ void Receive (lword&);
+ void Receive (sword&);
+ void Receive (byte&);
+ void Receive (char&);
+ void Receive (char*);
+ void Receive (CcuString&);
+
public:
UchTextStream ();
~UchTextStream ();
- UchTextStream (const UchTextStream&);
+// UchTextStream (const UchTextStream&);
// UchChannel* Copy () const;
virtual void Close (); // 'close' request
virtual void Quit (); // 'quit' request
-inline void Append (const char* l) { OutBuffer.Append (l, FALSE); }
-inline void Append (const UchTextLine& l) { l.Unparse (&OutBuffer); OutBuffer.Append ('\n');}
-inline UchTextStream& operator << (const char* l) { Append (l); return *this; }
-inline UchTextStream& operator << (const UchTextLine& l) { Append (l); return *this; }
-inline void Send () { DoSend (); }
-inline void Send (const char* l) { Append (l); DoSend (); }
-inline void Send (const UchTextLine& l) { Append (l); DoSend (); }
+ void Send (const char*, bool = false);
+ void Send (const UchTextLine&, bool = false);
};
class UchTextService : public UchTextStream {
@@ -115,7 +80,7 @@ enum status {
isUnavailable, // address not found in port server
isError, // could not init connection
isRunning, // connection established
- isLost, // no connection (auto-starting)
+ isLost // no connection (auto-starting)
};
protected:
@@ -127,13 +92,13 @@ protected:
CcuString Host;
void Closing (bool);
+ void Flush ();
status Restart ();
void AutoStart (int = -1, int = -1);
virtual void LostServer ();
virtual void GotServer ();
virtual void AbandonRestart ();
cmd_res Execute (const UchTextLine&);
- void DoSend ();
public:
UchTextService (UchBaseMultiplexer&, const char*, const char* = 0);
@@ -151,4 +116,52 @@ public:
// the simplest interface to a server.
extern bool TellServer (const char*, const char*, const char*);
+class UchTextWord {
+protected:
+ const char* Sval;
+ int Ival;
+public:
+inline UchTextWord () : Sval (0), Ival (0) {}
+inline UchTextWord (const char* s) { SetVal (s); }
+inline UchTextWord (int i) { SetVal (i); }
+ void SetVal (const char*);
+inline void SetVal (int i) { Sval = 0; Ival = i; }
+inline bool IsInt () const { return (Sval == 0) ? true : false; }
+inline bool IsString () const { return (Sval != 0) ? true : false; }
+ const char* GetQuotes () const;
+inline operator int () const { return Ival; }
+inline operator const char* () const { return Sval; }
+};
+
+
+class UchTextLine {
+protected:
+ int Num;
+ int Max;
+ UchTextWord* Words;
+void NewWord (const char* s, int i);
+
+public:
+ UchTextLine ();
+ ~UchTextLine ();
+inline UchTextWord& operator [] (int i) const { return Words [i]; }
+inline int NumWords () const { return Num; }
+inline void AddWord (const char* s) { NewWord (s, 0); }
+inline void AddWord (int i) { NewWord (0, i); }
+ void AddTrailer (const UchTextLine&, int);
+inline UchTextLine& operator << (int i) { AddWord (i); return *this; }
+inline UchTextLine& operator << (const char* s) { AddWord (s); return *this; }
+inline UchTextLine& operator << (const UchTextLine& l) { AddTrailer (l, 0); return *this; }
+ bool Parse (char*);
+ char* Unparse (char* dest, int len) const;
+ char* Unparse (UchMsgBuffer*) const;
+ bool Match (const char*, const char* = 0) const;
+ int Index (const char*) const;
+ int Index (int) const;
+inline bool Contains (const char* w) const { return (Index (w) == -1) ? false : true; }
+inline bool Contains (int i) const { return (Index (i) == -1) ? false : true; }
+inline void Reset () { Num = 0; }
+};
+
+
#endif /* TextStream_H_ */