-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClients.h
50 lines (43 loc) · 1.23 KB
/
Clients.h
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
#ifndef CLIENTS_H
#define CLIENTS_H
#include <iostream>
#include <string>
#include "Observer.h"
//The general client base - all the client objects must inherit from this base
class ClientBase : ISubscriber
{
public:
ClientBase(std::shared_ptr<Publisher> eventController, std::string name) :
ISubscriber(), m_name(name), m_eventController(eventController) {};
virtual ~ClientBase() { m_eventController = nullptr; m_name = ""; };
void Subscribe(Event event);
void Unsubscribe(Event event);
void SendEvent(Event event);
virtual void onEvent(Event event);
virtual void start() = 0;
[[nodiscard]] virtual void execute() = 0;
protected:
std::string m_name;
std::shared_ptr<Publisher> m_eventController;
};
class ClientA : ClientBase
{
public:
ClientA(std::shared_ptr<Publisher> eventController, std::string name)
:ClientBase(eventController, name) {};
~ClientA() {};
void start() override;
void execute() override;
void onEvent(Event event) override;
};
class ClientB : ClientBase
{
public:
ClientB(std::shared_ptr<Publisher> eventController, std::string name)
:ClientBase(eventController, name) {};
~ClientB() {};
void start() override;
void execute() override;
void onEvent(Event event) override;
};
#endif CLIENTS_H