X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/7df9dd832a325848a509b8a6ab4036c1ea96971c..5e7cbf1bbd282c0b18a09c5e77e237a4e20f6e32:/projects/stargazer/plugins/other/smux/handlers.cpp?ds=inline diff --git a/projects/stargazer/plugins/other/smux/handlers.cpp b/projects/stargazer/plugins/other/smux/handlers.cpp index 5f25a82f..ac179da9 100644 --- a/projects/stargazer/plugins/other/smux/handlers.cpp +++ b/projects/stargazer/plugins/other/smux/handlers.cpp @@ -10,30 +10,46 @@ #include "utils.h" #include "smux.h" +#ifdef SMUX_DEBUG bool SMUX::CloseHandler(const SMUX_PDUs_t * pdus) { printfd(__FILE__, "SMUX::CloseHandler()\n"); asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus); -return false; +return true; } +#else +bool SMUX::CloseHandler(const SMUX_PDUs_t *) +{ +return true; +} +#endif +#ifdef SMUX_DEBUG bool SMUX::RegisterResponseHandler(const SMUX_PDUs_t * pdus) { printfd(__FILE__, "SMUX::RegisterResponseHandler()\n"); asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus); -return false; +return true; +} +#else +bool SMUX::RegisterResponseHandler(const SMUX_PDUs_t *) +{ +return true; } +#endif bool SMUX::PDUsRequestHandler(const SMUX_PDUs_t * pdus) { +#ifdef SMUX_DEBUG printfd(__FILE__, "SMUX::PDUsRequestHandler()\n"); asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus); -PDUsHandlers::iterator it; -it = pdusHandlers.find(pdus->choice.pdus.present); +#endif +PDUsHandlers::iterator it(pdusHandlers.find(pdus->choice.pdus.present)); if (it != pdusHandlers.end()) { return (this->*(it->second))(&pdus->choice.pdus); } +#ifdef SMUX_DEBUG else { switch (pdus->present) @@ -51,20 +67,30 @@ else printfd(__FILE__, "SMUX::PDUsRequestHandler() - undefined\n"); } } -return false; +#endif +return true; } +#ifdef SMUX_DEBUG bool SMUX::CommitOrRollbackHandler(const SMUX_PDUs_t * pdus) { printfd(__FILE__, "SMUX::CommitOrRollbackHandler()\n"); asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus); -return false; +return true; +} +#else +bool SMUX::CommitOrRollbackHandler(const SMUX_PDUs_t *) +{ +return true; } +#endif bool SMUX::GetRequestHandler(const PDUs_t * pdus) { +#ifdef SMUX_DEBUG printfd(__FILE__, "SMUX::GetRequestHandler()\n"); asn_fprint(stderr, &asn_DEF_PDUs, pdus); +#endif const GetRequest_PDU_t * getRequest = &pdus->choice.get_request; GetResponse_PDU_t * msg = static_cast(calloc(1, sizeof(GetResponse_PDU_t))); assert(msg && "Enought mempry to allocate GetResponse_PDU_t"); @@ -84,9 +110,8 @@ for (int i = 0; i < vbl->list.count; ++i) it = sensors.find(OID(&vb->name)); if (it == sensors.end()) { - SendGetResponseErrorPDU(sock, getRequest, - PDU__error_status_noSuchName, i); - return true; + return SendGetResponseErrorPDU(sock, getRequest, + PDU__error_status_noSuchName, i); } VarBind_t * newVb = static_cast(calloc(1, sizeof(VarBind_t))); @@ -98,16 +123,20 @@ for (int i = 0; i < vbl->list.count; ++i) ASN_SEQUENCE_ADD(varBindList, newVb); } -SendGetResponsePDU(sock, msg); +bool res = SendGetResponsePDU(sock, msg); +#ifdef SMUX_DEBUG asn_fprint(stderr, &asn_DEF_GetResponse_PDU, msg); +#endif ASN_STRUCT_FREE(asn_DEF_GetResponse_PDU, msg); -return false; +return res; } bool SMUX::GetNextRequestHandler(const PDUs_t * pdus) { +#ifdef SMUX_DEBUG printfd(__FILE__, "SMUX::GetNextRequestHandler()\n"); asn_fprint(stderr, &asn_DEF_PDUs, pdus); +#endif const GetRequest_PDU_t * getRequest = &pdus->choice.get_request; GetResponse_PDU_t * msg = static_cast(calloc(1, sizeof(GetResponse_PDU_t))); assert(msg && "Enought mempry to allocate GetResponse_PDU_t"); @@ -127,10 +156,11 @@ for (int i = 0; i < vbl->list.count; ++i) it = sensors.upper_bound(OID(&vb->name)); if (it == sensors.end()) { +#ifdef SMUX_DEBUG printfd(__FILE__, "SMUX::GetNextRequestHandler() - '%s' not found\n", OID(&vb->name).ToString().c_str()); - SendGetResponseErrorPDU(sock, getRequest, - PDU__error_status_noSuchName, i); - return true; +#endif + return SendGetResponseErrorPDU(sock, getRequest, + PDU__error_status_noSuchName, i); } VarBind_t * newVb = static_cast(calloc(1, sizeof(VarBind_t))); @@ -142,17 +172,20 @@ for (int i = 0; i < vbl->list.count; ++i) ASN_SEQUENCE_ADD(varBindList, newVb); } -SendGetResponsePDU(sock, msg); +bool res = SendGetResponsePDU(sock, msg); +#ifdef SMUX_DEBUG asn_fprint(stderr, &asn_DEF_PDU, msg); +#endif ASN_STRUCT_FREE(asn_DEF_GetResponse_PDU, msg); -return false; +return res; } bool SMUX::SetRequestHandler(const PDUs_t * pdus) { +#ifdef SMUX_DEBUG printfd(__FILE__, "SMUX::SetRequestHandler()\n"); asn_fprint(stderr, &asn_DEF_PDUs, pdus); -SendGetResponseErrorPDU(sock, &pdus->choice.set_request, - PDU__error_status_readOnly, 0); -return false; +#endif +return SendGetResponseErrorPDU(sock, &pdus->choice.set_request, + PDU__error_status_readOnly, 0); }