YARP
Yet Another Robot Platform
SharedLibraryFactory.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #ifndef YARP_OS_SHAREDLIBRARYFACTORY_H
10 #define YARP_OS_SHAREDLIBRARYFACTORY_H
11 
12 #include <yarp/os/api.h>
13 
14 #include <yarp/os/SharedLibrary.h>
16 #include <yarp/os/Vocab.h>
17 
18 #include <string>
19 
20 
21 namespace yarp {
22 namespace os {
23 
31 {
32 public:
42  enum
43  {
45  STATUS_OK = yarp::os::createVocab('o', 'k'),
46  STATUS_LIBRARY_NOT_FOUND = yarp::os::createVocab('f', 'o', 'u', 'n'),
47  STATUS_LIBRARY_NOT_LOADED = yarp::os::createVocab('l', 'o', 'a', 'd'),
48  STATUS_FACTORY_NOT_FOUND = yarp::os::createVocab('f', 'a', 'c', 't'),
49  STATUS_FACTORY_NOT_FUNCTIONAL = yarp::os::createVocab('r', 'u', 'n')
50  };
51 
55  explicit SharedLibraryFactory();
56 
63  SharedLibraryFactory(const char* dll_name,
64  const char* fn_name = nullptr);
65 
70 
78  bool open(const char* dll_name, const char* fn_name = nullptr);
79 
85  bool isValid() const;
86 
92  int getStatus() const;
93 
99  std::string getError() const;
100 
106  const SharedLibraryClassApi& getApi() const;
107 
113  int getReferenceCount() const;
114 
120  int addRef();
121 
127  int removeRef();
128 
134  std::string getName() const;
135 
141  std::string getClassName() const;
142 
148  std::string getBaseClassName() const;
149 
159  bool useFactoryFunction(void* factory);
160 
161 private:
162  SharedLibrary lib;
163  int status;
165  int returnValue;
166  int rct; // FIXME Remove this reference counter and use a shared_ptr instead.
167  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) name;
168  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) className;
169  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) baseClassName;
170  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) error;
171 };
172 
173 } // namespace os
174 } // namespace yarp
175 
176 #endif // YARP_OS_SHAREDLIBRARYFACTORY_H
yarp::os::createVocab
constexpr yarp::conf::vocab32_t createVocab(char a, char b=0, char c=0, char d=0)
Definition: Vocab.h:22
yarp::os::Time::isValid
bool isValid()
Check if time is valid (non-zero).
Definition: Time.cpp:317
YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG
#define YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(x)
Suppress MSVC C4251 warning for the declaration.
Definition: system.h:339
api.h
SharedLibrary.h
YARP_os_API
#define YARP_os_API
Definition: api.h:19
yarp::os::SharedLibraryFactory::STATUS_NONE
@ STATUS_NONE
Not configured yet.
Definition: SharedLibraryFactory.h:44
yarp::os::SharedLibraryClassApi
Collection of hooks for creating/destroying a plugin.
Definition: SharedLibraryClassApi.h:36
yarp::os::SharedLibrary
Low-level wrapper for loading shared libraries (DLLs) and accessing symbols within it.
Definition: SharedLibrary.h:34
yarp::os::SharedLibraryFactory
A wrapper for a named factory method in a named shared library.
Definition: SharedLibraryFactory.h:31
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
Vocab.h
yarp::os::SharedLibraryFactory::~SharedLibraryFactory
virtual ~SharedLibraryFactory()
Destructor.
SharedLibraryClassApi.h