Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

connection.h

Go to the documentation of this file.
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  * Copyright (c) 2004 Mark Rowe. All rights reserved.
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  */
00025 
00026 #include <string>
00027 #include <list>
00028 #include <vector>
00029 #include <map>
00030 #include <msn/sstream_fix.h>
00031 #include <stdexcept>
00032 
00033 namespace MSN
00034 {
00035     class callback;
00036     class Message;
00037     class Passport;
00038     class NotificationServerConnection;
00039     
00049     class Connection
00050     {      
00051 public:
00058         int sock;
00059         
00067         bool connected;
00068         
00069 protected:
00072         int trID;
00073         
00074         std::string readBuffer;
00075 public: 
00076         void * user_data;
00077         
00078         Connection();
00079         virtual ~Connection();
00080         
00085         virtual void dispatchCommand(std::vector<std::string> & args) = 0;
00086         
00091         std::vector<std::string> getLine();
00092         
00093         bool isWholeLineAvailable();
00094         bool bytesAvailable();
00095         
00099         virtual size_t write(std::string s, bool log=true) throw (std::runtime_error);
00100         
00110         virtual size_t write(std::ostringstream & s, bool log=true) throw (std::runtime_error);
00111                 
00114         virtual void connect(const std::string & hostname, unsigned int port) = 0;
00115         virtual void disconnect() = 0;
00116         
00126         virtual void dataArrivedOnSocket();
00127         
00130         virtual void socketConnectionCompleted();
00131         
00132         virtual void socketIsWritable() {};
00133         
00136         virtual void errorOnSocket(int errno_);
00142         void showError(int errorCode);
00143         
00146         bool isConnected() { return this->connected; };
00147         virtual NotificationServerConnection *myNotificationServer() = 0;        
00148 
00149 protected:
00156         void handle_MSG(std::vector<std::string> & args);
00157         
00158         virtual void handleIncomingData() = 0;
00159 private:
00160         std::string writeBuffer;
00161         static std::map<std::string, void (Connection::*)(std::vector<std::string> &, std::string, std::string)> messageHandlers;
00162         void message_plain(std::vector<std::string> & args, std::string mime, std::string body);
00163         void message_initial_email_notification(std::vector<std::string> & args, std::string mime, std::string body);
00164         void message_email_notification(std::vector<std::string> & args, std::string mime, std::string body);
00165         void message_invitation(std::vector<std::string> & args, std::string mime, std::string body);
00166         void message_typing_user(std::vector<std::string> & args, std::string mime, std::string body);
00167     };
00168 }
00169 #endif

Generated on Sun Feb 6 19:59:40 2005 for libmsn by  doxygen 1.4.1