YARP
Yet Another Robot Platform
SharedLibraryFactory.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef YARP_OS_SHAREDLIBRARYFACTORY_H
7 #define YARP_OS_SHAREDLIBRARYFACTORY_H
8 
9 #include <yarp/os/api.h>
10 
11 #include <yarp/os/SharedLibrary.h>
13 #include <yarp/os/Vocab.h>
14 
15 #include <string>
16 
17 
18 namespace yarp {
19 namespace os {
20 
28 {
29 public:
39  enum
40  {
42  STATUS_OK = yarp::os::createVocab32('o', 'k'),
43  STATUS_LIBRARY_NOT_FOUND = yarp::os::createVocab32('f', 'o', 'u', 'n'),
44  STATUS_LIBRARY_NOT_LOADED = yarp::os::createVocab32('l', 'o', 'a', 'd'),
45  STATUS_FACTORY_NOT_FOUND = yarp::os::createVocab32('f', 'a', 'c', 't'),
46  STATUS_FACTORY_NOT_FUNCTIONAL = yarp::os::createVocab32('r', 'u', 'n')
47  };
48 
52  explicit SharedLibraryFactory();
53 
60  SharedLibraryFactory(const char* dll_name,
61  const char* fn_name = nullptr);
62 
67 
75  bool open(const char* dll_name, const char* fn_name = nullptr);
76 
82  bool isValid() const;
83 
89  int getStatus() const;
90 
96  std::string getError() const;
97 
103  const SharedLibraryClassApi& getApi() const;
104 
110  int getReferenceCount() const;
111 
117  int addRef();
118 
124  int removeRef();
125 
131  std::string getName() const;
132 
138  std::string getClassName() const;
139 
145  std::string getBaseClassName() const;
146 
156  bool useFactoryFunction(void* factory);
157 
158 private:
159  SharedLibrary lib;
160  int status;
162  int returnValue;
163  int rct; // FIXME Remove this reference counter and use a shared_ptr instead.
164  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) name;
165  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) className;
166  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) baseClassName;
167  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) error;
168 };
169 
170 } // namespace os
171 } // namespace yarp
172 
173 #endif // YARP_OS_SHAREDLIBRARYFACTORY_H
A wrapper for a named factory method in a named shared library.
virtual ~SharedLibraryFactory()
Destructor.
Low-level wrapper for loading shared libraries (DLLs) and accessing symbols within it.
Definition: SharedLibrary.h:31
bool isValid()
Check if time is valid (non-zero).
Definition: Time.cpp:314
constexpr yarp::conf::vocab32_t createVocab32(char a, char b=0, char c=0, char d=0)
Create a vocab from chars.
Definition: Vocab.h:28
The main, catch-all namespace for YARP.
Definition: dirs.h:16
Collection of hooks for creating/destroying a plugin.
#define YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(x)
Suppress MSVC C4251 warning for the declaration.
Definition: system.h:336
#define YARP_os_API
Definition: api.h:18