00001 /* 00002 Copyright (c) 2010, Dan Bethell, Johannes Saam. 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without modification, 00006 are permitted provided that the following conditions are met: 00007 00008 * Redistributions of source code must retain the above copyright notice, 00009 this list of conditions and the following disclaimer. 00010 00011 * Redistributions in binary form must reproduce the above copyright notice, 00012 this list of conditions and the following disclaimer in the documentation 00013 and/or other materials provided with the distribution. 00014 00015 * Neither the name of RmanConnect nor the names of its contributors may be 00016 used to endorse or promote products derived from this software without 00017 specific prior written permission. 00018 00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00020 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00021 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00022 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 00023 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00024 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00025 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00026 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 */ 00030 00031 #ifndef RMAN_CONNECT_SERVER_H_ 00032 #define RMAN_CONNECT_SERVER_H_ 00033 00034 #include "Data.h" 00035 #include <boost/asio.hpp> 00036 00038 namespace rmanconnect 00039 { 00046 class Server 00047 { 00048 public: 00054 Server(); 00060 Server( int port ); 00066 ~Server(); 00067 00075 void connect( int port, bool seach=false ); 00076 00079 void accept(); 00080 00089 Data listen(); 00090 00096 void quit(); 00097 00099 bool isConnected(){ return mAcceptor.is_open(); } 00100 00102 int getPort(){ return mPort; } 00103 00104 private: 00105 00106 // the port we're listening to 00107 int mPort; 00108 00109 // boost::asio tcp stuff 00110 boost::asio::io_service mIoService; 00111 boost::asio::ip::tcp::socket mSocket; 00112 boost::asio::ip::tcp::acceptor mAcceptor; 00113 }; 00114 } 00115 00267 #endif // RMAN_CONNECT_SERVER_H_