00001 /* boss_cscomm.h $Revision: 1.5 $ $Date: 2005/12/10 20:33:54 $ 00002 Copyright (C) 2001 University of Bonn. 00003 http://www.ikp.uni-bonn.de/boss 00004 00005 This program is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU General Public License 00007 as published by the Free Software Foundation; either version 2 00008 of the License, or (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place - Suite 330, 00018 Boston, MA 02111-1307, USA. 00019 */ 00020 00021 #ifndef __BOSSCSCOMMH__ 00022 #define __BOSSCSCOMMH__ 00023 00024 using namespace std; 00025 00026 #include <sys/types.h> 00027 #include <sys/socket.h> 00028 #include <sys/poll.h> 00029 #include <netinet/in.h> 00030 #include <arpa/inet.h> 00031 #include <unistd.h> 00032 #include <netdb.h> 00033 #include <errno.h> 00034 #include <stdio.h> 00035 #include <inttypes.h> 00036 00037 #include <string> 00038 #include <fstream> 00039 00040 00041 #define DEF_PORT_ID 27673 00042 00043 typedef enum {SERVER, CLIENT} ConnectionType; 00044 00045 struct Signal { 00046 string id; 00047 uint32_t size; 00048 short * signal; 00049 }; 00050 00051 struct Document { 00052 string id; 00053 string doc; 00054 }; 00055 00062 class BOSSCSComm { 00063 private: 00064 int server_socket,boss_socket; 00065 struct sockaddr_in serv_addr; 00066 socklen_t sock_len; 00067 ConnectionType type; 00068 uint32_t readSize(); 00069 char * readBytes(uint32_t & size); 00070 void writeSize(uint32_t size); 00071 public: 00072 BOSSCSComm(const string & host_name, const ConnectionType & T, const short port_id); 00073 ~BOSSCSComm(); 00074 void sendDocument(const string & id, const string & s); 00075 void sendSignal(const string & id, const char * d, const uint32_t & s); 00076 Document receiveDocument(); 00077 Signal receiveSignal(); 00078 string acceptConnection(); 00079 void closeSock(); 00080 void closeServer(); 00081 }; 00082 00083 #endif