+
+bool WaitPackets(int sd)
+{
+fd_set rfds;
+FD_ZERO(&rfds);
+FD_SET(sd, &rfds);
+
+struct timeval tv;
+tv.tv_sec = 0;
+tv.tv_usec = 500000;
+
+int res = select(sd + 1, &rfds, NULL, NULL, &tv);
+if (res == -1) // Error
+ {
+ if (errno != EINTR)
+ {
+ printfd(__FILE__, "Error on select: '%s'\n", strerror(errno));
+ }
+ return false;
+ }
+
+if (res == 0) // Timeout
+ {
+ return false;
+ }
+
+return true;
+}
+
+bool SNMP_AGENT::DispatchPDUs(const SMUX_PDUs_t * pdus)
+{
+SMUXHandlers::iterator it;
+it = smuxHandlers.find(pdus->present);
+if (it != smuxHandlers.end())
+ {
+ return (this->*(it->second))(pdus);
+ }
+else
+ {
+ switch (pdus->present)
+ {
+ case SMUX_PDUs_PR_NOTHING:
+ printfd(__FILE__, "PDUs: nothing\n");
+ break;
+ case SMUX_PDUs_PR_open:
+ printfd(__FILE__, "PDUs: open\n");
+ break;
+ case SMUX_PDUs_PR_registerRequest:
+ printfd(__FILE__, "PDUs: registerRequest\n");
+ break;
+ default:
+ printfd(__FILE__, "PDUs: undefined\n");
+ }
+ asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
+ }
+return false;
+}
+
+bool SNMP_AGENT::CloseHandler(const SMUX_PDUs_t * pdus)
+{
+printfd(__FILE__, "SNMP_AGENT::CloseHandler()\n");
+asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
+return false;
+}
+
+bool SNMP_AGENT::RegisterResponseHandler(const SMUX_PDUs_t * pdus)
+{
+printfd(__FILE__, "SNMP_AGENT::RegisterResponseHandler()\n");
+asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
+return false;
+}
+
+bool SNMP_AGENT::PDUsHandler(const SMUX_PDUs_t * pdus)
+{
+printfd(__FILE__, "SNMP_AGENT::PDUsHandler()\n");
+asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
+PDUsHandlers::iterator it;
+it = pdusHandlers.find(pdus->choice.pdus.present);
+if (it != pdusHandlers.end())
+ {
+ return (this->*(it->second))(&pdus->choice.pdus);
+ }
+else
+ {
+ switch (pdus->present)
+ {
+ case PDUs_PR_NOTHING:
+ printfd(__FILE__, "SNMP_AGENT::PDUsHandler() - nothing\n");
+ break;
+ case PDUs_PR_get_response:
+ printfd(__FILE__, "SNMP_AGENT::PDUsHandler() - get response\n");
+ break;
+ case PDUs_PR_trap:
+ printfd(__FILE__, "SNMP_AGENT::PDUsHandler() - trap\n");
+ break;
+ default:
+ printfd(__FILE__, "SNMP_AGENT::PDUsHandler() - undefined\n");
+ }
+ }
+return false;
+}
+
+bool SNMP_AGENT::CommitOrRollbackHandler(const SMUX_PDUs_t * pdus)
+{
+printfd(__FILE__, "SNMP_AGENT::CommitOrRollbackHandler()\n");
+asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
+return false;
+}
+
+bool SNMP_AGENT::GetRequestHandler(const PDUs_t * pdus)
+{
+printfd(__FILE__, "SNMP_AGENT::GetRequestHandler()\n");
+asn_fprint(stderr, &asn_DEF_PDUs, pdus);
+const GetRequest_PDU_t * getRequest = &pdus->choice.get_request;
+GetResponse_PDU_t msg;
+VarBindList_t * varBindList = &msg.variable_bindings;
+memset(&msg, 0, sizeof(msg));
+
+msg.request_id = getRequest->request_id;
+asn_long2INTEGER(&msg.error_status, 0);
+asn_long2INTEGER(&msg.error_index, 0);
+
+const VarBindList_t * vbl = &getRequest->variable_bindings;
+for (int i = 0; i < vbl->list.count; ++i)
+ {
+ VarBind_t * vb = getRequest->variable_bindings.list.array[i];
+ Sensors::iterator it;
+ it = sensors.find(OI2String(&vb->name));
+ if (it == sensors.end())
+ {
+ SendGetResponseErrorPDU(sock, getRequest, PDU__error_status_noSuchName, i);
+ return true;
+ }
+
+ VarBind_t newVb;
+ memset(&newVb, 0, sizeof(newVb));
+
+ newVb.name = vb->name;
+ it->second->GetValue(&newVb.value);
+
+ ASN_SEQUENCE_ADD(varBindList, &newVb);
+ }
+
+SendGetResponsePDU(sock, &msg);
+asn_fprint(stderr, &asn_DEF_PDU, &msg);
+return false;
+}
+
+bool SNMP_AGENT::GetNextRequestHandler(const PDUs_t * pdus)
+{
+printfd(__FILE__, "SNMP_AGENT::GetNextRequestHandler()\n");
+asn_fprint(stderr, &asn_DEF_PDUs, pdus);
+return false;
+}
+
+bool SNMP_AGENT::SetRequestHandler(const PDUs_t * pdus)
+{
+printfd(__FILE__, "SNMP_AGENT::SetRequestHandler()\n");
+asn_fprint(stderr, &asn_DEF_PDUs, pdus);
+SendGetResponseErrorPDU(sock, &pdus->choice.set_request, PDU__error_status_readOnly, 0);
+return false;
+}
+