1 /* 2 * This file is part of Wireless Display Software for Linux OS 3 * 4 * Copyright (C) 2014 Intel Corporation. 5 * 6 * Contact: Jussi Laako <jussi.laako@linux.intel.com> 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 21 * 02110-1301 USA 22 */ 23 24 25 #ifndef MIRAC_NETWORK_HPP 26 #define MIRAC_NETWORK_HPP 27 28 #include <cstring> 29 #include <string> 30 31 #include "mirac-exception.hpp" 32 33 34 class MiracConnectionLostException : public MiracException 35 { 36 public: MiracConnectionLostException(const char * function=NULL)37 MiracConnectionLostException (const char *function = NULL) throw () 38 { 39 msg = std::string("Connection lost"); 40 add_func(function); 41 } ~MiracConnectionLostException()42 virtual ~MiracConnectionLostException () throw () 43 { } 44 }; 45 46 47 48 class MiracNetwork 49 { 50 public: 51 MiracNetwork (); 52 MiracNetwork (int conn_handle); 53 virtual ~MiracNetwork (); 54 void Bind (const char *address, const char *service); 55 MiracNetwork * Accept (); 56 bool Connect (const char *address, const char *service); GetHandle() const57 int GetHandle () const 58 { return handle; } 59 std::string GetPeerAddress (); 60 unsigned short GetHostPort (); 61 bool Receive (std::string &message); 62 bool Receive (std::string &message, size_t length); 63 bool Send (const std::string &message = std::string()); 64 65 protected: 66 int handle; 67 size_t page_size; 68 std::string recv_buf; 69 std::string send_buf; 70 71 void Init (); 72 void Close (); 73 74 private: 75 void *conn_ares; 76 void *conn_aptr; 77 }; 78 79 80 #endif /* MIRAC_NETWORK_HPP */ 81 82