Skip to content

Commit e5a5000

Browse files
committed
Add some needed methods to channel and event structures
1 parent 226bfab commit e5a5000

5 files changed

Lines changed: 95 additions & 10 deletions

File tree

Source/Processors/Channel/InfoObjects.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ unsigned int NodeInfoBase::getCurrentNodeID() const
3939
return m_nodeID;
4040
}
4141

42+
String NodeInfoBase::getCurrentNodeType() const
43+
{
44+
return m_currentNodeType;
45+
}
46+
47+
String NodeInfoBase::getCurrentNodeName() const
48+
{
49+
return m_currentNodeName;
50+
}
51+
4252
//History Object
4353
String HistoryObject::getHistoricString()
4454
{
@@ -58,7 +68,8 @@ SourceProcessorInfo::SourceProcessorInfo(const GenericProcessor* source, uint16
5868
: m_sourceNodeID(source->getNodeId()),
5969
m_sourceSubNodeIndex(subproc),
6070
m_sourceType(source->getName()),
61-
m_sourceName(source->getName()) //TODO: fix those two when we have the ability to rename processors
71+
m_sourceName(source->getName()), //TODO: fix those two when we have the ability to rename processors
72+
m_sourceSubProcessorCount(source->getNumSubProcessors())
6273
{
6374
}
6475

@@ -82,6 +93,11 @@ String SourceProcessorInfo::getSourceName() const
8293
return m_sourceName;
8394
}
8495

96+
uint16 SourceProcessorInfo::getSourceSubprocessorCount() const
97+
{
98+
return m_sourceSubProcessorCount;
99+
}
100+
85101
//NamedInfoObject
86102
void NamedInfoObject::setName(String name)
87103
{
@@ -98,7 +114,7 @@ void NamedInfoObject::setIdentifier(String identifier)
98114
m_identifier = identifier;
99115
}
100116

101-
String NamedInfoObject::getDescriptor() const
117+
String NamedInfoObject::getIdentifier() const
102118
{
103119
return m_identifier;
104120
}

Source/Processors/Channel/InfoObjects.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,16 @@ class PLUGIN_API NodeInfoBase
4949
public:
5050
/** Gets the ID of the processor which currently owns this copy of the info object */
5151
unsigned int getCurrentNodeID() const;
52+
/** Gets the type of the processor which currently owns this copy of the info object */
53+
String getCurrentNodeType() const;
54+
/** Gets the name of the processor which currently owns this copy of the info object */
55+
String getCurrentNodeName() const;
5256
protected:
5357
NodeInfoBase() = delete;
5458
NodeInfoBase(uint16 id);
5559
uint16 m_nodeID{ 0 };
60+
String m_currentNodeType;
61+
String m_currentNodeName;
5662
};
5763

5864
/** This class allows creating a string with an historic of all the data a node has gone through */
@@ -89,13 +95,17 @@ class PLUGIN_API SourceProcessorInfo
8995
/** Gets the name of the processor which created this object */
9096
String getSourceName() const;
9197

98+
/** Gets the number of subprocessors the source processor has.
99+
Useful to determine if a processor has multiple subprocessors and label things accordingly*/
100+
uint16 getSourceSubprocessorCount() const;
101+
92102
private:
93103
SourceProcessorInfo() = delete;
94104
const uint16 m_sourceNodeID;
95105
const uint16 m_sourceSubNodeIndex;
96106
const String m_sourceType;
97107
const String m_sourceName;
98-
108+
const uint16 m_sourceSubProcessorCount;
99109
};
100110

101111
class PLUGIN_API NamedInfoObject
@@ -116,7 +126,7 @@ class PLUGIN_API NamedInfoObject
116126
/** Sets a machine-readable data identifier (eg.: sourcedata.continuous ) */
117127
void setIdentifier(String identifier);
118128

119-
String getDescriptor() const;
129+
String getIdentifier() const;
120130
protected:
121131
NamedInfoObject();
122132
virtual void setDefaultNameAndDescription() = 0;

