diff options
Diffstat (limited to 'project2/ice/slice2DaemonLoader.cpp')
-rw-r--r-- | project2/ice/slice2DaemonLoader.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/project2/ice/slice2DaemonLoader.cpp b/project2/ice/slice2DaemonLoader.cpp new file mode 100644 index 0000000..81fd501 --- /dev/null +++ b/project2/ice/slice2DaemonLoader.cpp @@ -0,0 +1,46 @@ +#include <pch.hpp> +#include "slice2DaemonLoader.h" +#include <boost/foreach.hpp> + +Slice2DaemonLoader::Slice2DaemonLoader(FILE * c) : + code(c) +{ +} + +bool +Slice2DaemonLoader::visitModuleStart(const Slice::ModulePtr & m) +{ + module = m->name(); + fprintf(code, "// Loader for %s\n", m->name().c_str()); + fprintf(code, "class %sIceDaemonAdapterHandler : public IceDaemonAdapterHandler {\n", m->name().c_str()); + fprintf(code, "\tpublic:\n"); + return true; +} + +bool +Slice2DaemonLoader::visitClassDefStart(const Slice::ClassDefPtr & c) +{ + interfaces.push_back(c->name()); + return false; +} + +void +Slice2DaemonLoader::visitModuleEnd(const Slice::ModulePtr & m) +{ + fprintf(code, "\t\tvoid add(Ice::ObjectAdapterPtr adapter, const IceDaemon * id, Ice::CommunicatorPtr ic) const {\n"); + BOOST_FOREACH(const auto & i, interfaces) { + fprintf(code, "\t\t\tadapter->add(new %s::%sImpl(id), ic->stringToIdentity(\"%s%s\"));\n", + module.c_str(), i.c_str(), module.c_str(), i.c_str()); + } + fprintf(code, "\t\t}\n\n"); + fprintf(code, "\t\tvoid remove(Ice::ObjectAdapterPtr adapter, Ice::CommunicatorPtr ic) const {\n"); + BOOST_FOREACH(const auto & i, interfaces) { + fprintf(code, "\t\t\tadapter->remove(ic->stringToIdentity(\"%s%s\"));\n", + module.c_str(), i.c_str()); + } + fprintf(code, "\t\t}\n\n"); + fprintf(code, "};\n"); + fprintf(code, "DECLARE_GENERIC_LOADER(\"%s\", IceDaemonAdapterHandlerLoader, %sIceDaemonAdapterHandler);\n", m->name().c_str(), m->name().c_str()); + fprintf(code, "// End loader for%s\n\n", m->name().c_str()); +} + |