/*******************************************************************************
* ALMA - Atacama Large Millimiter Array
* (c) European Southern Observatory, 2002
* Copyright by ESO (in the framework of the ALMA collaboration)
* and Cosylab 2002, All rights reserved
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* "@(#) $Id: acsexmplClientAmsSeq.cpp,v 1.9 2007/02/01 05:14:26 cparedes Exp $"
*
* who when what
* -------- ---------- ----------------------------------------------
*
* david 2002-06-13 Added a check for client.int()
*/
/** @file acsexmplClientAmsSeq.cpp
* @htmlonly
*
@endhtmlonly
* @param "component name" Use this required parameter to specify which AMS object
* should be activated.
* @param "pointing model values" Use this required parameter to specify which 12 values the pointing model should become.
* @htmlonly
@endhtmlonly
* @param "-ORBEndpoint iiop://yyy:xxxx" Use this optional parameter to specify which host/port SimpleClient
* should run on.
* @htmlonly
@endhtmlonly
* @param "-m corbaloc::yyy:xxxx/Manager" Use this optional parameter to specify where
* manager is.
* @htmlonly
@endhtmlonly
*/
/** @addtogroup ACSEXMPLTOC
*/
/*@{
*/
/** @addtogroup ACSEXMPLTOCCLIENTS
*/
/*@{
*/
/** @defgroup ACSEXMPLCLIENTAMSSEQDOC Client AmsSeq
* @{
* @htmlonly
Description
This example shows a client that:
- logs into manager
- gets a reference to an Antenna Mount Sequence component specified from the command-line
- takes a read-only double sequence property from the component and prints out its values
- sets a read-write double sequence property and then invokes an IDL method
- logs out of manager
What can I gain from this example?
- SimpleClient usage.
- Manipulation of BACI sequence properties.
- ACS logging mechanisms.
- Accessing (remote) components.
Links
@endhtmlonly
* @}
*/
/* @}*/
/* @}*/
#include
#include
#include
#include
using namespace maci;
class TestCBdoubleSeq: public virtual POA_ACS::CBdoubleSeq
{
public:
TestCBdoubleSeq(std::string _prop, int c=5, int dc=1) : prop(_prop), count(c), done_c(dc) {}
virtual void working (
const ACS::doubleSeq& value,
const ACSErr::Completion & c,
const ACS::CBDescOut & desc
)
{
if (count>0)
{
CompletionImpl completion(c);
if (completion.isErrorFree())
{
printf("CBdouble::working desc.id_tag: %u\n", (unsigned)desc.id_tag);
for(unsigned i=0;i 0 )
{
/*
ACS_SHORT_LOG((LM_INFO, "(%s::CBdouble::done) desc.id_tag: %u Value: %f TimeStamp: ",
prop.c_str(), (unsigned)desc.id_tag, value));
*/
}//if
done_c--;
}
virtual CORBA::Boolean negotiate (
ACS::TimeInterval time_to_transmit,
const ACS::CBDescOut & desc
)
{
return 1;
}
int getCount(){ return count+done_c;}
protected:
std::string prop;
int count, done_c;
}; /* end TestCBdouble */
/*******************************************************************************/
/** @cond
*/
int main(int argc, char *argv[])
{
//Checks command-line arguments.
if (argc < 2)
{
ACS_SHORT_LOG((LM_INFO, "Usage: %s ", argv[0]));
return -1;
}
else
{
ACS_SHORT_LOG((LM_INFO, "Welcome to %s!", argv[0]));
}
//Creates and initializes the SimpleClient object
SimpleClient client;
if(client.init(argc, argv)==0)
{
ACE_DEBUG((LM_DEBUG,"Cannot initialize client"));
return -1;
}
else
{
client.login();
}
try
{
//get a reference to the component
AMSSEQ::AmsTestSeq_var amsseq = client.getComponent(argv[1], 0, true);
//Get the read-only sequence property from the component reference
ACS::ROdoubleSeq_var ROdoubleSeqPM_p = amsseq->ROdoubleSeqPM();
if (ROdoubleSeqPM_p.ptr() != ACS::ROdoubleSeq::_nil())
{
//synchronously reading the value of PM
ACSErr::Completion_var completion;
ACS::doubleSeq_var val_value = ROdoubleSeqPM_p->get_sync(completion.out());
if (val_value.ptr() == 0)
{
ACS_SHORT_LOG((LM_INFO,"acsexmplAmsSeqClient: .. null value returned."));
}
else
{
ACS_SHORT_LOG((LM_INFO,"acsexmplAmsSeqClient: .. value is (length %u):", val_value->length()));
for (CORBA::ULong i = 0; i < val_value->length(); i++)
{
ACS_SHORT_LOG((LM_INFO,"\t(%u): %f", i, val_value[i]));
}
}
}
ACS::CBDescIn desc = {0,0,0};
//get the read-write sequence property from the component reference
ACS::RWdoubleSeq_var m_RWdoubleSeqPM_p = amsseq->RWdoubleSeqPM();
if (m_RWdoubleSeqPM_p.ptr() != ACS::RWdoubleSeq::_nil())
{
/* here we want to check on change only for double Seq
TestCBdoubleSeq* mcb1 = new TestCBdoubleSeq("ROdoubleSeqProp1s", 60);
ACS::CBdoubleSeq_var cb1 = mcb1->_this();
desc.id_tag = 1;
ACS::Monitordouble_var md = m_RWdoubleSeqPM_p->create_monitor(cb1.in(), desc);
md->set_timer_trigger(0);//10000000
md->set_value_trigger(5.0, true);
*/
ACS::doubleSeq_var val_value = new ACS::doubleSeq;
ACSErr::Completion_var completion;
//must explicitly allocate the length of sequences
val_value->length(12);
//store the value of the pointing model locally first
for( CORBA::ULong i = 0 ; i < val_value->length() ; i ++ )
{
val_value[i] = atof(argv[i+2]);
}
if (val_value.ptr() == 0)
{
ACS_SHORT_LOG((LM_INFO,"acsexmplAmsSeqClientSet: .. null value set."));
}
else
{
ACS_SHORT_LOG((LM_INFO,"acsexmplAmsSeqClientSet: .. new value to be set is (length %u):", val_value->length()));
completion = m_RWdoubleSeqPM_p->set_sync(val_value.in());
//some error may have occured...
if(completion->type != ACSErr::ACSErrTypeOK)
{
ACS_SHORT_LOG((LM_INFO, "acsexmplAmsSeqClientSet: .. Error in set_sync."));
}
}
/* Read back the value of PM */
ACS::doubleSeq_var read_value = m_RWdoubleSeqPM_p->get_sync(completion.out());
if (read_value.ptr() == 0)
{
ACS_SHORT_LOG((LM_INFO,"acsexmplAmsSeqClient: .. null value returned."));
}
else
{
ACS_SHORT_LOG((LM_INFO,"acsexmplAmsSeqClient: .. value is (length %u):", val_value->length()));
for (CORBA::ULong i = 0; i < read_value->length(); i++)
{
ACS_SHORT_LOG((LM_INFO,"\t(%u): %f", i, read_value[i]));
}
}
}
ACS_SHORT_LOG((LM_INFO, "Binding value to ROdoubleSeq"));
//simply set the coefficient
amsseq->setCoeff();
}
catch(maciErrType::CannotGetComponentExImpl &_ex)
{
_ex.log();
return -1;
}
catch (...)
{
ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__,
"main");
uex.log();
return -1;
}
try
{
//client.run();
//must cleanly release the component and log out from manager
ACS_SHORT_LOG((LM_INFO,"Releasing..."));
client.releaseComponent(argv[1]);
client.logout();
}
catch(maciErrType::CannotReleaseComponentExImpl &_ex)
{
_ex.log();
return -1;
}
catch(...)
{
ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__,
"main");
uex.log();
return -1;
}
// sleep for 3 seconds so the modular test is deterministic
ACE_OS::sleep(3);
return 0;
}
/** @endcond
*/
/*___oOo___*/