Skip to content

Commit

Permalink
PacketContainer: support deep copy of packet containers.
Browse files Browse the repository at this point in the history
  • Loading branch information
llongi committed Jul 12, 2016
1 parent db59a3e commit f416f24
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions include/events/packetContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,61 @@ static inline caerEventPacketHeader caerEventPacketContainerFindEventPacketByTyp
return (NULL);
}

/**
* Make a deep copy of an event packet container and all of its
* event packets and their current events.
*
* @param container an event packet container to copy.
*
* @return a deep copy of an event packet container, containing all events.
*/
static inline caerEventPacketContainer caerEventPacketContainerCopyAllEvents(caerEventPacketContainer container) {
if (container == NULL) {
return (NULL);
}

caerEventPacketContainer newContainer = caerEventPacketContainerAllocate(
caerEventPacketContainerGetEventsNumber(container));
if (newContainer == NULL) {
return (NULL);
}

CAER_EVENT_PACKET_CONTAINER_ITERATOR_START(container)
caerEventPacketContainerSetEventPacket(newContainer, caerEventPacketContainerIteratorCounter,
caerCopyEventPacketOnlyEvents(caerEventPacketContainerIteratorElement));
CAER_EVENT_PACKET_CONTAINER_ITERATOR_END

return (newContainer);
}

/**
* Make a deep copy of an event packet container, with its event packets
* sized down to only include the currently valid events (eventValid),
* and discarding everything else.
*
* @param container an event packet container to copy.
*
* @return a deep copy of an event packet container, containing only valid events.
*/
static inline caerEventPacketContainer caerEventPacketContainerCopyValidEvents(caerEventPacketContainer container) {
if (container == NULL) {
return (NULL);
}

caerEventPacketContainer newContainer = caerEventPacketContainerAllocate(
caerEventPacketContainerGetEventsNumber(container));
if (newContainer == NULL) {
return (NULL);
}

CAER_EVENT_PACKET_CONTAINER_ITERATOR_START(container)
caerEventPacketContainerSetEventPacket(newContainer, caerEventPacketContainerIteratorCounter,
caerCopyEventPacketOnlyValidEvents(caerEventPacketContainerIteratorElement));
CAER_EVENT_PACKET_CONTAINER_ITERATOR_END

return (newContainer);
}

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit f416f24

Please sign in to comment.