summaryrefslogtreecommitdiffstats
path: root/src/Net
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2008-09-29 22:26:31 +0200
committerMatthias Schiffer <matthias@gamezock.de>2008-09-29 22:26:31 +0200
commit2919e527e3e2c0bbdd35afe28c7da4b041ca25f1 (patch)
tree58e952b592c576e78a5160dce7e538603d0e4116 /src/Net
parent011eb079956c8b08db7b7ecff57503c436b39cbf (diff)
parent13fd1bb4f19e4791e000cb71cca2065820184bdb (diff)
downloadmad-2919e527e3e2c0bbdd35afe28c7da4b041ca25f1.tar
mad-2919e527e3e2c0bbdd35afe28c7da4b041ca25f1.zip
Merge
Diffstat (limited to 'src/Net')
-rw-r--r--src/Net/Packet.h3
-rw-r--r--src/Net/Packets/HostListPacket.cpp4
-rw-r--r--src/Net/Packets/HostListPacket.h2
-rw-r--r--src/Net/Packets/HostStatePacket.cpp50
-rw-r--r--src/Net/Packets/HostStatePacket.h74
-rw-r--r--src/Net/Packets/Makefile.am4
-rw-r--r--src/Net/Packets/Makefile.in7
7 files changed, 135 insertions, 9 deletions
diff --git a/src/Net/Packet.h b/src/Net/Packet.h
index a3fe524..366746b 100644
--- a/src/Net/Packet.h
+++ b/src/Net/Packet.h
@@ -36,7 +36,8 @@ class Packet {
LIST_DAEMONS = 0x0020,
STATUS = 0x0030, DAEMON_STATUS = 0x0031,
COMMAND_SHUTDOWN = 0x0040, COMMAND_REBOOT = 0x0041,
- DAEMON_COMMAND_SHUTDOWN = 0x0050, DAEMON_COMMAND_REBOOT = 0x0051
+ DAEMON_COMMAND_SHUTDOWN = 0x0050, DAEMON_COMMAND_REBOOT = 0x0051,
+ DAEMON_STATE_UPDATE = 0x0060
};
struct Data {
diff --git a/src/Net/Packets/HostListPacket.cpp b/src/Net/Packets/HostListPacket.cpp
index 30a33b3..8c3d395 100644
--- a/src/Net/Packets/HostListPacket.cpp
+++ b/src/Net/Packets/HostListPacket.cpp
@@ -46,7 +46,7 @@ void HostListPacket::assemblePacket() {
*nHosts = htons(hostList.size());
for(size_t i = 0; i < hostList.size(); ++i) {
- hostData[i].status = htons((uint16_t)hostList[i].getStatus());
+ hostData[i].state = htons((uint16_t)hostList[i].getState());
}
}
@@ -69,7 +69,7 @@ void HostListPacket::parsePacket() {
std::istringstream stream(std::string(charData, getLength() - (sizeof(uint16_t)+sizeof(HostData)*hostList.size())));
for(size_t i = 0; i < hostList.size(); ++i) {
- hostList[i].setStatus((Common::HostInfo::Status)ntohs(hostData[i].status));
+ hostList[i].setState((Common::HostInfo::State)ntohs(hostData[i].state));
if(!stream.eof()) {
std::string str;
diff --git a/src/Net/Packets/HostListPacket.h b/src/Net/Packets/HostListPacket.h
index 4d0b2d0..2cec9b0 100644
--- a/src/Net/Packets/HostListPacket.h
+++ b/src/Net/Packets/HostListPacket.h
@@ -33,7 +33,7 @@ namespace Packets {
class HostListPacket : public Packet {
protected:
struct HostData {
- uint16_t status;
+ uint16_t state;
};
uint16_t *nHosts;
diff --git a/src/Net/Packets/HostStatePacket.cpp b/src/Net/Packets/HostStatePacket.cpp
new file mode 100644
index 0000000..d34d9d5
--- /dev/null
+++ b/src/Net/Packets/HostStatePacket.cpp
@@ -0,0 +1,50 @@
+/*
+ * HostStatePacket.cpp
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.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 "HostStatePacket.h"
+
+namespace Mad {
+namespace Net {
+namespace Packets {
+
+HostStatePacket::HostStatePacket(Type type, uint16_t requestId, const std::string &name, Common::HostInfo::State state)
+: Packet(type, requestId)
+{
+ setLength(sizeof(HostStateData) + name.length());
+ hostStateData = (HostStateData*)&rawData->data;
+
+ hostStateData->state = htons(state);
+
+ std::memcpy(hostStateData->name, name.c_str(), name.length());
+}
+
+HostStatePacket& HostStatePacket::operator=(const Packet &p) {
+ Packet::operator=(p);
+
+ if(getLength() < sizeof(HostStateData))
+ setLength(sizeof(HostStateData));
+
+ hostStateData = (HostStateData*)&rawData->data;
+
+ return *this;
+}
+
+}
+}
+}
diff --git a/src/Net/Packets/HostStatePacket.h b/src/Net/Packets/HostStatePacket.h
new file mode 100644
index 0000000..5a34275
--- /dev/null
+++ b/src/Net/Packets/HostStatePacket.h
@@ -0,0 +1,74 @@
+/*
+ * HostStatePacket.h
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.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/>.
+ */
+
+#ifndef MAD_NET_PACKETS_HOSTSTATEPACKET_H_
+#define MAD_NET_PACKETS_HOSTSTATEPACKET_H_
+
+#include "../Packet.h"
+#include <Common/HostInfo.h>
+
+#include <string>
+
+namespace Mad {
+namespace Net {
+namespace Packets {
+
+class HostStatePacket : public Packet {
+ protected:
+ struct HostStateData {
+ uint16_t state;
+ uint8_t name[0];
+ };
+
+ HostStateData *hostStateData;
+
+ public:
+ HostStatePacket(Type type, uint16_t requestId, const std::string &name, Common::HostInfo::State state);
+
+ HostStatePacket(const Packet &p) : Packet(p) {
+ if(getLength() < sizeof(HostStateData))
+ setLength(sizeof(HostStateData));
+
+ hostStateData = (HostStateData*)&rawData->data;
+ }
+
+ HostStatePacket(const HostStatePacket &p) : Packet(p) {
+ hostStateData = (HostStateData*)&rawData->data;
+ }
+
+ HostStatePacket& operator=(const Packet &p);
+
+ HostStatePacket& operator=(const HostStatePacket &p) {
+ return (*this = (Packet)p);
+ }
+
+ std::string getName() const {
+ return std::string((char*)hostStateData->name, getLength()-sizeof(HostStateData));
+ }
+
+ Common::HostInfo::State getState() const {
+ return (Common::HostInfo::State)ntohs(hostStateData->state);
+ }
+};
+
+}
+}
+}
+
+#endif /* MAD_NET_PACKETS_HOSTSTATEPACKET_H_ */
diff --git a/src/Net/Packets/Makefile.am b/src/Net/Packets/Makefile.am
index 0b44f6d..19dcc7c 100644
--- a/src/Net/Packets/Makefile.am
+++ b/src/Net/Packets/Makefile.am
@@ -1,4 +1,4 @@
noinst_LTLIBRARIES = libpackets.la
-libpackets_la_SOURCES = ErrorPacket.cpp HostListPacket.cpp HostStatusPacket.cpp LogPacket.cpp
+libpackets_la_SOURCES = ErrorPacket.cpp HostListPacket.cpp HostStatePacket.cpp HostStatusPacket.cpp LogPacket.cpp
-noinst_HEADERS = ErrorPacket.h HostListPacket.h HostStatusPacket.h LogPacket.h
+noinst_HEADERS = ErrorPacket.h HostListPacket.h HostStatePacket.h HostStatusPacket.h LogPacket.h
diff --git a/src/Net/Packets/Makefile.in b/src/Net/Packets/Makefile.in
index 9109103..b500da6 100644
--- a/src/Net/Packets/Makefile.in
+++ b/src/Net/Packets/Makefile.in
@@ -49,7 +49,7 @@ CONFIG_CLEAN_FILES =
LTLIBRARIES = $(noinst_LTLIBRARIES)
libpackets_la_LIBADD =
am_libpackets_la_OBJECTS = ErrorPacket.lo HostListPacket.lo \
- HostStatusPacket.lo LogPacket.lo
+ HostStatePacket.lo HostStatusPacket.lo LogPacket.lo
libpackets_la_OBJECTS = $(am_libpackets_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
depcomp = $(SHELL) $(top_srcdir)/depcomp
@@ -188,8 +188,8 @@ target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = libpackets.la
-libpackets_la_SOURCES = ErrorPacket.cpp HostListPacket.cpp HostStatusPacket.cpp LogPacket.cpp
-noinst_HEADERS = ErrorPacket.h HostListPacket.h HostStatusPacket.h LogPacket.h
+libpackets_la_SOURCES = ErrorPacket.cpp HostListPacket.cpp HostStatePacket.cpp HostStatusPacket.cpp LogPacket.cpp
+noinst_HEADERS = ErrorPacket.h HostListPacket.h HostStatePacket.h HostStatusPacket.h LogPacket.h
all: all-am
.SUFFIXES:
@@ -243,6 +243,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ErrorPacket.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HostListPacket.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HostStatePacket.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HostStatusPacket.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LogPacket.Plo@am__quote@