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"
13 bool SMUX::CloseHandler(const SMUX_PDUs_t * pdus)
15 printfd(__FILE__, "SMUX::CloseHandler()\n");
16 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
20 bool SMUX::RegisterResponseHandler(const SMUX_PDUs_t * pdus)
22 printfd(__FILE__, "SMUX::RegisterResponseHandler()\n");
23 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
27 bool SMUX::PDUsRequestHandler(const SMUX_PDUs_t * pdus)
29 printfd(__FILE__, "SMUX::PDUsRequestHandler()\n");
30 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
31 PDUsHandlers::iterator it;
32 it = pdusHandlers.find(pdus->choice.pdus.present);
33 if (it != pdusHandlers.end())
35 return (this->*(it->second))(&pdus->choice.pdus);
39 switch (pdus->present)
42 printfd(__FILE__, "SMUX::PDUsRequestHandler() - nothing\n");
44 case PDUs_PR_get_response:
45 printfd(__FILE__, "SMUX::PDUsRequestHandler() - get response\n");
48 printfd(__FILE__, "SMUX::PDUsRequestHandler() - trap\n");
51 printfd(__FILE__, "SMUX::PDUsRequestHandler() - undefined\n");
57 bool SMUX::CommitOrRollbackHandler(const SMUX_PDUs_t * pdus)
59 printfd(__FILE__, "SMUX::CommitOrRollbackHandler()\n");
60 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
64 bool SMUX::GetRequestHandler(const PDUs_t * pdus)
66 printfd(__FILE__, "SMUX::GetRequestHandler()\n");
67 asn_fprint(stderr, &asn_DEF_PDUs, pdus);
68 const GetRequest_PDU_t * getRequest = &pdus->choice.get_request;
69 GetResponse_PDU_t * msg = static_cast<GetResponse_PDU_t *>(calloc(1, sizeof(GetResponse_PDU_t)));
70 assert(msg && "Enought mempry to allocate GetResponse_PDU_t");
71 VarBindList_t * varBindList = &msg->variable_bindings;
74 asn_INTEGER2long(&getRequest->request_id, &id);
75 asn_long2INTEGER(&msg->request_id, id);
76 asn_long2INTEGER(&msg->error_status, 0);
77 asn_long2INTEGER(&msg->error_index, 0);
79 const VarBindList_t * vbl = &getRequest->variable_bindings;
80 for (int i = 0; i < vbl->list.count; ++i)
82 VarBind_t * vb = getRequest->variable_bindings.list.array[i];
84 it = sensors.find(OID(&vb->name));
85 if (it == sensors.end())
87 SendGetResponseErrorPDU(sock, getRequest,
88 PDU__error_status_noSuchName, i);
92 VarBind_t * newVb = static_cast<VarBind_t *>(calloc(1, sizeof(VarBind_t)));
93 assert(newVb && "Enought mempry to allocate VarBind_t");
95 it->first.ToOID(&newVb->name);
96 it->second->GetValue(&newVb->value);
98 ASN_SEQUENCE_ADD(varBindList, newVb);
101 SendGetResponsePDU(sock, msg);
102 asn_fprint(stderr, &asn_DEF_GetResponse_PDU, msg);
103 ASN_STRUCT_FREE(asn_DEF_GetResponse_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 = static_cast<GetResponse_PDU_t *>(calloc(1, sizeof(GetResponse_PDU_t)));
113 assert(msg && "Enought mempry to allocate GetResponse_PDU_t");
114 VarBindList_t * varBindList = &msg->variable_bindings;
117 asn_INTEGER2long(&getRequest->request_id, &id);
118 asn_long2INTEGER(&msg->request_id, id);
119 asn_long2INTEGER(&msg->error_status, 0);
120 asn_long2INTEGER(&msg->error_index, 0);
122 const VarBindList_t * vbl = &getRequest->variable_bindings;
123 for (int i = 0; i < vbl->list.count; ++i)
125 VarBind_t * vb = getRequest->variable_bindings.list.array[i];
126 Sensors::iterator it;
127 it = sensors.upper_bound(OID(&vb->name));
128 if (it == sensors.end())
130 printfd(__FILE__, "SMUX::GetNextRequestHandler() - '%s' not found\n", OID(&vb->name).ToString().c_str());
131 SendGetResponseErrorPDU(sock, getRequest,
132 PDU__error_status_noSuchName, i);
136 VarBind_t * newVb = static_cast<VarBind_t *>(calloc(1, sizeof(VarBind_t)));
137 assert(newVb && "Enought mempry to allocate VarBind_t");
139 it->first.ToOID(&newVb->name);
140 it->second->GetValue(&newVb->value);
142 ASN_SEQUENCE_ADD(varBindList, newVb);
145 SendGetResponsePDU(sock, msg);
146 asn_fprint(stderr, &asn_DEF_PDU, msg);
147 ASN_STRUCT_FREE(asn_DEF_GetResponse_PDU, msg);
151 bool SMUX::SetRequestHandler(const PDUs_t * pdus)
153 printfd(__FILE__, "SMUX::SetRequestHandler()\n");
154 asn_fprint(stderr, &asn_DEF_PDUs, pdus);
155 SendGetResponseErrorPDU(sock, &pdus->choice.set_request,
156 PDU__error_status_readOnly, 0);