]> git.stg.codes - stg.git/commitdiff
Handlers moved to separate file and added to compilation
authorMaxim Mamontov <faust.madf@gmail.com>
Mon, 25 Jul 2011 18:15:29 +0000 (21:15 +0300)
committerMaxim Mamontov <faust.madf@gmail.com>
Mon, 25 Jul 2011 18:15:29 +0000 (21:15 +0300)
projects/stargazer/plugins/other/smux/Makefile
projects/stargazer/plugins/other/smux/handlers.cpp
projects/stargazer/plugins/other/smux/smux.cpp

index ca358f9c5e8b8cca0ca48cc164fe3ff8c0d01a3f..82c6af9a873a1f1c0b86152f38514e5215036a9d 100644 (file)
@@ -6,6 +6,7 @@ PROG = mod_smux.so
 
 SRCS =  smux.cpp \
        sensors.cpp \
 
 SRCS =  smux.cpp \
        sensors.cpp \
+       handlers.cpp \
        asn1/DisplayString.c \
        asn1/PhysAddress.c \
        asn1/IfEntry.c \
        asn1/DisplayString.c \
        asn1/PhysAddress.c \
        asn1/IfEntry.c \
index 5fb3dfda7796e040f0bf729d7adbe69376ee48ce..5a8c917d7a5c01927faaa56ca92ed84420399af4 100644 (file)
 
 #include "smux.h"
 
 
 #include "smux.h"
 
+std::string OI2String(OBJECT_IDENTIFIER_t * oi);
+int SendGetResponsePDU(int fd, GetResponse_PDU_t * getResponse);
+int SendGetResponseErrorPDU(int fd,
+                            const PDU_t * getRequest,
+                            int errorStatus,
+                            int errorIndex);
+
 bool SMUX::CloseHandler(const SMUX_PDUs_t * pdus)
 {
 printfd(__FILE__, "SMUX::CloseHandler()\n");
 bool SMUX::CloseHandler(const SMUX_PDUs_t * pdus)
 {
 printfd(__FILE__, "SMUX::CloseHandler()\n");
@@ -29,7 +36,7 @@ return false;
 
 bool SMUX::PDUsRequestHandler(const SMUX_PDUs_t * pdus)
 {
 
 bool SMUX::PDUsRequestHandler(const SMUX_PDUs_t * pdus)
 {
-printfd(__FILE__, "SMUX::PDUsHandler()\n");
+printfd(__FILE__, "SMUX::PDUsRequestHandler()\n");
 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
 PDUsHandlers::iterator it;
 it = pdusHandlers.find(pdus->choice.pdus.present);
 asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
 PDUsHandlers::iterator it;
 it = pdusHandlers.find(pdus->choice.pdus.present);
@@ -42,16 +49,16 @@ else
     switch (pdus->present)
         {
         case PDUs_PR_NOTHING:
     switch (pdus->present)
         {
         case PDUs_PR_NOTHING:
-            printfd(__FILE__, "SMUX::PDUsHandler() - nothing\n");
+            printfd(__FILE__, "SMUX::PDUsRequestHandler() - nothing\n");
             break;
         case PDUs_PR_get_response:
             break;
         case PDUs_PR_get_response:
-            printfd(__FILE__, "SMUX::PDUsHandler() - get response\n");
+            printfd(__FILE__, "SMUX::PDUsRequestHandler() - get response\n");
             break;
         case PDUs_PR_trap:
             break;
         case PDUs_PR_trap:
-            printfd(__FILE__, "SMUX::PDUsHandler() - trap\n");
+            printfd(__FILE__, "SMUX::PDUsRequestHandler() - trap\n");
             break;
         default:
             break;
         default:
-            printfd(__FILE__, "SMUX::PDUsHandler() - undefined\n");
+            printfd(__FILE__, "SMUX::PDUsRequestHandler() - undefined\n");
         }
     }
 return false;
         }
     }
 return false;
@@ -152,3 +159,81 @@ SendGetResponseErrorPDU(sock, &pdus->choice.set_request,
                         PDU__error_status_readOnly, 0);
 return false;
 }
                         PDU__error_status_readOnly, 0);
 return false;
 }
