00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "config_pstats.h"
00016 #include "pStatServerControlMessage.h"
00017
00018 #include "datagram.h"
00019 #include "datagramIterator.h"
00020
00021
00022
00023
00024
00025
00026 PStatServerControlMessage::
00027 PStatServerControlMessage() {
00028 _type = T_invalid;
00029 }
00030
00031
00032
00033
00034
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
00055
00056
00057
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 }