Recent Changes - Search:




edit SideBar

Doc /


1) JsonRpc-Cpp installation steps

You must have scons and libjsoncpp (see FAQ) installed on your system.

First get JsonRpc-Cpp sources either with a release or via SVN repository (see this page).

Compile it:

 $ scons 

Install it:

 # scons install

The library is located in /usr/local/lib and the include files in /usr/local/include/jsonrpc-cpp.

To build the examples:

 $ scons examples

The examples binaries (tcp-server and udp-server) are located in test/ directory of the sources.

To build the API documentation:

 $ scons doxygen

The HTML generated API documentation is located in doc/html/ directory of the sources

2) How-to create a RPC service

A typical RPC method signature in JsonRpc-Cpp is:

     * \brief A RPC function.
     * \param root JSON-RPC request
     * \param response JSON-RPC response
     * \return true if correctly processed, false otherwise
    bool Func(const Json::Value& root, Json::Value& response);

It is highly recommended that for each RPC method, a corresponding JSON documentation is provided:

     * \brief Get the description of Func method in JSON format.
     * \return JSON description
    Json::Value GetFuncDescription();

All kind of method which respect the RPC signature can be remotely available. After having your set of RPC methods and written JSON documentation, add it to a JsonHandler.

    Json::Rpc::Handler jsonHandler;
    MyClass obj;
    Json::Rpc::RpcMethod<MyClass>* method = new Json::Rpc::RpcMethod<MyClass>(obj, &MyClass::Print, std::string("func"), obj.GetFuncDescription());

For convenience we provide a simple UDP and TCP server implementation which embedded JsonHandler object. The precedent code becomes:

    Json::Rpc::TcpServer server(std::string(""), 8086);
    MyClass obj;
    server.AddMethod(new Json::Rpc::RpcMethod<MyClass>(obj, &MyClass::Func, std::string("func"), obj.GetFuncDescription()));

      std::cout << "Bind failed" << std::endl;
      return -1;

      std::cout << "Listen failed" << std::endl;
      return -1;

      /* select() time is 1 second */
Edit - History - Print - Recent Changes - Search
Page last modified on March 18, 2009, at 09:41 AM