5 #include "ace/Log_Msg.h"
6 #include "ace/OS_NS_string.h"
7 #include "ace/OS_NS_stdlib.h"
9 // This function is used to merge the LOGIN_NAME from server HOST_NAME
10 // into the userids kept on the client's side. Note that we must
11 // allocate memory for HOST_NAME...
14 PM_Client::insert_protocol_info (Protocol_Record
&protocol_record
)
16 Protocol_Record
*prp
= this->ss
->insert (protocol_record
.get_login ());
17 Drwho_Node
*current_node
= protocol_record
.get_drwho_list ();
18 Drwho_Node
*np
= this->get_drwho_node (ACE::strnew (current_node
->get_host_name ()),
21 // Update the active and inactive counts.
23 if (np
->get_active_count () < current_node
->get_active_count ())
25 np
->set_active_count (current_node
->get_active_count ());
29 if (np
->get_inactive_count () < current_node
->get_inactive_count())
30 np
->set_inactive_count (current_node
->get_inactive_count ());
35 // This routine does all the dirty work, and actually prints out the
36 // friends info in a nicely formatted manner.
41 const char *(Protocol_Record::*get_name
)();
43 if (Options::get_opt (Options::PRINT_LOGIN_NAME
))
44 get_name
= &Protocol_Record::get_login
;
46 get_name
= &Protocol_Record::get_real
;
48 int active_friends
= 0;
49 int users
= this->Protocol_Manager::get_total_users ();
52 "------------------------\n"));
54 if (Options::get_opt (Options::PRINT_LOGIN_NAME
))
55 this->max_key_length
= MAXUSERIDNAMELEN
;
57 // Goes through the queue of all the logged in friends and prints
58 // out the associated information.
60 for (Protocol_Record
*prp
= this->Protocol_Manager::get_each_friend ();
62 prp
= this->Protocol_Manager::get_each_friend ())
65 "%c%-*s [", (prp
->is_active_
!= 0 ? '*' : ' '),
67 (prp
->*get_name
) ()));
69 for (Drwho_Node
*np
= prp
->get_drwho_list (); ;)
75 active_friends
+= np
->get_active_count ();
77 if (np
->get_inactive_count () != 0)
79 if (np
->get_active_count () != 0)
82 np
->get_active_count ()));
84 else if (np
->get_active_count () > 1)
87 np
->get_active_count ()));
88 else if (np
->get_active_count () == 1)
100 ACE_DEBUG ((LM_DEBUG
,
104 ACE_DEBUG ((LM_DEBUG
,
105 "------------------------\n"));
106 ACE_DEBUG ((LM_DEBUG
,
107 "friends: %d\tusers: %d\n",
113 PM_Client::handle_protocol_entries (const char *cp
,
114 const char *login_name
,
115 const char *real_name
)
117 static Protocol_Record
protocol_record (1);
118 Drwho_Node
*current_node
= protocol_record
.get_drwho_list ();
120 protocol_record
.set_login (login_name
);
121 protocol_record
.set_real (real_name
);
122 current_node
->set_inactive_count (ACE_OS::atoi (cp
));
123 current_node
->set_active_count (ACE_OS::atoi (cp
= ACE_OS::strchr (cp
, ' ') + 1));
124 current_node
->set_host_name (cp
= ACE_OS::strchr (cp
, ' ') + 1);
126 this->insert_protocol_info (protocol_record
);
128 return (char *) ACE::strend (cp
);
131 PM_Client::PM_Client ()
136 PM_Client::~PM_Client ()