Support Request #11618
closedReceiving name of current filter instance
Description
Supportanfrage
I was trying to get the instance name of a filter using the recommend way in
https://support.digitalwerk.net/issues/11254
but unfortunately it did not work. The macro is not resolved. And I get the literal string "$(THIS_OBJECT_NAME)".
I tried this in the constructor and in Init() StageGraphReady.
Any suggestion? complete example how this works?
ADTF version is: 3.6.3 (still not the latest)
Lösung
Getting full Session name (path):
tResult cMyFilter::Init(tInitStage eStage)
{
RETURN_IF_FAILED(cFilter::Init(eStage)); // Note: Always call the ::Init from your base class (e.g. cQtUIFilter) at the beginning, this case cFilter
if (eStage == StageGraphReady)
{
auto strNameUsingGlobalFunction = get_named_graph_object_full_name(*this);
LOG_INFO("Instance name: %s", strNameUsingGlobalFunction.GetPtr());
}
RETURN_NOERROR;
}
Receiving a short instance name:
Use INamedGraphObject::GetName(...)
member function of your filter
Alternate way (but public):
RegisterPropertyVariable("name_property", m_strName);
and set "$(THIS_OBJECT_NAME"
for cString property variable m_strName
Related issues
Updated by hidden almost 4 years ago
- Related to Support Request #11254: Basic API questions about Sample Stream, Runner and getting the instance name added
Updated by hidden almost 4 years ago
- Project changed from Public Support to 11
- Status changed from New to In Progress
- Topic set to ADTF::Common
- Customer set to AUDI
- Department set to EF
Updated by hidden almost 4 years ago
- Status changed from In Progress to Customer Feedback Required
Hi Samer,
have a look here:
tResult cMyFilter::Init(tInitStage eStage)
{
RETURN_IF_FAILED(cFilter::Init(eStage)); // Note: Always call the ::Init from your base class (e.g. cQtUIFilter) at the beginning, this case cFilter
if (eStage == StageGraphReady)
{
auto strNameUsingGlobalFunction = get_named_graph_object_full_name(*this);
LOG_INFO("Instance name: %s", strNameUsingGlobalFunction.GetPtr());
}
RETURN_NOERROR;
}
Updated by hidden almost 4 years ago
Hi Samer,
I think you missed registering the property_variable in your constructor:
RegisterPropertyVariable("name_property", m_strName);
Only then will it be resolved during initialization.
Regards,
Martin
Updated by hidden almost 4 years ago
Hi Florian&Martin,
thanks for the answer! both variants work now.
However, I see a disadvantage in each of them.
- with get_named_graph_object_full_name(*this) I get a very long name, which is not helpful for debug messages
- with the property_variable, I expose a property which can be seen/changed by the user
I would prefer a way, where I get the name of the short-object internally.
For the current time, these ways suffice. The ticket can be closed!
Best Regards,
Samer
Updated by hidden almost 4 years ago
Hi Samer,
- with get_named_graph_object_full_name(*this) I get a very long name, which is not helpful for debug messages
then just use the INamedGraphObject::GetName(...) member function of your filter :-)
- with the property_variable, I expose a property which can be seen/changed by the user
Yes, these macros are actually intended to be used by the user creating a session (by using them in property values) and not for your use-case in the first place.
Regards,
Martin
Updated by hidden almost 4 years ago
- Status changed from Customer Feedback Required to To Be Closed
- Resolution set to Solved Issue
- Platform Other Linux 64bit added
Updated by hidden almost 4 years ago
- Project changed from 11 to Public Support
- Subject changed from Failed to Get Filter Name with $(THIS_OBJECT_NAME) to Receiving name of current filter instance
- Description updated (diff)
- Private changed from Yes to No