Following programs are requred to build:
- gcc >= 4.1 with C++ support
- MessagePack for C++ >= 0.5.2
- boost::asio for communucation and a loop processing.
Configure and install in the usual way:
$ cmake .
$ make
$ sudo make install
Test cases will give you a sample usage.
#include <msgpack/rpc/client.h>
#include <iostream>
int main(void)
{
msgpack::rpc::client c("127.0.0.1", 9090);
int result = c.call("add", 1, 2).get<int>();
std::cout << result << std::endl;
}
#include <msgpack/rpc/server.h>
class myserver : public msgpack::rpc::server::base {
public:
void add(msgpack::rpc::request req, int a1, int a2)
{
req.result(a1 + a2);
}
public:
void dispatch(msgpack::rpc::request req)
try {
std::string method;
req.method().convert(&method);
if(method == "add") {
std::tuple<int, int> params;
req.params().convert(¶ms);
add(req, params.get<0>(), params.get<1>());
} else {
req.error(msgpack::rpc::NO_METHOD_ERROR);
}
} catch (msgpack::type_error& e) {
req.error(msgpack::rpc::ARGUMENT_ERROR);
return;
} catch (std::exception& e) {
req.error(std::string(e.what()));
return;
}
};
int main(void)
{
myserver svr;
svr.instance.listen("0.0.0.0", 9090);
svr.instance.run(4); // run 4 threads
}
IDL parser and code generator is under development. It will resolve the problem that users have to implement verbose dispatch() function.
Copyright (C) 2008-2010 FURUHASHI Sadayuki <frsyuki _at_ users.sourceforge.jp>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.