casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImagerControl.h
Go to the documentation of this file.
1 //# ImagerControl.h: connect to synthesis imager task for control
2 //# Copyright (C) 2013
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef CASADBUS_IMAGERCONTROL_H_
29 #define CASADBUS_IMAGERCONTROL_H_
30 
31 /*******************************************************************************************
32 ********************************************************************************************
33 **** Note: the DBus-C++ header files should be include *BEFORE* the ****
34 **** Qt header files. Otherwise, the Qt header files (which use ****
35 **** the c-preprocessor to define "signals" to be "protected" ****
36 **** cause the following errors for DBus-C++ (and anything else ****
37 **** that has a variable etc. named "signals": ****
38 **** ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ****
39 **** .../dbus-c++/introspection.h:62: error: expected unqualified-id before ?protected? ****
40 **** .../dbus-c++/introspection.h:62: error: abstract declarator ?const DBus::Intros... ****
41 **** .../dbus-c++/introspection.h:62: error: expected ?;? before ?protected? ****
42 ********************************************************************************************
43 *******************************************************************************************/
44 #include <casadbus/types/variant.h>
45 #ifdef INTERACTIVE_ITERATION
46 #include <casadbus/interfaces/SynthImager.proxy.h>
47 #endif
49 
50 namespace casa {
51 
53 #ifdef INTERACTIVE_ITERATION
54  : private edu::nrao::casa::SynthesisImager_proxy,
55  public DBus::IntrospectableProxy,
56  public DBus::ObjectProxy
57 #endif
58  {
59  public:
60  static std::string name( ) { return "SynthesisImager"; }
61  static std::string connection_name( ) { return "edu.nrao.casa.SynthesisImager_001"; }
62  static std::string interface_name( ) { return "edu.nrao.casa.SynthesisImager"; }
63  static std::string object_path( ) { return "/casa/synthesis/imager"; }
64 
65  ImagerControl( const std::string &connection_name_=connection_name( ), const std::string &object_path_=object_path( ) );
66  ~ImagerControl( );
67 
69 #ifdef INTERACTIVE_ITERATION
70  return edu::nrao::casa::SynthesisImager_proxy::incrementController( );
71 #else
72  return false;
73 #endif
74  }
76 #ifdef INTERACTIVE_ITERATION
77  return edu::nrao::casa::SynthesisImager_proxy::decrementController( );
78 #else
79  return false;
80 #endif
81  }
82 
83  void changePauseFlag( const bool &state ) {
84 #ifdef INTERACTIVE_ITERATION
85  edu::nrao::casa::SynthesisImager_proxy::changePauseFlag( state );
86 #else
87  (void)state;
88 #endif
89  }
90 
91  void changeStopFlag(const bool& state) {
92 #ifdef INTERACTIVE_ITERATION
93  edu::nrao::casa::SynthesisImager_proxy::changeStopFlag( state );
94 #else
95  (void)state;
96 #endif
97  }
98 
99  // slots that are required for signals generated by SynthImager_adaptor...
100  void interactionRequired( const bool &/*required*/ ) { }
101  void detailUpdate( const std::map<std::string, DBus::Variant>& /*updatedParams*/ ) { }
102  void summaryUpdate( const DBus::Variant& /*summary*/ ) { }
103  void disconnect( ) { }
104 
105  std::string getDescription( ) {
106 #ifdef INTERACTIVE_ITERATION
107  return edu::nrao::casa::SynthesisImager_proxy::getDescription( );
108 #else
109  return std::string( );
110 #endif
111  }
112  std::map<std::string,dbus::variant> getDetails( )
113  {
114 #ifdef INTERACTIVE_ITERATION
115  return dbus::toStdMap( edu::nrao::casa::SynthesisImager_proxy::getDetails( ) );
116 #else
117  return std::map<std::string,dbus::variant>( );
118 #endif
119  }
120 
121  void controlUpdate(const std::map<std::string,dbus::variant>& newParams) {
122 #ifdef INTERACTIVE_ITERATION
123  edu::nrao::casa::SynthesisImager_proxy::controlUpdate( dbus::fromStdMap(newParams) );
124 #else
125  (void)newParams;
126 #endif
127  }
128 
129  /******************************************************************************
130  **********methods*provided*by*SynthesisImager_proxy********************************
131  *******************************************************************************
132  bool incrementController()
133  bool decrementController()
134  void interactionComplete()
135  void changeInteractiveMode(const bool& interactiveMode)
136  std::map< std::string, ::DBus::Variant > getDetails()
137  ::DBus::Variant getSummary()
138  std::string getDescription( )
139  *******************************************************************************
140  *******************************************************************************
141  ******************************************************************************/
142 
143 #if 0
144  /***** boilerplate from tSIIterBot.cc *****/
145  void sendInteractionComplete() {
146  checkDetails = true;
147 
148  casa::Record record;
149  record.define( casa::RecordFieldId("niter"), 123);
150  record.define( casa::RecordFieldId("cycleniter"), 456);
151  record.define( casa::RecordFieldId("interactiveniter"), 789);
152 
153  record.define( casa::RecordFieldId("threshold"), 5.67);
154  record.define( casa::RecordFieldId("cyclethreshold"), 7.89);
155  record.define( casa::RecordFieldId("interactivethreshold"), 8.91);
156 
157  record.define( casa::RecordFieldId("cyclefactor"), 4.56);
158  record.define( casa::RecordFieldId("loopgain"), 6.78);
159 
160  std::map<std::string, DBus::Variant> map= fromRecord(record);
161  controlUpdate(map);
162  interactionComplete();
163  }
164 
165 
166  int serviceLoop() {
168  while (!doneFlag) {
169  if (interactiveIRQ) {
170  interactiveIRQ = false;
171  if (serviceInteractiveFlag) {
172  sendInteractionComplete();
173  }
174  if (exitOnInteractiveFlag) {
175  doneFlag = true;
176  }
177  }
178  usleep(10000);
179  }
180  return exitCondition;
181  }
182 
183  protected:
184  /* Control Flags */
185  const bool serviceInteractiveFlag;
186  const bool exitOnInteractiveFlag;
187  const bool checkDetailsFlag;
188 
189  /* State Flags */
190  bool interactiveIRQ;
191 
192  bool checkDetails;
193  bool doneFlag;
194  int exitCondition;
195 #endif
196 
197  };
198 }
199 
200 #endif
void interactionRequired(const bool &)
slots that are required for signals generated by SynthImager_adaptor...
void detailUpdate(const std::map< std::string, DBus::Variant > &)
void changePauseFlag(const bool &state)
Definition: ImagerControl.h:83
void controlUpdate(const std::map< std::string, dbus::variant > &newParams)
std::map< std::string, dbus::variant > getDetails()
void summaryUpdate(const DBus::Variant &)
std::map< std::string, variant > toStdMap(const std::map< std::string, DBus::Variant > &src)
The identification of a record field.
Definition: RecordFieldId.h:91
void changeStopFlag(const bool &state)
Definition: ImagerControl.h:91
static std::string object_path()
Definition: ImagerControl.h:63
std::string getDescription()
A hierarchical collection of named fields of various types.
Definition: Record.h:180
::casac::record * fromRecord(const casacore::Record &)
See note in implementation about possible memory leak.
static std::string interface_name()
Definition: ImagerControl.h:62
ImagerControl(const std::string &connection_name_=connection_name(), const std::string &object_path_=object_path())
std::map< std::string, DBus::Variant > fromStdMap(const std::map< std::string, variant > &src)
static std::string name()
Definition: ImagerControl.h:60
static std::string connection_name()
Definition: ImagerControl.h:61
void define(const RecordFieldId &, Bool value)
Define a value for the given field.