00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
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