Merge pull request #2258 from likema/log-msg-reset-ostream
[ACE_TAO.git] / ACE / apps / drwho / PMC_Flo.cpp
blobba27fe887aeda26238ddaedcc7fe71798a65f33f
1 #include "Options.h"
2 #include "BS_Client.h"
3 #include "PMC_Flo.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_NS_stdio.h"
9 #include "ace/OS_Memory.h"
11 // This function "encodes" a list of friends by putting the userid's
12 // in a contiguous block. This block can then be transmitted over to
13 // the network to servers on other subnets. Several things are added
14 // to make decoding easier on the other end:
16 // * A count of the number of friends is prepended (assumption: there
17 // are no more than 9999999 friends... ;-))
18 // * The login userids are separated by a single space. */
20 int
21 PMC_Flo::encode (char *packet, int &packet_length)
23 if (Options::get_opt (Options::DEBUGGING) != 0)
24 ACE_DEBUG ((LM_DEBUG,
25 "in PMC_Flo::encode"));
27 ACE_NEW_RETURN (this->ss,
28 BS_Client,
29 -1);
31 SET_PACKET_TYPE (packet, Options::PROTO_FLO);
32 char *buf_ptr = SKIP_PACKET_TYPE (packet);
34 ACE_OS::sprintf (buf_ptr,
35 "%d",
36 this->friend_count ());
38 buf_ptr += MAXUSERIDNAMELEN;
40 // Iterate through all the friends, copying them into the packet
41 // buffer.
43 for (Protocol_Record *prp; (prp = this->get_next_friend ()) != 0; )
44 buf_ptr = ACE_OS::strecpy (buf_ptr,
45 prp->get_login ());
47 packet_length = buf_ptr - packet;
49 if (Options::get_opt (Options::DEBUGGING) != 0)
51 ACE_DEBUG ((LM_DEBUG,
52 "packet_length = %d\n",
53 packet_length));
54 ACE_OS::write (ACE_STDERR, packet, packet_length);
55 ACE_DEBUG ((LM_DEBUG,
56 "\n"));
59 return 1;
62 // This method is responsible for transforming the msg from the server
63 // back into a form usable by the client.
65 int
66 PMC_Flo::decode (char *packet, int &packet_length)
68 if (Options::get_opt (Options::DEBUGGING) != 0)
70 ACE_DEBUG ((LM_DEBUG,
71 "in PMC_Flo::decode, packet_length = %d\n",
72 packet_length));
73 ACE_OS::write (ACE_STDERR, packet, packet_length);
74 ACE_DEBUG ((LM_DEBUG,
75 "\n"));
78 char *cp = packet;
79 int remote_users = 0;
81 sscanf (cp,
82 "Users %d",
83 &remote_users);
85 this->increment_total_users (remote_users);
87 for (cp = (char *) ACE::strend (cp);
88 *cp != '\n';
89 cp++)
91 char *login_name = cp;
93 for (cp = (char *) ACE::strend (cp);
94 *(cp = this->handle_protocol_entries (cp, login_name)) != '\t';
96 continue;
99 return 1;
102 Protocol_Record *
103 PMC_Flo::insert_protocol_info (Protocol_Record &protocol_record)
105 Protocol_Record *prp = PM_Client::insert_protocol_info (protocol_record);
106 int length = ACE_OS::strlen (prp->get_real ());
108 if (length > this->max_key_length)
109 this->max_key_length = length;
111 return prp;
114 void
115 PMC_Flo::process ()
117 ACE_DEBUG ((LM_DEBUG,
118 "remote friends logged on\n"));
119 PM_Client::process ();
122 PMC_Flo::PMC_Flo ()