Instrument Neutral Distributed Interface INDI
2.2.5
integs
DriverMock.cpp
Go to the documentation of this file.
1
/*******************************************************************************
2
Copyright(c) 2022 Ludovic Pollet. All rights reserved.
3
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License version 2 as published by the Free Software Foundation.
7
8
This library is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
Library General Public License for more details.
12
13
You should have received a copy of the GNU Library General Public License
14
along with this library; see the file COPYING.LIB. If not, write to
15
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
Boston, MA 02110-1301, USA.
17
*******************************************************************************/
18
19
#include <system_error>
20
21
#include "
DriverMock.h
"
22
#include "
utils.h
"
23
24
25
class
FakeDriverListener
{
26
std::string abstractPath;
27
bool
ready =
false
;
28
public
:
29
int
serverConnection
;
30
void
setup
() {
31
if
(ready)
return
;
32
ready =
true
;
33
// Create a socket that will not have the clo on exec flag ?
34
abstractPath =
uniqueTestName
(
"/tmp/fakedriver-test"
);
35
setenv(
"FAKEDRIVER_ADDRESS"
, abstractPath.c_str(), 1);
36
37
serverConnection
=
unixSocketListen
(abstractPath);
38
}
39
};
40
41
static
FakeDriverListener
driverListener;
42
43
44
void
DriverMock::setup
()
45
{
46
driverListener.
setup
();
47
}
48
49
void
DriverMock::waitEstablish
()
50
{
51
driverConnection =
socketAccept
(driverListener.
serverConnection
);
52
unixSocketRecvFds
(driverConnection, 2, driverFds);
53
cnx
.
setFds
(driverFds[0], driverFds[1]);
54
}
55
56
void
DriverMock::terminateDriver
()
57
{
58
cnx
.
setFds
(-1, -1);
59
if
(driverConnection != -1) close(driverConnection);
60
if
(driverFds[0] != -1) close(driverFds[0]);
61
if
(driverFds[1] != -1) close(driverFds[1]);
62
driverConnection = -1;
63
driverFds[0] = -1;
64
driverFds[1] = -1;
65
}
66
67
68
void
DriverMock::ping
()
69
{
70
cnx
.
send
(
"<pingRequest uid='flush'/>\n"
);
71
cnx
.
expectXml
(
"<pingReply uid=\"flush\"/>"
);
72
}
73
74
DriverMock::DriverMock
()
75
{
76
driverConnection = -1;
77
driverFds[0] = -1;
78
driverFds[1] = -1;
79
}
80
81
DriverMock::~DriverMock
()
82
{
83
terminateDriver
();
84
}
DriverMock.h
ConnectionMock::send
void send(const std::string &content)
Definition
ConnectionMock.cpp:313
ConnectionMock::setFds
void setFds(int rd, int wr)
Definition
ConnectionMock.cpp:62
ConnectionMock::expectXml
void expectXml(const std::string &xml)
Definition
ConnectionMock.cpp:286
DriverMock::DriverMock
DriverMock()
Definition
DriverMock.cpp:74
DriverMock::ping
void ping()
Definition
DriverMock.cpp:68
DriverMock::terminateDriver
void terminateDriver()
Definition
DriverMock.cpp:56
DriverMock::cnx
ConnectionMock cnx
Definition
DriverMock.h:50
DriverMock::~DriverMock
virtual ~DriverMock()
Definition
DriverMock.cpp:81
DriverMock::waitEstablish
void waitEstablish()
Definition
DriverMock.cpp:49
DriverMock::setup
void setup()
Definition
DriverMock.cpp:44
FakeDriverListener
Definition
DriverMock.cpp:25
FakeDriverListener::setup
void setup()
Definition
DriverMock.cpp:30
FakeDriverListener::serverConnection
int serverConnection
Definition
DriverMock.cpp:29
socketAccept
int socketAccept(int fd)
Definition
utils.cpp:144
unixSocketListen
int unixSocketListen(const std::string &unixAddr)
Definition
utils.cpp:71
uniqueTestName
std::string uniqueTestName(const std::string &prefix)
Definition
utils.cpp:360
unixSocketRecvFds
void unixSocketRecvFds(int fd, int count, int *fdsDest)
Definition
utils.cpp:228
utils.h
Generated on Thu Oct 22 2026 14:46:48 for Instrument Neutral Distributed Interface INDI by
1.9.8