Commit 4bdffe123cc394dccb6f7e39a7fa12d2cc8378dd

Authored by Perry Werneck
1 parent df38c6bc
Exists in master and in 1 other branch develop

Working on the new API.

host.cc
... ... @@ -43,7 +43,8 @@
43 43  
44 44 namespace TN3270 {
45 45  
46   - Host::Host(const char *id, const char *url) {
  46 + Host::Host(const char *id, const char *url, time_t timeout) {
  47 + this->timeout = timeout;
47 48 this->session = Session::create(id);
48 49 if(url) {
49 50 this->connect(url);
... ... @@ -55,15 +56,17 @@
55 56 this->session = nullptr;
56 57 }
57 58  
58   - void Host::connect(const char *url) {
  59 + void Host::connect(const char *url, bool sync) {
59 60 this->session->connect(url);
60   - sync();
  61 + if(sync) {
  62 + this->sync();
  63 + }
61 64 }
62 65  
63 66  
64 67 /// @brief Writes characters to the associated file from the put area
65 68 int Host::sync() {
66   - this->session->waitForReady();
  69 + this->session->waitForReady(this->timeout);
67 70 return 0;
68 71 }
69 72  
... ... @@ -89,6 +92,8 @@
89 92  
90 93 std::string Host::toString() const {
91 94  
  95 + this->session->waitForReady(this->timeout);
  96 +
92 97 if(this->session->getConnectionState() == TN3270::DISCONNECTED) {
93 98 throw std::system_error(ENOTCONN, std::system_category());
94 99 }
... ... @@ -96,5 +101,70 @@
96 101 return this->session->toString();
97 102 }
98 103  
  104 + std::string Host::toString(int baddr, size_t len, char lf) const {
  105 +
  106 + this->session->waitForReady(this->timeout);
  107 +
  108 + if(this->session->getConnectionState() == TN3270::DISCONNECTED) {
  109 + throw std::system_error(ENOTCONN, std::system_category());
  110 + }
  111 +
  112 + return this->session->toString(baddr,len,lf);
  113 +
  114 + }
  115 +
  116 + std::string Host::toString(int row, int col, size_t sz, char lf) const {
  117 +
  118 + this->session->waitForReady(this->timeout);
  119 +
  120 + if(this->session->getConnectionState() == TN3270::DISCONNECTED) {
  121 + throw std::system_error(ENOTCONN, std::system_category());
  122 + }
  123 +
  124 + return this->session->toString(row,col,sz,lf);
  125 +
  126 +
  127 + }
  128 +
  129 + Host & Host::pop(int baddr, std::string &text) {
  130 +
  131 + this->session->waitForReady(this->timeout);
  132 +
  133 + if(this->session->getConnectionState() == TN3270::DISCONNECTED) {
  134 + throw std::system_error(ENOTCONN, std::system_category());
  135 + }
  136 +
  137 + session->pop(baddr, text);
  138 +
  139 + return *this;
  140 + }
  141 +
  142 + Host & Host::pop(int row, int col, std::string &text) {
  143 +
  144 + this->session->waitForReady(this->timeout);
  145 +
  146 + if(this->session->getConnectionState() == TN3270::DISCONNECTED) {
  147 + throw std::system_error(ENOTCONN, std::system_category());
  148 + }
  149 +
  150 + session->pop(row,col,text);
  151 +
  152 + return *this;
  153 + }
  154 +
  155 + Host & Host::pop(std::string &text) {
  156 +
  157 + this->session->waitForReady(this->timeout);
  158 +
  159 + if(this->session->getConnectionState() == TN3270::DISCONNECTED) {
  160 + throw std::system_error(ENOTCONN, std::system_category());
  161 + }
  162 +
  163 + session->pop(text);
  164 +
  165 + return *this;
  166 + }
  167 +
  168 +
99 169 }
100 170  
... ...
local/session.cc
... ... @@ -216,7 +216,19 @@
216 216 }
217 217  
218 218 TN3270::Session & Local::Session::pop(int baddr, std::string &text) {
  219 +
219 220 std::lock_guard<std::mutex> lock(sync);
  221 +
  222 + char *contents = lib3270_get_field_at(hSession, baddr);
  223 +
  224 + if(!contents) {
  225 + throw std::runtime_error("Can't get field contents");
  226 + }
  227 +
  228 + text.assign(convertFromHost(contents).c_str());
  229 +
  230 + lib3270_free(contents);
  231 +
220 232 return *this;
221 233 }
222 234  
... ...
testprogram/testprogram.cc
... ... @@ -47,7 +47,7 @@
47 47  
48 48 TN3270::Host host;
49 49  
50   - host.connect(getenv("TN3270URL"));
  50 + host.connect(getenv("LIB3270_DEFAULT_HOST"));
51 51 cout << host << endl;
52 52  
53 53 host << TN3270::ENTER;
... ...