-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.h
More file actions
69 lines (54 loc) · 1.68 KB
/
Server.h
File metadata and controls
69 lines (54 loc) · 1.68 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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: Server.h
* Author: tim
*
* Created on 20. April 2017, 10:29
*/
#ifndef SERVER_H
#define SERVER_H
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <thrift/transport/TSocket.h>
#include <thrift/transport/TBufferTransports.h>
#include <thrift/protocol/TBinaryProtocol.h>
#include "RESTManager.h"
#include "gen-cpp/Store.h"
using namespace ::apache::thrift;
using namespace ::apache::thrift::protocol;
using namespace ::apache::thrift::transport;
class Server {
public:
Server(sockaddr_in addr, RESTManager manager, std::string* storeIps, int* storePorts, unsigned int nStores);
virtual ~Server();
void receive();
std::vector<std::string> getReceivedMessages() const { return receivedMessages; }
bool hasReceivedMessages() const { return !receivedMessages.empty(); }
static void restock(std::string item);
void addObserver(void (*observer)(std::string));
void notifyObservers(std::string info) const;
private:
int sockfd;
bool bound;
sockaddr_in addr;
static RESTManager manager;
std::vector<std::string> receivedMessages;
std::vector<void (*)(std::string)> observers;
static std::map<std::string, int> offsets;
StoreClient** clients;
boost::shared_ptr<TTransport>** transport;
unsigned int nStores;
void saveReading(std::string message);
};
#endif /* SERVER_H */