casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ImagerControl.h
Go to the documentation of this file.
00001 //# ImagerControl.h: connect to synthesis imager task for control
00002 //# Copyright (C) 2013
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id$
00027 
00028 #ifndef CASADBUS_IMAGERCONTROL_H_
00029 #define CASADBUS_IMAGERCONTROL_H_
00030 
00031 /*******************************************************************************************
00032 ********************************************************************************************
00033 ****  Note: the DBus-C++ header files should be include *BEFORE* the                    ****
00034 ****        Qt header files. Otherwise, the Qt header files (which use                  ****
00035 ****        the c-preprocessor to define "signals" to be "protected"                    ****
00036 ****        cause the following errors for DBus-C++ (and anything else                  ****
00037 ****        that has a variable etc. named "signals":                                   ****
00038 ****        ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----  ****
00039 **** .../dbus-c++/introspection.h:62: error: expected unqualified-id before ?protected? ****
00040 **** .../dbus-c++/introspection.h:62: error: abstract declarator ?const DBus::Intros... ****
00041 **** .../dbus-c++/introspection.h:62: error: expected ?;? before ?protected?            ****
00042 ********************************************************************************************
00043 *******************************************************************************************/
00044 #include <casadbus/types/variant.h>
00045 #ifdef INTERACTIVE_ITERATION
00046 #include <casadbus/interfaces/SynthImager.proxy.h>
00047 #endif
00048 #include <casadbus/utilities/Conversion.h>
00049 
00050 namespace casa {
00051 
00052         class ImagerControl
00053 #ifdef INTERACTIVE_ITERATION
00054                                                         : private edu::nrao::casa::SynthImager_proxy,
00055                                                         public DBus::IntrospectableProxy,
00056                                                         public DBus::ObjectProxy
00057 #endif
00058                                                         {
00059                 public:
00060                         static std::string connection_name( ) { return "edu.nrao.casa.SynthImager001"; }
00061                         static std::string interface_name( ) { return "edu.nrao.casa.SynthImager"; }
00062                         static std::string object_name( ) { return "/casa/synthimager"; }
00063 
00064                         ImagerControl( const std::string &connection_name_=connection_name( ), const std::string &object_name_=object_name( ) );
00065                         ~ImagerControl( );
00066 
00067                     bool incrementController( ) {
00068 #ifdef INTERACTIVE_ITERATION
00069                                         return edu::nrao::casa::SynthImager_proxy::incrementController( );
00070 #else
00071                                         return false;
00072 #endif
00073                         }
00074                     bool decrementController( ) {
00075 #ifdef INTERACTIVE_ITERATION
00076                                         return edu::nrao::casa::SynthImager_proxy::decrementController( );
00077 #else
00078                                         return false;
00079 #endif
00080                         }
00081 
00082                     void changePauseFlag( const bool &state ) {
00083 #ifdef INTERACTIVE_ITERATION
00084                                         edu::nrao::casa::SynthImager_proxy::changePauseFlag( state );
00085 #endif
00086                         }
00087 
00088                     void changeStopFlag(const bool& state) {
00089 #ifdef INTERACTIVE_ITERATION
00090                                         edu::nrao::casa::SynthImager_proxy::changeStopFlag( state );
00091 #endif
00092                         }
00093 
00094                         // slots that are required for signals generated by SynthImager_adaptor...
00095                         void interactionRequired( const bool &/*required*/ ) { }
00096                         void detailUpdate( const std::map<std::string, DBus::Variant>& /*updatedParams*/ ) { }
00097                         void summaryUpdate( const DBus::Variant& /*summary*/ ) { }
00098                         void disconnect( ) { }
00099 
00100                         std::string getDescription( ) {
00101 #ifdef INTERACTIVE_ITERATION
00102                                         return edu::nrao::casa::SynthImager_proxy::getDescription( );
00103 #else
00104                                         return std::string( );
00105 #endif
00106                         }
00107                         std::map<std::string,dbus::variant> getDetails( )
00108                                 {
00109 #ifdef INTERACTIVE_ITERATION
00110                                         return dbus::toStdMap( edu::nrao::casa::SynthImager_proxy::getDetails( ) );
00111 #else
00112                                         return std::map<std::string,dbus::variant>( );
00113 #endif
00114                                 }
00115 
00116                     void controlUpdate(const std::map<std::string,dbus::variant>& newParams) {
00117 #ifdef INTERACTIVE_ITERATION
00118                                 edu::nrao::casa::SynthImager_proxy::controlUpdate( dbus::fromStdMap(newParams) );
00119 #endif
00120                         }
00121 
00122                         /******************************************************************************
00123                         **********methods*provided*by*SynthImager_proxy********************************
00124                         *******************************************************************************
00125                     bool incrementController()
00126                     bool decrementController()
00127                     void interactionComplete()
00128                     void changeInteractiveMode(const bool& interactiveMode)
00129                     std::map< std::string, ::DBus::Variant > getDetails()
00130                     ::DBus::Variant getSummary()
00131                         std::string getDescription( )
00132                         *******************************************************************************
00133                         *******************************************************************************
00134                         ******************************************************************************/
00135 
00136 #if 0
00137                         /***** boilerplate from tSIIterBot.cc *****/
00138                         void sendInteractionComplete() {
00139                                 checkDetails = true;
00140 
00141                                 casa::Record record;
00142                                 record.define( casa::RecordFieldId("niter"), 123);
00143                                 record.define( casa::RecordFieldId("cycleniter"), 456);
00144                                 record.define( casa::RecordFieldId("interactiveniter"), 789);
00145                                 
00146                                 record.define( casa::RecordFieldId("threshold"), 5.67);
00147                                 record.define( casa::RecordFieldId("cyclethreshold"), 7.89);
00148                                 record.define( casa::RecordFieldId("interactivethreshold"), 8.91);
00149 
00150                                 record.define( casa::RecordFieldId("cyclefactor"), 4.56);
00151                                 record.define( casa::RecordFieldId("loopgain"), 6.78);
00152 
00153                                 std::map<std::string, DBus::Variant> map= fromRecord(record);
00154                                 controlUpdate(map);
00155                                 interactionComplete();
00156                         }
00157 
00158 
00159                         int serviceLoop() {
00160                                 incrementController();
00161                                 while (!doneFlag) {
00162                                         if (interactiveIRQ) {
00163                                                 interactiveIRQ = false;
00164                                                 if (serviceInteractiveFlag) {
00165                                                         sendInteractionComplete();
00166                                                 }
00167                                                 if (exitOnInteractiveFlag) {
00168                                                         doneFlag = true;
00169                                                 }
00170                                         }
00171                                         usleep(10000);
00172                                 }
00173                                 return exitCondition;
00174                         }
00175 
00176                 protected:
00177                         /* Control Flags */
00178                         const bool serviceInteractiveFlag;
00179                         const bool exitOnInteractiveFlag;
00180                         const bool checkDetailsFlag;
00181 
00182                         /* State Flags */
00183                         bool interactiveIRQ;
00184 
00185                         bool checkDetails;
00186                         bool doneFlag;
00187                         int  exitCondition;
00188 #endif
00189 
00190         };
00191 }
00192 
00193 #endif