00001 #ifndef CHAT_API_CLASS 00002 #define CHAT_API_CLASS 00003 00004 /*****************************************************************************\ 00005 * * 00006 * Name : chat_connection * 00007 * Author : Chris Koeritz * 00008 * * 00009 * Purpose: * 00010 * * 00011 * Provides an interface to chat services. This allows a user to send text * 00012 * messages as well as files and other objects to a correspondent. * 00013 * * 00014 ******************************************************************************* 00015 * Copyright (c) 2000-$now By Author. This program is free software; you can * 00016 * redistribute it and/or modify it under the terms of the GNU General Public * 00017 * License as published by the Free Software Foundation; either version 2 of * 00018 * the License or (at your option) any later version. This is online at: * 00019 * http://www.fsf.org/copyleft/gpl.html * 00020 * Please send any updates to: fred@gruntose.com * 00021 \*****************************************************************************/ 00022 00023 #include "buzz_dll.h" 00024 00025 #include <sockets/definitions_sockets.h> 00026 00027 // forward. 00028 class communicator; 00029 class extended_address; 00030 class filename; 00031 class transport; 00032 00033 class BUZZ_CLASS_STYLE chat_connection 00034 { 00035 public: 00036 enum chat_capabilities { 00037 SEND_TEXT = 0x1, // all chat connections should support this. 00038 SEND_FILE = 0x2, // many chat connections can support this. if initially 00039 // it is not supported, try using the renegotiate() 00040 // method to get the other side to allow it. 00041 }; 00042 00043 chat_connection(communicator &commlink, const extended_address &where, 00044 int capabilities); 00045 // makes a connection to the location "where", which can use any supported 00046 // network address type and mode. the health of the connection can be 00047 // tested with the connected() method. the "capabilities" should be a 00048 // bitwise OR of the chat_capabilities that you wish to allow. this list 00049 // can be changed on this side with the capabilities() modification method 00050 // and on the other side with the renegotiate() method. the "commlink" 00051 // must be provided and must exist through the lifetime of the chat. 00052 00053 virtual ~chat_connection(); 00054 // terminates the chat and shuts down the connection. 00055 00056 enum outcomes { 00057 OKAY = common::OKAY, 00058 00059 NO_CONNECTION = communication_commons::NO_CONNECTION, 00060 00061 DEFINE_OUTCOME(NO_CAPABILITY, -66, "The connection does not support " 00062 "this currently"), 00063 }; 00064 00065 const char *outcome_name(const outcome &outcome) const; 00066 // returns the name for the "outcome" specified. 00067 00068 bool connected() const; 00069 // returns true if the connection appears healthy. 00070 00071 // observes or modifies the path where downloaded files will be stored. 00072 // if this is a bad path, then no files can be downloaded. 00073 filename download_path() const; 00074 void download_path(const filename &path); 00075 00076 // capability management: 00077 00078 int capabilities() const; 00079 // returns the current set of capabilities for this chat connection as 00080 // a bit-wise ORed integer. testing using the chat_capabilities will 00081 // tell if a particular capability is enabled. 00082 void capabilities(int new_capabilities); 00083 // modifies the set of capabilities we allow on this side. 00084 00085 outcome renegotiate(int new_capability); 00086 // asks the other side if it will enable the new connection of 00087 // capabilities specified in the "new_capability". don't forget to OR 00088 // in all the current capabilities that you want as well as the new ones; 00089 // if a capability is omitted from the new value and this call succeeds, 00090 // then you will have less power than before. 00091 00092 // worker functions. 00093 00094 outcome send_string(const istring &to_send); 00095 // sends a textual message "to_send" to the other side. 00096 00097 outcome send_file(const istring &filename); 00098 // transmits a file pointed at by the "filename" to the other side. this 00099 // will only work if the connection supports the SEND_FILE capability. 00100 00101 bool get_string(istring &received); 00102 // retrieves the next textual message into "received". true is returned if 00103 // a message was available. 00104 00105 bool get_file(istring &path); 00106 // retrieves the next file that is available to the default download area 00107 // and stores the full path to the file in "path". 00108 00109 // alert functions; over-ride to hear the announcements. 00110 00111 virtual void renegotiation(); 00112 // invoked when the capabilities have changed, either by one's own request 00113 // or by the other side's request. 00114 00115 virtual void data_ready(); 00116 // either a text message is ready or there is a file waiting. 00117 00118 private: 00119 transport *_sender; // the communication support we use for sending. 00120 transport *_receiver; // the communication support we use for receptions. 00121 00122 // not permitted. 00123 chat_connection(chat_connection &); 00124 chat_connection &operator =(chat_connection &); 00125 }; 00126 00127 #endif 00128
1.5.1