This file is indexed.

/usr/include/casacore/casa/OS/DynLib.h is in casacore-dev 2.2.0-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
//# DynLib.h: Class to handle loadig of dynamic libraries
//# Copyright (C) 2009
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//#        Internet email: aips2-request@nrao.edu.
//#        Postal address: AIPS++ Project Office
//#                        National Radio Astronomy Observatory
//#                        520 Edgemont Road
//#                        Charlottesville, VA 22903-2475 USA
//#
//# $Id$

#ifndef CASA_DYNLIB_H
#define CASA_DYNLIB_H

//# Includes
#include <casacore/casa/aips.h>
#include <string>

namespace casacore { //# NAMESPACE CASACORE - BEGIN

  // <summary> 
  // Class to handle loading of dynamic libraries
  // </summary>
  // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
  // </reviewed>

  // <use visibility=export>

  // <prerequisite> 
  //    <li> Basic knowledge of the dlopen function family
  // </prerequisite>

  // <synopsis> 
  // This class makes it possible to load a dynamic library and execute an
  // initialization function. Furthermore, one can get a pointer to any function
  // in the dynamic library and close the library.
  //
  // The search path of the shared library is as follows:
  // <ul>
  //  <li> If the environment library CASACORE_LDPATH is defined, it is tried to
  //       find the library using that path.
  //  <li> If not defined or not found, the system's (DY)LD_LIBRARY_PATH is used.
  //  <li> The library looked for has the name 'prefix'libname'suffix'.
  //       <br>As prefix first "lib" is used, thereafter the given one
  //       (e.g., "libcasa_").
  //       <br>As suffix first ".so" is used, thereafter ".dylib" (for OS-X).
  // </ul>
  //
  // It is a wrapper around functions dlopen, dlsym, and dlclose.
  // If dlopen and so are not supported on a platform, the class acts as if
  // the shared library could not be found.
  // </synopsis>

  // <example>
  // <srcblock>
  //    DynLib dl("derivedmscal", "libcasa_", "register_derivedmscal");
  //    AlwaysAssert (dl.getHandle());
  // </srcblock>
  // Using this 
  //  loads the shared library <src>libcasa_derivedmscal.so</src> and
  //  executes the given register initialization function.
  // </example>

  // <motivation> 
  // dlopen is a standard UNIX system call, but some operating systems
  // do not support it or have different function names (notably Windows).
  // In this way use of dynamic libraries is centralized and can easily b
  // tailored as needed.
  // </motivation>

  class DynLib
  {
  public:

    // Load the dynamic library. It is tried with prefixes <src>prefix</src>
    // and "lib" (in that oder) and with suffix ".so" or ".dylib" (for Apple).
    // No library version number is used.
    // If not loaded successfully, an exception is thrown.
    // <br>If a non-empty funcName is given, that function is looked up and
    // executed for initialization purposes. Its signature must be
    // <src>void func()</src>.
    // Note that the function name should not be mangled, thus declared
    // <src>extern "C"</src>.
    // An exception is thrown if the library is loaded successfully, but
    // <src>funcName</src> could not be found.
    // <br>If <src>closeOnDestruction=True</src>, the dynamic library is
    // closed on destruction of the DynLib object.
    DynLib (const std::string& library,
            const std::string& prefix=std::string(),
            const std::string& funcName=std::string(),
            bool closeOnDestruction=True);

    // The same as above, but it is tried with and without the given version
    // (in that order).
    DynLib (const std::string& library,
            const std::string& prefix,
            const std::string& version,
            const std::string& funcName,
            bool closeOnDestruction=True);

    // Load the dynamic library with the given name, prefix, and suffix.
    // If not loaded successfully, the internal handle is NULL.
    // <br>If <src>closeOnDestruction=True</src>, the dynamic library is closed
    // when the DynLib object is destructed.
    DynLib (const std::string& library,
            Bool closeOnDestruction,
            const std::string& prefix="lib",
#ifdef __APPLE__
            const std::string& suffix=".dylib");
#else
            const std::string& suffix=".so");
#endif

    // Close the dynamic library if told so in the constructor.
    ~DynLib();

    // Get a pointer to a function in the dynamic library.
    // The pointer has to be casted with a reinterpret_cast to a function
    // pointer with the correct signature. When compiling with -pedantic the
    // compiler will give a warning for such a cast, because on some systems
    // (in particular some micro-controllers) a data pointer differs from a
    // function pointer. However, that problem cannot be solved.
    // For example:
    // <srcblock>
    //   typedef Int MyFunc(Int, Int);
    //   void* initfunc = DynLib::getFunc (mod, ("register_"+name).c_str());
    //   if (initFunc) {
    //     MyFunc* func = reinterpret_cast<MyFunc*>(initfunc);
    //     Int result = func(1,2);
    //   }
    // </srcblock>
    // casts to a function returning Int and taking two Ints.
    // <br>A null pointer is returned if the function could not be found.
    void* getFunc (const std::string& funcName);

    // Get the dynamic library handle.
    void* getHandle() const
      { return itsHandle; }

    // Get the possible error.
    const std::string& getError() const
      { return itsError; }

  private:
    // Try to open the library with some prefixes, suffixes and versions
    // and to execute the initialization function.
    // If successful, itsHandle is filled. Otherwise an exception is thrown.
    void attach (const std::string& name,
                 const std::string& prefix,
                 const std::string& version,
                 const std::string& funcName);

    // Try to open the library with some prefixes, suffixes and versions
    // If successful, itsHandle is filled and the full library name is
    // returned. Otherwise an empty name is returned.
    std::string tryOpen (const std::string& name,
                         const std::string& libdir,
                         const std::string& prefix,
                         const std::string& version);

    // Open (load) the dynamic library.
    void open (const std::string& name);

    // Close (unload) the dynamic library (if opened).
    void close();

    // Try if the library can be opened using CASACORE_LDPATH.
    std::string tryCasacorePath (const std::string& library,
                                 const std::string& prefix,
                                 const std::string& version);

    //# Handle to dynamic library; note that the pointer is not owned, so the
    //# generated copy ctor and assignment are fine.
    void*       itsHandle;
    Bool        itsDoClose;
    std::string itsError;
  };

} //# NAMESPACE CASACORE - END

#endif