1 #include "stg/GetRequest-PDU.h"
2 #include "stg/GetResponse-PDU.h"
3 #include "stg/VarBindList.h"
4 #include "stg/VarBind.h"
6 #include "stg/common.h"
11 bool SMUX::CloseHandler(const SMUX_PDUs_t * pdus)
13 printfd(__FILE__, "SMUX::CloseHandler()\n");
14 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
18 bool SMUX::RegisterResponseHandler(const SMUX_PDUs_t * pdus)
20 printfd(__FILE__, "SMUX::RegisterResponseHandler()\n");
21 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
25 bool SMUX::PDUsRequestHandler(const SMUX_PDUs_t * pdus)
27 printfd(__FILE__, "SMUX::PDUsRequestHandler()\n");
28 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
29 PDUsHandlers::iterator it;
30 it = pdusHandlers.find(pdus->choice.pdus.present);
31 if (it != pdusHandlers.end())
33 return (this->*(it->second))(&pdus->choice.pdus);
37 switch (pdus->present)
40 printfd(__FILE__, "SMUX::PDUsRequestHandler() - nothing\n");
42 case PDUs_PR_get_response:
43 printfd(__FILE__, "SMUX::PDUsRequestHandler() - get response\n");
46 printfd(__FILE__, "SMUX::PDUsRequestHandler() - trap\n");
49 printfd(__FILE__, "SMUX::PDUsRequestHandler() - undefined\n");
55 bool SMUX::CommitOrRollbackHandler(const SMUX_PDUs_t * pdus)
57 printfd(__FILE__, "SMUX::CommitOrRollbackHandler()\n");
58 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
62 bool SMUX::GetRequestHandler(const PDUs_t * pdus)
64 printfd(__FILE__, "SMUX::GetRequestHandler()\n");
65 asn_fprint(stderr, &asn_DEF_PDUs, pdus);
66 const GetRequest_PDU_t * getRequest = &pdus->choice.get_request;
67 GetResponse_PDU_t msg;
68 VarBindList_t * varBindList = &msg.variable_bindings;
69 memset(&msg, 0, sizeof(msg));
71 msg.request_id = getRequest->request_id;
72 asn_long2INTEGER(&msg.error_status, 0);
73 asn_long2INTEGER(&msg.error_index, 0);
75 const VarBindList_t * vbl = &getRequest->variable_bindings;
76 for (int i = 0; i < vbl->list.count; ++i)
78 VarBind_t * vb = getRequest->variable_bindings.list.array[i];
80 it = sensors.find(OID(&vb->name));
81 if (it == sensors.end())
83 SendGetResponseErrorPDU(sock, getRequest,
84 PDU__error_status_noSuchName, i);
89 memset(&newVb, 0, sizeof(newVb));
91 newVb.name = vb->name;
92 it->second->GetValue(&newVb.value);
94 ASN_SEQUENCE_ADD(varBindList, &newVb);
97 SendGetResponsePDU(sock, &msg);
98 asn_fprint(stderr, &asn_DEF_PDU, &msg);
102 bool SMUX::GetNextRequestHandler(const PDUs_t * pdus)
104 printfd(__FILE__, "SMUX::GetNextRequestHandler()\n");
105 asn_fprint(stderr, &asn_DEF_PDUs, pdus);
106 const GetRequest_PDU_t * getRequest = &pdus->choice.get_request;
107 GetResponse_PDU_t msg;
108 VarBindList_t * varBindList = &msg.variable_bindings;
109 memset(&msg, 0, sizeof(msg));
111 msg.request_id = getRequest->request_id;
112 asn_long2INTEGER(&msg.error_status, 0);
113 asn_long2INTEGER(&msg.error_index, 0);
115 const VarBindList_t * vbl = &getRequest->variable_bindings;
116 for (int i = 0; i < vbl->list.count; ++i)
118 VarBind_t * vb = getRequest->variable_bindings.list.array[i];
119 Sensors::iterator it;
120 it = sensors.upper_bound(OID(&vb->name));
121 if (it == sensors.end())
123 SendGetResponseErrorPDU(sock, getRequest,
124 PDU__error_status_noSuchName, i);
129 memset(&newVb, 0, sizeof(newVb));
131 newVb.name = vb->name;
132 it->second->GetValue(&newVb.value);
134 ASN_SEQUENCE_ADD(varBindList, &newVb);
137 SendGetResponsePDU(sock, &msg);
138 asn_fprint(stderr, &asn_DEF_PDU, &msg);
142 bool SMUX::SetRequestHandler(const PDUs_t * pdus)
144 printfd(__FILE__, "SMUX::SetRequestHandler()\n");
145 asn_fprint(stderr, &asn_DEF_PDUs, pdus);
146 SendGetResponseErrorPDU(sock, &pdus->choice.set_request,
147 PDU__error_status_readOnly, 0);