im developing ctrl extension with c++ and currently im registering callback functions from ctrl script via extension and it works fine. Also calling startFunc straight away after function extension event i can call pre-defined function from ctrl script.
But i need to call that callback function outside of that extension event. How to do that ? This is what i have tried so far:
notes: m_param is defined as array which holds param from callback registration event
Basically the concept is correct.
The main question is just: what triggers the callback ?
For your current code:
You can not store the ExecuteParamRec since the thread pointer will at some point be invalid (when the thread stops) and in fact you don't need the thread
pointer as you are going to create a new one. You just need the CtrlScript pointer.
Also, m_param[TopicCount] = &rc; stores a pointer to a local variable, so the pointer is already invalid when the function is left.
Same here: return &result;
You MUST use a static IntegerVar here.
Also, don't use string class. Simply stick to the WinCC_OA CharString class which you already use here (which is also member of TextVar).
And your "args" pointer is still invalid.
Thank you for reply, m_param is on top of class file so it should be public ! Sorry for that.
I got ActiveMQ topic listener which calls this function when there is new message on topic - that works until its time to call callback function from Ctrl script.
How i introduce public array of ( i assume i need pointer for each callback function.. ) CtrlScript pointers right way ?
And thank you for pointing details for correct coding style.. im not super familiar with c++
So I assume you're already having a class derived from CtrlModule which implements the listener, right ?
If so, this class has already the CtrlScript pointer, so no need to store this again.
If not, check out this posting: https://portal.etm.at/index.php?option= ... =1040#1042
Then what you need to store is really just a CharString which holds the callback functions name.
recently I have implemented a simple driver for Apache Kafka, that's why I am curious in using ActiveMQ... and why you prefer to implement a Ctrl-Extension instead of using an API Manager or Driver... http://www.rocworks.at/wordpress/?p=764
So I assume you're already having a class derived from CtrlModule which implements the listener, right ?
If so, this class has already the CtrlScript pointer, so no need to store this again.
If not, check out this posting: https://portal.etm.at/index.php?option= ... =1040#1042
Then what you need to store is really just a CharString which holds the callback functions name.
Currently all code is in template class as this is first version of concept and that default class doesnt have CtrlModule. I checked the TCP example but it doesnt seems to work after i tried to do similiar.
I dont get it why i cannot store CtrlScript pointer and just use it when i want to call user defined function from OA, this is what i would like to do :
// this is "public" var
CtrlScript *m_script;
// imaginary "main" where this function is called
void main()
{
funcCall("Calculate");
}
const Variable *ExternHdl::execute(ExecuteParamRec ¶m)
{
enum
{
F_init = 0,
};
switch (param.funcNum)
{
case F_init :
{
m_script = param.thread->getScript();
// if here i call func it works but not after script is stored and used later
// RecVar vars;
// m_script->startFunc("nameofcuntion", &vars);
}
}
}
void ExternHdl::funcCall(const CharString &functionName)
{
RecVar vars;
m_script->startFunc(functionName, &vars);
OR
CtrlFunc *func = Controller::thisPtr->findFunc(functionName, m_script);
m_script->startThread(thread, func, &vars);
}
"does not work" is usually not enough to describe a problem.
Please be more specific. What does not work ? Does it crash ? Does it show an error ?
Is this a script you run in a CTRL manager or the UI manager ?
You can store the CtrlScript pointer if you KNOW that it is still valid when you need it.
But keep in mind that the UI manager starts a lot of scripts and that these scripts are also stopped (deleted) e.g. when the panel is closed.