ALMA Computing Group

acscourseMount5Impl.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 *    ALMA - Atacama Large Millimiter Array
00003 *    (c) Associated Universities Inc., 2002 *
00004 *    (c) European Southern Observatory, 2002
00005 *    Copyright by ESO (in the framework of the ALMA collaboration)
00006 *    and Cosylab 2002, All rights reserved
00007 *
00008 *    This library is free software; you can redistribute it and/or
00009 *    modify it under the terms of the GNU Lesser General Public
00010 *    License as published by the Free Software Foundation; either
00011 *    version 2.1 of the License, or (at your option) any later version.
00012 *
00013 *    This library is distributed in the hope that it will be useful,
00014 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 *    Lesser General Public License for more details.
00017 *
00018 *    You should have received a copy of the GNU Lesser General Public
00019 *    License along with this library; if not, write to the Free Software
00020 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00021 *
00022 *
00023 *
00024 * "@(#) $Id: acscourseMount5Impl.cpp,v 1.10 2008/10/02 08:58:19 cparedes Exp $"
00025 *
00026 */
00027  
00028 #include <acscourseMount5Impl.h>
00029 #include <iostream>
00030 
00031 using namespace std;
00032 
00033 /* ----------------------------------------------------------------*/
00045 void myHandlerFunction(ACSCOURSE_MOUNT::MountEventData joe, void *handlerParam)
00046 {
00047     ACS_SHORT_LOG((LM_INFO,"Handler: Received objfix command. Az: %f El: %f", joe.Azimuth, joe.Elevation));
00048 }
00049 
00050 /* ----------------------------------------------------------------*/
00051 Mount5Impl::Mount5Impl(const ACE_CString &_name, maci::ContainerServices *containerServices) :
00052     CharacteristicComponentImpl(_name, containerServices),
00053     m_cmdAz_sp(new baci::ROdouble(_name+":cmdAz", getComponent()),this),
00054     m_cmdEl_sp(new baci::ROdouble(_name+":cmdEl", getComponent()),this),
00055     m_actAz_sp(new baci::ROdouble(_name+":actAz", getComponent()),this),
00056     m_actEl_sp(new baci::ROdouble(_name+":actEl", getComponent()),this),
00057     m_MountSupplier_p(0),
00058     m_simpConsumer_p(0)
00059 {
00060     // ACS_TRACE is used for debugging purposes
00061     ACS_TRACE("::Mount5Impl::Mount5Impl");
00062 
00063     // Handle supplier creation here.
00064     // - ACSCOURSE_MOUNT::MOUNT_CHANNEL is the name of the channel these events will be published too
00065     m_MountSupplier_p =  new nc::SimpleSupplier(ACSCOURSE_MOUNT::MOUNT_CHANNEL, this);
00066 
00067     // Handle consumer creation here.
00068     // - m_simpConsumer_p is a SimpleConsumer pointer
00069     // - ACSCOURSE_MOUNT::MountEventData is the event that will be consumed
00070     // - ACSCOURSE_MOUNT::MOUNT_CHANNEL is the name of the channel these events will come from
00071     // - myHandlerFunction is the function that will be automatically invoked each time an event is received
00072     ACS_NEW_SIMPLE_CONSUMER(m_simpConsumer_p, ACSCOURSE_MOUNT::MountEventData, ACSCOURSE_MOUNT::MOUNT_CHANNEL, myHandlerFunction, 0);
00073 
00074     //Let the channel know we are ready to begin processing events.
00075     //After consumerReady has been invoked on the Consumer object, we 
00076     //have very little control over when myHandlerFunction is invoked.
00077     m_simpConsumer_p->consumerReady();
00078 }
00079 /* ----------------------------------------------------------------*/
00080 Mount5Impl::~Mount5Impl()
00081 {
00082     // ACS_TRACE is used for debugging purposes
00083     ACS_TRACE("::Mount5Impl::~Mount5Impl");
00084     ACS_DEBUG_PARAM("::Mount5Impl::~Mount5Impl", "Destroying %s...", name());
00085 
00086     // clean-up associated with the supplier object
00087     if (m_MountSupplier_p != 0)
00088         {
00089         m_MountSupplier_p->disconnect();
00090         m_MountSupplier_p=0;
00091         }
00092 
00093     // clean-up associated with the consumer object
00094     if (m_simpConsumer_p != 0)
00095         {
00096         m_simpConsumer_p->disconnect();
00097         m_simpConsumer_p=0;
00098         }
00099 }
00100 /* --------------------- [ CORBA interface ] ----------------------*/
00101 void 
00102 Mount5Impl::objfix (CORBA::Double az,
00103                     CORBA::Double elev)
00104 {
00105     ACS_TRACE("::Mount5Impl::objfix");
00106     ACS_SHORT_LOG((LM_INFO,"Received objfix command. Az: %f El: %f", az, elev));
00107     
00108     ACS::Time timestamp;
00109     
00110     try
00111         {
00112         m_cmdAz_sp->getDevIO()->write(az,   timestamp);
00113         m_cmdEl_sp->getDevIO()->write(elev, timestamp);
00114 
00115         m_actAz_sp->getDevIO()->write(az,   timestamp);
00116         m_actEl_sp->getDevIO()->write(elev, timestamp);
00117 
00118         //Create the data to be published on the event channel
00119         ACSCOURSE_MOUNT::MountEventData data;
00120         data.Azimuth = az;
00121         data.Elevation = elev;
00122         
00123         //Publish the data to the event channel
00124         m_MountSupplier_p->publishData<ACSCOURSE_MOUNT::MountEventData>(data);
00125         }
00126     catch (...) 
00127         {
00128         // Here we have to better handle errors!
00129         ACS_SHORT_LOG((LM_ERROR,"Error accessing devIO"));
00130         }
00131     
00132 }
00133 
00134 ACS::ROdouble_ptr
00135 Mount5Impl::cmdAz ()
00136 {
00137     if (m_cmdAz_sp == 0)
00138         {
00139         return ACS::ROdouble::_nil();
00140         }
00141 
00142     ACS::ROdouble_var prop = ACS::ROdouble::_narrow(m_cmdAz_sp->getCORBAReference());
00143     return prop._retn();
00144 }
00145 
00146 
00147 ACS::ROdouble_ptr
00148 Mount5Impl::cmdEl ()
00149 {
00150     if (m_cmdEl_sp == 0)
00151         {
00152         return ACS::ROdouble::_nil();
00153         }
00154 
00155     ACS::ROdouble_var prop = ACS::ROdouble::_narrow(m_cmdEl_sp->getCORBAReference());
00156     return prop._retn();
00157 }
00158 
00159 
00160 ACS::ROdouble_ptr
00161 Mount5Impl::actAz ()
00162 {
00163     if (m_actAz_sp == 0)
00164         {
00165         return ACS::ROdouble::_nil();
00166         }
00167 
00168     ACS::ROdouble_var prop = ACS::ROdouble::_narrow(m_actAz_sp->getCORBAReference());
00169     return prop._retn();
00170 }
00171 
00172 
00173 ACS::ROdouble_ptr
00174 Mount5Impl::actEl ()
00175 {
00176     if (m_actEl_sp == 0)
00177         {
00178         return ACS::ROdouble::_nil();
00179         }
00180     
00181     ACS::ROdouble_var prop = ACS::ROdouble::_narrow(m_actEl_sp->getCORBAReference());
00182     return prop._retn();
00183 }
00184 
00185 /* --------------- [ MACI DLL support functions ] -----------------*/
00186 #include <maciACSComponentDefines.h>
00187 MACI_DLL_SUPPORT_FUNCTIONS(Mount5Impl)
00188 /* ----------------------------------------------------------------*/
00189 
00190 
00191 /*___oOo___*/
00192