-
Notifications
You must be signed in to change notification settings - Fork 0
/
Message.h
executable file
·96 lines (85 loc) · 1.84 KB
/
Message.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
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
#pragma once
#include <stddef.h>
#include <vector>
#ifndef _WIN32
#include <semaphore.h>
#include <iostream>
#include <fcntl.h>
#include <unistd.h>
#else
#include <windows.h>
#endif
static constexpr size_t CLIENT_MEM_SIZE = 4096; // 4KB
static constexpr size_t MAX_CLIENTS_COUNT = 8; // 8 clients can interact with server
static constexpr size_t SHARED_MEMORY_SIZE = MAX_CLIENTS_COUNT * CLIENT_MEM_SIZE;
#ifndef _WIN32
using HANDLE = int;
using N_SEM = sem_t*;
#else
using N_SEM = HANDLE;
#endif
enum MessageType : size_t
{
HANDSHAKE = 0,
HANDSHAKE_OK,
HANDSHAKE_FAIL,
SET_CONFIG,
SET_CONFIG_OK,
SET_CONFIG_FAIL,
COMPARE_REQUEST,
COMPARE_RESULT,
COMPARE_FAIL,
DISCONNECT,
DISCONNECT_OK,
DISCONNECT_FAIL,
UNEXPECTED_REQUEST // default value, user must specify type of message
};
struct Configuration
{
size_t AffinityThreshold;
size_t MinPixelsForObject;
uint8_t PixelStep;
double CalculationTimeLimit;
size_t IdleTimeout;
double ThreadsMultiplier;
};
struct Message
{
Message(const size_t aId = 0, const MessageType aType = MessageType::UNEXPECTED_REQUEST)
: id(aId),
type(aType),
size(sizeof(Message)) {}
size_t id;
MessageType type;
size_t size;
};
struct MessageSetConfig : public Message
{
MessageSetConfig() : Message()
{
size = sizeof(MessageSetConfig);
}
Configuration configuration;
};
struct MessageCompareRequest : public Message
{
MessageCompareRequest() : Message()
{
size = sizeof(MessageCompareRequest);
}
char base[200];
char to_compare[200];
};
struct Rect
{
size_t l, r, t, b;
};
struct MessageCompareResult : public Message
{
MessageCompareResult() : Message()
{
size = sizeof(MessageCompareResult);
}
Rect payload[100];
size_t payload_bytes;
};