KiCad PCB EDA Suite
pluginldr.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015-2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
30 #ifndef PLUGINLDR_H
31 #define PLUGINLDR_H
32 
33 #include <string>
34 #include <wx/dynlib.h>
35 #include <wx/string.h>
36 
37 #define MASK_PLUGINLDR "PLUGIN_LOADER"
38 
39 
40 // helper function to link functions in the plugin
41 #define LINK_ITEM( funcPtr, funcType, funcName ) \
42  funcPtr = (funcType) m_PluginLoader.GetSymbol( wxT( funcName ) )
43 
44 // typedefs of the functions exported by the 3D Plugin Class
45 typedef char const* (*GET_PLUGIN_CLASS) ( void );
46 
47 typedef void (*GET_CLASS_VERSION) ( unsigned char*, unsigned char*,
48  unsigned char*, unsigned char* );
49 
50 typedef bool (*CHECK_CLASS_VERSION) ( unsigned char, unsigned char,
51  unsigned char, unsigned char );
52 
53 typedef const char* (*GET_PLUGIN_NAME) ( void );
54 
55 typedef void (*GET_VERSION) ( unsigned char*, unsigned char*,
56  unsigned char*, unsigned char* );
57 
58 
60 {
61 private:
62  bool ok; // set TRUE if all functions are linked
68 
69  wxString m_fileName; // name of last opened Plugin
70  std::string m_pluginInfo; // Name:Version tag for plugin
71 
72 protected:
73  std::string m_error; // error message
74 
81  bool open( const wxString& aFullFileName, const char* aPluginClass );
82 
87  void close( void );
88 
93  bool reopen( void );
94 
95  // the plugin loader
96  wxDynamicLibrary m_PluginLoader;
97 
98 public:
100  virtual ~KICAD_PLUGIN_LDR();
101 
107  virtual void GetLoaderVersion( unsigned char* Major, unsigned char* Minor,
108  unsigned char* Patch, unsigned char* Revision ) const = 0;
109 
118  virtual bool Open( const wxString& aFullFileName ) = 0;
119 
124  virtual void Close( void ) = 0;
125 
130  std::string GetLastError( void ) const;
131 
132  // the following functions are the equivalent of those required by kicad_plugin.h
133 
134  // returns the Plugin Class or NULL if no plugin loaded
135  char const* GetKicadPluginClass( void );
136 
137  // returns false if no plugin loaded
138  bool GetClassVersion( unsigned char* Major, unsigned char* Minor,
139  unsigned char* Patch, unsigned char* Revision );
140 
141  // returns false if the class version check fails or no plugin is loaded
142  bool CheckClassVersion( unsigned char Major, unsigned char Minor,
143  unsigned char Patch, unsigned char Revision );
144 
145  // returns the Plugin Name or NULL if no plugin loaded
146  const char* GetKicadPluginName( void );
147 
148  // returns false if no plugin is loaded
149  bool GetVersion( unsigned char* Major, unsigned char* Minor,
150  unsigned char* Patch, unsigned char* Revision );
151 
152  void GetPluginInfo( std::string& aPluginInfo );
153 };
154 
155 #endif // PLUGINLDR_H
virtual void GetLoaderVersion(unsigned char *Major, unsigned char *Minor, unsigned char *Patch, unsigned char *Revision) const =0
Function GetLoaderVersion returns the version information of the Plugin Loader for plugin compatibili...
const char * GetKicadPluginName(void)
Definition: pluginldr.cpp:440
wxDynamicLibrary m_PluginLoader
Definition: pluginldr.h:96
GET_CLASS_VERSION m_getClassVersion
Definition: pluginldr.h:64
char const *(* GET_PLUGIN_CLASS)(void)
Definition: pluginldr.h:45
void(* GET_CLASS_VERSION)(unsigned char *, unsigned char *, unsigned char *, unsigned char *)
Definition: pluginldr.h:47
virtual ~KICAD_PLUGIN_LDR()
Definition: pluginldr.cpp:47
std::string m_error
Definition: pluginldr.h:73
bool GetVersion(unsigned char *Major, unsigned char *Minor, unsigned char *Patch, unsigned char *Revision)
Definition: pluginldr.cpp:470
wxString m_fileName
Definition: pluginldr.h:69
const char *(* GET_PLUGIN_NAME)(void)
Definition: pluginldr.h:53
void GetPluginInfo(std::string &aPluginInfo)
Definition: pluginldr.cpp:503
GET_PLUGIN_CLASS m_getPluginClass
Definition: pluginldr.h:63
bool open(const wxString &aFullFileName, const char *aPluginClass)
Function open opens a plugin of the specified class and links the extensions required by kicad_plugin...
Definition: pluginldr.cpp:54
virtual bool Open(const wxString &aFullFileName)=0
Function Open opens a plugin of the given class, performs version compatibility checks,...
std::string m_pluginInfo
Definition: pluginldr.h:70
char const * GetKicadPluginClass(void)
Definition: pluginldr.cpp:317
bool(* CHECK_CLASS_VERSION)(unsigned char, unsigned char, unsigned char, unsigned char)
Definition: pluginldr.h:50
std::string GetLastError(void) const
Function GetLastError returns the value of the internal error string.
Definition: pluginldr.cpp:311
bool reopen(void)
Function reopen reopens a plugin and returns true on success.
Definition: pluginldr.cpp:298
bool GetClassVersion(unsigned char *Major, unsigned char *Minor, unsigned char *Patch, unsigned char *Revision)
Definition: pluginldr.cpp:347
bool CheckClassVersion(unsigned char Major, unsigned char Minor, unsigned char Patch, unsigned char Revision)
Definition: pluginldr.cpp:409
GET_VERSION m_getVersion
Definition: pluginldr.h:67
void(* GET_VERSION)(unsigned char *, unsigned char *, unsigned char *, unsigned char *)
Definition: pluginldr.h:55
CHECK_CLASS_VERSION m_checkClassVersion
Definition: pluginldr.h:65
virtual void Close(void)=0
Function Close cleans up and closes/unloads the plugin.
void close(void)
Function close nullifies internal pointers in preparation for closing the plugin.
Definition: pluginldr.cpp:284
GET_PLUGIN_NAME m_getPluginName
Definition: pluginldr.h:66