11#ifndef app_indiDriver_hpp
12#define app_indiDriver_hpp
14#include "../../INDI/libcommon/IndiDriver.hpp"
15#include "../../INDI/libcommon/IndiElement.hpp"
17#include "../../INDI/libcommon/IndiClient.hpp"
34 const std::string & hostAddress,
36 ) : pcf::IndiClient( clientName,
"none",
"1.7", hostAddress, hostPort)
46 processIndiRequests(
false);
51template<
class _parentT>
93 const std::string &szName,
94 const std::string &szDriverVersion,
95 const std::string &szProtocolVersion
132template<
class parentT>
134 const std::string &szName,
135 const std::string &szDriverVersion,
136 const std::string &szProtocolVersion
137 ) : pcf::IndiDriver(szName, szDriverVersion, szProtocolVersion)
144 fd = open( parent->driverInName().c_str(), O_RDWR);
147 parentT::template log<logger::software_error>({__FILE__, __LINE__, errno,
"Error opening input INDI FIFO."});
154 fd = open( parent->driverOutName().c_str(), O_RDWR);
157 parentT::template log<logger::software_error>({__FILE__, __LINE__, errno,
"Error opening output INDI FIFO."});
167 fd = open( parent->driverCtrlName().c_str(), O_RDWR);
170 parentT::template log<logger::software_error>({__FILE__, __LINE__, errno,
"Error opening control INDI FIFO."});
175 int wrno = write(fd, &c, 1);
178 parentT::template log<logger::software_error>({__FILE__, __LINE__, errno,
"Error writing to control INDI FIFO."});
186template<
class parentT>
189 std::lock_guard<std::mutex>
lock(m_outGoingMutex);
190 if(m_outGoing)
delete m_outGoing;
193template<
class parentT>
196 if(m_parent) m_parent->handleDefProperty(
ipRecv);
199template<
class parentT>
202 if(m_parent) m_parent->handleGetProperties(
ipRecv);
205template<
class parentT>
208 if(m_parent) m_parent->handleNewProperty(
ipRecv);
211template<
class parentT>
214 if(m_parent) m_parent->handleSetProperty(
ipRecv);
217template<
class parentT>
220 processIndiRequests(
false);
223template<
class parentT>
229template<
class parentT>
232 std::lock_guard<std::mutex>
lock(m_outGoingMutex);
235 if( m_outGoing !=
nullptr)
237 if(m_outGoing->getQuitProcess())
239 parentT::template log<logger::text_log>(
"INDI client disconnected.");
240 m_outGoing->quitProcess();
241 m_outGoing->deactivate();
243 m_outGoing =
nullptr;
248 if( m_outGoing ==
nullptr)
252 m_outGoing =
new indiClient(m_parent->configName()+
"-client", m_serverIPAddress, m_serverPort);
253 m_outGoing->activate();
257 parentT::template log<logger::software_error>({__FILE__, __LINE__,
"Exception thrown while creating IndiClient connection"});
261 if(m_outGoing ==
nullptr)
263 parentT::template log<logger::software_error>({__FILE__, __LINE__,
"Failed to allocate IndiClient connection"});
267 parentT::template log<logger::text_log>(
"INDI client connected and activated");
272 m_outGoing->sendNewProperty(
ipRecv);
273 if(m_outGoing->getQuitProcess())
275 parentT::template log<logger::software_error>({__FILE__, __LINE__,
"INDI client appears to be disconnected -- NEW not sent."});
284 catch(std::exception & e)
286 parentT::template log<logger::software_error>({__FILE__, __LINE__, std::string(
"Exception from IndiClient: ") + e.what()});
291 parentT::template log<logger::software_error>({__FILE__, __LINE__,
"Exception from IndiClient"});
296 parentT::template log<logger::software_error>({__FILE__, __LINE__,
"fall through in sendNewProperty"});
The base-class for XWCTk applications.
Simple INDI Client class.
void execute()
Implementation of the pcf::IndiClient interface, called by activate to actually begins the INDI event...
indiClient(const std::string &clientName, const std::string &hostAddress, const int hostPort)
Constructor, which establishes the INDI client connection.
~indiDriver()
D'tor, deletes the IndiClient pointer.
virtual void handleSetProperty(const pcf::IndiProperty &ipRecv)
virtual void handleDefProperty(const pcf::IndiProperty &ipRecv)
bool m_good
Flag to hold the status of this connection.
int m_serverPort
The port of the server for the INDI Client connection.
virtual void execute(void)
Define the execute virtual function. This runs the processIndiRequests function in this thread,...
indiDriver(parentT *parent, const std::string &szName, const std::string &szDriverVersion, const std::string &szProtocolVersion)
Public c'tor.
virtual void handleNewProperty(const pcf::IndiProperty &ipRecv)
virtual int sendNewProperty(const pcf::IndiProperty &ipRecv)
Send a newProperty command to another INDI driver.
std::mutex m_outGoingMutex
Mutex protecting the lifecycle and use of m_outGoing.
indiClient * m_outGoing
An INDI Client is used to send commands to other drivers.
virtual void handleGetProperties(const pcf::IndiProperty &ipRecv)
std::string m_serverIPAddress
The IP address of the server for the INDI Client connection.
_parentT parentT
The parent MagAOX app.
parentT * m_parent
This objects parent class.
bool good()
Get the value of the good flag.
virtual void update()
Define the update virt. func. here so the uptime message isn't sent.
const pcf::IndiProperty & ipRecv
std::unique_lock< std::mutex > lock(m_indiMutex)