The Sparta Modeling Framework
Loading...
Searching...
No Matches
Audience.hpp
1// <Audience.hpp> -*- C++ -*-
2
3#pragma once
4
5#include <string>
6#include <list>
7
11
12namespace sparta
13{
20 {
21 typedef std::list<ScheduleableHandle> ScheduleableHandleList;
22
23 public:
24
25 void setName(const std::string & name) {
26 name_ = name;
27 }
28
29 void release()
30 {
31 for (auto &ri : registry_)
32 {
33 ri->cancel();
34 }
35 registry_.clear();
36 }
37
38 const std::string& getName() const
39 {
40 return name_;
41 }
42
43 void enroll(ScheduleableHandle ev_hand)
44 {
45 registry_.push_back(ev_hand);
46 }
47
48 void enroll(ScheduleableHandle ev_hand, const Clock::Cycle& delay)
49 {
50 ev_hand->setDelay(delay);
51 enroll(ev_hand);
52 }
53
54 void withdraw(ScheduleableHandle ev_hand)
55 {
56 auto ei = std::find(registry_.begin(), registry_.end(), ev_hand);
57 if (ei != registry_.end()) {
58 registry_.erase(ei);
59 }
60 }
61
62 void notify()
63 {
64 for (auto &ri : registry_)
65 {
66 ri->schedule();
67 }
68 registry_.clear();
69 }
70
71 void delayedNotify(const Clock::Cycle& delay)
72 {
73 for (auto &ri : registry_)
74 {
75 ri->addDelay(delay);
76 ri->schedule();
77 }
78 registry_.clear();
79 }
80
81 protected:
82 std::string name_;
83 ScheduleableHandleList registry_;
84 };
85}
File that defines the Clock class.
File that defines the Scheduleable class.
A simple time-based, event precedence based scheduler.
Class used maintain a list of sparta::Scheduleable objects; used by observation-type classes.
Definition Audience.hpp:20
A light-weight reference counting handle for Scheduleables – DOES NOT delete.
void setDelay(Clock::Cycle delay)
Set a fixed delay for this event.
Macros for handling exponential backoff.