ALMA Computing Group

acsexmplClientComponentIOR.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 *
00023 * "@(#) $Id: acsexmplClientComponentIOR.cpp,v 1.8 2007/02/01 05:14:26 cparedes Exp $"
00024 *
00025 * who       when      what
00026 * --------  --------  ----------------------------------------------
00027 * david 2002-06-17 fixed client.init(argc, argv)
00028 * msekoran  17/02/01  created 
00029 */
00030 
00086 /* @}*/
00087 /* @}*/
00088 
00089 #include <maciSimpleClient.h>
00090 
00091 ACE_RCSID(acsexmpl, acsexmplMaciIOR, "$Id: acsexmplClientComponentIOR.cpp,v 1.8 2007/02/01 05:14:26 cparedes Exp $")
00092 using namespace maci;
00093 
00096 int main(int argc, char *argv[]) 
00097 {
00098     //Checks command-line arguments
00099     if (argc < 2)
00100         {
00101         ACS_SHORT_LOG((LM_INFO, "Usage: %s <component name> <options>", argv[0]));
00102         return -1;
00103         }
00104     else
00105         {
00106         ACS_SHORT_LOG((LM_INFO, "Welcome to %s!", argv[0]));
00107         }
00108     
00109     //Creates and initialyses the SimpleClient object
00110     SimpleClient client;
00111     if (client.init(argc,argv) == 0)
00112         {
00113         ACE_DEBUG((LM_DEBUG,"Cannot init client"));
00114         return -1;
00115         }
00116     else
00117         {
00118         //Must log into manager before we can really do anything
00119         client.login();
00120         }
00121     
00122     try
00123         {
00124         //Gets from manager the reference to the requested component.
00125         //Pay special attention that this reference is just a generic
00126         //CORBA object at this point.
00127         ACS_SHORT_LOG((LM_INFO, "Looking for Object '%s' ", argv[1]));
00128         CORBA::Object_var obj =  client.getComponent(argv[1], 0 , true);
00129         
00130         //Get the stringified IOR of the component.  The IOR of CORBA objects
00131         //can be considered to be a unique "phone number" used to access CORBA
00132         //servants.
00133         ACS_SHORT_LOG((LM_INFO, "Getting stringified IOR"));
00134         CORBA::String_var mior = client.getORB()->object_to_string(obj.in());    
00135         
00136         //Print the IOR to standard out
00137         u_int result;         
00138         ACS_SHORT_LOG ((LM_INFO, "IOR for %s is: %s", argv[1], mior.in()));
00139         result = ACE_OS::printf ("%s", mior.in());
00140         }
00141     catch(maciErrType::CannotGetComponentExImpl &_ex)
00142         {
00143         _ex.log();
00144         return -1;
00145         }
00146     catch(...)
00147         {
00148         ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__, 
00149                                                         "main");
00150         
00151         uex.log();
00152         return -1;
00153         }
00154 
00155     //Normally you would not want to have separate try sections for releasing
00156     //the components and logging out from manager.  This is a very special case 
00157     //since we do not know ahead of time what will be released.  In other words,
00158     //argv[1] could technically be "manager" which would end up raising a 
00159     //no-permission exception.  To get around this just use separate try/catch 
00160     //sections and ignore no-permission exceptions.
00161     try
00162         {
00163         //All clients must cleanly release objects they activate!
00164         client.releaseComponent(argv[1]);
00165         }
00166     catch(maciErrType::CannotReleaseComponentExImpl &_ex)
00167         {
00168         _ex.log();
00169         return -1;
00170         }
00171     catch(...)
00172         {
00173         ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__, 
00174                                                         "main");
00175         uex.log();
00176         return -1;
00177         }
00178     
00179     try
00180         {
00181         if (client.logout() == 0)
00182             {
00183             ACS_SHORT_LOG ((LM_INFO, "Cannot logout"));
00184             return -1;
00185             }
00186         }
00187     catch(...)
00188         {
00189         ACS_SHORT_LOG((LM_ERROR, "Exception caught"));
00190         return -1;
00191         }    
00192     
00193     ACS_SHORT_LOG((LM_INFO,"The end!"));
00194     return 0;
00195 }
00196 
00197