Commit 61474b339d85b61672246edddbaff98864181845
1 parent
b6e92ddd
Exists in
master
and in
1 other branch
Refactoring hllapi module.
Showing
3 changed files
with
125 additions
and
51 deletions
Show diff stats
.gitignore
src/core/calls.cc
... | ... | @@ -50,7 +50,7 @@ |
50 | 50 | { |
51 | 51 | try { |
52 | 52 | |
53 | - getSession().connect((const char *) uri, false); | |
53 | + getSession().connect((const char *) uri, (wait != 0)); | |
54 | 54 | |
55 | 55 | if(wait) |
56 | 56 | return hllapi_wait_for_ready(wait); |
... | ... | @@ -278,51 +278,81 @@ |
278 | 278 | return *datadir; |
279 | 279 | } |
280 | 280 | |
281 | - /* | |
281 | + HLLAPI_API_CALL hllapi_wait(WORD seconds) { | |
282 | 282 | |
283 | - HLLAPI_API_CALL hllapi_wait(WORD seconds) | |
284 | - { | |
285 | - if(!hllapi_is_connected()) | |
286 | - return HLLAPI_STATUS_DISCONNECTED; | |
283 | + try { | |
287 | 284 | |
288 | - session::get_default()->wait(seconds); | |
285 | + TN3270::Host &host = getSession(); | |
289 | 286 | |
290 | - return hllapi_get_state(); | |
291 | - } | |
287 | + if(!host.isConnected()) | |
288 | + return HLLAPI_STATUS_DISCONNECTED; | |
292 | 289 | |
293 | - HLLAPI_API_CALL hllapi_cmp_text_at(WORD row, WORD col, LPSTR text) | |
294 | - { | |
290 | + host.wait(seconds); | |
295 | 291 | |
296 | - if(!hllapi_is_connected()) | |
297 | - return HLLAPI_STATUS_DISCONNECTED; | |
292 | + return hllapi_get_state(); | |
298 | 293 | |
299 | - int rc = HLLAPI_STATUS_SYSTEM_ERROR; | |
294 | + } catch(std::exception &e) { | |
295 | + | |
296 | + hllapi_lasterror = e.what(); | |
300 | 297 | |
301 | - try | |
302 | - { | |
303 | - rc = session::get_default()->cmp_string_at(row,col,text); | |
304 | - } | |
305 | - catch(std::exception &e) | |
306 | - { | |
307 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
308 | 298 | } |
309 | 299 | |
310 | - return rc; | |
300 | + return HLLAPI_STATUS_SYSTEM_ERROR; | |
301 | + | |
311 | 302 | } |
312 | 303 | |
313 | - HLLAPI_API_CALL hllapi_find_text(LPSTR text) | |
314 | - { | |
315 | - if(!hllapi_is_connected()) | |
316 | - return HLLAPI_STATUS_DISCONNECTED; | |
304 | + HLLAPI_API_CALL hllapi_cmp_text_at(WORD row, WORD col, LPSTR text) { | |
317 | 305 | |
318 | - return (int) session::get_default()->find_string((const char *) text, false); | |
319 | - } | |
306 | + try { | |
320 | 307 | |
308 | + TN3270::Host &host = getSession(); | |
309 | + | |
310 | + if(!host.isConnected()) | |
311 | + return HLLAPI_STATUS_DISCONNECTED; | |
312 | + | |
313 | + string contents = host.toString(row, col, strlen(text), 0); | |
314 | + | |
315 | + return strncmp(contents.c_str(),text,strlen(text)); | |
316 | + | |
317 | + } catch(std::exception &e) { | |
318 | + | |
319 | + hllapi_lasterror = e.what(); | |
320 | + | |
321 | + } | |
322 | + | |
323 | + return HLLAPI_STATUS_SYSTEM_ERROR; | |
321 | 324 | |
322 | - void hllapi_free(void *p) | |
323 | - { | |
324 | - free(p); | |
325 | 325 | } |
326 | 326 | |
327 | + HLLAPI_API_CALL hllapi_find_text(LPSTR text) { | |
328 | + | |
329 | + try { | |
330 | + | |
331 | + TN3270::Host &host = getSession(); | |
332 | + | |
333 | + if(!host.isConnected()) { | |
334 | + hllapi_lasterror = "Not connected"; | |
335 | + return -1; | |
336 | + } | |
337 | + | |
338 | + string contents = host.toString(0,-1,0); | |
339 | + | |
340 | + size_t pos = contents.find(text); | |
341 | + | |
342 | + if(pos == string::npos) { | |
343 | + hllapi_lasterror = "Not found"; | |
344 | + return -1; | |
345 | + } | |
346 | + | |
347 | + return pos; | |
348 | + | |
349 | + } catch(std::exception &e) { | |
350 | + | |
351 | + hllapi_lasterror = e.what(); | |
352 | + | |
353 | + } | |
354 | + | |
355 | + return -1; | |
356 | + | |
357 | + } | |
327 | 358 | |
328 | -*/ | ... | ... |
src/testprogram/testprogram.cc
... | ... | @@ -40,6 +40,8 @@ |
40 | 40 | |
41 | 41 | int main(int argc, char **argv) { |
42 | 42 | |
43 | + char buffer[SCREEN_LENGTH+1]; | |
44 | + | |
43 | 45 | const char *host = ""; |
44 | 46 | const char *session = ""; // "pw3270:A"; |
45 | 47 | |
... | ... | @@ -77,14 +79,64 @@ |
77 | 79 | return rc; |
78 | 80 | } |
79 | 81 | |
80 | - cout << "TN3270 library revision is " << ((int) hllapi_get_revision()) << endl; | |
82 | + cout << "TN3270 library revision is " << ((int) hllapi_get_revision()) << endl << ">"; | |
81 | 83 | |
82 | - rc = hllapi_connect(host,1); | |
83 | - if(rc) { | |
84 | - cout << "hllapi_connect returns with rc=" << rc << " (" << hllapi_get_last_error() << ")" << endl; | |
85 | - return rc; | |
84 | + cout.flush(); | |
85 | + | |
86 | + string cmdline; | |
87 | + while(std::getline(std::cin, cmdline)) { | |
88 | + | |
89 | + if(cmdline.empty()) | |
90 | + break; | |
91 | + | |
92 | + memset(buffer,' ',SCREEN_LENGTH); | |
93 | + buffer[SCREEN_LENGTH] = 0; | |
94 | + | |
95 | + if(strcasecmp(cmdline.c_str(),"connect") == 0) { | |
96 | + | |
97 | + cout << "Connecting..." << endl; | |
98 | + rc = hllapi_connect(host,1); | |
99 | + cout << "hllapi_connect returns with rc=" << rc << " (" << hllapi_get_last_error() << ")" << endl; | |
100 | + | |
101 | + } else if(strcasecmp(cmdline.c_str(),"wait") == 0) { | |
102 | + | |
103 | + rc = hllapi_wait_for_ready(10); | |
104 | + cout << "hllapi_wait_for_ready returns with rc=" << rc << " (" << hllapi_get_last_error() << ")" << endl; | |
105 | + | |
106 | + } else if(strcasecmp(cmdline.c_str(),"disconnect") == 0) { | |
107 | + | |
108 | + cout << "Disconnecting..." << endl; | |
109 | + rc = hllapi_disconnect(); | |
110 | + cout << "hllapi_disconnect returns with rc=" << rc << " (" << hllapi_get_last_error() << ")" << endl; | |
111 | + | |
112 | + } else if(strcasecmp(cmdline.c_str(),"luname") == 0) { | |
113 | + | |
114 | + rc = hllapi_get_lu_name(buffer,SCREEN_LENGTH); | |
115 | + if(rc == HLLAPI_STATUS_SUCCESS) { | |
116 | + cout << "LU Name is " << buffer << endl; | |
117 | + } else { | |
118 | + cout << "hllapi_get_lu_name returns with rc=" << rc << " (" << hllapi_get_last_error() << ")" << endl; | |
119 | + } | |
120 | + | |
121 | + } else if(strcasecmp(cmdline.c_str(),"contents") == 0) { | |
122 | + | |
123 | + rc = hllapi_get_screen(0,buffer,SCREEN_LENGTH); | |
124 | + cout << "hllapi_get_screen returns with rc=" << rc << " (" << hllapi_get_last_error() << ")" << endl | |
125 | + << buffer << endl << endl; | |
126 | + | |
127 | + } else { | |
128 | + | |
129 | + cout << "Unknown command" << endl; | |
130 | + } | |
131 | + | |
132 | + | |
133 | + cout << endl << ">"; | |
134 | + cout.flush(); | |
86 | 135 | } |
87 | 136 | |
137 | + /* | |
138 | + | |
139 | + | |
88 | 140 | rc = hllapi_wait_for_ready(10); |
89 | 141 | if(rc) { |
90 | 142 | cout << "hllapi_wait_for_ready returns with rc=" << rc << " (" << hllapi_get_last_error() << ")" << endl; |
... | ... | @@ -95,7 +147,6 @@ |
95 | 147 | |
96 | 148 | cout << "Host is connected" << endl; |
97 | 149 | |
98 | - char buffer[SCREEN_LENGTH+1]; | |
99 | 150 | memset(buffer,' ',SCREEN_LENGTH); |
100 | 151 | buffer[SCREEN_LENGTH] = 0; |
101 | 152 | |
... | ... | @@ -113,6 +164,11 @@ |
113 | 164 | |
114 | 165 | } |
115 | 166 | |
167 | + rc = hllapi_get_lu_name(buffer,SCREEN_LENGTH); | |
168 | + if(rc == HLLAPI_STATUS_SUCCESS) { | |
169 | + cout << "LU Name is " << buffer << endl; | |
170 | + } | |
171 | + | |
116 | 172 | rc = hllapi_disconnect(); |
117 | 173 | if(rc) { |
118 | 174 | cout << "hllapi_disconnect returns with rc=" << rc << " (" << hllapi_get_last_error() << ")" << endl; |
... | ... | @@ -121,19 +177,6 @@ |
121 | 177 | |
122 | 178 | cout << "HLLAPI Last error was \"" << hllapi_get_last_error() << "\"" << endl; |
123 | 179 | |
124 | - /* | |
125 | - printf("Library revision is %d\n",(int) hllapi_get_revision()); | |
126 | - | |
127 | - if(host) { | |
128 | - | |
129 | - printf("connect=%d\n",(int) hllapi_connect((char *) host,1)); | |
130 | - printf("wait_for_ready=%d\n",(int) hllapi_wait_for_ready(10)); | |
131 | - printf("connected=%s\n",(int) hllapi_is_connected() ? "Yes" : "No"); | |
132 | - | |
133 | - printf("disconnect=%d\n",(int) hllapi_disconnect()); | |
134 | - } | |
135 | - | |
136 | - printf("connected=%s\n",(int) hllapi_is_connected() ? "Yes" : "No"); | |
137 | 180 | */ |
138 | 181 | |
139 | 182 | rc = hllapi_deinit(); | ... | ... |