-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartStore.cpp
More file actions
59 lines (43 loc) · 1.33 KB
/
startStore.cpp
File metadata and controls
59 lines (43 loc) · 1.33 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
/*
* File: startStore.cpp
* Author: debian
*
* Created on 2. Juni 2017, 05:15
*/
#include <cstdlib>
#include <string>
#include <thread>
#include "StoreManager.h"
#include "RESTManager.h"
#define STORE_COUNT 2
#define STORE_ITEMS "Cheese", "Bread", "Milk", "Juice"
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
string items[] = {STORE_ITEMS};
int prices[STORE_COUNT][4] = {{ 190, 150, 115, 190},
{ 230, 175, 120, 210}};
RESTManager manager(nullptr, 0);
manager.initStructure();
string storeIps[STORE_COUNT];
int storePorts[STORE_COUNT];
string ip = manager.getConfig("Store1Ip");
string brokerIp = manager.getConfig("BrokerIp");
int port = stoi(manager.getConfig("Store1Port"));
StoreManager* stores[STORE_COUNT];
for(int i = 0; i < STORE_COUNT; i++) {
storeIps[i] = ip;
storePorts[i] = port++;
stores[i] = new StoreManager(storePorts[i], items, prices[i], sizeof(prices[i]) / sizeof(int), brokerIp, i);
}
thread* storeServerThreads[STORE_COUNT];
for(int i = 0; i < STORE_COUNT; i++) {
storeServerThreads[i] = new thread(&StoreManager::startLoop, stores[i]);
}
for(thread* thread : storeServerThreads) {
thread->join();
}
return 0;
}