ircproxy The Ultimate Cyborg |
#include <Target.h>
This class represents the target that IRC messages can be targetted at.
Definition at line 40 of file Target.h.
Public Member Functions | |
virtual | ~Target () |
Destructor. | |
Network const & | network (void) const |
Return the network that this target belongs to. | |
Network & | network (void) |
Return the network that this target belongs to. | |
void | sub_channel (Identity &identity) |
virtual void | new_client_message_received (ClientMessageIn const &)=0 |
This is called when a new message targetted at this target is received. | |
virtual void | new_server_message_received (ServerMessageIn const &)=0 |
This is called when a new message targetted at this target is received. | |
Static Public Member Functions | |
static boost::shared_ptr< Channel > | add_channel (Identity &identity, std::string const &channel_name) |
Add a (non-existent) new channel with name channel_name. | |
static void | serverside_add_channel (ServerSession &server_session, boost::shared_ptr< Channel > new_channel) |
static boost::shared_ptr< Channel > | serverside_get_channel (Identity &identity, std::string const &channel_name, bool joined=false) |
Retrieve a shared pointer to the Channel object for channel_name. | |
static boost::shared_ptr< Channel > | clientside_get_channel (Identity const &identity, std::string const &channel_name) |
Retrieve a shared pointer to the Channel object for channel_name. | |
static boost::shared_ptr< Nick > | add_joined_nick (Identity &identity, std::string const &nick_name, boost::shared_ptr< Channel > &channel) |
Add a new nick with name nick_name to the joined channel with name channel_name. | |
static boost::shared_ptr< Nick > | get_joined_nick (Identity &identity, std::string const &nick_name, boost::shared_ptr< Channel > &channel) |
Return a shared pointer to the Nick object with name nick_name that is joined to channel channel. | |
Protected Member Functions | |
Target (Network *network) | |
Protected constructor. Use Target::get to access a target by name. | |
Protected Attributes | |
Network * | M_network |
The underlying network. |
Target::Target | ( | Network * | network | ) | [inline, protected] |
Target::~Target | ( | ) | [virtual] |
Destructor.
Definition at line 30 of file Target.cc.
References ASSERT, Network::is_private(), M_network, debug::channels::dc::maps, Network::name(), debug::channels::dc::objects, and Network::targets().
00031 { 00032 #if 0 // FIXME 00033 ASSERT(!debug::secondary_connection); 00034 Dout(dc::objects, "Destructing Target \"" << M_serverside_name << "\" of network \"" << M_network->name() << "\"."); 00035 // Of course, we also get here for private targets; however -- private targets 00036 // are never added to M_network.targets() (see assertion in Target::add). 00037 if (!M_network->is_private()) 00038 { 00039 target_lookup_map_type::iterator iter = M_network->targets().find(M_serverside_name); 00040 // This map only contains targets that are on common channels. 00041 if (iter != M_network->targets().end()) 00042 { 00043 Dout(dc::maps, "Erasing " << M_serverside_name << " from Network map."); 00044 M_network->targets().erase(iter); 00045 } 00046 #ifdef CWDEBUG 00047 else 00048 Dout(dc::notice, "Could not find \"" << M_serverside_name << "\" in network map " << M_network->targets()); 00049 #endif 00050 } 00051 #endif 00052 }
Network const& Target::network | ( | void | ) | const [inline] |
Return the network that this target belongs to.
Definition at line 53 of file Target.h.
References M_network.
Referenced by add_channel(), add_joined_nick(), and get_joined_nick().
00053 { return *M_network; }
Network& Target::network | ( | void | ) | [inline] |
boost::shared_ptr< Channel > Target::add_channel | ( | Identity & | identity, | |
std::string const & | channel_name | |||
) | [static] |
Add a (non-existent) new channel with name channel_name.
Definition at line 136 of file Target.cc.
References ASSERT, Identity::client_session(), DoutEntering, is_channel(), ClientSession::joined_channels(), ServerSession::joined_channels(), debug::channels::dc::maps, ServerConnection::network(), network(), Identity::server_connection(), Identity::server_session(), serverside_add_channel(), and Network::targets().
Referenced by serverside_get_channel().
00137 { 00138 ASSERT(!debug::secondary_connection); 00139 DoutEntering(dc::maps|dc::debug, "Target::add_channel(" << identity << ", \"" << channel_name << "\")"); 00140 // A new channel is always added on both, server and client side with the same name. 00141 #ifdef CWDEBUG 00142 ASSERT(is_channel(channel_name)); 00143 ServerSession::joined_channels_type::iterator iter1 = identity.server_session().joined_channels().find(channel_name); 00144 ClientSession::joined_channels_type::iterator iter2 = identity.client_session().joined_channels().find(channel_name); 00145 ASSERT(iter1 == identity.server_session().joined_channels().end() && 00146 iter2 == identity.client_session().joined_channels().end()); 00147 #endif 00148 boost::shared_ptr<Channel> new_channel; 00149 Network& network(identity.server_connection().network()); 00150 target_lookup_map_type::iterator network_iter = network.targets().find(channel_name); 00151 if (network_iter != network.targets().end()) 00152 new_channel = boost::static_pointer_cast<Channel>(network_iter->second.lock()); 00153 else 00154 { 00155 Channel* channel = new Channel(identity, channel_name, network); 00156 AllocTag(channel, channel_name); 00157 new_channel.reset(channel); 00158 } 00159 Target::serverside_add_channel(identity.server_session(), new_channel); 00160 Dout(dc::maps, "Inserting " << channel_name << " in clientside joined_channels map."); 00161 #if defined(CWDEBUG) || defined(DEBUG) 00162 std::pair<ClientSession::joined_channels_type::iterator, bool> clientside_res = 00163 #endif 00164 identity.client_session().joined_channels().insert(ClientSession::joined_channels_type::value_type(channel_name, new_channel)); 00165 ASSERT(clientside_res.second); 00166 return new_channel; 00167 }
void Target::sub_channel | ( | Identity & | identity | ) |
Remove this channel from the channel maps. Does the opposite of add_channel. Should only be called for channels that we have joined.
Definition at line 169 of file Target.cc.
References ASSERT, Identity::client_session(), DoutEntering, is_channel(), ClientSession::joined_channels(), ServerSession::joined_channels(), debug::channels::dc::maps, Channel::members(), Identity::mynick(), Identity::server_session(), and Channel::sub_joined_nick().
Referenced by Channel::new_server_message_received().
00170 { 00171 #if 0 // FIXME 00172 ASSERT(!debug::secondary_connection); 00173 DoutEntering(dc::maps|dc::debug, "Target::sub_channel(" << identity << ") for " << *this); 00174 ASSERT(is_channel(M_serverside_name)); 00175 Channel& channel(*static_cast<Channel*>(this)); 00176 channel.sub_joined_nick(identity.mynick()); 00177 for (Channel::members_type::iterator iter = channel.members().begin(); iter != channel.members().end(); ++iter) 00178 iter->second.get_nick()->sub_channel(channel); 00179 ServerSession::joined_channels_type::iterator iter1 = identity.server_session().joined_channels().find(M_serverside_name); 00180 ClientSession::joined_channels_type::iterator iter2 = identity.client_session().joined_channels().find(M_clientside_name); 00181 ASSERT(iter1 != identity.server_session().joined_channels().end() && 00182 iter2 != identity.client_session().joined_channels().end()); 00183 Dout(dc::maps, "Erasing " << M_serverside_name << " from serverside joined_channels map."); 00184 identity.server_session().joined_channels().erase(iter1); 00185 Dout(dc::maps, "Erasing " << M_clientside_name << " from clientside joined_channels map."); 00186 identity.client_session().joined_channels().erase(iter2); 00187 #endif 00188 }
void Target::serverside_add_channel | ( | ServerSession & | server_session, | |
boost::shared_ptr< Channel > | new_channel | |||
) | [static] |
For internal use only.
Definition at line 116 of file Target.cc.
References ASSERT, is_channel(), ServerSession::joined_channels(), debug::channels::dc::maps, ServerConnection::network(), ServerSession::server_connection(), and Network::targets().
Referenced by add_channel(), and ServerSession::new_message_received().
00117 { 00118 #if 0 00119 std::string channel_name(new_channel->serverside_name()); 00120 ASSERT(is_channel(channel_name)); 00121 std::pair<target_lookup_map_type::iterator, bool> res = 00122 server_session.server_connection().network().targets().insert(target_lookup_map_type::value_type(channel_name, new_channel)); 00123 #ifdef CWDEBUG 00124 if (res.second) 00125 Dout(dc::maps, "Inserted " << channel_name << " in Network map."); 00126 #endif 00127 Dout(dc::maps, "Inserting " << channel_name << " in serverside joined_channels map."); 00128 #if defined(CWDEBUG) || defined(DEBUG) 00129 std::pair<ClientSession::joined_channels_type::iterator, bool> serverside_res = 00130 #endif 00131 server_session.joined_channels().insert(ServerSession::joined_channels_type::value_type(channel_name, new_channel)); 00132 ASSERT(serverside_res.second); 00133 #endif 00134 }
boost::shared_ptr< Channel > Target::serverside_get_channel | ( | Identity & | identity, | |
std::string const & | channel_name, | |||
bool | joined = false | |||
) | [static] |
Retrieve a shared pointer to the Channel object for channel_name.
Definition at line 190 of file Target.cc.
References add_channel(), ASSERT, is_channel(), ServerSession::joined_channels(), Identity::key(), Identity::server_session(), and THROW_EXCEPTION.
Referenced by Identity::new_server_message_received(), and Channel::new_server_message_received().
00191 { 00192 ASSERT(!debug::secondary_connection); 00193 ASSERT(is_channel(channel_name)); 00194 00195 // Search in the serverside channels map of this session. 00196 ServerSession::joined_channels_type::iterator iter = 00197 (channel_name[0] == '@') ? identity.server_session().joined_channels().find(channel_name.substr(1)) 00198 : identity.server_session().joined_channels().find(channel_name); 00199 if (iter != identity.server_session().joined_channels().end()) 00200 return boost::static_pointer_cast<Channel>(iter->second); 00201 00202 if (joined) 00203 return Target::add_channel(identity, channel_name); 00204 00205 THROW_EXCEPTION(unknown_target(), "The identity " << identity.key() << " has no server side channel \"" << channel_name << "\""); 00206 }
boost::shared_ptr< Channel > Target::clientside_get_channel | ( | Identity const & | identity, | |
std::string const & | channel_name | |||
) | [static] |
Retrieve a shared pointer to the Channel object for channel_name.
Definition at line 208 of file Target.cc.
References ASSERT, Identity::client_session(), is_channel(), ClientSession::joined_channels(), Identity::key(), ClientSession::private_targets(), and THROW_EXCEPTION.
Referenced by Identity::new_client_message_received().
00209 { 00210 ASSERT(!debug::secondary_connection); 00211 ASSERT(is_channel(channel_name)); 00212 00213 // First search in the map with private channels. 00214 ClientSession::private_targets_type::const_iterator priv_iter = identity.client_session().private_targets().find(channel_name); 00215 if (priv_iter != identity.client_session().private_targets().end()) 00216 return boost::static_pointer_cast<Channel>(priv_iter->second); 00217 00218 // If we still didn't find it, search in the clientside channels map of this session. 00219 ClientSession::joined_channels_type::const_iterator iter = identity.client_session().joined_channels().find(channel_name); 00220 if (iter != identity.client_session().joined_channels().end()) 00221 return boost::static_pointer_cast<Channel>(iter->second); 00222 00223 THROW_EXCEPTION(unknown_target(), "The identity " << identity.key() << " has no client side channel \"" << channel_name << "\""); 00224 }
boost::shared_ptr< Nick > Target::add_joined_nick | ( | Identity & | identity, | |
std::string const & | nick_name, | |||
boost::shared_ptr< Channel > & | channel | |||
) | [static] |
Add a new nick with name nick_name to the joined channel with name channel_name.
Definition at line 73 of file Target.cc.
References ASSERT, DoutEntering, is_nick(), Network::is_private(), debug::channels::dc::maps, ServerConnection::network(), network(), Identity::server_connection(), and Network::targets().
Referenced by Identity::new_server_message_received(), and Channel::new_server_message_received().
00074 { 00075 #if 0 00076 ASSERT(!debug::secondary_connection); 00077 DoutEntering(dc::maps|dc::debug, "Target::add_joined_nick(" << identity << ", \"" << nick_name << "\", \"" << channel->serverside_name() << "\")"); 00078 ASSERT(is_nick(nick_name)); 00079 00080 boost::shared_ptr<Nick> new_nick; 00081 // Get the network. 00082 Network& network(identity.server_connection().network()); 00083 ASSERT(!network.is_private()); 00084 // Get the nick, if any, or else create one. 00085 target_lookup_map_type::iterator network_iter = network.targets().find(nick_name); 00086 if (network_iter != network.targets().end()) 00087 new_nick = boost::static_pointer_cast<Nick>(network_iter->second.lock()); 00088 else 00089 { 00090 Nick* nick = new Nick(identity, nick_name, network); 00091 AllocTag(nick, nick_name); 00092 new_nick.reset(nick); 00093 Dout(dc::maps, "Inserting " << nick_name << " in Network map."); 00094 #if defined(CWDEBUG) || defined(DEBUG) 00095 std::pair<target_lookup_map_type::iterator, bool> res = 00096 #endif 00097 network.targets().insert(target_lookup_map_type::value_type(nick_name, new_nick)); 00098 ASSERT(res.second); 00099 } 00100 // Add the new nick to this channel. 00101 Dout(dc::maps, "Adding nick " << nick_name << " as member to " << channel->serverside_name()); 00102 #if defined(CWDEBUG) || defined(DEBUG) 00103 std::pair<Channel::members_type::iterator, bool> res = 00104 #endif 00105 channel->members().insert(Channel::members_type::value_type(nick_name, Member(new_nick))); 00106 ASSERT(res.second); 00107 new_nick->add_channel(channel); 00108 return new_nick; 00109 #endif 00110 }
boost::shared_ptr< Nick > Target::get_joined_nick | ( | Identity & | identity, | |
std::string const & | nick_name, | |||
boost::shared_ptr< Channel > & | channel | |||
) | [static] |
Return a shared pointer to the Nick object with name nick_name that is joined to channel channel.
Definition at line 54 of file Target.cc.
References ASSERT, DoutEntering, is_nick(), Network::is_private(), Identity::key(), ServerConnection::network(), network(), Identity::server_connection(), and THROW_EXCEPTION.
Referenced by Identity::new_server_message_received(), and Channel::new_server_message_received().
00055 { 00056 #if 0 00057 ASSERT(!debug::secondary_connection); 00058 DoutEntering(dc::debug, "Target::get_joined_nick(" << identity << ", \"" << nick_name << "\", \"" << channel->serverside_name() << "\")"); 00059 ASSERT(is_nick(nick_name)); 00060 00061 // Get the network. 00062 Network& network(identity.server_connection().network()); 00063 ASSERT(!network.is_private()); 00064 00065 Channel::members_type::iterator iter = channel->members().find(nick_name); 00066 if (iter == channel->members().end()) 00067 THROW_EXCEPTION(unknown_target(), "The identity " << identity.key() << " has no server side joined nick \"" << nick_name << "\" on channel " << channel); 00068 00069 return iter->second.get_nick(); 00070 #endif 00071 }
virtual void Target::new_client_message_received | ( | ClientMessageIn const & | ) | [pure virtual] |
This is called when a new message targetted at this target is received.
Implemented in Channel, Nick, NoticeTarget, PrivateTarget, and QuestionTarget.
virtual void Target::new_server_message_received | ( | ServerMessageIn const & | ) | [pure virtual] |
This is called when a new message targetted at this target is received.
Implemented in Channel, Nick, and PrivateTarget.
Network* Target::M_network [protected] |
The underlying network.
Definition at line 42 of file Target.h.
Referenced by network(), Nick::serverside_nick_changed_to(), Nick::set_network(), and ~Target().
Copyright © 2005-2007 Carlo Wood. All rights reserved. |
---|