ALMA Computing Group

acsexmplClientAmsSeq.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: acsexmplClientAmsSeq.cpp,v 1.9 2007/02/01 05:14:26 cparedes Exp $"
00023 *
00024 * who       when        what
00025 * --------  ----------  ----------------------------------------------
00026 *
00027 * david     2002-06-13  Added a check for client.int()
00028 */
00029 
00055 
00060 
00097 /* @}*/
00098 /* @}*/
00099 
00100 #include <maciSimpleClient.h>
00101 #include <ACSErrTypeOK.h>
00102 #include <acsexmplAmsSeqC.h>
00103 
00104 
00105 ACE_RCSID(acsexmpl, acsexmplAmsSeqClient, "$Id: acsexmplClientAmsSeq.cpp,v 1.9 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> <pointing model double values> <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 initialize client"));
00130         return -1;
00131         }
00132     else
00133         {
00134         client.login();
00135         }
00136 
00137     try
00138         {
00139         //get a reference to the component
00140         AMSSEQ::AmsTestSeq_var amsseq = client.getComponent<AMSSEQ::AmsTestSeq>(argv[1], 0, true);
00141         
00142 
00143         //Get the read-only sequence property from the component reference
00144         ACS::ROdoubleSeq_var ROdoubleSeqPM_p = amsseq->ROdoubleSeqPM();
00145         if (ROdoubleSeqPM_p.ptr() != ACS::ROdoubleSeq::_nil())
00146             {
00147             //synchronously reading the value of PM
00148             ACSErr::Completion_var completion;
00149             ACS::doubleSeq_var val_value = ROdoubleSeqPM_p->get_sync(completion.out());
00150             
00151             if (val_value.ptr() == 0)
00152                 {
00153                 ACS_SHORT_LOG((LM_INFO,"acsexmplAmsSeqClient: .. null value returned."));
00154                 }
00155             else
00156                 {
00157                 ACS_SHORT_LOG((LM_INFO,"acsexmplAmsSeqClient: .. value is (length %u):", val_value->length()));
00158                 for (CORBA::ULong i = 0; i < val_value->length(); i++)
00159                     {
00160                     ACS_SHORT_LOG((LM_INFO,"\t(%u): %f", i, val_value[i]));
00161                     }
00162                 }
00163             }
00164    
00165         //get the read-write sequence property from the component reference
00166         ACS::RWdoubleSeq_var m_RWdoubleSeqPM_p = amsseq->RWdoubleSeqPM();
00167         if (m_RWdoubleSeqPM_p.ptr() != ACS::RWdoubleSeq::_nil())
00168             {
00169             ACS::doubleSeq_var val_value = new ACS::doubleSeq;
00170             ACSErr::Completion_var completion;
00171             
00172             //must explicitly allocate the length of sequences
00173             val_value->length(12);
00174             
00175             //store the value of the pointing model locally first
00176             for( CORBA::ULong i = 0 ; i < val_value->length() ; i ++ )
00177                 {
00178                 val_value[i] = atof(argv[i+2]);
00179                 }
00180             
00181             if (val_value.ptr() == 0)
00182                 {
00183                 ACS_SHORT_LOG((LM_INFO,"acsexmplAmsSeqClientSet: .. null value set."));
00184                 }
00185             else
00186                 {
00187                 ACS_SHORT_LOG((LM_INFO,"acsexmplAmsSeqClientSet: .. new value to be set is (length %u):", val_value->length()));
00188                 completion = m_RWdoubleSeqPM_p->set_sync(val_value.in());
00189                 //some error may have occured...
00190                 if(completion->type != ACSErr::ACSErrTypeOK)
00191                     {
00192                     ACS_SHORT_LOG((LM_INFO, "acsexmplAmsSeqClientSet: .. Error in set_sync."));
00193                     }
00194                 }
00195             
00196             /* Read  back the value of PM */
00197             ACS::doubleSeq_var read_value = m_RWdoubleSeqPM_p->get_sync(completion.out());
00198             if (read_value.ptr() == 0)
00199                 {
00200                 ACS_SHORT_LOG((LM_INFO,"acsexmplAmsSeqClient: .. null value returned."));
00201                 }
00202             else
00203                 {
00204                 ACS_SHORT_LOG((LM_INFO,"acsexmplAmsSeqClient: .. value is (length %u):", val_value->length()));
00205                 for (CORBA::ULong i = 0; i < read_value->length(); i++)
00206                     {
00207                     ACS_SHORT_LOG((LM_INFO,"\t(%u): %f", i, read_value[i]));
00208                     }
00209                 }
00210             } 
00211         
00212         ACS_SHORT_LOG((LM_INFO, "Binding value to ROdoubleSeq"));
00213         //simply set the coefficient
00214         amsseq->setCoeff();
00215         }
00216     catch(maciErrType::CannotGetComponentExImpl &_ex)
00217         {
00218         _ex.log();
00219         return -1;
00220         }
00221     catch (...)
00222         {
00223         ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__, 
00224                                                         "main");
00225         uex.log();
00226         return -1;
00227         }    
00228     
00229     try
00230         {
00231         //must cleanly release the component and log out from manager   
00232         ACS_SHORT_LOG((LM_INFO,"Releasing..."));
00233         client.releaseComponent(argv[1]);
00234         client.logout();
00235         }
00236     catch(maciErrType::CannotReleaseComponentExImpl &_ex)
00237         {
00238         _ex.log();
00239         return -1;
00240         }
00241     catch(...)
00242         {
00243         ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__, 
00244                                                         "main");
00245         uex.log();
00246         return -1;
00247         }
00248     
00249     // sleep for 3 seconds so the modular test is deterministic
00250     ACE_OS::sleep(3);
00251     return 0;
00252 }
00253 
00256 /*___oOo___*/
00257 
00258 
00259 
00260