00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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
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
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
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
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
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