PCMCluster.cpp

Go to the documentation of this file.
00001 
00002 //
00003 // This source file is a part of ParCompMark
00004 // Parallel Compositing Benchmark Framework
00005 //
00006 // for latest info see http://parcompmark.sourceforge.net
00007 
00008 //
00009 // Copyright (C) 2006 IT2 ParCompMark Dev. Team
00010 // 
00011 // This program is free software; you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License
00013 // as published by the Free Software Foundation; either version 2
00014 // of the License, or (at your option) any later version.
00015 // 
00016 // This program is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 // GNU General Public License for more details.
00020 // 
00021 // You should have received a copy of the GNU General Public License
00022 // along with this program; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00024 
00025 //
00026 // Inner includes
00027 //
00028 
00029 #include "../include/PCMCluster.h"
00030 
00031 #include <tinyxml/tinyxml.h>
00032 
00033 namespace ParCompMark
00034 {
00035 
00036   template <> Cluster * Singleton < Cluster >::mInstance = 0;
00037   //
00038   // Constructors & destructor
00039   //
00040 
00041   Cluster::Cluster()
00042         // You have to initialize the following attributes:
00043         // - mHosts
00044         // - mClusterDescription
00045   {
00046         mHosts = new Container < HostInfo, Mutex >;
00047 
00048   }
00049 
00050  /*----------------------------------------------------------------------*/
00051 
00052   Cluster::~Cluster()
00053   {
00054   }
00055 
00056  /*----------------------------------------------------------------------*/
00057 
00058   //
00059   // Class methods
00060   //
00061 
00062   Cluster *Cluster::parseXML(const std::string & strXml)
00063   {
00064         TiXmlDocument tiDocument;
00065 
00066         tiDocument.Parse(strXml.c_str());
00067 
00068         //The root element here is of Cluster type
00069         TiXmlElement *tiCluster = tiDocument.RootElement();
00070 
00071         Cluster *myCluster = new Cluster();
00072 
00073         //First parameter belonging to Cluster: most probably of HostInfo type
00074         TiXmlElement *tiParam = tiCluster->FirstChildElement();
00075 
00076         for(; tiParam != NULL; tiParam = tiParam->NextSiblingElement())
00077         {
00078 
00079          if(false)
00080          {
00081                 //TODO: save cluster information in class variables
00082          } else
00083          {
00084                 //processing xml part containing HOSTINFO information
00085 
00086                 HostInfo::Pointer currentHI = HostInfo::parseXML(tiParam);
00087 
00088                 if(currentHI.isNotNull())
00089                 {
00090                  myCluster->mHosts->add(currentHI->getName(), currentHI);
00091                 }
00092 
00093          }
00094         }
00095 
00096         return myCluster;
00097   }
00098 
00099  /*----------------------------------------------------------------------*/
00100 
00101   //
00102   // Methods
00103   //
00104 
00105   void Cluster::refreshData()
00106   {
00107         // Remove prevous data
00108         if(mClusterDescription.isNotNull())
00109          mClusterDescription.kill();
00110 
00111         mClusterDescription = new OutputNode("cluster", OutputNode::INFORMATION);
00112         for(Container < HostInfo, Mutex >::Iterator i = mHosts->begin(); i != mHosts->end(); i++)
00113         {
00114          // TODO: not work
00115          //mClusterDescription->createChildNode(i->second->serialize2XML());
00116         }
00117   }
00118 
00119  /*----------------------------------------------------------------------*/
00120 
00121   std::string Cluster::serialize2Squirrel()
00122   {
00123         // TODO: test version, be more specific
00124         std::ostringstream osstr;
00125         osstr << "{" << std::endl;
00126 
00127         // Retrieve hosts
00128         osstr << "hosts = [" << std::endl;
00129         for(Container < HostInfo, Mutex >::Iterator i = mHosts->begin(); i != mHosts->end(); i++)
00130         {
00131          osstr << "{" << std::endl;
00132          osstr << "address = \"" << i->first << '\"' << std::endl;
00133          osstr << "}" << std::endl;
00134         }
00135         osstr << "]" << std::endl;
00136 
00137         osstr << "}" << std::endl;
00138 
00139         return osstr.str();
00140   }
00141 
00142  /*----------------------------------------------------------------------*/
00143 
00144   std::string Cluster::serialize2XML()
00145   {
00146         refreshData();
00147 
00148         return mClusterDescription->serialize2XML();
00149   }
00150 
00151  /*----------------------------------------------------------------------*/
00152 
00153 }