ALMA Computing Group

acsexmplClient.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 *    ALMA - Atacama Large Millimiter Array
00003 *    (c) European Southern Observatory, 2002
00004 *    Copyright by ESO (in the framework of the ALMA collaboration)
00005 *    and Cosylab 2002, All rights reserved
00006 *
00007 *    This library is free software; you can redistribute it and/or
00008 *    modify it under the terms of the GNU Lesser General Public
00009 *    License as published by the Free Software Foundation; either
00010 *    version 2.1 of the License, or (at your option) any later version.
00011 *
00012 *    This library is distributed in the hope that it will be useful,
00013 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 *    Lesser General Public License for more details.
00016 *
00017 *    You should have received a copy of the GNU Lesser General Public
00018 *    License along with this library; if not, write to the Free Software
00019 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00020 *
00021 *
00022 * "@(#) $Id: acsexmplClient.cpp,v 1.98 2007/02/01 05:14:26 cparedes Exp $"
00023 *
00024 * who       when      what
00025 * --------  --------  ----------------------------------------------
00026 * oat 2002-12-17 templatization of the client.get_object method
00027 * david 2002-06-17 changed client.init(argc,argv) for improved error checking
00028 * gchiozzi 2002-02-13 cleane up
00029 * msekoran  2001/07/13  created 
00030 */
00031 
00055 
00060 
00097 /* @}*/
00098 /* @}*/
00099 
00100 #include <maciSimpleClient.h>
00101 #include "acsexmplMountC.h"
00102 
00103 #include "acsexmplCallbacks.h"
00104 
00105 ACE_RCSID(acsexmpl, acsexmpClient, "$Id: acsexmplClient.cpp,v 1.98 2007/02/01 05:14:26 cparedes Exp $")
00106 using namespace maci;
00107        
00108 /*******************************************************************************/
00112 int main(int argc, char *argv[])
00113 {
00114     // Checks command-line arguments.
00115     if (argc < 2)
00116         {
00117         ACS_SHORT_LOG((LM_INFO, "Usage: %s <component name> <options>", argv[0]));
00118         return -1;
00119         }
00120     else
00121         {
00122         ACS_SHORT_LOG((LM_INFO, "Welcome to %s!", argv[0]));
00123         }
00124     
00125     //Creates and initializes the SimpleClient object
00126     SimpleClient client;
00127     if (client.init(argc,argv) == 0)
00128         {
00129         ACE_DEBUG((LM_DEBUG,"Cannot init client"));
00130         return -1;
00131         }
00132     else
00133         {
00134         //Must log into manager before we can really do anything
00135         client.login();
00136         }
00137 
00138     try
00139         {
00140         //List all components of type "*Mount*" the Manager knows of. 
00141         ACS_SHORT_LOG((LM_INFO, "Listing all components of type *Mount*"));
00142         maci::HandleSeq seq;
00143         //See the doxygen documentation for maci.idl to understand what these parameters
00144         //are.
00145         maci::ComponentInfoSeq_var components = client.manager()->get_component_info(client.handle(), 
00146                                                                                      seq, 
00147                                                                                      "*", 
00148                                                                                      "*Mount*", 
00149                                                                                      false);
00150         
00151         for (CORBA::ULong i = static_cast<CORBA::ULong>(0); i < components->length(); i++)
00152             {
00153             //just print out all known mount components
00154             ACS_SHORT_LOG((LM_INFO,"%s (%s)", components[i].name.in(), components[i].type.in()));
00155             }
00156         
00157         // Now get the specific component we have requested from the command-line
00158         ACS_SHORT_LOG((LM_INFO, "Getting component: %s", argv[1]));
00159 
00160         //getComponent can throw an exception if it fails
00161         MOUNT_ACS::Mount_var mount = client.getComponent<MOUNT_ACS::Mount>(argv[1], 0, true);
00162         
00163         
00164         //Prints the descriptor of the requested component
00165         ACS_SHORT_LOG((LM_DEBUG, "Requesting descriptor()... "));
00166         ACS::CharacteristicComponentDesc_var descriptor = mount->descriptor();
00167         ACS_SHORT_LOG((LM_DEBUG, "Got descriptor()."));
00168         ACS_SHORT_LOG((LM_INFO,"Descriptor:"));
00169         ACS_SHORT_LOG((LM_INFO,"\tname: %s", descriptor->name.in()));
00170         
00171         //Get the reference to the  actAz double property
00172         ACS_SHORT_LOG((LM_INFO, "Getting component property: %s:actAz", argv[1]));
00173         ACS::ROdouble_var actAz = mount->actAz();
00174             
00175         if (actAz.ptr() != ACS::ROdouble::_nil())
00176             {
00177             //Get the current value of the property synchronously
00178             ACSErr::Completion_var completion;
00179             CORBA::Double val = actAz->get_sync(completion.out());
00180             ACS_SHORT_LOG((LM_INFO,"Value: %f", val));
00181             
00182             
00183             //Create the CBdouble property
00184             ACS_SHORT_LOG((LM_INFO, "Trying to narrow CB for actAz... "));
00185             MyCBdouble myCallback("actAz");
00186             //Activate it as a CORBA object
00187             ACS::CBdouble_var cb = myCallback._this(); 
00188             ACS_SHORT_LOG((LM_INFO, "OK"));
00189             
00190             //Invoke the asynchronous method.
00191             ACS_SHORT_LOG((LM_INFO, "Call get_async for actAz..."));
00192             ACS::CBDescIn desc;
00193             actAz->get_async(cb.in(), desc);    //returns control immediately
00194             
00195             //Here some other useful things should be done
00196             //while the asyncrhonous reply comes
00197             //...
00198             //...
00199             //...
00200             
00201             //Enter main loop and stays there for a fixed amount of time (1s)
00202             //This is done to give the asynchronous method a chance to finish.
00203             ACE_Time_Value tv(1);
00204             client.run(tv);
00205             }//if
00206         }
00207     catch(maciErrType::CannotGetComponentExImpl &_ex) // can be thrown by getComponent<..>(...)
00208         {
00209         _ex.log();
00210         return -1;
00211         }
00212     catch( CORBA::SystemException &_ex ) // can be thrown by get_component_info
00213         {
00214         ACSErrTypeCommon::CORBAProblemExImpl corbaProblemEx(__FILE__, __LINE__,
00215                                                             "main");
00216         corbaProblemEx.setMinor(_ex.minor());
00217         corbaProblemEx.setCompletionStatus(_ex.completed());
00218         corbaProblemEx.setInfo(_ex._info().c_str());
00219         corbaProblemEx.log();
00220         return -1;
00221         }
00222     catch(...)
00223         {
00224         ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__, 
00225                                                         "main");
00226         uex.log();
00227         return -1;
00228         }//try-catch
00229   
00230     //Another try section where we release our component and logout from the Manager
00231     try
00232         {
00233         ACS_SHORT_LOG((LM_INFO,"Releasing..."));
00234         client.releaseComponent( argv[1]);      
00235         client.logout();
00236         }
00237     catch(maciErrType::CannotReleaseComponentExImpl &_ex)
00238         {
00239         _ex.log();
00240         return -1;
00241         }
00242     catch(...)
00243         {
00244         ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__, 
00245                                                         "main");
00246         uex.log();
00247         return -1;
00248         }//try-catch
00249     
00250     
00251     //sleep for 3 sec to allow everytihng to cleanup and stabilize
00252     //so that the tests can be determinitstic.
00253     ACE_OS::sleep(3);   
00254     return 0;
00255 }
00259 /*___oOo___*/
00260 
00261 
00262 
00263