+
+std::string OI2String(OBJECT_IDENTIFIER_t * oi)
+{
+std::string res;
+
+int arcs[1024];
+int count = OBJECT_IDENTIFIER_get_arcs(oi, arcs, sizeof(arcs[0]), 1024);
+
+if (count > 1024)
+    return "";
+
+for (int i = 0; i < count; ++i)
+    {
+    res += ".";
+    std::string arc;
+    strprintf(&arc, "%d", arcs[i]);
+    res += arc;
+    }
+
+return res;
+}
+
+int SendGetResponsePDU(int fd, GetResponse_PDU_t * getResponse)
+{
+asn_enc_rval_t error;
+
+char buffer[1024];
+error = der_encode_to_buffer(&asn_DEF_GetResponse_PDU, getResponse, buffer,
+                             sizeof(buffer));
+
+if (error.encoded == -1)
+    {
+    printfd(__FILE__, "Could not encode GetResponsePDU (at %s)\n",
+            error.failed_type ? error.failed_type->name : "unknown");
+    return -1;
+    }
+else
+    {
+    write(fd, buffer, error.encoded);
+    printfd(__FILE__, "GetResponsePDU encoded successfully to %d bytes\n",
+            error.encoded);
+    }
+return 0;
+}
+
+int SendGetResponseErrorPDU(int fd,
+                            const PDU_t * getRequest,
+                            int errorStatus,
+                            int errorIndex)
+{
+asn_enc_rval_t error;
+GetResponse_PDU_t msg;
+
+memset(&msg, 0, sizeof(msg));
+
+msg.request_id = getRequest->request_id;
+asn_long2INTEGER(&msg.error_status, errorStatus);
+asn_long2INTEGER(&msg.error_index, errorIndex);
+
+char buffer[1024];
+error = der_encode_to_buffer(&asn_DEF_GetResponse_PDU, &msg, buffer,
+                             sizeof(buffer));
+
+if (error.encoded == -1)
+    {
+    printfd(__FILE__, "Could not encode GetResponsePDU for error (at %s)\n",
+            error.failed_type ? error.failed_type->name : "unknown");
+    return -1;
+    }
+else
+    {
+    write(fd, buffer, error.encoded);
+    printfd(__FILE__,
+            "GetResponsePDU for error encoded successfully to %d bytes\n",
+            error.encoded);
+    }
+return 0;
+}
index 01d9bb2151406b1d4d85aaf52fcd189a1bbdbbfe..bd83f1ab38b914a5da9d4792eb74f466b85f2c98 100644 (file)
 
 bool WaitPackets(int sd);
 
 
 bool WaitPackets(int sd);
 
-std::string OI2String(OBJECT_IDENTIFIER_t * oi)
-{
-std::string res;
-
-int arcs[1024];
-int count = OBJECT_IDENTIFIER_get_arcs(oi, arcs, sizeof(arcs[0]), 1024);
-
-if (count > 1024)
-    return "";
-
-for (int i = 0; i < count; ++i)
-    {
-    res += ".";
-    std::string arc;
-    strprintf(&arc, "%d", arcs[i]);
-    res += arc;
-    }
-
-return res;
-}
-
 bool String2OI(const std::string & str, OBJECT_IDENTIFIER_t * oi)
 {
 size_t left = 0, pos = 0, arcPos = 0;
 bool String2OI(const std::string & str, OBJECT_IDENTIFIER_t * oi)
 {
 size_t left = 0, pos = 0, arcPos = 0;
@@ -199,63 +178,6 @@ else
 return 0;
 }
 
 return 0;
 }
 
-int SendGetResponsePDU(int fd, GetResponse_PDU_t * getResponse)
-{
-asn_enc_rval_t error;
-
-char buffer[1024];
-error = der_encode_to_buffer(&asn_DEF_GetResponse_PDU, getResponse, buffer,
-                             sizeof(buffer));
-
-if (error.encoded == -1)
-    {
-    printfd(__FILE__, "Could not encode GetResponsePDU (at %s)\n",
-            error.failed_type ? error.failed_type->name : "unknown");
-    return -1;
-    }
-else
-    {
-    write(fd, buffer, error.encoded);
-    printfd(__FILE__, "GetResponsePDU encoded successfully to %d bytes\n",
-            error.encoded);
-    }
-return 0;
-}
-
-int SendGetResponseErrorPDU(int fd,
-                            const PDU_t * getRequest,
-                            int errorStatus,
-                            int errorIndex)
-{
-asn_enc_rval_t error;
-GetResponse_PDU_t msg;
-
-memset(&msg, 0, sizeof(msg));
-
-msg.request_id = getRequest->request_id;
-asn_long2INTEGER(&msg.error_status, errorStatus);
-asn_long2INTEGER(&msg.error_index, errorIndex);
-
-char buffer[1024];
-error = der_encode_to_buffer(&asn_DEF_GetResponse_PDU, &msg, buffer,
-                             sizeof(buffer));
-
-if (error.encoded == -1)
-    {
-    printfd(__FILE__, "Could not encode GetResponsePDU for error (at %s)\n",
-            error.failed_type ? error.failed_type->name : "unknown");
-    return -1;
-    }
-else
-    {
-    write(fd, buffer, error.encoded);
-    printfd(__FILE__,
-            "GetResponsePDU for error encoded successfully to %d bytes\n",
-            error.encoded);
-    }
-return 0;
-}
-
 SMUX_PDUs_t * RecvSMUXPDUs(int fd)
 {
 char buffer[1024];
 SMUX_PDUs_t * RecvSMUXPDUs(int fd)
 {
 char buffer[1024];