8 #include "observerpattern/Subject.hpp" 9 #include "utils/PVAssert.hpp" 10 #include "utils/PVLog.hpp" 17 std::vector<std::shared_ptr<BaseMessage const>> messages,
19 Response::Status returnStatus = Response::NO_ACTION;
20 auto &objectVector = table.getObjectVector();
21 std::vector<int> numPostponed(messages.size());
22 for (
auto &obj : objectVector) {
23 for (
int msgIdx = 0; msgIdx < messages.size(); msgIdx++) {
24 auto &msg = messages[msgIdx];
25 Response::Status status = obj->respond(msg);
26 returnStatus = returnStatus + status;
31 if (status == Response::POSTPONE) {
32 numPostponed[msgIdx]++;
35 "%s postponed on %s.\n",
36 obj->getDescription_c(),
37 msg->getMessageType().c_str());
44 for (
int msgIdx = 0; msgIdx < messages.size(); msgIdx++) {
45 int numPostponedThisMsg = numPostponed.at(msgIdx);
46 if (numPostponedThisMsg > 0) {
48 "%d objects postponed %s\n",
50 messages[msgIdx]->getMessageType().c_str());
59 std::vector<std::shared_ptr<BaseMessage const>> messages,
61 std::string
const &description) {
62 Response::Status status = Response::PARTIAL;
63 while (status == Response::PARTIAL) {
64 status =
notify(table, messages, printFlag);
67 status == Response::POSTPONE,
68 "At least one object of %s postponed, but no object of %s progressed.\n",
void notifyLoop(ObserverTable const &table, std::vector< std::shared_ptr< BaseMessage const >> messages, bool printFlag, std::string const &description)
static bool completed(Status &a)
Response::Status notify(ObserverTable const &table, std::vector< std::shared_ptr< BaseMessage const >> messages, bool printFlag)