Skip to content

Commit

Permalink
Add BitRangeEventP. (#649)
Browse files Browse the repository at this point in the history
  • Loading branch information
bakerstu authored Sep 13, 2022
1 parent 9bc4338 commit 1615f80
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/openlcb/EventHandlerTemplates.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,20 @@ void BitRangeEventPC::SendIdentified(WriteHelper *writer,
WriteHelper::global(), eventid_to_buffer(range), done);
}

void BitRangeEventP::handle_identify_global(const EventRegistryEntry& entry, EventReport *event,
BarrierNotifiable *done)
{
if (event->dst_node && event->dst_node != node_)
{
return done->notify();
}
uint64_t range = EncodeRange(event_base_, size_ * 2);
event->event_write_helper<1>()->WriteAsync(node_,
Defs::MTI_PRODUCER_IDENTIFIED_RANGE, WriteHelper::global(),
eventid_to_buffer(range), done->new_child());
done->maybe_done();
}

ByteRangeEventC::ByteRangeEventC(Node *node, uint64_t event_base,
uint8_t *backing_store, unsigned size)
: event_base_(event_base)
Expand Down
41 changes: 41 additions & 0 deletions src/openlcb/EventHandlerTemplates.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,47 @@ private:
unsigned size_; //< number of bits stored.
};

/// Producer event handler for a sequence of bits represented by a
/// dense block of consecutive event IDs.
class BitRangeEventP : public BitRangeEventPC
{
public:
/// Creates a new bit range producer. Backing store points to memory of at
/// least size bits (round up to multiple of 32). This class will advertise
/// producing size * 2 events contiguous from event_base. event_base will
/// turn bit 0 on, event_base + 1 will turn bit 0 off, event_base + 2 will
/// turn bit 1 on, event_base + 3 will turn bit 1 off, etc.
BitRangeEventP(Node *node, uint64_t event_base, uint32_t *backing_store,
unsigned size)
: BitRangeEventPC(node, event_base, backing_store, size)
{
}

/// Destructor.
virtual ~BitRangeEventP()
{
}

void handle_event_report(const EventRegistryEntry &entry, EventReport *event,
BarrierNotifiable *done) override
{
// Nothing to do for producers.
done->notify();
}

void handle_identify_consumer(const EventRegistryEntry &entry,
EventReport *event,
BarrierNotifiable *done) override
{
// Nothing to do for producers.
done->notify();
}

void handle_identify_global(const EventRegistryEntry &entry,
EventReport *event,
BarrierNotifiable *done) override;
};

/// Consumer event handler for a sequence of bytes represented by a dense block
/// of consecutive event IDs. Each byte has a consecutive block of 256 events.
class ByteRangeEventC : public SimpleEventHandler
Expand Down

0 comments on commit 1615f80

Please sign in to comment.