From: <sv...@ww...> - 2004-06-13 00:56:17
|
Author: mkrose Date: 2004-06-12 17:56:10 -0700 (Sat, 12 Jun 2004) New Revision: 1026 Added: trunk/CSP/CSPSim/Include/Dispatch.h Modified: trunk/CSP/CSPSim/CHANGES.current Log: Added experimental boilerplate for dispatching network messages within object hierarchies. Modified: trunk/CSP/CSPSim/CHANGES.current =================================================================== --- trunk/CSP/CSPSim/CHANGES.current 2004-06-12 22:49:26 UTC (rev 1025) +++ trunk/CSP/CSPSim/CHANGES.current 2004-06-13 00:56:10 UTC (rev 1026) @@ -2,10 +2,41 @@ =========================== 2004-06-12: wolverine + * Added Dispatch.h as a possible way to dispatch network messages through + object hierarchies. Not integrated with the build yet. + +2004-06-12: wolverine * Switching the writing of network buffers to use a SimData MemoryWriter. Switched the code that reads network buffers to use a SimData MemoryReader +2004-06-11: onsight + * Removed most serialize() methods, since SimData now handles saving and + loading of the public XML interface automatically. Minor tweaks to + Sky.cpp to serialize the stars (which don't use the standard XML + facilities). + + * Added a relative path to SimData in the working copy to the Python path + in CSPSim.py so that SimData will not be loaded from site-packages. The + idea is that CSPSim and SimData will be developed concurrently, and we + don't want to have to go through a separate install process everytime + something changes. Changes to SimData that require simultaneous changes + to CSPSim should be checked in as one submission. + + * Added an exception handler to CSPSim to suppress a stack trace when the + data compiler fails. The real trace is already logged, and this makes + the error message more visible. + + * Changed the configure script under Linux to look for SimData in the + working copy rather than site-packages. Not quite working so currently + disabled. Also set the SimData include path to be local in the Makefile. + +==> Windows devs: please change the project file to use the working copy + of SimData rather than the version installed in site-packages. + + * Added GNU Common C++ check to the configure script, and include/libs + to the Makefile templates. + 2004-06-10: wolverine * Merged the networking classes MessageSocketDuplex into NetworkMessenger. Also added a callback mechanism to handle Added: trunk/CSP/CSPSim/Include/Dispatch.h =================================================================== --- trunk/CSP/CSPSim/Include/Dispatch.h 2004-06-12 22:49:26 UTC (rev 1025) +++ trunk/CSP/CSPSim/Include/Dispatch.h 2004-06-13 00:56:10 UTC (rev 1026) @@ -0,0 +1,94 @@ +// Combat Simulator Project - CSPSim +// 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 Dispatch.h + * + **/ + + +#ifndef __DISPATCH_H__ +#define __DISPATCH_H__ + + +#include <SimData/TaggedRecord.h> + +/** + * Sample use: + * + * class Foo(): public Bar { + * + * public: + * + * // message dispatch logic (boilerplate) + * MESSAGE_DISPATCH(Foo, Bar) + * DISPATCH(UpdateMessage, handleUpdate) + * DISPATCH(ConfigMessage, handleConfig) + * DISPATCH(TrackingMessage, handleTracking) + * MESSAGE_DISPATCH_END + * + * protected: + * + * // class message handlers. + * bool handleUpdate(simdata::Ref<UpdateMessage>); + * bool handleConfig(simdata::Ref<ConfigMessage>); + * bool handleTracking(simdata::Ref<TrackingMessage>); + * + * // optional handler called if normal dispatch fails. should call + * // dispatchMessage() for all child objects that support messaging. + * virtual bool childDispatch(simdata::Ref<TaggedMessage> const &); + * }; + * + */ + +// classname is not used currently, but it may be handy to have in the future. +#define MESSAGE_DISPATCH(classname, superclass) \ + inline bool _parentDispatch(simdata::Ref<simdata::TaggedRecord> const &record) { \ + return superclass::dispatchMessage(record); \ + } \ + virtual bool dispatchMessage(simdata::Ref<simdata::TaggedRecord> const &record) { \ + switch (record->getId()) { \ + +#define DISPATCH(message, handler) \ + case message::_getId(): handler(record); return true; + +#define END_MESSAGE_DISPATCH \ + return _parentDispatch(record); \ +} + + +class MessageDispatchBase { + +public: + virtual bool dispatchMessage(simdata::Ref<simdata::TaggedRecord> const &record) { + return childDispatch(record); + } + +protected: + virtual bool childDispatch(simdata::Ref<simdata::TaggedRecord> const &record) { + return false; + } + +public: + virtual ~MessageDispatch() {} +}; + + +#endif // __DISPATCH_H__ + |