Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / 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 "common/Mutex.h"
22
23 class CephContext;
24
25 extern "C" {
26   const char *__ceph_plugin_version();
27   int __ceph_plugin_init(CephContext *cct,
28                          const std::string& type,
29                          const std::string& name);
30 }
31
32 namespace ceph {
33
34   class Plugin {
35   public:
36     void *library;
37     CephContext *cct;
38
39     explicit Plugin(CephContext *cct) : library(NULL), cct(cct) {}
40     virtual ~Plugin() {}
41   };
42
43   class PluginRegistry {
44   public:
45     CephContext *cct;
46     Mutex lock;
47     bool loading;
48     bool disable_dlclose;
49     std::map<std::string,std::map<std::string,Plugin*> > plugins;
50
51     explicit PluginRegistry(CephContext *cct);
52     ~PluginRegistry();
53
54     int add(const std::string& type, const std::string& name,
55             Plugin *factory);
56     int remove(const std::string& type, const std::string& name);
57     Plugin *get(const std::string& type, const std::string& name);
58     Plugin *get_with_load(const std::string& type, const std::string& name);
59
60     int load(const std::string& type,
61              const std::string& name);
62     int preload();
63     int preload(const std::string& type);
64   };
65 }
66
67 #endif