FACT++  1.0
ChatClient.h
Go to the documentation of this file.
1 #ifndef FACT_ChatClient
2 #define FACT_ChatClient
3 
4 // **************************************************************************
10 // **************************************************************************
11 #include "Time.h"
12 #include "MessageDim.h"
13 #include "DimErrorRedirecter.h"
14 
15 using namespace std;
16 
18 {
19 protected:
20  std::ostream &lout;
21 
22  int Write(const Time &t, const string &txt, int)
23  {
24  Out() << t << ": " << txt.substr(6) << endl;
25  return 0;
26  }
27 
28 protected:
29  // Redirect asynchronous output to the output window
30  ChatClientImp(std::ostream &out, std::ostream &in) :
31  MessageImp(out),
32  DimErrorRedirecter(static_cast<MessageImp&>(*this)),
33  MessageDimRX("CHAT", static_cast<MessageImp&>(*this)),
34  lout(in)
35  {
36  Out() << Time::fmt("%H:%M:%S");
37  }
38 };
39 
40 // **************************************************************************
50 // **************************************************************************
51 #include "WindowLog.h"
52 #include "ReadlineColor.h"
53 #include "tools.h"
54 
55 template <class T>
56 class ChatClient : public T, public ChatClientImp
57 {
58 public:
59  // Redirect asynchronous output to the output window
60  ChatClient(const char *name) : T(name),
61  ChatClientImp(T::GetStreamOut(), T::GetStreamIn())
62  {
63  }
64 
65  // returns whether a command should be put into the history
66  bool Process(const std::string &str)
67  {
68  if (ReadlineColor::Process(lout, str))
69  return true;
70 
71  if (T::Process(str))
72  return true;
73 
74  const int rc = DimClient::sendCommand("CHAT/MSG", str.c_str());
75  if (!rc)
76  lout << kRed << "ERROR - Sending message failed." << endl;
77 
78  return false;
79  }
80 
81  std::string GetUpdatePrompt() const
82  {
83  // If we have not cd'ed to a server show only the line start
84  return T::GetLinePrompt() + " " + (IsConnected() ? "" : "dis") + "connected> ";
85  }
86 };
87 
88 
89 
90 // **************************************************************************
96 // **************************************************************************
97 #include "Console.h"
98 
99 class ChatConsole : public ChatClient<Console>
100 {
101 public:
102  ChatConsole(const char *name, bool continous=false) :
103  ChatClient<Console>(name)
104  {
105  SetContinous(continous);
106  }
107 };
108 
109 // **************************************************************************
115 // **************************************************************************
116 #include "Shell.h"
117 
118 class ChatShell : public ChatClient<Shell>
119 {
120 public:
121  ChatShell(const char *name, bool = false) :
122  ChatClient<Shell>(name)
123  {
124  }
125 };
126 
127 #endif
ChatConsole(const char *name, bool continous=false)
Definition: ChatClient.h:102
Implements a remote control based on a Readline class for the Chat client.
Definition: ChatClient.h:56
static int sendCommand(const char *name, int data)
Definition: diccpp.cxx:1098
A base class taking care of padding, exit handler and error handlers.
This is an extension to the Readline class provding buffered output.
Definition: Console.h:34
The base implementation of a distributed messaging system.
Definition: MessageImp.h:10
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
char str[80]
Definition: test_client.c:7
Set color Red.
Definition: WindowLog.h:17
ChatClientImp(std::ostream &out, std::ostream &in)
Definition: ChatClient.h:30
STL namespace.
The base implementation for a chat client.
Definition: ChatClient.h:17
Derives the ChatClient from Control and adds a proper prompt.
Definition: ChatClient.h:99
ChatShell(const char *name, bool=false)
Definition: ChatClient.h:121
bool Process(const std::string &str)
Definition: ChatClient.h:66
ChatClient(const char *name)
Definition: ChatClient.h:60
Derives the ChatClient from Shell and adds colored prompt.
Definition: ChatClient.h:118
static const _time_format fmt(const char *txt=0)
A stream manipulator to set the output/input format.
Definition: Time.cc:415
std::string GetUpdatePrompt() const
Definition: ChatClient.h:81
bool Process(std::ostream &out, const std::string &str)
std::ostream & lout
Definition: ChatClient.h:20
Based on MessageImp, subscribes to a MESSAGE service in the Dim network.
Definition: MessageDim.h:34
TT t
Definition: test_client.c:26
int Write(const Time &t, const string &txt, int)
Output stream for local synchrounous output.
Definition: ChatClient.h:22
Implementation of a console based user shell with an input and output window.
Definition: Shell.h:12