summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2013-09-06 22:39:56 +0000
committerrandomdan <randomdan@localhost>2013-09-06 22:39:56 +0000
commitf2489fbc3981b5ed219b95491a20cac649a27c10 (patch)
treeab9fc9039678811d2b55dd2fdd211ca1a34a1e22
parentAdd missing early return on XML parse error (diff)
downloadproject2-f2489fbc3981b5ed219b95491a20cac649a27c10.tar.bz2
project2-f2489fbc3981b5ed219b95491a20cac649a27c10.tar.xz
project2-f2489fbc3981b5ed219b95491a20cac649a27c10.zip
Basics for p2daemons
-rw-r--r--project2/Jamfile.jam7
-rw-r--r--project2/common/options.h1
-rw-r--r--project2/common/plugable.h2
-rw-r--r--project2/daemon/Jamfile.jam15
-rw-r--r--project2/daemon/lib/Jamfile.jam15
-rw-r--r--project2/daemon/lib/daemon.cpp10
-rw-r--r--project2/daemon/lib/daemon.h20
-rw-r--r--project2/daemon/p2daemonAppEngine.cpp39
-rw-r--r--project2/daemon/p2daemonAppEngine.h29
-rw-r--r--project2/daemon/p2daemonMain.cpp26
10 files changed, 163 insertions, 1 deletions
diff --git a/project2/Jamfile.jam b/project2/Jamfile.jam
index b2bd49a..c1a7c24 100644
--- a/project2/Jamfile.jam
+++ b/project2/Jamfile.jam
@@ -20,12 +20,17 @@ alias p2parts : : : :
<library>lib//p2lib
;
+alias p2daemonparts : : : :
+ ;
+
build-project console ;
build-project cgi ;
+build-project daemon ;
explicit install installp2con installp2cgi installp2fcgi ;
-package.install install : : console//p2console cgi//p2cgi cgi//p2fcgi ;
+package.install install : : console//p2console cgi//p2cgi cgi//p2fcgi daemon//p2daemon ;
package.install installp2con : : console//p2console ;
package.install installp2cgi : : cgi//p2cgi ;
package.install installp2fcgi : : cgi//p2fcgi ;
+package.install installp2daemon : : daemon//p2daemon ;
diff --git a/project2/common/options.h b/project2/common/options.h
index c2416ef..cee95d4 100644
--- a/project2/common/options.h
+++ b/project2/common/options.h
@@ -9,6 +9,7 @@
#include <boost/function.hpp>
#include <boost/utility/enable_if.hpp>
#include "variableType.h"
+#include "plugable.h"
class Options {
public:
diff --git a/project2/common/plugable.h b/project2/common/plugable.h
index 74a2019..4b46f8c 100644
--- a/project2/common/plugable.h
+++ b/project2/common/plugable.h
@@ -8,6 +8,8 @@
#include <boost/foreach.hpp>
#include "exceptions.h"
+class ComponentLoader;
+
class Plugable {
public:
template <class CT>
diff --git a/project2/daemon/Jamfile.jam b/project2/daemon/Jamfile.jam
new file mode 100644
index 0000000..123e6fc
--- /dev/null
+++ b/project2/daemon/Jamfile.jam
@@ -0,0 +1,15 @@
+alias glibmm : : : :
+ <cflags>"`pkg-config --cflags glibmm-2.4`"
+ <linkflags>"`pkg-config --libs glibmm-2.4`"
+ ;
+exe p2daemon :
+ [ glob *.cpp ]
+ :
+ <library>lib
+ <library>..//p2parts
+ <library>..//p2daemonparts
+ <library>../common//p2common
+ <library>../cli//p2cli
+ <include>../../libmisc
+ ;
+
diff --git a/project2/daemon/lib/Jamfile.jam b/project2/daemon/lib/Jamfile.jam
new file mode 100644
index 0000000..e028f19
--- /dev/null
+++ b/project2/daemon/lib/Jamfile.jam
@@ -0,0 +1,15 @@
+alias glibmm : : : :
+ <cflags>"`pkg-config --cflags glibmm-2.4`"
+ <linkflags>"`pkg-config --libs glibmm-2.4`"
+ ;
+lib p2daemonlib :
+ [ glob *.cpp ]
+ :
+ <include>../../../libmisc
+ <library>glibmm
+ <library>../../common//p2common
+ : :
+ <include>.
+ ;
+
+
diff --git a/project2/daemon/lib/daemon.cpp b/project2/daemon/lib/daemon.cpp
new file mode 100644
index 0000000..1a70fc1
--- /dev/null
+++ b/project2/daemon/lib/daemon.cpp
@@ -0,0 +1,10 @@
+#include "daemon.h"
+
+Daemon::Daemon()
+{
+}
+
+Daemon::~Daemon()
+{
+}
+
diff --git a/project2/daemon/lib/daemon.h b/project2/daemon/lib/daemon.h
new file mode 100644
index 0000000..106d3f4
--- /dev/null
+++ b/project2/daemon/lib/daemon.h
@@ -0,0 +1,20 @@
+#ifndef DAEMON_H
+#define DAEMON_H
+
+#include <glibmm/ustring.h>
+#include <genLoader.h>
+#include <intrusivePtrBase.h>
+
+class Daemon : public IntrusivePtrBase {
+ public:
+ Daemon();
+ virtual ~Daemon();
+
+ virtual void process() const = 0;
+};
+
+typedef boost::intrusive_ptr<Daemon> DaemonPtr;
+typedef GenLoader<Daemon, int &, char **> DaemonLoader;
+
+#endif
+
diff --git a/project2/daemon/p2daemonAppEngine.cpp b/project2/daemon/p2daemonAppEngine.cpp
new file mode 100644
index 0000000..62bcff7
--- /dev/null
+++ b/project2/daemon/p2daemonAppEngine.cpp
@@ -0,0 +1,39 @@
+#include "p2daemonAppEngine.h"
+#include <logger.h>
+#include <dlfcn.h>
+
+std::string DaemonAppEngine::daemonType;
+boost::optional<std::string> DaemonAppEngine::libraryPath;
+Glib::ustring DaemonAppEngine::reqPlatform;
+
+DECLARE_OPTIONS(DaemonAppEngine, "Project2 Daemon options")
+("daemon.type", Options::value(&daemonType), "The core daemon module to run")
+("daemon.library", Options::value(&libraryPath), "The optional library containing the core daemon to load")
+("daemon.platform", Options::value(&reqPlatform), "Platform")
+END_OPTIONS(DaemonAppEngine);
+
+DaemonAppEngine::DaemonAppEngine(int argc, char ** argv) :
+ library(!!libraryPath ? loadLibrary(*libraryPath) : boost::shared_ptr<void>()),
+ daemon(DaemonLoader::createNew(daemonType, argc, argv))
+{
+}
+
+void
+DaemonAppEngine::process() const
+{
+ Logger()->message(LOG_INFO, "Starting daemon.");
+ daemon->process();
+ Logger()->message(LOG_INFO, "Daemon exitted.");
+}
+
+boost::shared_ptr<void>
+DaemonAppEngine::loadLibrary(const std::string & path)
+{
+ void * handle = dlopen(path.c_str(), RTLD_NOW);
+ if (!handle) {
+ Logger()->messagebf(LOG_ERR, "Failed to load library '%s' (%s)", path, dlerror());
+ throw std::runtime_error("module load failed");
+ }
+ return boost::shared_ptr<void>(handle, &dlclose);
+}
+
diff --git a/project2/daemon/p2daemonAppEngine.h b/project2/daemon/p2daemonAppEngine.h
new file mode 100644
index 0000000..a74f34a
--- /dev/null
+++ b/project2/daemon/p2daemonAppEngine.h
@@ -0,0 +1,29 @@
+#ifndef DAEMONAPPENGINE_H
+#define DAEMONAPPENGINE_H
+
+#include <options.h>
+#include <boost/optional.hpp>
+#include "lib/daemon.h"
+
+class DaemonAppEngine {
+ public:
+ DaemonAppEngine(int, char **);
+ ~DaemonAppEngine() = default;
+
+ void process() const;
+
+ INITOPTIONS;
+
+ static Glib::ustring reqPlatform;
+ static std::string daemonType;
+ static boost::optional<std::string> libraryPath;
+
+ private:
+ static boost::shared_ptr<void> loadLibrary(const std::string & path);
+
+ boost::shared_ptr<void> library;
+ DaemonPtr daemon;
+};
+
+#endif
+
diff --git a/project2/daemon/p2daemonMain.cpp b/project2/daemon/p2daemonMain.cpp
new file mode 100644
index 0000000..2399827
--- /dev/null
+++ b/project2/daemon/p2daemonMain.cpp
@@ -0,0 +1,26 @@
+#include "pch.hpp"
+#include "p2daemonAppEngine.h"
+#include "optionsSource.h"
+#include "claOptions.h"
+#include <boost/bind.hpp>
+#include <options.h>
+
+SimpleMessageException(UnsupportedArguments);
+
+int
+main(int argc, char ** argv)
+{
+ Plugable::onAllComponents(boost::bind(&ComponentLoader::onBegin, _1));
+ Plugable::newLoader<OptionsSource, OptionsSource>("_2", new CommandLineArguments(argc, argv,
+ [](const char * a) { throw UnsupportedArguments(a); }));
+ OptionsSource::loadSources([] { return DaemonAppEngine::reqPlatform;} );
+ //Plugable::onAllComponents(boost::bind(&ComponentLoader::onBefore, _1));
+
+ DaemonAppEngine dae(argc, argv);
+ dae.process();
+
+ //Plugable::onAllComponents(boost::bind(&ComponentLoader::onIteration, _1));
+ //Plugable::onAllComponents(boost::bind(&ComponentLoader::onPeriodic, _1));
+ Plugable::onAllComponents(boost::bind(&ComponentLoader::onIdle, _1));
+}
+