ALMA Computing Group

acsexmplBuildingImpl.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 *
00023 * "@(#) $Id: acsexmplBuildingImpl.cpp,v 1.127 2008/10/09 08:41:11 cparedes Exp $"
00024 *
00025 * who       when      what
00026 * --------  --------  ----------------------------------------------
00027 * dave 2003-08-25 release_COB on the door after we're done with it.
00028 * gchiozzi 2003-04-09 Replaced writeXXXX with write
00029 * oat 2002-12-17 Templatization of the ContainerImpl.get_object method
00030 * david 2002-06-18 removed Building::invokeAction as there are no asynchronous calls in this class
00031 * bgustafs 2002-04-09 modified for VxWorks
00032 * almamgr 2002-04-07 Removed poa parameter from call to ConstructorEpilogue()
00033 * blopez   2002-04-05 writeLong changed to writeString at version initialization
00034 * gchiozzi 2002-04-04 Replaced set_sync() with getDevIO()->write<T>()
00035 * jib/blo  2002-04-02 Created
00036 */
00037 
00038 #include <acsexmplBuildingImpl.h>
00039 
00040 //Because of bugs in the ContainerServices...we default to using this
00041 #include <maciContainerImpl.h>
00042 
00043 //Used to access other components, activate "OffShoot"s, etc.
00044 #include <maciContainerServices.h>
00045 
00046 #include <iostream>
00047 
00052 ACE_RCSID(acsexmpl, acsexmplBuildingImpl, "$Id: acsexmplBuildingImpl.cpp,v 1.127 2008/10/09 08:41:11 cparedes Exp $")
00053 
00054 using namespace baci;
00055 using namespace maci;
00056 
00057 // Building Constructor
00058 Building::Building(
00059                    const ACE_CString &name,
00060                    maci::ContainerServices * containerServices) : 
00061     CharacteristicComponentImpl(name, containerServices),
00062     // Create the smart pointer for the ROsttring property
00063     m_version_sp(new ROstring(name+":version", getComponent()),this),
00064     m_door_p(acsexmplBuilding::Door::_nil())
00065 {
00066     ACS_TRACE("::Building::Building");
00067 }
00068 
00069 void
00070 Building::execute()
00071 {
00072     ACS_SHORT_LOG((LM_INFO,"Building::execute"));
00073     
00074     /*
00075      * Get a reference to the front door
00076      */    
00077 
00078     /*
00079      * Get the component "<name>/FRONTDOOR"
00080      */
00081     ACE_CString frontDoorCobName(this->name());
00082     frontDoorCobName += "/FRONTDOOR";
00083     
00084     // Use container to activate the door object
00085     ACS_SHORT_LOG((LM_INFO, "Getting component: %s", frontDoorCobName.c_str() ));
00086     
00087     m_door_p = acsexmplBuilding::Door::_nil();
00088 
00089     m_door_p = getContainerServices()->getComponent<acsexmplBuilding::Door>(frontDoorCobName.c_str());    
00090 
00091     if (CORBA::is_nil(m_door_p.in()))
00092         {
00093         throw acsErrTypeLifeCycle::LifeCycleExImpl(__FILE__, __LINE__, "::Building::execute");
00094         }
00095     // Set current version - the devIO will write values to errcode and 
00096     // timestamp. In this simple example, we don't really care what values
00097     // it sets.
00098     ACS::Time timestamp;
00099     // Write out the version number to the property.
00100     m_version_sp->getDevIO()->write(rcsid_acsexmpl_acsexmplBuildingImpl, timestamp);
00101     
00102 }
00103 
00104 // Building Destructor
00105 void Building::cleanUp()
00106 {
00107     ACS_TRACE("::Building::cleanUp");
00108 
00109     // must release the door component
00110     if(CORBA::is_nil(m_door_p.in()) == false)
00111         {
00112         ACS_LOG(LM_RUNTIME_CONTEXT, "::Building::cleanUp",
00113                 (LM_DEBUG, "Releasing /FRONTDOOR"));
00114         //generate the door's name again
00115         ACE_CString frontDoorCobName(this->name());
00116         frontDoorCobName += "/FRONTDOOR";
00117 
00118         getContainerServices()->releaseComponent(frontDoorCobName.c_str());
00119 
00120         // be sure to set the reference to nil
00121         m_door_p = acsexmplBuilding::Door::_nil();
00122         }
00123     
00124 }
00125 
00126 // Building Destructor
00127 Building::~Building()
00128 {
00129     ACS_TRACE("::Building::~Building");
00130     
00131     // I cannot call cleanUp() here, because the cleanUp() requires access to CORBA
00132     // to release the Door.
00133     // It is always bad practice to call cleanUp in the destructor.
00134     // It can be done just as an "emergency procedure" in the classes where it 
00135     // does not cause trouble.
00136 }
00137 
00138 /* --------------------- [ CORBA interface ] ----------------------*/
00139 void
00140 Building::openFrontDoor ()
00141 {
00142     try 
00143         {
00144         //Always check to ensure the door reference is valid!
00145         if (CORBA::is_nil(m_door_p.in()) == false)
00146             {       
00147             ACS_SHORT_LOG((LM_INFO,"*** Opening the front door ... ***"));
00148             
00149             // Execute the method move() of class Door
00150             double pos = 0.0;
00151             m_door_p->move(pos);
00152             } 
00153         }
00154     catch(...)
00155         {
00156         // TBD: Exception handling 
00157         ACS_SHORT_LOG((LM_ERROR, "::Building::openFrontDoor"));
00158         }
00159 }
00160 
00161 void
00162 Building::closeFrontDoor ()
00163 {
00164     try 
00165         {
00166         //Always check to ensure the door reference is valid!
00167         if (CORBA::is_nil(m_door_p.in()) == false)
00168             {
00169             ACS_SHORT_LOG((LM_INFO,"*** Closing the front door ... ***"));
00170             // Execute the method move() of class Door
00171             double pos = 100.0;
00172             m_door_p->move(pos);    
00173             }
00174         }
00175     catch(...)
00176         {
00177         // TBD: Exception handling 
00178         ACS_SHORT_LOG((LM_ERROR, "::Building::closeFrontDoor"));
00179         }
00180 }
00181 
00182 ACS::ROstring_ptr
00183 Building::version ()
00184 {
00185     if (m_version_sp == 0)
00186         {
00187         return ACS::ROstring::_nil();
00188         }
00189     
00190     ACS::ROstring_var prop = ACS::ROstring::_narrow(m_version_sp->getCORBAReference());
00191     return prop._retn();
00192 }
00193 
00194 /* --------------- [ MACI DLL support functions ] -----------------*/
00195 #include <maciACSComponentDefines.h>
00196 MACI_DLL_SUPPORT_FUNCTIONS(Building)
00197 /* ----------------------------------------------------------------*/
00198 
00199