Open Lighting Architecture  0.9.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Namespaces | Macros | Typedefs | Functions
Module.h File Reference

Detailed Description

Information required to use the StreamingClient as a plugin.

Sometimes it's useful for client applications to avoid linking against libola, say for instance if they install separately from OLA. By deferring the linking and using libola as a plugin, clients can use OLA if it's installed on the system or if not, take some other action like displaing a message or using another output mechanism.

This file provides plugin interfaces so that a client code can load a small subset of libola at runtime. For each function we #define the symbol name and then provide the function type signature and the actual function itself.

http://www.tldp.org/HOWTO/html_single/C++-dlopen provides some good background.

#include <dlfcn.h>
#include <ola/DmxBuffer.h>
#include <iostream>
using std::cout;
using std::endl;
template <typename FunctionType>
FunctionType LoadSymbol(void *module, const char *symbol) {
FunctionType ptr = reinterpret_cast<FunctionType>(dlsym(module, symbol));
if (!ptr) {
cout << "Failed to find " << symbol << " " << dlerror() << endl;
}
return ptr;
}
int main() {
// Adjust to suit.
void *module = dlopen("/usr/local/lib/libola.dylib", RTLD_NOW);
// void *module = dlopen("/usr/local/lib/libola.so", RTLD_NOW);
if (!module) {
cout << "Failed to load" << dlerror() << endl;
return -1;
}
ola_new_streaming_client_t *new_client_ptr =
LoadSymbol<ola_new_streaming_client_t*>(module, OLA_NEW_STREAMING_CLIENT);
ola_delete_streaming_client_t *delete_client_ptr =
LoadSymbol<ola_delete_streaming_client_t*>(
ola_new_dmxbuffer_t *new_buffer_ptr =
LoadSymbol<ola_new_dmxbuffer_t*>(module, OLA_NEW_DMXBUFFER);
ola_delete_dmxbuffer_t *delete_buffer_ptr =
LoadSymbol<ola_delete_dmxbuffer_t*>(module, OLA_DELETE_DMXBUFFER);
ola_set_dmxbuffer_t *set_buffer_ptr =
LoadSymbol<ola_set_dmxbuffer_t*>(module, OLA_SET_DMXBUFFER);
if (!(new_client_ptr && delete_client_ptr && new_buffer_ptr &&
delete_buffer_ptr && set_buffer_ptr)) {
return -1;
}
client = new_client_ptr(options);
cout << "Setup() returned: " << client->Setup() << endl;
ola::DmxBuffer *buffer = new_buffer_ptr();
// Now actually send the DMX
uint8_t data[] = {1, 2, 3};
set_buffer_ptr(buffer, data, sizeof(data));
const unsigned int universe = 1;
client->SendDMX(universe, *buffer, ola::client::StreamingClient::SendArgs());
client->Stop();
delete_buffer_ptr(buffer);
delete_client_ptr(client);
if (module) {
dlclose(module);
}
}

Go to the source code of this file.

Namespaces

namespace  ola
 The namespace containing all OLA symbols.
namespace  ola::client
 OLA C++ API.

Macros

#define OLA_NEW_STREAMING_CLIENT   "ola_new_streaming_client"
 The symbol for the function to create a new StreamingClient.
#define OLA_DELETE_STREAMING_CLIENT   "ola_delete_streaming_client"
 The symbol for the function to delete a StreamingClient.
#define OLA_NEW_DMXBUFFER   "ola_new_dmxbuffer"
 The symbol for the function to create a new DmxBuffer.
#define OLA_DELETE_DMXBUFFER   "ola_delete_dmxbuffer"
 The symbol for the function to delete a DmxBuffer.
#define OLA_SET_DMXBUFFER   "ola_set_dmxbuffer"
 The symbol for the function to set the contents of a DmxBuffer.

Typedefs

typedef
ola::client::StreamingClientInterface
ola_new_streaming_client_t (const ola::client::StreamingClient::Options &options)
 A function pointer to create a new StreamingClient.
typedef void ola_delete_streaming_client_t (ola::client::StreamingClientInterface *client)
 A function pointer to delete a StreamingClient.
typedef ola::DmxBufferola_new_dmxbuffer_t ()
 A function pointer to create a new DmxBuffer.
typedef void ola_delete_dmxbuffer_t (ola::DmxBuffer *buffer)
 A function pointer to delete a DmxBuffer.
typedef void ola_set_dmxbuffer_t (ola::DmxBuffer *buffer, const uint8_t *data, unsigned int size)
 A function pointer to set the contents of a DmxBuffer.

Functions

ola::client::StreamingClientInterfaceola_new_streaming_client (const ola::client::StreamingClient::Options &options)
void ola_delete_streaming_client (ola::client::StreamingClientInterface *client)
ola::DmxBufferola_new_dmxbuffer ()
void ola_delete_dmxbuffer (ola::DmxBuffer *buffer)
void ola_set_dmxbuffer (ola::DmxBuffer *buffer, const uint8_t *data, unsigned int size)

Typedef Documentation

typedef void ola_set_dmxbuffer_t(ola::DmxBuffer *buffer, const uint8_t *data, unsigned int size)

A function pointer to set the contents of a DmxBuffer.

To avoid the vtable penalty with DmxBuffer we expose a function to call Set(). If you want to access other methods in DmxBuffer please send a patch.