Commit 36c13ad1bb57294710776a73cfeca3bdcee2aa64
1 parent
5f3b9cfb
Exists in
master
and in
3 other branches
Activating auto-connect when the corresponding toggle is set and the
session is offline.
Showing
3 changed files
with
58 additions
and
14 deletions
Show diff stats
src/core/toggles/init.c
| ... | ... | @@ -59,13 +59,13 @@ |
| 59 | 59 | |
| 60 | 60 | /*---[ Implement ]------------------------------------------------------------------------------------------------------------*/ |
| 61 | 61 | |
| 62 | -static void toggle_altscreen(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt)) | |
| 62 | +static void toggle_altscreen(H3270 *session, const struct lib3270_toggle *t, LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt)) | |
| 63 | 63 | { |
| 64 | 64 | if(!session->screen_alt) |
| 65 | 65 | set_viewsize(session,t->value ? 24 : session->max.rows,80); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | -static void toggle_redraw(H3270 *session, struct lib3270_toggle GNUC_UNUSED(*t), LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt)) | |
| 68 | +static void toggle_redraw(H3270 *session, const struct lib3270_toggle GNUC_UNUSED(*t), LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt)) | |
| 69 | 69 | { |
| 70 | 70 | session->cbk.display(session); |
| 71 | 71 | } |
| ... | ... | @@ -73,11 +73,11 @@ static void toggle_redraw(H3270 *session, struct lib3270_toggle GNUC_UNUSED(*t), |
| 73 | 73 | /** |
| 74 | 74 | * @brief No-op toggle. |
| 75 | 75 | */ |
| 76 | -static void toggle_nop(H3270 GNUC_UNUSED(*session), struct lib3270_toggle GNUC_UNUSED(*t), LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt)) | |
| 76 | +static void toggle_nop(H3270 GNUC_UNUSED(*session), const struct lib3270_toggle GNUC_UNUSED(*t), LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt)) | |
| 77 | 77 | { |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | -static void toggle_keepalive(H3270 *session, struct lib3270_toggle GNUC_UNUSED(*t), LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt)) | |
| 80 | +static void toggle_keepalive(H3270 *session, const struct lib3270_toggle GNUC_UNUSED(*t), LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt)) | |
| 81 | 81 | { |
| 82 | 82 | if(session->connection.sock > 0) |
| 83 | 83 | { |
| ... | ... | @@ -96,21 +96,65 @@ static void toggle_keepalive(H3270 *session, struct lib3270_toggle GNUC_UNUSED(* |
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | +static void toggle_connect(H3270 *hSession, const struct lib3270_toggle *toggle, LIB3270_TOGGLE_TYPE tt) | |
| 100 | +{ | |
| 101 | + if(tt != LIB3270_TOGGLE_TYPE_INITIAL && lib3270_is_disconnected(hSession) && !hSession->popups && toggle->value) | |
| 102 | + { | |
| 103 | + if(lib3270_reconnect(hSession,0)) | |
| 104 | + lib3270_write_log(hSession,"3270","Auto-connect fails: %s",strerror(errno)); | |
| 105 | + } | |
| 106 | + | |
| 107 | +} | |
| 108 | + | |
| 99 | 109 | /** |
| 100 | 110 | * @brief Called from system initialization code to handle initial toggle settings. |
| 101 | 111 | */ |
| 102 | 112 | void initialize_toggles(H3270 *session) |
| 103 | 113 | { |
| 104 | - int f; | |
| 114 | + static const struct _upcalls | |
| 115 | + { | |
| 116 | + LIB3270_TOGGLE_ID id; | |
| 117 | + void (*upcall)(H3270 *session, const struct lib3270_toggle *t, LIB3270_TOGGLE_TYPE tt); | |
| 118 | + } | |
| 119 | + upcalls[] = | |
| 120 | + { | |
| 121 | + { | |
| 122 | + LIB3270_TOGGLE_RECTANGLE_SELECT, | |
| 123 | + toggle_rectselect | |
| 124 | + | |
| 125 | + }, | |
| 126 | + { | |
| 127 | + LIB3270_TOGGLE_MONOCASE, | |
| 128 | + toggle_redraw | |
| 129 | + }, | |
| 130 | + { | |
| 131 | + LIB3270_TOGGLE_UNDERLINE, | |
| 132 | + toggle_redraw | |
| 133 | + | |
| 134 | + }, | |
| 135 | + { | |
| 136 | + LIB3270_TOGGLE_ALTSCREEN, | |
| 137 | + toggle_altscreen | |
| 138 | + | |
| 139 | + }, | |
| 140 | + { | |
| 141 | + LIB3270_TOGGLE_KEEP_ALIVE, | |
| 142 | + toggle_keepalive | |
| 143 | + }, | |
| 144 | + { | |
| 145 | + LIB3270_TOGGLE_CONNECT_ON_STARTUP, | |
| 146 | + toggle_connect | |
| 147 | + } | |
| 148 | + | |
| 149 | + }; | |
| 150 | + | |
| 151 | + unsigned int f; | |
| 105 | 152 | |
| 106 | 153 | for(f=0;f<LIB3270_TOGGLE_COUNT;f++) |
| 107 | 154 | session->toggle[f].upcall = toggle_nop; |
| 108 | 155 | |
| 109 | - session->toggle[LIB3270_TOGGLE_RECTANGLE_SELECT].upcall = toggle_rectselect; | |
| 110 | - session->toggle[LIB3270_TOGGLE_MONOCASE].upcall = toggle_redraw; | |
| 111 | - session->toggle[LIB3270_TOGGLE_UNDERLINE].upcall = toggle_redraw; | |
| 112 | - session->toggle[LIB3270_TOGGLE_ALTSCREEN].upcall = toggle_altscreen; | |
| 113 | - session->toggle[LIB3270_TOGGLE_KEEP_ALIVE].upcall = toggle_keepalive; | |
| 156 | + for(f=0;f<(sizeof(upcalls)/sizeof(upcalls[0]));f++) | |
| 157 | + session->toggle[upcalls[f].id].upcall = upcalls[f].upcall; | |
| 114 | 158 | |
| 115 | 159 | for(f=0;f<LIB3270_TOGGLE_COUNT;f++) |
| 116 | 160 | { | ... | ... |
src/include/internals.h
| ... | ... | @@ -383,8 +383,8 @@ struct _h3270 |
| 383 | 383 | |
| 384 | 384 | struct lib3270_toggle |
| 385 | 385 | { |
| 386 | - char value; /**< toggle value */ | |
| 387 | - void (*upcall)(H3270 *, struct lib3270_toggle *, LIB3270_TOGGLE_TYPE); /**< change value */ | |
| 386 | + char value; /**< toggle value */ | |
| 387 | + void (*upcall)(H3270 *, const struct lib3270_toggle *, LIB3270_TOGGLE_TYPE); /**< change value */ | |
| 388 | 388 | } toggle[LIB3270_TOGGLE_COUNT]; |
| 389 | 389 | |
| 390 | 390 | // Network & Termtype |
| ... | ... | @@ -756,7 +756,7 @@ LIB3270_INTERNAL int use_syslog; |
| 756 | 756 | LIB3270_INTERNAL int key_ACharacter(H3270 *hSession, unsigned char c, enum keytype keytype, enum iaction cause,Boolean *skipped); |
| 757 | 757 | LIB3270_INTERNAL int cursor_move(H3270 *session, int baddr); |
| 758 | 758 | |
| 759 | -LIB3270_INTERNAL void toggle_rectselect(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGGLE_TYPE tt); | |
| 759 | +LIB3270_INTERNAL void toggle_rectselect(H3270 *session, const struct lib3270_toggle *t, LIB3270_TOGGLE_TYPE tt); | |
| 760 | 760 | LIB3270_INTERNAL void remove_input_calls(H3270 *session); |
| 761 | 761 | |
| 762 | 762 | LIB3270_INTERNAL int lib3270_sock_send(H3270 *hSession, unsigned const char *buf, int len); | ... | ... |
src/selection/selection.c
| ... | ... | @@ -154,7 +154,7 @@ static void update_selected_region(H3270 *session) |
| 154 | 154 | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | -void toggle_rectselect(H3270 *session, struct lib3270_toggle GNUC_UNUSED(*t), LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt)) | |
| 157 | +void toggle_rectselect(H3270 *session, const struct lib3270_toggle GNUC_UNUSED(*t), LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt)) | |
| 158 | 158 | { |
| 159 | 159 | if(!session->selected) |
| 160 | 160 | return; | ... | ... |