]> git.proxmox.com Git - ceph.git/blob - ceph/src/common/PluginRegistry.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / common / PluginRegistry.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph distributed storage system
5 *
6 * Copyright (C) 2013,2014 Cloudwatt <libre.licensing@cloudwatt.com>
7 * Copyright (C) 2014 Red Hat <contact@redhat.com>
8 *
9 * Author: Loic Dachary <loic@dachary.org>
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 */
17
18 #ifndef CEPH_COMMON_PLUGINREGISTRY_H
19 #define CEPH_COMMON_PLUGINREGISTRY_H
20
21 #include <map>
22 #include <string>
23 #include "common/ceph_mutex.h"
24 #include "include/common_fwd.h"
25
26 extern "C" {
27 const char *__ceph_plugin_version();
28 int __ceph_plugin_init(CephContext *cct,
29 const std::string& type,
30 const std::string& name);
31 }
32
33 namespace ceph {
34
35 class Plugin {
36 public:
37 void *library;
38 CephContext *cct;
39
40 explicit Plugin(CephContext *cct) : library(NULL), cct(cct) {}
41 virtual ~Plugin() {}
42 };
43
44 class PluginRegistry {
45 public:
46 CephContext *cct;
47 ceph::mutex lock = ceph::make_mutex("PluginRegistery::lock");
48 bool loading;
49 bool disable_dlclose;
50 std::map<std::string,std::map<std::string,Plugin*> > plugins;
51
52 explicit PluginRegistry(CephContext *cct);
53 ~PluginRegistry();
54
55 int add(const std::string& type, const std::string& name,
56 Plugin *factory);
57 int remove(const std::string& type, const std::string& name);
58 Plugin *get(const std::string& type, const std::string& name);
59 Plugin *get_with_load(const std::string& type, const std::string& name);
60
61 int load(const std::string& type,
62 const std::string& name);
63 int preload();
64 int preload(const std::string& type);
65 };
66 }
67
68 #endif