19 #ifndef CORRELATOR_PLUGIN_HPP
20 #define CORRELATOR_PLUGIN_HPP
23 #include <ApamaTypes.h>
24 #include <AP_Platform.h>
68 #define AP_PLUGIN_VERSION 0x00090000
71 #if (__GNUC__ > 4 || __GNUC_MINOR__ > 3 || !defined(__linux__))
72 #define _has_std_initializer_list
185 virtual uint32 version()
const = 0;
201 virtual char8* char8alloc(
size_t len)
const = 0;
214 virtual char8* char8dup(
const char8* s)
const = 0;
224 virtual void char8free(char8* s)
const = 0;
235 virtual AP_uint64 getContextId()
const = 0;
244 virtual void pluginNowBlocking()
const = 0;
264 virtual ~NoContext() {}
265 virtual uint32
version()
const {
return 0; }
266 virtual char8*
char8alloc(
size_t len)
const {
return 0; }
267 virtual char8*
char8dup(
const char8* s)
const {
return 0; }
268 virtual void char8free(char8* s)
const { }
288 typedef std::shared_ptr<AP_EventHandlerInterface>
ptr_t;
338 virtual void sendEvent(
const char* event) = 0;
353 virtual void sendEventTo(
const char* event, AP_uint64 targetContext, AP_uint64 sourceContext) = 0;
377 virtual void sendEventTo(
const char *event,
const char *targetChannel,
const AP_Context &source) = 0;
378 #ifdef _has_std_initializer_list
396 subscribe_impl(handler, channels.begin(), channels.end());
426 template<
typename ITER>
429 subscribe_impl(handler, start, end);
450 subscribe_impl(handler, &channel, (&channel)+1);
452 #ifdef _has_std_initializer_list
468 unsubscribe_impl(handler, channels.begin(), channels.end());
496 template<
typename ITER>
499 unsubscribe_impl(handler, start, end);
516 unsubscribe_impl(handler, &channel, (&channel)+1);
537 template<
typename ITER>
540 for (ITER it = start; it != end; ++it) {
541 subscribe_impl(handler, (
char const *
const *) &(*it), (
char const *
const *) &(*it) + 1);
548 template<
typename ITER>
551 for (ITER it = start; it != end; ++it) {
552 unsubscribe_impl(handler, (
char const *
const *) &(*it), (
char const *
const *) &(*it) + 1);
718 template <
typename FN>
720 visitSequenceElementsImpl(Wrap<FN>(fn), start, length);
858 operator int64()
const {
869 operator float64()
const {
880 operator bool()
const {
891 operator const char8*()
const {
917 virtual ~ElementFn() { }
918 virtual void operator()(
AP_Type &)
const =0;
922 virtual void visitSequenceElementsImpl(
const ElementFn &,
size_t start,
size_t length)
const =0;
926 template <
typename FN>
927 class Wrap :
public ElementFn {
929 explicit Wrap(
const FN &fn) : fn(fn) {}
930 void operator()(
AP_Type &arg)
const { fn(arg); }
949 : ptr(reinterpret_cast<const char *>(static_cast<const
AP_Type *>(array))),
955 size_t size()
const {
return n; }
962 return *
reinterpret_cast<const AP_Type *
>(ptr + i*stride);
1113 #endif // CORRELATOR_PLUGIN_HPP
virtual void pluginNowBlocking() const =0
Called by the plugin when it performs a potentially blocking operation.
virtual const char8 ** stringSequenceElements(size_t start=0, size_t length=size_t(-1)) const =0
Generate an array of string pointers encapsulating elements [start..start+length-1] of the sequence o...
Execution context for a library function call.
Definition: correlator_plugin.hpp:178
AP_UnimplementedException(const std::string &what)
Construct an AP_UnimplementedException from a message.
Definition: correlator_plugin.hpp:111
AP_PLUGIN_DLL_SYM AP_ErrorCode(AP_PLUGIN_CALL *AP_ThreadEndedFunctionPtr)(const AP_Context &ctx)
Type of a plugin library thread ended function.
Definition: correlator_plugin.hpp:1111
size_t nParams
Argument count.
Definition: correlator_plugin.hpp:1003
virtual size_t sequenceLength() const =0
Get the number of elements in a sequence object.
Type-safe encapsulation of a MonitorScript object, for passing arguments and return values into and o...
Definition: correlator_plugin.hpp:623
const char8 * returnType
Return type.
Definition: correlator_plugin.hpp:1009
void subscribe(const AP_EventHandlerInterface::ptr_t &handler, std::initializer_list< const char * > channels)
Subscribe an event handler to a list of channels.
Definition: correlator_plugin.hpp:394
virtual bool * booleanSequenceElements(size_t start=0, size_t length=size_t(-1)) const =0
Generate an array of booleans encapsulating elements [start..start+length-1] of the sequence object...
std::shared_ptr< AP_EventHandlerInterface > ptr_t
A smart-pointer type for managing lifetime of event handlers.
Definition: correlator_plugin.hpp:288
virtual void pluginNowBlocking() const =0
Called by the plugin when it performs a potentially blocking operation.
void unsubscribe(const AP_EventHandlerInterface::ptr_t &handler, const T &channel)
Unsubscribe an event handler from a channel.
Definition: correlator_plugin.hpp:514
virtual AP_Chunk *const * chunkSequenceElements(size_t start=0, size_t length=size_t(-1)) const =0
Generate an array of pointers to chunks encapsulating elements [start..start+length-1] of the sequenc...
AP_FunctionPtr fptr
Pointer to function implementation.
Definition: correlator_plugin.hpp:1000
AP_Capabilities
Plugin capabilities.
Definition: AP_PluginCommon.h:74
AP_PLUGIN_DLL_SYM AP_ErrorCode(AP_PLUGIN_CALL * AP_InitFunctionPtr)(const AP_Context &ctx, uint32 &version, uint32 &nFunctions, AP_Function *&functions)
Type of a plugin library initialisation function.
Definition: correlator_plugin.hpp:1038
virtual ~AP_Context()
Destructor.
Definition: correlator_plugin.hpp:182
virtual AP_uint64 getContextId() const =0
Return the identifier of the EPL (parallelism) context associated with this plugin execution context...
virtual AP_Type & sequenceElement(size_t index) const =0
Get a reference to a single sequence element.
AP_Type & operator=(AP_Chunk *val)
Operator to assign chunk value to object.
Definition: correlator_plugin.hpp:852
virtual bool booleanValue() const =0
Get the boolean value of the object.
virtual void sendEvent(const char *event)=0
Send an event to the correlator.
Thrown by plugin authors to signal an error to any EPL calling this plugin.
Definition: correlator_plugin.hpp:132
virtual void releaseFloatSequenceElements() const =0
Free the resources allocated by all preceding calls to floatSequenceElements() and ensures that any c...
virtual AP_TypeDiscriminator sequenceType() const =0
Get the element type of a sequence object.
virtual void releaseBooleanSequenceElements() const =0
Free the resources allocated by all preceding calls to booleanSequenceElements() and ensures that any...
AP_Chunk()
Default constructor declared because there's a non-default one, which is deprecated.
Definition: correlator_plugin.hpp:607
virtual void setSequenceLength(size_t length) const =0
Set the length of a sequence object.
const AP_Type & operator[](size_t i) const
Return a reference to an element of the list.
Definition: correlator_plugin.hpp:961
virtual void releaseIntegerSequenceElements() const =0
Free the resources allocated by all preceding calls to integerSequenceElements() and ensures that any...
virtual void copyFrom(const AP_Type &other)=0
Copy another AP_Type into this, regardless of type.
void(AP_PLUGIN_CALL * AP_FunctionPtr)(const AP_Context &ctx, const AP_TypeList &args, AP_Type &rval, AP_TypeDiscriminator rtype)
Type of a plugin function.
Definition: correlator_plugin.hpp:983
AP_TypeDiscriminator
A typed discriminator for the contents of an AP_Type object.
Definition: AP_PluginCommon.h:47
virtual ~AP_EventHandlerInterface()
Ensure we have a virtual destructor, so that derived class destructors can be correctly called...
Definition: correlator_plugin.hpp:293
Shared definitions for the C and C++ plugin APIs.
virtual ~AP_CorrelatorInterface()=0
Destructor.
virtual void releaseStringSequenceElements() const =0
Free the resources allocated by all preceding calls to stringSequenceElements() and copies any change...
virtual int64 * integerSequenceElements(size_t start=0, size_t length=size_t(-1)) const =0
Generate an array of integers encapsulating elements [start..start+length-1] of the sequence object...
AP_Type & operator[](size_t index) const
Operator to get sequence element of object.
Definition: correlator_plugin.hpp:902
AP_BoundsException(const std::string &what)
Construct an AP_BoundsException from a message.
Definition: correlator_plugin.hpp:123
An interface class that should be implemented by event handlers which are registered via AP_Correlato...
Definition: correlator_plugin.hpp:278
AP_PLUGIN_DLL_SYM AP_ErrorCode(AP_PLUGIN_CALL * AP_ShutdownFunctionPtr)(const AP_Context &ctx)
Type of a plugin library shutdown function.
Definition: correlator_plugin.hpp:1054
Type error.
Definition: correlator_plugin.hpp:94
virtual char8 * char8dup(const char8 *s) const =0
Duplicate a string value created using char8alloc().
AP_Type & operator=(const AP_Type &other)
Copy assignment operator from another AP_Type.
Definition: correlator_plugin.hpp:907
AP_TypeException(const std::string &what)
Construct an AP_TypeException from a message.
Definition: correlator_plugin.hpp:98
Thrown by an attempt to use a function that is defined but not implemented in this version of the API...
Definition: correlator_plugin.hpp:107
Asynchronous interface to the correlator.
Definition: correlator_plugin.hpp:311
void visitSequenceElements(const FN &fn, size_t start=0, size_t length=size_t(-1)) const
Visit the specified elements of a sequence using the specified functor.
Definition: correlator_plugin.hpp:719
virtual char8 * char8alloc(size_t len) const =0
Allocate storage for an 8-bit string value.
virtual void sendEventTo(const char *event, AP_uint64 targetContext, AP_uint64 sourceContext)=0
Send an event to a specific context in the correlator.
virtual AP_CorrelatorInterface * getCorrelator() const =0
Return the correlator implementation.
virtual void releaseSequenceElements() const =0
Free the resources allocated by all preceding calls to sequenceElements() and ensures that any change...
Container class for an ordered list of AP_Type objects, typically used to hold the argument list for ...
Definition: correlator_plugin.hpp:942
void subscribe(const AP_EventHandlerInterface::ptr_t &handler, const T &channel)
Subscribe an event handler to a list of channels.
Definition: correlator_plugin.hpp:448
void subscribe(const AP_EventHandlerInterface::ptr_t &handler, const ITER &start, const ITER &end)
Subscribe an event handler to a list of channels.
Definition: correlator_plugin.hpp:427
virtual AP_Type *const * sequenceElements(size_t start=0, size_t length=size_t(-1)) const =0
Generate an array of pointers to AP_Type objects, encapsulating elements [start..start+length-1] of t...
bool empty() const
Return true iff size() == 0.
Definition: correlator_plugin.hpp:958
virtual void releaseChunkSequenceElements() const =0
Free the resources allocated by all preceding calls to chunkSequenceElements().
AP_UserPluginException(const std::string &type, const std::string &what)
Construct an AP_UserPluginException from a type and a message.
Definition: correlator_plugin.hpp:142
virtual float64 floatValue() const =0
Get the float value of the object.
Base class for all 'chunk' classes.
Definition: correlator_plugin.hpp:566
virtual AP_Chunk * chunkValue() const =0
Get the chunk value of the object.
Boundary checking error.
Definition: correlator_plugin.hpp:119
const std::string & getType() const
Return the type of this user exception.
Definition: correlator_plugin.hpp:147
const char8 ** paramTypes
Argument types.
Definition: correlator_plugin.hpp:1006
virtual int64 integerValue() const =0
Get the integer value of the object.
AP_PLUGIN_DLL_SYM AP_ErrorCode(AP_PLUGIN_CALL * AP_LibraryVersionFunctionPtr)(const AP_Context &ctx, uint32 &version)
Type of a plugin library version function.
Definition: correlator_plugin.hpp:1075
void unsubscribe(const AP_EventHandlerInterface::ptr_t &handler, std::initializer_list< const char * > channels)
Unsubscribe an event handler from a list of channels.
Definition: correlator_plugin.hpp:466
Plugin function descriptor.
Definition: correlator_plugin.hpp:994
virtual AP_TypeDiscriminator discriminator() const =0
Get the type of the encapsulated object.
AP_PLUGIN_DLL_SYM AP_Capabilities(AP_PLUGIN_CALL * AP_GetCapabilitiesFunctionPtr)(const AP_Context &ctx)
Type of a plugin capability function.
Definition: correlator_plugin.hpp:1093
Base class of all exceptions thrown across the correlator/plugin boundary.
Definition: correlator_plugin.hpp:82
virtual void createSequence(AP_TypeDiscriminator inner)=0
Take an uninitialised sequence object and create an empty sequence with the indicated member type...
virtual ~AP_Type()=0
Destructor.
size_t size() const
Return the number of objects in the list.
Definition: correlator_plugin.hpp:955
AP_ENGINE_CLIENT_API void char8free(char *string)
Free any char* string returned from the client API.
AP_PluginException(const std::string &what)
Construct an AP_PluginException from a message.
Definition: correlator_plugin.hpp:86
const char8 * name
Function name.
Definition: correlator_plugin.hpp:997
virtual float64 * floatSequenceElements(size_t start=0, size_t length=size_t(-1)) const =0
Generate an array of floats encapsulating elements [start..start+length-1] of the sequence object...
AP_Chunk(const AP_Context &)
Obsolete constructor retained for backward compatability.
Definition: correlator_plugin.hpp:601
virtual void char8free(char8 *s) const =0
Free the memory occupied by a string created using char8alloc() or char8dup().
AP_TypeList(const T *array, size_t n)
Construct a list from an array of classes derived from AP_Type.
Definition: correlator_plugin.hpp:948
virtual uint32 version() const =0
Return active plugin API version.
virtual ~AP_Chunk()
Pure virtual destructor.
Definition: correlator_plugin.hpp:583
void unsubscribe(const AP_EventHandlerInterface::ptr_t &handler, const ITER &start, const ITER &end)
Unsubscribe an event handler from a list of channels.
Definition: correlator_plugin.hpp:497
virtual const char8 * stringValue() const =0
Get the string value of the object.
virtual void handleEvent(const AP_Context &ctx, const char *event, const char *channel)=0
Called for each event sent to a channel to which this event handler is subscribed.