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 return SendGetResponseErrorPDU(sock, getRequest,
115 PDU__error_status_noSuchName, i);
118 VarBind_t * newVb = static_cast<VarBind_t *>(calloc(1, sizeof(VarBind_t)));
119 assert(newVb && "Enought mempry to allocate VarBind_t");
121 it->first.ToOID(&newVb->name);
122 it->second->GetValue(&newVb->value);
124 ASN_SEQUENCE_ADD(varBindList, newVb);
127 bool res = SendGetResponsePDU(sock, msg);
129 asn_fprint(stderr, &asn_DEF_GetResponse_PDU, msg);
131 ASN_STRUCT_FREE(asn_DEF_GetResponse_PDU, msg);
135 bool SMUX::GetNextRequestHandler(const PDUs_t * pdus)
138 printfd(__FILE__, "SMUX::GetNextRequestHandler()\n");
139 asn_fprint(stderr, &asn_DEF_PDUs, pdus);
141 const GetRequest_PDU_t * getRequest = &pdus->choice.get_request;
142 GetResponse_PDU_t * msg = static_cast<GetResponse_PDU_t *>(calloc(1, sizeof(GetResponse_PDU_t)));
143 assert(msg && "Enought mempry to allocate GetResponse_PDU_t");
144 VarBindList_t * varBindList = &msg->variable_bindings;
147 asn_INTEGER2long(&getRequest->request_id, &id);
148 asn_long2INTEGER(&msg->request_id, id);
149 asn_long2INTEGER(&msg->error_status, 0);
150 asn_long2INTEGER(&msg->error_index, 0);
152 const VarBindList_t * vbl = &getRequest->variable_bindings;
153 for (int i = 0; i < vbl->list.count; ++i)
155 VarBind_t * vb = getRequest->variable_bindings.list.array[i];
156 Sensors::iterator it;
157 it = sensors.upper_bound(OID(&vb->name));
158 if (it == sensors.end())
161 printfd(__FILE__, "SMUX::GetNextRequestHandler() - '%s' not found\n", OID(&vb->name).ToString().c_str());
163 return SendGetResponseErrorPDU(sock, getRequest,
164 PDU__error_status_noSuchName, i);
167 VarBind_t * newVb = static_cast<VarBind_t *>(calloc(1, sizeof(VarBind_t)));
168 assert(newVb && "Enought mempry to allocate VarBind_t");
170 it->first.ToOID(&newVb->name);
171 it->second->GetValue(&newVb->value);
173 ASN_SEQUENCE_ADD(varBindList, newVb);
176 bool res = SendGetResponsePDU(sock, msg);
178 asn_fprint(stderr, &asn_DEF_PDU, msg);
180 ASN_STRUCT_FREE(asn_DEF_GetResponse_PDU, msg);
184 bool SMUX::SetRequestHandler(const PDUs_t * pdus)
187 printfd(__FILE__, "SMUX::SetRequestHandler()\n");
188 asn_fprint(stderr, &asn_DEF_PDUs, pdus);
190 return SendGetResponseErrorPDU(sock, &pdus->choice.set_request,
191 PDU__error_status_readOnly, 0);