From: <sv...@ww...> - 2005-12-05 05:27:14
|
Author: mkrose Date: 2005-12-04 21:27:07 -0800 (Sun, 04 Dec 2005) New Revision: 1721 Removed: trunk/CSP/csp/cspsim/DispatchCenter.cpp trunk/CSP/csp/cspsim/DispatchCenter.h Log: Remove DispatchCenter, which is no longer used. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1721 Deleted: trunk/CSP/csp/cspsim/DispatchCenter.cpp =================================================================== --- trunk/CSP/csp/cspsim/DispatchCenter.cpp 2005-12-05 05:26:24 UTC (rev 1720) +++ trunk/CSP/csp/cspsim/DispatchCenter.cpp 2005-12-05 05:27:07 UTC (rev 1721) @@ -1,81 +0,0 @@ -// Combat Simulator Project -// Copyright (C) 2004 The Combat Simulator Project -// http://csp.sourceforge.net -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - -/** - * @file DispatchCenter.cpp - * - **/ - - -#include "DispatchCenter.h" -#include <csp/csplib/util/Log.h> -#include "Animation.h" -#include "Config.h" -#include "ObjectModel.h" -#include <csp/csplib/net/Networking.h> -#include <csp/csplib/net/NetworkMessage.h> - -#include <csp/csplib/util/Dispatch.h> -#include <SimData/TaggedRecordRegistry.h> - -DispatchCenter::DispatchCenter() { - simdata::TaggedRecordRegistry const ®istry = simdata::TaggedRecordRegistry::getConstInstance(); - // TODO will need to be sorted and validated eventually! - m_factories = registry.getFactories(); -} - -TaggedRecord::Ref DispatchCenter::decode(NetworkMessage *message) const { - assert(message); - simdata::uint16 id = message->getType(); - assert(id < m_factories.size()); - simdata::TaggedRecordFactoryBase *factory = m_factories[id]; - TaggedRecord::Ref record = factory->create(); - // TODO too much buffer copying; need to optimize - std::string payload(static_cast<char*>(message->getPayloadPtr()), message->getPayloadLen()); - simdata::StringReader reader(payload); - simdata::TagReader tag_reader(reader); - // TODO need to catch errors - record->serialize(tag_reader); - return record; -} - -bool DispatchCenter::encode(TaggedRecord::Ref record, NetworkMessage *message) const { - assert(record.valid()); - assert(message != 0); - // TODO get the id from the record. since ids are assigned dynamically, we - // need to extend the tagged record interface to allow ids to be assigned to the - // record class, and retrieved from any record instance (ie. need a class static - // field --- uint16). - //simdata::uint16 id = 0; // XXX - // TODO serialize without constructing a new writer/tagwriter each time, and - // without reallocating the write buffer. - simdata::StringWriter writer; - simdata::TagWriter tag_writer(writer); - record->serialize(tag_writer); - //std::string const &buffer = writer.str(); - // TODO message initialization from the buffer data needs to be implemented - // (requires changes to NetworkMessage) - // message->initialize(id, buffer.data(), buffer.size()); - return true; -} - -bool DispatchCenter::dispatch(TaggedRecord::Ref record, MessageDispatcher &object) const { - return object.dispatchMessage(record); -} - Deleted: trunk/CSP/csp/cspsim/DispatchCenter.h =================================================================== --- trunk/CSP/csp/cspsim/DispatchCenter.h 2005-12-05 05:26:24 UTC (rev 1720) +++ trunk/CSP/csp/cspsim/DispatchCenter.h 2005-12-05 05:27:07 UTC (rev 1721) @@ -1,120 +0,0 @@ -// Combat Simulator Project -// Copyright (C) 2004 The Combat Simulator Project -// http://csp.sourceforge.net -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - -/** - * @file DispatchCenter.h - * @brief Singleton for decoding and dispatching network messsages. - * - * The dispatch center maintains an array of TaggedRecordFactories, - * indexed by message type. When a network message arrives, the - * header is parsed to determine the message type. The dispatch - * center uses the message type to retrieve the appropriate tagged - * record factory and create a tagged record instance. The tagged - * record instance then initializes itself from the network message - * payload. - * - * The message header also include a destination id, which is used - * to retrieve the object that should receive the message. If the - * object does not exist, it may be created and added to the - * battlefield. The tagged record instance then passed to the - * object's dispatch method. Handers defined in the object's - * class hierarchy may receive the record and take appropriate - * actions. If no handler is found, the record is passsed to the - * objects childDispatch method. This virtual method can be - * overridden in derived classes to selectively forward messages on - * to internal objects (e.g. the vehicle subsystems). - * - * Caveats: - * - * The message type is just a 16-bit integer id for a given tagged - * record class that all nodes agree on. Eventually this assignment - * will be managed by a centralized server, and transmitted to each - * client that joins the game. For now we simply assign these ids - * sequentially to all tagged record classes in alphabetical order by - * class name. Thus all clients must have the exact same set of - * tagged record classes to communicate properly. No validation has - * been implemented yet, so remote connections should only be initiated - * between clients sync'd to the same repository revision. - * - * Eventually, tagged record factories will return instances from an - * object pool in order to minimize allocation/deallocation overhead. - * The dispatch center will be responsible for returning the tagged - * records to the pool after dispatch. This requires that the object - * receiving the message not maintain a reference to the tagged - * record. This constraint can be enforced by testing the reference - * count after dispatch is completed. Alternatively, we can use - * a separate smart-pointer class that automatically returns an - * instance to the parent object pool when the reference count - * reaches zero (instead of deleting the instance). Such a pool + - * smart pointer system has been implemented, but not yet integrated - * with CSPSim/SimData. - * - **/ - - -#ifndef __CSPSIM_DISPATCHCENTER_H__ -#define __CSPSIM_DISPATCHCENTER_H__ - - -#include <SimData/TaggedRecord.h> -#include <SimData/Singleton.h> -#include <vector> - -// bring TaggedRecord into the global namespace -using simdata::TaggedRecord; - -// forward declarations -class NetworkMessage; -class MessageDispatcher; - -namespace simdata { - class TaggedRecordFactoryBase; -} - - -/** Singleton class for decoding network messages to tagged records, and - * dispatching these records to object handlers. - */ -class DispatchCenter: public simdata::Singleton<DispatchCenter> { - friend class simdata::Singleton<DispatchCenter>; - -public: - - DispatchCenter(); - - /** Decode a tagged record from a raw network message. - */ - TaggedRecord::Ref decode(NetworkMessage *message) const; - - /** Encode a tagged record to a raw network message. - */ - bool encode(TaggedRecord::Ref record, NetworkMessage *message) const; - - /** Dispatch a tagged record to an object handler. - */ - bool dispatch(TaggedRecord::Ref record, MessageDispatcher &object) const; - -private: - std::vector<simdata::TaggedRecordFactoryBase *> m_factories; - -}; - - -#endif // __CSPSIM_DISPATCHCENTER_H__ - |