You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(47) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(140) |
Feb
(98) |
Mar
(152) |
Apr
(104) |
May
(71) |
Jun
(94) |
Jul
(169) |
Aug
(83) |
Sep
(47) |
Oct
(134) |
Nov
(7) |
Dec
(20) |
2004 |
Jan
(41) |
Feb
(14) |
Mar
(42) |
Apr
(47) |
May
(68) |
Jun
(143) |
Jul
(65) |
Aug
(29) |
Sep
(40) |
Oct
(34) |
Nov
(33) |
Dec
(97) |
2005 |
Jan
(29) |
Feb
(30) |
Mar
(9) |
Apr
(37) |
May
(13) |
Jun
(31) |
Jul
(22) |
Aug
(23) |
Sep
|
Oct
(37) |
Nov
(34) |
Dec
(117) |
2006 |
Jan
(48) |
Feb
(6) |
Mar
(2) |
Apr
(71) |
May
(10) |
Jun
(16) |
Jul
(7) |
Aug
(1) |
Sep
(14) |
Oct
(17) |
Nov
(25) |
Dec
(26) |
2007 |
Jan
(8) |
Feb
(2) |
Mar
(7) |
Apr
(26) |
May
|
Jun
(12) |
Jul
(30) |
Aug
(14) |
Sep
(9) |
Oct
(4) |
Nov
(7) |
Dec
(6) |
2008 |
Jan
(10) |
Feb
(10) |
Mar
(6) |
Apr
(8) |
May
|
Jun
(10) |
Jul
(18) |
Aug
(15) |
Sep
(16) |
Oct
(5) |
Nov
(3) |
Dec
(10) |
2009 |
Jan
(11) |
Feb
(2) |
Mar
|
Apr
(15) |
May
(31) |
Jun
(18) |
Jul
(11) |
Aug
(26) |
Sep
(52) |
Oct
(17) |
Nov
(4) |
Dec
|
2010 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <sv...@ww...> - 2004-06-17 06:32:05
|
Author: mkrose Date: 2004-06-16 23:31:57 -0700 (Wed, 16 Jun 2004) New Revision: 1050 Modified: trunk/CSP/CSPSim/Doc/footer.html trunk/CSP/SimData/CHANGES.current trunk/CSP/SimData/Doc/Doxyfile trunk/CSP/SimData/Doc/Makefile trunk/CSP/SimData/Doc/footer.html trunk/CSP/SimData/Include/SimData/DataArchive.h trunk/CSP/SimData/Include/SimData/Enum.h trunk/CSP/SimData/Include/SimData/ExceptionBase.h trunk/CSP/SimData/Include/SimData/GeoPos.h trunk/CSP/SimData/Include/SimData/Key.h trunk/CSP/SimData/Include/SimData/Link.h trunk/CSP/SimData/Include/SimData/List.h trunk/CSP/SimData/Include/SimData/Log.h trunk/CSP/SimData/Include/SimData/Noise.h trunk/CSP/SimData/Include/SimData/Object.h trunk/CSP/SimData/Include/SimData/Path.h trunk/CSP/SimData/Include/SimData/Real.h trunk/CSP/SimData/Include/SimData/Types.h trunk/CSP/SimData/Include/SimData/Uniform.h trunk/CSP/SimData/Include/SimData/Version.h trunk/CSP/SimData/Source/BaseType.cpp trunk/CSP/SimData/Source/Enum.cpp trunk/CSP/SimData/Source/GeoPos.cpp trunk/CSP/SimData/Source/Key.cpp trunk/CSP/SimData/Source/Link.cpp trunk/CSP/SimData/Source/List.cpp trunk/CSP/SimData/Source/Noise.cpp trunk/CSP/SimData/Source/Object.cpp trunk/CSP/SimData/Source/Path.cpp trunk/CSP/SimData/Source/Real.cpp trunk/CSP/SimData/Source/Version.cpp Log: Documentation cleanup; copyright notice corrections; initial version string display changed to log message. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1050 Diff omitted (111061 bytes). |
From: <sv...@ww...> - 2004-06-16 08:50:07
|
Author: mkrose Date: 2004-06-16 01:50:01 -0700 (Wed, 16 Jun 2004) New Revision: 1049 Modified: trunk/CSP/tools/subcmd.py Log: Fix help passthru for svn commands. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1049 Modified: trunk/CSP/tools/subcmd.py =================================================================== --- trunk/CSP/tools/subcmd.py 2004-06-16 08:46:47 UTC (rev 1048) +++ trunk/CSP/tools/subcmd.py 2004-06-16 08:50:01 UTC (rev 1049) @@ -712,7 +712,7 @@ def help(self): command = self._keys[0] - return self._svn(command, 'help', (command,)) + return self._svn('help', [command,]) class Blame(SVNCommand): |
From: <sv...@ww...> - 2004-06-16 08:46:54
|
Author: mkrose Date: 2004-06-16 01:46:47 -0700 (Wed, 16 Jun 2004) New Revision: 1048 Modified: trunk/CSP/CSPSim/CHANGES.current trunk/CSP/CSPSim/Include/Bus.h Log: Updated docs in Bus.h Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1048 Diff omitted (18224 bytes). |
From: <sv...@ww...> - 2004-06-16 06:08:20
|
Author: mkrose Date: 2004-06-15 23:08:14 -0700 (Tue, 15 Jun 2004) New Revision: 1047 Added: trunk/CSP/CSPSim/Doc/ trunk/CSP/CSPSim/Doc/Doxyfile trunk/CSP/CSPSim/Doc/Makefile trunk/CSP/CSPSim/Doc/footer.html Modified: trunk/CSP/CSPSim/CHANGES.current trunk/CSP/CSPSim/Makefile.in Log: Added doxygen directory, control file, and make targets. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1047 Diff omitted (39387 bytes). |
From: <sv...@ww...> - 2004-06-16 02:53:50
|
Author: mkrose Date: 2004-06-15 19:53:44 -0700 (Tue, 15 Jun 2004) New Revision: 1046 Modified: trunk/CSP/SimData/Include/SimData/Log.h Log: Fix check for SIMDATA_LOGFILE env variable. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1046 Modified: trunk/CSP/SimData/Include/SimData/Log.h =================================================================== --- trunk/CSP/SimData/Include/SimData/Log.h 2004-06-15 18:08:08 UTC (rev 1045) +++ trunk/CSP/SimData/Include/SimData/Log.h 2004-06-16 02:53:44 UTC (rev 1046) @@ -61,7 +61,7 @@ char *save = getenv("SIMDATA_LOGFILE"); // default to stderr if SIMDATA_LOGFILE isn't set logstrm = new logstream(std::cerr); - if (save) { + if (save && *save) { logstrm->setOutput(save); } } |
From: <sv...@ww...> - 2004-06-15 18:08:14
|
Author: delta Date: 2004-06-15 11:08:08 -0700 (Tue, 15 Jun 2004) New Revision: 1045 Modified: trunk/CSP/SimData/Include/SimData/Log.h Log: Typo in a condition. OS, plz check it. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1045 Modified: trunk/CSP/SimData/Include/SimData/Log.h =================================================================== --- trunk/CSP/SimData/Include/SimData/Log.h 2004-06-14 08:37:38 UTC (rev 1044) +++ trunk/CSP/SimData/Include/SimData/Log.h 2004-06-15 18:08:08 UTC (rev 1045) @@ -61,7 +61,7 @@ char *save = getenv("SIMDATA_LOGFILE"); // default to stderr if SIMDATA_LOGFILE isn't set logstrm = new logstream(std::cerr); - if (save and *save) { + if (save) { logstrm->setOutput(save); } } |
From: <sv...@ww...> - 2004-06-14 08:37:45
|
Author: mkrose Date: 2004-06-14 01:37:38 -0700 (Mon, 14 Jun 2004) New Revision: 1044 Modified: trunk/CSP/SimData/Include/SimData/LogStream.h trunk/CSP/SimData/Source/LogStream.cpp Log: Remove sync() when redirecting log output to prevent segfaults; slight tweak of logic for closing logstreams, and minor formating fixups Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1044 Modified: trunk/CSP/SimData/Include/SimData/LogStream.h =================================================================== --- trunk/CSP/SimData/Include/SimData/LogStream.h 2004-06-14 07:49:33 UTC (rev 1043) +++ trunk/CSP/SimData/Include/SimData/LogStream.h 2004-06-14 08:37:38 UTC (rev 1044) @@ -41,6 +41,7 @@ #include <iostream> #include <fstream> #include <string> +#include <cassert> #include <SimData/Namespace.h> #include <SimData/Export.h> @@ -218,6 +219,7 @@ } void _close() { + lbuf.set_sb(NULL); if (m_out != NULL) { m_out->close(); delete m_out; @@ -231,7 +233,7 @@ */ void setOutput(std::ostream& out_) { _close(); - lbuf.set_sb(out_.rdbuf() ); + lbuf.set_sb(out_.rdbuf()); } /** Set the output stream @@ -241,7 +243,8 @@ void setOutput(std::string const &fn) { _close(); m_out = new std::ofstream(fn.c_str()); - lbuf.set_sb( m_out->rdbuf() ); + assert(m_out != NULL); + lbuf.set_sb(m_out->rdbuf()); } /** Set the global log class and priority level. Modified: trunk/CSP/SimData/Source/LogStream.cpp =================================================================== --- trunk/CSP/SimData/Source/LogStream.cpp 2004-06-14 07:49:33 UTC (rev 1043) +++ trunk/CSP/SimData/Source/LogStream.cpp 2004-06-14 08:37:38 UTC (rev 1044) @@ -42,12 +42,12 @@ logbuf::~logbuf() { - if (sbuf) sync(); + //if (sbuf) sync(); // logs are already flushed by endl } void logbuf::set_sb(std::streambuf* sb) { - if (sbuf) sync(); + //if (sbuf) sync(); // enabling this causes segfaults when redirecting output sbuf = sb; } |
From: <sv...@ww...> - 2004-06-14 07:49:42
|
Author: mkrose Date: 2004-06-14 00:49:33 -0700 (Mon, 14 Jun 2004) New Revision: 1043 Modified: trunk/CSP/SimData/CHANGES.current trunk/CSP/SimData/Include/SimData/Log.h trunk/CSP/SimData/Include/SimData/LogStream.h Log: Logging now checks SIMDATA_LOGFILE environment variable when opening the log. If not set or empty, log messages are initially directed to stderr (log output can also be redirected at runtime). Change the initial "SimData [version] loaded @ xxx" message to be a log message. With the SIMDATA_LOGFILE this makes it possible to suppress display of this message on startup while still allowing the version and load address to be determined.. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1043 Modified: trunk/CSP/SimData/CHANGES.current =================================================================== --- trunk/CSP/SimData/CHANGES.current 2004-06-14 06:55:18 UTC (rev 1042) +++ trunk/CSP/SimData/CHANGES.current 2004-06-14 07:49:33 UTC (rev 1043) @@ -5,6 +5,15 @@ * Fixup python call for saving/restoring ints from archives (now _int32). + * Logging now checks SIMDATA_LOGFILE environment variable when + opening the log. If not set or empty, log messages are initially + directed to stderr (log output can also be redirected at runtime). + + * Change the initial "SimData [version] loaded @ xxx" message to be + a log message. With the SIMDATA_LOGFILE this makes it possible to + suppress display of this message on startup while still allowing + the version and load address to be determined.. + 2004-06-12: onsight * Commented out throw statement for assignment to Ref<> from an incompatible type. Callers must check that the ref is not null Modified: trunk/CSP/SimData/Include/SimData/Log.h =================================================================== --- trunk/CSP/SimData/Include/SimData/Log.h 2004-06-14 06:55:18 UTC (rev 1042) +++ trunk/CSP/SimData/Include/SimData/Log.h 2004-06-14 07:49:33 UTC (rev 1043) @@ -28,6 +28,7 @@ #define __SIMDATA_LOG_H__ +#include <cstdlib> #include <cstdio> #include <string> @@ -56,7 +57,14 @@ inline SIMDATA_EXPORT logstream& log() { //static logstream logstrm(std::cerr); static logstream *logstrm = 0; - if (logstrm == 0) logstrm = new logstream(std::cerr); + if (logstrm == 0) { + char *save = getenv("SIMDATA_LOGFILE"); + // default to stderr if SIMDATA_LOGFILE isn't set + logstrm = new logstream(std::cerr); + if (save and *save) { + logstrm->setOutput(save); + } + } return *logstrm; } Modified: trunk/CSP/SimData/Include/SimData/LogStream.h =================================================================== --- trunk/CSP/SimData/Include/SimData/LogStream.h 2004-06-14 06:55:18 UTC (rev 1042) +++ trunk/CSP/SimData/Include/SimData/LogStream.h 2004-06-14 07:49:33 UTC (rev 1043) @@ -1,18 +1,18 @@ /* SimData: Data Infrastructure for Simulations - * Copyright (C) 2002, 2003 Mark Rose <tm...@st...> - * + * Copyright 2002, 2003, 2004 Mark Rose <tm...@st...> + * * This file is part of SimData. - * + * * 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. @@ -24,13 +24,13 @@ * @brief Stream based logging mechanism. * * Stream based logging mechanism. - * + * * Based on the LogStream library written by Bernie Bright, 1998 * Copyright (C) 1998 Bernie Bright - bb...@c0... * * Source code from Bernie Bright's LogStream library is used * here under the turms of the GNU General Public License - * version 2 or later, as allowed by the GNU Library General + * version 2 or later, as allowed by the GNU Library General * Public License Version 2 (clause 3). */ @@ -53,13 +53,11 @@ using std::ostream; -// // TODO: // // 1. Change output destination. Done. // 2. Make logbuf thread safe. // 3. Read environment for default debugClass and debugPriority. -// /** An output-only, category-based log stream. * @@ -108,7 +106,7 @@ /** Get the logging classes currently enabled. * @return All enabled debug logging anded together. */ - int get_log_classes (); + int get_log_classes(); /** Set the logging priority. @@ -119,7 +117,7 @@ /** Get the current logging priority. - * + * * @return The priority cutoff for logging messages. */ int get_log_priority (); @@ -129,7 +127,7 @@ * * @param sb stream buffer */ - void set_sb( std::streambuf* sb ); + void set_sb(std::streambuf* sb); protected: @@ -155,37 +153,33 @@ void operator= ( const logbuf& ); }; -inline int -logbuf::sync() -{ + +inline int logbuf::sync() { if (!sbuf) return -1; return sbuf->pubsync(); } -inline void -logbuf::set_log_state(int c, int p) -{ + +inline void logbuf::set_log_state(int c, int p) { logging_enabled = ((c & logClass) != 0 && p >= logPriority); } + //inline logbuf::int_type -inline int -logbuf::overflow(int c) -{ +inline int logbuf::overflow(int c) { return logging_enabled ? sbuf->sputc(static_cast<char>(c)) : (EOF == 0 ? 1: 0); } /** LogStream manipulator for setting the log level of a message. */ -struct loglevel -{ - loglevel(int c, int p) - : logClass(c), logPriority(p) {} +struct loglevel { + loglevel(int c, int p): logClass(c), logPriority(p) {} int logClass; int logPriority; }; + /** A helper class for logstream construction. * * A helper class that ensures a streambuf and ostream are constructed and @@ -199,7 +193,8 @@ logstream_base() {} logbuf lbuf; }; - + + /** Class to manage the debug logging stream. */ class SIMDATA_EXPORT logstream : private logstream_base, public std::ostream @@ -207,14 +202,14 @@ std::ofstream *m_out; public: /** The default is to send messages to cerr. - * + * * @param out_ output stream */ logstream(std::ostream& out_) - : logstream_base(), - ostream(&lbuf), // msvc6 accepts ostream(&lbuf) _using std::ostream_, but not std::ostream(&lbuf) ... - m_out(NULL) - { + : logstream_base(), + ostream(&lbuf), // msvc6 accepts ostream(&lbuf) _using std::ostream_, but not std::ostream(&lbuf) ... + m_out(NULL) + { lbuf.set_sb(out_.rdbuf()); } @@ -234,19 +229,19 @@ * * @param out_ output stream */ - void setOutput(std::ostream& out_) { + void setOutput(std::ostream& out_) { _close(); - lbuf.set_sb(out_.rdbuf() ); + lbuf.set_sb(out_.rdbuf() ); } /** Set the output stream * * @param fn output file path */ - void setOutput(std::string const &fn) { + void setOutput(std::string const &fn) { _close(); m_out = new std::ofstream(fn.c_str()); - lbuf.set_sb( m_out->rdbuf() ); + lbuf.set_sb( m_out->rdbuf() ); } /** Set the global log class and priority level. @@ -265,13 +260,12 @@ /** Output operator to capture the debug level and priority of a message. * @param l log level */ - inline std::ostream& operator<< ( const loglevel& l ); + inline std::ostream& operator<< (const loglevel& l); }; -inline std::ostream& -logstream::operator<< ( const loglevel& l ) -{ - lbuf.set_log_state( l.logClass, l.logPriority ); + +inline std::ostream& logstream::operator<< (const loglevel& l) { + lbuf.set_log_state(l.logClass, l.logPriority); return *this; } |
From: <sv...@ww...> - 2004-06-14 06:55:24
|
Author: mkrose Date: 2004-06-13 23:55:18 -0700 (Sun, 13 Jun 2004) New Revision: 1042 Modified: trunk/CSP/CSPSim/CHANGES.current trunk/CSP/CSPSim/Include/System.h Log: Added many detailed comments to System.h, as well as a general overview. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1042 Diff omitted (12784 bytes). |
From: <sv...@ww...> - 2004-06-14 02:52:21
|
Author: wolverine Date: 2004-06-13 19:52:15 -0700 (Sun, 13 Jun 2004) New Revision: 1041 Modified: trunk/CSP/CSPSim/Source/ClientNode.cpp trunk/CSP/CSPSim/Source/Networking/DispatchMessageHandler.cpp Log: Changes for debugging ClientNode with DispatchMessageHandler Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1041 Modified: trunk/CSP/CSPSim/Source/ClientNode.cpp =================================================================== --- trunk/CSP/CSPSim/Source/ClientNode.cpp 2004-06-13 22:38:27 UTC (rev 1040) +++ trunk/CSP/CSPSim/Source/ClientNode.cpp 2004-06-14 02:52:15 UTC (rev 1041) @@ -9,7 +9,6 @@ #include <SimData/Archive.h> #include <SimData/Ref.h> #include <SimData/Date.h> -#include <SimData/DataManager.h> #include <KineticsChannels.h> @@ -20,6 +19,7 @@ #include <SimData/FileUtility.h> #include <SimData/GeoPos.h> +#include <osgDB/FileUtils> using bus::Kinetics; @@ -35,6 +35,35 @@ csplog().setLogLevels(CSP_ALL, level); csplog().setOutput("ClientNode.log"); + VirtualBattlefield * battlefield = new VirtualBattlefield(); + battlefield->create(); + simdata::DataManager dataManager; + + // setup osg search path for external data files + std::string image_path = getDataPath("ImagePath"); + std::string model_path = getDataPath("ModelPath"); + std::string font_path = getDataPath("FontPath"); + std::string search_path; + simdata::ospath::addpath(search_path, image_path); + simdata::ospath::addpath(search_path, model_path); + simdata::ospath::addpath(search_path, font_path); + osgDB::setDataFilePathList(search_path); + + // open the primary data archive + std::string cache_path = getCachePath(); + std::string archive_file = simdata::ospath::join(cache_path, "sim.dar"); + try { + simdata::DataArchive *sim = new simdata::DataArchive(archive_file.c_str(), 1); + assert(sim); + dataManager.addArchive(sim); + } + catch (simdata::Exception &e) { + CSP_LOG(APP, ERROR, "Error opening data archive " << archive_file); + CSP_LOG(APP, ERROR, e.getType() << ": " << e.getMessage()); + throw e; + //::exit(0); + } + printf("sizeof(int) = %d\n", sizeof(int)); printf("sizeof(double) = %d\n", sizeof(double)); printf("sizeof(simdata::Vector3) = %d\n", sizeof(simdata::Vector3)); @@ -46,9 +75,6 @@ printf("sizeof(NetworkMessage) = %d\n", sizeof(NetworkMessage)); printf("sizeof(ObjectUpdateMessagePayload) = %d\n", sizeof(ObjectUpdateMessagePayload)); - VirtualBattlefield * battlefield = new VirtualBattlefield(); - battlefield->create(); - simdata::DataManager dataManager; MessageHeader header; header.dumpOffsets(); Modified: trunk/CSP/CSPSim/Source/Networking/DispatchMessageHandler.cpp =================================================================== --- trunk/CSP/CSPSim/Source/Networking/DispatchMessageHandler.cpp 2004-06-13 22:38:27 UTC (rev 1040) +++ trunk/CSP/CSPSim/Source/Networking/DispatchMessageHandler.cpp 2004-06-14 02:52:15 UTC (rev 1041) @@ -18,6 +18,7 @@ void DispatchMessageHandler::process(NetworkMessage * message, NetworkMessenger * messenger) { + CSP_LOG(APP, DEBUG, "DispatchMessageHandler::process()"); NetworkNode * node = message->getOriginatorNode(); unsigned int addr = node->getAddress().getAddress().s_addr; unsigned short port = node->getPort(); @@ -36,12 +37,15 @@ if (remoteObjectWrapper == NULL) { + CSP_LOG(APP, DEBUG, "DispatchMessageHandler::process() - object not found in database so adding it"); // TODO create new object and add it to table. // // set remoteObjectWrapper to value of new object. simdata::Ref<DynamicObject> obj = addRemoteObject(message); + CSP_LOG(APP, DEBUG, "DispatchMessageHandler::process() - wrapping new object"); RemoteObjectWrapper * remoteObjectWrapper = new RemoteObjectWrapper(obj); // TODO add new object to wrapper object + CSP_LOG(APP, DEBUG, "DispatchMessageHandler::process() - putting new object in remote object table"); m_RemoteObjectTable.putRemoteObject( addr, port, objectID, remoteObjectWrapper ); } simdata::Ref<DynamicObject> object = remoteObjectWrapper->getWrappedObject(); @@ -62,11 +66,17 @@ // use hard coded mirage for now. std::string vehicle = g_Config.getPath("Testing", "Vehicle", "sim:vehicles.aircraft.m2k", false); + CSP_LOG(APP, DEBUG, "DispatchMessageHandler::addRemoteObject() - calling dataManager using path: " + << vehicle.c_str()); + simdata::Ref<DynamicObject> ao = _dataManager.getObject(vehicle.c_str()); assert(ao.valid()); + + CSP_LOG(APP, DEBUG, "DispatchMessageHandler::addRemoteObject() - sending update message to new object"); ao->putUpdateMessage(message); + CSP_LOG(APP, DEBUG, "DispatchMessageHandler::addRemoteObject() - adding new object to battlefield"); _virtualBattlefield->addUnit(ao); return ao; } |
From: <sv...@ww...> - 2004-06-13 22:38:42
|
Author: wolverine Date: 2004-06-13 15:38:27 -0700 (Sun, 13 Jun 2004) New Revision: 1040 Modified: trunk/CSP/CSPSim/Source/ClientNode.cpp Log: new test client Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1040 Modified: trunk/CSP/CSPSim/Source/ClientNode.cpp =================================================================== --- trunk/CSP/CSPSim/Source/ClientNode.cpp 2004-06-13 22:22:55 UTC (rev 1039) +++ trunk/CSP/CSPSim/Source/ClientNode.cpp 2004-06-13 22:38:27 UTC (rev 1040) @@ -46,13 +46,17 @@ printf("sizeof(NetworkMessage) = %d\n", sizeof(NetworkMessage)); printf("sizeof(ObjectUpdateMessagePayload) = %d\n", sizeof(ObjectUpdateMessagePayload)); + VirtualBattlefield * battlefield = new VirtualBattlefield(); + battlefield->create(); + simdata::DataManager dataManager; + MessageHeader header; header.dumpOffsets(); printf("Network test client starting up...\n"); Port localPort = g_Config.getInt("Networking", "LocalMessagePort", 10000, true); std::string localHost = g_Config.getString("Networking", "LocalMessageHost", "127.0.0.1", true); - + Port remotePort = (Port)g_Config.getInt("Networking", "RemoteMessagePort", 0, true); std::string remoteHost = g_Config.getString("Networking", "RemoteMessageHost", "127.0.0.1", true); @@ -63,7 +67,14 @@ PrintMessageHandler * printMessageHandler = new PrintMessageHandler(); printMessageHandler->setFrequency(1); networkMessenger->registerReceiveHandler(printMessageHandler); - + DispatchMessageHandler * dispatchMessageHandler = new DispatchMessageHandler(); + dispatchMessageHandler->setLocalAddress( localNode->getAddress().getAddress().s_addr ); + dispatchMessageHandler->setLocalPort(localPort); + dispatchMessageHandler->setVirtualBattlefield(battlefield); + dispatchMessageHandler->setDataManager(dataManager); + networkMessenger->registerReceiveHandler(dispatchMessageHandler); + + unsigned short messageType = 2; unsigned short payloadLen = sizeof(int) + sizeof(double) + 3*sizeof(simdata::Vector3) + sizeof(simdata::Quat) /* + sizeof(simdata::Matrix3) + sizeof(double) */; @@ -99,31 +110,34 @@ b_Attitude->value() = simdata::Quat(1.0, 1.0, 1.0, 0.0); // ptrPayload->id = 1; - // ptrPayload->timeStamp = 1.0; - - simdata::MemoryWriter writer((simdata::uint8 *)ptrPayload); - writer << id; - writer << type; - writer << timestamp; + while(1) + { + timestamp += 1.0; + ptrPayload->timeStamp = timestamp; + b_GlobalPosition->value() = simdata::Vector3(timestamp*1.0, timestamp*0.5, 1.0); + + simdata::MemoryWriter writer((simdata::uint8 *)ptrPayload); + writer << id; + writer << type; + writer << timestamp; // b_GlobalPosition->value().writeBinary((unsigned char *)&(ptrPayload->globalPosition),24); // b_LinearVelocity->value().writeBinary((unsigned char *)&(ptrPayload->linearVelocity),24); // b_AngularVelocity->value().writeBinary((unsigned char *)&(ptrPayload->angularVelocity),24); // b_Attitude->value().writeBinary((unsigned char *)&(ptrPayload->attitude),32); - b_GlobalPosition->value().serialize(writer); - b_LinearVelocity->value().serialize(writer); - b_AngularVelocity->value().serialize(writer); - b_Attitude->value().serialize(writer); + b_GlobalPosition->value().serialize(writer); + b_LinearVelocity->value().serialize(writer); + b_AngularVelocity->value().serialize(writer); + b_Attitude->value().serialize(writer); - ptrPayload->dump(); + ptrPayload->dump(); - networkMessenger->queueMessage(remoteNode, message); + networkMessenger->queueMessage(remoteNode, message); - while(1) - { networkMessenger->sendQueuedMessages(); networkMessenger->receiveMessages(); + sleep(1); } return 0; } |
From: <sv...@ww...> - 2004-06-13 22:23:02
|
Author: mkrose Date: 2004-06-13 15:22:55 -0700 (Sun, 13 Jun 2004) New Revision: 1039 Modified: trunk/CSP/tools/subcmd.py Log: Fix usage, which was broken when splitting subcmd.py out of subset. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1039 Modified: trunk/CSP/tools/subcmd.py =================================================================== --- trunk/CSP/tools/subcmd.py 2004-06-13 18:48:03 UTC (rev 1038) +++ trunk/CSP/tools/subcmd.py 2004-06-13 22:22:55 UTC (rev 1039) @@ -1005,7 +1005,7 @@ return Result(0) def help(self): - print __doc__ % {'prog': app.programName()} + app.usage() print 'Available commands:' commands = {} for command in Command.Index.values(): |
From: <sv...@ww...> - 2004-06-13 18:48:09
|
Author: delta Date: 2004-06-13 11:48:03 -0700 (Sun, 13 Jun 2004) New Revision: 1038 Modified: trunk/CSP/SimData/VisualStudio2003/SimData.vcproj Log: Added TaggedRecord.h to vcproj header folder. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1038 Modified: trunk/CSP/SimData/VisualStudio2003/SimData.vcproj =================================================================== --- trunk/CSP/SimData/VisualStudio2003/SimData.vcproj 2004-06-13 17:59:50 UTC (rev 1037) +++ trunk/CSP/SimData/VisualStudio2003/SimData.vcproj 2004-06-13 18:48:03 UTC (rev 1038) @@ -368,6 +368,9 @@ RelativePath="..\Include\SimData\String.h"> </File> <File + RelativePath="..\Include\SimData\TaggedRecord.h"> + </File> + <File RelativePath="..\Include\SimData\TypeAdapter.h"> </File> <File |
From: <sv...@ww...> - 2004-06-13 17:59:56
|
Author: mkrose Date: 2004-06-13 10:59:50 -0700 (Sun, 13 Jun 2004) New Revision: 1037 Modified: trunk/CSP/Demeter/README Log: test new commit email message Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1037 Modified: trunk/CSP/Demeter/README =================================================================== --- trunk/CSP/Demeter/README 2004-06-13 17:30:27 UTC (rev 1036) +++ trunk/CSP/Demeter/README 2004-06-13 17:59:50 UTC (rev 1037) @@ -26,3 +26,4 @@ under *nix: aclocal; autoconf; ./configure; make + |
From: <sv...@ww...> - 2004-06-13 17:30:33
|
Author: mkrose Date: 2004-06-13 10:30:27 -0700 (Sun, 13 Jun 2004) New Revision: 1036 Modified: trunk/CSP/SimData/CHANGES.current trunk/CSP/SimData/SimData/Tests/ArchiveTests.py Log: Fixup python call for saving/restoring ints from archives (now _int32). Modified: trunk/CSP/SimData/CHANGES.current =================================================================== --- trunk/CSP/SimData/CHANGES.current 2004-06-13 17:21:26 UTC (rev 1035) +++ trunk/CSP/SimData/CHANGES.current 2004-06-13 17:30:27 UTC (rev 1036) @@ -1,6 +1,10 @@ Version 0.4.0 (in progress) =========================== +2004-06-13: onsight + * Fixup python call for saving/restoring ints from archives (now + _int32). + 2004-06-12: onsight * Commented out throw statement for assignment to Ref<> from an incompatible type. Callers must check that the ref is not null @@ -14,8 +18,15 @@ * Added tagged record compiler and associated header. * Disallowed copying of Referenced derived classes (should always - use Ref<> pointers). + use Ref<> pointers); then reverted because we already inherit + from NonCopyable. + * Minor fix to DataManager cleanup. + + * TaggedRecord.h copyright notice. + + * Singleton now NonCopyable, with const accessor. + 2004-16-12: wolverine * added a MemoryWriter class to write out a SimData object to a binary memory buffer. Added a MemoryReader class. Added Modified: trunk/CSP/SimData/SimData/Tests/ArchiveTests.py =================================================================== --- trunk/CSP/SimData/SimData/Tests/ArchiveTests.py 2004-06-13 17:21:26 UTC (rev 1035) +++ trunk/CSP/SimData/SimData/Tests/ArchiveTests.py 2004-06-13 17:30:27 UTC (rev 1036) @@ -206,10 +206,10 @@ def testInt(self): """Test storage and retrieval of Int""" x0 = 42 - self.archive._int(x0) + self.archive._int32(x0) self.setRead() self.assertEqual(self.size, 4) - x1 = self.archive._int() + x1 = self.archive._int32() self.assertEqual(x0, x1) def testDouble(self): |
From: <sv...@ww...> - 2004-06-13 17:21:33
|
Author: mkrose Date: 2004-06-13 10:21:26 -0700 (Sun, 13 Jun 2004) New Revision: 1035 Added: trunk/CSP/base/domtree.py Modified: trunk/CSP/tools/subcmd.py trunk/CSP/tools/sublib.py Log: Add a simple dom parser. Add support to subset for diffing submitted revisions. Added: trunk/CSP/base/domtree.py =================================================================== --- trunk/CSP/base/domtree.py 2004-06-13 14:37:10 UTC (rev 1034) +++ trunk/CSP/base/domtree.py 2004-06-13 17:21:26 UTC (rev 1035) @@ -0,0 +1,73 @@ +# Copyright 2004 Mark Rose <mk...@us...> +# +# 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 + +""" +Very simple XML parsing using minidom and lots of Python magic. +""" + +from xml.dom.minidom import parse, parseString + + +class DomTree: + """ + Dom node wrapper providing access to child nodes via instance + attributes and iterators. + """ + + def __init__(self, dom): + self.name = dom.nodeName + self.type = dom.nodeType + self.node = dom + self.text = '' + self.children = [] + self._dict = {} + for node in dom.childNodes: + if node.nodeType == node.TEXT_NODE: + self.text += node.data + else: + tree = DomTree(node) + self.children.append(tree) + self._dict[tree.name] = tree + def __getattr__(self, key): + return self.__dict__['_dict'].get(key, None) + def attr(self, name, default=None): + return self.node.getAttribute(name) + def attrs(self): + return self.node._attrs.keys() + def hasattr(self, name): + return self.node.hasAttribute(name) + def __len__(self): return len(self.children) + def __str__(self): return self.__repr__() + def __repr__(self): + if self.text.strip(): return self.text + return 'node %s' % self.name + def keys(self): + return self._dict.keys() + def get(self, name, default): + return self.child + def __iter__(self): + for child in self.children: + yield child + raise StopIteration + + +def ParseFile(file): + return DomTree(parse(file)) + + +def ParseString(text): + return DomTree(parseString(text)) + Modified: trunk/CSP/tools/subcmd.py =================================================================== --- trunk/CSP/tools/subcmd.py 2004-06-13 14:37:10 UTC (rev 1034) +++ trunk/CSP/tools/subcmd.py 2004-06-13 17:21:26 UTC (rev 1035) @@ -358,10 +358,13 @@ self.save() return Result(0) + # TODO this Frankenstein method is in desparate need of refactoring def diff(self, names, revision): dircmd = os.environ.get('SUBSET_DIFF_DIR', '') onecmd = os.environ.get('SUBSET_DIFF_ONE', dircmd) + rev = 0 cs = None + info = None if not names: name = 'default changeset' files = filter(self._closed, sublib.svn_st()) @@ -385,15 +388,28 @@ files = diffs else: name = names[0] - cs = self.getChangeset(name) - if not cs: - return Error('no changeset "%s"' % name) - files = cs.files() - cs.describe() - if not files: return Result(0) + if name[0] == 'r': + try: + rev = int(name[1:]) + except ValueError: + pass + rev = abs(rev) + if rev: + name = 'revision %d' % rev + info = sublib.svn_revision_info(rev) + files = [] + else: + cs = self.getChangeset(name) + if not cs: + return Error('no changeset "%s"' % name) + files = cs.files() + cs.describe() + if not files and not rev: return Result(0) tmproot = '/tmp/subset.diff.%010d' % random.randint(1, 1000000000) os.mkdir(tmproot) cleanup = [] + if rev: + files = sublib.svn_savediffs(tmproot, rev) singleton = not cs and (len(files) == 1) if singleton and not onecmd: print 'SUBSET_DIFF_ONE undefined; cannot view diff.' @@ -416,24 +432,35 @@ index.write('<p/>\n') index.write('\n<p/>\n') else: - index.write('<h3>%s</h3>' % name) + index.write('<h3>%s</h3>\n' % name) + if info is not None: + index.write('<p/><i>Submitted by: %s<br/>\n' % info.author) + index.write('Submitted on: %s</i><p/>\n' % info.date) + index.write('%s\n' % str(info.msg).replace('\n', '<br/>\n')) cleanup.append(diffindex) if revision: index.write('<b>diff to revision %s</b>' % revision) index.write('<ul>\n') - for file in files: - if os.path.isdir(file.abspath()): - index.write('<li>%s/</li>\n' % (file.path)) - continue - outbase = file.path.replace(os.path.sep, '~') + '.diff' - outfile = os.path.join(tmproot, outbase) - cleanup.append(outfile) - exit_code = sublib.svn_savediff(file, outfile, revision) - if makeindex: - if exit_code: - index.write('<li>%s <i>...unable to diff</i></li>\n' % (file.path)) - else: - index.write('<li><a href="%s">%s</a></li>\n' % (outbase, file.path)) + if rev: + for name, path in files: + cleanup.append(path) + if makeindex: + index.write('<li><a href="%s">%s</a></li>\n' % (path, name)) + else: + for file in files: + if makeindex: + if os.path.isdir(file.abspath()): + index.write('<li>%s/</li>\n' % (file.path)) + continue + outbase = file.path.replace(os.path.sep, '~') + '.diff' + outfile = os.path.join(tmproot, outbase) + cleanup.append(outfile) + exit_code = sublib.svn_savediff(file, outfile, revision) + if makeindex: + if exit_code: + index.write('<li>%s <i>...unable to diff</i></li>\n' % (file.path)) + else: + index.write('<li><a href="%s">%s</a></li>\n' % (outbase, file.path)) if makeindex: index.write('</ul>\n</small></body></html>') index.close() @@ -943,10 +970,12 @@ def _define(self): self._long = ('diff: generate diffs for files or changesets.\n' '\n' - 'usage: %prog diff [changeset | file [file...]]' + 'usage: %prog diff [changeset | rREV | file [file...]]' '\n' 'If no arguments are specified, all files in the default changeset\n' - 'will be diffed') + 'will be diffed. The "rREV" syntax shows diffs of files submitted\n' + 'at the specified revision (e.g. "r101"), relative to the previous\n' + 'revision.') self._short = 'generate diffs' self._addKeys('diff') self._addOption('-r', '--revision', default='', metavar='REV', help='diff relative to a specific revision') Modified: trunk/CSP/tools/sublib.py =================================================================== --- trunk/CSP/tools/sublib.py 2004-06-13 14:37:10 UTC (rev 1034) +++ trunk/CSP/tools/sublib.py 2004-06-13 17:21:26 UTC (rev 1035) @@ -31,6 +31,7 @@ import time from CSP.base import app +from CSP.base import domtree class File: ADD = 'ADD' @@ -67,7 +68,7 @@ path = root else: path = ' '.join(files) - st = os.popen('svn st %s' % path).readlines() + st = os.popen('svn st -q %s' % path).readlines() files = [] for line in st: path = line[1:].strip() @@ -117,6 +118,34 @@ return exit_code +def svn_savediffs(target, rev2, rev1=None, context=100): + files = [] + if rev1 is None: + rev1 = rev2 - 1 + root = svn_root() + exit_code, out = runo('svn diff -r %d:%d --diff-cmd diff -x "-U %d -b" %s' % (rev1, rev2, context, root)) + if exit_code: return [] + diff = None + for line in out: + line = line[:-1] # remove newline + if line.startswith('Index: '): + fn = line[7:] + dest = fn.replace(os.sep, '~') + '.diff' + dest = os.path.join(target, dest) + diff = open(dest, 'wt') + files.append((fn, dest)) + if diff: diff.write(line + '\n') + return files + + +def svn_revision_info(rev): + root = svn_root() + exit_code, out = runo('svn log --xml -v -r %d %s' % (rev, root)) + if exit_code: return None + doc = domtree.ParseString(''.join(out)) + return doc.log.logentry + + def runoe(cmd): process = popen2.Popen3(cmd, capturestderr=1) process.tochild.close() |
From: <sv...@ww...> - 2004-06-13 14:37:16
|
Author: wolverine Date: 2004-06-13 07:37:10 -0700 (Sun, 13 Jun 2004) New Revision: 1034 Added: trunk/CSP/CSPSim/Source/Networking/DispatchMessageHandler.cpp Modified: trunk/CSP/CSPSim/Source/CSPSim.cpp trunk/CSP/CSPSim/Source/DynamicObject.cpp trunk/CSP/CSPSim/Source/Makefile.in trunk/CSP/CSPSim/Source/Networking/EchoMessageHandler.cpp trunk/CSP/CSPSim/Source/Networking/NetworkMessenger.cpp trunk/CSP/CSPSim/Source/Networking/PrintMessageHandler.cpp trunk/CSP/CSPSim/Source/SimObject.cpp Log: Added DispatchMessageHandler.cpp to handle incoming messages and forward them to the correct object. Modified: trunk/CSP/CSPSim/Source/CSPSim.cpp =================================================================== --- trunk/CSP/CSPSim/Source/CSPSim.cpp 2004-06-13 14:36:27 UTC (rev 1033) +++ trunk/CSP/CSPSim/Source/CSPSim.cpp 2004-06-13 14:37:10 UTC (rev 1034) @@ -425,6 +425,15 @@ m_RemoteServerNode = new NetworkNode(1, remoteAddr.c_str(), remotePort ); m_localNode = new NetworkNode(1, localAddr.c_str(), localMessagePort); m_NetworkMessenger = new NetworkMessenger(m_localNode); + PrintMessageHandler * printMessageHandler = new PrintMessageHandler(); + printMessageHandler->setFrequency(100); + m_NetworkMessenger->registerReceiveHandler(printMessageHandler); + DispatchMessageHandler * dispatchMessageHandler = new DispatchMessageHandler(); + dispatchMessageHandler->setLocalAddress( m_localNode->getAddress().getAddress().s_addr ); + dispatchMessageHandler->setLocalPort( localMessagePort ); + dispatchMessageHandler->setDataManager(m_DataManager); + dispatchMessageHandler->setVirtualBattlefield(getBattlefield()); + m_NetworkMessenger->registerReceiveHandler(dispatchMessageHandler); #if 0 // set the Main Menu then start the main loop Modified: trunk/CSP/CSPSim/Source/DynamicObject.cpp =================================================================== --- trunk/CSP/CSPSim/Source/DynamicObject.cpp 2004-06-13 14:36:27 UTC (rev 1033) +++ trunk/CSP/CSPSim/Source/DynamicObject.cpp 2004-06-13 14:37:10 UTC (rev 1034) @@ -406,8 +406,7 @@ simdata::MemoryWriter writer((simdata::uint8*)ptrPayload); writer << m_ID; - simdata::uint32 objType = 1; - writer << objType; + writer << m_Type; writer << CSPSim::theSim->getElapsedTime(); b_GlobalPosition->value().serialize(writer); b_LinearVelocity->value().serialize(writer); Modified: trunk/CSP/CSPSim/Source/Makefile.in =================================================================== --- trunk/CSP/CSPSim/Source/Makefile.in 2004-06-13 14:36:27 UTC (rev 1033) +++ trunk/CSP/CSPSim/Source/Makefile.in 2004-06-13 14:37:10 UTC (rev 1034) @@ -78,6 +78,7 @@ Networking/NetworkAddress.cpp \ Networking/PrintMessageHandler.cpp \ Networking/EchoMessageHandler.cpp \ + Networking/DispatchMessageHandler.cpp \ NumericalMethod.cpp \ ObjectModel.cpp \ ObjectRangeInfo.cpp \ Added: trunk/CSP/CSPSim/Source/Networking/DispatchMessageHandler.cpp =================================================================== --- trunk/CSP/CSPSim/Source/Networking/DispatchMessageHandler.cpp 2004-06-13 14:36:27 UTC (rev 1033) +++ trunk/CSP/CSPSim/Source/Networking/DispatchMessageHandler.cpp 2004-06-13 14:37:10 UTC (rev 1034) @@ -0,0 +1,72 @@ +#include "Networking.h" +#include "DynamicObject.h" + +#include "Config.h" +#include <SimData/FileUtility.h> + +extern SimpleConfig g_Config; +DispatchMessageHandler::DispatchMessageHandler() +{ + _addr = 0; + _port = 0; +} + +DispatchMessageHandler::~DispatchMessageHandler() +{ + +} + +void DispatchMessageHandler::process(NetworkMessage * message, NetworkMessenger * messenger) +{ + NetworkNode * node = message->getOriginatorNode(); + unsigned int addr = node->getAddress().getAddress().s_addr; + unsigned short port = node->getPort(); + if (isLocal(addr, port)) + return; + simdata::uint16 messageType = message->getType(); + + void * ptr = message->getPayloadPtr(); + ObjectUpdateMessagePayload * messagePayload = (ObjectUpdateMessagePayload*)ptr; + + unsigned int objectID = messagePayload->id; + unsigned int objectType = messagePayload->id; + + RemoteObjectWrapper * remoteObjectWrapper = m_RemoteObjectTable.getRemoteObject( + addr, port, objectID ); + + if (remoteObjectWrapper == NULL) + { + // TODO create new object and add it to table. + // + // set remoteObjectWrapper to value of new object. + simdata::Ref<DynamicObject> obj = addRemoteObject(message); + RemoteObjectWrapper * remoteObjectWrapper = new RemoteObjectWrapper(obj); + // TODO add new object to wrapper object + m_RemoteObjectTable.putRemoteObject( addr, port, objectID, remoteObjectWrapper ); + } + simdata::Ref<DynamicObject> object = remoteObjectWrapper->getWrappedObject(); + object->putUpdateMessage(message); + + +} + +bool DispatchMessageHandler::isLocal(unsigned int addr, unsigned short port) +{ + return ((_addr == addr) && (_port == port)); +} + + +simdata::Ref<DynamicObject> DispatchMessageHandler::addRemoteObject( NetworkMessage * message ) +{ + CSP_LOG(APP, DEBUG, "DispatchMessageHandler::addRemoteObject() - adding new object"); + + // use hard coded mirage for now. + std::string vehicle = g_Config.getPath("Testing", "Vehicle", "sim:vehicles.aircraft.m2k", false); + simdata::Ref<DynamicObject> ao = _dataManager.getObject(vehicle.c_str()); + assert(ao.valid()); + + ao->putUpdateMessage(message); + + _virtualBattlefield->addUnit(ao); + return ao; +} Modified: trunk/CSP/CSPSim/Source/Networking/EchoMessageHandler.cpp =================================================================== --- trunk/CSP/CSPSim/Source/Networking/EchoMessageHandler.cpp 2004-06-13 14:36:27 UTC (rev 1033) +++ trunk/CSP/CSPSim/Source/Networking/EchoMessageHandler.cpp 2004-06-13 14:37:10 UTC (rev 1034) @@ -29,6 +29,16 @@ #include "Networking.h" +EchoMessageHandler::EchoMessageHandler() +{ + +} + +EchoMessageHandler::~EchoMessageHandler() +{ + +} + void EchoMessageHandler::process(NetworkMessage * message, NetworkMessenger * messenger) { Modified: trunk/CSP/CSPSim/Source/Networking/NetworkMessenger.cpp =================================================================== --- trunk/CSP/CSPSim/Source/Networking/NetworkMessenger.cpp 2004-06-13 14:36:27 UTC (rev 1033) +++ trunk/CSP/CSPSim/Source/Networking/NetworkMessenger.cpp 2004-06-13 14:37:10 UTC (rev 1034) @@ -46,7 +46,7 @@ m_messageReceiveArrayCount = 0; m_messageReceiveArray.reserve(m_messageReceiveArrayMax); - m_ReceiveHandler = NULL; +// m_ReceiveHandler = NULL; } NetworkMessenger::NetworkMessenger(NetworkNode * originatorNode) @@ -68,7 +68,7 @@ m_messageReceiveArrayCount = 0; m_messageReceiveArray.reserve(m_messageReceiveArrayMax); - m_ReceiveHandler = NULL; +// m_ReceiveHandler = NULL; } //NetworkMessenger::NetworkMessenger(ost::InetAddress & addr, Port port) @@ -138,8 +138,14 @@ NetworkMessage * networkMessage = receiveMessage(); if ( networkMessage ) { - if ( m_ReceiveHandler ) - m_ReceiveHandler->process(networkMessage, this); + std::list<NetworkMessageHandler *>::iterator iter = m_ReceiveHandlerList.begin(); + std::list<NetworkMessageHandler *>::const_iterator end = m_ReceiveHandlerList.end(); + for (;iter != end ; ++iter) { + NetworkMessageHandler * handler = (NetworkMessageHandler*)(*iter); + if (handler != NULL) { + handler->process(networkMessage, this); + } + } } else return; @@ -158,7 +164,7 @@ void NetworkMessenger::registerReceiveHandler(NetworkMessageHandler * handler) { - m_ReceiveHandler = handler; + m_ReceiveHandlerList.push_back(handler); } Modified: trunk/CSP/CSPSim/Source/Networking/PrintMessageHandler.cpp =================================================================== --- trunk/CSP/CSPSim/Source/Networking/PrintMessageHandler.cpp 2004-06-13 14:36:27 UTC (rev 1033) +++ trunk/CSP/CSPSim/Source/Networking/PrintMessageHandler.cpp 2004-06-13 14:37:10 UTC (rev 1034) @@ -30,6 +30,17 @@ #include "Networking.h" #include <stdio.h> +PrintMessageHandler::PrintMessageHandler() +{ + m_frequency = 1; + m_count = 0; +} + +PrintMessageHandler::~PrintMessageHandler() +{ + +} + void PrintMessageHandler::process(NetworkMessage * message, NetworkMessenger * messenger) { if (m_count % m_frequency == 0) Modified: trunk/CSP/CSPSim/Source/SimObject.cpp =================================================================== --- trunk/CSP/CSPSim/Source/SimObject.cpp 2004-06-13 14:36:27 UTC (rev 1033) +++ trunk/CSP/CSPSim/Source/SimObject.cpp 2004-06-13 14:37:10 UTC (rev 1034) @@ -37,11 +37,14 @@ SIMDATA_REGISTER_INTERFACE(SimObject) +unsigned int SimObject::localObjectInstance = 0; SimObject::SimObject() { CSP_LOG(APP, DEBUG, "SimObject::SimObject()" ); + m_ID = ++SimObject::localObjectInstance; + m_Type = 1; // TODO change this m_Flags = 0; setAggregateFlag(true); |
From: <sv...@ww...> - 2004-06-13 14:36:35
|
Author: wolverine Date: 2004-06-13 07:36:27 -0700 (Sun, 13 Jun 2004) New Revision: 1033 Modified: trunk/CSP/CSPSim/Include/Networking.h trunk/CSP/CSPSim/Include/SimObject.h Log: Added DispatchMessageHandler.cpp to handle incoming messages and forward them to the correct object. Modified: trunk/CSP/CSPSim/Include/Networking.h =================================================================== --- trunk/CSP/CSPSim/Include/Networking.h 2004-06-13 14:36:13 UTC (rev 1032) +++ trunk/CSP/CSPSim/Include/Networking.h 2004-06-13 14:36:27 UTC (rev 1033) @@ -33,14 +33,19 @@ #include <sys/types.h> #include <list> +#include <map> #include <SimData/Vector3.h> #include <SimData/String.h> #include <SimData/Uniform.h> #include <SimData/Quat.h> +#include <SimData/DataManager.h> #include <SimData/Date.h> #include <stdio.h> +#include "DynamicObject.h" +#include "VirtualBattlefield.h" + typedef int SockFd; typedef simdata::uint16 Port; class NetworkNode; @@ -267,6 +272,39 @@ }; +class DynamicObject; + +class RemoteObjectWrapper +{ + public: + RemoteObjectWrapper(simdata::Ref<DynamicObject> & object) { m_Object = object; } + NetworkNode * getObjectHost() { return m_Host; } + simdata::Ref<DynamicObject> getWrappedObject() { return m_Object; } + private: + simdata::Ref<DynamicObject> m_Object; + NetworkNode * m_Host; + + +}; + +class RemoteObjectTable +{ + public: + RemoteObjectWrapper * getRemoteObject(int ipaddr, short port, int id) + { + return m_table[ipaddr][port][id]; + } + + void putRemoteObject(int ipaddr, short port, int id, RemoteObjectWrapper * object) + { + m_table[ipaddr][port][id] = object; + } + + private: + std::map< int , std::map < short, std::map < short, RemoteObjectWrapper * > > > m_table; + +}; + class NetworkMessageHandler; class NetworkMessenger @@ -283,7 +321,7 @@ int m_messageReceiveArrayGrow; NetworkNode * m_originatorNode; std::list<NetworkMessage*> m_messagePool; - NetworkMessageHandler * m_ReceiveHandler; + std::list<NetworkMessageHandler *> m_ReceiveHandlerList; ost::UDPSocket * m_UDPReceiverSocket; ost::UDPSocket * m_UDPSenderSocket; @@ -335,7 +373,9 @@ { public: + EchoMessageHandler(); virtual void process(NetworkMessage * message, NetworkMessenger * messenger); + virtual ~EchoMessageHandler(); }; @@ -345,13 +385,39 @@ int m_frequency; int m_count; public: - PrintMessageHandler() { m_frequency = 1; m_count = 0;} + PrintMessageHandler(); virtual void process(NetworkMessage * message, NetworkMessenger * messenger); + virtual ~PrintMessageHandler(); void setFrequency(int frequency) { m_frequency = frequency; } int getFrequency() { return m_frequency; } }; +class DispatchMessageHandler : public NetworkMessageHandler +{ + public: + DispatchMessageHandler(); + virtual void process(NetworkMessage * message, NetworkMessenger * messenger); + virtual ~DispatchMessageHandler(); + void setLocalAddress(unsigned int addr) { _addr = addr; } + void setLocalPort(unsigned short port) { _port = port; } + void setVirtualBattlefield(VirtualBattlefield * battlefield) { _virtualBattlefield = battlefield; } + void setDataManager(simdata::DataManager & dataManager) { _dataManager = dataManager; } + + protected: + bool isLocal(unsigned int addr, unsigned short port); + simdata::Ref<DynamicObject> addRemoteObject( NetworkMessage * message ); + + private: + + RemoteObjectTable m_RemoteObjectTable; + unsigned int _addr; + unsigned short _port; + VirtualBattlefield * _virtualBattlefield; + simdata::DataManager _dataManager; + +}; + // not currently using these below class NetworkBroadcaster Modified: trunk/CSP/CSPSim/Include/SimObject.h =================================================================== --- trunk/CSP/CSPSim/Include/SimObject.h 2004-06-13 14:36:13 UTC (rev 1032) +++ trunk/CSP/CSPSim/Include/SimObject.h 2004-06-13 14:36:27 UTC (rev 1033) @@ -111,6 +111,11 @@ m_ID = id; } + void setType(unsigned int type) { + assert(m_Type == 0); + m_Type = type; + } + /** Update callback. * * @param dt time since elapsed last call to onUpdate() @@ -133,6 +138,7 @@ /** Get the unique object id of this instance. */ unsigned int getID() const { return m_ID; } + unsigned int getType() const { return m_Type; } /** Called before an object is added to the scene graph. * @@ -161,7 +167,10 @@ protected: unsigned int m_ID; + unsigned int m_Type; unsigned int m_Flags; + + static unsigned int localObjectInstance; }; |
From: <sv...@ww...> - 2004-06-13 14:36:19
|
Author: wolverine Date: 2004-06-13 07:36:13 -0700 (Sun, 13 Jun 2004) New Revision: 1032 Modified: trunk/CSP/CSPSim/CHANGES.current Log: Added DispatchMessageHandler.cpp to handle incoming messages and forward them to the correct object. Modified: trunk/CSP/CSPSim/CHANGES.current =================================================================== --- trunk/CSP/CSPSim/CHANGES.current 2004-06-13 08:20:09 UTC (rev 1031) +++ trunk/CSP/CSPSim/CHANGES.current 2004-06-13 14:36:13 UTC (rev 1032) @@ -1,6 +1,10 @@ Version 0.4.0 (in progress) =========================== +2004-06-13: wolverine + * Added DispatchMessageHandler to the networking layer to forward incoming + messages to the correct object. + 2004-06-12: wolverine * Added Dispatch.h as a possible way to dispatch network messages through object hierarchies. Not integrated with the build yet. |
From: <sv...@ww...> - 2004-06-13 08:20:17
|
Author: mkrose Date: 2004-06-13 01:20:09 -0700 (Sun, 13 Jun 2004) New Revision: 1031 Modified: trunk/CSP/SimData/Include/SimData/Ref.h trunk/CSP/SimData/Include/SimData/Singleton.h trunk/CSP/SimData/Include/SimData/TaggedRecord.h trunk/CSP/SimData/Source/DataManager.cpp Log: TaggedRecord.h copyright notice; Singleton NonCopyable and const accessor; Ref already NonCopyable; DataManager cleanup bug. Modified: trunk/CSP/SimData/Include/SimData/Ref.h =================================================================== --- trunk/CSP/SimData/Include/SimData/Ref.h 2004-06-13 03:11:52 UTC (rev 1030) +++ trunk/CSP/SimData/Include/SimData/Ref.h 2004-06-13 08:20:09 UTC (rev 1031) @@ -90,11 +90,6 @@ } inline unsigned _count() const { return __count; } mutable unsigned __count; - - // Referenced objects should never be copied; always allocate them on the - // heap and use Ref<> smart-pointers to refer to them. - Referenced const & operator=(Referenced const &); - Referenced(Referenced const &); }; Modified: trunk/CSP/SimData/Include/SimData/Singleton.h =================================================================== --- trunk/CSP/SimData/Include/SimData/Singleton.h 2004-06-13 03:11:52 UTC (rev 1030) +++ trunk/CSP/SimData/Include/SimData/Singleton.h 2004-06-13 08:20:09 UTC (rev 1031) @@ -29,13 +29,16 @@ #define __SIMDATA_SINGLETON_H__ #include <SimData/Namespace.h> +#include <SimData/Properties.h> NAMESPACE_SIMDATA /** Creates a single, static instance of the templated class. + * TODO could stand lots of improvement (delete priority, thread + * safety, etc). */ template <class C> -class Singleton { +class Singleton: public NonCopyable { public: /** Get the one instance of the template class. */ @@ -43,7 +46,10 @@ static C __instance; return __instance; } -private: + static C const & getConstInstance() { + return getInstance(); + } +protected: Singleton() {} ~Singleton() {} }; Modified: trunk/CSP/SimData/Include/SimData/TaggedRecord.h =================================================================== --- trunk/CSP/SimData/Include/SimData/TaggedRecord.h 2004-06-13 03:11:52 UTC (rev 1030) +++ trunk/CSP/SimData/Include/SimData/TaggedRecord.h 2004-06-13 08:20:09 UTC (rev 1031) @@ -1,6 +1,33 @@ -#ifndef __SIMDATA_TRF_H__ -#define __SIMDATA_TRF_H__ +/* SimData: Data Infrastructure for Simulations + * Copyright (C) 2004 Mark Rose <mk...@us...> + * + * This file is part of SimData. + * + * 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 TaggedRecord.h + * @brief Base classes for tagged records. + */ + + +#ifndef __SIMDATA_TAGGED_RECORD_H__ +#define __SIMDATA_TAGGED_RECORD_H__ + #include <string> #include <stack> #include <vector> @@ -12,6 +39,7 @@ #include <SimData/Archive.h> #include <SimData/Namespace.h> + NAMESPACE_SIMDATA // use our own, platform-neutral int64 representation @@ -328,5 +356,5 @@ NAMESPACE_SIMDATA_END -#endif // __SIMDATA_TRF_H__ +#endif // __SIMDATA_TAGGED_RECORD_H__ Modified: trunk/CSP/SimData/Source/DataManager.cpp =================================================================== --- trunk/CSP/SimData/Source/DataManager.cpp 2004-06-13 03:11:52 UTC (rev 1030) +++ trunk/CSP/SimData/Source/DataManager.cpp 2004-06-13 08:20:09 UTC (rev 1031) @@ -45,6 +45,7 @@ *i = 0; } } + _archives.clear(); } void DataManager::addArchive(DataArchive *d) { |
From: <sv...@ww...> - 2004-06-13 03:11:59
|
Author: mkrose Date: 2004-06-12 20:11:52 -0700 (Sat, 12 Jun 2004) New Revision: 1030 Modified: trunk/CSP/tools/pyrun Log: Change the name of the main module. __main__ seems to be *too* magic. Also fixed a corner case where the main program is in a top-level directory rather than a package. Modified: trunk/CSP/tools/pyrun =================================================================== --- trunk/CSP/tools/pyrun 2004-06-13 03:07:22 UTC (rev 1029) +++ trunk/CSP/tools/pyrun 2004-06-13 03:11:52 UTC (rev 1030) @@ -170,23 +170,25 @@ name, basename = uniq_modules[file] # special case for the main program module if file == program: - f = open('__main__.py', 'wt') + f = open('X__main__.py', 'wt') # big ol' hack. insert some magic to make the main script look like it - # was run directly instead of imported. better solutions welcome. note - # than setting __name__ to '__main__' is not always sufficient (e.g. - # pickle can complain about missing classes when loading). + # was run directly instead of imported. better solutions welcome. inject = 1 for line in open(program, 'rt'): if (inject and (line.startswith('app.start(') or line.startswith('if __name__ =='))): inject = 0 - print >>f, "import sys; sys.modules['__main__'] = sys.modules[__name__]; __name__ = '__main__';" + #print >>f, "import sys; sys.modules['__main__'] = sys.modules[__name__]; __name__ = '__main__';" + print >>f, "__name__ = '__main__';" print >>f, line, f.close() - out.writepy('__main__.py', basename) + out.writepy('X__main__.py', basename) for ext in ('.py', '.pyc', '.pyo'): - prog_name = '__main__' + ext + prog_name = 'X__main__' + ext if os.path.exists(prog_name): os.unlink(prog_name) - main_module = '.'.join(basename.split(os.sep) + ['__main__']) + if basename: + main_module = '.'.join(basename.split(os.sep) + ['X__main__']) + else: + main_module = 'X__main__' # add a stub so that the entry point is always import <ENTRY_MODULE> f = open(ENTRY_MODULE+'.py', 'wt') f.write('import %s\n' % main_module) |
From: <sv...@ww...> - 2004-06-13 03:02:10
|
Author: mkrose Date: 2004-06-12 20:02:03 -0700 (Sat, 12 Jun 2004) New Revision: 1028 Modified: trunk/CSP/SimData/CHANGES.current trunk/CSP/SimData/Include/SimData/Ref.h Log: Disallow copying for Referenced subclasses. Modified: trunk/CSP/SimData/CHANGES.current =================================================================== --- trunk/CSP/SimData/CHANGES.current 2004-06-13 02:59:08 UTC (rev 1027) +++ trunk/CSP/SimData/CHANGES.current 2004-06-13 03:02:03 UTC (rev 1028) @@ -13,6 +13,9 @@ * Added tagged record compiler and associated header. + * Disallowed copying of Referenced derived classes (should always + use Ref<> pointers). + 2004-16-12: wolverine * added a MemoryWriter class to write out a SimData object to a binary memory buffer. Added a MemoryReader class. Added Modified: trunk/CSP/SimData/Include/SimData/Ref.h =================================================================== --- trunk/CSP/SimData/Include/SimData/Ref.h 2004-06-13 02:59:08 UTC (rev 1027) +++ trunk/CSP/SimData/Include/SimData/Ref.h 2004-06-13 03:02:03 UTC (rev 1028) @@ -90,6 +90,11 @@ } inline unsigned _count() const { return __count; } mutable unsigned __count; + + // Referenced objects should never be copied; always allocate them on the + // heap and use Ref<> smart-pointers to refer to them. + Referenced const & operator=(Referenced const &); + Referenced(Referenced const &); }; |
From: <sv...@ww...> - 2004-06-13 02:59:17
|
Author: mkrose Date: 2004-06-12 19:59:08 -0700 (Sat, 12 Jun 2004) New Revision: 1027 Added: trunk/CSP/SimData/Include/SimData/TaggedRecord.h trunk/CSP/SimData/Tools/TaggedRecordCompiler/ trunk/CSP/SimData/Tools/TaggedRecordCompiler/BaseTypes.py trunk/CSP/SimData/Tools/TaggedRecordCompiler/CodeFormat.py trunk/CSP/SimData/Tools/TaggedRecordCompiler/bootstrap.py trunk/CSP/SimData/Tools/TaggedRecordCompiler/trc.py Modified: trunk/CSP/SimData/CHANGES.current Log: Add tagged record compiler and related include files. Allows data record descriptions to be compiled into classes that hold the specified data and can be serialized into a tagged binary format. Modified: trunk/CSP/SimData/CHANGES.current =================================================================== --- trunk/CSP/SimData/CHANGES.current 2004-06-13 00:56:10 UTC (rev 1026) +++ trunk/CSP/SimData/CHANGES.current 2004-06-13 02:59:08 UTC (rev 1027) @@ -11,6 +11,8 @@ * Minor tweaks to unsigned Reader/Writer classes to used fixed size integers. + * Added tagged record compiler and associated header. + 2004-16-12: wolverine * added a MemoryWriter class to write out a SimData object to a binary memory buffer. Added a MemoryReader class. Added Added: trunk/CSP/SimData/Include/SimData/TaggedRecord.h =================================================================== --- trunk/CSP/SimData/Include/SimData/TaggedRecord.h 2004-06-13 00:56:10 UTC (rev 1026) +++ trunk/CSP/SimData/Include/SimData/TaggedRecord.h 2004-06-13 02:59:08 UTC (rev 1027) @@ -0,0 +1,332 @@ +#ifndef __SIMDATA_TRF_H__ +#define __SIMDATA_TRF_H__ + +#include <string> +#include <stack> +#include <vector> +#include <sstream> +#include <cassert> +#include <ostream> + +#include <SimData/Ref.h> +#include <SimData/Archive.h> +#include <SimData/Namespace.h> + +NAMESPACE_SIMDATA + +// use our own, platform-neutral int64 representation +// TODO the base class (hasht) should probably renamed. +typedef hasht int64; + + +/** + * Simple Writer class for serializing to a string buffer. + */ +class StringWriter: public Writer { + std::string _buffer; +public: + StringWriter() { + _buffer.reserve(1024); + } + virtual Writer & operator<<(char const x) { + _buffer.append(reinterpret_cast<const char*>(&x), sizeof(x)); + return *this; + } + virtual Writer & operator<<(int16 const x) { + _buffer.append(reinterpret_cast<const char*>(&x), sizeof(x)); + return *this; + } + virtual Writer & operator<<(int32 const x) { + _buffer.append(reinterpret_cast<const char*>(&x), sizeof(x)); + return *this; + } + virtual Writer & operator<<(int64 const x) { + _buffer.append(reinterpret_cast<const char*>(&x), sizeof(x)); + return *this; + } + virtual Writer & operator<<(uint8 const x) { + _buffer.append(reinterpret_cast<const char*>(&x), sizeof(x)); + return *this; + } + virtual Writer & operator<<(uint16 const x) { + _buffer.append(reinterpret_cast<const char*>(&x), sizeof(x)); + return *this; + } + virtual Writer & operator<<(uint32 const x) { + _buffer.append(reinterpret_cast<const char*>(&x), sizeof(x)); + return *this; + } + virtual Writer & operator<<(float const x) { + _buffer.append(reinterpret_cast<const char*>(&x), sizeof(x)); + return *this; + } + virtual Writer & operator<<(double const x) { + _buffer.append(reinterpret_cast<const char*>(&x), sizeof(x)); + return *this; + } + virtual Writer & operator<<(bool const x) { + _buffer.append(reinterpret_cast<const char*>(&x), sizeof(x)); + return *this; + } + virtual Writer & operator<<(hasht const &x) { + _buffer.append(reinterpret_cast<const char*>(&x), sizeof(x)); + return *this; + } + virtual Writer & operator<<(char const *x) { + assert(0); + return *this; + } + virtual Writer & operator<<(BaseType const &x) { + x.serialize(*this); + return *this; + } + virtual Writer & operator<<(std::string const &x) { + writeLength(x.size()); + _buffer.append(x); + return *this; + } + std::string str() const { + return _buffer; + } +}; + +/** + * Simple Reader class for serializing from a string buffer. + */ +class StringReader: public Reader { + const unsigned char *_data; + int _bytes; +public: + StringReader(std::string const &buffer) + : _data(reinterpret_cast<const unsigned char *>(buffer.data())), + _bytes(buffer.size()) { } + virtual Reader & operator>>(char &x) { + assert(_bytes >= sizeof(x)); + x = *(reinterpret_cast<char const*>(_data)); + _data += sizeof(x); + _bytes -= sizeof(x); + return *this; + } + virtual Reader & operator>>(int16 &x) { + assert(_bytes >= sizeof(x)); + x = *(reinterpret_cast<int16 const*>(_data)); + _data += sizeof(x); + _bytes -= sizeof(x); + return *this; + } + virtual Reader & operator>>(int32 &x) { + assert(_bytes >= sizeof(x)); + x = *(reinterpret_cast<int32 const*>(_data)); + _data += sizeof(x); + _bytes -= sizeof(x); + return *this; + } + virtual Reader & operator>>(int64 &x) { + assert(_bytes >= sizeof(x)); + x = *(reinterpret_cast<int64 const*>(_data)); + _data += sizeof(x); + _bytes -= sizeof(x); + return *this; + } + virtual Reader & operator>>(uint8 &x) { + assert(_bytes >= sizeof(x)); + x = *(reinterpret_cast<uint8 const*>(_data)); + _data += sizeof(x); + _bytes -= sizeof(x); + return *this; + } + virtual Reader & operator>>(uint16 &x) { + assert(_bytes >= sizeof(x)); + x = *(reinterpret_cast<uint16 const*>(_data)); + _data += sizeof(x); + _bytes -= sizeof(x); + return *this; + } + virtual Reader & operator>>(uint32 &x) { + assert(_bytes >= sizeof(x)); + x = *(reinterpret_cast<uint32 const*>(_data)); + _data += sizeof(x); + _bytes -= sizeof(x); + return *this; + } + virtual Reader & operator>>(float &x) { + assert(_bytes >= sizeof(x)); + x = *(reinterpret_cast<float const*>(_data)); + _data += sizeof(x); + _bytes -= sizeof(x); + return *this; + } + virtual Reader & operator>>(double &x) { + assert(_bytes >= sizeof(x)); + x = *(reinterpret_cast<double const*>(_data)); + _data += sizeof(x); + _bytes -= sizeof(x); + return *this; + } + virtual Reader & operator>>(bool &x) { + assert(_bytes >= sizeof(x)); + x = *(reinterpret_cast<bool const*>(_data)); + _data += sizeof(x); + _bytes -= sizeof(x); + return *this; + } + virtual Reader & operator>>(char * &x) { + assert(0); + return *this; + } + virtual Reader & operator>>(BaseType &x) { + x.serialize(*this); + return *this; + } + virtual Reader & operator>>(std::string &x) { + int length = readLength(); + assert(_bytes >= length); + x.clear(); + x.append(reinterpret_cast<const char*>(_data), length); + _data += length; + _bytes -= length; + return *this; + } +}; + + +/** + * Base class for TagWriter and TagReader which manages a stack + * of nested records. + */ +class TagBase { + protected: + std::stack<int> _tagstack; + enum { TAG_END = 0 }; + int _lasttag; + public: + TagBase(): _lasttag(0) { } +}; + + +/** + * Class for writing tagged records to wire format. + */ +class TagWriter: public TagBase { + public: + Writer &writer; + TagWriter(Writer &writer_): TagBase(), writer(writer_) { } + void writeTag(int tag) { + int delta = tag - _lasttag; + _lasttag = tag; + if (delta < 128) { + writer << static_cast<unsigned char>(delta); + } else { + unsigned char thi = static_cast<unsigned char>(delta >> 7); + unsigned char tlo = static_cast<unsigned char>(0x80 | (delta & 0x7f)); + writer << tlo << thi; + } + } + void beginCompound() { + _tagstack.push(_lasttag); + _lasttag = 0; + } + void endCompound() { + writer << static_cast<unsigned char>(TAG_END); + _lasttag = _tagstack.top(); + _tagstack.pop(); + } + void writeLength(int x) { + assert(x >= 0); + while (x >= 128) { + writer << static_cast<unsigned char>(0x80 | (x & 0x7f)); + x >>= 7; + } + writer << static_cast<unsigned char>(x); + } +}; + + +/** + * Class for reading tagged records from wire format. + */ +class TagReader: public TagBase { + public: + Reader &reader; + TagReader(Reader &reader_): TagBase(), reader(reader_) { } + int nextTag() { + uint8 ubyte; + reader >> ubyte; + if (ubyte == 0) { return 0; } + int delta = ubyte & 0x7f; + if (ubyte & 0x80) { + reader >> ubyte; + delta |= ubyte << 7; + } + _lasttag += delta; + return _lasttag; + } + void beginCompound() { + _tagstack.push(_lasttag); + _lasttag = 0; + } + void endCompound() { + _lasttag = _tagstack.top(); + _tagstack.pop(); + } + int readLength() { + int length = 0; + int sh = 0; + unsigned char x; + do { + reader >> x; + length |= (x & 0x7f) << sh; + sh += 7; + } while (x & 0x80); + return length; + } +}; + + +/** + * Base class for auto-generated record classes that can be serialized + * to a tagged binary format. Subclasses are generated by compiling + * record definitions with the TaggedRecordCompiler. + */ +class TaggedRecord: public Referenced { +public: + typedef int64 Id; + virtual void serialize(TagReader &reader) = 0; + virtual void serialize(TagWriter &writer) const = 0; + virtual Id getId() const=0; + virtual int getVersion() const=0; + virtual std::string getName() const=0; + virtual void dump(std::ostream &, int indent=0) const=0; +protected: + virtual ~TaggedRecord() {} +}; + + +// dump a human-readable representation of a TaggedRecord instance +inline std::ostream & operator << (std::ostream &os, TaggedRecord const &tr) { + tr.dump(os); + return os; +} + + +/** + * Small helper class for indenting TaggedRecord dumps. + */ +class Indent { +public: + int level; + Indent(int level_=0): level(level_) {} + Indent & operator++() { ++level; return *this; } + Indent & operator--() { --level; return *this; } +}; + +std::ostream & operator << (std::ostream &os, Indent const &indent) { + for (int i = 0; i < indent.level; ++i) os << " "; + return os; +} + + +NAMESPACE_SIMDATA_END + +#endif // __SIMDATA_TRF_H__ + Added: trunk/CSP/SimData/Tools/TaggedRecordCompiler/BaseTypes.py =================================================================== --- trunk/CSP/SimData/Tools/TaggedRecordCompiler/BaseTypes.py 2004-06-13 00:56:10 UTC (rev 1026) +++ trunk/CSP/SimData/Tools/TaggedRecordCompiler/BaseTypes.py 2004-06-13 02:59:08 UTC (rev 1027) @@ -0,0 +1,644 @@ +# SimData: Data Infrastructure for Simulations +# Copyright 2004 Mark Rose <mk...@us...> +# +# This file is part of SimData. +# +# 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. + +""" +Data types supported by the trf format. +""" + +import sys + +import CodeFormat + +import md5 +def md5hash(s): + """return a 64-bit (python long) hash of a string""" + return long(md5.md5(s).hexdigest()[:16], 16) + + +class Declaration: + DEFAULT = 0 + COMPOUND = 0 + MULTIPLE = 0 + TOPLEVEL = 0 + ANONYMOUS = 0 + TYPEDEF = 0 + ANONYMOUS_COUNT = {} + DELETE = 0 + POINTER = 0 + + def __init__(self, id, opts=None, name=None): + if id is None: id = '' + anon = self.__class__.ANONYMOUS + if anon: + assert id == '' + count = Declaration.ANONYMOUS_COUNT.setdefault(anon, 0) + id = '%s%d' % (anon, count) + Declaration.ANONYMOUS_COUNT[anon] = count + 1 + if not self.__class__.DEFAULT: + assert opts is None or not opts.has_key('DEFAULT') + self.id = id + self.opts = opts + self.child = None + self.elements = [] + self.localtypes = {} + self.name = name + self.init() + + def dump_init(self, format, comma): + text = '%s(%s)' % (self.varname(), self.default()) + if comma: text = text + ',' + format.write(text) + + def dump_clear(self, format): + format.write('void clear_%s() { m_has_%s = 0; }' % (self.id, self.id)) + + def init(self): pass + def dump_private(self, format): assert 0 + def dump_public(self, format): assert 0 + def dump_delete(self, format): assert 0 + def dump_save(self, format): assert 0 + def dump_load(self, format): assert 0 + def dump_print(self, format): assert 0 + def default(self): + if self.isPointer(): return 'NULL' + return self.opts.get('DEFAULT', '') + def fulltype(self): + typename = self.typename() + if self.isPointer(): typename = 'simdata::Ref<%s>' % typename + return typename + def typename(self): return self.__class__.TYPENAME + def isTypedef(self): return self.__class__.TYPEDEF + def needsDelete(self): return self.__class__.DELETE + def isPointer(self): return self.__class__.POINTER + def isCompound(self): return self.__class__.COMPOUND + def isDeprecated(self): return self.opts.get('DEPRECATED', 0) + def varname(self): + if self.name: return self.name + return 'm_' + self.id + + +class CompoundType(Declaration): + COMPOUND = 1 + + def add(self, element): + if element.isTypedef(): + self.localtypes[element.id] = element + else: + self.elements.append(element) + + def classdef(self, format, base=None): + format.write() + if base is None: + format.write('class %s {' % (self.id)) + else: + format.write('class %s: public %s {' % (self.id, base)) + if self.localtypes: + format.write('public:') + format.write() + format.indent() + for typedef in self.localtypes.values(): + typedef.dump(format) + format.write() + format.dedent() + format.write() + format.write('private:') + format.write() + format.indent() + if self.elements: + format.write('enum {') + format.indent() + idx = 8 + for element in self.elements: + format.write('TAG_%s = %d,' % (element.id, idx)) + idx = idx + 1 + format.dedent() + format.write('};') + format.write() + for element in self.elements: + format.write('simdata::int32 m_has_%s : 1;' % (element.id)) + format.write() + for element in self.elements: + element.dump_private(format); + format.dedent() + format.write() + format.write('public:') + format.write() + format.indent() + if self.elements: + format.write('%s():' % self.id) + format.indent() + for idx, element in enumerate(self.elements): + format.write('m_has_%s(0),' % element.id) + comma = (idx + 1) < len(self.elements) + element.dump_init(format, comma) + format.dedent() + format.write('{ }') + format.write() + deletes = [x for x in self.elements if x.needsDelete()] + if deletes: + format.write('~%s() {' % self.id) + format.indent() + for delete in deletes: + delete.dump_delete(format) + format.dedent() + format.write('}') + format.write() + for element in self.elements: + format.write('bool has_%s() const { return m_has_%s; }' % (element.id, element.id)) + element.dump_clear(format) + format.write() + for element in self.elements: + element.dump_public(format); + format.write() + self._declaration(format) + format.dedent() + format.write('public:') + format.indent() + self._save(format) + self._load(format) + self._print(format) + self._extra(format) + format.dedent() + format.write('};') + format.write() + + def _declaration(self, format): + pass + + def _save(self, format): + format.write('void serialize(simdata::TagWriter &writer) const {') + format.indent() + format.write('writer.beginCompound();') + for element in self.elements: + format.write('if (m_has_%s) {' % element.id) + format.indent() + format.write('writer.writeTag(TAG_%s);' % element.id) + element.dump_save(format) + format.dedent() + format.write('}') + format.write('writer.endCompound();') + format.dedent() + format.write('}') + + def _load(self, format): + format.write('void serialize(simdata::TagReader &reader) {') + format.indent() + format.write('reader.beginCompound();') + format.write('while (1) {') + format.indent() + format.write('int tag = reader.nextTag();') + format.write('if (!tag) break;') + format.write('switch (tag) {') + for element in self.elements: + format.write('case TAG_%s: {' % element.id) + format.indent() + format.write('m_has_%s = 1;' % element.id) + element.dump_load(format) + format.write('break; }') + format.dedent() + format.write('default: break;') + format.write('}') + format.dedent() + format.write('}') + format.write('reader.endCompound();') + format.dedent() + format.write('}') + + def _print(self, format): + format.write('void dump(std::ostream &os, int level=0) const {') + format.indent() + format.write('simdata::Indent indent(level);') + format.write('os << indent << "%s <\\n";' % self.id) + format.write('++indent;') + for element in self.elements: + format.write('if (m_has_%s) {' % element.id) + format.indent() + format.write('os << indent << "%s: ";' % element.id) + element.dump_print(format) + format.write('os << "\\n";') + format.dedent() + format.write('}') + format.write('--indent;') + format.write('os << indent << ">";') + format.dedent() + format.write('}') + + def _extra(self, format): + pass + + def dump_save(self, format): + if self.isPointer(): + format.write('%s->serialize(writer);' % self.varname()) + else: + format.write('%s.serialize(writer);' % self.varname()) + + def dump_load(self, format): + if self.isPointer(): + type = self.typename() + format.write('%s = new %s();' % (self.varname(), type)) + format.write('%s->serialize(reader);' % self.varname()) + else: + format.write('%s.serialize(reader);' % self.varname()) + + def dump_print(self, format): + if self.isPointer(): + format.write('%s->dump(os, indent.level);' % self.varname()) + else: + format.write('%s.dump(os, indent.level);' % self.varname()) + + +class SimpleType(Declaration): + DEFAULT = 1 + + CT_SET = ''' + void set_%(id)s(%(type)s const & value) { + >m_has_%(id)s = true; + >m_%(id)s = value; + } + ''' + + def dump_private(self, format): + self.dump_decl(format) + + def dump_public(self, format): + self.dump_get(format) + self.dump_set(format) + + def dump_decl(self, format): + type = self.typename() + format.write('%s %s;' % (type, self.varname())) + + def dump_get(self, format): + type = self.typename() + id = self.id + format.write('%s const & %s() const { return m_%s; }' % (type, id, id)) + + def dump_set(self, format): + if self.isDeprecated(): return + d = {'id': self.id, 'type': self.typename()} + format.template(SimpleType.CT_SET, d) + return + type = self.typename() + id = self.id + format.write('void set_%s(%s const &value) {' % (id, type)) + format.indent() + format.write('m_has_%s = true;' % (id)) + format.write('%s = value;' % self.varname()) + format.dedent() + format.write('}') + + def dump_save(self, format): + format.write('writer.writer << %s;' % self.varname()) + + def dump_load(self, format): + format.write('reader.reader >> %s;' % self.varname()) + + def dump_print(self, format): + format.write('os << %s;' % self.varname()) + + +class ArrayType(Declaration): + + def __init__(self, id, childtype, opts=None): + Declaration.__init__(self, id, opts=opts) + self.child = childtype(id, name='%s[i]' % self.varname()) + + CT_SET = ''' + std::vector< %(type)s > & set_%(id)s() { + >m_has_%(id)s = true; + >return %(name)s; + } + ''' + + def dump_private(self, format): + self.dump_decl(format) + + def dump_public(self, format): + self.dump_get(format) + self.dump_set(format) + + def dump_decl(self, format): + type = self.child.fulltype() + format.write('std::vector< %s > %s;' % (type, self.varname())) + + def dump_clear(self, format): + format.write('void clear_%s() {' % self.id) + format.indent() + format.write('m_has_%s = 0;' % self.id) + format.write('%s.clear();' % self.varname()) + format.dedent() + format.write('}') + + def dump_get(self, format): + type = self.child.fulltype() + id = self.id + name = self.varname() + format.write('std::vector< %s > const & %s() const { return %s; }' % (type, id, name)) + + def dump_set(self, format): + if self.isDeprecated(): return + type = self.child.fulltype() + d = {'id': self.id, 'type': type, 'name': self.varname()} + format.template(ArrayType.CT_SET, d) + + def dump_save(self, format): + format.write('writer.writeLength(%s.size());' % self.varname()) + format.write('for (int i=0; i < %s.size(); ++i) {' % self.varname()) + format.indent() + self.child.dump_save(format) + format.dedent() + format.write('}') + + def dump_load(self, format): + format.write('int %s_len = reader.readLength();' % self.id) + format.write('%s.resize(%s_len);' % (self.varname(), self.id)) + format.write('for (int i=0; i < %s_len; ++i) {' % self.id) + format.indent() + self.child.dump_load(format) + format.dedent() + format.write('}') + + def dump_print(self, format): + format.write('os << "[\\n";') + format.write('++indent;') + format.write('for (int i=0; i < %s.size(); ++i) {' % self.varname()) + format.indent() + self.child.dump_print(format) + format.write('os << "\\n";') + format.dedent() + format.write('}') + format.write('--indent;') + format.write('os << "]";') + + +class TrfType(SimpleType): + def typename(self): + return 'simdata::' + SimpleType.typename(self) + + +class Message(CompoundType): + DEFAULT = 0 + MULTIPLE = 0 + TOPLEVEL = 1 + TYPEDEF = 0 + POINTER = 1 + DELETE = 0 + TYPENAME = 'Message' + + def __call__(self, id, opts=None, name=None): + message = Message(id, opts=opts, name=name) + message.TYPENAME = self.id + return message + + def typename(self): return self.TYPENAME + + def dump(self, format=None, file=file): + if not format: + format = CodeFormat.Format(file=file) + base = self.opts.get('BASE', 'simdata::TaggedRecord') + self.classdef(format, base) + + def _extra(self, format): + CompoundType._extra(self, format) + name = self.id + try: + version = int(self.opts.get('VERSION', 0)) + except ValueError: + print >>sys.stderr, 'ERROR: VERSION option on %s must be an integer' % name + sys.exit(1) + id = md5hash('%s_%d' % (name, version)) + d = {'name': name, 'version': version, 'id': id} + format.template(Message.TRF_GETID, d) + format.template(Message.TRF_GETVERSION, d) + format.template(Message.TRF_GETNAME, d) + + def dump_private(self, format): + format.write('simdata::Ref<%s> %s;' % (self.typename(), self.varname())) + + def dump_public(self, format): + d = {'id': self.id, 'name': self.varname(), 'type': self.typename()} + format.template(Message.TRF_GET, d) + format.template(Message.TRF_SET, d) + + TRF_GETID = ''' + virtual Id getId() const { return _getId(); } + static inline Id _getId() { return %(id)dll; } + ''' + + TRF_GETVERSION = ''' + virtual int getVersion() const { return _getVersion(); } + static inline int _getVersion() { return %(version)d; } + ''' + + TRF_GETNAME = ''' + virtual std::string getName() const { return _getName(); } + static inline std::string _getName() { return "%(name)s"; } + ''' + + def dump_delete(self, format): + format.write('delete %s;' % self.varname()) + + def _declaration(self, format): + pass + + TRF_SET = ''' + simdata::Ref<%(type)s> & set_%(id)s() { + >m_has_%(id)s = 1; + >if (%(name)s.isNull()) %(name)s = new %(type)s(); + >return %(name)s; + } + ''' + + TRF_GET = ''' + simdata::Ref<%(type)s> const & %(id)s() const { + >return %(name)s; + } + ''' + + +class Group(CompoundType): + TYPENAME = 'group' + TYPEDEF = 1 + + def add(self, element): + self.elements.append(element); + + def dump(self, format): + self.classdef(format, base='simdata::Referenced') + + def __call__(self, id, opts=None, name=None): + return GroupDeclaration(self.id, id, opts=opts, name=name) + + +class GroupDeclaration(CompoundType): + DELETE = 0 + POINTER = 1 + + TRF_DECL = ''' + simdata::Ref<%(type)s> m_%(id)s; + ''' + + TRF_SET = ''' + simdata::Ref<%(type)s> & set_%(id)s() { + >m_has_%(id)s = 1; + >if (m_%(id)s.isNull()) m_%(id)s = new %(type)s(); + >return m_%(id)s; + } + ''' + + TRF_GET = ''' + simdata::Ref<%(type)s> const & %(id)s() const { + >return m_%(id)s; + } + ''' + + def __init__(self, typename, id, opts=None, name=None): + CompoundType.__init__(self, id, opts=opts, name=name) + self._typename = typename + + def typename(self): return self._typename + + def dump_private(self, format): + d = {'id': self.id, 'type': self._typename} + format.template(GroupDeclaration.TRF_DECL, d) + + def dump_public(self, format): + d = {'id': self.id, 'type': self._typename} + format.template(GroupDeclaration.TRF_GET, d) + format.template(GroupDeclaration.TRF_SET, d) + + def dump_delete(self, format): + format.write('delete %s;' % self.varname()) + + +class Bitset(CompoundType): + TYPENAME = 'bitset' + ANONYMOUS = 'bitset' + + def add(self, element): + assert element.TYPENAME == 'bool' + assert len(self.elements) < 32 + self.elements.append(element); + + def default(self): + value = 0 + mask = 1 + for bool in self.elements: + if int(bool.default()): + value |= mask + mask <<= 1 + return '0x%08x' % value + + def dump_private(self, format): + width = 32 + format.write('simdata::int%d %s;' % (width, self.varname())) + + def dump_get(self, format): + mask = 1 + for bool in self.elements: + format.write('bool %s() const {' % bool.id) + format.indent() + format.write('return (%s & 0x%08x) != 0;' % (self.varname(), mask)) + format.dedent() + format.write('}') + mask = mask << 1 + + def dump_set(self, format): + mask = 1 + id = self.id + name = self.varname() + for bool in self.elements: + if not bool.isDeprecated(): + format.write('void set_%s(bool state) {' % bool.id) + format.indent() + format.write('m_has_%s = true;' % id); + format.write('%s = state ? (%s | 0x%08x) : (%s & ~0x%08x);' % (name, name, mask, name, mask)) + format.dedent() + format.write('}') + mask = mask << 1 + + def dump_public(self, format): + self.dump_get(format) + self.dump_set(format) + + def dump_save(self, format): + format.write('writer.writer << %s;' % self.varname()) + + def dump_load(self, format): + format.write('reader.reader >> %s;' % self.varname()) + + def dump_print(self, format): + for bool in self.elements: + format.write('os << indent << "%s: " << "\\n";' % bool.id) + +class t_bool(SimpleType): TYPENAME = 'bool' +class t_float(SimpleType): TYPENAME = 'float' +class t_double(SimpleType): TYPENAME = 'double' +class t_int64(TrfType): TYPENAME = 'int64' +class t_int32(TrfType): TYPENAME = 'int32' +class t_int16(TrfType): TYPENAME = 'int16' +class t_int8(TrfType): TYPENAME = 'int8' +class t_string(SimpleType): TYPENAME = 'std::string' + + +class SimDataType(SimpleType): + def typename(self): + return SimpleType.typename(self) + +class t_Matrix3(SimDataType): TYPENAME = 'simdata::Matrix3' +class t_Quat(SimDataType): TYPENAME = 'simdata::Quat' +class t_Vector3(SimDataType): TYPENAME = 'simdata::Vector3' +class t_Key(SimDataType): TYPENAME = 'simdata::Key' +class t_Date(SimDataType): TYPENAME = 'simdata::SimDate' +class t_Path(SimDataType): TYPENAME = 'simdata::Path' + +#class t_TimeStamp(SimDataType): TYPENAME = 'TimeStamp' +#class t_Vector3f(SimDataType): TYPENAME = 'Vector3f' +#class t_Quatf(SimDataType): TYPENAME = 'Quatf' + +TYPES = [Message, Bitset, Group] + +TYPES.extend([ + t_float, + t_double, + t_int64, + t_int32, + t_int16, + t_int8, + t_bool, + t_string, +]) + +TYPES.extend([ + t_Matrix3, + t_Quat, + t_Vector3, + t_Key, + t_Date, + t_Path, +]) + +TYPEMAP = {} + +def RegisterType(type): + global TYPEMAP + TYPEMAP[type.TYPENAME] = type + +map(RegisterType, TYPES) + Added: trunk/CSP/SimData/Tools/TaggedRecordCompiler/CodeFormat.py =================================================================== --- trunk/CSP/SimData/Tools/TaggedRecordCompiler/CodeFormat.py 2004-06-13 00:56:10 UTC (rev 1026) +++ trunk/CSP/SimData/Tools/TaggedRecordCompiler/CodeFormat.py 2004-06-13 02:59:08 UTC (rev 1027) @@ -0,0 +1,64 @@ +# SimData: Data Infrastructure for Simulations +# Copyright 2004 Mark Rose <mk...@us...> +# +# This file is part of SimData. +# +# 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. + +""" +Helper class for formatting nested output. +""" + +import sys + +class Format: + + def __init__(self, file=None, indent=''): + if file is None: + file = sys.stdout + self._file = file + self._indent = indent + + def indent(self): + self._indent = self._indent + ' ' + + def dedent(self): + self._indent = self._indent[:-2] + + def write(self, text=''): + if text: + print >>self._file, '%s%s' % (self._indent, text) + else: + print >>self._file + + def template(self, template, dict): + template = template % dict + n = 0 + for line in template.split('\n'): + n += 1 + line = line.strip() + if not line: continue + if line == '.': + self.write(); + continue + indent = 0 + istr = '' + while indent < len(line) and line[indent] == '>': + indent += 1 + istr += ' ' + line = istr + line[indent:] + if line: + self.write(line) + Added: trunk/CSP/SimData/Tools/TaggedRecordCompiler/bootstrap.py =================================================================== --- trunk/CSP/SimData/Tools/TaggedRecordCompiler/bootstrap.py 2004-06-13 00:56:10 UTC (rev 1026) +++ trunk/CSP/SimData/Tools/TaggedRecordCompiler/bootstrap.py 2004-06-13 02:59:08 UTC (rev 1027) @@ -0,0 +1,33 @@ +# SimData: Data Infrastructure for Simulations +# Copyright 2004 Mark Rose <mk...@us...> +# +# This file is part of SimData. +# +# 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. + +try: + import CSP +except: + import sys + import os.path + dn = os.path.dirname + csp_root = dn(dn(dn(dn(dn(__file__))))) + sys.path.insert(0, csp_root) + try: + import CSP + except: + print 'Unable to import the main CSP module. Check that you have' + print 'a complete working copy.' + sys.exit(1) Added: trunk/CSP/SimData/Tools/TaggedRecordCompiler/trc.py =================================================================== --- trunk/CSP/SimData/Tools/TaggedRecordCompiler/trc.py 2004-06-13 00:56:10 UTC (rev 1026) +++ trunk/CSP/SimData/Tools/TaggedRecordCompiler/trc.py 2004-06-13 02:59:08 UTC (rev 1027) @@ -0,0 +1,200 @@ +#!/usr/bin/python +# +# SimData: Data Infrastructure for Simulations +# Copyright 2004 Mark Rose <mk...@us...> +# +# This file is part of SimData. +# +# 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. + +""" +Standalone compiler for converting tagged record descriptions +into C++ classes. + +Usage: %(prog)s [options] infile +""" + +import sys +import os +import os.path +import re + +import bootstrap +from CSP.base import app + +import BaseTypes + + +HEADER="""// generated file --- do not edit!' + +#ifndef __%(module_uc)s_TRF_H__ +#define __%(module_uc)s_TRF_H__ + +#include <SimData/TaggedRecord.h> +%(includes)s +""" + +FOOTER = """ +#endif // __%(module_uc)s_TRF_H__ +""" + + +class DataPackCompiler: + + re_line = re.compile(r'^(\w*:?:?\w+)(\[\])?\s+(\w*)\s*((?:\s+\w+\s*=\s*\w+)*)\s*({|})?$') + re_opts = re.compile(r'\s*=\s*') + re_ns = re.compile(r'namespace\s+([a-zA-Z_][a-zA-Z0-9]*)\s*;?') + + class Node: + pass + + def __init__(self, file, outfile): + self._root = None + self._active = None + self._outfile = outfile + self._parse(file) + + def _parse(self, source): + module = os.path.basename(source) + module = os.path.splitext(module)[0] + module = module.replace('.', '_') + self.source = source + file = open(source) + line_number = 0 + depth = 0 + dp = DataPackCompiler + object = None + object_stack = [] + toplevel = [] + toplevel_types = {} + includes = [] + namespace = '' + header = 1 + for line in file: + line_number = line_number + 1 + trim = line.strip() + if not trim: continue + if header and trim.startswith('#include'): + includes.append(trim) + continue + if header and trim.startswith('namespace'): + m = DataPackCompiler.re_ns.match(trim) + if m: + if namespace: self.error('multiple namespace declarations') + namespace = m.groups(1) + continue + else: + self.error('syntax error') + if trim.startswith('//'): + continue + header = 0 + while trim: + rest = '' + idx1 = trim.find('{') + idx2 = trim.find(';') + if idx1 >= 0 and (idx2 < 0 or idx2 > idx1): + rest = trim[idx1+1:].strip() + trim = trim[:idx1+1].strip() + elif idx2 >= 0: + rest = trim[idx2+1:].strip() + trim = trim[:idx2].strip() + while trim.startswith('}'): + if depth < 1: + self.error(line_number, 'unmatched brace') + depth = depth - 1 + object_stack = object_stack[:-1] + trim = trim[1:] + if not trim: + trim = rest + continue + m = dp.re_line.match(trim) + if m is None: + print trim + self.error(line_number, 'invalid syntax.') + type, array, id, options, block = m.groups() + if type is None: + self.error(line_number, 'invalid syntax (no type)') + type_class = None + if object_stack: + parent = object_stack[-1] + type_class = parent.localtypes.get(type, None) + if type_class is None: + type_class = BaseTypes.TYPEMAP.get(type, None) + if type_class is None: + type_class = toplevel_types.get(type, None) + if type_class is None: + self.error(line_number, 'unknown data type "%s"' % type) + if not id and not type_class.ANONYMOUS: + self.error(line_number, 'invalid syntax (unnamed field)') + if options is not None: + options = dp.re_opts.sub('=', options).strip() + option_list = options.split() + options = {} + for option_pair in option_list: + option, value = option_pair.split('=') + options[option] = value + if array: + object = BaseTypes.ArrayType(id, type_class, opts=options) + else: + object = type_class(id, opts=options) + if len(object_stack) > 0: + object_stack[-1].add(object) + else: + if not type_class.TOPLEVEL: + self.error(line_number, 'syntax error') + toplevel.append(object) + toplevel_types[id] = object + if block is not None: + if block == '{': + # TODO check that type supports blocks + depth = depth + 1 + object_stack.append(object) + else: + if depth < 1: + self.error(line_number, 'unmatched brace') + depth = depth - 1 + object_stack = object_stack[:-1] + trim = rest + if depth > 0: + self.error(line_number, 'unmatched brace') + includes = '\n'.join(includes) + values = {'module_uc': module.upper(), 'module': module, 'includes': includes}; + print >>self._outfile, HEADER % values + if namespace: print >>self._outfile, 'namespace %s {' % namespace + [x.dump(file=self._outfile) for x in toplevel] + if namespace: print >>self._outfile, '} // namespace %s' % namespace + print >>self._outfile, FOOTER % values + + def error(self, line_number, msg): + print >>sys.stderr, 'line %d: %s' % (line_number, msg) + sys.exit(1) + + +def main(args): + if len(args) != 1: + app.usage() + return 1 + output = app.options.output + if output: + outfile = open(output, 'wt') + else: + outfile = sys.stdout + file = args[0] + DataPackCompiler(file, outfile) + return 0 + +app.addOption('-o', '--output', metavar='FILE', default='', help='output file (default stdout)') +app.start() + Property changes on: trunk/CSP/SimData/Tools/TaggedRecordCompiler/trc.py ___________________________________________________________________ Name: svn:executable + * |
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__ + |
From: <sv...@ww...> - 2004-06-12 22:49:36
|
Author: mkrose Date: 2004-06-12 15:49:26 -0700 (Sat, 12 Jun 2004) New Revision: 1025 Modified: trunk/CSP/SimData/CHANGES.current trunk/CSP/SimData/Include/SimData/Archive.h Log: Fixup integer sizes in reader/writer classes. Modified: trunk/CSP/SimData/CHANGES.current =================================================================== --- trunk/CSP/SimData/CHANGES.current 2004-06-12 22:14:57 UTC (rev 1024) +++ trunk/CSP/SimData/CHANGES.current 2004-06-12 22:49:26 UTC (rev 1025) @@ -8,6 +8,9 @@ * Added isNull() method to Ref. + * Minor tweaks to unsigned Reader/Writer classes to used fixed + size integers. + 2004-16-12: wolverine * added a MemoryWriter class to write out a SimData object to a binary memory buffer. Added a MemoryReader class. Added Modified: trunk/CSP/SimData/Include/SimData/Archive.h =================================================================== --- trunk/CSP/SimData/Include/SimData/Archive.h 2004-06-12 22:14:57 UTC (rev 1024) +++ trunk/CSP/SimData/Include/SimData/Archive.h 2004-06-12 22:49:26 UTC (rev 1025) @@ -42,8 +42,6 @@ NAMESPACE_SIMDATA -class Packer; -class UnPacker; class DataArchive; @@ -83,11 +81,11 @@ virtual bool _loadAll() const { return false; } virtual Reader& operator>>(char &x)=0; - virtual Reader& operator>>(short &x)=0; - virtual Reader& operator>>(int &x)=0; - virtual Reader& operator>>(unsigned char &x)=0; - virtual Reader& operator>>(unsigned short &x)=0; - virtual Reader& operator>>(unsigned int &x)=0; + virtual Reader& operator>>(int16 &x)=0; + virtual Reader& operator>>(int32 &x)=0; + virtual Reader& operator>>(uint8 &x)=0; + virtual Reader& operator>>(uint16 &x)=0; + virtual Reader& operator>>(uint32 &x)=0; virtual Reader& operator>>(bool &x)=0; virtual Reader& operator>>(float &x)=0; virtual Reader& operator>>(double &x)=0; @@ -95,6 +93,7 @@ virtual Reader& operator>>(BaseType &x)=0; virtual Reader& operator>>(hasht &x)=0; virtual Reader& operator>>(std::string &x)=0; + virtual int32 readLength() { int32 n; operator>>(n); return n; } // explicit methods for use from Python @@ -115,13 +114,13 @@ (*self) >> y; return y; } - int _int() { - int y; + int32 _int32() { + SIMDATA(int32) y; (*self) >> y; return y; } - short _short() { - short y; + int16 _int16() { + SIMDATA(int16) y; (*self) >> y; return y; } @@ -130,18 +129,18 @@ (*self) >> y; return y; } - unsigned int _uint() { - unsigned int y; + uint8 _uint8() { + SIMDATA(uint8) y; (*self) >> y; return y; } - unsigned short _ushort() { - unsigned short y; + uint16 _uint16() { + SIMDATA(uint16) y; (*self) >> y; return y; } - unsigned char _uchar() { - unsigned char y; + uint32 _uint32() { + SIMDATA(uint32) y; (*self) >> y; return y; } @@ -205,7 +204,7 @@ template<typename T> Reader& operator>>(Reader& reader, std::vector<T> &y) { - int n; + int32 n; reader >> n; y.resize(n); typename std::vector<T>::iterator i = y.begin(); @@ -222,11 +221,11 @@ virtual ~Writer() {} virtual Writer& operator<<(const char)=0; - virtual Writer& operator<<(const short)=0; - virtual Writer& operator<<(const int)=0; - virtual Writer& operator<<(const unsigned char)=0; - virtual Writer& operator<<(const unsigned short)=0; - virtual Writer& operator<<(const unsigned int)=0; + virtual Writer& operator<<(const int16)=0; + virtual Writer& operator<<(const int32)=0; + virtual Writer& operator<<(const uint8)=0; + virtual Writer& operator<<(const uint16)=0; + virtual Writer& operator<<(const uint32)=0; virtual Writer& operator<<(const bool)=0; virtual Writer& operator<<(const float)=0; virtual Writer& operator<<(const double)=0; @@ -234,6 +233,7 @@ virtual Writer& operator<<(const BaseType &x)=0; virtual Writer& operator<<(const hasht &x)=0; virtual Writer& operator<<(const std::string &x)=0; + virtual void writeLength(int32 n) { operator<<(n); } // explicit packing (use from python) @@ -242,12 +242,12 @@ void _double(double x) { (*self) << x; } void _float(float x) { (*self) << x; } void _bool(bool x) { (*self) << x; } - void _int(int x) { (*self) << x; } - void _short(short x) { (*self) << x; } + void _int32(int32 x) { (*self) << x; } + void _int16(int16 x) { (*self) << x; } void _char(char x) { (*self) << x; } - void _uint(unsigned int x) { (*self) << x; } - void _ushort(unsigned short x) { (*self) << x; } - void _uchar(unsigned char x) { (*self) << x; } + void _uint8(uint8 x) { (*self) << x; } + void _uint16(uint16 x) { (*self) << x; } + void _uint32(uint32 x) { (*self) << x; } void _hasht(hasht const &x) { (*self) << x; } void _string(std::string const &x) { (*self) << x; } void _basetype(BaseType const &x) { (*self) << x; } @@ -277,8 +277,8 @@ */ class SIMDATA_EXPORT ArchiveWriter: public Writer { FILE *_f; - int _n; - void write(const void* x, int n) { + int32 _n; + void write(const void* x, int32 n) { fwrite(x, n, 1, _f); } public: @@ -287,29 +287,29 @@ assert(_f != 0); } void resetCount() { _n = 0; } - int getCount() { return _n; } + int32 getCount() { return _n; } Writer& operator<<(const char x) { write(&x, sizeof(x)); _n += sizeof(x); return *this; } - Writer& operator<<(const short x) { + Writer& operator<<(const int16 x) { write(&x, sizeof(x)); _n += sizeof(x); return *this; } - Writer& operator<<(const int x) { + Writer& operator<<(const int32 x) { write(&x, sizeof(x)); _n += sizeof(x); return *this; } - Writer& operator<<(const unsigned char x) { + Writer& operator<<(const uint8 x) { write(&x, sizeof(x)); _n += sizeof(x); return *this; } - Writer& operator<<(const unsigned short x) { + Writer& operator<<(const uint16 x) { write(&x, sizeof(x)); _n += sizeof(x); return *this; } - Writer& operator<<(const unsigned int x) { + Writer& operator<<(const uint32 x) { write(&x, sizeof(x)); _n += sizeof(x); return *this; } @@ -327,8 +327,8 @@ return *this; } Writer& operator<<(const char* x) { - int n = strlen(x); - operator<<(n); + int32 n = strlen(x); + writeLength(n); write(x, n); _n += n; return *this; @@ -359,7 +359,7 @@ */ class SIMDATA_EXPORT ArchiveReader: public Reader { const char* _d; - int _n; + int32 _n; DataArchive* _archive; bool _loadall; @@ -367,7 +367,7 @@ DataArchive* _getArchive() { return _archive; } bool _loadAll() const { return _loadall; } - ArchiveReader(const char* data, int n, DataArchive* archive=0, bool loadall = true): + ArchiveReader(const char* data, int32 n, DataArchive* archive=0, bool loadall = true): Reader(), _d(data), _n(n), _archive(archive), _loadall(loadall) { } bool isComplete() const { return _n == 0; } @@ -386,14 +386,14 @@ _d += sizeof(float); return *this; } - Reader& operator>>(int &y) { + Reader& operator>>(int32 &y) { _n -= sizeof(int); if (_n < 0) throw DataUnderflow(); memcpy(&y, _d, sizeof(int)); _d += sizeof(int); return *this; } - Reader& operator>>(unsigned int &y) { + Reader& operator>>(uint32 &y) { _n -= sizeof(unsigned int); if (_n < 0) throw DataUnderflow(); memcpy(&y, _d, sizeof(unsigned int)); @@ -406,32 +406,30 @@ y = (x != 0); return *this; } - Reader& operator>>(short &y) { - _n -= sizeof(short); + Reader& operator>>(int16 &y) { + _n -= sizeof(int16); if (_n < 0) throw DataUnderflow(); - memcpy(&y, _d, sizeof(short)); - _d += sizeof(short); + memcpy(&y, _d, sizeof(int16)); + _d += sizeof(int16); return *this; } - Reader& operator>>(unsigned short &y) { - _n -= sizeof(unsigned short); + Reader& operator>>(uint16 &y) { + _n -= sizeof(uint16); if (_n < 0) throw DataUnderflow(); - memcpy(&y, _d, sizeof(unsigned short)); - _d += sizeof(unsigned short); + memcpy(&y, _d, sizeof(uint16)); + _d += sizeof(uint16); return *this; } Reader& operator>>(char &y) { _n -= sizeof(char); if (_n < 0) throw DataUnderflow(); - memcpy(&y, _d, sizeof(char)); - _d += sizeof(char); + y = static_cast<char>(*_d++); return *this; } - Reader& operator>>(unsigned char &y) { - _n -= sizeof(unsigned char); + Reader& operator>>(uint8 &y) { + _n -= sizeof(uint8); if (_n < 0) throw DataUnderflow(); - memcpy(&y, _d, sizeof(unsigned char)); - _d += sizeof(unsigned char); + y = static_cast<uint8>(*_d++); return *this; } Reader& operator>>(hasht &y) { @@ -442,8 +440,7 @@ return *this; } Reader& operator>>(char* &y) { - int n; - operator>>(n); + int32 n = readLength(); // XXX this not really a data underflow if (n < 0) throw DataUnderflow(); _n -= n; @@ -489,29 +486,29 @@ _n += sizeof(char); return *this; } - Writer& operator<<(const short x) { - memcpy(_ptr+_n, &x, sizeof(short)); - _n += sizeof(short); + Writer& operator<<(const int16 x) { + memcpy(_ptr+_n, &x, sizeof(x)); + _n += sizeof(x); return *this; } - Writer& operator<<(const int x) { - memcpy(_ptr+_n, &x, sizeof(x)); - _n += sizeof(int); + Writer& operator<<(const int32 x) { + memcpy(_ptr+_n, &x, sizeof(x)); + _n += sizeof(x); return *this; } - Writer& operator<<(const unsigned char x) { - memcpy(_ptr+_n, &x, sizeof(unsigned char)); - _n += sizeof(unsigned char); + Writer& operator<<(const uint8 x) { + memcpy(_ptr+_n, &x, sizeof(x)); + _n += sizeof(x); return *this; } - Writer& operator<<(const unsigned short x) { - memcpy(_ptr+_n, &x, sizeof(unsigned short)); - _n += sizeof(unsigned short); + Writer& operator<<(const uint16 x) { + memcpy(_ptr+_n, &x, sizeof(x)); + _n += sizeof(x); return *this; } - Writer& operator<<(const unsigned int x) { - memcpy(_ptr+_n, &x, sizeof(x)); - _n += sizeof(int); + Writer& operator<<(const uint32 x) { + memcpy(_ptr+_n, &x, sizeof(x)); + _n += sizeof(x); return *this; } Writer& operator<<(const bool x) { @@ -530,7 +527,7 @@ return *this; } Writer& operator<<(const char* x) { - int n = strlen(x); + int32 n = strlen(x); operator<<(n); memcpy(_ptr+_n, x, n); _n += n; @@ -571,14 +568,14 @@ _n += sizeof(char); return *this; } - Reader& operator>>(short &x) { - memcpy(&x, _ptr+_n, sizeof(short)); - _n += sizeof(short); + Reader& operator>>(int16 &x) { + memcpy(&x, _ptr+_n, sizeof(int16)); + _n += sizeof(int16); return *this; } - Reader& operator>>(int &x) { - memcpy(&x, _ptr+_n, sizeof(x)); - _n += sizeof(int); + Reader& operator>>(int32 &x) { + memcpy(&x, _ptr+_n, sizeof(int32)); + _n += sizeof(int32); return *this; } Reader& operator>>(unsigned char &x) { @@ -586,14 +583,14 @@ _n += sizeof(unsigned char); return *this; } - Reader& operator>>(unsigned short &x) { - memcpy(&x, _ptr+_n, sizeof(unsigned short)); - _n += sizeof(unsigned short); + Reader& operator>>(uint16 &x) { + memcpy(&x, _ptr+_n, sizeof(uint16)); + _n += sizeof(uint16); return *this; } - Reader& operator>>(unsigned int &x) { - memcpy(&x, _ptr+_n, sizeof(x)); - _n += sizeof(int); + Reader& operator>>(uint32 &x) { + memcpy(&x, _ptr+_n, sizeof(uint32)); + _n += sizeof(uint32); return *this; } Reader& operator>>(bool &y) { @@ -614,7 +611,7 @@ return *this; } Reader& operator>>(char* &x) { - int n = strlen(x); + int32 n = strlen(x); operator>>(n); memcpy(x, _ptr+_n, n); _n += n; |