-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
115 lines (87 loc) · 3.01 KB
/
main.cpp
File metadata and controls
115 lines (87 loc) · 3.01 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <iostream>
#include "clients/MessageReceiverThread.h"
#include "clients/MessageServerThread.h"
#include "clients/MessageStorage.h"
#include "clients/StorageMessageClientThread.h"
#include "clients/StorageMessageServerThread.h"
using namespace clients;
#define IP_ADDRESS "127.0.0.1"
#define MESSAGE_PORT 8888
#define STORAGE_PORT 8889
int main()
{
MessageStorage storage;
MessageReceiverThread receiverThread1;
MessageReceiverThread receiverThread2;
MessageServerThread serverThread;
StorageMessageClientThread storageClient;
StorageMessageServerThread storageServer;
printf("Initializing message sender\n");
if (!serverThread.initialize(IP_ADDRESS, MESSAGE_PORT))
{
auto errorCode = errno;
auto errorDescription = strerror(errorCode);
printf(
"Unable to initialize the message server\n\tCode: %d\n\tDescription: %s\n",
errorCode,
errorDescription);
return -1;
}
printf("Initializing message receiver 1\n");
if (!receiverThread1.initialize(IP_ADDRESS, MESSAGE_PORT))
{
auto errorCode = errno;
auto errorDescription = strerror(errorCode);
printf(
"Unable to initialize the message client\n\tCode: %d\n\tDescription: %s\n",
errorCode,
errorDescription);
return -1;
}
printf("Initializing message receiver 2\n");
if (!receiverThread2.initialize(IP_ADDRESS, MESSAGE_PORT))
{
auto errorCode = errno;
auto errorDescription = strerror(errorCode);
printf(
"Unable to initialize the message client\n\tCode: %d\n\tDescription: %s\n",
errorCode,
errorDescription);
return -1;
}
printf("Initializing storage server\n");
if (!storageServer.initialize(IP_ADDRESS, STORAGE_PORT))
{
auto errorCode = errno;
auto errorDescription = strerror(errorCode);
printf(
"Unable to initialize the storage server\n\tCode: %d\n\tDescription: %s\n",
errorCode,
errorDescription);
return -1;
}
printf("Initializing storage client\n");
if (!storageClient.initialize(IP_ADDRESS, STORAGE_PORT))
{
auto errorCode = errno;
auto errorDescription = strerror(errorCode);
printf(
"Unable to initialize the storage client\n\tCode: %d\n\tDescription: %s\n",
errorCode,
errorDescription);
return -1;
}
receiverThread1.addListener(&storage);
receiverThread2.addListener(&storage);
storage.addListener(&storageServer);
printf("Start message server thread\n");
serverThread.start();
printf("Start message receiver threads\n");
receiverThread1.start();
receiverThread2.start();
printf("Start storage server thread\n");
storageServer.start();
printf("Start storage client thread\n");
storageClient.start();
serverThread.join();
}