Skip to content

Commit

Permalink
TheParticipantFactory* is NULL for Missing Config
Browse files Browse the repository at this point in the history
Right now it issues a warning and uses the default configuration. With
this it logs an error and returns `NULL`.

Also corrected other logging to match guidelines.
  • Loading branch information
iguessthislldo committed Nov 28, 2023
1 parent e22eac1 commit 5b67db9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
44 changes: 23 additions & 21 deletions dds/DCPS/Service_Participant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,10 @@ Service_Participant::get_domain_participant_factory(int &argc,
}

if (config_fname.empty()) {
if (DCPS_debug_level) {
ACE_DEBUG((LM_NOTICE,
ACE_TEXT("(%P|%t) NOTICE: not using file configuration - no configuration ")
ACE_TEXT("file specified.\n")));
if (log_level >= LogLevel::Info) {
ACE_DEBUG((LM_INFO,
"(%P|%t) INFO: Service_Participant::get_domain_participant_factory: "
"no configuration file specified.\n"));
}

} else {
Expand All @@ -420,31 +420,33 @@ Service_Participant::get_domain_participant_factory(int &argc,
config_fname = new_path;
}

// Load configuration only if the configuration
// file exists.
FILE* in = ACE_OS::fopen(config_fname.c_str(),
ACE_TEXT("r"));

// Load configuration only if the configuration file exists.
FILE* const in = ACE_OS::fopen(config_fname.c_str(), ACE_TEXT("r"));
if (!in) {
ACE_DEBUG((LM_WARNING,
ACE_TEXT("(%P|%t) WARNING: not using file configuration - ")
ACE_TEXT("can not open \"%s\" for reading. %p\n"),
config_fname.c_str(), ACE_TEXT("fopen")));
if (log_level >= LogLevel::Error) {
ACE_ERROR((LM_ERROR,
"(%P|%t) ERROR: Service_Participant::get_domain_participant_factory: "
"could not find config file \"%s\": %p\n",
config_fname.c_str(), ACE_TEXT("fopen")));
}
return DDS::DomainParticipantFactory::_nil();

} else {
ACE_OS::fclose(in);

if (DCPS_debug_level > 1) {
ACE_DEBUG((LM_NOTICE,
ACE_TEXT("(%P|%t) NOTICE: Service_Participant::get_domain_participant_factory ")
ACE_TEXT("Going to load configuration from <%s>\n"),
config_fname.c_str()));
if (log_level >= LogLevel::Info) {
ACE_DEBUG((LM_INFO,
"(%P|%t) INFO: Service_Participant::get_domain_participant_factory: "
"Going to load configuration from <%s>\n",
config_fname.c_str()));
}

if (this->load_configuration(config_fname) != 0) {
ACE_ERROR((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: Service_Participant::get_domain_participant_factory: ")
ACE_TEXT("load_configuration() failed.\n")));
if (log_level >= LogLevel::Error) {
ACE_ERROR((LM_ERROR,
"(%P|%t) ERROR: Service_Participant::get_domain_participant_factory: "
"load_configuration() failed.\n"));
}
return DDS::DomainParticipantFactory::_nil();
}
}
Expand Down
5 changes: 5 additions & 0 deletions docs/news.d/partfactnull.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.. news-prs: 4372
.. news-start-section: Notes
- ``TheParticipantFactory*`` will now return a null pointer when ``DCPSConfigFile`` doesn't exist.
.. news-end-section

0 comments on commit 5b67db9

Please sign in to comment.