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

panda/src/pstatclient/pStatClientControlMessage.cxx

Go to the documentation of this file.
00001 // Filename: pStatClientControlMessage.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 "pStatClientControlMessage.h"
00021 #include "pStatClientVersion.h"
00022 
00023 #include <datagram.h>
00024 #include <datagramIterator.h>
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //     Function: PStatClientControlMessage::Constructor
00028 //       Access: Public
00029 //  Description:
00030 ////////////////////////////////////////////////////////////////////
00031 PStatClientControlMessage::
00032 PStatClientControlMessage() {
00033   _type = T_invalid;
00034 }
00035 
00036 ////////////////////////////////////////////////////////////////////
00037 //     Function: PStatClientControlMessage::encode
00038 //       Access: Public
00039 //  Description: Writes the message into the indicated datagram.
00040 ////////////////////////////////////////////////////////////////////
00041 void PStatClientControlMessage::
00042 encode(Datagram &datagram) const {
00043   datagram.clear();
00044   datagram.add_uint8(_type);
00045   switch (_type) {
00046   case T_hello:
00047     datagram.add_string(_client_hostname);
00048     datagram.add_string(_client_progname);
00049     datagram.add_uint16(_major_version);
00050     datagram.add_uint16(_minor_version);
00051     break;
00052 
00053   case T_define_collectors:
00054     {
00055       datagram.add_uint16(_collectors.size());
00056       for (int i = 0; i < (int)_collectors.size(); i++) {
00057         _collectors[i]->write_datagram(datagram);
00058       }
00059     }
00060     break;
00061 
00062   case T_define_threads:
00063     {
00064       datagram.add_uint16(_first_thread_index);
00065       datagram.add_uint16(_names.size());
00066       for (int i = 0; i < (int)_names.size(); i++) {
00067         datagram.add_string(_names[i]);
00068       }
00069     }
00070     break;
00071 
00072   default:
00073     pstats_cat.error()
00074       << "Invalid PStatClientControlMessage::Type " << (int)_type << "\n";
00075   }
00076 }
00077 
00078 ////////////////////////////////////////////////////////////////////
00079 //     Function: PStatClientControlMessage::decode
00080 //       Access: Public
00081 //  Description: Extracts the message from the indicated datagram.
00082 //               Returns true on success, false on error.
00083 ////////////////////////////////////////////////////////////////////
00084 bool PStatClientControlMessage::
00085 decode(const Datagram &datagram, PStatClientVersion *version) {
00086   DatagramIterator source(datagram);
00087   _type = (Type)source.get_uint8();
00088 
00089   switch (_type) {
00090   case T_hello:
00091     _client_hostname = source.get_string();
00092     _client_progname = source.get_string();
00093     if (source.get_remaining_size() == 0) {
00094       _major_version = 1;
00095       _minor_version = 0;
00096     } else {
00097       _major_version = source.get_uint16();
00098       _minor_version = source.get_uint16();
00099     }
00100     break;
00101 
00102   case T_define_collectors:
00103     {
00104       int num = source.get_uint16();
00105       _collectors.clear();
00106       for (int i = 0; i < num; i++) {
00107         PStatCollectorDef *def = new PStatCollectorDef;
00108         def->read_datagram(source, version);
00109         _collectors.push_back(def);
00110       }
00111     }
00112     break;
00113 
00114   case T_define_threads:
00115     {
00116       _first_thread_index = source.get_uint16();
00117       int num = source.get_uint16();
00118       _names.clear();
00119       for (int i = 0; i < num; i++) {
00120         _names.push_back(source.get_string());
00121       }
00122     }
00123     break;
00124 
00125   case T_datagram:
00126     // Not, strictly speaking, a control message.
00127     return false;
00128 
00129   default:
00130     pstats_cat.error()
00131       << "Read invalid PStatClientControlMessage type: " << (int)_type << "\n";
00132     _type = T_invalid;
00133     return false;
00134   }
00135 
00136   return true;
00137 }

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