Migrating the C and C++ EPL plug-ins written in 9.12 or earlier
To migrate an existing EPL plug-in that has been written in C or C++ and has been created with version 9.12 or earlier, you will need to follow the steps below. The two APIs are quite different, but you will find the implementation overall simpler and easier to manage.
1. Include epl_plugin.hpp instead of correlator_plugin.hpp.
#include <epl_plugin.hpp>
2. Import the com::apama::epl namespace.
using namespace com::apama::epl;
3. Define a class which inherits from EPLPlugin. This will hold all the methods which are exported to EPL. Previously, these could have been free functions or static member functions. Now they are non-static member functions.
class MyPlugin: public EPLPlugin<MyPlugin>
4. Add a zero-argument constructor.
MyPlugin(): base_plugin_t("MyPlugin") {}
5. Change all your exported methods to be members of your class and change the void(const AP_Contex &, const AP_TypeList &, AP_Type &, AP_TypeDiscriminator) signature to be the actual C++ types that your method will take and return. You will no longer need to unpack the typelist argument or explicitly set the return value, you can just read the arguments and return directly.
void myMethod(int64_t arg1)
{
data.push_back(arg1);
}
bool anotherMethod(double arg1, double arg2)
{
return arg1 < arg2;
}
6. Change use of functions on the AP_Context argument to functions to use the getCorrelator() static method instead.
getCorrelator().sendEvent("MyEvent(42)");
7. Replace the AP_Function array, type signatures and version declaration from the AP_INIT_FUNCTION_NAME free function with an initialize() static function on your class.
static void initialize(base_plugin_t::method_data_t &md)
{
md.registerMethod<decltype(&MyPlugin::myMethod),
&MyPlugin::myMethod>("myMethod");
md.registerMethod<decltype(&MyPlugin::anotherMethod),
&MyPlugin::anotherMethod>("anotherMethod");
}
8. Other code from AP_INIT_FUNCTION_NAME goes in your constructor.
9. Code from AP_SHUTDOWN_FUNCTION_NAME goes in your destructor.
~MyPlugin()
{
...
}
10. Remove AP_LIBRARY_VERSION_FUNCTION_NAME.
11. Add a call to APAMA_DECLARE_EPL_PLUGIN for your class.
APAMA_DECLARE_EPL_PLUGIN(MyPlugin)
12. If you use chunks, you no longer need to inherit from a particular class, just declare methods which return custom_t<T>, where T is the type you want to store in EPL.
struct MyChunkType
{
int64_t datum;
};
custom_t<MyChunkType> createChunk(int64_t datum)
{
return custom_t<MyChunkType>(new MyChunkType{datum});
}
int64_t getChunkValue(const custom_t<MyChunkType> &chunk)
{
return chunk->datum;
}