Source/Processors/Channel/MetaData.cpp

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ size_t MetaDataValue::getDataSize() const
162162

163163
void MetaDataValue::allocSpace()
164164
{
165-
m_data.malloc(m_size);
165+
m_data.calloc(m_size);
166166
}
167167

168168
MetaDataValue::MetaDataValue(const MetaDataValue& v)
@@ -239,6 +239,19 @@ void MetaDataValue::getValue(T* data) const
239239
memcpy(data, m_data.getData(), m_size);
240240
}
241241

242+
//Using this version of the method in normal processor operation is not recommended
243+
//However it is useful for format-agnostic processes.
244+
template<>
245+
void MetaDataValue::getValue<void>(void* data) const
246+
{
247+
memcpy(data, m_data.getData(), m_size);
248+
}
249+
250+
const void* MetaDataValue::getRawValuePointer() const
251+
{
252+
return m_data.getData();
253+
}
254+
242255
template <typename T>
243256
void MetaDataValue::setValue(const Array<T>& data)
244257
{
@@ -331,7 +344,10 @@ void MetaDataEventObject::addEventMetaData(MetaDataDescriptor* desc)
331344
return;
332345
}
333346
m_eventMetaDataDescriptorArray.add(desc);
334-
m_totalSize += desc->getDataSize();
347+
size_t size = desc->getDataSize();
348+
m_totalSize += size;
349+
if (m_maxSize < size)
350+
m_maxSize = size;
335351
}
336352

337353
void MetaDataEventObject::addEventMetaData(const MetaDataDescriptor& desc)
@@ -343,7 +359,10 @@ void MetaDataEventObject::addEventMetaData(const MetaDataDescriptor& desc)
343359
return;
344360
}
345361
m_eventMetaDataDescriptorArray.add(new MetaDataDescriptor(desc));
346-
m_totalSize += desc.getDataSize();
362+
size_t size = desc.getDataSize();
363+
m_totalSize += size;
364+
if (m_maxSize < size)
365+
m_maxSize = size;
347366
}
348367

349368
size_t MetaDataEventObject::getTotalEventMetaDataSize() const
@@ -356,7 +375,7 @@ const MetaDataDescriptor* MetaDataEventObject::getEventMetaDataDescriptor(int in
356375
return m_eventMetaDataDescriptorArray[index];
357376
}
358377

359-
const int MetaDataEventObject::getEventMetaDataCount() const
378+
int MetaDataEventObject::getEventMetaDataCount() const
360379
{
361380
return m_eventMetaDataDescriptorArray.size();
362381
}
@@ -373,14 +392,29 @@ int MetaDataEventObject::findEventMetaData(MetaDataDescriptor::MetaDataTypes typ
373392
return -1;
374393
}
375394

395+
size_t MetaDataEventObject::getMaxEventMetaDataSize() const
396+
{
397+
return m_maxSize;
398+
}
399+
376400
//MetaDataEvent
377401
MetaDataEvent::MetaDataEvent() {}
378402

