Leosac
0.8.0
Open Source Access Control
FExternalServer.cpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2014-2022 Leosac
3
4
This file is part of Leosac.
5
6
Leosac is free software: you can redistribute it and/or modify
7
it under the terms of the GNU Affero General Public License as published by
8
the Free Software Foundation, either version 3 of the License, or
9
(at your option) any later version.
10
11
Leosac is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU Affero General Public License for more details.
15
16
You should have received a copy of the GNU Affero General Public License
17
along with this program. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
#include "
FExternalServer.hpp
"
21
22
using namespace
Leosac::Hardware
;
23
24
FExternalServer::FExternalServer
(zmqpp::context &ctx, std::string
const
&server_name)
25
: backend_(ctx,
zmqpp
::socket_type::req)
26
, name_(server_name)
27
{
28
backend_
.connect(
"inproc://"
+ server_name);
29
}
30
31
bool
FExternalServer::connect
()
32
{
33
zmqpp::message msg;
34
msg <<
"CONNECT"
;
35
36
return
send_to_backend
(msg);
37
}
38
39
bool
FExternalServer::disconnect
()
40
{
41
zmqpp::message msg;
42
msg <<
"DISCONNECT"
;
43
44
return
send_to_backend
(msg);
45
}
46
47
bool
FExternalServer::send_to_backend
(zmqpp::message &msg)
48
{
49
std::string rep;
50
backend_
.send(msg);
51
backend_
.receive(rep);
52
53
assert(rep ==
"OK"
|| rep ==
"KO"
);
54
if
(rep ==
"OK"
)
55
return
true
;
56
return
false
;
57
}
58
59
const
std::string &
FExternalServer::name
()
const
60
{
61
return
name_
;
62
}
zmqpp
Definition:
CoreUtils.hpp:27
Leosac::Hardware::FExternalServer::backend_
zmqpp::socket backend_
A socket to talk to the backend server.
Definition:
FExternalServer.hpp:85
Leosac::Hardware::FExternalServer::connect
bool connect()
Connect to the server.
Definition:
FExternalServer.cpp:31
FExternalServer.hpp
Leosac::Hardware::FExternalServer::disconnect
bool disconnect()
Disconnect from the server.
Definition:
FExternalServer.cpp:39
Leosac::Hardware::FExternalServer::name_
std::string name_
Definition:
FExternalServer.hpp:87
Leosac::Hardware::FExternalServer::FExternalServer
FExternalServer(zmqpp::context &ctx, const std::string &server_name)
Construct a facade to an external server; this facade will connect to the server.
Definition:
FExternalServer.cpp:24
Leosac::Hardware::FExternalServer::name
const std::string & name() const
Returns the device's name.
Definition:
FExternalServer.cpp:59
Leosac::Hardware::FExternalServer::send_to_backend
bool send_to_backend(zmqpp::message &m)
Send a message to the backend_ server and wait for a response.
Definition:
FExternalServer.cpp:47
Leosac::Hardware
Provides facade classes to hardware device implementation.
Definition:
Buzzer.cpp:25
src
hardware
facades
FExternalServer.cpp
Generated on Tue Mar 22 2022 10:48:22 for Leosac by
1.8.17