summaryrefslogtreecommitdiffstats
path: root/src/Core/Requests
diff options
context:
space:
mode:
Diffstat (limited to 'src/Core/Requests')
-rw-r--r--src/Core/Requests/CommandRequest.cpp47
-rw-r--r--src/Core/Requests/CommandRequest.h45
-rw-r--r--src/Core/Requests/Makefile.am4
-rw-r--r--src/Core/Requests/Makefile.in7
4 files changed, 98 insertions, 5 deletions
diff --git a/src/Core/Requests/CommandRequest.cpp b/src/Core/Requests/CommandRequest.cpp
new file mode 100644
index 0000000..35d4dd2
--- /dev/null
+++ b/src/Core/Requests/CommandRequest.cpp
@@ -0,0 +1,47 @@
+/*
+ * CommandRequest.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 "CommandRequest.h"
+#include <Net/Connection.h>
+#include <Net/Packets/ErrorPacket.h>
+
+namespace Mad {
+namespace Core {
+namespace Requests {
+
+void CommandRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
+ connection->send(Net::Packet(reboot ? Net::Packet::COMMAND_REBOOT : Net::Packet::COMMAND_SHUTDOWN, requestId));
+}
+
+void CommandRequest::handlePacket(Net::Connection*, const Net::Packet &packet) {
+ if(packet.getType() == Net::Packet::ERROR) {
+ finishWithError(Net::Packets::ErrorPacket(packet).getException());
+ return;
+ }
+ else if(packet.getType() != Net::Packet::OK) {
+ finishWithError(Common::Exception(Common::Exception::UNEXPECTED_PACKET));
+ return; // TODO Logging
+ }
+
+ finish();
+}
+
+}
+}
+}
diff --git a/src/Core/Requests/CommandRequest.h b/src/Core/Requests/CommandRequest.h
new file mode 100644
index 0000000..181fa4d
--- /dev/null
+++ b/src/Core/Requests/CommandRequest.h
@@ -0,0 +1,45 @@
+/*
+ * CommandRequest.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_CORE_REQUESTS_COMMANDREQUEST_H_
+#define MAD_CORE_REQUESTS_COMMANDREQUEST_H_
+
+#include <Common/Request.h>
+
+namespace Mad {
+namespace Core {
+namespace Requests {
+
+class CommandRequest : public Common::Request<> {
+ private:
+ bool reboot;
+
+ protected:
+ virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
+ virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet);
+
+ public:
+ CommandRequest(bool reboot0, slot_type slot) : Common::Request<>(slot), reboot(reboot0) {}
+};
+
+}
+}
+}
+
+#endif /* MAD_CORE_REQUESTS_COMMANDREQUEST_H_ */
diff --git a/src/Core/Requests/Makefile.am b/src/Core/Requests/Makefile.am
index d220dd6..2d08477 100644
--- a/src/Core/Requests/Makefile.am
+++ b/src/Core/Requests/Makefile.am
@@ -1,4 +1,4 @@
noinst_LTLIBRARIES = librequests.la
-librequests_la_SOURCES = DaemonStatusRequest.cpp
+librequests_la_SOURCES = CommandRequest.cpp DaemonStatusRequest.cpp
-noinst_HEADERS = DaemonStatusRequest.h
+noinst_HEADERS = CommandRequest.h DaemonStatusRequest.h
diff --git a/src/Core/Requests/Makefile.in b/src/Core/Requests/Makefile.in
index 23458f1..22ac701 100644
--- a/src/Core/Requests/Makefile.in
+++ b/src/Core/Requests/Makefile.in
@@ -48,7 +48,7 @@ CONFIG_HEADER = $(top_builddir)/src/config.h
CONFIG_CLEAN_FILES =
LTLIBRARIES = $(noinst_LTLIBRARIES)
librequests_la_LIBADD =
-am_librequests_la_OBJECTS = DaemonStatusRequest.lo
+am_librequests_la_OBJECTS = CommandRequest.lo DaemonStatusRequest.lo
librequests_la_OBJECTS = $(am_librequests_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
depcomp = $(SHELL) $(top_srcdir)/depcomp
@@ -187,8 +187,8 @@ target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = librequests.la
-librequests_la_SOURCES = DaemonStatusRequest.cpp
-noinst_HEADERS = DaemonStatusRequest.h
+librequests_la_SOURCES = CommandRequest.cpp DaemonStatusRequest.cpp
+noinst_HEADERS = CommandRequest.h DaemonStatusRequest.h
all: all-am
.SUFFIXES:
@@ -240,6 +240,7 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CommandRequest.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonStatusRequest.Plo@am__quote@
.cpp.o: