summaryrefslogtreecommitdiff
path: root/netfs/daemon/daemon.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'netfs/daemon/daemon.cpp')
-rw-r--r--netfs/daemon/daemon.cpp32
1 files changed, 21 insertions, 11 deletions
diff --git a/netfs/daemon/daemon.cpp b/netfs/daemon/daemon.cpp
index 3736167..199ecaa 100644
--- a/netfs/daemon/daemon.cpp
+++ b/netfs/daemon/daemon.cpp
@@ -1,38 +1,48 @@
#include "pch.hpp"
#include <Ice/Ice.h>
#include <boost/foreach.hpp>
-#include <boost/crc.hpp>
#include "daemon.h"
-#include "daemonConfig.h"
#include "daemonService.h"
#include "daemonVolume.h"
+#include <slicer/slicer.h>
+#include <xml/serializer.h>
#include "ioHelpers.h"
#include <sys/stat.h>
-int16_t
-makeHostID()
+std::string
+NetFSDaemon::hostname()
{
char buf[128];
gethostname(buf, sizeof(buf));
- boost::crc_basic<16> crc_ccitt1( 0x1021, 0xFFFF, 0, false, false );
- crc_ccitt1.process_bytes(buf, sizeof(buf));
- return crc_ccitt1.checksum();
+ return buf;
}
// name = NetFSDaemonAdapter
void
NetFSDaemon::start(const std::string & name, const Ice::CommunicatorPtr & ic, const Ice::StringSeq&)
{
+ this->ic = ic;
Ice::PropertiesPtr props = ic->getProperties();
- dc = DaemonConfig::Load(props->getProperty("NetFSD.ConfigPath"));
+ LoadConfiguration(props->getProperty("NetFSD.ConfigPath"));
- int16_t hostseed = makeHostID();
- adapter = ic->createObjectAdapterWithEndpoints(name, dc->self->iceEndpoint);
- adapter->add(new ServiceServer(hostseed, dc), ic->stringToIdentity("Service"));
+ adapter = ic->createObjectAdapterWithEndpoints(name, dc->Self->Endpoint);
+ adapter->add(new ServiceServer(dc->CurrentConfiguration), ic->stringToIdentity("Service"));
adapter->activate();
}
void
+NetFSDaemon::LoadConfiguration(const boost::filesystem::path & path)
+{
+ dc = new NetFS::Daemon::RuntimeConfiguration();
+ dc->CurrentConfiguration = Slicer::Deserialize<Slicer::Xml, NetFS::Daemon::Configuration>(path);
+ auto selfItr = dc->CurrentConfiguration->Hosts.find(hostname());
+ if (selfItr == dc->CurrentConfiguration->Hosts.end()) {
+ throw std::runtime_error("This host is not defined in the configuration.");
+ }
+ dc->Self = selfItr->second;
+}
+
+void
NetFSDaemon::stop()
{
adapter->deactivate();