Orocos Real-Time Toolkit  2.6.0
OperationCallerProxy.hpp
00001 #include "ServiceRequesterC.h"
00002 #include <string>
00003 #include "../../base/OperationCallerBaseInvoker.hpp"
00004 #include "CorbaOperationCallerFactory.hpp"
00005 
00006 namespace RTT
00007 {
00008     namespace corba {
00014         struct OperationCallerProxy
00015             : public base::OperationCallerBaseInvoker
00016         {
00017             std::string mname;
00018             CServiceRequester_var msrq;
00019             OperationCallerProxy(const std::string& opname, CServiceRequester_ptr srq)
00020             : mname(opname), msrq(srq) {}
00021 
00022             virtual bool ready() const {
00023                 return msrq->callerReady( mname.c_str() );
00024             }
00025 
00026             virtual void disconnect() {
00027                 msrq->disconnectCaller( mname.c_str() );
00028             }
00029 
00030             virtual bool setImplementation(boost::shared_ptr<base::DisposableInterface> impl, ExecutionEngine* caller = 0) {
00031                 // impossible for remote operation callers.
00032                 return false;
00033             }
00034 
00035             virtual bool setImplementationPart(OperationInterfacePart* orp, ExecutionEngine* caller = 0) {
00036                 // todo: forward to remote side.
00037                 // if orp is local, we need to provide the remote side with a service to this operation part.
00038                 // if orp is remote, we need to pass on the service
00039                 CorbaOperationCallerFactory* cocf = dynamic_cast<CorbaOperationCallerFactory*>(orp);
00040                 if (cocf) {
00041                     // good: it's already a remote service, just pass on the misery
00042                     return msrq->connectCallerTo(mname.c_str(), cocf->getService() );
00043                 } else {
00044                     // bad: we need to create or lookup
00045                     log(Error) <<"Can't connect an operation caller proxy directly to a local service."<<endlog();
00046                     log(Error) <<"Use CServiceRequester::connectTo() or CServiceRequester::connectCallerTo(). "<<endlog();
00047                 }
00048                 return false;
00049             }
00050 
00051             virtual void setCaller(ExecutionEngine* caller) {
00052                     // ignored.
00053             }
00054 
00055             virtual const std::string& getName() const {
00056                 return mname;
00057             }
00058         };
00059     }
00060 }