Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

monitorserver.cpp

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
00002 
00003    this file is part of rcssserver3D
00004    Fri May 9 2003
00005    Copyright (C) 2002,2003 Koblenz University
00006    Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group
00007    $Id: monitorserver.cpp,v 1.6 2005/07/10 05:28:11 fruit Exp $
00008 
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; version 2 of the License.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program; if not, write to the Free Software
00020    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00021 */
00022 
00023 #include <zeitgeist/logserver/logserver.h>
00024 #include "monitorserver.h"
00025 #include "monitoritem.h"
00026 
00027 using namespace oxygen;
00028 using namespace boost;
00029 using namespace std;
00030 
00031 MonitorServer::MonitorServer() : Node()
00032 {
00033 }
00034 
00035 MonitorServer::~MonitorServer()
00036 {
00037 }
00038 
00039 bool
00040 MonitorServer::RegisterMonitorSystem(const std::string& monitorSysName)
00041 {
00042     // check if a monitor system of the requested type was already created
00043     shared_ptr<MonitorSystem> monitorSys =
00044         shared_dynamic_cast<MonitorSystem>(GetChildOfClass(monitorSysName));
00045 
00046     if (monitorSys.get() != 0)
00047     {
00048         return true;
00049     }
00050 
00051     // create the monitor system
00052     monitorSys = shared_dynamic_cast<MonitorSystem>(GetCore()->New(monitorSysName));
00053 
00054     if (monitorSys.get() == 0)
00055     {
00056         GetLog()->Error() << "ERROR: (MonitorServer) Cannot create monitor system '"
00057                           << monitorSysName << "'" << std::endl;
00058         return false;
00059     }
00060 
00061     // link the monitor system in the hierarchy
00062     monitorSys->SetName(monitorSysName);
00063 
00064     if (! AddChildReference(monitorSys))
00065         {
00066             GetLog()->Error() << "ERROR: (MonitorServer) Cannot link the monitor system '"
00067                               << monitorSysName << "' to the hierarchy\n";
00068             return false;
00069         }
00070 
00071     GetLog()->Debug() << "(MonitorServer) Registered monitor system '"
00072                       << monitorSysName << "'\n";
00073 
00074     return true;
00075 }
00076 
00077 bool
00078 MonitorServer::RegisterMonitorItem(const std::string& monitorItemName)
00079 {
00080     // check if a monitor item of the requested type was already created
00081     shared_ptr<MonitorItem> monitorItem =
00082         shared_dynamic_cast<MonitorItem>(GetChildOfClass(monitorItemName));
00083 
00084     if (monitorItem.get() != 0)
00085     {
00086         return true;
00087     }
00088 
00089     // create the monitor item
00090     monitorItem = shared_dynamic_cast<MonitorItem>(GetCore()->New(monitorItemName));
00091 
00092     if (monitorItem.get() == 0)
00093     {
00094         GetLog()->Error() << "ERROR: (MonitorServer) Cannot create monitor item '"
00095                           << monitorItemName << "'" << std::endl;
00096         return false;
00097     }
00098 
00099     // link the monitor item in the hierarchy
00100     monitorItem->SetName(monitorItemName);
00101 
00102     if (! AddChildReference(monitorItem))
00103         {
00104             GetLog()->Error() << "ERROR: (MonitorServer) Cannot link the monitor item '"
00105                               << monitorItemName << "' to the hierarchy\n";
00106             return false;
00107         }
00108 
00109     GetLog()->Debug() << "(MonitorServer) Registered monitor item '"
00110                       << monitorItemName << "'\n";
00111 
00112     return true;
00113 }
00114 
00115 boost::shared_ptr<MonitorSystem> MonitorServer::GetMonitorSystem()
00116 {
00117     return shared_static_cast<MonitorSystem>
00118         (
00119          FindChildSupportingClass<MonitorSystem>()
00120          );
00121 }
00122 
00123 void
00124 MonitorServer::CollectItemPredicates(bool initial, PredicateList& pList)
00125 {
00126     Leaf::TLeafList itemList;
00127     ListChildrenSupportingClass<MonitorItem>(itemList);
00128 
00129     for (
00130         Leaf::TLeafList::const_iterator iter = itemList.begin();
00131         iter != itemList.end();
00132         ++iter
00133         )
00134     {
00135         shared_ptr<MonitorItem> item =
00136             shared_static_cast<MonitorItem>(*iter);
00137 
00138         if (initial)
00139         {
00140             item->GetInitialPredicates(pList);
00141         } else
00142         {
00143             item->GetPredicates(pList);
00144         }
00145     }
00146 }
00147 
00148 string MonitorServer::GetMonitorHeaderInfo()
00149 {
00150     shared_ptr<MonitorSystem> monitorSystem = GetMonitorSystem();
00151 
00152     if (monitorSystem.get() == 0)
00153     {
00154         GetLog()->Warning()
00155             << "WARNING: (MonitorServer) Monitor System missing.\n";
00156         return string();
00157     }
00158 
00159     PredicateList pList;
00160     CollectItemPredicates(true,pList);
00161     return monitorSystem->GetMonitorHeaderInfo(pList);
00162 }
00163 
00164 string MonitorServer::GetMonitorInfo()
00165 {
00166     shared_ptr<MonitorSystem> monitorSystem = GetMonitorSystem();
00167 
00168     if (monitorSystem.get() == 0)
00169         {
00170             return string();
00171         }
00172 
00173     PredicateList pList;
00174     CollectItemPredicates(false,pList);
00175     return monitorSystem->GetMonitorInfo(pList);
00176 }
00177 
00178 void MonitorServer::ParseMonitorMessage(const string& data)
00179 {
00180     shared_ptr<MonitorSystem> monitorSystem = GetMonitorSystem();
00181 
00182     if (monitorSystem.get() != 0)
00183         {
00184             monitorSystem->ParseMonitorMessage(data);
00185         }
00186 }
00187 

Generated on Thu Apr 6 15:25:39 2006 for rcssserver3d by  doxygen 1.4.4