S3FC project page S3FC home page

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

s3_rpc_server Class Template Reference

An RPC server that controls a single T_obj instance. More...

#include <s3_rpc.h>

Inheritance diagram for s3_rpc_server:

Inheritance graph
[legend]
Collaboration diagram for s3_rpc_server:

Collaboration graph
[legend]
List of all members.

Public Methods

 s3_rpc_server (const std::string &n_name, T_obj &n_obj)
 Initialising constructor: Instantiate an RPC server that controls a single T_obj instance, setting its name, target instance and callmap. More...

virtual ~s3_rpc_server ()
 Destructor: disconnect from the postal system and clean up. More...


Protected Methods

virtual void main_loop ()
 Function that is invoked as the main loop in its own thread. More...

void handle_message (const s3_message &msg)
void exec_cmd_call (const s3_message &msg, std::string body_str)
std::string remove_first (std::string &str)

Static Protected Methods

void reply_client (s3_message_box &mb, const s3_message &msg, const std::string &err, bool err)

Protected Attributes

s3_message_box mb
 Message box that receives RPC requests relating to obj. More...

T_obj * obj
 Pointer to T_obj instance on which this serves invokes methods. More...

s3_rpc_type_common< T_obj
>::callmap_t 
cmap
 Map between function names and callers that invoke the functions. More...

s3_semaphore started

Detailed Description

template<typename T_obj>
class s3_rpc_server< T_obj >

An RPC server that controls a single T_obj instance.

Each server has a name string and allows named methods of the T_obj instance to be remotely invoked from an s3_rpc_client. Each method of T_obj that should be remotely invoked are provided with a name string. In order to invoke a method on an instance, the client requires the name of the RPC server controlling the as well as the name of the method to invoke.

The RPC system uses the Stone Three Postal System and all clients and servers wishing to interact using RPC should use the same postal system (i.e. they should all invoke s3_message_box::init() with the same arguments in all process spaces). The name assigned to an s3_rpc_server should be unique within all other RPC servers using the same postal system, as each RPC server contains a message box with a name that is derived from the RPC server name.

Mapping a method name to a member function is done by the callmap, which associates the name string of the method with a dispatcher instance that invokes it. The RPC server obtains this callmap by calling the following method:

 *  static s3_rpc_server<T_obj>::callmap_t s3_rpc_callmap<T_obj>::value()
 * 
s3_rpc_callmap should therefore be specialised for each T_obj type that should be controllable using RPC.

Definition at line 254 of file s3_rpc.h.


Constructor & Destructor Documentation

template<typename T_obj>
s3_rpc_server< T_obj >::s3_rpc_server const std::string &    n_name,
T_obj &    n_obj
 

Initialising constructor: Instantiate an RPC server that controls a single T_obj instance, setting its name, target instance and callmap.

Parameters:
name  Name string of T_obj instance. This name is used to associate an s3_rpc_client with this server instance.
n_target  T_obj instance which this server controls.

Definition at line 150 of file s3_rpc.tcc.

References s3_message_box::connect, mb, s3_rpc_common::rpc_server_name, s3_message_box::set_name, s3_thread_base::start, started, and s3_semaphore::wait.

template<typename T_obj>
s3_rpc_server< T_obj >::~s3_rpc_server   [virtual]
 

Destructor: disconnect from the postal system and clean up.

Definition at line 178 of file s3_rpc.tcc.

References s3_rpc_type_common::clear_callmap, cmap, s3_message_box::disconnect, mb, s3_thread_base::request_terminate, and s3_thread_base::wait_on_exit.


Member Function Documentation

template<typename T_obj>
void s3_rpc_server< T_obj >::exec_cmd_call const s3_message   msg,
std::string    body_str
[protected]
 

Definition at line 245 of file s3_rpc.tcc.

References cmap, mb, obj, remove_first, reply_client, and s3_conversion::split_string.

Referenced by handle_message.

template<typename T_obj>
void s3_rpc_server< T_obj >::handle_message const s3_message   msg [protected]
 

Definition at line 209 of file s3_rpc.tcc.

References s3_rpc_common::cmd_tag_call, exec_cmd_call, s3_message::get_body, s3_message::is_empty, mb, remove_first, and reply_client.

Referenced by main_loop.

template<typename T_obj>
void s3_rpc_server< T_obj >::main_loop   [protected, virtual]
 

Function that is invoked as the main loop in its own thread.

Override this in derived class.

Note:
This is to become pure virtual once the older void* main_loop(void*) is dropped entirely.

Implements s3_thread_base.

Definition at line 190 of file s3_rpc.tcc.

References s3_message_box::get_msg, handle_message, mb, s3_semaphore::post, S3FC_DBG, started, s3_thread_base::state_changed, s3_message_box::subscribe_arrival, s3_thread_base::test_terminate, and s3_thread_base::wait_on_state_changed.

template<typename T_obj>
std::string s3_rpc_server< T_obj >::remove_first std::string &    str [protected]
 

Definition at line 286 of file s3_rpc.tcc.

Referenced by exec_cmd_call, and handle_message.

template<typename T_obj>
void s3_rpc_server< T_obj >::reply_client s3_message_box   mb,
const s3_message   msg,
const std::string &    err,
bool    err
[static, protected]
 

Definition at line 312 of file s3_rpc.tcc.

References s3_message::get_body, s3_message::get_from, s3_message_box::reply_msg, and S3FC_DBG.

Referenced by exec_cmd_call, and handle_message.


Member Data Documentation

template<typename T_obj>
s3_rpc_type_common<T_obj>::callmap_t s3_rpc_server::cmap [protected]
 

Map between function names and callers that invoke the functions.

Definition at line 268 of file s3_rpc.h.

Referenced by exec_cmd_call, and ~s3_rpc_server.

template<typename T_obj>
s3_message_box s3_rpc_server::mb [protected]
 

Message box that receives RPC requests relating to obj.

Definition at line 260 of file s3_rpc.h.

Referenced by exec_cmd_call, handle_message, main_loop, s3_rpc_server, and ~s3_rpc_server.

template<typename T_obj>
T_obj* s3_rpc_server::obj [protected]
 

Pointer to T_obj instance on which this serves invokes methods.

Definition at line 264 of file s3_rpc.h.

Referenced by exec_cmd_call.

template<typename T_obj>
s3_semaphore s3_rpc_server::started [protected]
 

Reimplemented from s3_thread_base.

Definition at line 270 of file s3_rpc.h.

Referenced by main_loop, and s3_rpc_server.


The documentation for this class was generated from the following files:
Send comments to: s3fc@stonethree.com SourceForge Logo