libmsn 4.2.1
|
00001 #ifndef __msn_connection_h__ 00002 #define __msn_connection_h__ 00003 00004 /* 00005 * connection.h 00006 * libmsn 00007 * 00008 * Created by Mark Rowe on Mon Mar 22 2004. 00009 * Refactored by Tiago Salem Herrmann on 08/2007. 00010 * Copyright (c) 2004 Mark Rowe. All rights reserved. 00011 * Copyright (c) 2007 Tiago Salem Herrmann. All rights reserved 00012 * 00013 * This program is free software; you can redistribute it and/or modify 00014 * it under the terms of the GNU General Public License as published by 00015 * the Free Software Foundation; either version 2 of the License, or 00016 * (at your option) any later version. 00017 * 00018 * This program is distributed in the hope that it will be useful, 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 * GNU General Public License for more details. 00022 * 00023 * You should have received a copy of the GNU General Public License 00024 * along with this program; if not, write to the Free Software 00025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00026 */ 00027 #include <string> 00028 #include <list> 00029 #include <vector> 00030 #include <map> 00031 #include <stdexcept> 00032 00033 #ifdef _MSC_VER 00034 #pragma warning( disable : 4290 ) 00035 #endif 00036 00037 #include "libmsn_export.h" 00038 00039 namespace MSN 00040 { 00041 class callback; 00042 class Message; 00043 class Passport; 00044 class NotificationServerConnection; 00045 00052 class LIBMSN_EXPORT Connection 00053 { 00054 public: 00061 void *sock; 00062 00065 bool connected; 00066 00067 00068 protected: 00069 00070 std::string readBuffer; 00071 public: 00074 int trID; 00075 00076 Connection(); 00077 virtual ~Connection(); 00078 00083 virtual void dispatchCommand(std::vector<std::string> & args) = 0; 00084 00089 std::vector<std::string> getLine(); 00090 00091 bool isWholeLineAvailable(); 00092 bool bytesAvailable(); 00093 00097 virtual size_t write(std::string s, bool log=true) throw (std::runtime_error); 00098 00108 virtual size_t write(std::ostringstream & s, bool log=true) throw (std::runtime_error); 00109 00112 virtual void connect(const std::string & hostname, unsigned int port) = 0; 00113 virtual void disconnect() = 0; 00114 00124 virtual void dataArrivedOnSocket(); 00125 00128 virtual void socketConnectionCompleted(); 00129 00130 virtual void socketIsWritable() {}; 00131 00134 virtual void errorOnSocket(int errno_); 00140 void showError(int errorCode); 00141 00144 bool isConnected() { return this->connected; }; 00145 virtual NotificationServerConnection *myNotificationServer() = 0; 00146 00147 protected: 00148 virtual void handleIncomingData() = 0; 00149 private: 00150 std::string writeBuffer; 00151 }; 00152 } 00153 #endif