S3FC project page S3FC home page

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

s3_rpc.cc

Go to the documentation of this file.
00001 /*
00002  * Stone Three Foundation Class (s3fc) provides a number of utility classes.
00003  * Copyright (C) 2001 by Stone Three Signal Processing (Pty) Ltd.
00004  *
00005  * Authored by Stone Three Signal Processing (Pty) Ltd.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  * 
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  * 
00021  * Please see the file 'COPYING' in the source root directory.
00022  */
00023 
00032 #include <s3fc/s3_rpc.h>
00033 
00034 #include <sstream>
00035 #include <ctime>
00036 #include <cstdlib>
00037 
00038 //
00039 const std::string s3_rpc_common::cmd_tag_call = "call";
00040 
00041 //
00042 std::string s3_rpc_common::rpc_server_name(const std::string& name)
00043 {
00044    std::string s("_rpc_server_");
00045    s.append(name);
00046    return s;
00047 }
00048 
00049 //
00050 std::string s3_rpc_common::rpc_random_client_name(const std::string& name)
00051 {
00052    timespec ts;
00053    clock_gettime(CLOCK_REALTIME, &ts);
00054    srand(ts.tv_nsec);
00055    unsigned int r = static_cast<unsigned int>(rand());
00056    std::stringstream ss;
00057    ss << "_rpc_client_" << name << r << "_";
00058    return ss.str();
00059 }
00060 
00061 //
00062 s3_rpc_exception::s3_rpc_exception(const std::string& where,
00063                const std::string& what) :
00064    s3_exception("")
00065 {
00066    std::stringstream ss;
00067    ss << where << ": [" << what << "]";
00068    err_string = ss.str();
00069 }
00070 
00071 #if 0
00072 //
00073 s3_rpc_client::s3_rpc_client(const std::string& n_name) :
00074    server_name(s3_rpc_common::rpc_server_name(n_name))
00075 {
00076    std::string lname = s3_rpc_common::rpc_random_client_name(n_name);
00077    try
00078    {
00079       mb.set_name(lname);
00080       mb.connect();
00081    }
00082    catch(const std::exception& e)
00083    {
00084       std::stringstream ss;
00085       ss << "s3_message_box::connect() threw exception (name: "
00086     << lname << "): [" << e.what() << "]";
00087       // rethrow as RPC exception
00088       throw s3_rpc_exception("s3_rpc_client::s3_rpc_client",
00089               ss.str());
00090    }
00091 }
00092 
00093 //
00094 std::string s3_rpc_client::call(const std::string& method)
00095 {
00096    return call_common(method, "");
00097 }
00098 
00099 //
00100 std::string s3_rpc_client::call_common(const std::string& method,
00101                    const std::string& args)
00102 {
00103    std::stringstream ss;
00104    ss << s3_rpc_common::cmd_tag_call << "|" << method << "|" << args;
00105    mb.send_msg(server_name, ss.str());
00106    return "";
00107 }
00108 #endif

Send comments to: s3fc@stonethree.com SourceForge Logo