ALMA Computing Group

acsexmplClientFridgeCmd.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: acsexmplClientFridgeCmd.cpp,v 1.8 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 created 00028 */ 00029 00059 00064 00101 /* @}*/ 00102 /* @}*/ 00103 00104 #include <maciSimpleClient.h> 00105 #include <acsexmplFridgeC.h> 00106 00107 ACE_RCSID(acsexmpl, acsexmplFridgeClientCmd, "$Id: acsexmplClientFridgeCmd.cpp,v 1.8 2007/02/01 05:14:26 cparedes Exp $") 00108 using namespace maci; 00109 /*******************************************************************************/ 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 //Get the specific component we have requested on the command-line 00141 FRIDGE::FridgeControl_var fridge = client.getComponent<FRIDGE::FridgeControl>(argv[1], 0, true); 00142 00143 //Run whatever supported command the end-user has specified 00144 //from the command-line 00145 if(strcmp(argv[2],"ON") == 0) // Command ON 00146 { 00147 ACS_SHORT_LOG((LM_INFO, "ON")); 00148 fridge->on(); 00149 } 00150 else if(strcmp(argv[2],"OFF") == 0) // Command OFF 00151 { 00152 ACS_SHORT_LOG((LM_INFO, "OFF")); 00153 fridge->off(); 00154 } 00155 else if(strcmp(argv[2],"OPEN") == 0) // Command OPEN 00156 { 00157 ACS_SHORT_LOG((LM_INFO, "OPEN")); 00158 fridge->open(); 00159 } 00160 else if(strcmp(argv[2],"CLOSE") == 0) // Command CLOSE 00161 { 00162 ACS_SHORT_LOG((LM_INFO, "CLOSE")); 00163 fridge->close(); 00164 } 00165 else 00166 { 00167 // User specified some non-existant command 00168 ACS_SHORT_LOG((LM_INFO, "Unknown command")); 00169 } 00170 } 00171 catch(maciErrType::CannotGetComponentExImpl &_ex) 00172 { 00173 _ex.log(); 00174 return -1; 00175 } 00176 catch(...) 00177 { 00178 ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__, 00179 "main"); 00180 uex.log(); 00181 return -1; 00182 } 00183 00184 try 00185 { 00186 //Release the component and log out from manager. 00187 ACS_SHORT_LOG((LM_INFO,"Releasing...")); 00188 client.releaseComponent(argv[1]); 00189 client.logout(); 00190 } 00191 catch(maciErrType::CannotReleaseComponentExImpl &_ex) 00192 { 00193 _ex.log(); 00194 return -1; 00195 } 00196 catch(...) 00197 { 00198 ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__, 00199 "main"); 00200 uex.log(); 00201 }//try-catch 00202 00203 // sleep for 3 sec. 00204 ACE_OS::sleep(3); 00205 return 0; 00206 } 00210 /*___oOo___*/ 00211 00212 00213