ServiceRequesterI.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: The SourceWorks  Tue Sep 7 00:55:18 CEST 2010  ServiceRequesterI.cpp
00003 
00004                         ServiceRequesterI.cpp -  description
00005                            -------------------
00006     begin                : Tue September 07 2010
00007     copyright            : (C) 2010 The SourceWorks
00008     email                : peter@thesourceworks.com
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 // -*- C++ -*-
00040 //
00041 // $Id$
00042 
00043 // ****  Code generated by the The ACE ORB (TAO) IDL Compiler ****
00044 // TAO and the TAO IDL Compiler have been developed by:
00045 //       Center for Distributed Object Computing
00046 //       Washington University
00047 //       St. Louis, MO
00048 //       USA
00049 //       http://www.cs.wustl.edu/~schmidt/doc-center.html
00050 // and
00051 //       Distributed Object Computing Laboratory
00052 //       University of California at Irvine
00053 //       Irvine, CA
00054 //       USA
00055 //       http://doc.ece.uci.edu/
00056 // and
00057 //       Institute for Software Integrated Systems
00058 //       Vanderbilt University
00059 //       Nashville, TN
00060 //       USA
00061 //       http://www.isis.vanderbilt.edu/
00062 //
00063 // Information about TAO is available at:
00064 //     http://www.cs.wustl.edu/~schmidt/TAO.html
00065 
00066 // TAO_IDL - Generated from
00067 // ../../../ACE_wrappers/TAO/TAO_IDL/be/be_codegen.cpp:1196
00068 
00069 #include "ServiceRequesterI.h"
00070 #include "CorbaOperationCallerFactory.hpp"
00071 #include "TaskContext.hpp"
00072 
00073 using namespace RTT;
00074 using namespace RTT::detail;
00075 
00076 // Implementation skeleton constructor
00077 RTT_corba_CServiceRequester_i::RTT_corba_CServiceRequester_i ( RTT::ServiceRequester::shared_ptr service, PortableServer::POA_ptr poa )
00078     : mservice(service), mpoa( PortableServer::POA::_duplicate(poa) )
00079 {
00080 }
00081 
00082 // Implementation skeleton destructor
00083 RTT_corba_CServiceRequester_i::~RTT_corba_CServiceRequester_i (void)
00084 {
00085 }
00086 
00087 char * RTT_corba_CServiceRequester_i::getRequestName (
00088     void)
00089 {
00090     return CORBA::string_dup( mservice->getRequestName().c_str() );
00091 }
00092 
00093 ::RTT::corba::CRequestNames * RTT_corba_CServiceRequester_i::getRequestNames (
00094     void)
00095 {
00096     ServiceRequester::RequesterNames names = mservice->getRequesterNames();
00097     ::RTT::corba::CRequestNames_var result = new ::RTT::corba::CRequestNames();
00098     result->length( names.size() );
00099     for (unsigned int i=0; i != names.size(); ++i )
00100         result[i] = CORBA::string_dup( names[i].c_str() );
00101 
00102     return result._retn();
00103 }
00104 
00105 ::RTT::corba::COperationCallerNames * RTT_corba_CServiceRequester_i::getOperationCallerNames (
00106     void)
00107 {
00108     ServiceRequester::OperationCallerNames names = mservice->getOperationCallerNames();
00109     ::RTT::corba::COperationCallerNames_var result = new ::RTT::corba::COperationCallerNames();
00110     result->length( names.size() );
00111     for (unsigned int i=0; i != names.size(); ++i )
00112         result[i] = CORBA::string_dup( names[i].c_str() );
00113 
00114     return result._retn();
00115 }
00116 
00117 ::RTT::corba::CServiceRequester_ptr RTT_corba_CServiceRequester_i::getRequest (
00118     const char * service_name)
00119 {
00120     std::string svc(service_name);
00121     if ( svc == "this" )
00122         return _this();
00123 
00124     if ( mservice->requiresService(service_name) == false )
00125         return RTT::corba::CServiceRequester::_nil();
00126 
00127     // Creates service requester
00128     if ( mrequests.find(svc) == mrequests.end() ) {
00129         log(Debug) << "Creating CServiceRequester for "<< service_name <<endlog();
00130         RTT_corba_CServiceRequester_i* mserv;
00131         mserv = new RTT_corba_CServiceRequester_i( mservice->requires(service_name), mpoa );
00132         CServiceRequester_ptr request = mserv->activate_this();
00133         mrequests[svc] = std::pair<RTT::corba::CServiceRequester_var, PortableServer::ServantBase_var>(request,mserv);
00134     }
00135     // Now return it.
00136     return RTT::corba::CServiceRequester::_duplicate( mrequests[svc].first.in() );
00137 }
00138 
00139 ::CORBA::Boolean RTT_corba_CServiceRequester_i::hasRequest (
00140     const char * name)
00141 {
00142     return mservice->requiresService( name );
00143 }
00144 
00145 ::CORBA::Boolean RTT_corba_CServiceRequester_i::connectTo (
00146     ::RTT::corba::CService_ptr svc)
00147 {
00148     ServiceRequester::OperationCallerNames names = mservice->getOperationCallerNames();
00149 
00150     for (unsigned int i=0; i != names.size(); ++i )
00151         connectCallerTo( names[i].c_str(), svc);
00152 
00153     return mservice->ready();;
00154 }
00155 
00156 ::CORBA::Boolean RTT_corba_CServiceRequester_i::connectCallerTo (
00157       const char * name,
00158       ::RTT::corba::CService_ptr svc)
00159 {
00160     std::string oname(name);
00161     if ( mservice->getOperationCaller(oname) == 0) {
00162         log(Error) << "No such OperationCaller: " << oname << " in "<< mservice->getRequestName()<<endlog();
00163         return false;
00164     }
00165     if ( svc->getArity(oname.c_str()) == -1) {
00166         CORBA::String_var svcname = svc->getName();
00167         log(Error) << "No such Operation: " << oname << " in "<< svcname.in() << endlog();
00168         return false;
00169     }
00170 
00171     // creates a local factory for this remote method.
00172     OperationInterfacePart* tmp = new CorbaOperationCallerFactory(oname,svc, mpoa.in() );
00173     return mservice->getOperationCaller(oname)->setImplementationPart( tmp, mservice->getServiceOwner()->engine() );
00174 }
00175 
00176 ::CORBA::Boolean RTT_corba_CServiceRequester_i::disconnectCaller (
00177       const char * name )
00178 {
00179     std::string oname(name);
00180     if ( mservice->getOperationCaller(oname) == 0) {
00181         log(Error) << "No such OperationCaller: " << oname << " in "<< mservice->getRequestName()<<endlog();
00182         return false;
00183     }
00184     // disconnects.
00185     mservice->getOperationCaller(oname)->disconnect();
00186     return true;
00187 }
00188 
00189 ::CORBA::Boolean RTT_corba_CServiceRequester_i::callerReady (
00190       const char * name )
00191 {
00192     std::string oname(name);
00193     if ( mservice->getOperationCaller(oname) == 0) {
00194         log(Error) << "No such OperationCaller: " << oname << " in "<< mservice->getRequestName()<<endlog();
00195         return false;
00196     }
00197     // disconnects.
00198     return mservice->getOperationCaller(oname)->ready();
00199 }
00200 
00201 ::CORBA::Boolean RTT_corba_CServiceRequester_i::ready (
00202     void)
00203 {
00204     return mservice->ready();
00205 }
00206 
00207 void RTT_corba_CServiceRequester_i::disconnect (
00208     void)
00209 {
00210     mservice->disconnect();
00211 }
00212 
00213 


rtt
Author(s): RTT Developers
autogenerated on Wed Aug 26 2015 16:15:53