ALMA Computing Group

acsexmplClientFridge.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: acsexmplClientFridge.cpp,v 1.9 2007/02/01 05:14:26 cparedes Exp $"
00023 *
00024 * who       when      what
00025 * --------  --------  ----------------------------------------------
00026 * david 2002-06-17 fixed client.init(argc,argv)
00027 * gchiozzi 2002-03-18 Replaced includes of fridge*.* with acsexmplFridge*.*
00028 * gchiozzi 2002-03-18 created 
00029 */
00030 
00054 
00059 
00099 /* @}*/
00100 /* @}*/
00101 
00102 #include <maciSimpleClient.h>
00103 #include <acsexmplFridgeC.h>
00104 #include "acsexmplCallbacks.h"
00105 
00106 ACE_RCSID(acsexmpl, acsexmplFridgeClient, "$Id: acsexmplClientFridge.cpp,v 1.9 2007/02/01 05:14:26 cparedes Exp $")
00107 using namespace maci;
00108     
00109 /*******************************************************************************/
00113 /*
00114  * Main procedure
00115  */
00116 int main(int argc, char *argv[])
00117 {
00118     //Checks command-line arguments.
00119     if (argc < 2)
00120         {
00121         ACS_SHORT_LOG((LM_INFO, "Usage: %s <component name> <options>", argv[0]));
00122         return -1;
00123         }
00124     else
00125         {
00126         ACS_SHORT_LOG((LM_INFO, "Welcome to %s!", argv[0]));
00127         }
00128 
00129     //Creates and initializes the SimpleClient object
00130     SimpleClient client;    
00131     if (client.init(argc,argv) == 0)
00132         {
00133         ACE_DEBUG((LM_DEBUG,"Cannot init client"));
00134         return -1;
00135         }
00136     else
00137         {
00138         //Must log into manager before we can really do anything
00139         client.login();
00140         }
00141 
00142     //Create an instance of our user-defined callback class
00143     MyCBdouble myCallback("refTemp");
00144 
00145     try
00146         {
00147         //Get the specific component we have requested on the command-line
00148         FRIDGE::FridgeControl_var fridge = client.getComponent<FRIDGE::FridgeControl>(argv[1], 0, true);
00149             
00150         //Get one of the component's BACI properties
00151         ACS::RWdouble_var refTemperature = fridge->refTemperature();
00152         
00153         if (refTemperature.ptr() != ACS::RWdouble::_nil())
00154             {
00155             ACSErr::Completion_var completion;
00156             
00157             //Just synchronously reading the value of refTemp
00158             CORBA::Double val = refTemperature->get_sync(completion.out());
00159             ACS_SHORT_LOG((LM_INFO,"Value: %f", val));
00160             
00161             //Activate the callback as a CORBA object
00162             ACS::CBdouble_var cb = myCallback._this();
00163             ACS_SHORT_LOG((LM_INFO, "OK"));
00164             
00165             ACS::CBDescIn desc;
00166             desc.id_tag = 2;
00167             ACS_SHORT_LOG((LM_INFO, "Trying to create monitor for refTemperature..."));
00168 
00169             //Create the actual monitor
00170             ACS::Monitordouble_var md = refTemperature->create_monitor(cb.in(), desc);
00171             if (md.ptr() != ACS::Monitordouble::_nil())
00172                 {
00173                 ACS_SHORT_LOG((LM_INFO, "OK"));
00174                 //Set the timer trigger to one second.
00175                 md->set_timer_trigger(10000000);
00176                 }
00177             else
00178                 {
00179                 ACS_SHORT_LOG((LM_INFO, "Failed"));
00180                 }
00181 
00182             //Give the callback some time to run.
00183             ACE_Time_Value time(20);
00184             client.run(time);
00185             
00186             //Must explicitly destroy the callback before exiting
00187             md->destroy();
00188             //Give the callback time to be really destroyed
00189             ACE_OS::sleep(15);
00190             }
00191         }
00192     catch(maciErrType::CannotGetComponentExImpl &_ex)
00193         {
00194         _ex.log();
00195         return -1;
00196         }
00197     catch(...)
00198         {
00199         ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__, 
00200                                                         "main");
00201         uex.log();
00202         return -1;
00203         }//try-catch
00204         
00205     try
00206         {
00207         //Must release components and logout from manager       
00208         ACS_SHORT_LOG((LM_INFO,"Releasing..."));
00209         client.releaseComponent(argv[1]);
00210         client.logout();
00211         }
00212     catch(maciErrType::CannotReleaseComponentExImpl &_ex)
00213         {
00214         _ex.log();
00215         return -1;
00216         }
00217     catch(...)
00218         {
00219         ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__, 
00220                                                             "main");
00221         uex.log();
00222         return -1;
00223         }//try-catch
00224   
00225     // sleep for 3 sec.
00226     ACE_OS::sleep(3);
00227     return 0;
00228 }
00229 
00233 /*___oOo___*/
00234 
00235 
00236 
00237