aboutsummaryrefslogtreecommitdiffstats
path: root/staging_vespalib/src/vespa/vespalib/util/librarypool.h
blob: 57a92f473c2e3174a3fb783f2d8f4daa1b26c4f4 (plain) (blame)
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
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <vespa/vespalib/util/sync.h>
#include <vespa/vespalib/stllike/string.h>
#include <vespa/fastos/dynamiclibrary.h>
#include <map>

namespace vespalib {

class LibraryPool
{
public:
    LibraryPool();
    ~LibraryPool();
    /**
     * This will load the library with the name given.
     * - It will verify linkage at load time.
     * - Symbols will be private.
     * @param name The name of the library to load. That is without the 'lib' prefix and the '.so' extension.
     * @throws IllegalArgumentException if there are any errors.
     */
    void loadLibrary(const vespalib::stringref & name);
    /**
     * Will return the library requested. NULL if not found.
     * @param name The name of the library as given in the @ref loadLibrary call.
     * @return The library that has already been loaded. NULL if not found.
     */
    FastOS_DynamicLibrary *get(const vespalib::stringref & name);
    const FastOS_DynamicLibrary *get(const vespalib::stringref & name) const;
private:
    typedef std::shared_ptr<FastOS_DynamicLibrary>      DynamicLibrarySP;
    typedef std::map<vespalib::string, DynamicLibrarySP>  LibraryMap;
    LibraryMap _libraries;
    Lock       _lock;
};

}