-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathMyLib.cpp
More file actions
54 lines (44 loc) · 1.91 KB
/
Copy pathMyLib.cpp
File metadata and controls
54 lines (44 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright Ciriaco Garcia de Celis 2016.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <memory>
#include "MyLib/MyLib.h"
template <> void MyLib::onMessage(WantPrinter&)
{
printer->send(LINE("<MyLib> sending printer to client"));
publish(printer);
// some activity to spend ink
timerStart('A', std::chrono::nanoseconds(333333333), TimerCycle::Periodic);
timerStart(std::string("faster event"), std::chrono::seconds(1), TimerCycle::Periodic); // char const* const& is ugly
timerStart<std::string>("slower event", std::chrono::seconds(2), TimerCycle::Periodic); // alternative syntax
timerStart(LibraryIsTired{}, std::chrono::seconds(8));
auto billingAddress = callback<const std::shared_ptr<Billing>>(); // billingAddress(bill) is equivalent to publish(bill)
timerStart(bills, std::chrono::seconds(1), billingAddress, TimerCycle::Periodic); // periodic invocation
}
template <> void MyLib::onMessage(std::shared_ptr<RequestA>& msg)
{
printer->send(LINE("<MyLib> received " << msg->data));
publish(std::make_shared<ReplyA>("reply to " + msg->data));
bills->count++;
}
template <> void MyLib::onMessage(std::shared_ptr<RequestB>& msg)
{
printer->send(LINE("<MyLib> received " << msg->data));
auto reply = std::make_shared<ReplyB>("reply to " + msg->data);
publish(std::move(reply)); // example invalidating 'reply'
if (reply) printer->send(LINE("<MyLib> no subscriber to replies for " << msg->data));
bills->count++;
}
template <> void MyLib::onTimer(const std::string& whatEvent)
{
publish(std::unique_ptr<Info>(new Info { whatEvent }));
}
template <> void MyLib::onTimer(const char& acter)
{
printer->send(LINE("<MyLib> beat " << acter));
}
template <> void MyLib::onTimer(const LibraryIsTired& seriously)
{
publish(seriously);
}