From: Markus R. <rol...@us...> - 2005-12-05 21:17:01
|
Update of /cvsroot/simspark/simspark/spark/oxygen/monitorserver In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14301/monitorserver Added Files: custommonitor.cpp custommonitor.h custommonitor_c.cpp monitorcmdparser.cpp monitorcmdparser.h monitorcmdparser_c.cpp monitoritem.h monitoritem_c.cpp monitorserver.cpp monitorserver.h monitorserver_c.cpp monitorsystem.cpp monitorsystem.h monitorsystem_c.cpp Log Message: --- NEW FILE: monitorcmdparser.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: monitorcmdparser.h,v 1.1 2005/12/05 21:16:49 rollmark Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef OXYGEN_MONITORCMDPARSER_H #define OXYGEN_MONITORCMDPARSER_H #include <zeitgeist/leaf.h> #include <oxygen/gamecontrolserver/predicate.h> namespace oxygen { class MonitorCmdParser : public zeitgeist::Leaf { public: MonitorCmdParser(); virtual ~MonitorCmdParser(); /** This function is called from the monitor server implementation to parse any command strings received from the monitor client process */ virtual void ParseMonitorMessage(const std::string& data) = 0; }; } // namespace oxygen DECLARE_ABSTRACTCLASS(MonitorCmdParser); #endif // OXYGEN_MONITORCMDPARSER_H --- NEW FILE: monitorsystem.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: monitorsystem.cpp,v 1.1 2005/12/05 21:16:49 rollmark Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "monitorsystem.h" using namespace oxygen; MonitorSystem::MonitorSystem() : Node() { } MonitorSystem::~MonitorSystem() { } --- NEW FILE: monitorcmdparser_c.cpp --- /* -*- mode: c++; c-basic-indent: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: monitorcmdparser_c.cpp,v 1.1 2005/12/05 21:16:49 rollmark Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "monitorcmdparser.h" using namespace oxygen; void CLASS(MonitorCmdParser)::DefineClass() { DEFINE_BASECLASS(zeitgeist/Leaf); } --- NEW FILE: monitorsystem_c.cpp --- /* -*- mode: c++; c-basic-indent: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: monitorsystem_c.cpp,v 1.1 2005/12/05 21:16:49 rollmark Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "monitorsystem.h" using namespace oxygen; void CLASS(MonitorSystem)::DefineClass() { DEFINE_BASECLASS(zeitgeist/Leaf); } --- NEW FILE: monitorserver_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: monitorserver_c.cpp,v 1.1 2005/12/05 21:16:49 rollmark Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "monitorserver.h" using namespace oxygen; using namespace std; FUNCTION(MonitorServer,registerMonitorSystem) { string inMonitorSysName; return ( (in.GetSize() == 1) && (in.GetValue(in.begin(), inMonitorSysName)) && (obj->RegisterMonitorSystem(inMonitorSysName)) ); } FUNCTION(MonitorServer,registerMonitorItem) { string inMonitorItemName; return ( (in.GetSize() == 1) && (in.GetValue(in.begin(), inMonitorItemName)) && (obj->RegisterMonitorItem(inMonitorItemName)) ); } void CLASS(MonitorServer)::DefineClass() { DEFINE_BASECLASS(zeitgeist/Node); DEFINE_FUNCTION(registerMonitorSystem); DEFINE_FUNCTION(registerMonitorItem); } --- NEW FILE: monitoritem.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: monitoritem.h,v 1.1 2005/12/05 21:16:49 rollmark Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef OXYGEN_MONITORITEM_H #define OXYGEN_MONITORITEM_H #include <zeitgeist/leaf.h> #include <oxygen/gamecontrolserver/predicate.h> namespace oxygen { class MonitorItem : public zeitgeist::Leaf { public: MonitorItem() : Leaf() {} virtual ~MonitorItem() {} /** This function is called once for every MonitorSystem each time * a new client connects. It should append predicates to a list * that is sent using the active monitor */ virtual void GetInitialPredicates(PredicateList& pList) = 0; /** This function will be called periodically to append predicates to a list that is sent using the active monitor */ virtual void GetPredicates(PredicateList& pList) = 0; }; DECLARE_ABSTRACTCLASS(MonitorItem); } // namespace oxygen #endif // OXYGEN_MONITORITEM_H --- NEW FILE: custommonitor.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: custommonitor.cpp,v 1.1 2005/12/05 21:16:49 rollmark Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "custommonitor.h" using namespace oxygen; CustomMonitor::CustomMonitor() : zeitgeist::Leaf() { } CustomMonitor::~CustomMonitor() { } --- NEW FILE: custommonitor_c.cpp --- /* -*- mode: c++; c-basic-indent: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: custommonitor_c.cpp,v 1.1 2005/12/05 21:16:49 rollmark Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "custommonitor.h" using namespace oxygen; void CLASS(CustomMonitor)::DefineClass() { DEFINE_BASECLASS(zeitgeist/Leaf); } --- NEW FILE: custommonitor.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: custommonitor.h,v 1.1 2005/12/05 21:16:49 rollmark Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef OXYGEN_CUSTOMMONITOR_H #define OXYGEN_CUSTOMMONITOR_H #include <zeitgeist/leaf.h> #include <oxygen/gamecontrolserver/predicate.h> namespace oxygen { class CustomMonitor : public zeitgeist::Leaf { public: CustomMonitor(); virtual ~CustomMonitor(); /** This function will be called be called periodically from the monitor implementation to do any monitor updates. Custom predicates that the Monitor client receives are passed as a PredicateList */ virtual void ParseCustomPredicates(const oxygen::PredicateList& pList) = 0; }; } // namespace oxygen DECLARE_ABSTRACTCLASS(CustomMonitor); #endif // OXYGEN_CUSTOMMONITOR_H --- NEW FILE: monitoritem_c.cpp --- /* -*- mode: c++; c-basic-indent: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: monitoritem_c.cpp,v 1.1 2005/12/05 21:16:49 rollmark Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "monitoritem.h" using namespace oxygen; void CLASS(MonitorItem)::DefineClass() { DEFINE_BASECLASS(zeitgeist/Leaf); } --- NEW FILE: monitorserver.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: monitorserver.h,v 1.1 2005/12/05 21:16:49 rollmark Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef OXYGEN_MONITORSERVER_H #define OXYGEN_MONITORSERVER_H #include <zeitgeist/class.h> #include <zeitgeist/node.h> #include "monitorsystem.h" namespace oxygen { class MonitorServer : public zeitgeist::Node { public: MonitorServer(); virtual ~MonitorServer(); // one note about std::string. This class is capable of handling // binary data (i.e. not NULL terminated strings). Use the // std::string(basic_string(const charT* s, size_type n) // constructor to construct a string containing binary data and // the const charT* data() member to access binary data. /** This function creates an instance of class 'monitorSysName' * and adds it as a child node below this server */ bool RegisterMonitorSystem(const std::string& monitorSysName); /** This function creates an instance of class 'monitorItem' and adds it as a child node below this server */ bool RegisterMonitorItem(const std::string& monitorItemName); /** the following set of functions if called by the SpadesServer */ /** This function is called once for every monitor. It should * return any header/setup information that is needed. */ std::string GetMonitorHeaderInfo(); /** This function will be called periodically to get information * about the current state of the world. The format is completely * determined by what the monitors will expect; no processing is * done by the simulation engine */ std::string GetMonitorInfo(); /** If a monitor sends information to the world model, this * function is called to process it. */ void ParseMonitorMessage(const std::string& data); protected: /** returns a shared_ptr to the first registered MonitorSystem */ boost::shared_ptr<MonitorSystem> GetMonitorSystem(); /** collects a list of predicates from all registered MonitorItems */ void CollectItemPredicates(bool initial, PredicateList& pList); private: }; DECLARE_CLASS(MonitorServer); } // namespace oxygen #endif // OXYGEN_MONITORSERVER_H --- NEW FILE: monitorsystem.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: monitorsystem.h,v 1.1 2005/12/05 21:16:49 rollmark Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef OXYGEN_MONITORSYSTEM_H #define OXYGEN_MONITORSYSTEM_H #include <zeitgeist/class.h> #include <zeitgeist/node.h> #include <oxygen/gamecontrolserver/predicate.h> namespace oxygen { class MonitorSystem : public zeitgeist::Node { public: MonitorSystem(); virtual ~MonitorSystem(); // one note about std::string. This class is capable of handling // binary data (i.e. not NULL terminated strings). Use the // std::string(basic_string(const charT* s, size_type n) // constructor to construct a string containing binary data and // the const charT* data() member to access binary data. /** This function is called once for every MonitorSystem each time * a new client connects. It should return any header/setup * information that is needed. * \param items holds a list of additional name value * pairs. These predicates are collected from MonitorItem objects * registered to the MonitorServer. The monitor should transfer * them to the client if possible. */ virtual std::string GetMonitorHeaderInfo(const PredicateList& pList) = 0; /** This function will be called periodically to get information * about the current state of the world. * \param items holds a list of additional name value pairs. These * predicates are collected from MonitorItem objects registered to * the MonitorServer. The monitor should transfer them to the * client if possible. */ virtual std::string GetMonitorInfo(const PredicateList& pList) = 0; /** If a monitor sends information to the world model, this * function is called to process it. */ virtual void ParseMonitorMessage(const std::string& /* data */) = 0; }; DECLARE_ABSTRACTCLASS(MonitorSystem); } // namespace oxygen #endif // OXYGEN_MONITORSYSTEM_H --- NEW FILE: monitorcmdparser.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: monitorcmdparser.cpp,v 1.1 2005/12/05 21:16:49 rollmark Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "monitorcmdparser.h" using namespace oxygen; MonitorCmdParser::MonitorCmdParser() : zeitgeist::Leaf() { } MonitorCmdParser::~MonitorCmdParser() { } --- NEW FILE: monitorserver.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: monitorserver.cpp,v 1.1 2005/12/05 21:16:49 rollmark Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <zeitgeist/logserver/logserver.h> #include "monitorserver.h" #include "monitoritem.h" using namespace oxygen; using namespace boost; using namespace std; MonitorServer::MonitorServer() : Node() { } MonitorServer::~MonitorServer() { } bool MonitorServer::RegisterMonitorSystem(const std::string& monitorSysName) { // check if a monitor system of the requested type was already created shared_ptr<MonitorSystem> monitorSys = shared_dynamic_cast<MonitorSystem>(GetChildOfClass(monitorSysName)); if (monitorSys.get() != 0) { return true; } // create the monitor system monitorSys = shared_dynamic_cast<MonitorSystem>(GetCore()->New(monitorSysName)); if (monitorSys.get() == 0) { GetLog()->Error() << "ERROR: (MonitorServer) Cannot create monitor system '" << monitorSysName << "'" << std::endl; return false; } // link the monitor system in the hierarchy monitorSys->SetName(monitorSysName); if (! AddChildReference(monitorSys)) { GetLog()->Error() << "ERROR: (MonitorServer) Cannot link the monitor system '" << monitorSysName << "' to the hierarchy\n"; return false; } GetLog()->Debug() << "(MonitorServer) Registered monitor system '" << monitorSysName << "'\n"; return true; } bool MonitorServer::RegisterMonitorItem(const std::string& monitorItemName) { // check if a monitor item of the requested type was already created shared_ptr<MonitorItem> monitorItem = shared_dynamic_cast<MonitorItem>(GetChildOfClass(monitorItemName)); if (monitorItem.get() != 0) { return true; } // create the monitor item monitorItem = shared_dynamic_cast<MonitorItem>(GetCore()->New(monitorItemName)); if (monitorItem.get() == 0) { GetLog()->Error() << "ERROR: (MonitorServer) Cannot create monitor item '" << monitorItemName << "'" << std::endl; return false; } // link the monitor item in the hierarchy monitorItem->SetName(monitorItemName); if (! AddChildReference(monitorItem)) { GetLog()->Error() << "ERROR: (MonitorServer) Cannot link the monitor item '" << monitorItemName << "' to the hierarchy\n"; return false; } GetLog()->Debug() << "(MonitorServer) Registered monitor item '" << monitorItemName << "'\n"; return true; } boost::shared_ptr<MonitorSystem> MonitorServer::GetMonitorSystem() { return shared_static_cast<MonitorSystem> ( FindChildSupportingClass<MonitorSystem>() ); } void MonitorServer::CollectItemPredicates(bool initial, PredicateList& pList) { Leaf::TLeafList itemList; ListChildrenSupportingClass<MonitorItem>(itemList); for ( Leaf::TLeafList::const_iterator iter = itemList.begin(); iter != itemList.end(); ++iter ) { shared_ptr<MonitorItem> item = shared_static_cast<MonitorItem>(*iter); if (initial) { item->GetInitialPredicates(pList); } else { item->GetPredicates(pList); } } } string MonitorServer::GetMonitorHeaderInfo() { shared_ptr<MonitorSystem> monitorSystem = GetMonitorSystem(); if (monitorSystem.get() == 0) { GetLog()->Warning() << "WARNING: (MonitorServer) Monitor System missing.\n"; return string(); } PredicateList pList; CollectItemPredicates(true,pList); return monitorSystem->GetMonitorHeaderInfo(pList); } string MonitorServer::GetMonitorInfo() { shared_ptr<MonitorSystem> monitorSystem = GetMonitorSystem(); if (monitorSystem.get() == 0) { return string(); } PredicateList pList; CollectItemPredicates(false,pList); return monitorSystem->GetMonitorInfo(pList); } void MonitorServer::ParseMonitorMessage(const string& data) { shared_ptr<MonitorSystem> monitorSystem = GetMonitorSystem(); if (monitorSystem.get() != 0) { monitorSystem->ParseMonitorMessage(data); } } |