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(pdusHandlers.find(pdus->choice.pdus.present));
48 if (it != pdusHandlers.end())
50 return (this->*(it->second))(&pdus->choice.pdus);
55 switch (pdus->present)
58 printfd(__FILE__, "SMUX::PDUsRequestHandler() - nothing\n");
60 case PDUs_PR_get_response:
61 printfd(__FILE__, "SMUX::PDUsRequestHandler() - get response\n");
64 printfd(__FILE__, "SMUX::PDUsRequestHandler() - trap\n");
67 printfd(__FILE__, "SMUX::PDUsRequestHandler() - undefined\n");
75 bool SMUX::CommitOrRollbackHandler(const SMUX_PDUs_t * pdus)
77 printfd(__FILE__, "SMUX::CommitOrRollbackHandler()\n");
78 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
82 bool SMUX::CommitOrRollbackHandler(const SMUX_PDUs_t *)
88 bool SMUX::GetRequestHandler(const PDUs_t * pdus)
91 printfd(__FILE__, "SMUX::GetRequestHandler()\n");
92 asn_fprint(stderr, &asn_DEF_PDUs, pdus);
94 const GetRequest_PDU_t * getRequest = &pdus->choice.get_request;
95 GetResponse_PDU_t * msg = static_cast<GetResponse_PDU_t *>(calloc(1, sizeof(GetResponse_PDU_t)));
96 assert(msg && "Enought mempry to allocate GetResponse_PDU_t");
97 VarBindList_t * varBindList = &msg->variable_bindings;
100 asn_INTEGER2long(&getRequest->request_id, &id);
101 asn_long2INTEGER(&msg->request_id, id);
102 asn_long2INTEGER(&msg->error_status, 0);
103 asn_long2INTEGER(&msg->error_index, 0);
105 const VarBindList_t * vbl = &getRequest->variable_bindings;
106 for (int i = 0; i < vbl->list.count; ++i)
108 VarBind_t * vb = getRequest->variable_bindings.list.array[i];
109 Sensors::iterator it;
110 it = sensors.find(OID(&vb->name));
111 if (it == sensors.end())
113 return SendGetResponseErrorPDU(sock, getRequest,
114 PDU__error_status_noSuchName, i);
117 VarBind_t * newVb = static_cast<VarBind_t *>(calloc(1, sizeof(VarBind_t)));
118 assert(newVb && "Enought mempry to allocate VarBind_t");
120 it->first.ToOID(&newVb->name);
121 it->second->GetValue(&newVb->value);
123 ASN_SEQUENCE_ADD(varBindList, newVb);
126 bool res = SendGetResponsePDU(sock, msg);
128 asn_fprint(stderr, &asn_DEF_GetResponse_PDU, msg);
130 ASN_STRUCT_FREE(asn_DEF_GetResponse_PDU, msg);
134 bool SMUX::GetNextRequestHandler(const PDUs_t * pdus)
137 printfd(__FILE__, "SMUX::GetNextRequestHandler()\n");
138 asn_fprint(stderr, &asn_DEF_PDUs, pdus);
140 const GetRequest_PDU_t * getRequest = &pdus->choice.get_request;
141 GetResponse_PDU_t * msg = static_cast<GetResponse_PDU_t *>(calloc(1, sizeof(GetResponse_PDU_t)));
142 assert(msg && "Enought mempry to allocate GetResponse_PDU_t");
143 VarBindList_t * varBindList = &msg->variable_bindings;
146 asn_INTEGER2long(&getRequest->request_id, &id);
147 asn_long2INTEGER(&msg->request_id, id);
148 asn_long2INTEGER(&msg->error_status, 0);
149 asn_long2INTEGER(&msg->error_index, 0);
151 const VarBindList_t * vbl = &getRequest->variable_bindings;
152 for (int i = 0; i < vbl->list.count; ++i)
154 VarBind_t * vb = getRequest->variable_bindings.list.array[i];
155 Sensors::iterator it;
156 it = sensors.upper_bound(OID(&vb->name));
157 if (it == sensors.end())
160 printfd(__FILE__, "SMUX::GetNextRequestHandler() - '%s' not found\n", OID(&vb->name).ToString().c_str());
162 return SendGetResponseErrorPDU(sock, getRequest,
163 PDU__error_status_noSuchName, i);
166 VarBind_t * newVb = static_cast<VarBind_t *>(calloc(1, sizeof(VarBind_t)));
167 assert(newVb && "Enought mempry to allocate VarBind_t");
169 it->first.ToOID(&newVb->name);
170 it->second->GetValue(&newVb->value);
172 ASN_SEQUENCE_ADD(varBindList, newVb);
175 bool res = SendGetResponsePDU(sock, msg);
177 asn_fprint(stderr, &asn_DEF_PDU, msg);
179 ASN_STRUCT_FREE(asn_DEF_GetResponse_PDU, msg);
183 bool SMUX::SetRequestHandler(const PDUs_t * pdus)
186 printfd(__FILE__, "SMUX::SetRequestHandler()\n");
187 asn_fprint(stderr, &asn_DEF_PDUs, pdus);
189 return SendGetResponseErrorPDU(sock, &pdus->choice.set_request,
190 PDU__error_status_readOnly, 0);