summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Schink <swo-dev@marcschink.de>2017-07-07 10:02:01 +0200
committerMarc Schink <swo-dev@marcschink.de>2017-07-11 10:35:35 +0200
commit5a624bd4731a04fdadf478b2e2085be75c0f7f2b (patch)
treeef314fdeb1e6b1ecff3d04b9fa5ecbe947d651d0
parent34b69a76bea79945ed320d8dd78c487a8d5c5e79 (diff)
bindings: Add abstract class for source packets
-rw-r--r--bindings/cxx/Makefile.am1
-rw-r--r--bindings/cxx/hardware.cpp16
-rw-r--r--bindings/cxx/instrumentation.cpp16
-rw-r--r--bindings/cxx/libswocxx.h20
-rw-r--r--bindings/cxx/sourcepacket.cpp45
5 files changed, 58 insertions, 40 deletions
diff --git a/bindings/cxx/Makefile.am b/bindings/cxx/Makefile.am
index 5a7f064..8c4c590 100644
--- a/bindings/cxx/Makefile.am
+++ b/bindings/cxx/Makefile.am
@@ -37,6 +37,7 @@ libswocxx_la_SOURCES = \
payloadpacket.cpp \
pcsample.cpp \
pcvalue.cpp \
+ sourcepacket.cpp \
synchronization.cpp \
unknown.cpp \
version.cpp
diff --git a/bindings/cxx/hardware.cpp b/bindings/cxx/hardware.cpp
index 5026ef5..08ac307 100644
--- a/bindings/cxx/hardware.cpp
+++ b/bindings/cxx/hardware.cpp
@@ -33,22 +33,6 @@ Hardware::Hardware(const union libswo_packet *packet)
_packet = *packet;
}
-const vector<uint8_t> Hardware::get_payload(void) const
-{
- return vector<uint8_t>(_packet.hw.payload,
- _packet.hw.payload + _packet.hw.size - 1);
-}
-
-uint8_t Hardware::get_address(void) const
-{
- return _packet.hw.address;
-}
-
-uint32_t Hardware::get_value(void) const
-{
- return _packet.hw.value;
-}
-
const std::string Hardware::to_string(void) const
{
std::stringstream ss;
diff --git a/bindings/cxx/instrumentation.cpp b/bindings/cxx/instrumentation.cpp
index b9bdb6f..2b16947 100644
--- a/bindings/cxx/instrumentation.cpp
+++ b/bindings/cxx/instrumentation.cpp
@@ -34,22 +34,6 @@ Instrumentation::Instrumentation(const union libswo_packet *packet)
_packet = *packet;
}
-uint8_t Instrumentation::get_address(void) const
-{
- return _packet.inst.address;
-}
-
-const vector<uint8_t> Instrumentation::get_payload(void) const
-{
- return vector<uint8_t>(_packet.inst.payload,
- _packet.inst.payload + _packet.inst.size - 1);
-}
-
-uint32_t Instrumentation::get_value(void) const
-{
- return _packet.inst.value;
-}
-
const std::string Instrumentation::to_string(void) const
{
std::stringstream ss;
diff --git a/bindings/cxx/libswocxx.h b/bindings/cxx/libswocxx.h
index 0b6ca20..0fa4974 100644
--- a/bindings/cxx/libswocxx.h
+++ b/bindings/cxx/libswocxx.h
@@ -192,29 +192,33 @@ public:
const string to_string(void) const;
};
-class LIBSWO_API Instrumentation : public PayloadPacket
+class LIBSWO_API SourcePacket : public PayloadPacket
{
public:
- Instrumentation(const struct libswo_packet_inst *packet);
- Instrumentation(const union libswo_packet *packet);
+ virtual ~SourcePacket(void);
uint8_t get_address(void) const;
const vector<uint8_t> get_payload(void) const;
uint32_t get_value(void) const;
+ virtual const string to_string(void) const = 0;
+};
+
+class LIBSWO_API Instrumentation : public SourcePacket
+{
+public:
+ Instrumentation(const struct libswo_packet_inst *packet);
+ Instrumentation(const union libswo_packet *packet);
+
const string to_string(void) const;
};
-class LIBSWO_API Hardware : public PayloadPacket
+class LIBSWO_API Hardware : public SourcePacket
{
public:
Hardware(const struct libswo_packet_hw *packet);
Hardware(const union libswo_packet *packet);
- uint8_t get_address(void) const;
- const vector<uint8_t> get_payload(void) const;
- uint32_t get_value(void) const;
-
const string to_string(void) const;
};
diff --git a/bindings/cxx/sourcepacket.cpp b/bindings/cxx/sourcepacket.cpp
new file mode 100644
index 0000000..6396ba7
--- /dev/null
+++ b/bindings/cxx/sourcepacket.cpp
@@ -0,0 +1,45 @@
+/*
+ * This file is part of the libswo project.
+ *
+ * Copyright (C) 2017 Marc Schink <swo-dev@marcschink.de>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "libswocxx.h"
+
+namespace libswo
+{
+
+SourcePacket::~SourcePacket(void)
+{
+}
+
+uint8_t SourcePacket::get_address(void) const
+{
+ return _packet.inst.address;
+}
+
+const vector<uint8_t> SourcePacket::get_payload(void) const
+{
+ return vector<uint8_t>(_packet.inst.payload,
+ _packet.inst.payload + _packet.inst.size - 1);
+}
+
+uint32_t SourcePacket::get_value(void) const
+{
+ return _packet.inst.value;
+}
+
+}