Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
Plugger.h
1 /*
2  * Path class interface
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2005-12, IRIT UPS.
6  *
7  * OTAWA is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * OTAWA is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OTAWA; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #ifndef ELM_SYS_PLUGGER_H
22 #define ELM_SYS_PLUGGER_H
23 
24 #include <elm/macros.h>
25 #include <elm/PreIterator.h>
26 #include <elm/sys/Plugin.h>
27 #include <elm/data/Range.h>
28 #include <elm/data/Vector.h>
29 #include <elm/sys/Directory.h>
30 #include <elm/sys/Path.h>
31 #include <elm/util/ErrorHandler.h>
32 
33 namespace elm { namespace sys {
34 
35 // Plugger class
36 class Plugger: public ErrorBase {
37  friend class Plugin;
38  friend class PluginManager;
39 public:
40  typedef enum error_t {
41  OK = 0,
48  } error_t;
49 
50 public:
51  Plugger(CString hook, const Version& plugger_version, String paths = "*");
52  virtual ~Plugger(void);
53  void addPath(String path);
54  void removePath(String path);
55  void resetPaths(void);
56  Plugin *plug(const string& path);
57  Plugin *plugFile(sys::Path path);
58  inline String hook(void) const { return _hook; }
59  string getLastError(void);
60  inline bool quiet(void) const { return _quiet; }
61  inline void setQuiet(bool quiet) { _quiet = quiet; }
62  bool isPlugged(string name) const;
63 
64  // deprecated
65  virtual void onError(String message);
66  virtual void onWarning(String message);
67  error_t lastError(void);
69 
70  // Iterator class
71  class Iter: public PreIterator<Iter, String> {
72  public:
73  Iter(Plugger& _plugger, bool end = false);
74  ~Iter(void);
75  bool ended(void) const;
76  String item(void) const;
77  void next(void);
78  Plugin *plug(void) const;
79  Path path(void) const;
80  private:
81  Plugger& plugger;
82  Vector<Plugin *>& statics;
83  int i, c;
84  int _path;
85  Directory::Iter *file;
86  void go(void);
87  };
88 
89  // iterator access
90  inline const Vector<string>& paths() const { return _paths; }
91  inline Range<Iter> available() { return range(Iter(*this), Iter(*this, true)); }
92  inline const Vector<Plugin *>& plugged() const { return plugins; }
93 
94  // deprecated
95  class PathIterator: public Vector<string>::Iter {
96  public:
97  inline PathIterator(const Plugger& plugger): Vector<string>::Iter(plugger._paths) { }
99  };
100 
101 private:
102 
103  static Vector<Plugger *> pluggers;
104  CString _hook;
105  Version per_vers;
106  Vector<Plugin *> plugins;
107  Vector<String> _paths;
108  error_t err;
109  bool _quiet;
110  static void leave(Plugin *plugin);
111  Plugin *plug(Plugin *plugin, void *handle);
112  inline Vector<Plugin *>& statics(void) { return Plugin::static_plugins; }
113  void onError(error_level_t level, const string& message);
114  Plugin *lookELD(const Path& path, error_t& err, Vector<Plugin *>& deps);
115 
116  // portability functions
117  static void *link(sys::Path lib);
118  static void unlink(void *handle);
119  static void *lookSymbol(void *handle, cstring hook);
120  static void *lookLibrary(sys::Path lib, Vector<string> rpath);
121  static string error(void);
122 };
123 
124 } } // elm::sys
125 
126 #endif // ELM_SYS_PLUGGER_H
elm::sys::Directory::Iter
Definition: Directory.h:38
elm::ErrorBase
Definition: ErrorHandler.h:49
elm::sys::Plugger::PluginManager
friend class PluginManager
Definition: Plugger.h:38
elm::sys::Plugger::Iter::item
String item(void) const
Definition: system_Plugger.cpp:740
elm::iter
Definition: util_WAHVector.cpp:157
elm::Range
Definition: Range.h:29
elm::sys::Plugger::hook
String hook(void) const
Definition: Plugger.h:58
elm::sys::Path
Definition: Path.h:33
elm::sys::Plugger::lastErrorMessage
String lastErrorMessage(void)
Definition: system_Plugger.cpp:543
elm::sys::Plugger::getLastError
string getLastError(void)
Definition: system_Plugger.cpp:554
elm::sys::Plugger::NO_PLUGIN
@ NO_PLUGIN
Definition: Plugger.h:42
elm::sys::Plugin
Definition: Plugin.h:43
elm::sys::Plugger::plug
Plugin * plug(const string &path)
Definition: system_Plugger.cpp:199
elm::sys::Plugger::Iter::path
Path path(void) const
Definition: system_Plugger.cpp:756
elm::sys::Plugger::PathIterator::PathIterator
PathIterator(const PathIterator &iter)
Definition: Plugger.h:98
elm::sys::Plugger::Iter::ended
bool ended(void) const
Definition: system_Plugger.cpp:731
elm::sys::Plugger::onError
virtual void onError(String message)
Definition: system_Plugger.cpp:606
elm::error_level_t
error_level_t
Definition: ErrorHandler.h:31
elm::sys::Plugger::Plugin
friend class Plugin
Definition: Plugger.h:37
elm::CString
Definition: CString.h:17
elm::Version
Definition: Version.h:32
elm::sys::Plugger::OK
@ OK
Definition: Plugger.h:41
elm::range
Range< I > range(const I &begin, const I &end)
Definition: Range.h:67
elm::sys::Plugger::paths
const Vector< string > & paths() const
Definition: Plugger.h:90
elm::sys::Plugger::setQuiet
void setQuiet(bool quiet)
Definition: Plugger.h:61
elm::sys::Plugger::Iter
Definition: Plugger.h:71
elm::sys::Plugger::lastError
error_t lastError(void)
Definition: system_Plugger.cpp:532
elm::sys::Plugger::quiet
bool quiet(void) const
Definition: Plugger.h:60
elm::sys::Plugger::isPlugged
bool isPlugged(string name) const
Definition: system_Plugger.cpp:241
elm::sys::Plugger::available
Range< Iter > available()
Definition: Plugger.h:91
elm::sys::Plugger::BAD_PLUGIN
@ BAD_PLUGIN
Definition: Plugger.h:46
elm
Definition: adapter.h:26
elm::sys::Plugger::~Plugger
virtual ~Plugger(void)
Definition: system_Plugger.cpp:150
elm::Vector
Definition: Vector.h:34
elm::sys::Plugger::resetPaths
void resetPaths(void)
Definition: system_Plugger.cpp:188
elm::sys::Plugger::Iter::plug
Plugin * plug(void) const
Definition: system_Plugger.cpp:776
elm::sys::Plugger::BAD_VERSION
@ BAD_VERSION
Definition: Plugger.h:44
elm::sys::Plugger::Iter::Iter
Iter(Plugger &_plugger, bool end=false)
Definition: system_Plugger.cpp:704
elm::sys::Plugger::Iter::~Iter
~Iter(void)
Definition: system_Plugger.cpp:721
elm::sys::Plugger::NO_HOOK
@ NO_HOOK
Definition: Plugger.h:43
elm::sys::Plugger::plugFile
Plugin * plugFile(sys::Path path)
Definition: system_Plugger.cpp:411
elm::sys::Plugger::error_t
error_t
Definition: Plugger.h:40
elm::sys::Plugger::Iter::next
void next(void)
Definition: system_Plugger.cpp:767
elm::sys::Plugger::PathIterator
Definition: Plugger.h:95
elm::String
Definition: String.h:30
elm::sys::Plugger
Definition: Plugger.h:36
elm::sys::Plugger::addPath
void addPath(String path)
Definition: system_Plugger.cpp:171
elm::sys::Plugger::onWarning
virtual void onWarning(String message)
Definition: system_Plugger.cpp:634
elm::sys::Plugger::Plugger
Plugger(CString hook, const Version &plugger_version, String paths="*")
Definition: system_Plugger.cpp:112
elm::sys::Plugger::plugged
const Vector< Plugin * > & plugged() const
Definition: Plugger.h:92
elm::PreIterator
Definition: iter.h:28
elm::sys::Plugger::NO_MAGIC
@ NO_MAGIC
Definition: Plugger.h:45
elm::sys::Plugger::removePath
void removePath(String path)
Definition: system_Plugger.cpp:180
elm::sys::Plugger::MISSING_DEP
@ MISSING_DEP
Definition: Plugger.h:47
elm::sys::Plugger::PathIterator::PathIterator
PathIterator(const Plugger &plugger)
Definition: Plugger.h:97