3 #include "stg/GetRequest-PDU.h"
4 #include "stg/GetResponse-PDU.h"
5 #include "stg/VarBindList.h"
6 #include "stg/VarBind.h"
8 #include "stg/common.h"
14 bool SMUX::CloseHandler(const SMUX_PDUs_t * pdus)
16 printfd(__FILE__, "SMUX::CloseHandler()\n");
17 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
21 bool SMUX::CloseHandler(const SMUX_PDUs_t *)
28 bool SMUX::RegisterResponseHandler(const SMUX_PDUs_t * pdus)
30 printfd(__FILE__, "SMUX::RegisterResponseHandler()\n");
31 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
35 bool SMUX::RegisterResponseHandler(const SMUX_PDUs_t *)
41 bool SMUX::PDUsRequestHandler(const SMUX_PDUs_t * pdus)
44 printfd(__FILE__, "SMUX::PDUsRequestHandler()\n");
45 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
47 PDUsHandlers::iterator it;
48 it = pdusHandlers.find(pdus->choice.pdus.present);
49 if (it != pdusHandlers.end())
51 return (this->*(it->second))(&pdus->choice.pdus);
56 switch (pdus->present)
59 printfd(__FILE__, "SMUX::PDUsRequestHandler() - nothing\n");
61 case PDUs_PR_get_response:
62 printfd(__FILE__, "SMUX::PDUsRequestHandler() - get response\n");
65 printfd(__FILE__, "SMUX::PDUsRequestHandler() - trap\n");
68 printfd(__FILE__, "SMUX::PDUsRequestHandler() - undefined\n");
76 bool SMUX::CommitOrRollbackHandler(const SMUX_PDUs_t * pdus)
78 printfd(__FILE__, "SMUX::CommitOrRollbackHandler()\n");
79 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
83 bool SMUX::CommitOrRollbackHandler(const SMUX_PDUs_t *)
89 bool SMUX::GetRequestHandler(const PDUs_t * pdus)
92 printfd(__FILE__, "SMUX::GetRequestHandler()\n");
93 asn_fprint(stderr, &asn_DEF_PDUs, pdus);
95 const GetRequest_PDU_t * getRequest = &pdus->choice.get_request;
96 GetResponse_PDU_t * msg = static_cast<GetResponse_PDU_t *>(calloc(1, sizeof(GetResponse_PDU_t)));
97 assert(msg && "Enought mempry to allocate GetResponse_PDU_t");
98 VarBindList_t * varBindList = &msg->variable_bindings;
101 asn_INTEGER2long(&getRequest->request_id, &id);
102 asn_long2INTEGER(&msg->request_id, id);
103 asn_long2INTEGER(&msg->error_status, 0);
104 asn_long2INTEGER(&msg->error_index, 0);
106 const VarBindList_t * vbl = &getRequest->variable_bindings;
107 for (int i = 0; i < vbl->list.count; ++i)
109 VarBind_t * vb = getRequest->variable_bindings.list.array[i];
110 Sensors::iterator it;
111 it = sensors.find(OID(&vb->name));
112 if (it == sensors.end())
114 SendGetResponseErrorPDU(sock, getRequest,
115 PDU__error_status_noSuchName, i);
119 VarBind_t * newVb = static_cast<VarBind_t *>(calloc(1, sizeof(VarBind_t)));
120 assert(newVb && "Enought mempry to allocate VarBind_t");
122 it->first.ToOID(&newVb->name);
123 it->second->GetValue(&newVb->value);
125 ASN_SEQUENCE_ADD(varBindList, newVb);
128 SendGetResponsePDU(sock, msg);
130 asn_fprint(stderr, &asn_DEF_GetResponse_PDU, msg);
132 ASN_STRUCT_FREE(asn_DEF_GetResponse_PDU, msg);
136 bool SMUX::GetNextRequestHandler(const PDUs_t * pdus)
139 printfd(__FILE__, "SMUX::GetNextRequestHandler()\n");
140 asn_fprint(stderr, &asn_DEF_PDUs, pdus);
142 const GetRequest_PDU_t * getRequest = &pdus->choice.get_request;
143 GetResponse_PDU_t * msg = static_cast<GetResponse_PDU_t *>(calloc(1, sizeof(GetResponse_PDU_t)));
144 assert(msg && "Enought mempry to allocate GetResponse_PDU_t");
145 VarBindList_t * varBindList = &msg->variable_bindings;
148 asn_INTEGER2long(&getRequest->request_id, &id);
149 asn_long2INTEGER(&msg->request_id, id);
150 asn_long2INTEGER(&msg->error_status, 0);
151 asn_long2INTEGER(&msg->error_index, 0);
153 const VarBindList_t * vbl = &getRequest->variable_bindings;
154 for (int i = 0; i < vbl->list.count; ++i)
156 VarBind_t * vb = getRequest->variable_bindings.list.array[i];
157 Sensors::iterator it;
158 it = sensors.upper_bound(OID(&vb->name));
159 if (it == sensors.end())
162 printfd(__FILE__, "SMUX::GetNextRequestHandler() - '%s' not found\n", OID(&vb->name).ToString().c_str());
164 SendGetResponseErrorPDU(sock, getRequest,
165 PDU__error_status_noSuchName, i);
169 VarBind_t * newVb = static_cast<VarBind_t *>(calloc(1, sizeof(VarBind_t)));
170 assert(newVb && "Enought mempry to allocate VarBind_t");
172 it->first.ToOID(&newVb->name);
173 it->second->GetValue(&newVb->value);
175 ASN_SEQUENCE_ADD(varBindList, newVb);
178 SendGetResponsePDU(sock, msg);
180 asn_fprint(stderr, &asn_DEF_PDU, msg);
182 ASN_STRUCT_FREE(asn_DEF_GetResponse_PDU, msg);
186 bool SMUX::SetRequestHandler(const PDUs_t * pdus)
189 printfd(__FILE__, "SMUX::SetRequestHandler()\n");
190 asn_fprint(stderr, &asn_DEF_PDUs, pdus);
192 SendGetResponseErrorPDU(sock, &pdus->choice.set_request,
193 PDU__error_status_readOnly, 0);