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"
16 bool SMUX::CloseHandler(const SMUX_PDUs_t * pdus)
18 printfd(__FILE__, "SMUX::CloseHandler()\n");
19 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
23 bool SMUX::CloseHandler(const SMUX_PDUs_t *)
30 bool SMUX::RegisterResponseHandler(const SMUX_PDUs_t * pdus)
32 printfd(__FILE__, "SMUX::RegisterResponseHandler()\n");
33 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
37 bool SMUX::RegisterResponseHandler(const SMUX_PDUs_t *)
43 bool SMUX::PDUsRequestHandler(const SMUX_PDUs_t * pdus)
46 printfd(__FILE__, "SMUX::PDUsRequestHandler()\n");
47 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
49 PDUsHandlers::iterator it(pdusHandlers.find(pdus->choice.pdus.present));
50 if (it != pdusHandlers.end())
52 return (this->*(it->second))(&pdus->choice.pdus);
57 switch (pdus->present)
60 printfd(__FILE__, "SMUX::PDUsRequestHandler() - nothing\n");
62 case PDUs_PR_get_response:
63 printfd(__FILE__, "SMUX::PDUsRequestHandler() - get response\n");
66 printfd(__FILE__, "SMUX::PDUsRequestHandler() - trap\n");
69 printfd(__FILE__, "SMUX::PDUsRequestHandler() - undefined\n");
77 bool SMUX::CommitOrRollbackHandler(const SMUX_PDUs_t * pdus)
79 printfd(__FILE__, "SMUX::CommitOrRollbackHandler()\n");
80 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
84 bool SMUX::CommitOrRollbackHandler(const SMUX_PDUs_t *)
90 bool SMUX::GetRequestHandler(const PDUs_t * pdus)
93 printfd(__FILE__, "SMUX::GetRequestHandler()\n");
94 asn_fprint(stderr, &asn_DEF_PDUs, pdus);
96 const GetRequest_PDU_t * getRequest = &pdus->choice.get_request;
97 GetResponse_PDU_t * msg = static_cast<GetResponse_PDU_t *>(calloc(1, sizeof(GetResponse_PDU_t)));
98 assert(msg && "Enought mempry to allocate GetResponse_PDU_t");
99 VarBindList_t * varBindList = &msg->variable_bindings;
102 asn_INTEGER2long(&getRequest->request_id, &id);
103 asn_long2INTEGER(&msg->request_id, id);
104 asn_long2INTEGER(&msg->error_status, 0);
105 asn_long2INTEGER(&msg->error_index, 0);
107 const VarBindList_t * vbl = &getRequest->variable_bindings;
108 for (int i = 0; i < vbl->list.count; ++i)
110 VarBind_t * vb = getRequest->variable_bindings.list.array[i];
111 Sensors::iterator it;
112 it = sensors.find(OID(&vb->name));
113 if (it == sensors.end())
115 return SendGetResponseErrorPDU(sock, getRequest,
116 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 bool res = 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 return SendGetResponseErrorPDU(sock, getRequest,
165 PDU__error_status_noSuchName, i);
168 VarBind_t * newVb = static_cast<VarBind_t *>(calloc(1, sizeof(VarBind_t)));
169 assert(newVb && "Enought mempry to allocate VarBind_t");
171 it->first.ToOID(&newVb->name);
172 it->second->GetValue(&newVb->value);
174 ASN_SEQUENCE_ADD(varBindList, newVb);
177 bool res = SendGetResponsePDU(sock, msg);
179 asn_fprint(stderr, &asn_DEF_PDU, msg);
181 ASN_STRUCT_FREE(asn_DEF_GetResponse_PDU, msg);
185 bool SMUX::SetRequestHandler(const PDUs_t * pdus)
188 printfd(__FILE__, "SMUX::SetRequestHandler()\n");
189 asn_fprint(stderr, &asn_DEF_PDUs, pdus);
191 return SendGetResponseErrorPDU(sock, &pdus->choice.set_request,
192 PDU__error_status_readOnly, 0);