PageRenderTime 11ms CodeModel.GetById 3ms app.highlight 6ms RepoModel.GetById 0ms app.codeStats 1ms

/xbmc/screensavers/rsxs-0.9/src/dlopen.hh

http://github.com/xbmc/xbmc
C++ Header | 73 lines | 44 code | 7 blank | 22 comment | 4 complexity | 3f666b6bf17ee85f5d5a7c0d609b9c3a MD5 | raw file
 1/*
 2 * Really Slick XScreenSavers
 3 * Copyright (C) 2002-2006  Michael Chapman
 4 *
 5 * This program is free software; you can redistribute it and/or modify
 6 * it under the terms of the GNU General Public License version 2 as
 7 * published by the Free Software Foundation.
 8 *
 9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 *
18 *****************************************************************************
19 *
20 * This is a Linux port of the Really Slick Screensavers,
21 * Copyright (C) 2002 Terence M. Welsh, available from www.reallyslick.com
22 */
23#ifndef _DLOPEN_HH
24#define _DLOPEN_HH
25
26#include <common.hh>
27
28#if USE_DLOPEN
29
30#include <ltdl.h>
31
32class Loader : public ResourceManager::Resource<void> {
33public:
34	typedef std::string Exception;
35public:
36	Loader() {
37		if (lt_dlinit())
38			throw Exception(lt_dlerror());
39	}
40	~Loader() { lt_dlexit(); }
41	void operator()() const {}
42};
43
44class Library;
45class Library : public ResourceManager::Resource<const Library*> {
46public:
47	typedef std::string Exception;
48private:
49	lt_dlhandle _handle;
50public:
51	Library(const std::string& library) {
52		static bool inited = false;
53		if (!inited) {
54			Common::resources->manage(new Loader);
55			inited = true;
56		}
57		_handle = lt_dlopenext(library.c_str());
58		if (!_handle)
59			throw Exception(lt_dlerror());
60	}
61	~Library() { lt_dlclose(_handle); }
62	const Library* operator()() const { return this; }
63	lt_ptr operator()(const std::string& function) const {
64		lt_ptr ptr = lt_dlsym(_handle, function.c_str());
65		if (!ptr)
66			throw Exception(lt_dlerror());
67		return ptr;
68	}
69};
70
71#endif // USE_DLOPEN
72
73#endif // _DLOPEN_HH