API
 
Loading...
Searching...
No Matches
mzmqClient.hpp
Go to the documentation of this file.
1/** \file mzmqClient.hpp
2 * \brief The MagAO-X milkzmqClient wrapper
3 *
4 * \author Jared R. Males (jaredmales@gmail.com)
5 *
6 * \ingroup mzmqClient_files
7 */
8
9#ifndef mzmqClient_hpp
10#define mzmqClient_hpp
11
12// #include <ImageStreamIO/ImageStruct.h>
13// #include <ImageStreamIO/ImageStreamIO.h>
14
15#include <milkzmqClient.hpp>
16
17#include "../../libMagAOX/libMagAOX.hpp" //Note this is included on command line to trigger pch
18#include "../../magaox_git_version.h"
19
20namespace MagAOX
21{
22namespace app
23{
24
25/** \defgroup mzmqClient ImageStreamIO 0mq Stream Client
26 * \brief Reads the contents of an ImageStreamIO image stream over a zeroMQ channel
27 *
28 * <a href="../handbook/operating/software/apps/mzmqClient.html">Application Documentation</a>
29 *
30 * \ingroup apps
31 *
32 */
33
34/** \defgroup mzmqClient_files ImageStreamIO Stream Synchronization
35 * \ingroup mzmqClient
36 */
37
38/// MagAO-X application to control reading ImageStreamIO streams from a zeroMQ channel
39/** Contents are published to a local ImageStreamIO shmem buffer.
40 *
41 * \todo handle the alternate local name option as in the base milkzmqClient
42 * \todo md docs for this.
43 *
44 * \ingroup mzmqClient
45 *
46 */
47class mzmqClient : public MagAOXApp<>, public milkzmq::milkzmqClient
48{
49
50 public:
51 /// Default c'tor
52 mzmqClient();
53
54 /// Destructor
55 ~mzmqClient() noexcept;
56
57 /// Setup the configuration system (called by MagAOXApp::setup())
58 virtual void setupConfig();
59
60 /// load the configuration system results (called by MagAOXApp::setup())
61 virtual void loadConfig();
62
63 /// Startup functions
64 /** Sets up the INDI vars.
65 *
66 */
67 virtual int appStartup();
68
69 /// Implementation of the FSM for the Siglent SDG
70 virtual int appLogic();
71
72 /// Do any needed shutdown tasks. Currently nothing in this app.
73 virtual int appShutdown();
74
75 protected:
76 std::vector<std::string> m_shMemImNames;
77
78 /** \name milkzmq Status and Error Handling
79 * Implementation of status updates, warnings, and errors from milkzmq using logs.
80 *
81 * @{
82 */
83
84 /// Log status (with LOG_INFO level of priority).
85 virtual void reportInfo( const std::string &msg /**< [in] the status message */ );
86
87 /// Log status (with LOG_NOTICE level of priority).
88 virtual void reportNotice( const std::string &msg /**< [in] the status message */ );
89
90 /// Log a warning.
91 virtual void reportWarning( const std::string &msg /**< [in] the warning message */ );
92
93 /// Log an error.
94 virtual void reportError( const std::string &msg, ///< [in] the error message
95 const std::string &file, ///< [in] the name of the file where the error occurred
96 int line ///< [in] the line number of the error
97 );
98 ///@}
99};
100
101inline mzmqClient::mzmqClient() : MagAOXApp( MAGAOX_CURRENT_SHA1, MAGAOX_REPO_MODIFIED )
102{
103 m_powerMgtEnabled = false;
104
105 return;
106}
107
108inline mzmqClient::~mzmqClient() noexcept
109{
110 return;
111}
112
114{
115 config.add( "server.address",
116 "",
117 "server.address",
118 argType::Required,
119 "server",
120 "address",
121 false,
122 "string",
123 "The server's remote address. Usually localhost if using a tunnel." );
124 config.add( "server.imagePort",
125 "",
126 "server.imagePort",
127 argType::Required,
128 "server",
129 "imagePort",
130 false,
131 "int",
132 "The server's port. Usually the port on localhost forwarded to the host." );
133
134 config.add( "server.shmimNames",
135 "",
136 "server.shmimNames",
137 argType::Required,
138 "server",
139 "shmimNames",
140 false,
141 "string",
142 "List of names of the remote shmim streams to get." );
143}
144
146{
148
149 config( m_address, "server.address" );
150 config( m_imagePort, "server.imagePort" );
151
152 config( m_shMemImNames, "server.shmimNames" );
153
154 std::cerr << "m_imagePort = " << m_imagePort << "\n";
155}
156
158{
159 for( size_t n = 0; n < m_shMemImNames.size(); ++n )
160 {
162 }
163
164 for( size_t n = 0; n < m_imageThreads.size(); ++n )
165 {
166 if( imageThreadStart( n ) > 0 )
167 {
168 log<software_critical>( { __FILE__, __LINE__, "Starting image thread " + m_imageThreads[n].m_imageName } );
169 return -1;
170 }
171 }
172
173 return 0;
174}
175
177{
178 // first do a join check to see if other threads have exited.
179
180 for( size_t n = 0; n < m_imageThreads.size(); ++n )
181 {
182 if( pthread_tryjoin_np( m_imageThreads[n].m_thread->native_handle(), 0 ) == 0 )
183 {
185 { __FILE__, __LINE__, "image thread " + m_imageThreads[n].m_imageName + " has exited" } );
186
187 return -1;
188 }
189 }
190
191 return 0;
192}
193
195{
196 m_timeToDie.store( true, std::memory_order_relaxed );
197
198 for( size_t n = 0; n < m_imageThreads.size(); ++n )
199 {
201 }
202
203 for( size_t n = 0; n < m_imageThreads.size(); ++n )
204 {
205 if( m_imageThreads[n].m_thread->joinable() )
206 {
207 m_imageThreads[n].m_thread->join();
208 }
209 }
210
211 return 0;
212}
213
214inline void mzmqClient::reportInfo( const std::string &msg )
215{
217}
218
219inline void mzmqClient::reportNotice( const std::string &msg )
220{
222}
223
224inline void mzmqClient::reportWarning( const std::string &msg )
225{
227}
228
229inline void mzmqClient::reportError( const std::string &msg, const std::string &file, int line )
230{
231 log<software_error>( { file.c_str(), (uint32_t)line, msg } );
232}
233
234} // namespace app
235} // namespace MagAOX
236#endif
The base-class for XWCTk applications.
std::string m_configName
The name of the configuration file (minus .conf).
static int log(const typename logT::messageT &msg, logPrioT level=logPrio::LOG_DEFAULT)
Make a log entry.
MagAO-X application to control reading ImageStreamIO streams from a zeroMQ channel.
virtual int appLogic()
Implementation of the FSM for the Siglent SDG.
virtual void reportNotice(const std::string &msg)
Log status (with LOG_NOTICE level of priority).
virtual int appShutdown()
Do any needed shutdown tasks. Currently nothing in this app.
mzmqClient()
Default c'tor.
virtual void reportWarning(const std::string &msg)
Log a warning.
virtual void reportInfo(const std::string &msg)
Log status (with LOG_INFO level of priority).
~mzmqClient() noexcept
Destructor.
virtual void setupConfig()
Setup the configuration system (called by MagAOXApp::setup())
virtual int appStartup()
Startup functions.
virtual void loadConfig()
load the configuration system results (called by MagAOXApp::setup())
std::vector< std::string > m_shMemImNames
virtual void reportError(const std::string &msg, const std::string &file, int line)
Log an error.
std::stringstream msg
Definition dm.hpp:19
static constexpr logPrioT LOG_NOTICE
A normal but significant condition.
static constexpr logPrioT LOG_INFO
Informational. The info log level is the lowest level recorded during normal operations.
static constexpr logPrioT LOG_WARNING
A condition has occurred which may become an error, but the process continues.