blob: 9e8a60a9dab879e62f8a170cfa5d536b2ed4b58c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
#include <Ice/Ice.h>
#include "daemon.h"
#include "daemonService.h"
#include "daemonVolume.h"
#include <slicer/slicer.h>
#include <xml/serializer.h>
#include "modeCheck.h"
#include <sys/stat.h>
NetFSDaemon::NetFSDaemon()
{
}
NetFSDaemon::~NetFSDaemon()
{
if (adapter) {
adapter->deactivate();
}
}
std::string
NetFSDaemon::hostname()
{
auto props = ic->getProperties();
auto hostNameOverride = props->getProperty("NetFSD.HostNameOverride");
if (hostNameOverride.empty()) {
char buf[128];
gethostname(buf, sizeof(buf));
return buf;
}
return hostNameOverride;
}
// name = NetFSDaemonAdapter
void
NetFSDaemon::start(const std::string & name, const Ice::CommunicatorPtr & ic, const Ice::StringSeq&)
{
this->ic = ic;
Ice::PropertiesPtr props = ic->getProperties();
LoadConfiguration(props->getProperty("NetFSD.ConfigPath"));
adapter = ic->createObjectAdapterWithEndpoints(name, dc->Self->Endpoint);
adapter->add(new ServiceServer(dc->CurrentConfiguration), ic->stringToIdentity("Service"));
adapter->activate();
}
NetFS::Daemon::ConfigurationPtr
NetFSDaemon::ReadConfiguration(const boost::filesystem::path & path) const
{
return Slicer::Deserialize<Slicer::XmlFileDeserializer, NetFS::Daemon::Configuration>(path);
}
void
NetFSDaemon::LoadConfiguration(const boost::filesystem::path & path)
{
dc = new NetFS::Daemon::RuntimeConfiguration();
dc->CurrentConfiguration = ReadConfiguration(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();
adapter = nullptr;
}
extern "C" {
DLL_PUBLIC
IceBox::Service *
createNetFSDaemon(Ice::CommunicatorPtr)
{
return new NetFSDaemon();
}
}
|