problem using get_default_library()

6 posts / 0 new
Last post
nads.uiowa.edu's picture
Offline
Last seen: 2 years 2 months ago
Joined: 05/18/2021
Posts: 3
problem using get_default_library()

Hi all,

I'm trying to verify default libraries and profiles in DDS 6.0.1. I started working with the c++\hello_idl example in VS2017.

I added an else clause to hello.cxx to print out the default library like this:

 

participant = DDSDomainParticipantFactory::get_instance()->create_participant( arg.domainId, DDS_PARTICIPANT_QOS_DEFAULT, NULL, /* Listener */ DDS_STATUS_MASK_NONE); if (participant == NULL) {

std::cerr << "! Unable to create DDS domain participant" << std::endl;

goto exitFn;

else {

std::string deflib(participant->get_default_library());

std::cout << "Default library is: " << deflib << std::endl;

}

but it crashes with the following output:

Creating domain participant...
RTI Connext DDS Research License issued to University of Iowa (UIOWA04-UP) ... For non-production use only.
Expires on 07-oct-2021 See www.rti.com for more information.
Backtrace:
#1 RTICdrStream_initializeDesBufferPointersFromSampleInNonPrimitiveSeq [0x7F6F9543]
#2 UnhandledExceptionFilter [0xC5DB5E0]
#3 memset [0xED33DC0]
#4 _C_specific_handler [0xED1C6E0]
#5 _chkstk [0xED31F60]
#6 RtlRaiseException [0xECE1020]
#7 KiUserExceptionDispatcher [0xED30B80]
#8 strlen [0xA80AFC80]
#9 std::char_traits<char>::length at c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.15.26726\include\iosfwd:466 [0xE91AC3E0]
#10 std::basic_string<char,std::char_traits<char>,std::allocator<char> >::assign at c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.15.26726\include\xstring:2676 [0xE91ABB90]
#11 std::basic_string<char,std::char_traits<char>,std::allocator<char> >::basic_string<char,std::char_traits<char>,std::allocator<char> > at c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.15.26726\include\xstring:2185 [0xE91A88E0]
#12 startApplication at c:\users\cschwarz\documents\rti_workspace\6.0.1\examples\connext_dds\c++\hello_idl\src\hello.cxx:231 [0xE91A48B0]
#13 main at c:\users\cschwarz\documents\rti_workspace\6.0.1\examples\connext_dds\c++\hello_idl\src\hello.cxx:546 [0xE91A5240]
#14 invoke_main at f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:79 [0xE91C58C0]
#15 __scrt_common_main_seh at f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:288 [0xE91C56B0]
#16 __scrt_common_main at f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:331 [0xE91C5690]
#17 mainCRTStartup at f:\dd\vctools\crt\vcstartup\src\startup\exe_main.cpp:17 [0xE91C5980]
#18 BaseThreadInitThunk [0xD5C7020]
#19 RtlUserThreadStart [0xECE2630]

Any ideas on why this happens or how to properly use this informational function (same applies to get_default_profile() and get_default_profile_library()).

 

 

 

 

Organization:
Keywords:
Howard's picture
Offline
Last seen: 4 days 12 hours ago
Joined: 11/29/2012
Posts: 618


So, unless you set a default QOS Profile library name, there is none set by default...and will return NULL.

virtual const char* DDSDomainParticipant::get_default_library( ) 

<<extension>> Gets the default XML library associated with a DDSDomainParticipant.

Returns
The default library or null if the default library was not set.
See Also
DDSDomainParticipant::set_default_library
  
nads.uiowa.edu's picture
Offline
Last seen: 2 years 2 months ago
Joined: 05/18/2021
Posts: 3

Thank you, yes I set it using the NDDS_QOS_PROFILES environment variable.

I tried moving away the default xml file and then the program errors out earlier - either because of that NULL or because it's trying to follow the environment variable but unable to find it. Anyway, it confirms that I have specified a default XML library.

Chris

Howard's picture
Offline
Last seen: 4 days 12 hours ago
Joined: 11/29/2012
Posts: 618

No, NDDS_QOS_PROFILES environment variable just specifies where to load the XML file.  It doesn't set a QOS Library...which isn't a file, but a named tag defined in XML using

<qos_library name="aLibraryName">

If you want to set a default QOS Library, then you have to use participant->set_default_library("aLibraryName");

That doesn't tell Connext DDS what XML file to load.  The XML file is NOT a QOS Library...but will contain 1 or more definitions of QOS libraries.  So, whatever XML files that have been loaded, they would need to define a qos library with the name passed to "set_default_library()"

In addition, setting a default library does not direct Connext DDS to use it the library for anything by itself.  You will also have to set a default QOS Profile using

participant->set_default_profile("aProfileName");

But unless you're actually trying to set a default profile/library for which to create DDS Entities, you don't need to do this to compile/run a helloworld app.

I tried moving away the default xml file and then the program errors out earlier - either because of that NULL or because it's trying to follow the environment variable but unable to find it.

I'm not sure what you mean exactly, "moving away".  Are you saying you don't want to use the default XML file?

Connext DDS doesn't require you to use QOS profiles, nor have QOS profiles defined in XML files loaded at runtime...although it's best practice to do both.

By default, if the file "USER_QOS_PROFILES.xml" exists in the current working directory when the first participant is created, it'll be automatically loaded.  If not, it's not.  But it NOT an error, UNLESS your code is creating DDS entities that require a profile that's been defined in the .xml file.

If your code is using QOS profiles (which are defined in named QOS libraries), then Connext DDS must already have loaded that definition (usually from an XML file) before it creates the first participant.

Again, not finding a file, even if it's one defined in NDDS_QOS_PROFILES will not necessarily produce any errors.  It's not until you try to use a QOS Profile that hasn't been defined (loaded), that you'll see an error due to that issue.

 

 

nads.uiowa.edu's picture
Offline
Last seen: 2 years 2 months ago
Joined: 05/18/2021
Posts: 3

Ah OK,

I think I understand better. The function doesn't do what I thought it did. I didn't realize the default library had to be set before it could be read.

I am having difficulty keeping the rules of loading QoS profiles from XML files straight and so I thought using this function would be an easy way to provide confirmation of which library has been loaded. Not quite I guess. I do understand that profiles and libraries are not the same thing as the XML file.

All right, thank you. I'm 1% smarter today than I was yesterday. :)

Chris

Howard's picture
Offline
Last seen: 4 days 12 hours ago
Joined: 11/29/2012
Posts: 618

Good to hear that you were able to decipher my ramblings... 

Just wanna make sure the right vocabulary is used to describe what happens since different words convey different ideas of how things work.

I didn't realize the default library had to be set before it could be read.

So, I wouldn't use the word "read" unless referring to loading a file or parsing a string.  After an XML file/string is loaded/read, the QOS Libraries and Profiles defined therein are "instantiated" or "defined" and then can be "used" to create DDS Entities.

"I thought using this function would be an easy way to provide confirmation of which library has been loaded"

So, there may be multiple QOS Libraries defined, both builtin libraries as well as multiple user defined libraries.  You can use the DDSDomainParticipantFactory::get_qos_profile_libraries() API to get a list of all of the Libraries that are currently defined in the Factory:

    DDSTheParticipantFactory->get_qos_profile_libraries(libraries);

    for (int i = 0; i < libraries.length(); ++i) {
        printf("library[%d] = %s\n", i, libraries[i]);
    }

 

DDSDomainParticipant/DDSDomainParticipantFactory::get_default_library() is supposed to return the name of the library that has been configured to be default by the user.

This could be done in the XML file using the "is_default_qos" attribute. 

HOWEVER,

1) this is not a best practice.  Not recommended.  Actually, using default QOS profiles is NOT a best practice.  If you are defining QOS profiles, then they should be used directly with create_xxx_with_profile() APIs

2) there is bug in Connext 6.0.1 (and earlier) in which while "is_default_qos="true"" works to set the default QOS Profile, get_default_library() is returning NULL, unless set_default_library() is used.    That's bug since what's supposed to happen is that if the default qos profile is set in XML, then get_default_library() is supposed to return the library in which the default QOS profile is defined.

That bug is fixed in Connext 6.1.0.