Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / apps / drwho / PMS_Flo.cpp
blob7c15845f717104a6416fd36698c387d4adacad86
1 #include "Options.h"
2 #include "BS_Server.h"
3 #include "PMS_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 packs the located friends userids, plus the machines
12 // they are logged into (along with the inactive and active counts on
13 // each machine) into a buffer that is subsequently transmitted back
14 // to the client across the network.
16 int
17 PMS_Flo::encode (char *packet, int &packet_length)
19 if (Options::get_opt (Options::DEBUGGING) != 0)
20 ACE_DEBUG ((LM_DEBUG,
21 "in PMS_Flo::encode"));
23 Protocol_Record *prp;
24 char *buf_ptr = packet;
26 ACE_OS::sprintf (buf_ptr,
27 "Users %d",
28 this->get_total_users ());
29 buf_ptr += ACE_OS::strlen (buf_ptr) + 1;
31 // We only send back info on friends that we actually see logged in.
33 for (;
34 (prp = this->get_next_friend ()) != 0;
35 *buf_ptr++ = '\t')
36 buf_ptr = this->handle_protocol_entries (ACE_OS::strecpy (buf_ptr,
37 prp->get_login ()),
38 prp->get_drwho_list ());
39 *buf_ptr++ = '\n';
40 packet_length = buf_ptr - packet;
42 if (Options::get_opt (Options::DEBUGGING) != 0)
44 ACE_DEBUG ((LM_DEBUG,
45 "packet_length = %d\n",
46 packet_length));
47 ACE_OS::write (ACE_STDERR, packet, packet_length);
48 ACE_DEBUG ((LM_DEBUG,
49 "\n"));
52 return 1;
55 // This function takes a packet received from the client and calls the
56 // appropriate Protocol_Manager routine to build the local table of
57 // friends.
59 int
60 PMS_Flo::decode (char *packet, int &packet_length)
62 if (Options::get_opt (Options::DEBUGGING) != 0)
63 ACE_DEBUG ((LM_DEBUG,
64 "in PMS_Flo::decode, packet_length = %d\n",
65 packet_length));
67 ACE_NEW_RETURN (this->ss,
68 BS_Server (packet),
69 -1);
70 return 1;
73 PMS_Flo::PMS_Flo ()