Commit 4d87d9fa8789efa503a638404282f55bb4bb1303
1 parent
24b1b802
Exists in
master
Implementando configuração dos timers de auto limpeza.
Showing
5 changed files
with
82 additions
and
10 deletions
Show diff stats
src/gobject.c
| @@ -320,3 +320,31 @@ void pw3270_dbus_get_screen_length(PW3270Dbus *object, const gchar *id, DBusGMet | @@ -320,3 +320,31 @@ void pw3270_dbus_get_screen_length(PW3270Dbus *object, const gchar *id, DBusGMet | ||
| 320 | 320 | ||
| 321 | dbus_g_method_return(context,lib3270_get_length(ses->host)); | 321 | dbus_g_method_return(context,lib3270_get_length(ses->host)); |
| 322 | } | 322 | } |
| 323 | + | ||
| 324 | +void pw3270_dbus_set_timeout(PW3270Dbus *object, const gchar *id, int timeout, DBusGMethodInvocation *context) { | ||
| 325 | + | ||
| 326 | + struct session * ses = session_find(id); | ||
| 327 | + | ||
| 328 | + if(!ses) { | ||
| 329 | + pw3270_dbus_return_error(context,ENOENT); | ||
| 330 | + return; | ||
| 331 | + } | ||
| 332 | + | ||
| 333 | + ses->maxidle = (time_t) timeout; | ||
| 334 | + | ||
| 335 | + dbus_g_method_return(context,0); | ||
| 336 | +} | ||
| 337 | + | ||
| 338 | +void pw3270_dbus_set_autoclose(PW3270Dbus *object, const gchar *id, int timeout, DBusGMethodInvocation *context) { | ||
| 339 | + | ||
| 340 | + struct session * ses = session_find(id); | ||
| 341 | + | ||
| 342 | + if(!ses) { | ||
| 343 | + pw3270_dbus_return_error(context,ENOENT); | ||
| 344 | + return; | ||
| 345 | + } | ||
| 346 | + | ||
| 347 | + ses->autoclose = (time_t) timeout; | ||
| 348 | + | ||
| 349 | + dbus_g_method_return(context,0); | ||
| 350 | +} |
src/iocallback.c
| @@ -254,6 +254,7 @@ static void beep(H3270 *session) { | @@ -254,6 +254,7 @@ static void beep(H3270 *session) { | ||
| 254 | } | 254 | } |
| 255 | 255 | ||
| 256 | void register_3270_io_handlers(void) { | 256 | void register_3270_io_handlers(void) { |
| 257 | + | ||
| 257 | static const struct lib3270_callbacks hdl = { | 258 | static const struct lib3270_callbacks hdl = { |
| 258 | 259 | ||
| 259 | sizeof(struct lib3270_callbacks), | 260 | sizeof(struct lib3270_callbacks), |
src/private.h
| @@ -41,9 +41,12 @@ | @@ -41,9 +41,12 @@ | ||
| 41 | #include <lib3270.h> | 41 | #include <lib3270.h> |
| 42 | 42 | ||
| 43 | struct session { | 43 | struct session { |
| 44 | - unsigned int id; ///< @brief Identificador da sessão. | ||
| 45 | - time_t activity; ///< @brief Timestamp da última atividade dessa sessão. | ||
| 46 | - H3270 * host; ///< @brief Sessão TN3270. | 44 | + unsigned int id; ///< @brief Identificador da sessão. |
| 45 | + time_t activity; ///< @brief Timestamp da última atividade dessa sessão. | ||
| 46 | + time_t timeout; ///< @brief Após quantos segundos eu encerro a sessao? | ||
| 47 | + time_t maxidle; ///< @brief Tempo máximo que a sessão pode ficar IDLE | ||
| 48 | + time_t autoclose; ///< @brief Destroi a sessão quantos segundos após a desconexão? | ||
| 49 | + H3270 * host; ///< @brief Sessão TN3270. | ||
| 47 | }; | 50 | }; |
| 48 | 51 | ||
| 49 | G_GNUC_INTERNAL GMainLoop * main_loop; | 52 | G_GNUC_INTERNAL GMainLoop * main_loop; |
src/service.h
| @@ -83,18 +83,18 @@ | @@ -83,18 +83,18 @@ | ||
| 83 | void pw3270_dbus_get_screen_height(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context); | 83 | void pw3270_dbus_get_screen_height(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context); |
| 84 | void pw3270_dbus_get_screen_length(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context); | 84 | void pw3270_dbus_get_screen_length(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context); |
| 85 | 85 | ||
| 86 | + void pw3270_dbus_set_timeout(PW3270Dbus *object, const gchar *id, int timeout, DBusGMethodInvocation *context); | ||
| 87 | + void pw3270_dbus_set_autoclose(PW3270Dbus *object, const gchar *id, int timeout, DBusGMethodInvocation *context); | ||
| 88 | + | ||
| 86 | /* | 89 | /* |
| 87 | void pw3270_dbus_quit(PW3270Dbus *object, DBusGMethodInvocation *context); | 90 | void pw3270_dbus_quit(PW3270Dbus *object, DBusGMethodInvocation *context); |
| 88 | - void pw3270_dbus_connect(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context); | ||
| 89 | void pw3270_dbus_get_ur_l(PW3270Dbus *object, DBusGMethodInvocation *context); | 91 | void pw3270_dbus_get_ur_l(PW3270Dbus *object, DBusGMethodInvocation *context); |
| 90 | void pw3270_dbus_set_ur_l(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context); | 92 | void pw3270_dbus_set_ur_l(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context); |
| 91 | - void pw3270_dbus_disconnect(PW3270Dbus *object, DBusGMethodInvocation *context); | ||
| 92 | 93 | ||
| 93 | void pw3270_dbus_get_message_id(PW3270Dbus *object, DBusGMethodInvocation *context); | 94 | void pw3270_dbus_get_message_id(PW3270Dbus *object, DBusGMethodInvocation *context); |
| 94 | void pw3270_dbus_get_connection_state(PW3270Dbus *object, DBusGMethodInvocation *context); | 95 | void pw3270_dbus_get_connection_state(PW3270Dbus *object, DBusGMethodInvocation *context); |
| 95 | void pw3270_dbus_get_secure_state(PW3270Dbus *object, DBusGMethodInvocation *context); | 96 | void pw3270_dbus_get_secure_state(PW3270Dbus *object, DBusGMethodInvocation *context); |
| 96 | 97 | ||
| 97 | - void pw3270_dbus_get_screen_contents(PW3270Dbus *object, DBusGMethodInvocation *context); | ||
| 98 | H3270 * pw3270_dbus_get_session_handle(PW3270Dbus *object); | 98 | H3270 * pw3270_dbus_get_session_handle(PW3270Dbus *object); |
| 99 | GError * pw3270_dbus_get_error_from_errno(int code); | 99 | GError * pw3270_dbus_get_error_from_errno(int code); |
| 100 | 100 |
src/session.c
| @@ -31,8 +31,40 @@ | @@ -31,8 +31,40 @@ | ||
| 31 | 31 | ||
| 32 | /*---[ Implement ]----------------------------------------------------------------------------------*/ | 32 | /*---[ Implement ]----------------------------------------------------------------------------------*/ |
| 33 | 33 | ||
| 34 | -static GList * sessions = NULL; ///< @brief Lista de sessões ativas. | ||
| 35 | -static time_t maxidle = 300; | 34 | +static GList * sessions = NULL; ///< @brief Lista de sessões ativas. |
| 35 | + | ||
| 36 | +struct session *find_by_h3270(H3270 *host) { | ||
| 37 | + | ||
| 38 | + GList * it; | ||
| 39 | + | ||
| 40 | + for(it = g_list_first(sessions); it != NULL; it = g_list_next(it)) { | ||
| 41 | + | ||
| 42 | + if( ((struct session *) it->data)->host == host) { | ||
| 43 | + return (struct session *) it->data; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + return NULL; | ||
| 49 | +} | ||
| 50 | + | ||
| 51 | + | ||
| 52 | +void on_connect(H3270 *hSession, int state, void *none) { | ||
| 53 | + | ||
| 54 | + struct session *ses = find_by_h3270(hSession); | ||
| 55 | + | ||
| 56 | + if(!ses) { | ||
| 57 | + return; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + ses->activity = time(0); | ||
| 61 | + ses->timeout = state ? ses->maxidle : ses->autoclose; | ||
| 62 | + | ||
| 63 | +#ifdef DEBUG | ||
| 64 | + g_message("Session %p-%u is %s (timeout=%u)",ses,ses->id,state ? "connected" : "disconnected",(unsigned int) ses->timeout); | ||
| 65 | +#endif // DEBUG | ||
| 66 | + | ||
| 67 | +} | ||
| 36 | 68 | ||
| 37 | struct session * session_new() { | 69 | struct session * session_new() { |
| 38 | 70 | ||
| @@ -42,10 +74,15 @@ struct session * session_new() { | @@ -42,10 +74,15 @@ struct session * session_new() { | ||
| 42 | 74 | ||
| 43 | rc->id = ++id; | 75 | rc->id = ++id; |
| 44 | rc->activity = time(0); | 76 | rc->activity = time(0); |
| 77 | + rc->timeout = 600; | ||
| 78 | + rc->maxidle = 600; | ||
| 79 | + rc->autoclose = 60; | ||
| 45 | rc->host = lib3270_session_new(""); | 80 | rc->host = lib3270_session_new(""); |
| 46 | 81 | ||
| 47 | sessions = g_list_append(sessions,rc); | 82 | sessions = g_list_append(sessions,rc); |
| 48 | 83 | ||
| 84 | + lib3270_register_schange(rc->host, LIB3270_STATE_CONNECT, (void (*)(H3270 *, int, void *)) on_connect, rc); | ||
| 85 | + | ||
| 49 | return rc; | 86 | return rc; |
| 50 | 87 | ||
| 51 | }; | 88 | }; |
| @@ -84,15 +121,18 @@ void session_destroy(struct session *ses) { | @@ -84,15 +121,18 @@ void session_destroy(struct session *ses) { | ||
| 84 | 121 | ||
| 85 | void session_check_for_timeout(void) { | 122 | void session_check_for_timeout(void) { |
| 86 | 123 | ||
| 87 | - time_t timeout = time(NULL) - maxidle; | ||
| 88 | GList * it; | 124 | GList * it; |
| 89 | 125 | ||
| 90 | for(it = g_list_first(sessions); it != NULL; it = g_list_next(it)) { | 126 | for(it = g_list_first(sessions); it != NULL; it = g_list_next(it)) { |
| 91 | 127 | ||
| 92 | struct session *ses = (struct session *) it->data; | 128 | struct session *ses = (struct session *) it->data; |
| 93 | 129 | ||
| 94 | - if( ses->activity < timeout) { | 130 | + if( ses->timeout && (ses->activity + ses->timeout) < time(NULL) ) { |
| 131 | +#ifdef DEBUG | ||
| 132 | + g_message("Closing IDLE session %p-%u (idle=%u)",ses,ses->id,(unsigned int) (time(NULL) - ses->activity)); | ||
| 133 | +#else | ||
| 95 | g_message("Closing IDLE session %p-%u",ses,ses->id); | 134 | g_message("Closing IDLE session %p-%u",ses,ses->id); |
| 135 | +#endif // DEBUG | ||
| 96 | session_destroy(ses); | 136 | session_destroy(ses); |
| 97 | break; | 137 | break; |
| 98 | } | 138 | } |