summaryrefslogtreecommitdiffstats
path: root/src/Core
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/Core
parent011eb079956c8b08db7b7ecff57503c436b39cbf (diff)
parent13fd1bb4f19e4791e000cb71cca2065820184bdb (diff)
downloadmad-2919e527e3e2c0bbdd35afe28c7da4b041ca25f1.tar
mad-2919e527e3e2c0bbdd35afe28c7da4b041ca25f1.zip
Merge
Diffstat (limited to 'src/Core')
-rw-r--r--src/Core/ConnectionManager.cpp15
-rw-r--r--src/Core/ConnectionManager.h4
-rw-r--r--src/Core/Requests/DaemonStateUpdateRequest.cpp43
-rw-r--r--src/Core/Requests/DaemonStateUpdateRequest.h47
-rw-r--r--src/Core/Requests/DaemonStatusRequest.cpp1
-rw-r--r--src/Core/Requests/DaemonStatusRequest.h8
-rw-r--r--src/Core/Requests/Makefile.am4
-rw-r--r--src/Core/Requests/Makefile.in8
8 files changed, 114 insertions, 16 deletions
diff --git a/src/Core/ConnectionManager.cpp b/src/Core/ConnectionManager.cpp
index faf6e29..c83f3aa 100644
--- a/src/Core/ConnectionManager.cpp
+++ b/src/Core/ConnectionManager.cpp
@@ -21,6 +21,7 @@
#include "ConfigManager.h"
#include <Common/Logger.h>
#include <Common/RequestHandlers/StatusRequestHandler.h>
+#include "Requests/DaemonStateUpdateRequest.h"
#include "RequestHandlers/DaemonCommandRequestHandler.h"
#include "RequestHandlers/DaemonListRequestHandler.h"
#include "RequestHandlers/DaemonStatusRequestHandler.h"
@@ -64,6 +65,16 @@ void ConnectionManager::refreshPollfds() {
}
}
+void ConnectionManager::updateState(const std::string &name, Common::HostInfo::State state) {
+ daemonInfo[name].setState(state);
+
+ for(std::list<Net::ServerConnection*>::iterator con = clientConnections.begin(); con != clientConnections.end(); ++con) {
+ Common::RequestManager::getRequestManager()->sendRequest(*con, std::auto_ptr<Common::RequestBase>(
+ new Requests::DaemonStateUpdateRequest(name, state)
+ ));
+ }
+}
+
ConnectionManager::ConnectionManager() {
Common::RequestManager::init(true);
@@ -137,7 +148,7 @@ void ConnectionManager::handleConnections(std::list<Net::ServerConnection*>& con
if(idCon->second == *con) {
idCon->second = 0;
- daemonInfo[idCon->first].setStatus(Common::HostInfo::INACTIVE);
+ updateState(idCon->first, Common::HostInfo::INACTIVE);
break;
}
}
@@ -200,7 +211,7 @@ void ConnectionManager::identifyDaemonConnection(Net::Connection *connection, co
}
idCon->second = *con;
- daemonInfo[idCon->first].setStatus(Common::HostInfo::RUNNING);
+ updateState(idCon->first, Common::HostInfo::RUNNING);
connection->setIdentified();
Common::Logger::logf("Identified as '%s'.", name.c_str());
diff --git a/src/Core/ConnectionManager.h b/src/Core/ConnectionManager.h
index 0832b5a..cd470d9 100644
--- a/src/Core/ConnectionManager.h
+++ b/src/Core/ConnectionManager.h
@@ -66,6 +66,8 @@ class ConnectionManager {
void handleConnections(std::list<Net::ServerConnection*> &connections);
+ void updateState(const std::string &name, Common::HostInfo::State state);
+
public:
static ConnectionManager* getConnectionManager() {
return connectionManager.get();
@@ -75,7 +77,7 @@ class ConnectionManager {
connectionManager = std::auto_ptr<ConnectionManager>(new ConnectionManager());
}
- virtual ~ConnectionManager();
+ ~ConnectionManager();
bool wait(int timeout) {
return (poll(pollfds.data(), pollfds.size(), timeout) > 0);
diff --git a/src/Core/Requests/DaemonStateUpdateRequest.cpp b/src/Core/Requests/DaemonStateUpdateRequest.cpp
new file mode 100644
index 0000000..00e0bdf
--- /dev/null
+++ b/src/Core/Requests/DaemonStateUpdateRequest.cpp
@@ -0,0 +1,43 @@
+/*
+ * DaemonStateUpdateRequest.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 "DaemonStateUpdateRequest.h"
+#include <Net/Connection.h>
+#include <Net/Packets/HostStatePacket.h>
+
+namespace Mad {
+namespace Core {
+namespace Requests {
+
+void DaemonStateUpdateRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
+ connection->send(Net::Packets::HostStatePacket(Net::Packet::DAEMON_STATE_UPDATE, requestId, name, state));
+}
+
+void DaemonStateUpdateRequest::handlePacket(Net::Connection*, const Net::Packet &packet) {
+ if(packet.getType() != Net::Packet::OK) {
+ finishWithError(Common::Exception(Common::Exception::UNEXPECTED_PACKET));
+ return; // TODO Logging
+ }
+
+ finish();
+}
+
+}
+}
+}
diff --git a/src/Core/Requests/DaemonStateUpdateRequest.h b/src/Core/Requests/DaemonStateUpdateRequest.h
new file mode 100644
index 0000000..9a1c8f0
--- /dev/null
+++ b/src/Core/Requests/DaemonStateUpdateRequest.h
@@ -0,0 +1,47 @@
+/*
+ * DaemonStateUpdateRequest.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_DAEMONSTATEUPDATEREQUEST_H_
+#define MAD_CORE_REQUESTS_DAEMONSTATEUPDATEREQUEST_H_
+
+#include <Common/Request.h>
+#include <Common/HostInfo.h>
+
+namespace Mad {
+namespace Core {
+namespace Requests {
+
+class DaemonStateUpdateRequest : public Common::Request<> {
+ private:
+ std::string name;
+ Common::HostInfo::State state;
+
+ protected:
+ virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
+ virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet);
+
+ public:
+ DaemonStateUpdateRequest(const std::string &name0, Common::HostInfo::State state0) : Common::Request<>(slot_type()), name(name0), state(state0) {}
+};
+
+}
+}
+}
+
+#endif /* MAD_CORE_REQUESTS_DAEMONSTATEUPDATEREQUEST_H_ */
diff --git a/src/Core/Requests/DaemonStatusRequest.cpp b/src/Core/Requests/DaemonStatusRequest.cpp
index 1741731..3b028c9 100644
--- a/src/Core/Requests/DaemonStatusRequest.cpp
+++ b/src/Core/Requests/DaemonStatusRequest.cpp
@@ -19,7 +19,6 @@
#include "DaemonStatusRequest.h"
#include <Common/RequestManager.h>
-#include <Net/Packets/HostStatusPacket.h>
namespace Mad {
namespace Core {
diff --git a/src/Core/Requests/DaemonStatusRequest.h b/src/Core/Requests/DaemonStatusRequest.h
index baeb847..09cbc2b 100644
--- a/src/Core/Requests/DaemonStatusRequest.h
+++ b/src/Core/Requests/DaemonStatusRequest.h
@@ -21,15 +21,9 @@
#define MAD_CORE_REQUESTS_DAEMONSTATUSREQUEST_H_
#include <Common/Request.h>
+#include <Net/Packets/HostStatusPacket.h>
namespace Mad {
-
-namespace Net {
-namespace Packets {
-class HostStatusPacket;
-}
-}
-
namespace Core {
namespace Requests {
diff --git a/src/Core/Requests/Makefile.am b/src/Core/Requests/Makefile.am
index 2d08477..e69088b 100644
--- a/src/Core/Requests/Makefile.am
+++ b/src/Core/Requests/Makefile.am
@@ -1,4 +1,4 @@
noinst_LTLIBRARIES = librequests.la
-librequests_la_SOURCES = CommandRequest.cpp DaemonStatusRequest.cpp
+librequests_la_SOURCES = CommandRequest.cpp DaemonStateUpdateRequest.cpp DaemonStatusRequest.cpp
-noinst_HEADERS = CommandRequest.h DaemonStatusRequest.h
+noinst_HEADERS = CommandRequest.h DaemonStateUpdateRequest.h DaemonStatusRequest.h
diff --git a/src/Core/Requests/Makefile.in b/src/Core/Requests/Makefile.in
index 22ac701..e6367a2 100644
--- a/src/Core/Requests/Makefile.in
+++ b/src/Core/Requests/Makefile.in
@@ -48,7 +48,8 @@ CONFIG_HEADER = $(top_builddir)/src/config.h
CONFIG_CLEAN_FILES =
LTLIBRARIES = $(noinst_LTLIBRARIES)
librequests_la_LIBADD =
-am_librequests_la_OBJECTS = CommandRequest.lo DaemonStatusRequest.lo
+am_librequests_la_OBJECTS = CommandRequest.lo \
+ DaemonStateUpdateRequest.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 +188,8 @@ target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = librequests.la
-librequests_la_SOURCES = CommandRequest.cpp DaemonStatusRequest.cpp
-noinst_HEADERS = CommandRequest.h DaemonStatusRequest.h
+librequests_la_SOURCES = CommandRequest.cpp DaemonStateUpdateRequest.cpp DaemonStatusRequest.cpp
+noinst_HEADERS = CommandRequest.h DaemonStateUpdateRequest.h DaemonStatusRequest.h
all: all-am
.SUFFIXES:
@@ -241,6 +242,7 @@ distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CommandRequest.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonStateUpdateRequest.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonStatusRequest.Plo@am__quote@
.cpp.o: