μHAL (v2.7.9)
Part of the IPbus software repository
NodeTreeBuilder.hpp
Go to the documentation of this file.
1 /*
2 ---------------------------------------------------------------------------
3 
4  This file is part of uHAL.
5 
6  uHAL is a hardware access library and programming framework
7  originally developed for upgrades of the Level-1 trigger of the CMS
8  experiment at CERN.
9 
10  uHAL is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  uHAL is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with uHAL. If not, see <http://www.gnu.org/licenses/>.
22 
23 
24  Andrew Rose, Imperial College, London
25  email: awr01 <AT> imperial.ac.uk
26 
27  Marc Magrans de Abril, CERN
28  email: marc.magrans.de.abril <AT> cern.ch
29 
30 ---------------------------------------------------------------------------
31 */
32 
40 #ifndef _uhal_NodeTreeBuilder_hpp_
41 #define _uhal_NodeTreeBuilder_hpp_
42 
43 
44 #include <boost/filesystem/path.hpp>
45 #include <boost/noncopyable.hpp>
46 #include <boost/shared_ptr.hpp>
47 #include <boost/spirit/include/qi.hpp>
48 
49 #include "pugixml.hpp"
50 
51 #include "uhal/definitions.hpp"
55 #include "uhal/log/exception.hpp"
56 #include "uhal/Node.hpp"
57 #include "uhal/XmlParser.hpp"
58 
59 
60 namespace uhal
61 {
62  namespace exception
63  {
65  UHAL_DEFINE_EXCEPTION_CLASS ( NodeMustHaveUID , "Exception class to handle the case where creation of a node was attempted without it having a UID." )
67  UHAL_DEFINE_EXCEPTION_CLASS ( IncorrectAddressTableFileCount , "Exception class to handle the case where too many or two few address files are specified." )
69  UHAL_DEFINE_EXCEPTION_CLASS ( FailedToOpenAddressTableFile , "Exception class to handle the case where the address file failed to open." )
71  UHAL_DEFINE_EXCEPTION_CLASS ( IncrementalNodeRequiresSizeAttribute , "Exception class to handle the case where an incremental node is specified without a size attribute." )
73  UHAL_DEFINE_EXCEPTION_CLASS ( ArraySizeExceedsRegisterBound , "Exception class to handle the case where a memory block has a size which would exceed the available register space." )
74 
76  UHAL_DEFINE_EXCEPTION_CLASS ( BlockAccessNodeCannotHaveChild , "Exception class to handle the case when someone tries to give a block access node a child." )
77 
79  UHAL_DEFINE_EXCEPTION_CLASS ( MaskedNodeCannotHaveChild , "Exception class to handle the case when someone tries to give a bit-masked node a child." )
80  }
81 
82 
87  class NodeTreeBuilder: private boost::noncopyable
88  {
89  private:
94  NodeTreeBuilder ();
95 
96  public:
98  virtual ~NodeTreeBuilder ();
99 
104  static NodeTreeBuilder& getInstance();
105 
112  Node* getNodeTree ( const std::string& aFilenameExpr , const boost::filesystem::path& aPath );
113 
115  void clearAddressFileCache();
116 
117  Node* build(const pugi::xml_node& aNode, const boost::filesystem::path& aAddressFilePath);
118 
119  private:
127  void CallBack ( const std::string& aProtocol , const boost::filesystem::path& aPath , std::vector<uint8_t>& aFile , std::vector< const Node* >& aAddressTable );
128 
134  void calculateHierarchicalAddresses ( Node* aNode , const uint32_t& aAddr );
135 
136  void checkForAddressCollisions ( Node* aNode , const boost::filesystem::path& aPath );
137 
138  Node* plainNodeCreator ( const bool& aRequireId , const pugi::xml_node& aXmlNode );
139  // Node* classNodeCreator ( const bool& aRequireId , const pugi::xml_node& aXmlNode );
140  Node* moduleNodeCreator ( const bool& aRequireId , const pugi::xml_node& aXmlNode );
141  Node* bitmaskNodeCreator ( const bool& aRequireId , const pugi::xml_node& aXmlNode );
142 
143  void setUid ( const bool& aRequireId , const pugi::xml_node& aXmlNode , Node* aNode );
144  void setClassName ( const pugi::xml_node& aXmlNode , Node* aNode );
145  void setPars ( const pugi::xml_node& aXmlNode , Node* aNode );
146  void setAddr ( const pugi::xml_node& aXmlNode , Node* aNode );
147  void setTags ( const pugi::xml_node& aXmlNode , Node* aNode );
148  void setDescription ( const pugi::xml_node& aXmlNode , Node* aNode );
149  void setModule ( const pugi::xml_node& aXmlNode , Node* aNode );
150  void setPermissions ( const pugi::xml_node& aXmlNode , Node* aNode );
151  void setMask ( const pugi::xml_node& aXmlNode , Node* aNode );
152  void setModeAndSize ( const pugi::xml_node& aXmlNode , Node* aNode );
153  void setFirmwareInfo ( const pugi::xml_node& aXmlNode , Node* aNode );
154  void addChildren ( const pugi::xml_node& aXmlNode , Node* aNode );
155 
156  static const std::string mIdAttribute;
157  static const std::string mAddressAttribute;
158  static const std::string mParametersAttribute;
159  static const std::string mTagsAttribute;
160  static const std::string mDescriptionAttribute;
161  static const std::string mPermissionsAttribute;
162  static const std::string mMaskAttribute;
163  static const std::string mModeAttribute;
164  static const std::string mSizeAttribute;
165  static const std::string mClassAttribute;
166  static const std::string mModuleAttribute;
167  static const std::string mFirmwareInfo;
168 
171 
172  std::deque< boost::filesystem::path > mFileCallStack;
173 
174  private:
177 
179  boost::unordered_map< std::string , const Node* > mNodes;
180 
182  static const struct permissions_lut : boost::spirit::qi::symbols<char, defs::NodePermission>
183  {
185  permissions_lut();
186  } mPermissionsLut;
187 
188 
190  static const struct mode_lut : boost::spirit::qi::symbols<char, defs::BlockReadWriteMode>
191  {
193  mode_lut();
194  } mModeLut;
195 
196  grammars::NodeTreeClassAttributeGrammar mNodeTreeClassAttributeGrammar;
198  grammars::NodeTreeFirmwareinfoAttributeGrammar mNodeTreeFirmwareInfoAttributeGrammar;
199 
200  };
201 
202 }
203 
204 #endif
uhal::NodeTreeBuilder::mAddressAttribute
static const std::string mAddressAttribute
Definition: NodeTreeBuilder.hpp:157
UHAL_DEFINE_EXCEPTION_CLASS
#define UHAL_DEFINE_EXCEPTION_CLASS(ClassName, ClassDescription)
Definition: exception.hpp:59
uhal::NodeTreeBuilder::mode_lut
A look-up table that the boost qi parser uses for associating strings ("single","block",...
Definition: NodeTreeBuilder.hpp:191
boost::shared_ptr
Definition: DerivedNodeFactory.hpp:52
uhal::NodeTreeBuilder::mClassAttribute
static const std::string mClassAttribute
Definition: NodeTreeBuilder.hpp:165
definitions.hpp
Node.hpp
XmlParser.hpp
boost
Definition: log.hpp:13
uhal::NodeTreeBuilder::mTagsAttribute
static const std::string mTagsAttribute
Definition: NodeTreeBuilder.hpp:159
uhal::NodeTreeBuilder::mDescriptionAttribute
static const std::string mDescriptionAttribute
Definition: NodeTreeBuilder.hpp:160
uhal::NodeTreeBuilder::mModuleAttribute
static const std::string mModuleAttribute
Definition: NodeTreeBuilder.hpp:166
uhal::grammars::NodeTreeParametersGrammar
A struct wrapping a set of rules as a grammar that can parse a NodeTreeParametersGrammar of the form ...
Definition: NodeTreeParametersGrammar.hpp:52
pugixml.hpp
uhal::NodeTreeBuilder::mMaskAttribute
static const std::string mMaskAttribute
Definition: NodeTreeBuilder.hpp:162
uhal::NodeTreeBuilder::mIdAttribute
static const std::string mIdAttribute
Definition: NodeTreeBuilder.hpp:156
uhal::NodeTreeBuilder
A class to build a node tree from an Address table file NOTE! This is a factory method and must be Mu...
Definition: NodeTreeBuilder.hpp:88
uhal
Definition: HttpResponseGrammar.hpp:49
uhal::NodeTreeBuilder::mParametersAttribute
static const std::string mParametersAttribute
Definition: NodeTreeBuilder.hpp:158
uhal::NodeTreeBuilder::mNodeTreeFirmwareInfoAttributeGrammar
grammars::NodeTreeFirmwareinfoAttributeGrammar mNodeTreeFirmwareInfoAttributeGrammar
Definition: NodeTreeBuilder.hpp:198
uhal::NodeTreeBuilder::mPermissionsAttribute
static const std::string mPermissionsAttribute
Definition: NodeTreeBuilder.hpp:161
uhal::NodeTreeBuilder::mNodes
boost::unordered_map< std::string, const Node * > mNodes
Hash map associating a Node tree with a file name so that we do not need to repeatedly parse the xml ...
Definition: NodeTreeBuilder.hpp:179
uhal::NodeTreeBuilder::mNodeTreeParametersGrammar
grammars::NodeTreeParametersGrammar mNodeTreeParametersGrammar
Definition: NodeTreeBuilder.hpp:197
uhal::Node
A heirarchical node for navigating heirarchical firmwares.
Definition: Node.hpp:86
uhal::NodeTreeBuilder::mFileCallStack
std::deque< boost::filesystem::path > mFileCallStack
Definition: NodeTreeBuilder.hpp:172
pugi::xml_node
Definition: pugixml.hpp:455
uhal::NodeTreeBuilder::mTopLevelNodeParser
Parser< Node * > mTopLevelNodeParser
Definition: NodeTreeBuilder.hpp:169
uhal::NodeTreeBuilder::mNodeParser
Parser< Node * > mNodeParser
Definition: NodeTreeBuilder.hpp:170
uhal::NodeTreeBuilder::mFirmwareInfo
static const std::string mFirmwareInfo
Definition: NodeTreeBuilder.hpp:167
NodeTreeParametersGrammar.hpp
uhal::NodeTreeBuilder::mNodeTreeClassAttributeGrammar
grammars::NodeTreeClassAttributeGrammar mNodeTreeClassAttributeGrammar
Definition: NodeTreeBuilder.hpp:196
uhal::NodeTreeBuilder::mSizeAttribute
static const std::string mSizeAttribute
Definition: NodeTreeBuilder.hpp:164
uhal::NodeTreeBuilder::permissions_lut
A look-up table that the boost qi parser uses for associating strings ("r","w","rw",...
Definition: NodeTreeBuilder.hpp:183
NodeTreeClassAttributeGrammar.hpp
uhal::Parser
Forward declaration of the Parser so we can declare it friend.
Definition: XmlParser.hpp:71
NodeTreeFirmwareInfoAttributeGrammar.hpp
exception.hpp
uhal::NodeTreeBuilder::mInstance
static boost::shared_ptr< NodeTreeBuilder > mInstance
The single instance of the class.
Definition: NodeTreeBuilder.hpp:176
uhal::NodeTreeBuilder::mModeAttribute
static const std::string mModeAttribute
Definition: NodeTreeBuilder.hpp:163