Instrument Neutral Distributed Interface INDI  2.0.2
IndiClientMock.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 #include <unistd.h>
21 
22 #include "IndiClientMock.h"
23 #include "IndiServerController.h"
24 #include "utils.h"
25 
27 {
28  fd = -1;
29 }
30 
32 {
33  close();
34 }
35 
37 {
38  if (fd != -1) ::close(fd);
39  cnx.setFds(-1, -1);
40 }
41 
43 {
44 #ifdef ENABLE_INDI_SHARED_MEMORY
46 #else
48 #endif
49 }
50 
52 {
53  connectUnix(server.getUnixSocketPath());
54 }
55 
57 {
58  connectTcp("127.0.0.1", server.getTcpPort());
59 }
60 
61 void IndiClientMock::connectUnix(const std::string &path)
62 {
63  fd = unixSocketConnect(path);
64  cnx.setFds(fd, fd);
65 }
66 
67 void IndiClientMock::connectTcp(const std::string &host, int port)
68 {
69  fd = tcpSocketConnect(host, port, false);
70  cnx.setFds(fd, fd);
71 }
72 
74 {
75  this->fd = fd;
76  cnx.setFds(fd, fd);
77 }
78 
80 {
81  cnx.send("<pingRequest uid='flush'/>\n");
82  cnx.expectXml("<pingReply uid='flush'/>\n");
83 }
void send(const std::string &content)
void setFds(int rd, int wr)
void expectXml(const std::string &xml)
virtual ~IndiClientMock()
void connectUnix(const IndiServerController &server)
void associate(int fd)
void connectTcp(const IndiServerController &server)
ConnectionMock cnx
void connect(const IndiServerController &server)
websocketpp::server< deflate_server_config > server
Definition: indiwsserver.h:39
int fd
Definition: intelliscope.c:43
int unixSocketConnect(const std::string &unixAddr, bool failAllowed)
Definition: utils.cpp:155
int tcpSocketConnect(const std::string &host, int port, bool failAllowed)
Definition: utils.cpp:301