1
0
mirror of https://github.com/stefanocasazza/ULib.git synced 2025-09-28 19:05:55 +08:00
ULib/include/ulib/net/rpc/rpc_method.h
stefanocasazza 4838528c74 MACOSX fix
2015-10-30 19:37:21 +01:00

135 lines
3.3 KiB
C++

// ============================================================================
//
// = LIBRARY
// ULib - c++ library
//
// = FILENAME
// rpc_method.h
//
// = AUTHOR
// Stefano Casazza
//
// ============================================================================
#ifndef ULIB_RPC_METHOD_H
#define ULIB_RPC_METHOD_H 1
#include <ulib/string.h>
/**
* @class URPCMethod
*
* URPCMethod provides an interface for the things that methods most know how to do.
*
* Specifically, it needs to know the following:
* - Its name so the URPCObject can find it
* - How to execute itself given a URPCEnvelope
* - If it fails, how to fill in a URPCFault
* - How to encode itself for execution or response
*/
// Forward declaration
class URPCFault;
class URPCEncoder;
class URPCEnvelope;
class U_EXPORT URPCMethod {
public:
// Check for memory error
U_MEMORY_TEST
// Allocator e Deallocator
U_MEMORY_ALLOCATOR
U_MEMORY_DEALLOCATOR
// COSTRUTTORI
URPCMethod()
{
U_TRACE_REGISTER_OBJECT(0, URPCMethod, "", 0)
}
URPCMethod(const UString& n, const UString& _ns) : method_name(n), ns(_ns)
{
U_TRACE_REGISTER_OBJECT(0, URPCMethod, "%V,%V", n.rep, _ns.rep)
}
virtual ~URPCMethod()
{
U_TRACE_UNREGISTER_OBJECT(0, URPCMethod)
}
// GLOBAL SERVICES
static URPCFault* pFault;
static URPCEncoder* encoder;
static bool hasFailed()
{
U_TRACE_NO_PARAM(0, "URPCMethod::hasFailed()")
bool result = (pFault != 0);
U_RETURN(result);
}
// VIRTUAL METHOD
virtual UString getHeaderContent() const { return UString::getStringNull(); }
// Used to get the name of the method. This is matched up using the URPCObject dispatcher to respond to a call
virtual UString getMethodName() const { return method_name; }
// Used to get the namespace of the method
virtual UString getNamespaces() const { return ns; }
// Transforms the method into something that servers and clients can send. The encoder holds the
// actual data while the client hands data to be entered in. This makes a whole lot more sense in the
// samples that should have shipped with the library
virtual void encode()
{
U_TRACE_NO_PARAM(0, "URPCMethod::encode()")
U_INTERNAL_ASSERT(false) // If this assert fires, you need to implement the method
}
// Only to be called on the server by the dispatcher.
// This method executes the call and returns true if the call succeeded, false if it failed.
// URPCMethod should keep any return data in a member variable. The information will be returned via a call to encode
virtual bool execute(URPCEnvelope& theCall)
{
U_TRACE(0, "URPCMethod::execute(%p)", &theCall)
// If this assert fires, you need to implement the method.
// We include a default implementation because client-side Methods should never call execute.
U_INTERNAL_ASSERT(false)
U_RETURN(false);
}
// DEBUG
#if defined(U_STDCPP_ENABLE) && defined(DEBUG)
const char* dump(bool reset) const;
#endif
protected:
UString method_name, ns;
private:
#ifdef U_COMPILER_DELETE_MEMBERS
URPCMethod& operator=(const URPCMethod&) = delete;
#else
URPCMethod& operator=(const URPCMethod&) { return *this; }
#endif
};
#endif