μHAL (v2.6.5)
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 #include "uhal/log/exception.hpp"
44 #include "uhal/definitions.hpp"
45 #include "uhal/Node.hpp"
46 
47 #include <boost/filesystem/path.hpp>
48 #include <boost/spirit/include/qi.hpp>
49 
53 
54 #include "pugixml.hpp"
55 
56 #include "uhal/XmlParser.hpp"
57 
58 
59 namespace uhal
60 {
61  namespace exception
62  {
64  UHAL_DEFINE_EXCEPTION_CLASS ( NodeMustHaveUID , "Exception class to handle the case where creation of a node was attempted without it having a UID." )
66  UHAL_DEFINE_EXCEPTION_CLASS ( IncorrectAddressTableFileCount , "Exception class to handle the case where too many or two few address files are specified." )
68  UHAL_DEFINE_EXCEPTION_CLASS ( FailedToOpenAddressTableFile , "Exception class to handle the case where the address file failed to open." )
70  UHAL_DEFINE_EXCEPTION_CLASS ( IncrementalNodeRequiresSizeAttribute , "Exception class to handle the case where an incremental node is specified without a size attribute." )
72  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." )
73 
74 #ifdef THROW_ON_ADDRESS_SPACE_OVERLAP
75  UHAL_DEFINE_EXCEPTION_CLASS ( AddressSpaceOverlap , "Exception class to handle the case where two addresses overlap." )
77 #endif
78 
80  UHAL_DEFINE_EXCEPTION_CLASS ( BlockAccessNodeCannotHaveChild , "Exception class to handle the case when someone tries to give a block access node a child." )
81 
82 
83  UHAL_DEFINE_EXCEPTION_CLASS ( MaskedNodeCannotHaveChild , "Exception class to handle the case when someone tries to give a bit-masked node a child." )
84 
85  // //! Exception class to handle the case when a node has both masked and unmasked children. Uses the base uhal::exception implementation of what()
86  // class BothMaskedAndUnmaskedChildren : public exception {};
87 
88 
89  // //! Exception class to handle the case where a child node has an address which overlaps with the parent. Uses the base uhal::exception implementation of what()
90  // class ChildHasAddressOverlap : public exception {};
91  // //! Exception class to handle the case where a child node has an address mask which overlaps with the parent. Uses the base uhal::exception implementation of what()
92  // class ChildHasAddressMaskOverlap : public exception {};
93  // //! Exception class to handle the case where a class is requested which does not exist in the class factory.
94  // UHAL_DEFINE_EXCEPTION_CLASS ( LabelUnknownToClassFactory , "Exception class to handle the case where a class is requested which does not exist in the class factory." )
95  }
96 
97 
102  class NodeTreeBuilder: private boost::noncopyable
103  {
104 
105  private:
110  NodeTreeBuilder ();
111 
115  virtual ~NodeTreeBuilder ();
116 
117 
118  public:
123  static NodeTreeBuilder& getInstance();
124 
131  Node* getNodeTree ( const std::string& aFilenameExpr , const boost::filesystem::path& aPath );
132 
134  void clearAddressFileCache();
135 
136 
137  private:
145  void CallBack ( const std::string& aProtocol , const boost::filesystem::path& aPath , std::vector<uint8_t>& aFile , std::vector< const Node* >& aAddressTable );
146 
147 
153  void calculateHierarchicalAddresses ( Node* aNode , const uint32_t& aAddr );
154 
155 
156  void checkForAddressCollisions ( Node* aNode , const boost::filesystem::path& aPath );
157 
158 
159  static bool NodePtrCompare ( Node* aNodeL, Node* aNodeR );
160 
161 
162  Node* plainNodeCreator ( const bool& aRequireId , const pugi::xml_node& aXmlNode );
163  // Node* classNodeCreator ( const bool& aRequireId , const pugi::xml_node& aXmlNode );
164  Node* moduleNodeCreator ( const bool& aRequireId , const pugi::xml_node& aXmlNode );
165  Node* bitmaskNodeCreator ( const bool& aRequireId , const pugi::xml_node& aXmlNode );
166 
167  void setUid ( const bool& aRequireId , const pugi::xml_node& aXmlNode , Node* aNode );
168  void setClassName ( const pugi::xml_node& aXmlNode , Node* aNode );
169  void setPars ( const pugi::xml_node& aXmlNode , Node* aNode );
170  void setAddr ( const pugi::xml_node& aXmlNode , Node* aNode );
171  void setTags ( const pugi::xml_node& aXmlNode , Node* aNode );
172  void setDescription ( const pugi::xml_node& aXmlNode , Node* aNode );
173  void setModule ( const pugi::xml_node& aXmlNode , Node* aNode );
174  void setPermissions ( const pugi::xml_node& aXmlNode , Node* aNode );
175  void setMask ( const pugi::xml_node& aXmlNode , Node* aNode );
176  void setModeAndSize ( const pugi::xml_node& aXmlNode , Node* aNode );
177  void setFirmwareInfo ( const pugi::xml_node& aXmlNode , Node* aNode );
178  void addChildren ( const pugi::xml_node& aXmlNode , Node* aNode );
179 
180  static const char* mIdAttribute;
181  static const char* mAddressAttribute;
182  static const char* mParametersAttribute;
183  static const char* mTagsAttribute;
184  static const char* mDescriptionAttribute;
185  static const char* mPermissionsAttribute;
186  static const char* mMaskAttribute;
187  static const char* mModeAttribute;
188  static const char* mSizeAttribute;
189  static const char* mClassAttribute;
190  static const char* mModuleAttribute;
191  static const char* mFirmwareInfo;
192 
195 
196  std::deque< boost::filesystem::path > mFileCallStack;
197 
198  private:
201 
203  boost::unordered_map< std::string , const Node* > mNodes;
204 
206  static const struct permissions_lut : boost::spirit::qi::symbols<char, defs::NodePermission>
207  {
209  permissions_lut();
210  } mPermissionsLut;
211 
212 
214  static const struct mode_lut : boost::spirit::qi::symbols<char, defs::BlockReadWriteMode>
215  {
217  mode_lut();
218  } mModeLut;
219 
220 
221  grammars::NodeTreeClassAttributeGrammar mNodeTreeClassAttributeGrammar;
223  grammars::NodeTreeFirmwareinfoAttributeGrammar mNodeTreeFirmwareInfoAttributeGrammar;
224 
225  };
226 
227 }
228 
229 #endif
A class to build a node tree from an Address table file NOTE! This is a factory method and must be Mu...
A look-up table that the boost qi parser uses for associating strings ("r","w","rw","wr","read","write","readwrite","writeread") with enumerated permissions types.
grammars::NodeTreeFirmwareinfoAttributeGrammar mNodeTreeFirmwareInfoAttributeGrammar
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 ...
A struct wrapping a set of rules as a grammar that can parse a NodeTreeParametersGrammar of the form ...
static const char * mParametersAttribute
static NodeTreeBuilder * mInstance
The single instance of the class.
static const char * mModeAttribute
static const char * mAddressAttribute
#define UHAL_DEFINE_EXCEPTION_CLASS(ClassName, ClassDescription)
Definition: exception.hpp:64
Parser< Node *> mNodeParser
static const char * mModuleAttribute
static const char * mMaskAttribute
std::deque< boost::filesystem::path > mFileCallStack
static const char * mSizeAttribute
static const char * mPermissionsAttribute
A heirarchical node for navigating heirarchical firmwares.
Definition: Node.hpp:83
static const char * mFirmwareInfo
static const char * mTagsAttribute
static const char * mDescriptionAttribute
static const char * mIdAttribute
A look-up table that the boost qi parser uses for associating strings ("single","block","port","incremental","non-incremental","inc","non-inc") with enumerated mode types.
Parser< Node *> mTopLevelNodeParser
grammars::NodeTreeParametersGrammar mNodeTreeParametersGrammar
static const char * mClassAttribute
grammars::NodeTreeClassAttributeGrammar mNodeTreeClassAttributeGrammar
Forward declaration of the Parser so we can declare it friend.
Definition: XmlParser.hpp:71