1 #include "asn1/OpenPDU.h"
2 #include "asn1/ClosePDU.h"
3 #include "asn1/RReqPDU.h"
4 #include "asn1/GetRequest-PDU.h"
5 #include "asn1/GetResponse-PDU.h"
6 #include "asn1/VarBindList.h"
7 #include "asn1/VarBind.h"
8 #include "asn1/OBJECT_IDENTIFIER.h"
9 #include "asn1/ber_decoder.h"
10 #include "asn1/der_encoder.h"
12 #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::RegisterResponseHandler(const SMUX_PDUs_t * pdus)
25 printfd(__FILE__, "SMUX::RegisterResponseHandler()\n");
26 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
30 bool SMUX::PDUsHandler(const SMUX_PDUs_t * pdus)
32 printfd(__FILE__, "SMUX::PDUsHandler()\n");
33 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
34 PDUsHandlers::iterator it;
35 it = pdusHandlers.find(pdus->choice.pdus.present);
36 if (it != pdusHandlers.end())
38 return (this->*(it->second))(&pdus->choice.pdus);
42 switch (pdus->present)
45 printfd(__FILE__, "SMUX::PDUsHandler() - nothing\n");
47 case PDUs_PR_get_response:
48 printfd(__FILE__, "SMUX::PDUsHandler() - get response\n");
51 printfd(__FILE__, "SMUX::PDUsHandler() - trap\n");
54 printfd(__FILE__, "SMUX::PDUsHandler() - undefined\n");
60 bool SMUX::CommitOrRollbackHandler(const SMUX_PDUs_t * pdus)
62 printfd(__FILE__, "SMUX::CommitOrRollbackHandler()\n");
63 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
67 bool SMUX::GetRequestHandler(const PDUs_t * pdus)
69 printfd(__FILE__, "SMUX::GetRequestHandler()\n");
70 asn_fprint(stderr, &asn_DEF_PDUs, pdus);
71 const GetRequest_PDU_t * getRequest = &pdus->choice.get_request;
72 GetResponse_PDU_t msg;
73 VarBindList_t * varBindList = &msg.variable_bindings;
74 memset(&msg, 0, sizeof(msg));
76 msg.request_id = getRequest->request_id;
77 asn_long2INTEGER(&msg.error_status, 0);
78 asn_long2INTEGER(&msg.error_index, 0);
80 const VarBindList_t * vbl = &getRequest->variable_bindings;
81 for (int i = 0; i < vbl->list.count; ++i)
83 VarBind_t * vb = getRequest->variable_bindings.list.array[i];
85 it = sensors.find(OI2String(&vb->name));
86 if (it == sensors.end())
88 SendGetResponseErrorPDU(sock, getRequest,
89 PDU__error_status_noSuchName, i);
94 memset(&newVb, 0, sizeof(newVb));
96 newVb.name = vb->name;
97 it->second->GetValue(&newVb.value);
99 ASN_SEQUENCE_ADD(varBindList, &newVb);
102 SendGetResponsePDU(sock, &msg);
103 asn_fprint(stderr, &asn_DEF_PDU, &msg);
107 bool SMUX::GetNextRequestHandler(const PDUs_t * pdus)
109 printfd(__FILE__, "SMUX::GetNextRequestHandler()\n");
110 asn_fprint(stderr, &asn_DEF_PDUs, pdus);
111 const GetRequest_PDU_t * getRequest = &pdus->choice.get_request;
112 GetResponse_PDU_t msg;
113 VarBindList_t * varBindList = &msg.variable_bindings;
114 memset(&msg, 0, sizeof(msg));
116 msg.request_id = getRequest->request_id;
117 asn_long2INTEGER(&msg.error_status, 0);
118 asn_long2INTEGER(&msg.error_index, 0);
120 const VarBindList_t * vbl = &getRequest->variable_bindings;
121 for (int i = 0; i < vbl->list.count; ++i)
123 VarBind_t * vb = getRequest->variable_bindings.list.array[i];
124 Sensors::iterator it;
125 it = sensors.upper_bound(OI2String(&vb->name));
126 if (it == sensors.end())
128 SendGetResponseErrorPDU(sock, getRequest,
129 PDU__error_status_noSuchName, i);
134 memset(&newVb, 0, sizeof(newVb));
136 newVb.name = vb->name;
137 it->second->GetValue(&newVb.value);
139 ASN_SEQUENCE_ADD(varBindList, &newVb);
142 SendGetResponsePDU(sock, &msg);
143 asn_fprint(stderr, &asn_DEF_PDU, &msg);
147 bool SMUX::SetRequestHandler(const PDUs_t * pdus)
149 printfd(__FILE__, "SMUX::SetRequestHandler()\n");
150 asn_fprint(stderr, &asn_DEF_PDUs, pdus);
151 SendGetResponseErrorPDU(sock, &pdus->choice.set_request,
152 PDU__error_status_readOnly, 0);