Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / apps / drwho / PM_Client.cpp
blob1272a3fcdc45562b0702228e2d23c2d9c4cd5b60
1 #include "Options.h"
2 #include "PM_Server.h"
3 #include "PM_Client.h"
4 #include "ace/ACE.h"
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...
13 Protocol_Record *
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 ()),
19 prp->drwho_list_);
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 ());
26 prp->is_active_ = 1;
29 if (np->get_inactive_count () < current_node->get_inactive_count())
30 np->set_inactive_count (current_node->get_inactive_count ());
32 return prp;
35 // This routine does all the dirty work, and actually prints out the
36 // friends info in a nicely formatted manner.
38 void
39 PM_Client::process ()
41 const char *(Protocol_Record::*get_name)();
43 if (Options::get_opt (Options::PRINT_LOGIN_NAME))
44 get_name = &Protocol_Record::get_login;
45 else
46 get_name = &Protocol_Record::get_real;
48 int active_friends = 0;
49 int users = this->Protocol_Manager::get_total_users ();
51 ACE_DEBUG ((LM_DEBUG,
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 ();
61 prp != 0;
62 prp = this->Protocol_Manager::get_each_friend ())
64 ACE_DEBUG ((LM_DEBUG,
65 "%c%-*s [", (prp->is_active_ != 0 ? '*' : ' '),
66 this->max_key_length,
67 (prp->*get_name) ()));
69 for (Drwho_Node *np = prp->get_drwho_list (); ;)
71 ACE_DEBUG ((LM_DEBUG,
72 np->get_host_name (),
73 stdout));
75 active_friends += np->get_active_count ();
77 if (np->get_inactive_count () != 0)
79 if (np->get_active_count () != 0)
80 ACE_DEBUG ((LM_DEBUG,
81 "*(%d)",
82 np->get_active_count ()));
84 else if (np->get_active_count () > 1)
85 ACE_DEBUG ((LM_DEBUG,
86 "*(%d)",
87 np->get_active_count ()));
88 else if (np->get_active_count () == 1)
89 ACE_DEBUG ((LM_DEBUG,
90 "*"));
92 np = np->next_;
93 if (np == 0)
94 break;
95 else
96 ACE_DEBUG ((LM_DEBUG,
97 " "));
100 ACE_DEBUG ((LM_DEBUG,
101 "]\n"));
104 ACE_DEBUG ((LM_DEBUG,
105 "------------------------\n"));
106 ACE_DEBUG ((LM_DEBUG,
107 "friends: %d\tusers: %d\n",
108 active_friends,
109 users));
112 char *
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 ()
132 : max_key_length (0)
136 PM_Client::~PM_Client ()