summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormsmit <msmit@remedy.nl>2011-06-15 13:39:08 +0000
committermsmit <msmit@remedy.nl>2011-06-15 13:39:08 +0000
commit03190b3599332fac6fcd47c0d054f1eedec53814 (patch)
treeb24343ec8ae632c8b199e8cc7b1f7442c48c64e9
parent13352a6702c717a0e2f65f097dd6e3aa70ddc9a6 (diff)
downloadATCD-03190b3599332fac6fcd47c0d054f1eedec53814.tar.gz
Wed Jun 15 13:38:57 UTC 2011 Marcel Smit <msmit@remedy.nl>
* connectors/dds4ccm/impl/ndds/TypeSupport.h: * connectors/dds4ccm/impl/ndds/TypeSupport.cpp: Optimized management of DomainParticipants and type-factory combinations.
-rw-r--r--CIAO/ChangeLog6
-rw-r--r--CIAO/connectors/dds4ccm/impl/ndds/TypeSupport.cpp138
-rw-r--r--CIAO/connectors/dds4ccm/impl/ndds/TypeSupport.h59
3 files changed, 148 insertions, 55 deletions
diff --git a/CIAO/ChangeLog b/CIAO/ChangeLog
index 243b6053acd..8b62dda5ab6 100644
--- a/CIAO/ChangeLog
+++ b/CIAO/ChangeLog
@@ -1,3 +1,9 @@
+Wed Jun 15 13:38:57 UTC 2011 Marcel Smit <msmit@remedy.nl>
+
+ * connectors/dds4ccm/impl/ndds/TypeSupport.h:
+ * connectors/dds4ccm/impl/ndds/TypeSupport.cpp:
+ Optimized management of DomainParticipants and type-factory combinations.
+
Wed Jun 15 07:30:00 UTC 2011 Marcel Smit <msmit@remedy.nl>
* connectors/dds4ccm/tests/MemLeakDetection/TypeRegistration/Base/TypeRegistration_Test_Base.idl:
diff --git a/CIAO/connectors/dds4ccm/impl/ndds/TypeSupport.cpp b/CIAO/connectors/dds4ccm/impl/ndds/TypeSupport.cpp
index fadda6bdb71..ad4468de9aa 100644
--- a/CIAO/connectors/dds4ccm/impl/ndds/TypeSupport.cpp
+++ b/CIAO/connectors/dds4ccm/impl/ndds/TypeSupport.cpp
@@ -14,78 +14,116 @@ namespace CIAO
}
DDS_TypeFactory_i*
- DDS_TypeSupport_i::get_factory (const char* type,
- ::DDS::DomainParticipant_ptr dp)
+ DDS_TypeSupport_i::get_factory_i (const char* type,
+ ::DDS::DomainParticipant_ptr dp)
{
- DDS4CCM_TRACE ("DDS_TypeSupport_i::get_factory");
+ DDS4CCM_TRACE ("DDS_TypeSupport_i::get_factory_i");
participantfactories::iterator entry = participant_factories.find(dp);
if (entry != participant_factories.end())
{
+ if (entry->second.size () == 0UL)
+ {
+ DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO
+ "DDS_TypeSupport_i::get_factory_i - "
+ "No type-factory combinations for DomainParticipant <%@> found\n",
+ dp));
+ return 0;
+ }
+
DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO
- "DDS_TypeSupport_i::get_factory - "
+ "DDS_TypeSupport_i::get_factory_i - "
"A factory of type <%C> and with DomainParticipant <%@> "
- "is registred\n",
+ "is registered\n",
type,
dp));
- if (entry->second.size () == 0)
- return 0;
// Return factory belonging to the specified type.
- return entry->second[type];
+ typefactories tf = entry->second;
+ typefactories::iterator it = tf.find(type);
+ if (it != tf.end())
+ return it->second;
+ else
+ return 0;
}
DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO
- "DDS_TypeSupport_i::get_factory - "
+ "DDS_TypeSupport_i::get_factory_i - "
"A factory of type <%C> and with DomainParticipant <%@> "
- "was not registred\n",
+ "is not registered\n",
type,
dp));
return 0;
}
bool
- DDS_TypeSupport_i::set_factory (const char* type,
- DDS_TypeFactory_i* f,
- ::DDS::DomainParticipant_ptr dp)
+ DDS_TypeSupport_i::register_factory_i (const char* type,
+ DDS_TypeFactory_i* f,
+ ::DDS::DomainParticipant_ptr dp)
{
- DDS4CCM_TRACE ("DDS_TypeSupport_i::set_factory");
+ DDS4CCM_TRACE ("DDS_TypeSupport_i::register_factory_i");
participantfactories::iterator dp_entry = participant_factories.find(dp);
+
if (dp_entry == participant_factories.end())
{ // entry not found -> insert.
- // first create a new type factory for this dp.
+ // Add the DomainParticipant.
typefactories tf;
- std::pair <typefactories::iterator, bool> tf_ret =
- tf.insert(typefactories::value_type (type, f));
- if (tf_ret.second == false)
+ std::pair <participantfactories::iterator, bool> dp_ret = participant_factories.insert(
+ std::pair< ::DDS::DomainParticipant_ptr, typefactories > (dp, tf));
+ if (dp_ret.second == false)
{
DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
- "DDS_TypeSupport_i::set_factory - "
- "Unable to create new Type factory for type <%C>\n",
- type));
+ "DDS_TypeSupport_i::register_factory_i - "
+ "Unable to create new DomainParticipant entry: "
+ "type <%C> - DomainParticipant <%@>\n",
+ type,
+ dp));
return false;
}
+ }
- std::pair <participantfactories::iterator, bool> dp_ret =
- participant_factories.insert(
- std::pair< ::DDS::DomainParticipant_ptr, typefactories > (dp, tf));
- if (dp_ret.second == false)
+ // DomainParticipant has been added
+ dp_entry = participant_factories.find(dp);
+ typefactories tf = dp_entry->second;
+ // tf contains the list of type-factory combinations.
+ // search for the given type
+ typefactories::iterator tf_entry = tf.find(type);
+ if (tf_entry == tf.end())
+ { // Factory not registered for specified type.
+ // Register it
+ std::pair <typefactories::iterator, bool> tf_ret =
+ tf.insert(typefactories::value_type (type, f));
+ if (tf_ret.second == false)
{
DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
- "DDS_TypeSupport_i::set_factory - "
- "Unable to create new DomainParticipant entry type <%C>\n",
+ "DDS_TypeSupport_i::register_factory_i - "
+ "Unable to create new factory entry type <%C>\n",
type));
return false;
}
+ DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO
+ "DDS_TypeSupport_i::register_factory_i - "
+ "Created new factory entry for type <%C>\n",
+ type));
+ // necessary to assign the type-factory combination to the correct
+ // DomainParticipant entry.
+ dp_entry->second = tf;
+ return true;
}
- return true;
+ // Unable to register type-factory combination since it already exists.
+ DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
+ "DDS_TypeSupport_i::register_factory_i - "
+ "Unable to register type-factory combination since "
+ "it already exists for type <%C>\n",
+ type));
+ return false;
}
void
- DDS_TypeSupport_i::remove_participant_factory(const char * type,
- ::DDS::DomainParticipant_ptr dp)
+ DDS_TypeSupport_i::unregister_participant_factory_i (const char * type,
+ ::DDS::DomainParticipant_ptr dp)
{
- DDS4CCM_TRACE ("DDS_TypeSupport_i::remove_participant_factory");
+ DDS4CCM_TRACE ("DDS_TypeSupport_i::unregister_participant_factory_i");
participantfactories::iterator dp_entry = participant_factories.find(dp);
@@ -97,30 +135,34 @@ namespace CIAO
if (it != tf.end())
{
it->second = 0;
+ tf.erase(it);
+
+ if (tf.size () == 0UL)
+ { // no more entries -> remove the participant from
+ // the list
+ participant_factories.erase(dp_entry);
+
+ DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO
+ "DDS_TypeSupport_i::unregister_participant_factory_i - "
+ "Erased entry for participant <%@>\n",
+ dp,
+ type));
+ }
}
else
{
DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
- "DDS_TypeSupport_i::remove_participant_factory - "
+ "DDS_TypeSupport_i::unregister_participant_factory_i - "
"Could not find the correct factory belonging to participant <%@> "
"and type <%C>. Unable to remove.\n",
dp,
type));
}
-
- // erase the participant from the map
- participant_factories.erase(dp_entry);
-
- DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO
- "DDS_TypeSupport_i::remove_participant_factory - "
- "Erased entry for participant <%@>\n",
- dp,
- type));
}
else
{
DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
- "DDS_TypeSupport_i::remove_participant_factory - "
+ "DDS_TypeSupport_i::unregister_participant_factory_i - "
"Could not find the correct factory belonging to participant <%@>. "
"Unable to remove.\n",
dp));
@@ -134,7 +176,7 @@ namespace CIAO
{
DDS4CCM_TRACE ("DDS_TypeSupport_i::register_type");
- if (get_factory (type, dp))
+ if (get_factory_i (type, dp))
{
DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_INFO, DDS4CCM_INFO
"DDS_TypeSupport_i::register_type - "
@@ -147,7 +189,7 @@ namespace CIAO
"Registered factory for type %C and participant <%@>\n",
type, dp));
- return set_factory (type, f, dp);
+ return register_factory_i (type, f, dp);
}
DDS_TypeFactory_i*
@@ -155,8 +197,8 @@ namespace CIAO
{
DDS4CCM_TRACE ("DDS_TypeSupport_i::unregister_type");
- DDS_TypeFactory_i * f = get_factory(type, dp);
- remove_participant_factory (type, dp);
+ DDS_TypeFactory_i * f = get_factory_i(type, dp);
+ unregister_participant_factory_i(type, dp);
DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_INFO, DDS4CCM_INFO
"DDS_TypeSupport_i::unregister_type - "
@@ -174,7 +216,7 @@ namespace CIAO
const char* type = dw->get_topic ()->get_type_name();
- DDS_TypeFactory_i *f = get_factory (type, dp);
+ DDS_TypeFactory_i *f = get_factory_i(type, dp);
if (f)
{
DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_INFO, DDS4CCM_INFO
@@ -199,7 +241,7 @@ namespace CIAO
DDS4CCM_TRACE ("DDS_TypeSupport_i::create_datareader");
const char* type = dr->get_topicdescription ()->get_type_name();
- DDS_TypeFactory_i *f = get_factory (type, dp);
+ DDS_TypeFactory_i *f = get_factory_i(type, dp);
if (f)
{
DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_INFO, DDS4CCM_INFO
diff --git a/CIAO/connectors/dds4ccm/impl/ndds/TypeSupport.h b/CIAO/connectors/dds4ccm/impl/ndds/TypeSupport.h
index 77ede894669..598b76c3b27 100644
--- a/CIAO/connectors/dds4ccm/impl/ndds/TypeSupport.h
+++ b/CIAO/connectors/dds4ccm/impl/ndds/TypeSupport.h
@@ -65,14 +65,42 @@ namespace CIAO
class DDS4CCM_NDDS_Export DDS_TypeSupport_i
{
public:
+ /**
+ * @name close
+ * Clears all internal maps, freeing the memory.
+ */
static void close (void);
+
+ /**
+ * @name register_tye
+ * Registering a type-factory combination per DomainParticipant.
+ * Returns false if insertions to one of the maps fails or if there's
+ * already a factory for the given type registered.
+ * Returns true if insertions succeeds.
+ */
static bool register_type (const char* type, DDS_TypeFactory_i* factory,
::DDS::DomainParticipant_ptr dp);
+
+ /**
+ * @name unregister_tye
+ * Unregistering a type-factory combination for a specific
+ * DomainParticipant. If the combination cannot be found,
+ * this method returns nil.
+ */
static DDS_TypeFactory_i * unregister_type (const char* type,
::DDS::DomainParticipant_ptr dp);
+
+ /**
+ * @name create_datawriter
+ * Create a type specific datawriter
+ */
static ::DDS::DataWriter_ptr create_datawriter (DDSDataWriter* dw,
::DDS::DomainParticipant_ptr dp,
::DDS::Publisher_ptr pub);
+ /**
+ * @name create_datawriter
+ * Create a type specific datareader
+ */
static ::DDS::DataReader_ptr create_datareader (DDSDataReader* dr,
::DDS::DomainParticipant_ptr dp,
::DDS::Subscriber_ptr sub);
@@ -85,15 +113,32 @@ namespace CIAO
typedef std::map< ::DDS::DomainParticipant_ptr, typefactories > participantfactories;
static participantfactories participant_factories;
- static DDS_TypeFactory_i* get_factory (const char* type,
- ::DDS::DomainParticipant_ptr dp);
+ /**
+ * @name get_factory_i
+ * Searches for a TypeFactory, based on a type and DomainParticipant
+ */
+ static DDS_TypeFactory_i* get_factory_i (const char* type,
+ ::DDS::DomainParticipant_ptr dp);
- static bool set_factory (const char* type,
- DDS_TypeFactory_i* f,
- ::DDS::DomainParticipant_ptr dp);
+ /**
+ * @name register_factory_i
+ * Insert a new type-factory combination per DomainParticipant and type.
+ * Returns true if no factory for the given type was registered.
+ * Returns false if insertions to the internal lists fail.
+ */
+ static bool register_factory_i (const char* type,
+ DDS_TypeFactory_i* f,
+ ::DDS::DomainParticipant_ptr dp);
- static void remove_participant_factory (const char * type,
- ::DDS::DomainParticipant_ptr dp);
+ /**
+ * @name unregister_participant_factory_i
+ * Erasing the registered type-factory combination per DomainParticipant.
+ * If the latest type-factory combination is removed, the DomainParticipant
+ * will also be removed from the internal lists.
+ * This method does not free any memory!
+ */
+ static void unregister_participant_factory_i (const char * type,
+ ::DDS::DomainParticipant_ptr dp);
};
}