API
 
Loading...
Searching...
No Matches
MagAOXApp_test.hpp
Go to the documentation of this file.
1#ifndef app_tests_MagAOXApp_test_hpp
2#define app_tests_MagAOXApp_test_hpp
3
4namespace libXWCTest
5{
6namespace appTest
7{
8namespace MagAOXAppTest
9{
10
11#undef APP_XWCTEST_BASE
12#ifdef XWCTEST_NAMESPACE
13 #define APP_XWCTEST_BASE MagAOX::app::XWCTEST_NAMESPACE::MagAOXApp<true>
14#else
15 #define APP_XWCTEST_BASE MagAOX::app::MagAOXApp<true>
16#endif
17
18#ifdef XWCTEST_NAMESPACE
19namespace XWCTEST_NAMESPACE
20{
21#endif
22
24{
25 MagAOXApp_test( bool gitmod = false ) : MagAOXApp( "sha1", gitmod )
26 {
27 }
28
29 bool appStartupFail {false};
30 bool appLogicFail {false};
31 bool appShutdownFail {false};
32
34 {
35 config.add( "name2", "", "name2", argType::Required, "", "", true, "string", "" );
36 config.m_sources = true;
37 }
38
39 void setup( int argc, char **argv )
40 {
41 APP_XWCTEST_BASE::setup( argc, argv );
42 }
43
44 virtual int appStartup()
45 {
46 if(appStartupFail)
47 {
48 return -1;
49 }
50
51 return 0;
52 }
53 virtual int appLogic()
54 {
55 if(appLogicFail)
56 {
57 return -1;
58 }
59
60 return 0;
61 }
62 virtual int appShutdown()
63 {
64 if(appShutdownFail)
65 {
66 return -1;
67 }
68
69 return 0;
70 }
71
72 std::string configPathGlobal()
73 {
74 return APP_XWCTEST_BASE::m_configPathGlobal;
75 }
76
77 std::string configPathUser()
78 {
79 return APP_XWCTEST_BASE::m_configPathUser;
80 }
81
82 std::string configPathLocal()
83 {
84 return APP_XWCTEST_BASE::m_configPathLocal;
85 }
86
87 std::string &invokedName()
88 {
89 return APP_XWCTEST_BASE::invokedName;
90 }
91
92 bool &doHelp()
93 {
94 return APP_XWCTEST_BASE::doHelp;
95 }
96
98 {
99 return APP_XWCTEST_BASE::m_configOnly;
100 }
101
102 void setPowerMgtEnabled( bool pme )
103 {
104 m_powerMgtEnabled = pme;
105 }
106
107 void setConfigName( const std::string &cn )
108 {
109 m_configName = cn;
110
111 m_indiDriver = new MagAOX::app::indiDriver<APP_XWCTEST_BASE>( this, m_configName, "0", "0" );
112 }
113
114 void setConfigBase( const std::string &cb )
115 {
116 m_configBase = cb;
117 }
118
119 int called_back{ 0 };
120
121 void setAlert()
122 {
123 m_stateAlert = true;
124 }
125
127 {
128 pcf::IndiProperty ip( pcf::IndiProperty::Switch );
129 ip.setDevice( configName() );
130 ip.setName( "fsm_clear_alert" );
131 ip.add( pcf::IndiElement( "request" ) );
132 ip["request"].setSwitchState( pcf::IndiElement::On );
133
134 st_newCallBack_clearFSMAlert( this, ip );
135 }
136
137 std::string powerDevice()
138 {
139 return m_powerDevice;
140 }
141
142 std::string powerChannel()
143 {
144 return m_powerChannel;
145 }
146
147 std::string powerElement()
148 {
149 return m_powerElement;
150 }
151
152 std::string powerTargetElement()
153 {
154 return m_powerTargetElement;
155 }
156
158 {
159 return m_powerOnWait;
160 }
161
163 {
164 return APP_XWCTEST_BASE::onPowerOff();
165 }
166
168 {
169 return APP_XWCTEST_BASE::whilePowerOff();
170 }
171
173 {
174 return APP_XWCTEST_BASE::powerOnWaitElapsed();
175 }
176
178 {
179 return APP_XWCTEST_BASE::powerState();
180 }
181
182 void configurePowerManagement( const std::string &device, const std::string &channel )
183 {
184 m_indiP_powerChannel = pcf::IndiProperty( pcf::IndiProperty::Text );
185 m_powerDevice = device;
186 m_indiP_powerChannel.setDevice( device );
187
188 m_powerChannel = channel;
189 m_indiP_powerChannel.setName( channel );
190 }
191
192 void configurePowerOnWait( unsigned long powerOnWait, int powerOnCounter, int loopPause )
193 {
194 m_powerOnWait = powerOnWait;
195 m_powerOnCounter = powerOnCounter;
196 m_loopPause = loopPause;
197 }
198
199 int setPowerState( const std::string &state, const std::string target )
200 {
201 pcf::IndiProperty ip( pcf::IndiProperty::Text );
202 ip.setDevice( m_powerDevice );
203 ip.setName( m_powerChannel );
204 ip.add( pcf::IndiElement( "state" ) );
205 ip["state"].setValue( state );
206
207 ip.add( pcf::IndiElement( "target" ) );
208 ip["target"].setValue( target );
209
210 return setCallBack_m_indiP_powerChannel( ip );
211 }
212
214 {
215 return APP_XWCTEST_BASE::setSigTermHandler();
216 }
217
218 void _handlerSigTerm( int signum, siginfo_t *siginf, void *ucont )
219 {
220 APP_XWCTEST_BASE::_handlerSigTerm( signum, siginf, ucont );
221 }
222
224 {
225 return APP_XWCTEST_BASE::setEuidReal();
226 }
227
228 int setEuidReal( int euidr, bool set = true )
229 {
230 m_euidReal = euidr;
231
232 if(set)
233 {
234 return APP_XWCTEST_BASE::setEuidReal();
235 }
236
237 return 0;
238 }
239
241 {
242 return APP_XWCTEST_BASE::setEuidCalled();
243 }
244
245 int setEuidCalled( int euidc )
246 {
247 m_euidCalled = euidc;
248 return APP_XWCTEST_BASE::setEuidCalled();
249 }
250
252 {
253 return APP_XWCTEST_BASE::lockPID();
254 }
255
257 {
258 return APP_XWCTEST_BASE::unlockPID();
259 }
260};
261
262int callback( void *app, const pcf::IndiProperty &ipRecv )
263{
264 static_cast<void>( ipRecv ); // be unused
265
266 MagAOXApp_test *appt = static_cast<MagAOXApp_test *>( app );
267
268 appt->called_back = 1;
269
270 return 0;
271}
272
273#ifdef XWCTEST_NAMESPACE
274} // namespace XWCTEST_NAMESPACE
275#endif
276
277} // namespace MagAOXAppTest
278} // namespace appTest
279} // namespace libXWCTest
280
281#endif // app_tests_MagAOXApp_test_hpp
#define XWCTEST_NAMESPACE
#define APP_XWCTEST_BASE
int callback(void *app, const pcf::IndiProperty &ipRecv)
Namespace for all libXWC tests.
Definition MagAOXApp.hpp:49
void _handlerSigTerm(int signum, siginfo_t *siginf, void *ucont)
void configurePowerManagement(const std::string &device, const std::string &channel)
void configurePowerOnWait(unsigned long powerOnWait, int powerOnCounter, int loopPause)
int setPowerState(const std::string &state, const std::string target)