CommandProxy.cpp

00001 /***************************************************************************
00002   tag: Peter Soetens  Mon Jun 26 13:25:59 CEST 2006  CommandProxy.cxx 
00003 
00004                         CommandProxy.cxx -  description
00005                            -------------------
00006     begin                : Mon June 26 2006
00007     copyright            : (C) 2006 Peter Soetens
00008     email                : peter.soetens@fmtc.be
00009  
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
00035  *                                                                         *
00036  ***************************************************************************/
00037  
00038  
00039 
00040 #include "OperationsI.h"
00041 #include "CommandProxy.hpp"
00042 #include "ConditionInterface.hpp"
00043 
00044 #include <ace/String_Base.h>
00045 
00046 using namespace std;
00047 
00048 namespace RTT
00049 {namespace Corba
00050 {
00051 
00052     CommandProxy::CommandProxy( ::RTT::Corba::Command_ptr e) 
00053         : mdata( ::RTT::Corba::Command::_duplicate(e) )
00054     {
00055         try {
00056             mdata->reset(); // force connect to object.
00057         }
00058         catch (CORBA::Exception &e) {
00059             Logger::log() <<Logger::Error << "CORBA exception raised when creating CommandProxy!" << Logger::nl;
00060             Logger::log() << e._info().c_str() << Logger::endl;
00061         }
00062         catch (...) {
00063             throw;
00064         }
00065     }
00066 
00067     CommandProxy::~CommandProxy()
00068     {
00069     }
00070     
00071     namespace {
00072         struct ValidCondition
00073             : public ConditionInterface
00074         {
00075             ::RTT::Corba::Command_var mserver;
00076 
00077             ValidCondition( ::RTT::Corba::Command_ptr server )
00078                 : mserver(::RTT::Corba::Command::_duplicate(server) )
00079             {}
00080             bool evaluate()
00081             {
00082                 return mserver->done();
00083             }
00084             
00085             ValidCondition* clone() const
00086             {
00087                 return new ValidCondition( mserver.in() );
00088             }
00089 
00090             ValidCondition* copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const {
00091                 return this->clone();
00092             }
00093         };
00094     }
00095 
00096     ConditionInterface* CommandProxy::createCondition() const {
00097         return new ValidCondition( mdata.in() );
00098     }
00099 
00100 
00101     CommandProxy* CommandProxy::Create(::RTT::Corba::Command_ptr t) {
00102         if ( CORBA::is_nil( t ) )
00103             return 0;
00104 
00105         // create new:
00106         CommandProxy* ctp = new CommandProxy( t );
00107         return ctp;
00108     }
00109 
00110     Corba::Command_ptr CommandProxy::server() const
00111     {
00112         return Corba::Command::_duplicate( mdata.in() );
00113     }
00114 
00115 }}
00116 

Generated on Tue Mar 25 17:41:41 2008 for OrocosReal-TimeToolkit by  doxygen 1.5.3