Drizzled Public API Documentation

rabbitmq_handler.h
00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2010 Marcus Eriksson
00005  *
00006  *  Authors:
00007  *
00008  *  Marcus Eriksson <krummas@gmail.com>
00009  *
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License
00021  *  along with this program; if not, write to the Free Software
00022  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00023  */
00024 
00025 #pragma once
00026 
00027 #include <exception>
00028 #include <string>
00029 #include <amqp.h>
00030 #include <amqp_framing.h>
00031 #include <netinet/in.h>
00032 
00033 namespace drizzle_plugin
00034 {
00035 
00040 class rabbitmq_handler_exception : public std::exception
00041 {
00042 private:
00043   const char* message;
00044 public:
00045   rabbitmq_handler_exception(const char* m):message(m) {};
00046   rabbitmq_handler_exception(std::string m):message(m.c_str()) {};
00047   virtual const char* what() const throw()
00048   {
00049     return message;
00050   }
00051 };
00052 
00053 
00058 class RabbitMQHandler
00059 {
00060 private:
00061   amqp_connection_state_t rabbitmqConnection; 
00062   int sockfd; 
00063 
00064   const std::string &hostname;
00065   const in_port_t port;
00066   const std::string &username;
00067   const std::string &password;
00068   const std::string &virtualhost;
00069 public:
00086   RabbitMQHandler(const std::string &hostname, 
00087                   const in_port_t port, 
00088                   const std::string &username, 
00089                   const std::string &password, 
00090                   const std::string &virtualhost)
00091     throw(rabbitmq_handler_exception);
00092 
00093   ~RabbitMQHandler();
00094 
00108   void publish(void *message, 
00109                const int length, 
00110                const std::string &exchangeName, 
00111                const std::string &routingKey)
00112     throw(rabbitmq_handler_exception);
00113 
00114 
00115 private:
00128   void handleAMQPError(amqp_rpc_reply_t x, std::string context) throw(rabbitmq_handler_exception);
00129 };
00130 
00131 } /* namespace drizzle_plugin */
00132