Clay Library  1.0.1
All Classes Functions Variables Groups
clay_plugin.h
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of "clay" library.
4 It is licensed under the terms of the MIT license.
5 For the latest info, see http://libclay.sourceforge.net
6 
7 Copyright (c) 2010-2013 Lin Jia Jun (Joe Lam)
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 
29 #ifndef __CLAY_PLUGIN_H_INCLUDED__
30 #define __CLAY_PLUGIN_H_INCLUDED__
31 
32 #include <map>
33 #include <string>
34 
35 namespace clay
36 {
37 
38 namespace plugin
39 {
40 
43 {
44 
45 private:
46 
48  std::string m_name;
49 
51  void* module;
52 
53 public:
54 
58  explicit ClayModule(const std::string& sName);
59 
61  virtual ~ClayModule();
62 
66  std::string GetName();
67 
71  void* GetHandle();
72 
77  void* Load(const std::string& sLibraryFileName);
78 
80  void Unload();
81 
85  bool IsLoaded();
86 
91  void* GetFunction(const std::string& sFunctionName);
92 
93 };
94 
95 typedef std::map<std::string, ClayModule*> ClayModuleMap;
96 
99 {
100 
101 private:
102 
104  ClayModuleMap m_ModuleMap;
105 
107  void FreeAllModules();
108 
109  std::string GetValidPath(const std::string& sFilePath);
110 
111 public:
112 
115 
118 
124  ClayModule* LoadModule(const std::string& sLibraryName, const std::string& sLibraryFilePath);
125 
130  ClayModule* FindModule(const std::string& sLibraryName);
131 
132 };
133 
134 } // end of clay::plugin
135 
136 namespace lib
137 {
138 
143 int Plugin(const std::string& sLibraryName, const std::string& sLibraryFilePath);
149 
152 } // end of clay::lib
153 
154 } // end of clay
155 
156 #endif // __CLAY_PLUGIN_H_INCLUDED__