segmentation fault when subscribing to events

Hi,

i wrote a Device Server that subscribe to events with many device attributes and different data types… I implements only one callback method which is triggered when the events are received (push model).
I have an segmentation fault when receiving an event with data type different from the subscription one…
The problem comes from the allocation of the array in the cb.

i simply tried with tangotest and i have the same error ;(

extract of example subscribe event (data type of the attribute is DevDouble):


try
{
the_device = new Tango::DeviceProxy("sys/tg_test/1");
if (the_device->state() == Tango::FAULT)
{
set_state(Tango::FAULT);
}
else
{

cb = new DoubleEventCallBack();
if (cb!=NULL)
event_id=the_device->subscribe_event("long_scalar_w",Tango::CHANGE_EVENT,cb);
}
}
catch(Tango::DevFailed &e)
{
set_state(Tango::FAULT);
}




extract of the callback (array declaration in DevLong):


void DoubleEventCallBack::push_event(Tango::EventData *myevent)
{

Tango::DevVarLongArray *double_value;

try
{
if(!myevent->err)
{
*(myevent->attr_value) >> double_value;
delete double_value;
}
}
catch(int e)
{
cout << "DoubleEventCallBack::push_event(): could not extract data!\n";
}
}



Is it the good way to do this when i have to subsribe to events on dynamic attributes unknown in advance ?
Thanks for help

Hi,

In your callback,
myevent->attr_value->data_type
gives you the type of the received event data (int corresponding to the index of the type in enum CmdArgType type declared in tango_const.h include file).

You can then adapt your code depending on the received type.
Rosenberg's Law: Software is easy to make, except when you want it to do something new.
Corollary: The only software that's worth making is software that does something new.
Edited 2 months ago
By the way, you should catch Tango::DevFailed exceptions (not int exceptions) in your callback when you try to extract the data.
Rosenberg's Law: Software is easy to make, except when you want it to do something new.
Corollary: The only software that's worth making is software that does something new.


JCM
thanks,
so i adapt my code depending on the received type :)

but still many problems:

1) impossible to compile with the type in enum CmdArgType type declared in tango_const.h include file.
not understood, so put the value smile

2) myevent->attr_value->data_type returns always the same value equal to 2 !
not understood, so passed the data_type at the callback call smile

3) as i have only one callback for all events, i protected with a mutex. However the events are blocked or slowed
down after a while ;( but that's another story … smile

extract of the push_event() method :)


try
{
if(!myevent->err)
{
eventLock.lock();

switch(type)
{
case 2:
Tango::DevVarShortArray *short_value;
*(myevent->attr_value) >> short_value;
delete short_value;
break;
case 6
Tango::DevVarUShortArray *ushort_value;
*(myevent->attr_value) >> ushort_value;
delete ushort_value;
break;
case 3:
Tango::DevVarLongArray *long_value;
*(myevent->attr_value) >> long_value;
delete long_value;
break;
case 7:
Tango::DevVarULongArray *ulong_value;
*(myevent->attr_value) >> ulong_value;
delete ulong_value;
break;
case 4:
Tango::DevVarFloatArray *float_value;
*(myevent->attr_value) >> float_value;
delete float_value;
break;
case 5:
Tango::DevVarDoubleArray *double_value;
*(myevent->attr_value) >> double_value;
delete double_value;
break;
}

eventLock.unlock();
}
}
catch(Tango::DevFailed &e)
{
cout << "DoubleEventCallBack::push_event(): could not extract data\n" << endl;
Tango::Except::print_exception(e);
}


JCM
thanks,
so i adapt my code depending on the received type :)

but still many problems:

1) impossible to compile with the type in enum CmdArgType type declared in tango_const.h include file.
not understood, so put the value smile

Did you prefix it with the namespace Tango?
e.g.: Tango::DEV_SHORT ?

JCM
2) myevent->attr_value->data_type returns always the same value equal to 2 !
not understood, so passed the data_type at the callback call smile

The data type is transmitted on the network only since Tango 9 (IDL 5).
Are you subscribing to Tango 8 devices?
Maybe what you are observing is a consequence of the fix of https://github.com/tango-controls/cppTango/issues/248 ?
Rosenberg's Law: Software is easy to make, except when you want it to do something new.
Corollary: The only software that's worth making is software that does something new.
Late answer smile


Reynald
1) impossible to compile with the type in enum CmdArgType type declared in tango_const.h include file.
not understood, so put the value smile



Did you prefix it with the namespace Tango?
e.g.: Tango::DEV_SHORT ?

Not effectively. I'm going to try.



Reynald
2) myevent->attr_value->data_type returns always the same value equal to 2 !
not understood, so passed the data_type at the callback call smile


The data type is transmitted on the network only since Tango 9 (IDL 5).
Are you subscribing to Tango 8 devices?
Maybe what you are observing is a consequence of the fix of https://github.com/tango-controls/cppTango/issues/248 ?

All Tango 9 devices.



Thanks again.






 
Register or login to create to post a reply.