first skeleton
authorMichal Voců <michal@ruk.cuni.cz>
Wed, 20 Jan 2010 19:23:24 +0000 (19:23 +0000)
committerMichal Voců <michal@ruk.cuni.cz>
Wed, 20 Jan 2010 19:23:24 +0000 (19:23 +0000)
org.glite.lb.logger/src/activemq_cpp_plugin.cpp [new file with mode: 0644]

diff --git a/org.glite.lb.logger/src/activemq_cpp_plugin.cpp b/org.glite.lb.logger/src/activemq_cpp_plugin.cpp
new file mode 100644 (file)
index 0000000..e6ca060
--- /dev/null
@@ -0,0 +1,104 @@
+#ident "$Header$"
+
+/*
+ * activemq_cpp_plugin.cpp
+ *
+ *  Created on: Jan 20, 2010
+ *      Author: michal
+ */
+
+#include "interlogd.h"
+
+#include <cms/ConnectionFactory.h>
+#include <string>
+
+class OutputPlugin {
+
+public:
+
+       OutputPlugin() : connection(NULL) {};
+
+       virtual void onException(const cms::CMSException &ex);
+
+public:
+
+       cms::Session *session;
+       cms::Topic   *destination;
+       cms::MessageProducer *producer;
+
+       static cms::Connection *connection;
+       static cms::ConnectionFactory *connectionFactory = NULL;
+
+};
+
+
+extern "C"
+int
+event_queue_connect(struct event_queue *eq)
+{
+       OutputPlugin *output;
+       std::string topicName;
+
+       if(eq->plugin_data == NULL) {
+               output = new OutputPlugin();
+               eq->plugin_data = (void*)output;
+       } else {
+               output = (OutputPlugin*)eq->plugin_data;
+       }
+
+       output->session = OutputPlugin::connection->createSession(/* TODO: ackMode */);
+       output->destination = output->session->createTopic(topicName);
+       output->producer = output->session->createProducer(output->destination);
+       OutputPlugin::connection->start();
+
+       return 0;
+}
+
+
+extern "C"
+int
+event_queue_send(struct event_queue *eq)
+{
+       return 0;
+}
+
+
+extern "C"
+int
+event_queue_close(struct event_queue *eq)
+{
+       OutputPlugin *output = (OutputPlugin*)eq->plugin_data;
+
+       assert(output != NULL);
+
+       OutputPlugin::connection->stop();
+
+       return 0;
+}
+
+
+extern "C"
+int
+plugin_init()
+{
+       std::string brokerURI;
+
+       try {
+               activemq::library::ActiveMQCPP::initializeLibrary();
+
+               OutputPlugin::connectionFactory = cms::ConnectionFactory::createCMSConnectionFactory(brokerURI);
+               OutputPlugin::connection = output->connectionFactory->createConnection();
+       } catch (cms::CMSException e) {
+               return -1;
+       }
+
+       return 0;
+}
+
+
+extern "C"
+int
+plugin_supports_scheme(const char *scheme)
+{
+
+}