asioconnector.h

00001 // Copyright (C) 2008,2009,2010 by Philipp Münzel. All rights reserved.
00002 // Released under the terms of the license described in license.txt
00003 
00004 #ifndef ASIOCONNECTOR_H
00005 #define ASIOCONNECTOR_H
00006 
00007 #include "dllexport.h"
00008 
00009 #include <string>
00010 #include <memory>
00011 #include <boost/asio.hpp>
00012 #include <boost/thread.hpp>
00013 
00014 #include "canaerotypes.h"
00015 #include "connector.h"
00016 #include "udpsender.h"
00017 #include "udpreceiver.h"
00018 
00019 namespace SCS {
00020 
00033 class DLL_PUBLIC ASIOConnector: public NetworkConnector<can_t>
00034 {
00035 public:
00041     ASIOConnector(const std::string& host_addr,
00042                   int incoming_port,
00043                   int outgoing_port);
00044 
00048     ~ASIOConnector();
00049 
00054     void setListener(BusConnector<can_t>* listener);
00055 
00060     void send(const void* msg, std::size_t bytes);
00061 
00062 
00063 private:
00067     void runIService();
00068 
00072     void runOService();
00073 
00077     void receive(void* msg, std::size_t bytes_recvd);
00078 
00079 private:
00080     boost::asio::io_service m_o_service;
00081     boost::asio::io_service m_i_service;
00082     std::auto_ptr<UDPSender> m_sender;
00083     std::auto_ptr<UDPReceiver> m_receiver;
00084     std::auto_ptr<boost::asio::io_service::work> m_o_work;
00085     std::auto_ptr<boost::asio::io_service::work> m_i_work;
00086     boost::thread m_sender_thread;
00087     boost::thread m_receiver_thread;
00088     BusConnector<can_t>* m_connector;
00089 };
00090 
00091 }
00092 
00093 #endif // ASIOCONNECTOR_H