From 423b757c15a7ee486b678697f88372fc2b27ddd8 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 18 Sep 2019 15:15:59 -0300 Subject: [PATCH] Small adjustments in the toggle API. --- src/core/toggles/getset.c | 14 ++++++++------ src/include/lib3270/toggle.h | 24 +++++++++++++----------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/core/toggles/getset.c b/src/core/toggles/getset.c index 5a701de..ac869a0 100644 --- a/src/core/toggles/getset.c +++ b/src/core/toggles/getset.c @@ -41,14 +41,15 @@ /*---[ Implement ]------------------------------------------------------------------------------------------------------------*/ -LIB3270_EXPORT unsigned char lib3270_get_toggle(H3270 *session, LIB3270_TOGGLE ix) +LIB3270_EXPORT unsigned char lib3270_get_toggle(const H3270 *hSession, LIB3270_TOGGLE ix) { - CHECK_SESSION_HANDLE(session); - if(ix < 0 || ix >= LIB3270_TOGGLE_COUNT) + if(ix < 0 || ix >= LIB3270_TOGGLE_COUNT) { + errno = EINVAL; return 0; + } - return session->toggle[ix].value != 0; + return hSession->toggle[ix].value != 0; } /** @@ -107,8 +108,9 @@ LIB3270_EXPORT int lib3270_toggle(H3270 *session, LIB3270_TOGGLE ix) CHECK_SESSION_HANDLE(session); - if(ix < 0 || ix >= LIB3270_TOGGLE_COUNT) - return 0; + if(ix < 0 || ix >= LIB3270_TOGGLE_COUNT) { + return -(errno = EINVAL); + } t = &session->toggle[ix]; diff --git a/src/include/lib3270/toggle.h b/src/include/lib3270/toggle.h index ff5d830..dc752ed 100644 --- a/src/include/lib3270/toggle.h +++ b/src/include/lib3270/toggle.h @@ -58,27 +58,27 @@ /** * @brief get toggle state. * - * @param h Session handle. - * @param ix Toggle id. + * @param hSession Session handle. + * @param ix Toggle id. * * @return 0 if the toggle is disabled, non zero if enabled. * */ - LIB3270_EXPORT unsigned char lib3270_get_toggle(H3270 *h, LIB3270_TOGGLE ix); + LIB3270_EXPORT unsigned char lib3270_get_toggle(const H3270 *hSession, LIB3270_TOGGLE ix); /** * @brief Set toggle state. * - * @param h Session handle. - * @param ix Toggle id. - * @param value New toggle state (non zero for true). + * @param hSession Session handle. + * @param ix Toggle id. + * @param value New toggle state (non zero for true). * * @returns 0 if the toggle is already at the state, 1 if the toggle was changed; < 0 on error (sets errno). * * @retval -EINVAL Invalid toggle id. * */ - LIB3270_EXPORT int lib3270_set_toggle(H3270 *h, LIB3270_TOGGLE ix, int value); + LIB3270_EXPORT int lib3270_set_toggle(H3270 *hSession, LIB3270_TOGGLE ix, int value); /** * @brief Translate a string toggle name to the corresponding value. @@ -127,12 +127,14 @@ /** * @brief Revert toggle status. * - * @param h Session handle. - * @param ix Toggle id. + * @param hSession Session handle. + * @param ix Toggle id. * - * @return Toggle status. + * @returns 0 if the toggle is already at the state, 1 if the toggle was changed; < 0 on error (sets errno). + * + * @retval -EINVAL Invalid toggle id. */ - LIB3270_EXPORT int lib3270_toggle(H3270 *h, LIB3270_TOGGLE ix); + LIB3270_EXPORT int lib3270_toggle(H3270 *hSession, LIB3270_TOGGLE ix); LIB3270_EXPORT const void * lib3270_register_toggle_listener(H3270 *hSession, LIB3270_TOGGLE tx, void (*func)(H3270 *, LIB3270_TOGGLE, char, void *),void *data); LIB3270_EXPORT int lib3270_unregister_toggle_listener(H3270 *hSession, LIB3270_TOGGLE tx, const void *id); -- libgit2 0.21.2