403+
int MetaDataEvent::getMetadataValueCount() const
404+
{
405+
return m_metaDataValues.size();
406+
}
407+
408+
const MetaDataValue* MetaDataEvent::getMetaDataValue(int index) const
409+
{
410+
return m_metaDataValues[index];
411+
}
412+
379413
void MetaDataEvent::serializeMetaData(void* dstBuffer) const
380414
{
381415
int metaDataSize = m_metaDataValues.size();
382416
char* buffer = static_cast<char*>(dstBuffer);
383-
int ptrIndex = 0;
417+
size_t ptrIndex = 0;
384418

385419
for (int i = 0; i < metaDataSize; i++)
386420
{
@@ -489,6 +523,8 @@ template PLUGIN_API void MetaDataValue::getValue<uint64>(Array<uint64>&) const;
489523
template PLUGIN_API void MetaDataValue::getValue<float>(Array<float>&) const;
490524
template PLUGIN_API void MetaDataValue::getValue<double>(Array<double>&) const;
491525

526+
template PLUGIN_API void MetaDataValue::getValue<void>(void*) const;
527+
492528
//Helper function to compare identifier strings
493529
bool compareIdentifierStrings(const String& identifier, const String& compareWith)
494530
{

Source/Processors/Channel/MetaData.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ class PLUGIN_API MetaDataValue
149149
template <typename T>
150150
void getValue(Array<T>& data) const;
151151

152+
/** It is generally not advised to use this method, which can, however, be of use in performance critical modules.
153+
It is usually preferable to use the strongly typed copy getter methods, when speed is not an issue.
154+
Keep in mind that any pointer returned by this will become invalid after the block execution.*/
155+
const void* getRawValuePointer() const;
156+
152157
private:
153158
MetaDataValue() = delete;
154159
void setValue(const void* data);
@@ -205,16 +210,22 @@ class PLUGIN_API MetaDataEventObject : public MetaDataEventLock
205210
const MetaDataDescriptor* getEventMetaDataDescriptor(int index) const;
206211
int findEventMetaData(MetaDataDescriptor::MetaDataTypes type, unsigned int length, String identifier = String::empty) const;
207212
size_t getTotalEventMetaDataSize() const;
208-
const int getEventMetaDataCount() const;
213+
int getEventMetaDataCount() const;
214+
//gets the largest metadata size, which can be useful to reserve buffers in advance
215+
size_t getMaxEventMetaDataSize() const;
209216
protected:
210217
MetaDataDescriptorArray m_eventMetaDataDescriptorArray;
211218
MetaDataEventObject();
212219
size_t m_totalSize{ 0 };
220+
size_t m_maxSize{ 0 };
213221
};
214222

215223
//And the base from which event objects can hold their metadata before serializing
216224
class PLUGIN_API MetaDataEvent
217225
{
226+
public:
227+
int getMetadataValueCount() const;
228+
const MetaDataValue* getMetaDataValue(int index) const;
218229
protected:
219230
void serializeMetaData(void* dstBuffer) const;
220231
bool deserializeMetaData(const MetaDataEventObject* info, const void* srcBuffer, int size);

Source/Processors/GenericProcessor/GenericProcessor.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,23 +409,35 @@ void GenericProcessor::updateChannelIndexes(bool updateNodeID)
409409
{
410410
DataChannel* channel = dataChannelArray[i];
411411
if (updateNodeID)
412+
{
412413
channel->m_nodeID = nodeId;
414+
channel->m_currentNodeName = getName();
415+
channel->m_currentNodeType = getName(); //Fix when the ability to name individual processors is implemented
416+
}
413417
uint32 sourceID = getProcessorFullId(channel->getSourceNodeID(), channel->getSubProcessorIdx());
414418
dataChannelMap[sourceID][channel->getSourceIndex()] = i;
415419
}
416420
for (int i = 0; i < eventChannelArray.size(); i++)
417421
{
418422
EventChannel* channel = eventChannelArray[i];
419423
if (updateNodeID)
424+
{
420425
channel->m_nodeID = nodeId;
426+
channel->m_currentNodeName = getName();
427+
channel->m_currentNodeType = getName(); //Fix when the ability to name individual processors is implemented
428+
}
421429
uint32 sourceID = getProcessorFullId(channel->getSourceNodeID(), channel->getSubProcessorIdx());
422430
eventChannelMap[sourceID][channel->getSourceIndex()] = i;
423431
}
424432
for (int i = 0; i < spikeChannelArray.size(); i++)
425433
{
426434
SpikeChannel* channel = spikeChannelArray[i];
427435
if (updateNodeID)
436+
{
428437
channel->m_nodeID = nodeId;
438+
channel->m_currentNodeName = getName();
439+
channel->m_currentNodeType = getName(); //Fix when the ability to name individual processors is implemented
440+
}
429441
uint32 sourceID = getProcessorFullId(channel->getSourceNodeID(), channel->getSubProcessorIdx());
430442
spikeChannelMap[sourceID][channel->getSourceIndex()] = i;
431443
}

0 commit comments

Comments
 (0)