Cleanup ACE_HAS_PTHREAD_SIGMASK_PROTOTYPE, all platforms support it so far as I can...
[ACE_TAO.git] / ACE / apps / drwho / PMC_Usr.cpp
blob5a4a00191a7e81a8c494d8f966a488402a93b9b7
1 #include "Options.h"
2 #include "SL_Client.h"
3 #include "PMC_Usr.h"
4 #include "ace/ACE.h"
5 #include "ace/Log_Msg.h"
6 #include "ace/OS_NS_string.h"
7 #include "ace/OS_NS_unistd.h"
8 #include "ace/OS_Memory.h"
10 int
11 PMC_Usr::encode (char *packet, int &packet_length)
13 if (Options::get_opt (Options::DEBUGGING) != 0)
14 ACE_DEBUG ((LM_DEBUG,
15 "in PMC_Usr::encode"));
17 ACE_NEW_RETURN (this->ss,
18 SL_Client (this->usr_name),
19 -1);
21 SET_PACKET_TYPE (packet, Options::PROTO_USR);
23 char *buf_ptr = SKIP_PACKET_TYPE (packet);
25 buf_ptr = ACE_OS::strecpy (buf_ptr,
26 this->get_next_friend ()->get_login ());
28 packet_length = buf_ptr - packet;
30 if (Options::get_opt (Options::DEBUGGING) != 0)
32 ACE_DEBUG ((LM_DEBUG,
33 "packet_length = %d\n",
34 packet_length));
35 ACE_OS::write (ACE_STDERR, packet, packet_length);
36 ACE_DEBUG ((LM_DEBUG,
37 "\n"));
39 return 1;
42 // This method is responsible for transforming the msg from the server
43 // back into a form usable by the client.
45 int
46 PMC_Usr::decode (char *packet, int &packet_length)
48 if (Options::get_opt (Options::DEBUGGING) != 0)
50 ACE_DEBUG ((LM_DEBUG,
51 "in PMC_Usr::decode, packet_length = %d\n",
52 packet_length));
53 ACE_OS::write (ACE_STDERR, packet, packet_length);
54 ACE_DEBUG ((LM_DEBUG,
55 "\n"));
58 char *cp = packet;
60 if (*cp != '\n')
62 char *login_name = cp;
64 for (cp = (char *) ACE::strend (cp);
65 *(cp = this->handle_protocol_entries (cp, login_name)) != '\t';
67 continue;
70 return 1;
73 void
74 PMC_Usr::process ()
76 Protocol_Record *prp = this->get_each_friend ();
77 Drwho_Node *np = prp->get_drwho_list ();
79 if (np == 0)
80 ACE_DEBUG ((LM_DEBUG,
81 "<unknown>"));
82 else
84 // First try to get a login session that is active...
86 for (; np != 0; np = np->next_)
87 if (np->active_count_ > 0)
89 ACE_DEBUG ((LM_DEBUG,
90 "%s ",
91 np->get_host_name ()));
93 if (Options::get_opt (Options::USE_VERBOSE_FORMAT) == 0)
94 return;
97 for (np = prp->get_drwho_list ();
98 np != 0;
99 np = np->next_)
100 if (np->active_count_ == 0)
102 ACE_DEBUG ((LM_DEBUG,
103 "%s ",
104 np->get_host_name ()));
106 if (Options::get_opt (Options::USE_VERBOSE_FORMAT) == 0)
107 return;
112 PMC_Usr::PMC_Usr (char *u_name)
113 : usr_name (u_name)