Commit 68743f00d62f57d4acbeb39e32a04d2d9132c30c

Authored by Perry Werneck
1 parent f2b6e6f0

Planejando versão C++

Showing 1 changed file with 92 additions and 2 deletions   Show diff stats
src/include/lib3270++.h
... ... @@ -33,6 +33,7 @@
33 33  
34 34 #define LIB3270_HPP_INCLUDED 1
35 35  
  36 + #include <iostream>
36 37 #include <lib3270.h>
37 38  
38 39 #if defined(_WIN32)
... ... @@ -62,6 +63,8 @@
62 63  
63 64 namespace TN3270 {
64 65  
  66 + class Host;
  67 +
65 68 enum ProgramMessage : uint8_t {
66 69 MESSAGE_NONE = LIB3270_MESSAGE_NONE, ///< @brief No message
67 70 MESSAGE_SYSWAIT = LIB3270_MESSAGE_SYSWAIT, ///< @brief --
... ... @@ -138,7 +141,7 @@
138 141  
139 142 // Connect/disconnect
140 143 virtual void connect(const char *url) = 0;
141   - virtual void disconnect(const char *url);
  144 + virtual void disconnect();
142 145  
143 146 // Gets
144 147 virtual std::string toString(int baddr = 0, size_t len = -1, bool lf = false) = 0;
... ... @@ -169,7 +172,7 @@
169 172 return push(text.c_str());
170 173 }
171 174  
172   - virtual Session & push(int baddr = 0, const std::string &text) = 0;
  175 + virtual Session & push(int baddr, const std::string &text) = 0;
173 176 virtual Session & push(int row, int col, const std::string &text) = 0;
174 177 virtual Session & push(const PFKey key) = 0;
175 178 virtual Session & push(const PAKey key) = 0;
... ... @@ -177,6 +180,83 @@
177 180  
178 181 };
179 182  
  183 + /// @brief TN3270 Host
  184 + class TN3270_PUBLIC Host : public std::basic_streambuf<char, std::char_traits<char> > {
  185 + private:
  186 +
  187 + /// @brief Connection with the host
  188 + Session *session;
  189 +
  190 + protected:
  191 +
  192 + /// @brief Writes characters to the associated file from the put area
  193 + int sync() override;
  194 +
  195 + /// @brief Writes characters to the associated output sequence from the put area.
  196 + int overflow(int c) override;
  197 +
  198 + public:
  199 + Host(const char *id = nullptr, const char *url = nullptr);
  200 + ~Host();
  201 +
  202 + inline ProgramMessage getProgramMessage() const {
  203 + return session->getProgramMessage();
  204 + }
  205 +
  206 + inline operator ProgramMessage() const {
  207 + return getProgramMessage();
  208 + }
  209 +
  210 + inline ConnectionState getConnectionState() const {
  211 + return session->getConnectionState();
  212 + }
  213 +
  214 + inline operator ConnectionState() const {
  215 + return getConnectionState();
  216 + }
  217 +
  218 +
  219 + // Sets
  220 +
  221 + /// @brief Set field at current posicion, jumps to next writable field.
  222 + inline Host & push(const char *text) {
  223 + session->push(text);
  224 + return *this;
  225 + };
  226 +
  227 + inline Host & push(const std::string &text) {
  228 + session->push(text));
  229 + return *this;
  230 +
  231 + }
  232 +
  233 + inline Host & push(int baddr, const std::string &text) {
  234 + session->push(baddr,text);
  235 + return *this;
  236 + }
  237 +
  238 + inline Host & push(int row, int col, const std::string &text) {
  239 + session->push(row,col,text);
  240 + return *this;
  241 + }
  242 +
  243 + inline Host & push(const PFKey key) {
  244 + session->push(key);
  245 + return *this;
  246 + }
  247 +
  248 + inline Host & push(const PAKey key) {
  249 + session->push(key);
  250 + return *this;
  251 + }
  252 +
  253 + inline Host & push(const Action action) {
  254 + session->push(action);
  255 + return *this;
  256 + }
  257 +
  258 + };
  259 +
180 260 }
181 261  
182 262 TN3270_PUBLIC const char * toCharString(const TN3270::ProgramMessage programMessage) noexcept;
... ... @@ -192,6 +272,16 @@
192 272 return session.pop(value);
193 273 }
194 274  
  275 + template <typename T>
  276 + inline TN3270_PUBLIC TN3270::Host & operator<<(TN3270::Host& host, const T value) {
  277 + return host.push(value);
  278 + }
  279 +
  280 + template <typename T>
  281 + inline TN3270_PUBLIC TN3270::Host & operator>>(TN3270::Host& host, const T value) {
  282 + return Host.pop(value);
  283 + }
  284 +
195 285 #endif
196 286  
197 287 #endif // LIB3270_H_INCLUDED
... ...