mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-11 23:33:33 +08:00
Minor API cleanup in GDTR: regist() --> registerDataType()
This commit is contained in:
@@ -70,12 +70,12 @@ public:
|
||||
/**
|
||||
* Result of data type registration
|
||||
*/
|
||||
enum RegistResult
|
||||
enum RegistrationResult
|
||||
{
|
||||
RegistResultOk, ///< Success, data type is now registered and can be used.
|
||||
RegistResultCollision, ///< Data type name or ID is not unique.
|
||||
RegistResultInvalidParams, ///< Invalid input parameters.
|
||||
RegistResultFrozen ///< Data Type Registery has been frozen and can't be modified anymore.
|
||||
RegistrationResultOk, ///< Success, data type is now registered and can be used.
|
||||
RegistrationResultCollision, ///< Data type name or ID is not unique.
|
||||
RegistrationResultInvalidParams, ///< Invalid input parameters.
|
||||
RegistrationResultFrozen ///< Data Type Registery has been frozen and can't be modified anymore.
|
||||
};
|
||||
|
||||
private:
|
||||
@@ -88,8 +88,8 @@ private:
|
||||
|
||||
List* selectList(DataTypeKind kind) const;
|
||||
|
||||
RegistResult remove(Entry* dtd);
|
||||
RegistResult registImpl(Entry* dtd);
|
||||
RegistrationResult remove(Entry* dtd);
|
||||
RegistrationResult registImpl(Entry* dtd);
|
||||
|
||||
public:
|
||||
/**
|
||||
@@ -108,7 +108,7 @@ public:
|
||||
* @param id Data Type ID for this data type.
|
||||
*/
|
||||
template <typename Type>
|
||||
RegistResult regist(DataTypeID id);
|
||||
RegistrationResult registerDataType(DataTypeID id);
|
||||
|
||||
/**
|
||||
* Data Type registry needs to be frozen before a node instance can use it in
|
||||
@@ -205,10 +205,10 @@ struct UAVCAN_EXPORT DefaultDataTypeRegistrator
|
||||
{
|
||||
DefaultDataTypeRegistrator()
|
||||
{
|
||||
const GlobalDataTypeRegistry::RegistResult res =
|
||||
GlobalDataTypeRegistry::instance().regist<Type>(Type::DefaultDataTypeID);
|
||||
const GlobalDataTypeRegistry::RegistrationResult res =
|
||||
GlobalDataTypeRegistry::instance().registerDataType<Type>(Type::DefaultDataTypeID);
|
||||
|
||||
if (res != GlobalDataTypeRegistry::RegistResultOk)
|
||||
if (res != GlobalDataTypeRegistry::RegistrationResultOk)
|
||||
{
|
||||
handleFatalError("Type reg failed");
|
||||
}
|
||||
@@ -221,24 +221,24 @@ struct UAVCAN_EXPORT DefaultDataTypeRegistrator
|
||||
* GlobalDataTypeRegistry
|
||||
*/
|
||||
template <typename Type>
|
||||
GlobalDataTypeRegistry::RegistResult GlobalDataTypeRegistry::regist(DataTypeID id)
|
||||
GlobalDataTypeRegistry::RegistrationResult GlobalDataTypeRegistry::registerDataType(DataTypeID id)
|
||||
{
|
||||
if (isFrozen())
|
||||
{
|
||||
return RegistResultFrozen;
|
||||
return RegistrationResultFrozen;
|
||||
}
|
||||
static Entry entry;
|
||||
{
|
||||
const RegistResult remove_res = remove(&entry);
|
||||
if (remove_res != RegistResultOk)
|
||||
const RegistrationResult remove_res = remove(&entry);
|
||||
if (remove_res != RegistrationResultOk)
|
||||
{
|
||||
return remove_res;
|
||||
}
|
||||
}
|
||||
entry = Entry(DataTypeKind(Type::DataTypeKind), id, Type::getDataTypeSignature(), Type::getDataTypeFullName());
|
||||
{
|
||||
const RegistResult remove_res = remove(&entry);
|
||||
if (remove_res != RegistResultOk)
|
||||
const RegistrationResult remove_res = remove(&entry);
|
||||
if (remove_res != RegistrationResultOk)
|
||||
{
|
||||
return remove_res;
|
||||
}
|
||||
|
||||
@@ -27,22 +27,22 @@ GlobalDataTypeRegistry::List* GlobalDataTypeRegistry::selectList(DataTypeKind ki
|
||||
}
|
||||
}
|
||||
|
||||
GlobalDataTypeRegistry::RegistResult GlobalDataTypeRegistry::remove(Entry* dtd)
|
||||
GlobalDataTypeRegistry::RegistrationResult GlobalDataTypeRegistry::remove(Entry* dtd)
|
||||
{
|
||||
if (!dtd)
|
||||
{
|
||||
UAVCAN_ASSERT(0);
|
||||
return RegistResultInvalidParams;
|
||||
return RegistrationResultInvalidParams;
|
||||
}
|
||||
if (isFrozen())
|
||||
{
|
||||
return RegistResultFrozen;
|
||||
return RegistrationResultFrozen;
|
||||
}
|
||||
|
||||
List* list = selectList(dtd->descriptor.getKind());
|
||||
if (!list)
|
||||
{
|
||||
return RegistResultInvalidParams;
|
||||
return RegistrationResultInvalidParams;
|
||||
}
|
||||
|
||||
list->remove(dtd); // If this call came from regist<>(), that would be enough
|
||||
@@ -56,25 +56,25 @@ GlobalDataTypeRegistry::RegistResult GlobalDataTypeRegistry::remove(Entry* dtd)
|
||||
}
|
||||
p = next;
|
||||
}
|
||||
return RegistResultOk;
|
||||
return RegistrationResultOk;
|
||||
}
|
||||
|
||||
GlobalDataTypeRegistry::RegistResult GlobalDataTypeRegistry::registImpl(Entry* dtd)
|
||||
GlobalDataTypeRegistry::RegistrationResult GlobalDataTypeRegistry::registImpl(Entry* dtd)
|
||||
{
|
||||
if (!dtd || (dtd->descriptor.getID() > DataTypeID::Max))
|
||||
{
|
||||
UAVCAN_ASSERT(0);
|
||||
return RegistResultInvalidParams;
|
||||
return RegistrationResultInvalidParams;
|
||||
}
|
||||
if (isFrozen())
|
||||
{
|
||||
return RegistResultFrozen;
|
||||
return RegistrationResultFrozen;
|
||||
}
|
||||
|
||||
List* list = selectList(dtd->descriptor.getKind());
|
||||
if (!list)
|
||||
{
|
||||
return RegistResultInvalidParams;
|
||||
return RegistrationResultInvalidParams;
|
||||
}
|
||||
|
||||
{ // Collision check
|
||||
@@ -83,12 +83,12 @@ GlobalDataTypeRegistry::RegistResult GlobalDataTypeRegistry::registImpl(Entry* d
|
||||
{
|
||||
if (p->descriptor.getID() == dtd->descriptor.getID()) // ID collision
|
||||
{
|
||||
return RegistResultCollision;
|
||||
return RegistrationResultCollision;
|
||||
}
|
||||
if (!std::strncmp(p->descriptor.getFullName(), dtd->descriptor.getFullName(),
|
||||
DataTypeDescriptor::MaxFullNameLen)) // Name collision
|
||||
{
|
||||
return RegistResultCollision;
|
||||
return RegistrationResultCollision;
|
||||
}
|
||||
p = p->getNextListNode();
|
||||
}
|
||||
@@ -122,7 +122,7 @@ GlobalDataTypeRegistry::RegistResult GlobalDataTypeRegistry::registImpl(Entry* d
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return RegistResultOk;
|
||||
return RegistrationResultOk;
|
||||
}
|
||||
|
||||
GlobalDataTypeRegistry& GlobalDataTypeRegistry::instance()
|
||||
|
||||
@@ -95,8 +95,9 @@ TEST(GlobalDataTypeRegistry, Basic)
|
||||
/*
|
||||
* Runtime registrations
|
||||
*/
|
||||
ASSERT_EQ(GlobalDataTypeRegistry::RegistResultOk,
|
||||
GlobalDataTypeRegistry::instance().regist<DataTypeAService>(DataTypeAService::DefaultDataTypeID));
|
||||
ASSERT_EQ(GlobalDataTypeRegistry::RegistrationResultOk,
|
||||
GlobalDataTypeRegistry::instance().registerDataType<DataTypeAService>(
|
||||
DataTypeAService::DefaultDataTypeID));
|
||||
|
||||
ASSERT_EQ(2, GlobalDataTypeRegistry::instance().getNumMessageTypes());
|
||||
ASSERT_EQ(1, GlobalDataTypeRegistry::instance().getNumServiceTypes());
|
||||
@@ -109,8 +110,10 @@ TEST(GlobalDataTypeRegistry, Basic)
|
||||
/*
|
||||
* Runtime re-registration
|
||||
*/
|
||||
ASSERT_EQ(GlobalDataTypeRegistry::RegistResultOk, GlobalDataTypeRegistry::instance().regist<DataTypeAService>(147));
|
||||
ASSERT_EQ(GlobalDataTypeRegistry::RegistResultOk, GlobalDataTypeRegistry::instance().regist<DataTypeB>(741));
|
||||
ASSERT_EQ(GlobalDataTypeRegistry::RegistrationResultOk,
|
||||
GlobalDataTypeRegistry::instance().registerDataType<DataTypeAService>(147));
|
||||
ASSERT_EQ(GlobalDataTypeRegistry::RegistrationResultOk,
|
||||
GlobalDataTypeRegistry::instance().registerDataType<DataTypeB>(741));
|
||||
|
||||
ASSERT_EQ(2, GlobalDataTypeRegistry::instance().getNumMessageTypes());
|
||||
ASSERT_EQ(1, GlobalDataTypeRegistry::instance().getNumServiceTypes());
|
||||
@@ -129,11 +132,11 @@ TEST(GlobalDataTypeRegistry, Basic)
|
||||
/*
|
||||
* These types will be necessary for the aggregate signature test
|
||||
*/
|
||||
ASSERT_EQ(GlobalDataTypeRegistry::RegistResultCollision,
|
||||
GlobalDataTypeRegistry::instance().regist<DataTypeC>(741)); // ID COLLISION
|
||||
ASSERT_EQ(GlobalDataTypeRegistry::RegistrationResultCollision,
|
||||
GlobalDataTypeRegistry::instance().registerDataType<DataTypeC>(741)); // ID COLLISION
|
||||
|
||||
ASSERT_EQ(GlobalDataTypeRegistry::RegistResultOk,
|
||||
GlobalDataTypeRegistry::instance().regist<DataTypeC>(DataTypeC::DefaultDataTypeID));
|
||||
ASSERT_EQ(GlobalDataTypeRegistry::RegistrationResultOk,
|
||||
GlobalDataTypeRegistry::instance().registerDataType<DataTypeC>(DataTypeC::DefaultDataTypeID));
|
||||
uavcan::DefaultDataTypeRegistrator<DataTypeD> reg_DataTypeD;
|
||||
|
||||
GlobalDataTypeRegistry::instance().getDataTypeIDMask(uavcan::DataTypeKindMessage, dtmask);
|
||||
@@ -154,14 +157,14 @@ TEST(GlobalDataTypeRegistry, Basic)
|
||||
*/
|
||||
GlobalDataTypeRegistry::instance().freeze();
|
||||
|
||||
ASSERT_EQ(GlobalDataTypeRegistry::RegistResultFrozen,
|
||||
GlobalDataTypeRegistry::instance().regist<DataTypeAService>(555)); // Rejected
|
||||
ASSERT_EQ(GlobalDataTypeRegistry::RegistrationResultFrozen,
|
||||
GlobalDataTypeRegistry::instance().registerDataType<DataTypeAService>(555)); // Rejected
|
||||
|
||||
ASSERT_EQ(GlobalDataTypeRegistry::RegistResultFrozen,
|
||||
GlobalDataTypeRegistry::instance().regist<DataTypeAMessage>(999)); // Rejected
|
||||
ASSERT_EQ(GlobalDataTypeRegistry::RegistrationResultFrozen,
|
||||
GlobalDataTypeRegistry::instance().registerDataType<DataTypeAMessage>(999)); // Rejected
|
||||
|
||||
ASSERT_EQ(GlobalDataTypeRegistry::RegistResultFrozen,
|
||||
GlobalDataTypeRegistry::instance().regist<DataTypeB>(888)); // Rejected
|
||||
ASSERT_EQ(GlobalDataTypeRegistry::RegistrationResultFrozen,
|
||||
GlobalDataTypeRegistry::instance().registerDataType<DataTypeB>(888)); // Rejected
|
||||
|
||||
/*
|
||||
* Searching
|
||||
|
||||
Reference in New Issue
Block a user