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