YARP  2.3.70.1
Yet Another Robot Platform
SharedLibraryClassApi.h File Reference
#include <yarp/conf/system.h>
#include <yarp/os/Vocab.h>
#include <cstring>
+ Include dependency graph for SharedLibraryClassApi.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  yarp::os::SharedLibraryClassApi
 Collection of hooks for creating/destroying a plugin. More...
 

Namespaces

 yarp
 The main, catch-all namespace for YARP.
 
 yarp::os
 An interface to the operating system, including Port based communication.
 

Macros

#define YARP_SHAREDLIBRARYCLASSAPI_PADDING   (30-2*(YARP_POINTER_SIZE/4))
 
#define YARP_SHARED_CLASS_FN   extern "C" YARP_EXPORT
 
#define YARP_DEFINE_SHARED_SUBCLASS(factoryname, classname, basename)
 Macro to create a bunch of functions with undecorated names that can be found within a plugin library to handle creation/deletion of that plugin. More...
 
#define YARP_DEFAULT_FACTORY_NAME   "yarp_default_factory"
 
#define YARP_DEFINE_DEFAULT_SHARED_CLASS(classname)   YARP_DEFINE_SHARED_SUBCLASS(yarp_default_factory, classname, classname)
 
#define YARP_DEFINE_SHARED_CLASS(factoryname, classname)   YARP_DEFINE_SHARED_SUBCLASS(factoryname, classname, classname)
 

Macro Definition Documentation

◆ YARP_DEFAULT_FACTORY_NAME

#define YARP_DEFAULT_FACTORY_NAME   "yarp_default_factory"

Definition at line 113 of file SharedLibraryClassApi.h.

◆ YARP_DEFINE_DEFAULT_SHARED_CLASS

#define YARP_DEFINE_DEFAULT_SHARED_CLASS (   classname)    YARP_DEFINE_SHARED_SUBCLASS(yarp_default_factory, classname, classname)

Definition at line 114 of file SharedLibraryClassApi.h.

◆ YARP_DEFINE_SHARED_CLASS

#define YARP_DEFINE_SHARED_CLASS (   factoryname,
  classname 
)    YARP_DEFINE_SHARED_SUBCLASS(factoryname, classname, classname)

Definition at line 115 of file SharedLibraryClassApi.h.

◆ YARP_DEFINE_SHARED_SUBCLASS

#define YARP_DEFINE_SHARED_SUBCLASS (   factoryname,
  classname,
  basename 
)
Value:
YARP_SHARED_CLASS_FN void *factoryname ## _create () { \
classname *cn = new classname; \
basename *bn = dynamic_cast<basename *>(cn); \
if (!bn) delete cn; \
return static_cast<void *>(bn); \
} \
YARP_SHARED_CLASS_FN void factoryname ## _destroy (void *obj) { classname *cn = dynamic_cast<classname *>(static_cast<basename *>(obj)); if(cn) delete cn; } \
YARP_SHARED_CLASS_FN int factoryname ## _getVersion (char *ver, int len) { return 0; } \
YARP_SHARED_CLASS_FN int factoryname ## _getAbi (char *abi, int len) { return 0; } \
YARP_SHARED_CLASS_FN int factoryname ## _getClassName (char *name, int len) { char cname[] = # classname; strncpy(name, cname, len); return strlen(cname)+1; } \
YARP_SHARED_CLASS_FN int factoryname ## _getBaseClassName (char *name, int len) { char cname[] = # basename; strncpy(name, cname, len); return strlen(cname)+1; } \
YARP_SHARED_CLASS_FN int factoryname(void *api, int len) { \
if (len<(int)sizeof(yarp::os::SharedLibraryClassApi)) return -1; \
sapi->startCheck = VOCAB4('Y', 'A', 'R', 'P'); \
sapi->structureSize = sizeof(yarp::os::SharedLibraryClassApi); \
sapi->systemVersion = 5; \
sapi->create = factoryname ## _create; \
sapi->destroy = factoryname ## _destroy; \
sapi->getVersion = factoryname ## _getVersion; \
sapi->getAbi = factoryname ## _getAbi; \
sapi->getClassName = factoryname ## _getClassName; \
sapi->getBaseClassName = factoryname ## _getBaseClassName; \
for (int i=0; i<YARP_SHAREDLIBRARYCLASSAPI_PADDING; i++) { sapi->roomToGrow[i] = 0; } \
sapi->endCheck = VOCAB4('P', 'L', 'U', 'G'); \
return sapi->startCheck; \
}
Collection of hooks for creating/destroying a plugin.
#define YARP_SHAREDLIBRARYCLASSAPI_PADDING
#define YARP_SHARED_CLASS_FN
#define VOCAB4(a, b, c, d)
Definition: Vocab.h:23

Macro to create a bunch of functions with undecorated names that can be found within a plugin library to handle creation/deletion of that plugin.

Use with care.

Parameters
factorynamethe name of the "hook" function to make. A collection of other helper functions with names composed of the factoryname with _create/_destroy/... appended.
classnamethe class that the hook will be able to instantiate.
basenamethe superclass that the user of the plugin should be working with.

Definition at line 74 of file SharedLibraryClassApi.h.

◆ YARP_SHARED_CLASS_FN

#define YARP_SHARED_CLASS_FN   extern "C" YARP_EXPORT

Definition at line 56 of file SharedLibraryClassApi.h.

◆ YARP_SHAREDLIBRARYCLASSAPI_PADDING

#define YARP_SHAREDLIBRARYCLASSAPI_PADDING   (30-2*(YARP_POINTER_SIZE/4))

Definition at line 24 of file SharedLibraryClassApi.h.