ComsChannelMessage.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <coms/ComsChannelMessage.h>
00022 
00023 ComsChannelMessage::ComsChannelMessage() :
00024         ComsMessage("ComsChannelMessage")
00025 {
00026 }
00027 
00028 ComsChannelMessage::ComsChannelMessage(RequestType type, unsigned int id) :
00029         ComsMessage("ComsChannelMessage"),
00030         type_(type), id_(id)
00031 {
00032 }
00033 
00034 ComsChannelMessage::~ComsChannelMessage()
00035 {
00036 }
00037 
00038 bool ComsChannelMessage::writeMessage(NetBuffer &buffer)
00039 {
00040         buffer.addToBuffer((int) type_);
00041         buffer.addToBuffer(id_);
00042         buffer.addToBuffer((int) channels_.size());
00043         std::list<ChannelDefinition>::iterator itor;
00044         for (itor = channels_.begin();
00045                 itor != channels_.end();
00046                 itor++)
00047         {
00048                 buffer.addToBuffer(itor->getType());
00049                 buffer.addToBuffer(itor->getChannel());
00050         }
00051         buffer.addToBuffer((int) availableChannels_.size());
00052         for (itor = availableChannels_.begin();
00053                 itor != availableChannels_.end();
00054                 itor++)
00055         {
00056                 buffer.addToBuffer(itor->getType());
00057                 buffer.addToBuffer(itor->getChannel());
00058         }
00059         return true;
00060 }
00061 
00062 bool ComsChannelMessage::readMessage(NetBufferReader &reader)
00063 {
00064         int type, size;
00065         if (!reader.getFromBuffer(type)) return false;
00066         type_ = (RequestType) type;
00067         if (!reader.getFromBuffer(id_)) return false;
00068         if (!reader.getFromBuffer(size)) return false;
00069         for (int s=0; s<size; s++)
00070         {
00071                 unsigned int channelType;
00072                 std::string channelChannel;
00073                 if (!reader.getFromBuffer(channelType)) return false;
00074                 if (!reader.getFromBuffer(channelChannel)) return false;
00075                 channels_.push_back(
00076                         ChannelDefinition(channelChannel.c_str(), channelType));
00077         }
00078         if (!reader.getFromBuffer(size)) return false;
00079         for (int s=0; s<size; s++)
00080         {
00081                 unsigned int channelType;
00082                 std::string channelChannel;
00083                 if (!reader.getFromBuffer(channelType)) return false;
00084                 if (!reader.getFromBuffer(channelChannel)) return false;
00085                 availableChannels_.push_back(
00086                         ChannelDefinition(channelChannel.c_str(), channelType));
00087         }
00088         return true;
00089 }

Generated on Mon Feb 16 15:14:49 2009 for Scorched3D by  doxygen 1.5.3