/*******************************************************************************
* 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: acsexmplClientWave.cpp,v 1.102 2007/02/01 05:14:26 cparedes Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* david 2002-06-17 fixed client.init(argc,argv)
* gchiozzi 2002-02-13 cleane up
* msekoran 2001/07/13 created
*/
/** @file acsexmplClientWave.cpp
* @htmlonly
*
@endhtmlonly
* @param "component name" Use this required parameter to specify which component
* should be activated.
* @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 ACSEXMPLCLIENTWAVEDOC Client Wave
* @{
* @htmlonly
Description
This example shows a client that:
logs into manager
gets a MOUNT component
spawns a thread
calls the mount->objfix() command from within the thread setting the mount position in a sin() wave
@endhtmlonly
* @}
*/
/* @}*/
/* @}*/
#include
#include
#include "acsexmplCallbacks.h"
#include
#include
using namespace ACS;
using namespace maci;
//ATTENTION:
//For the time being use global variable. Not clean.
int LENGTH = 10;
int INTERVAL = 1;
int ITERATIONS = 0;
/**
* This is the worker function for the thread
* that calls the objfix command
* @param A ThreadBaseParameter which contains a reference to the component we need.
* @return void
* @htmlonly
@endhtmlonly
*/
class WorkerThread : public ACS::Thread
{
public:
WorkerThread(const ACE_CString& name,
MOUNT_ACS::Mount * mount,
const ACS::TimeInterval& responseTime=ThreadBase::defaultResponseTime,
const ACS::TimeInterval& sleepTime=ThreadBase::defaultSleepTime) :
ACS::Thread(name, responseTime, sleepTime),
myCallback("objfix")
{
ACS_TRACE("WorkerThread::WorkerThread");
mount_p = mount;
cbv = myCallback._this();
}
~WorkerThread() {
ACS_TRACE("WorkerThread::~WorkerThread");
}
virtual void onStart()
{
az = 0; el = 0; count = 0;
}
virtual void runLoop()
{
//while there are still values that need to be set...
if (ITERATIONS<=0)
exit();
ACS::CBDescIn desc;
try
{
//perform a few miscellaneous operations on the azimuth and
//elevation the telescope will move to.
az = sin(count * 0.157) * 200 - 100;
el = sin(count * 0.157) * 90;
//move the telescope asynchronously
ACS_SHORT_LOG((LM_INFO, "%s: Going to (%f,%f)", getName().c_str(),az,el));
mount_p->objfix(az, el, cbv.in(), desc);
count = count++==10 ? 0 : count;
//make sure we stop moving the telescope at some point.
ITERATIONS--;
}
catch(...)
{
ACS_SHORT_LOG((LM_ERROR,"Error!"));
}
ACE_OS::fflush(stdout);
}
virtual void onStop()
{
ACS_SHORT_LOG((LM_INFO, "%s: OK", getName().c_str()));
}
private:
MOUNT_ACS::Mount * mount_p;
double az, el;
int count;
MyCBvoid myCallback;
ACS::CBvoid_var cbv;
};
/*******************************************************************************/
/** @cond
*/
int main(int argc, char *argv[])
{
//Checks command-line arguments.
if (argc < 4)
{
ACS_SHORT_LOG((LM_INFO, "Usage: %s