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 | 320 | |
| 321 | 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
src/private.h
| ... | ... | @@ -41,9 +41,12 @@ |
| 41 | 41 | #include <lib3270.h> |
| 42 | 42 | |
| 43 | 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 | 52 | G_GNUC_INTERNAL GMainLoop * main_loop; | ... | ... |
src/service.h
| ... | ... | @@ -83,18 +83,18 @@ |
| 83 | 83 | void pw3270_dbus_get_screen_height(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context); |
| 84 | 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 | 90 | void pw3270_dbus_quit(PW3270Dbus *object, DBusGMethodInvocation *context); |
| 88 | - void pw3270_dbus_connect(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context); | |
| 89 | 91 | void pw3270_dbus_get_ur_l(PW3270Dbus *object, DBusGMethodInvocation *context); |
| 90 | 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 | 94 | void pw3270_dbus_get_message_id(PW3270Dbus *object, DBusGMethodInvocation *context); |
| 94 | 95 | void pw3270_dbus_get_connection_state(PW3270Dbus *object, DBusGMethodInvocation *context); |
| 95 | 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 | 98 | H3270 * pw3270_dbus_get_session_handle(PW3270Dbus *object); |
| 99 | 99 | GError * pw3270_dbus_get_error_from_errno(int code); |
| 100 | 100 | ... | ... |
src/session.c
| ... | ... | @@ -31,8 +31,40 @@ |
| 31 | 31 | |
| 32 | 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 | 69 | struct session * session_new() { |
| 38 | 70 | |
| ... | ... | @@ -42,10 +74,15 @@ struct session * session_new() { |
| 42 | 74 | |
| 43 | 75 | rc->id = ++id; |
| 44 | 76 | rc->activity = time(0); |
| 77 | + rc->timeout = 600; | |
| 78 | + rc->maxidle = 600; | |
| 79 | + rc->autoclose = 60; | |
| 45 | 80 | rc->host = lib3270_session_new(""); |
| 46 | 81 | |
| 47 | 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 | 86 | return rc; |
| 50 | 87 | |
| 51 | 88 | }; |
| ... | ... | @@ -84,15 +121,18 @@ void session_destroy(struct session *ses) { |
| 84 | 121 | |
| 85 | 122 | void session_check_for_timeout(void) { |
| 86 | 123 | |
| 87 | - time_t timeout = time(NULL) - maxidle; | |
| 88 | 124 | GList * it; |
| 89 | 125 | |
| 90 | 126 | for(it = g_list_first(sessions); it != NULL; it = g_list_next(it)) { |
| 91 | 127 | |
| 92 | 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 | 134 | g_message("Closing IDLE session %p-%u",ses,ses->id); |
| 135 | +#endif // DEBUG | |
| 96 | 136 | session_destroy(ses); |
| 97 | 137 | break; |
| 98 | 138 | } | ... | ... |