4 #include "stg/common.h"
6 #pragma GCC diagnostic push
7 #pragma GCC diagnostic ignored "-Wold-style-cast"
8 #include "stg/GetRequest-PDU.h"
9 #include "stg/GetResponse-PDU.h"
10 #include "stg/VarBindList.h"
11 #include "stg/VarBind.h"
12 #pragma GCC diagnostic pop
19 bool SMUX::CloseHandler(const SMUX_PDUs_t * pdus)
21 printfd(__FILE__, "SMUX::CloseHandler()\n");
22 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
26 bool SMUX::CloseHandler(const SMUX_PDUs_t *)
33 bool SMUX::RegisterResponseHandler(const SMUX_PDUs_t * pdus)
35 printfd(__FILE__, "SMUX::RegisterResponseHandler()\n");
36 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
40 bool SMUX::RegisterResponseHandler(const SMUX_PDUs_t *)
46 bool SMUX::PDUsRequestHandler(const SMUX_PDUs_t * pdus)
49 printfd(__FILE__, "SMUX::PDUsRequestHandler()\n");
50 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
52 PDUsHandlers::iterator it(pdusHandlers.find(pdus->choice.pdus.present));
53 if (it != pdusHandlers.end())
55 return (this->*(it->second))(&pdus->choice.pdus);
60 switch (pdus->present)
63 printfd(__FILE__, "SMUX::PDUsRequestHandler() - nothing\n");
65 case PDUs_PR_get_response:
66 printfd(__FILE__, "SMUX::PDUsRequestHandler() - get response\n");
69 printfd(__FILE__, "SMUX::PDUsRequestHandler() - trap\n");
72 printfd(__FILE__, "SMUX::PDUsRequestHandler() - undefined\n");
80 bool SMUX::CommitOrRollbackHandler(const SMUX_PDUs_t * pdus)
82 printfd(__FILE__, "SMUX::CommitOrRollbackHandler()\n");
83 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
87 bool SMUX::CommitOrRollbackHandler(const SMUX_PDUs_t *)
93 bool SMUX::GetRequestHandler(const PDUs_t * pdus)
96 printfd(__FILE__, "SMUX::GetRequestHandler()\n");
97 asn_fprint(stderr, &asn_DEF_PDUs, pdus);
99 const GetRequest_PDU_t * getRequest = &pdus->choice.get_request;
100 GetResponse_PDU_t * msg = static_cast<GetResponse_PDU_t *>(calloc(1, sizeof(GetResponse_PDU_t)));
101 assert(msg && "Enought mempry to allocate GetResponse_PDU_t");
102 VarBindList_t * varBindList = &msg->variable_bindings;
105 asn_INTEGER2long(&getRequest->request_id, &id);
106 asn_long2INTEGER(&msg->request_id, id);
107 asn_long2INTEGER(&msg->error_status, 0);
108 asn_long2INTEGER(&msg->error_index, 0);
110 const VarBindList_t * vbl = &getRequest->variable_bindings;
111 for (int i = 0; i < vbl->list.count; ++i)
113 VarBind_t * vb = getRequest->variable_bindings.list.array[i];
114 Sensors::iterator it;
115 it = sensors.find(OID(&vb->name));
116 if (it == sensors.end())
118 return SendGetResponseErrorPDU(sock, getRequest,
119 PDU__error_status_noSuchName, i);
122 VarBind_t * newVb = static_cast<VarBind_t *>(calloc(1, sizeof(VarBind_t)));
123 assert(newVb && "Enought mempry to allocate VarBind_t");
125 it->first.ToOID(&newVb->name);
126 it->second->GetValue(&newVb->value);
128 ASN_SEQUENCE_ADD(varBindList, newVb);
131 bool res = SendGetResponsePDU(sock, msg);
133 asn_fprint(stderr, &asn_DEF_GetResponse_PDU, msg);
135 ASN_STRUCT_FREE(asn_DEF_GetResponse_PDU, msg);
139 bool SMUX::GetNextRequestHandler(const PDUs_t * pdus)
142 printfd(__FILE__, "SMUX::GetNextRequestHandler()\n");
143 asn_fprint(stderr, &asn_DEF_PDUs, pdus);
145 const GetRequest_PDU_t * getRequest = &pdus->choice.get_request;
146 GetResponse_PDU_t * msg = static_cast<GetResponse_PDU_t *>(calloc(1, sizeof(GetResponse_PDU_t)));
147 assert(msg && "Enought mempry to allocate GetResponse_PDU_t");
148 VarBindList_t * varBindList = &msg->variable_bindings;
151 asn_INTEGER2long(&getRequest->request_id, &id);
152 asn_long2INTEGER(&msg->request_id, id);
153 asn_long2INTEGER(&msg->error_status, 0);
154 asn_long2INTEGER(&msg->error_index, 0);
156 const VarBindList_t * vbl = &getRequest->variable_bindings;
157 for (int i = 0; i < vbl->list.count; ++i)
159 VarBind_t * vb = getRequest->variable_bindings.list.array[i];
160 Sensors::iterator it;
161 it = sensors.upper_bound(OID(&vb->name));
162 if (it == sensors.end())
165 printfd(__FILE__, "SMUX::GetNextRequestHandler() - '%s' not found\n", OID(&vb->name).ToString().c_str());
167 return SendGetResponseErrorPDU(sock, getRequest,
168 PDU__error_status_noSuchName, i);
171 VarBind_t * newVb = static_cast<VarBind_t *>(calloc(1, sizeof(VarBind_t)));
172 assert(newVb && "Enought mempry to allocate VarBind_t");
174 it->first.ToOID(&newVb->name);
175 it->second->GetValue(&newVb->value);
177 ASN_SEQUENCE_ADD(varBindList, newVb);
180 bool res = SendGetResponsePDU(sock, msg);
182 asn_fprint(stderr, &asn_DEF_PDU, msg);
184 ASN_STRUCT_FREE(asn_DEF_GetResponse_PDU, msg);
188 bool SMUX::SetRequestHandler(const PDUs_t * pdus)
191 printfd(__FILE__, "SMUX::SetRequestHandler()\n");
192 asn_fprint(stderr, &asn_DEF_PDUs, pdus);
194 return SendGetResponseErrorPDU(sock, &pdus->choice.set_request,
195 PDU__error_status_readOnly, 0);