GDTR collision checks, ordered storage

This commit is contained in:
Pavel Kirienko
2014-02-28 11:59:54 +04:00
parent c4add96a81
commit e4f6866524
3 changed files with 39 additions and 1 deletions
@@ -30,6 +30,17 @@ class GlobalDataTypeRegistry : Noncopyable
{ }
};
struct EntryInsertionComparator
{
const uint16_t id;
EntryInsertionComparator(Entry* dtd) : id(dtd->decriptor.getID()) { }
bool operator()(const Entry* entry) const
{
assert(entry);
return entry->decriptor.getID() > id;
}
};
typedef LinkedListRoot<Entry> List;
List msgs_;
List srvs_;
+27 -1
View File
@@ -63,7 +63,33 @@ bool GlobalDataTypeRegistry::add(Entry* dtd)
if (!list)
return false;
list->insert(dtd);
{ // Collision check
Entry* p = list->get();
while (p)
{
if (p->decriptor.getID() == dtd->decriptor.getID()) // ID collision
return false;
p = p->getNextListNode();
}
}
list->insertBefore(dtd, EntryInsertionComparator(dtd));
#if UAVCAN_DEBUG
{ // Order check
Entry* p = list->get();
int id = -1;
while (p)
{
if (id >= p->decriptor.getID())
{
assert(0);
std::abort();
}
id = p->decriptor.getID();
p = p->getNextListNode();
}
}
#endif
return true;
}
@@ -127,6 +127,7 @@ TEST(GlobalDataTypeRegistry, Basic)
/*
* These types will be necessary for the aggregate signature test
*/
ASSERT_FALSE(GlobalDataTypeRegistry::instance().assign<DataTypeC>(741)); // COLLISION - error
ASSERT_TRUE(GlobalDataTypeRegistry::instance().assign<DataTypeC>(DataTypeC::DefaultDataTypeID));
uavcan::DefaultDataTypeRegistrator<DataTypeD> reg_DataTypeD;