Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/pstatclient/pStatServerControlMessage.cxx

Go to the documentation of this file.
00001 // Filename: pStatServerControlMessage.cxx
00002 // Created by:  drose (09Jul00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "config_pstats.h"
00020 #include "pStatServerControlMessage.h"
00021 
00022 #include <datagram.h>
00023 #include <datagramIterator.h>
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //     Function: PStatServerControlMessage::Constructor
00027 //       Access: Public
00028 //  Description:
00029 ////////////////////////////////////////////////////////////////////
00030 PStatServerControlMessage::
00031 PStatServerControlMessage() {
00032   _type = T_invalid;
00033 }
00034 
00035 ////////////////////////////////////////////////////////////////////
00036 //     Function: PStatServerControlMessage::encode
00037 //       Access: Public
00038 //  Description: Writes the message into the indicated datagram.
00039 ////////////////////////////////////////////////////////////////////
00040 void PStatServerControlMessage::
00041 encode(Datagram &datagram) const {
00042   datagram.clear();
00043   datagram.add_uint8(_type);
00044   switch (_type) {
00045   case T_hello:
00046     datagram.add_string(_server_hostname);
00047     datagram.add_string(_server_progname);
00048     datagram.add_uint16(_udp_port);
00049     break;
00050 
00051   default:
00052     pstats_cat.error()
00053       << "Invalid PStatServerControlMessage::Type " << (int)_type << "\n";
00054   }
00055 }
00056 
00057 ////////////////////////////////////////////////////////////////////
00058 //     Function: PStatServerControlMessage::decode
00059 //       Access: Public
00060 //  Description: Extracts the message from the indicated datagram.
00061 //               Returns true on success, false on error.
00062 ////////////////////////////////////////////////////////////////////
00063 bool PStatServerControlMessage::
00064 decode(const Datagram &datagram) {
00065   DatagramIterator source(datagram);
00066   _type = (Type)source.get_uint8();
00067 
00068   switch (_type) {
00069   case T_hello:
00070     _server_hostname = source.get_string();
00071     _server_progname = source.get_string();
00072     _udp_port = source.get_uint16();
00073     break;
00074 
00075   default:
00076     pstats_cat.error()
00077       << "Read invalid PStatServerControlMessage type: " << (int)_type << "\n";
00078     _type = T_invalid;
00079     return false;
00080   }
00081 
00082   return true;
00083 }

Generated on Fri May 2 00:43:28 2003 for Panda by doxygen1.3