dfranusic/pmink

Enable plugin based fgn extensions

dfranusic opened this issue · 1 comments

  • create pluggable interface for easier implementation of custom user functions (callable from fgn's advanced matching mode)
  • plugins are more suitable for funtions that depend on custom daemons and operate asynchronously(e.g. RRP based real-time rating module), or when low level system functions are needed for implementation of custom logic

An example of a simple fgn plugin:

pm_plg_fgn_example.h
// header guard
#ifndef PM_FGN_MODULE_EXAMPLE_H
#define PM_FGN_MODULE_EXAMPLE_H

// fgn plugin macros
#include <pm_fgn_plugins.h>

// module name (pm_plg_fgn_example)
#define PM_FGN_MODULE pm_plg_fgn_example

// declare module init method
PM_FGN_MODULE_INIT_DECLARE(PM_FGN_MODULE)

// declare "pm_plg_fgn_example.example_test" method
PM_FGN_MODULE_METHOD_DECLARE(example_test)

#endif //PM_FGN_MODULE_EXAMPLE_H
pm_plg_fgn_example.cpp
// pm_plg_fgn_example plugin header
#include "pm_plg_fgn_example.h"

// define module init (start)
PM_FGN_MODULE_INIT_DEFINE(
    // module name
    PM_FGN_MODULE,
    // add method "example_test" to module "example"
    PM_FGN_MODULE_ADD_METHOD(example_test)
)

// define example.example_test method
PM_FGN_MODULE_METHOD_DEFINE(example_test){
    // get fgn payload (pointer to fgn::FgnPayload)
    PM_FGN_PLD_GET(pld);
    // get GT called address
    char* GT = pld->params.get_cstr(PT::_pt_sccp_called_pa_gt_address);
    // if GT address == 123456, return true
    if(GT && strcmp(GT, "123456") == 0) PM_FGN_MODULE_RET_BOOL(1);
    // default return (false)
    PM_FGN_MODULE_RET_BOOL(0);
}
example.lua
-- pmink module
local F = require('pmink')(...)
-- example plugin
local P = require('pm_plg_fgn_example')(...)
-- call test method
return P.example_test()