LoadableModule.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #include "squid.h"
10 #include "base/TextException.h"
11 #include "libltdl/ltdl.h" /* generated file */
12 #include "LoadableModule.h"
13 
14 // Note: We must use preprocessor instead of C ifs because if dlopen()
15 // is seen by the static linker, the linker will complain.
16 
17 LoadableModule::LoadableModule(const String &aName): theName(aName), theHandle(0)
18 {
19  // Initialise preloaded symbol lookup table.
20  LTDL_SET_PRELOADED_SYMBOLS();
21  if (lt_dlinit() != 0)
22  throw TexcHere("internal error: cannot initialize libtool module loader");
23 }
24 
26 {
27  if (loaded())
28  unload();
29  assert(lt_dlexit() == 0); // XXX: replace with a warning
30 }
31 
32 bool
34 {
35  return theHandle != 0;
36 }
37 
38 void
40 {
41  if (loaded())
42  throw TexcHere("internal error: reusing LoadableModule object");
43 
44  theHandle = openModule(mode);
45 
46  if (!loaded())
47  throw TexcHere(errorMsg());
48 }
49 
50 void
52 {
53  if (!loaded())
54  throw TexcHere("internal error: unloading not loaded module");
55 
56  if (!closeModule())
57  throw TexcHere(errorMsg());
58 
59  theHandle = 0;
60 }
61 
62 void *
64 {
65  return lt_dlopen(theName.termedBuf());
66 }
67 
68 bool
70 {
71  // we cast to avoid including ltdl.h in LoadableModule.h
72  return lt_dlclose(static_cast<lt_dlhandle>(theHandle)) == 0;
73 }
74 
75 const char *
77 {
78  return lt_dlerror();
79 }
80 
void * openModule(int mode)
const char * errorMsg()
#define assert(EX)
Definition: assert.h:17
bool loaded() const
char const * termedBuf() const
Definition: SquidString.h:90
void load(int mode=lmNow)
#define TexcHere(msg)
Definition: TextException.h:81
LoadableModule(const String &aName)

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors