PLearn 0.1
|
Base for the trampoline mechanism of PLearn remote method invocation. More...
#include <RemoteTrampoline.h>
Public Types | |
typedef unsigned int | flag_t |
type for remote method flags | |
Public Member Functions | |
RemoteTrampoline (const string &methodname, const RemoteMethodDoc &doc, const flag_t &flgs=0) | |
Constructor takes the methodname and some documentation. | |
const RemoteMethodDoc & | documentation () const |
Documentation accessor. | |
const flag_t & | flags () const |
Flags accessor. | |
virtual void | call (Object *instance, int nargs, PStream &io) const =0 |
Perform the act of binding arguments on a stream with an object instance. | |
void | checkNargs (int nargs, int expected_nargs) const |
Check that the number of arguments is O.K. or PLERROR. | |
template<class T > | |
T * | as (Object *instance) const |
Perform dynamic-cast of its argument or PLERROR if wrong type or NULL. | |
Static Public Member Functions | |
static void | prepareToSendResults (PStream &out, int nres) |
Just forward the call to Object::prepareToSendResults (in .cc to avoid circular .h inclusion problem) | |
static void | sendRemoteMethodVoidResult (PStream &io) |
template<class T > | |
static void | sendRemoteMethodResult (PStream &io, const T &r) |
template<class T1 > | |
static void | sendRemoteMethodResult (PStream &io, const tuple< T1 > &r) |
template<class T1 , class T2 > | |
static void | sendRemoteMethodResult (PStream &io, const tuple< T1, T2 > &r) |
template<class T1 , class T2 , class T3 > | |
static void | sendRemoteMethodResult (PStream &io, const tuple< T1, T2, T3 > &r) |
template<class T1 , class T2 , class T3 , class T4 > | |
static void | sendRemoteMethodResult (PStream &io, const tuple< T1, T2, T3, T4 > &r) |
template<class T1 , class T2 , class T3 , class T4 , class T5 > | |
static void | sendRemoteMethodResult (PStream &io, const tuple< T1, T2, T3, T4, T5 > &r) |
template<class T1 , class T2 , class T3 , class T4 , class T5 , class T6 > | |
static void | sendRemoteMethodResult (PStream &io, const tuple< T1, T2, T3, T4, T5, T6 > &r) |
Static Public Attributes | |
static const flag_t | nopython = 1 |
nopython flag: do not inject this method in python | |
Protected Attributes | |
string | m_methodname |
Name of the method associated with trampoline. | |
RemoteMethodDoc | m_documentation |
Documentation associated with the method. | |
flag_t | m_flags |
Flags associated with this method. |
Base for the trampoline mechanism of PLearn remote method invocation.
The PLearn RMI mechanism provided through the Object::call() method can easily be interfaced to existing methods through the declareMethod system. Each declareMethod involves the creation of a TRAMPOLINE object. The purpose of this trampoline is to link together an object method with (i) the object instance, (ii) the serialized form of its arguments passed on a PStream, and (iii) the return value generated by calling the method.
The trampoline takes care of all the details related to stream handling, including the deserialisation of arguments from the stream into temporary variables, calling the method with an appropriate object instance, calling Object::prepareToSendResult, and serializing the return value onto the stream.
The base class provides a virtual call() function, which is overridden in derived classes. Derived class templates are provided for each function arity (number of arguments).
Other virtual functions are provided to provide type-annotated documentation.
Definition at line 106 of file RemoteTrampoline.h.
typedef unsigned int PLearn::RemoteTrampoline::flag_t |
type for remote method flags
Definition at line 109 of file RemoteTrampoline.h.
PLearn::RemoteTrampoline::RemoteTrampoline | ( | const string & | methodname, |
const RemoteMethodDoc & | doc, | ||
const flag_t & | flgs = 0 |
||
) | [inline] |
Constructor takes the methodname and some documentation.
Definition at line 114 of file RemoteTrampoline.h.
References PLearn::RemoteMethodDoc::checkConsistency(), m_documentation, and PLearn::RemoteMethodDoc::setName().
: m_methodname(methodname), m_documentation(doc), m_flags(flgs) { m_documentation.setName(methodname); m_documentation.checkConsistency(); }
T* PLearn::RemoteTrampoline::as | ( | Object * | instance | ) | const [inline] |
Perform dynamic-cast of its argument or PLERROR if wrong type or NULL.
Definition at line 156 of file RemoteTrampoline.h.
References m_methodname, and PLERROR.
{ T* t_instance = dynamic_cast<T*>(instance); if (! t_instance) PLERROR("PLearn Remote Function: object instance is null or of the wrong " "type for remote function '%s'", m_methodname.c_str()); return t_instance; }
virtual void PLearn::RemoteTrampoline::call | ( | Object * | instance, |
int | nargs, | ||
PStream & | io | ||
) | const [pure virtual] |
Perform the act of binding arguments on a stream with an object instance.
The actual number of arguments is passed only for error-checking, since the trampoline knows the number of arguments that it is expecting. If this is used to call a global function or a static method that was declared with declareFunction, instead of a regular method declared with declareMethod, then the instance argument is ignored (and should be passed 0 by convention).
Implemented in PLearn::RemoteTrampoline_0< T, R >, PLearn::RemoteTrampoline_0< T, void >, PLearn::RemoteTrampoline_1< T, R, A1 >, PLearn::RemoteTrampoline_1< T, void, A1 >, PLearn::RemoteTrampoline_2< T, R, A1, A2 >, PLearn::RemoteTrampoline_2< T, void, A1, A2 >, PLearn::RemoteTrampoline_3< T, R, A1, A2, A3 >, PLearn::RemoteTrampoline_3< T, void, A1, A2, A3 >, PLearn::RemoteTrampoline_4< T, R, A1, A2, A3, A4 >, PLearn::RemoteTrampoline_4< T, void, A1, A2, A3, A4 >, PLearn::RemoteTrampoline_5< T, R, A1, A2, A3, A4, A5 >, PLearn::RemoteTrampoline_5< T, void, A1, A2, A3, A4, A5 >, PLearn::RemoteTrampoline_6< T, R, A1, A2, A3, A4, A5, A6 >, PLearn::RemoteTrampoline_6< T, void, A1, A2, A3, A4, A5, A6 >, PLearn::FRemoteTrampoline_0< R >, PLearn::FRemoteTrampoline_0< void >, PLearn::FRemoteTrampoline_1< R, A1 >, PLearn::FRemoteTrampoline_1< void, A1 >, PLearn::FRemoteTrampoline_2< R, A1, A2 >, PLearn::FRemoteTrampoline_2< void, A1, A2 >, PLearn::FRemoteTrampoline_3< R, A1, A2, A3 >, PLearn::FRemoteTrampoline_3< void, A1, A2, A3 >, PLearn::FRemoteTrampoline_4< R, A1, A2, A3, A4 >, PLearn::FRemoteTrampoline_4< void, A1, A2, A3, A4 >, PLearn::FRemoteTrampoline_5< R, A1, A2, A3, A4, A5 >, PLearn::FRemoteTrampoline_5< void, A1, A2, A3, A4, A5 >, PLearn::FRemoteTrampoline_6< R, A1, A2, A3, A4, A5, A6 >, and PLearn::FRemoteTrampoline_6< void, A1, A2, A3, A4, A5, A6 >.
Referenced by PLearn::pythonGlobalFuncTramp(), and PLearn::PythonObjectWrapper::trampoline().
Check that the number of arguments is O.K. or PLERROR.
Definition at line 49 of file RemoteTrampoline.cc.
References PLERROR.
Referenced by PLearn::FRemoteTrampoline_1< void, A1 >::call(), PLearn::RemoteTrampoline_3< T, void, A1, A2, A3 >::call(), PLearn::RemoteTrampoline_1< T, void, A1 >::call(), PLearn::FRemoteTrampoline_4< R, A1, A2, A3, A4 >::call(), PLearn::RemoteTrampoline_4< T, void, A1, A2, A3, A4 >::call(), PLearn::FRemoteTrampoline_6< R, A1, A2, A3, A4, A5, A6 >::call(), PLearn::RemoteTrampoline_0< T, R >::call(), PLearn::FRemoteTrampoline_5< R, A1, A2, A3, A4, A5 >::call(), PLearn::FRemoteTrampoline_1< R, A1 >::call(), PLearn::RemoteTrampoline_5< T, void, A1, A2, A3, A4, A5 >::call(), PLearn::FRemoteTrampoline_5< void, A1, A2, A3, A4, A5 >::call(), PLearn::RemoteTrampoline_2< T, void, A1, A2 >::call(), PLearn::FRemoteTrampoline_4< void, A1, A2, A3, A4 >::call(), PLearn::FRemoteTrampoline_2< R, A1, A2 >::call(), PLearn::RemoteTrampoline_2< T, R, A1, A2 >::call(), PLearn::FRemoteTrampoline_3< R, A1, A2, A3 >::call(), PLearn::RemoteTrampoline_5< T, R, A1, A2, A3, A4, A5 >::call(), PLearn::FRemoteTrampoline_0< R >::call(), PLearn::RemoteTrampoline_4< T, R, A1, A2, A3, A4 >::call(), PLearn::FRemoteTrampoline_0< void >::call(), PLearn::FRemoteTrampoline_6< void, A1, A2, A3, A4, A5, A6 >::call(), PLearn::RemoteTrampoline_6< T, R, A1, A2, A3, A4, A5, A6 >::call(), PLearn::RemoteTrampoline_3< T, R, A1, A2, A3 >::call(), PLearn::FRemoteTrampoline_3< void, A1, A2, A3 >::call(), PLearn::RemoteTrampoline_6< T, void, A1, A2, A3, A4, A5, A6 >::call(), PLearn::RemoteTrampoline_0< T, void >::call(), PLearn::FRemoteTrampoline_2< void, A1, A2 >::call(), and PLearn::RemoteTrampoline_1< T, R, A1 >::call().
{ if (nargs != expected_nargs) PLERROR("PLearn Remote Function: expected %d arguments for calling function '%s'; " "received %d", expected_nargs, m_methodname.c_str(), nargs); }
const RemoteMethodDoc& PLearn::RemoteTrampoline::documentation | ( | ) | const [inline] |
Documentation accessor.
Definition at line 125 of file RemoteTrampoline.h.
References m_documentation.
Referenced by PLearn::RemoteMethodMap::getMethodHelpText(), PLearn::HTMLHelpCommand::helpOnClass(), PLearn::HelpSystem::helpOnFunctionHTML(), and PLearn::HelpSystem::helpOnMethodHTML().
{ return m_documentation; }
const flag_t& PLearn::RemoteTrampoline::flags | ( | ) | const [inline] |
Flags accessor.
Definition at line 131 of file RemoteTrampoline.h.
References m_flags.
{ return m_flags; }
Just forward the call to Object::prepareToSendResults (in .cc to avoid circular .h inclusion problem)
Definition at line 56 of file RemoteTrampoline.cc.
References PLearn::Object::prepareToSendResults().
Referenced by sendRemoteMethodResult(), and sendRemoteMethodVoidResult().
{ Object::prepareToSendResults(out, nres); }
static void PLearn::RemoteTrampoline::sendRemoteMethodResult | ( | PStream & | io, |
const tuple< T1 > & | r | ||
) | [inline, static] |
Definition at line 185 of file RemoteTrampoline.h.
References PLearn::PStream::flush(), and prepareToSendResults().
{ prepareToSendResults(io, 1); io << get<0>(r); io.flush(); }
static void PLearn::RemoteTrampoline::sendRemoteMethodResult | ( | PStream & | io, |
const T & | r | ||
) | [inline, static] |
Definition at line 177 of file RemoteTrampoline.h.
References PLearn::PStream::flush(), and prepareToSendResults().
Referenced by PLearn::FRemoteTrampoline_4< R, A1, A2, A3, A4 >::call(), PLearn::FRemoteTrampoline_6< R, A1, A2, A3, A4, A5, A6 >::call(), PLearn::RemoteTrampoline_0< T, R >::call(), PLearn::FRemoteTrampoline_1< R, A1 >::call(), PLearn::FRemoteTrampoline_5< R, A1, A2, A3, A4, A5 >::call(), PLearn::RemoteTrampoline_2< T, R, A1, A2 >::call(), PLearn::FRemoteTrampoline_2< R, A1, A2 >::call(), PLearn::RemoteTrampoline_5< T, R, A1, A2, A3, A4, A5 >::call(), PLearn::FRemoteTrampoline_3< R, A1, A2, A3 >::call(), PLearn::RemoteTrampoline_4< T, R, A1, A2, A3, A4 >::call(), PLearn::FRemoteTrampoline_0< R >::call(), PLearn::RemoteTrampoline_3< T, R, A1, A2, A3 >::call(), PLearn::RemoteTrampoline_6< T, R, A1, A2, A3, A4, A5, A6 >::call(), and PLearn::RemoteTrampoline_1< T, R, A1 >::call().
{ prepareToSendResults(io, 1); io << r; io.flush(); }
static void PLearn::RemoteTrampoline::sendRemoteMethodResult | ( | PStream & | io, |
const tuple< T1, T2, T3, T4, T5, T6 > & | r | ||
) | [inline, static] |
Definition at line 225 of file RemoteTrampoline.h.
References PLearn::PStream::flush(), and prepareToSendResults().
{ prepareToSendResults(io, 6); io << get<0>(r) << get<1>(r) << get<2>(r) << get<3>(r) << get<4>(r) << get<5>(r); io.flush(); }
static void PLearn::RemoteTrampoline::sendRemoteMethodResult | ( | PStream & | io, |
const tuple< T1, T2, T3 > & | r | ||
) | [inline, static] |
Definition at line 201 of file RemoteTrampoline.h.
References PLearn::PStream::flush(), and prepareToSendResults().
{ prepareToSendResults(io, 3); io << get<0>(r) << get<1>(r) << get<2>(r); io.flush(); }
static void PLearn::RemoteTrampoline::sendRemoteMethodResult | ( | PStream & | io, |
const tuple< T1, T2 > & | r | ||
) | [inline, static] |
Definition at line 193 of file RemoteTrampoline.h.
References PLearn::PStream::flush(), and prepareToSendResults().
{ prepareToSendResults(io, 2); io << get<0>(r) << get<1>(r); io.flush(); }
static void PLearn::RemoteTrampoline::sendRemoteMethodResult | ( | PStream & | io, |
const tuple< T1, T2, T3, T4, T5 > & | r | ||
) | [inline, static] |
Definition at line 217 of file RemoteTrampoline.h.
References PLearn::PStream::flush(), and prepareToSendResults().
{ prepareToSendResults(io, 5); io << get<0>(r) << get<1>(r) << get<2>(r) << get<3>(r) << get<4>(r); io.flush(); }
static void PLearn::RemoteTrampoline::sendRemoteMethodResult | ( | PStream & | io, |
const tuple< T1, T2, T3, T4 > & | r | ||
) | [inline, static] |
Definition at line 209 of file RemoteTrampoline.h.
References PLearn::PStream::flush(), and prepareToSendResults().
{ prepareToSendResults(io, 4); io << get<0>(r) << get<1>(r) << get<2>(r) << get<3>(r); io.flush(); }
static void PLearn::RemoteTrampoline::sendRemoteMethodVoidResult | ( | PStream & | io | ) | [inline, static] |
Definition at line 170 of file RemoteTrampoline.h.
References PLearn::PStream::flush(), and prepareToSendResults().
Referenced by PLearn::RemoteTrampoline_1< T, void, A1 >::call(), PLearn::RemoteTrampoline_3< T, void, A1, A2, A3 >::call(), PLearn::FRemoteTrampoline_1< void, A1 >::call(), PLearn::RemoteTrampoline_4< T, void, A1, A2, A3, A4 >::call(), PLearn::RemoteTrampoline_5< T, void, A1, A2, A3, A4, A5 >::call(), PLearn::RemoteTrampoline_2< T, void, A1, A2 >::call(), PLearn::FRemoteTrampoline_5< void, A1, A2, A3, A4, A5 >::call(), PLearn::FRemoteTrampoline_4< void, A1, A2, A3, A4 >::call(), PLearn::FRemoteTrampoline_0< void >::call(), PLearn::FRemoteTrampoline_6< void, A1, A2, A3, A4, A5, A6 >::call(), PLearn::RemoteTrampoline_0< T, void >::call(), PLearn::RemoteTrampoline_6< T, void, A1, A2, A3, A4, A5, A6 >::call(), PLearn::FRemoteTrampoline_3< void, A1, A2, A3 >::call(), and PLearn::FRemoteTrampoline_2< void, A1, A2 >::call().
{ prepareToSendResults(io, 0); io.flush(); }
Documentation associated with the method.
Definition at line 237 of file RemoteTrampoline.h.
Referenced by documentation(), and RemoteTrampoline().
flag_t PLearn::RemoteTrampoline::m_flags [protected] |
Flags associated with this method.
Definition at line 240 of file RemoteTrampoline.h.
Referenced by flags().
string PLearn::RemoteTrampoline::m_methodname [protected] |
Name of the method associated with trampoline.
Definition at line 234 of file RemoteTrampoline.h.
Referenced by as().
const RemoteTrampoline::flag_t PLearn::RemoteTrampoline::nopython = 1 [static] |
nopython flag: do not inject this method in python
Definition at line 111 of file RemoteTrampoline.h.
Referenced by PLearn::injectPLearnClasses().