Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / examples / Simple / chat / Broadcaster_i.cpp
blobbb8f3451a21f1c71117535381c88d978ab13b48f
1 //=============================================================================
2 /**
3 * @file Broadcaster_i.cpp
5 * Implementation of the Broadcaster_i class. This class is the servant
6 * object for the chat server.
8 * @author Pradeep Gore <pradeep@cs.wustl.edu>
9 */
10 //=============================================================================
12 #include "Broadcaster_i.h"
14 bool
15 Broadcaster_i::Receiver_Data::operator == (const Broadcaster_i::Receiver_Data &receiver_data) const
17 // The <_is_equivalent> function checks if the _var and _ptr objects
18 // are the same. NOTE: this call might not behave well on other
19 // ORBs since <_is_equivalent> isn't guaranteed to differentiate
20 // object references.
21 return
22 this->receiver_->_is_equivalent (receiver_data.receiver_.in ())
23 && this->nickname_ == receiver_data.nickname_;
26 void
27 Broadcaster_i::add (Receiver_ptr receiver,
28 const char *nickname)
30 Broadcaster_i::Receiver_Data receiver_data;
32 // Store the client information.
33 receiver_data.receiver_ = Receiver::_duplicate (receiver);
34 receiver_data.nickname_ = nickname;
36 // Insert the Receiver reference to the set
37 if (receiver_set_.insert (receiver_data) == -1)
38 throw Broadcaster::CannotAdd ("failed to add to the receiver set\n");
40 // Tell everyone which person just joined the chat.
41 ACE_CString broadcast_string =
42 ACE_CString ("**** ")
43 + ACE_CString (nickname)
44 + ACE_CString (" has joined the chat ****\n");
46 try
48 this->broadcast (broadcast_string.fast_rep ());
50 catch (const CORBA::Exception& ex)
52 ex._tao_print_exception ("Broadcaster_i::broadcast failed.\t\n");
56 void
57 Broadcaster_i::remove (Receiver_ptr receiver)
59 Broadcaster_i::Receiver_Data receiver_data_to_remove;
61 // Go through the list of <Receiver_Data> to find which registered client
62 // wants to be removed.
63 for (RECEIVER_SET_ITERATOR iter = this->receiver_set_.begin ();
64 iter != this->receiver_set_.end ();
65 iter++)
67 // The <_is_equivalent> function checks if the _var and _ptr objects
68 // are the same. NOTE: this call might not behave well on other
69 // ORBs since <_is_equivalent> isn't guaranteed to differentiate
70 // object references.
71 if ((*iter).receiver_.in ()->_is_equivalent (receiver) == 1)
73 receiver_data_to_remove = *iter;
74 break;
78 // Remove the reference from our list.
79 if (this->receiver_set_.remove (receiver_data_to_remove) == -1)
80 throw Broadcaster::CannotRemove ("failed to remove from receiver set\n");
82 // Tell everyone, which person left the chat.
83 ACE_CString broadcast_string = "**** "
84 + receiver_data_to_remove.nickname_
85 + " left the chat"
86 + " ****\n";
88 this->broadcast (broadcast_string.fast_rep ());
91 void
92 Broadcaster_i::say (Receiver_ptr receiver,
93 const char *text)
95 try
97 ACE_CString sender_nickname ("Sender Unknown");
99 // Find the nickname for this receiver.
101 for (RECEIVER_SET_ITERATOR iter = this->receiver_set_.begin ();
102 iter != this->receiver_set_.end ();
103 iter++)
105 // The <_is_equivalent> function checks if the _var and
106 // _ptr objects are the same. NOTE: this call might not
107 // behave well on other ORBs since <_is_equivalent> isn't
108 // guaranteed to differentiate object references.
109 if ((*iter).receiver_.in ()->_is_equivalent (receiver) == 1)
110 sender_nickname = (*iter).nickname_;
113 // Broadcast the message to all registered clients
114 ACE_CString broadcast_string ("[" + sender_nickname + "] " + text);
116 this->broadcast (broadcast_string.fast_rep ());
118 catch (const CORBA::Exception& ex)
120 ex._tao_print_exception ("Broadcaster_i::say\t\n");
124 void
125 Broadcaster_i::broadcast (const char *text)
127 // Broadcast the message to all registered clients.
129 for (RECEIVER_SET_ITERATOR iter = this->receiver_set_.begin ();
130 iter != this->receiver_set_.end ();
131 iter++)
135 (*iter).receiver_->message (text);
137 catch (const CORBA::Exception& ex)
139 ex._tao_print_exception ("Failed to send a message\n");