Wolframe, 0.0.3

moduleInterface.hpp
Go to the documentation of this file.
1 /************************************************************************
2 
3  Copyright (C) 2011 - 2014 Project Wolframe.
4  All rights reserved.
5 
6  This file is part of Project Wolframe.
7 
8  Commercial Usage
9  Licensees holding valid Project Wolframe Commercial licenses may
10  use this file in accordance with the Project Wolframe
11  Commercial License Agreement provided with the Software or,
12  alternatively, in accordance with the terms contained
13  in a written agreement between the licensee and Project Wolframe.
14 
15  GNU General Public License Usage
16  Alternatively, you can redistribute this file and/or modify it
17  under the terms of the GNU General Public License as published by
18  the Free Software Foundation, either version 3 of the License, or
19  (at your option) any later version.
20 
21  Wolframe is distributed in the hope that it will be useful,
22  but WITHOUT ANY WARRANTY; without even the implied warranty of
23  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  GNU General Public License for more details.
25 
26  You should have received a copy of the GNU General Public License
27  along with Wolframe. If not, see <http://www.gnu.org/licenses/>.
28 
29  If you have questions regarding the use of this file, please contact
30  Project Wolframe.
31 
32 ************************************************************************/
35 
36 #ifndef _MODULE_INTERFACE_HPP_INCLUDED
37 #define _MODULE_INTERFACE_HPP_INCLUDED
38 
39 #include <string>
40 #include <cstring>
41 #include <list>
42 #include <vector>
44 #include "module/constructor.hpp"
45 
46 namespace _Wolframe {
47 namespace module {
48 
52 {
53 public:
54  virtual ~BuilderBase() {}
55 
56  virtual const char* objectClassName() const = 0;
58  virtual ObjectConstructorBase* constructor() = 0;
59 };
60 
64  :public BuilderBase
65 {
66  friend class ModulesDirectory;
67 public:
68  SimpleBuilder( const char* builderID )
69  : m_className( builderID ) {}
70 
71  virtual ~SimpleBuilder() {}
72 
73  virtual const char* objectClassName() const { return m_className; }
74 
76  virtual ObjectConstructorBase* constructor() = 0;
77 protected:
78  const char* m_className;
79 };
80 
84  :public BuilderBase
85 {
86  friend class ModulesDirectory;
87 public:
94  ConfiguredBuilder( const char* title, const char* section, const char* keyword,
95  const char* className )
96  : m_title( title ), m_section( section ), m_keyword( keyword ),
97  m_className( className ) {}
98 
99  virtual ~ConfiguredBuilder() {}
100 
101  virtual const char* objectClassName() const { return m_className; }
102 
105  virtual ObjectConstructorBase::ObjectType objectType() const = 0;
106 
110  virtual config::NamedConfiguration* configuration( const char* logPrefix ) = 0;
111 
113  virtual ObjectConstructorBase* constructor() = 0;
114 
115 protected:
116  const char* m_title;
117  const char* m_section;
118  const char* m_keyword; //< configuration keyword (element)
120  const char* m_className; //< class name of the object
121 };
122 
123 
128 template < class Tconstructor, class Tconf >
130 {
131 public:
132  ConfiguredBuilderDescription( const char* title, const char* section,
133  const char* keyword, const char* className )
134  : ConfiguredBuilder( title, section, keyword, className ) {}
135 
137 
138  virtual config::NamedConfiguration* configuration( const char* logPrefix ) {
139  return new Tconf( m_title, logPrefix, m_keyword );
140  }
142  return m_constructor.objectType();
143  }
145  return &m_constructor;
146  }
147 private:
148  Tconstructor m_constructor;
149 };
150 
151 
152 //*********** Module interface *********
153 
156 typedef BuilderBase* (*createBuilderFunc)();
157 
158 
162 {
163  enum SignSize {
165  };
166 
168  unsigned short ifaceVersion;
169  const char* name;
171 public:
172  ModuleEntryPoint( unsigned short iVer, const char* modName, createBuilderFunc* createBuilder_)
173  : ifaceVersion( iVer ), name( modName ), createBuilder( createBuilder_ )
174  {
175  std::memset ( signature, 0, MODULE_SIGN_SIZE);
176  std::memcpy ( signature, "Wolframe Module", std::strlen("Wolframe Module"));
177  }
178 };
179 
181 
182 }} // namespace _Wolframe::module
183 
184 #endif // _MODULE_INTERFACE_HPP_INCLUDED
Builder for objects with configuration.
Definition: moduleInterface.hpp:83
virtual config::NamedConfiguration * configuration(const char *logPrefix)
Get the configuration for the object.
Definition: moduleInterface.hpp:138
Base classes for virtual constructors to build objects loaded from modules.
ConfiguredBuilderDescription(const char *title, const char *section, const char *keyword, const char *className)
Definition: moduleInterface.hpp:132
Template for constructing a configured builder.
Definition: moduleInterface.hpp:129
virtual ~SimpleBuilder()
Definition: moduleInterface.hpp:71
virtual ObjectConstructorBase * constructor()=0
BuilderBase *(* createBuilderFunc)()
Function that constructs a builder. This function is specific for each of the configured builders in ...
Definition: moduleInterface.hpp:156
createBuilderFunc * createBuilder
NULL terminated array of functions that create the builders.
Definition: moduleInterface.hpp:170
virtual ObjectConstructorBase * constructor()
get the virtual constructor for the object
Definition: moduleInterface.hpp:144
virtual config::NamedConfiguration * configuration(const char *logPrefix)=0
Get the configuration for the object.
SimpleBuilder(const char *builderID)
Definition: moduleInterface.hpp:68
virtual ObjectConstructorBase * constructor()=0
get the virtual constructor for the object
The modules directory used by the constructors of the providers to build themselves.
Definition: moduleDirectory.hpp:48
char signature[MODULE_SIGN_SIZE]
module entry point signature
Definition: moduleInterface.hpp:167
virtual ObjectConstructorBase::ObjectType objectType() const =0
Get the type of the object: filter, audit, command handler etc. This is not the same as the objectNam...
ConfiguredBuilder(const char *title, const char *section, const char *keyword, const char *className)
Constructor.
Definition: moduleInterface.hpp:94
ObjectType
Definition: constructor.hpp:47
const char * m_className
Definition: moduleInterface.hpp:78
Definition: moduleInterface.hpp:51
virtual ObjectConstructorBase::ObjectType objectType() const =0
SignSize
Definition: moduleInterface.hpp:163
const char * m_keyword
Definition: moduleInterface.hpp:119
Base classes for the configuration structures.
ModuleEntryPoint entryPoint
Definition: moduleInterface.hpp:180
A named configuration is a normal configuration that provides also an className function.
Definition: configurationBase.hpp:126
Base class for builders of objects without configuration.
Definition: moduleInterface.hpp:63
const char * m_title
used for printing (logging etc.)
Definition: moduleInterface.hpp:116
virtual ~ConfiguredBuilder()
Definition: moduleInterface.hpp:99
virtual ObjectConstructorBase::ObjectType objectType() const
Get the type of the object: filter, audit, command handler etc. This is not the same as the objectNam...
Definition: moduleInterface.hpp:141
virtual const char * objectClassName() const =0
Tconstructor m_constructor
Definition: moduleInterface.hpp:148
Constructor base class.
Definition: constructor.hpp:44
const char * name
name of the module
Definition: moduleInterface.hpp:169
virtual ObjectConstructorBase::ObjectType objectType() const =0
virtual ~ConfiguredBuilderDescription()
Definition: moduleInterface.hpp:136
virtual ~BuilderBase()
Definition: moduleInterface.hpp:54
const char * m_className
Definition: moduleInterface.hpp:120
ModuleEntryPoint(unsigned short iVer, const char *modName, createBuilderFunc *createBuilder_)
Definition: moduleInterface.hpp:172
unsigned short ifaceVersion
version of the module loader interface
Definition: moduleInterface.hpp:168
virtual const char * objectClassName() const
Definition: moduleInterface.hpp:101
The module entry point structure. Only one entry point per module.
Definition: moduleInterface.hpp:161
virtual ObjectConstructorBase * constructor()=0
const char * m_section
Definition: moduleInterface.hpp:117
virtual const char * objectClassName() const
Definition: moduleInterface.hpp:73