//*****************************************************************************
// RCF - Remote Call Framework
// Copyright (c) 2005. All rights reserved.
// Developed by Jarl Lindrud.
// Contact: jlindrud@hotmail.com .
//*****************************************************************************
#ifndef INCLUDE_RCF_CLIENTSTUB_HPP
#define INCLUDE_RCF_CLIENTSTUB_HPP
#include <string>
#include <vector>
#include <memory>
#include <boost/shared_ptr.hpp>
#include <RCF/AsyncFilter.hpp>
#include <RCF/Endpoint.hpp>
#include <RCF/GetInterfaceName.hpp>
#include <RCF/Protocol/Protocol.hpp>
#include <RCF/SerializationProtocol.hpp>
#include <RCF/Token.hpp>
#include <SF/shared_ptr.hpp>
#include <SF/SerializeEnum.hpp>
namespace RCF {
namespace IDL {
class DoRequest;
template<typename T>
class InParameter;
template<typename T>
class OutParameter;
template<typename T>
class InReturnValue;
template<typename T>
class OutReturnValue;
} // namespace IDL
/// Indicates whether a client should use one-way or two-way semantics for remote calls.
enum RemoteCallSemantics
{
Oneway,
Twoway
};
#ifdef RCF_USE_SF_SERIALIZATION
SF_SERIALIZE_ENUM(RemoteCallSemantics)
#endif
class ClientStub;
typedef boost::shared_ptr<ClientStub> ClientStubPtr;
/// Manages the client side of communications between server and client.
class ClientStub
{
public:
/// Constructor.
ClientStub();
/// Constructor.
/// \param objectName Name of the binding on the server which the client wants to invoke.
ClientStub(const std::string &objectName);
/// Copy constructor. NB - transfers ownership of the client transport!
ClientStub(const ClientStub &rhs);
/// Assignment operator. NB - transfers ownership of the client transport!
ClientStub &operator=(const ClientStub &rhs);
/// Destructor.
~ClientStub();
/// Sets the server endpoint to which the client will call.
/// \param endpoint Server endpoint.
void setEndpoint(const I_Endpoint &endpoint);
/// Sets the server endpoint to which the client will call.
/// \param endpoint Server endpoint.
void setEndpoint(boost::shared_ptr<I_Endpoint> endpoint);
/// Returns a copy of the currently set server endpoint.
/// \return Shared pointer to an endpoint.
boost::shared_ptr<I_Endpoint> getEndpoint() const;
// TODO: a lot of these get/set functions should not be publicly available
/// Gets the token, if any, that the client is using.
/// \return Returns a copy of the token the client is using. If none, then it returns a default constructed Token.
Token getToken() const;
/// Sets the token that the client should use in its calls to the server.
/// \param token Token that the client should pass in subsequent calls to the server.
void setToken(Token token);
/// Gets the binding name on the server that the client is accessing.
/// \return Name of the server binding.
std::string getServerBindingName() const;
/// Sets the binding name on the server that the client should access on subsequent calls.
/// \param serverBindingName Name of the server binding.
void setServerBindingName(const std::string &serverBindingName);
/// Gets the calling semantics that the client is currently using (oneway or twoway).
/// \return Current calling semantics.
RemoteCallSemantics getDefaultCallingSemantics() const;
/// Sets the calling semantics that the client should use in subsequent calls (oneway or twoway).
/// \param defaultCallingSemantics Calling semantics to be used.
void setDefaultCallingSemantics(RemoteCallSemantics defaultCallingSemantics);
/// Sets the serialization protocol.
/// \param protocol Integer identifier of the desired serialization protocol.
void setSerializationProtocol(int protocol);
/// Gets the serialization protocol.
/// \return Integer identifier of the currently set serialization protocol.
int getSerializationProtocol();
/// Enables pointer tracking for outbound SF serialization.
/// \parameter Whether to enable or not.
void enableSfSerializationPointerTracking(bool enable);
/// Sets the client transport, releasing the currently configured transport.
/// \param transport Client transport.
void setTransport(std::auto_ptr<I_ClientTransport> transport);
/// Returns a reference to currently configured client transport.
/// \return Current client transport.
I_ClientTransport& getTransport();
/// Releases and returns the currently configured client transport.
/// \return Auto pointer to client transport.
std::auto_ptr<I_ClientTransport> releaseTransport();
/// Deletes the current client transport, and replaces it with a cloned copy.
void resetTransport();
/// Attempts to connect the underlying client transport.
void connectTransport();
/// Attempts to determine if the underlying client transport is connected.
/// \return True if the transport is connected, false otherwise.
bool isConnected();
/// Sets the payload filtering sequence.
/// \param filters Vector of filters, enumerated in the order in which they should be applied to unfiltered data
void setPayloadFilters(const std::vector<FilterPtr> &filters);
/// Sets the payload filtering sequence.
/// \param filterPtr Single filter.
void setPayloadFilters(FilterPtr filterPtr);
/// Sets the transport filtering sequence.
/// \param filters Vector of filters, enumerated in the order in which they should be applied to unfiltered data
void setTransportFilters(const std::vector<FilterPtr> &filters);
/// Sets the transport filtering sequence.
/// \param filterPtr Single filter.
void setTransportFilters(FilterPtr filterPtr);
const std::vector<FilterPtr> &getPayloadFilters();
/// Sets the remote call timeout value. By default, the timeout is set to 10 seconds.
/// \param remoteCallTimeoutMs TImeout value, in milliseconds.
void setRemoteCallTimeoutMs(unsigned int remoteCallTimeoutMs);
/// Gets the remote call timeout value.
/// \return Timeout value, in milliseconds.
unsigned int getRemoteCallTimeoutMs();
template<typename Archive> void serialize(Archive &ar, const unsigned int)
{
ar & token
& defaultCallingSemantics
& protocol
& endpointName
& objectName
& interfaceName
& remoteCallTimeoutMs
& mEndpoint;
}
private:
Token token;
RemoteCallSemantics defaultCallingSemantics;
int protocol;
std::string endpointName;
std::string objectName;
std::string interfaceName;
unsigned int remoteCallTimeoutMs;
boost::shared_ptr<I_Endpoint> mEndpoint;
std::auto_ptr<I_ClientTransport> transport;
std::vector<FilterPtr> mTransportFilters;
std::vector<FilterPtr> mPayloadFilters;
// TODO: a less intricate way of doing this
/*template<
typename R,
typename A1 = Meta::Null,
typename A2 = Meta::Null,
typename A3 = Meta::Null,
typename A4 = Meta::Null,
typename A5 = Meta::Null,
typename A6 = Meta::Null>
friend class ClientMarshal;*/
//friend class IDL::DoRequest;
public:
/*
private:
friend class IDL::DoRequest;
template<typename T>
friend class IDL::InParameter;
template<typename T>
friend class IDL::OutParameter;
template<typename T>
friend class IDL::InReturnValue;
template<typename T>
friend class IDL::OutReturnValue;
*/
void onPreCall();
SerializationProtocolIn in;
SerializationProtocolOut out;
};
} // namespace RCF
#endif // ! INCLUDE_RCF_CLIENTSTUB_HPP