API
 
Loading...
Searching...
No Matches
mzmqServer.hpp
Go to the documentation of this file.
1/** \file mzmqServer.hpp
2 * \brief The MagAO-X milkzmqServer wrapper
3 *
4 * \author Jared R. Males (jaredmales@gmail.com)
5 *
6 * \ingroup mzmqServer_files
7 */
8
9#ifndef mzmqServer_hpp
10#define mzmqServer_hpp
11
12// #include <ImageStruct.h>
13// #include <ImageStreamIO.h>
14
15#include <milkzmqServer.hpp>
16
17// #include <mx/timeUtils.hpp>
18
19#include "../../libMagAOX/libMagAOX.hpp" //Note this is included on command line to trigger pch
20#include "../../magaox_git_version.h"
21
22namespace MagAOX
23{
24namespace app
25{
26
27/** \defgroup mzmqServer ImageStreamIO Stream Server
28 * \brief Writes the contents of an ImageStreamIO image stream over a zeroMQ channel
29 *
30 * <a href="../handbook/operating/software/apps/mzmqServer.html">Application Documentation</a>
31 *
32 * \ingroup apps
33 *
34 */
35
36/** \defgroup mzmqServer_files ImageStreamIO Stream Synchronization
37 * \ingroup mzmqServer
38 */
39
40/// MagAO-X application to control writing ImageStreamIO streams to a zeroMQ channel
41/** \todo document this better
42 * \ingroup mzmqServer
43 *
44 */
45class mzmqServer : public MagAOXApp<>, public milkzmq::milkzmqServer
46{
47
48 public:
49 /// Default c'tor
50 mzmqServer();
51
52 /// Destructor
53 ~mzmqServer() noexcept;
54
55 /// Setup the configuration system (called by MagAOXApp::setup())
56 virtual void setupConfig();
57
58 /// load the configuration system results (called by MagAOXApp::setup())
59 virtual void loadConfig();
60
61 /// Startup functions
62 /** Sets up the INDI vars.
63 *
64 */
65 virtual int appStartup();
66
67 /// Implementation of the FSM for the Siglent SDG
68 virtual int appLogic();
69
70 /// Do any needed shutdown tasks. Currently nothing in this app.
71 virtual int appShutdown();
72
73 protected:
74 bool m_compress{ false };
75 std::vector<std::string> m_shMemImNames;
76
77 /** \name milkzmq Status and Error Handling
78 * Implementation of status updates, warnings, and errors from milkzmq using logs.
79 *
80 * @{
81 */
82
83 /// Log status (with LOG_INFO level of priority).
84 virtual void reportInfo( const std::string &msg /**< [in] the status message */ );
85
86 /// Log status (with LOG_NOTICE level of priority).
87 virtual void reportNotice( const std::string &msg /**< [in] the status message */ );
88
89 /// Log a warning.
90 virtual void reportWarning( const std::string &msg /**< [in] the warning message */ );
91
92 /// Log an error.
93 virtual void reportError( const std::string &msg, ///< [in] the error message
94 const std::string &file, ///< [in] the name of the file where the error occurred
95 int line ///< [in] the line number of the error
96 );
97 ///@}
98};
99
100inline mzmqServer::mzmqServer() : MagAOXApp( MAGAOX_CURRENT_SHA1, MAGAOX_REPO_MODIFIED )
101{
102 m_powerMgtEnabled = false;
103
104 return;
105}
106
107inline mzmqServer::~mzmqServer() noexcept
108{
109 return;
110}
111
113{
114 config.add(
115 "server.imagePort", "", "server.imagePort", argType::Required, "server", "imagePort", false, "int", "" );
116
117 config.add(
118 "server.shmimNames", "", "server.shmimNames", argType::Required, "server", "shmimNames", false, "string", "" );
119
120 config.add(
121 "server.usecSleep", "", "server.usecSleep", argType::Required, "server", "usecSleep", false, "int", "" );
122
123 config.add( "server.fpsTgt", "", "server.fpsTgt", argType::Required, "server", "fpsTgt", false, "float", "" );
124
125 config.add( "server.fpsGain", "", "server.fpsGain", argType::Required, "server", "fpsGain", false, "float", "" );
126
127 config.add( "server.compress",
128 "",
129 "server.compress",
130 argType::Required,
131 "server",
132 "compress",
133 false,
134 "bool",
135 "Flag to turn on compression for INT16 and UINT16." );
136}
137
139{
141
142 config( m_imagePort, "server.imagePort" );
143
144 config( m_shMemImNames, "server.shmimNames" );
145 config( m_usecSleep, "server.usecSleep" );
146 config( m_fpsTgt, "server.fpsTgt" );
147
148 config( m_fpsGain, "server.fpsGain" );
149
150 config( m_compress, "server.compress" );
151}
152
153#include <sys/syscall.h>
154
156{
157 if( m_compress )
159
160 for( size_t n = 0; n < m_shMemImNames.size(); ++n )
161 {
163 }
164
165 if( serverThreadStart() < 0 )
166 {
168 return -1;
169 }
170
171 for( size_t n = 0; n < m_imageThreads.size(); ++n )
172 {
173 if( imageThreadStart( n ) > 0 )
174 {
175 log<software_critical>( { __FILE__, __LINE__, "Starting image thread " + m_imageThreads[n].m_imageName } );
176 return -1;
177 }
178 }
179
180 std::cerr << "Main Thread: " << syscall( SYS_gettid ) << "\n";
181
182 return 0;
183}
184
186{
187 // first do a join check to see if other threads have exited.
188
189 if( pthread_tryjoin_np( m_serverThread.native_handle(), 0 ) == 0 )
190 {
191 log<software_error>( { __FILE__, __LINE__, "server thread has exited" } );
192
193 return -1;
194 }
195
196 for( size_t n = 0; n < m_imageThreads.size(); ++n )
197 {
198 if( pthread_tryjoin_np( m_imageThreads[n].m_thread->native_handle(), 0 ) == 0 )
199 {
201 { __FILE__, __LINE__, "image thread " + m_imageThreads[n].m_imageName + " has exited" } );
202
203 return -1;
204 }
205 }
206
207 return 0;
208}
209
211{
212 m_timeToDie.store( true, std::memory_order_relaxed );
213
215
216 if( m_serverThread.joinable() )
217 {
218 m_serverThread.join();
219 }
220
221 for( size_t n = 0; n < m_imageThreads.size(); ++n )
222 {
224 }
225
226 for( size_t n = 0; n < m_imageThreads.size(); ++n )
227 {
228 if( m_imageThreads[n].m_thread->joinable() )
229 {
230 m_imageThreads[n].m_thread->join();
231 }
232 }
233
234 return 0;
235}
236
237inline void mzmqServer::reportInfo( const std::string &msg )
238{
240}
241
242inline void mzmqServer::reportNotice( const std::string &msg )
243{
245}
246
247inline void mzmqServer::reportWarning( const std::string &msg )
248{
250}
251
252inline void mzmqServer::reportError( const std::string &msg, const std::string &file, int line )
253{
254 log<software_error>( { file.c_str(), (uint32_t)line, msg } );
255}
256
257} // namespace app
258} // namespace MagAOX
259#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 writing ImageStreamIO streams to a zeroMQ channel.
virtual void setupConfig()
Setup the configuration system (called by MagAOXApp::setup())
virtual void loadConfig()
load the configuration system results (called by MagAOXApp::setup())
virtual int appShutdown()
Do any needed shutdown tasks. Currently nothing in this app.
virtual int appStartup()
Startup functions.
virtual void reportError(const std::string &msg, const std::string &file, int line)
Log an error.
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).
mzmqServer()
Default c'tor.
virtual void reportInfo(const std::string &msg)
Log status (with LOG_INFO level of priority).
std::vector< std::string > m_shMemImNames
~mzmqServer() noexcept
Destructor.
virtual void reportWarning(const std::string &msg)
Log a warning.
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.