13 #include <linux/list.h>
14 #include <linux/types.h>
15 #include <linux/slab.h>
17 #include <linux/reboot.h>
28 #define CON3270_OUTPUT_BUFFER_SIZE 1024
29 #define CON3270_STRING_PAGES 4
62 #define CON_UPDATE_ERASE 1
63 #define CON_UPDATE_LIST 2
64 #define CON_UPDATE_STATUS 4
65 #define CON_UPDATE_ALL 8
67 static void con3270_update(
struct con3270 *);
72 static void con3270_set_timer(
struct con3270 *
cp,
int expires)
86 con3270_update_status(
struct con3270 *cp)
90 str = (cp->
nr_up != 0) ?
"History" :
"Running";
92 codepage_convert(cp->
view.ascebc, cp->
status->string + 24, 7);
97 con3270_create_status(
struct con3270 *cp)
99 static const unsigned char blueprint[] =
101 'c',
'o',
'n',
's',
'o',
'l',
'e',
' ',
'v',
'i',
'e',
'w',
102 TO_RA,0,0,0,
'R',
'u',
'n',
'n',
'i',
'n',
'g',
TO_SF,TF_LOG };
106 memcpy(cp->
status->string, blueprint,
sizeof(blueprint));
109 cp->
view.cols * (cp->
view.rows - 1));
113 codepage_convert(cp->
view.ascebc, cp->
status->string + 8, 12);
114 codepage_convert(cp->
view.ascebc, cp->
status->string + 24, 7);
121 con3270_update_string(
struct con3270 *cp,
struct string *
s,
int nr)
123 if (s->
len >= cp->
view.cols - 5)
126 cp->
view.cols * (nr + 1));
133 con3270_rebuild_update(
struct con3270 *cp)
143 list_del_init(&s->
update);
144 nr = cp->view.
rows - 2 + cp->nr_up;
146 if (nr < cp->view.rows - 1)
147 list_add(&s->update, &cp->
update);
159 con3270_alloc_string(
struct con3270 *cp,
size_t size)
163 s = alloc_string(&cp->
freemem, size);
168 if (!list_empty(&s->
update))
171 if (free_string(&cp->
freemem, s) >= size)
174 s = alloc_string(&cp->
freemem, size);
178 con3270_rebuild_update(cp);
179 con3270_update_status(cp);
198 con3270_update(
struct con3270 *cp)
203 unsigned long updated;
212 con3270_set_timer(cp, 1);
219 con3270_rebuild_update(cp);
220 con3270_update_status(cp);
253 con3270_update_string(cp, s, cp->
line_nr);
257 list_del_init(&s->
update);
261 if (list_empty(&cp->
update))
264 wrq->
callback = con3270_write_callback;
269 con3270_set_timer(cp, 1);
274 spin_unlock_irqrestore(&cp->
view.lock, flags);
283 static char kreset_data =
TW_KR;
286 int nr_up, deactivate;
293 switch (cp->
input->string[0]) {
302 con3270_set_timer(cp, 1);
305 nr_up += cp->
view.rows - 2;
313 nr_up -= cp->
view.rows - 2;
318 if (nr_up != cp->
nr_up) {
320 con3270_rebuild_update(cp);
321 con3270_update_status(cp);
322 con3270_set_timer(cp, 1);
324 spin_unlock_irqrestore(&cp->
view.lock, flags);
337 raw3270_put_view(&cp->
view);
346 raw3270_get_view(rq->
view);
348 tasklet_schedule(&((
struct con3270 *) rq->
view)->readlet);
355 con3270_issue_read(
struct con3270 *cp)
364 rrq->
callback = con3270_read_callback;
384 con3270_set_timer(cp, 1);
402 con3270_issue_read(cp);
416 .activate = con3270_activate,
417 .deactivate = con3270_deactivate,
418 .intv = (
void *) con3270_irq
422 con3270_cline_add(
struct con3270 *cp)
424 if (!list_empty(&cp->
cline->list))
429 con3270_rebuild_update(cp);
433 con3270_cline_insert(
struct con3270 *cp,
unsigned char c)
436 cp->
view.ascebc[(c <
' ') ?
' ' : c];
437 if (list_empty(&cp->
cline->update)) {
444 con3270_cline_end(
struct con3270 *cp)
450 size = (cp->
cline->len < cp->
view.cols - 5) ?
452 s = con3270_alloc_string(cp, size);
454 if (s->
len < cp->
view.cols - 5) {
458 while (--size > cp->
cline->len)
463 list_del_init(&cp->
cline->list);
464 if (!list_empty(&cp->
cline->update)) {
466 list_del_init(&cp->
cline->update);
483 while (count-- > 0) {
485 if (cp->
cline->len == 0)
486 con3270_cline_add(cp);
488 con3270_cline_insert(cp, c);
489 if (c ==
'\n' || cp->
cline->len >= cp->
view.cols)
490 con3270_cline_end(cp);
494 if (cp->
view.dev && !timer_pending(&cp->
timer))
495 con3270_set_timer(cp,
HZ/10);
496 spin_unlock_irqrestore(&cp->
view.lock,flags);
510 con3270_wait_write(
struct con3270 *cp)
533 con3270_wait_write(cp);
535 con3270_rebuild_update(cp);
536 con3270_update_status(cp);
538 spin_unlock_irqrestore(&cp->
view.lock, flags);
541 con3270_wait_write(cp);
543 spin_unlock_irqrestore(&cp->
view.lock, flags);
547 unsigned long event,
void *data)
554 .notifier_call = con3270_notify,
559 .notifier_call = con3270_notify,
568 .
write = con3270_write,
569 .device = con3270_device,
605 condev->
read->callback = con3270_read_callback;
606 condev->
read->callback_data = condev;
610 INIT_LIST_HEAD(&condev->
lines);
611 INIT_LIST_HEAD(&condev->
update);
613 (
unsigned long) condev);
615 (
void (*)(
unsigned long)) con3270_read_tasklet,
616 (
unsigned long) condev->
read);
620 INIT_LIST_HEAD(&condev->
freemem);
626 condev->
cline->len = 0;
627 con3270_create_status(condev);