Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow loading of global service plugins via the CORBA interface of each TaskContextProxy #228

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rtt/internal/FusedFunctorDataSource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "BindStorage.hpp"
#include "../ExecutionEngine.hpp"
#include "../os/oro_allocator.hpp"
#include "UnMember.hpp"
#include <boost/bind.hpp>
#include <boost/type_traits.hpp>
#include <boost/function.hpp>
Expand Down
108 changes: 60 additions & 48 deletions rtt/transports/corba/OperationInterfaceI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
#include "../../internal/SendHandleC.hpp"
#include "../../Logger.hpp"
#include "../../internal/GlobalEngine.hpp"
#include "../../plugin/PluginLoader.hpp"

using namespace RTT;
using namespace RTT::detail;
Expand Down Expand Up @@ -214,8 +215,11 @@ void RTT_corba_CSendHandle_i::dispose (

// Implementation skeleton constructor
RTT_corba_COperationInterface_i::RTT_corba_COperationInterface_i (OperationInterface* gmf, PortableServer::POA_ptr the_poa)
:mfact(gmf), mpoa( PortableServer::POA::_duplicate(the_poa))
: mfact(gmf), mpoa( PortableServer::POA::_duplicate(the_poa)),
loadPluginOperation("loadPlugin", &RTT_corba_COperationInterface_i::loadPlugin, this),
loadPluginOperationPart(&loadPluginOperation)
{
loadPluginOperation.doc("Loads a RTT plugin.").arg("plugin_path", "The path to the shared library containing the plugin.");
}

PortableServer::POA_ptr RTT_corba_COperationInterface_i::_default_POA()
Expand All @@ -235,6 +239,7 @@ ::RTT::corba::COperationInterface::COperationList * RTT_corba_COperationInterfac
RTT::corba::COperationInterface::COperationList_var rlist = new RTT::corba::COperationInterface::COperationList();

vector<string> flist = mfact->getNames();
flist.push_back(loadPluginOperationPart.getName());
rlist->length( flist.size() );
size_t drops=0;
for (size_t i=0; i != flist.size(); ++i)
Expand All @@ -251,10 +256,9 @@ ::RTT::corba::CDescriptions * RTT_corba_COperationInterface_i::getArguments (
const char * operation)
{
CDescriptions_var ret = new CDescriptions();
if ( mfact->hasMember( string( operation ) ) == false || mfact->isSynchronous(string(operation)))
throw ::RTT::corba::CNoSuchNameException( operation );
OperationInterfacePart* mofp = findOperation(operation);
// operation found, convert args:
OperationInterface::Descriptions args = mfact->getArgumentList( string(operation) );
OperationInterface::Descriptions args = mofp->getArgumentList();
ret->length( args.size() );
for (size_t i =0; i != args.size(); ++i) {
ret[i].name = CORBA::string_dup( args[i].name.c_str() );
Expand All @@ -267,82 +271,75 @@ ::RTT::corba::CDescriptions * RTT_corba_COperationInterface_i::getArguments (
char * RTT_corba_COperationInterface_i::getResultType (
const char * operation)
{
if ( mfact->hasMember( string( operation ) ) == false || mfact->isSynchronous(string(operation)) )
throw ::RTT::corba::CNoSuchNameException( operation );
return CORBA::string_dup( mfact->getResultType( string(operation) ).c_str() );
OperationInterfacePart* mofp = findOperation(operation);
return CORBA::string_dup( mofp->resultType().c_str() );
}

char* RTT_corba_COperationInterface_i::getArgumentType(
const char* operation,
CORBA::UShort nbr)
{
if ( mfact->hasMember( string( operation ) ) == false || mfact->isSynchronous(string(operation)) )
throw ::RTT::corba::CNoSuchNameException( operation );
if ( nbr > mfact->getPart(operation)->arity() )
throw ::RTT::corba::CWrongArgumentException( nbr, mfact->getPart(operation)->arity() );
return CORBA::string_dup( mfact->getPart( operation )->getArgumentType(nbr)->getTypeName().c_str() );
OperationInterfacePart* mofp = findOperation(operation);
if ( nbr > mofp->arity() )
throw ::RTT::corba::CWrongArgumentException( nbr, mofp->arity() );
return CORBA::string_dup( mofp->getArgumentType(nbr)->getTypeName().c_str() );
}

char* RTT_corba_COperationInterface_i::getCollectType(
const char* operation,
CORBA::UShort nbr)
{
if ( mfact->hasMember( string( operation ) ) == false || mfact->isSynchronous(string(operation)) )
throw ::RTT::corba::CNoSuchNameException( operation );
if ( nbr > mfact->getPart(operation)->collectArity() )
throw ::RTT::corba::CWrongArgumentException( nbr, mfact->getPart(operation)->collectArity() );
return CORBA::string_dup( mfact->getPart( operation )->getCollectType(nbr)->getTypeName().c_str() );
OperationInterfacePart* mofp = findOperation(operation);
if ( nbr > mofp->collectArity() )
throw ::RTT::corba::CWrongArgumentException( nbr, mofp->collectArity() );
return CORBA::string_dup( mofp->getCollectType(nbr)->getTypeName().c_str() );

}

::CORBA::UShort RTT_corba_COperationInterface_i::getArity (
const char * operation)
{
if ( mfact->hasMember( string( operation ) ) == false || mfact->isSynchronous(string(operation)) )
throw ::RTT::corba::CNoSuchNameException( operation );
return mfact->getPart(operation)->arity();
OperationInterfacePart* mofp = findOperation(operation);
return mofp->arity();
}

::CORBA::UShort RTT_corba_COperationInterface_i::getCollectArity (
const char * operation)
{
if ( mfact->hasMember( string( operation ) ) == false || mfact->isSynchronous(string(operation)) )
throw ::RTT::corba::CNoSuchNameException( operation );
return mfact->getPart(operation)->collectArity();
OperationInterfacePart* mofp = findOperation(operation);
return mofp->collectArity();
}

char * RTT_corba_COperationInterface_i::getDescription (
const char * operation)
{
if ( mfact->hasMember( string( operation ) ) == false || mfact->isSynchronous(string(operation)) )
throw ::RTT::corba::CNoSuchNameException( operation );
return CORBA::string_dup( mfact->getDescription( string(operation) ).c_str() );
OperationInterfacePart* mofp = findOperation(operation);
return CORBA::string_dup( mofp->description().c_str() );
}

void RTT_corba_COperationInterface_i::checkOperation (
const char * operation,
const ::RTT::corba::CAnyArguments & args)
{
if ( mfact->hasMember( string( operation ) ) == false || mfact->isSynchronous(string(operation)) )
throw ::RTT::corba::CNoSuchNameException( operation );
OperationInterfacePart* mofp = findOperation(operation);

try {
OperationInterfacePart* mofp = mfact->getPart(operation);
OperationCallerC mc(mofp, operation, internal::GlobalEngine::Instance());
for (unsigned int i = 0; i < mofp->arity() && i < args.length(); ++i) {
const TypeInfo* ti = mofp->getArgumentType(i+1);
assert(ti);
CorbaTypeTransporter* ctt = dynamic_cast<CorbaTypeTransporter*> (ti->getProtocol(ORO_CORBA_PROTOCOL_ID));
if (ctt) {
DataSourceBase::shared_ptr ds = ctt->createDataSource(&args[i]);
if (ds)
mc.arg(ds);
else {
log(Error) << "Registered transport for type "<< ti->getTypeName()
<< " could not create data source from Any (argument "<< i+1
<<"): calling operation '"<< operation <<"' will fail." <<endlog();
}
DataSourceBase::shared_ptr ds = ctt->createDataSource(&args[i]);
if (ds)
mc.arg(ds);
else {
log(Error) << "Registered transport for type "<< ti->getTypeName()
<< " could not create data source from Any (argument "<< i+1
<<"): calling operation '"<< operation <<"' will fail." <<endlog();
}
} else {
throw wrong_types_of_args_exception(i+1,"type known to CORBA", ti->getTypeName());
throw wrong_types_of_args_exception(i+1,"type known to CORBA", ti->getTypeName());
}
}
mc.check();
Expand All @@ -361,14 +358,14 @@ ::CORBA::Any * RTT_corba_COperationInterface_i::callOperation (
const char * operation,
::RTT::corba::CAnyArguments & args)
{
if ( mfact->hasMember( string( operation ) ) == false || mfact->isSynchronous(string(operation)) )
throw ::RTT::corba::CNoSuchNameException( operation );
OperationInterfacePart* mofp = findOperation(operation);

// convert Corba args to C++ args.
try {
OperationCallerC orig(mfact->getPart(operation), operation, internal::GlobalEngine::Instance());
OperationCallerC orig(mofp, operation, internal::GlobalEngine::Instance());
vector<DataSourceBase::shared_ptr> results;
for (size_t i =0; i != args.length(); ++i) {
const TypeInfo* ti = mfact->getPart(operation)->getArgumentType( i + 1);
const TypeInfo* ti = mofp->getArgumentType( i + 1);
CorbaTypeTransporter* ctt = dynamic_cast<CorbaTypeTransporter*> ( ti->getProtocol(ORO_CORBA_PROTOCOL_ID) );
// we need to store the results for returning them to caller (args is inout!) after the call()
results.push_back( ctt->createDataSource( &args[i] ) );
Expand All @@ -391,7 +388,7 @@ ::CORBA::Any * RTT_corba_COperationInterface_i::callOperation (

// Return results into args:
for (size_t i =0; i != args.length(); ++i) {
const TypeInfo* ti = mfact->getPart(operation)->getArgumentType( i + 1);
const TypeInfo* ti = mofp->getArgumentType( i + 1);
CorbaTypeTransporter* ctta = dynamic_cast<CorbaTypeTransporter*> ( ti->getProtocol(ORO_CORBA_PROTOCOL_ID) );
ctta->updateAny(results[i], args[i]);
}
Expand All @@ -418,13 +415,13 @@ ::RTT::corba::CSendHandle_ptr RTT_corba_COperationInterface_i::sendOperation (
const ::RTT::corba::CAnyArguments & args)
{
// This implementation is 90% identical to callOperation above, only deviating in the orig.ready() part.
if ( mfact->hasMember( string( operation ) ) == false || mfact->isSynchronous(string(operation)) )
throw ::RTT::corba::CNoSuchNameException( operation );
OperationInterfacePart* mofp = findOperation(operation);

// convert Corba args to C++ args.
try {
OperationCallerC orig(mfact->getPart(operation), operation, internal::GlobalEngine::Instance());
OperationCallerC orig(mofp, operation, internal::GlobalEngine::Instance());
for (size_t i =0; i != args.length(); ++i) {
const TypeInfo* ti = mfact->getPart(operation)->getArgumentType( i + 1);
const TypeInfo* ti = mofp->getArgumentType( i + 1);
CorbaTypeTransporter* ctt = dynamic_cast<CorbaTypeTransporter*> ( ti->getProtocol(ORO_CORBA_PROTOCOL_ID) );
orig.arg( ctt->createDataSource( &args[i] ));
}
Expand All @@ -433,7 +430,7 @@ ::RTT::corba::CSendHandle_ptr RTT_corba_COperationInterface_i::sendOperation (
// we may not destroy the SendHandle, before the operation completes:
resulthandle.setAutoCollect(true);
// our resulthandle copy makes sure that the resulthandle can return.
RTT_corba_CSendHandle_i* ret_i = new RTT_corba_CSendHandle_i( resulthandle, mfact->getPart(operation) );
RTT_corba_CSendHandle_i* ret_i = new RTT_corba_CSendHandle_i( resulthandle, mofp );
CSendHandle_var ret = ret_i->_this();
ret_i->_remove_ref(); // if POA drops this, it gets cleaned up.
return ret._retn();
Expand All @@ -451,3 +448,18 @@ ::RTT::corba::CSendHandle_ptr RTT_corba_COperationInterface_i::sendOperation (
}
return CSendHandle::_nil();
}

RTT::OperationInterfacePart *RTT_corba_COperationInterface_i::findOperation( const char *operation )
{
string operation_str(operation);
OperationInterfacePart* mofp = mfact->getPart(operation_str);
if ( !mofp && (operation_str == "loadPlugin") )
mofp = &loadPluginOperationPart;
if ( !mofp || mfact->isSynchronous(operation_str) )
throw ::RTT::corba::CNoSuchNameException( operation );
return mofp;
}

bool RTT_corba_COperationInterface_i::loadPlugin(const string &pluginPath) {
return RTT::plugin::PluginLoader::Instance()->loadPlugin(pluginPath, "");
}
8 changes: 8 additions & 0 deletions rtt/transports/corba/OperationInterfaceI.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
#endif
#include "../../OperationInterface.hpp"
#include "../../internal/SendHandleC.hpp"
#include "../../internal/OperationInterfacePartFused.hpp"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
#pragma once
Expand Down Expand Up @@ -125,6 +126,9 @@ class RTT_corba_COperationInterface_i
{
RTT::OperationInterface* mfact;
PortableServer::POA_var mpoa;
RTT::Operation<bool(std::string)> loadPluginOperation;
RTT::internal::OperationInterfacePartFused<bool(std::string)> loadPluginOperationPart;

public:
//Constructor
RTT_corba_COperationInterface_i(RTT::OperationInterface* mfact, PortableServer::POA_ptr the_poa);
Expand Down Expand Up @@ -180,6 +184,10 @@ class RTT_corba_COperationInterface_i
::RTT::corba::CSendHandle_ptr sendOperation (
const char * operation,
const ::RTT::corba::CAnyArguments & args);

private:
RTT::OperationInterfacePart *findOperation ( const char *operation );
bool loadPlugin ( const std::string& pluginPath );
};


Expand Down