YARP
Yet Another Robot Platform
Loading...
Searching...
No Matches
YarpPlugin.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_YARPPLUGIN_H
7
#define YARP_OS_YARPPLUGIN_H
8
9
#include <
yarp/os/YarpPluginSelector.h
>
10
#include <
yarp/os/YarpPluginSettings.h
>
11
12
namespace
yarp::os
{
13
19
template
<
class
T>
20
class
YarpPlugin
21
{
22
private
:
23
SharedLibraryClassFactory<T>
* factory;
24
SharedLibraryClass<T>
content;
25
YarpPluginSettings
settings;
26
27
public
:
33
YarpPlugin
()
34
{
35
factory
=
nullptr
;
36
}
37
43
virtual
~YarpPlugin
()
44
{
45
close
();
46
}
47
58
bool
open
(
YarpPluginSettings
& settings)
59
{
60
close
();
61
factory
=
new
SharedLibraryClassFactory<T>
();
62
if
(!
factory
) {
63
return
false
;
64
}
65
if
(!settings.
open
(*
factory
)) {
66
settings.
reportStatus
(*
factory
);
67
close
();
68
return
false
;
69
}
70
this->settings = settings;
71
return
true
;
72
}
73
81
bool
close
()
82
{
83
if
(!
factory
) {
84
return
true
;
85
}
86
factory
->removeRef();
87
if
(
factory
->getReferenceCount() <= 0) {
88
delete
factory
;
89
factory
=
nullptr
;
90
}
91
return
true
;
92
}
93
99
bool
isValid
()
const
100
{
101
return
(
factory
!=
nullptr
);
102
}
103
112
T*
create
()
113
{
114
if
(!
factory
) {
115
return
nullptr
;
116
}
117
return
factory
->create();
118
}
119
127
void
destroy
(T* obj)
128
{
129
if
(!
factory
) {
130
return
;
131
}
132
factory
->destroy(obj);
133
}
134
140
std::string
getName
()
141
{
142
if
(!
factory
) {
143
return
{};
144
}
145
return
factory
->getName();
146
}
147
153
std::string
getClassName
()
154
{
155
if
(!
factory
) {
156
return
{};
157
}
158
return
factory
->getClassName();
159
}
160
166
std::string
getBaseClassName
()
167
{
168
if
(!
factory
) {
169
return
{};
170
}
171
return
factory
->getBaseClassName();
172
}
173
179
SharedLibraryClassFactory<T>
*
getFactory
()
const
180
{
181
return
factory
;
182
}
183
};
184
185
}
// namespace yarp::os
186
187
#endif
// YARP_OS_YARPPLUGIN_H
YarpPluginSelector.h
YarpPluginSettings.h
yarp::os::BufferedPort
A mini-server for performing network communication in the background.
Definition
BufferedPort.h:60
yarp::os::YarpPluginSettings
Collect hints for finding a particular plugin.
Definition
YarpPluginSettings.h:21
yarp::os::YarpPluginSettings::open
bool open(SharedLibraryFactory &factory)
Initialize a factory object based on the hints available.
Definition
YarpPlugin.cpp:81
yarp::os::YarpPluginSettings::reportStatus
void reportStatus(SharedLibraryFactory &factory) const
Give a human-readable report of the status of a factory.
Definition
YarpPlugin.cpp:167
yarp::os::YarpPlugin
Type-safe access to a plugin.
Definition
YarpPlugin.h:21
yarp::os::YarpPlugin::getFactory
SharedLibraryClassFactory< T > * getFactory() const
Definition
YarpPlugin.h:179
yarp::os::YarpPlugin::close
bool close()
End this use of the plugin.
Definition
YarpPlugin.h:81
yarp::os::YarpPlugin::create
T * create()
Create an object using the plugin.
Definition
YarpPlugin.h:112
yarp::os::YarpPlugin::open
bool open(YarpPluginSettings &settings)
Load a library and prepare an object factory, based on the hints supplied.
Definition
YarpPlugin.h:58
yarp::os::YarpPlugin::getName
std::string getName()
Definition
YarpPlugin.h:140
yarp::os::YarpPlugin::destroy
void destroy(T *obj)
Destroy an object previously created using the plugin.
Definition
YarpPlugin.h:127
yarp::os::YarpPlugin::getBaseClassName
std::string getBaseClassName()
Definition
YarpPlugin.h:166
yarp::os::YarpPlugin::YarpPlugin
YarpPlugin()
Constructor.
Definition
YarpPlugin.h:33
yarp::os::YarpPlugin::getClassName
std::string getClassName()
Definition
YarpPlugin.h:153
yarp::os::YarpPlugin::~YarpPlugin
virtual ~YarpPlugin()
Destructor.
Definition
YarpPlugin.h:43
yarp::os::YarpPlugin::isValid
bool isValid() const
Definition
YarpPlugin.h:99
factory
DumpObj * factory(Bottle &obj)
Definition
main.cpp:82
yarp::os
An interface to the operating system, including Port based communication.
Definition
AbstractCarrier.h:13
YARP
3.11.100+20250603.4+gitaa77f8b5c
src
libYARP_os
src
yarp
os
YarpPlugin.h
Generated on Wed Jun 4 2025 02:40:12 for YARP by
1.9.8