a simple RPC wrapper generator to C/C++ functions

Overview

This project initiated from the following practical problem. To control experimental equipment via computers, manufactures provide software drivers with SDK written in C/C++. Unfortunately, Windows platform is often the only supported platform or support for other platforms stays years behind. In order to control such equipment from a Linux platform, for instance, Remote Procedure Calling (RPC) techniques can be used.

Simple RPC C++ project provides a Python script that generates wrappers to C/C++ functions and RPC server applications so that the wrapped C/C++ functions could be called from an application (local host) but the C/C++ functions are executed on a server application (remote host).

The usage of word "simple" in the name of this project is due to the following:

  • RPC technology can be simple to use --- editing existing code should be minimal in order to remotely call C/C++ functions. Just changing the name of a header file should be sufficient to adapt an application to use RPC for certain C/C++ functions. Note that existing RPC libraries require RPC specific client applications; the current project aims at requiring minimal modification to client applications so that switching from calling C/C++ functions directly or via RPC, would be straightforward.

  • Simplification can be sufficient for practical applications --- C/C++ functions that can be wrapped for RPC, are assumed to have "simple" prototypes, that is, the arguments should have types that Boost serialization library can handle. This includes all standard C/C++ scalar types and standard STL collections. These types can be defined in arguments as is, or as references, or as pointers. Notice that pointer arguments are treated in application program (in local host) as scalars that can be passed to RPC server program where they point to actual memory location of the remote host.

  • Simplicity goes with restrictions --- For instance, wrapping C++ template functions is not supported. In addition, when running an application and RPC server on hosts with different architecture or operating system, special care must be taken to ensure that the data exchange between local and remote host is correct. For instance, the size of standard C/C++ int type may be different on local and remote hosts leading to possible corruption of data. To avoid this, always use scalar types with fixed byte width, for instance, int32_t, uint64_t, etc. Finally, no care is taken when the endian of local and remote hosts differ..

Installation

The project assumes availability of Python 2.x. Python 3.x support might require minor modifications in the project source code, patches are welcome.

Checkout the project source code, see Source/Checkout for instructions. In the source code directory, run

sudo python setup.py install

Windows users should run python setup.py install from command prompt.

To verify success, execute

  cd tests
  make

If the tests pass, you can try out the "Example" project below.

Example

A typical C/C++ project consists of three parts: application source file containing the main function, source file(s) of computational functions, and header file(s) of the corresponding prototypes. All source files are compiled and linked together resulting an application program. When running this application program, the main function calls computational functions and outputs the results. Our aim is that when main function calls computational functions then they are actually executed in remote host. For that we use RPC technique to send function arguments and then receive function results over network. The current project Simple RPC C++ provides a Python script simple_rpc that constructs RPC wrapper functions to computational functions and generates the corresponding RPC source code. By design, modifications to existing source files are minimal. In fact, in a typical usage case only the application source file requires minor editing while no modifications are needed to the rest of source or header files, as will be demonstrated below.

To illustrate this, consider the following example project consisting of three files:

Source file: example_dot.cpp Header file: example_dot.hpp Application source file: example_dot_app.cpp
#include "example_dot.hpp"


double dot_product(const vector<double> & a,
const vector<double> & b
)
{
double sum = 0;
for (int i = 0; i < a.size(); i++)
sum += a[i] * b[i];
return sum;
}
#ifndef EXAMPLE_DOT_HPP_DEFINED

#define EXAMPLE_DOT_HPP_DEFINED

#include <vector>
using namespace std;

double dot_product(const vector<double> & a,
const vector<double> & b
);

#endif
#include <iostream>


#include "example_dot.hpp"

main()
{
vector<double> a(3);
a[0] = 1.2; a[1] = 3.4; a[2] = 5.6;
cout << "dot_product(a,a) -> ";
cout << dot_product(a,a) << endl;
}
The corresponding application can be compiled and executed: ``` $ c++ example_dot.cpp example_dot_app.cpp -o example_dot_app $ ./example_dot_app dot_product(a,a) -> 44.36 ```

In order to call dot_product via RPC server, first, we generate wrapper codes:

$ simple_rpc example_dot.hpp
Creating RPC wrappers to functions:
    double dot_product(const vector<double> & a,
		       const vector<double> & b
		      )
creating file example_dot-rpc.hpp
creating file example_dot-rpc.cpp
creating file example_dot-rpc-server.cpp

Notice that the simple_rpc script takes header files for input and generates three files as shown above. These files will be used to compile and build two executable programs: one for application and one for RPC server.

Next, we will modify the application source code as follows.

Source file: example_dot.cpp Header file: example_dot.hpp Application source file: example_dot_app.cpp
#include "example_dot.hpp"


double dot_product(const vector<double> & a,
const vector<double> & b
)
{
double sum = 0;
for (int i = 0; i < a.size(); i++)
sum += a[i] * b[i];
return sum;
}
#ifndef EXAMPLE_DOT_HPP_DEFINED

#define EXAMPLE_DOT_HPP_DEFINED

#include <vector>
using namespace std;

double dot_product(const vector<double> & a,
const vector<double> & b
);

#endif
#include <iostream>


#include "example_dot-rpc.hpp" // <-- (1)

#ifdef SimpleRPC // <-- (2)
using namespace simple_rpc::example_dot; // <-- (2)
#endif // <-- (2)

main()
{
SIMPLE_RPC_CONNECT("127.0.0.1", 2340, 2); // <-- (3)
vector<double> a(3);
a[0] = 1.2; a[1] = 3.4; a[2] = 5.6;
cout << "dot_product(a,a) -> ";
cout << dot_product(a,a) << endl;
}
The application source code is modified in three places indicated with `// <-- (#)`: 1. The name of the header file is appended with `-rpc` suffix. The generated header file contains RPC wrapper functions to functions found in the original header file. 1. `ifdef SimpleRPC` block is inserted. This is done for convenience as it will make easy to disable (use `-DDISABLE_SIMPLE_RPC` when compiling application code) and enable RPC in the application code. Following `using namespace` declaration exposes the RPC wrapper of `compute_dot` function to current namespace. In general, RPC wrappers are defined in namespace `simple_rpc::`. 1. `SIMPLE_RPC_CONNECT` macro is used to specify the RPC server host IP, port number and debug level (0 means no debug messages are shown, increasing this number will increase verbosity). Here we use debug level 2 in order to illustrate the connection between the application code and RPC server, see below.

Next, the application and the RPC server programs must be built. In the given example we use RPC server local host (the corresponding host IP is 127.0.0.1) but, in general, the application program must be built on local host while the RPC server program on server host, especially, if these hosts run different operating systems. The following table illustrates the build process:

Remote host Local host
$ c++ example_dot.cpp example_dot-rpc-server.cpp \

-o example_dot-rpc-server -pthread \
-lboost_system -lboost_serialization \
-I`simple_rpc --include-dir`
$ c++ example_dot-rpc.cpp example_dot_app.cpp \

-o example_dot_app-rpc -pthread \
-lboost_system -lboost_serialization \
-I`simple_rpc --include-dir`
Notice that all source codes of functions must be compiled on remote host while the application source code with RPC wrapper source is compiled on local host.

Finally, we run the RPC server in remote host, and subsequently, run the application program:

Remote host Local host
$ ./example_dot-rpc-server

rpc-server[2] waits connection via port 2340...connected!
rpc-server:read_scalar<j>(a.size) <- 4 bytes
rpc-server:read_vector<d>(a) <- 24 bytes
rpc-server:read_scalar<j>(b.size) <- 4 bytes
rpc-server:read_vector<d>(b) <- 24 bytes
rpc-server:write_buffer_list(dot_product(a, b)) -> 16 bytes
rpc-server[3] waits connection via port 2340...
$ ./example_dot_app-rpc

set_debug_level:write_buffer_list(set_debug_level(debug_level)) -> 4 bytes
dot_product:write_buffer_list(dot_product(a, b)) -> 56 bytes
dot_product:read_scalar<d>(return_value) <- 8 bytes
dot_product(a,a) -> 44.36

Notice that RPC server can run continuously and different application programs can execute functions from the server. This will work only when different application programs will not execute the server functions at the same time. Server will serve the first application and during the time of execution, connections to the server by other applications will be declined.

You might also like...
Python wrapper for DMLab maze generator

dmlab-maze-generator Python wrapper for DMLab C++ maze generator. Usage !pip install dmlab-maze-generator from dmlab_maze_generator import create_ran

Libft is an individual project at 42 that requires us to re-create some standard C library functions including some additional ones that can be used later to build a library of useful functions for the rest of the program.

🔖 Index What is Libft? List of Functions Technologies ✨ What is Libft? Libft is an individual project at 42 that requires us to re-create some standa

Libft is an individual project at 42 that requires us to re-create some standard C library functions including some additional ones that can be used later to build a library of useful functions for the rest of the program.
Libft is an individual project at 42 that requires us to re-create some standard C library functions including some additional ones that can be used later to build a library of useful functions for the rest of the program.

Libft is an individual project at 42 that requires us to re-create some standard C library functions including some additional ones that can be used later to build a library of useful functions for the rest of the program.

A wrapper around std::variant with some helper functions

A wrapper around std::variant with some helper functions

modern C++(C++11), simple, easy to use rpc framework

modern C++(C++11), simple, easy to use rpc framework

Cap'n Proto serialization/RPC system - core tools and C++ library
Cap'n Proto serialization/RPC system - core tools and C++ library

Cap'n Proto is an insanely fast data interchange format and capability-based RPC system. Think JSON, except binary. Or think Protocol Buffers, except

Comprehensive RPC framework with support for C++, C#, Java, JavaScript, Python and more.

Ice - Comprehensive RPC Framework Ice helps you network your software with minimal effort. By taking care of all interactions with low-level network p

C++ framework for json-rpc (json remote procedure call)
C++ framework for json-rpc (json remote procedure call)

I am currently working on a new C++17 implementation - json-rpc-cxx. Master Develop | libjson-rpc-cpp This framework provides cross platform JSON-RPC

rpclib is a modern C++ msgpack-RPC server and client library

rpclib rpclib is a RPC library for C++, providing both a client and server implementation. It is built using modern C++14, and as such, requires a rec

Cap'n Proto serialization/RPC system - core tools and C++ library
Cap'n Proto serialization/RPC system - core tools and C++ library

Cap'n Proto is an insanely fast data interchange format and capability-based RPC system. Think JSON, except binary. Or think Protocol Buffers, except

Support for multiple RPC protocols in a single library

AnyRPC A multiprotocol remote procedure call system for C++ Overview AnyRPC provides a common system to work with a number of different remote procedu

Groupware server backend with RPC/HTTP, MAPI/HTTP, IMAP, POP3 and PHP-MAPI support

Gromox is the central groupware server component of grammm. It is capable of serving as a replacement for Microsoft Exchange and compatibles. Connecti

Flare是广泛投产于腾讯广告后台的现代化C++开发框架,包含了基础库、RPC、各种客户端等。主要特点为易用性强、长尾延迟低。

Flare 后台服务开发框架 腾讯广告 是腾讯公司最重要的业务之一,其后台大量采用 C++ 开发。 Flare 是我们吸收先前服务框架和业界开源项目及最新研究成果开发的现代化的后台服务开发框架,旨在提供针对目前主流软硬件环境下的易用、高性能、平稳的服务开发能力。

c++11, high performance, cross platform, easy to use rpc framework.

modern C++(C++11), simple, easy to use rpc framework

Bypass UAC at any level by abusing the Program Compatibility Assistant with RPC, WDI, and more Windows components
Bypass UAC at any level by abusing the Program Compatibility Assistant with RPC, WDI, and more Windows components

ByeIntegrity 8.0 The eighth Windows privilege escalation attack in the ByeIntegrity family. ByeIntegrity 8.0 is the most complex one I've created so f

🚀 Discord RPC Blocker for Lunar Client
🚀 Discord RPC Blocker for Lunar Client

🚀 Soyuz Soyuz has one simple purpose; listen for incoming Discord RPC requests from Lunar Client and block them! Limitations Windows only Soon to com

C++ framework for json-rpc (json remote procedure call)
C++ framework for json-rpc (json remote procedure call)

I am currently working on a new C++17 implementation - json-rpc-cxx. Master Develop | libjson-rpc-cpp This framework provides cross platform JSON-RPC

gRPC - An RPC library and framework Baind Unity 3D Project

Unity 3D Compose for Desktop and Android, a modern UI framework for C ++ , C# that makes building performant and beautiful user interfaces easy and enjoyable.

Comments
  • Home page suggestions to help people getting started

    Home page suggestions to help people getting started

    The "Example" section at https://code.google.com/p/simple-rpc-cpp appears to 
    contain two issues in the table that illustrates the build command (toward the 
    bottom of the page).
    
    1. A "-I" is required before the `simple_rpc --include-dir` in both commands
    
    2. For the "local host" build command, "example_dot-rcp.cpp" is specified 
    whereas it should be "example_dot-rpc.cpp" (RPC is mistyped)
    
    It might also be helpful to add an "Installation" section. Draft wording (which 
    you are of course welcome to improve) is below:
    
    Installation
    
    Checkout the project and change into the newly-created directory. As the 
    scripts use /usr/bin/env and expect Python 2 as the default interpreter, you 
    may need to modify your PATH to return a Python 2 interpreter.
    
    Make the setup script executable via chmod +x setup.py. Now run ./setup.py. 
    Type 0 (for "Configure") then press enter three times. Reload setup.py and use 
    option 1 (for "Build"), then reload setup.py with root privileges and use 
    option 2 (for "Install"). 
    
    To verify success, "cd tests" and then run "make". If the tests pass, you can 
    try out the "Example" project.
    

    Original issue reported on code.google.com by [email protected] on 4 Jun 2013 at 1:53

    Priority-Medium Type-Defect auto-migrated 
    opened by GoogleCodeExporter 1
  • No license provided

    No license provided

    Hi, I couldn't find any license information. If it was intended to be publicated as free software, please provide a license. See https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/licensing-a-repository#choosing-the-right-license

    Thanks!

    opened by tatdakar 0
Owner
Pearu Peterson
Pearu Peterson
Cap'n Proto serialization/RPC system - core tools and C++ library

Cap'n Proto is an insanely fast data interchange format and capability-based RPC system. Think JSON, except binary. Or think Protocol Buffers, except

Cap'n Proto 9.5k Dec 30, 2022
Comprehensive RPC framework with support for C++, C#, Java, JavaScript, Python and more.

Ice - Comprehensive RPC Framework Ice helps you network your software with minimal effort. By taking care of all interactions with low-level network p

ZeroC Ice 1.9k Jan 7, 2023
C++ framework for json-rpc (json remote procedure call)

I am currently working on a new C++17 implementation -> json-rpc-cxx. Master Develop | libjson-rpc-cpp This framework provides cross platform JSON-RPC

Peter Spiess-Knafl 833 Jan 7, 2023
rpclib is a modern C++ msgpack-RPC server and client library

rpclib rpclib is a RPC library for C++, providing both a client and server implementation. It is built using modern C++14, and as such, requires a rec

null 1.4k Dec 30, 2022
Groupware server backend with RPC/HTTP, MAPI/HTTP, IMAP, POP3 and PHP-MAPI support

Gromox is the central groupware server component of grammm. It is capable of serving as a replacement for Microsoft Exchange and compatibles. Connecti

grammm 139 Dec 26, 2022
c++11, high performance, cross platform, easy to use rpc framework.

modern C++(C++11), simple, easy to use rpc framework

qicosmos 1.2k Dec 30, 2022
Industrial-grade RPC framework used throughout Baidu, with 1,000,000+ instances and thousands kinds of services. "brpc" means "better RPC".

中文版 An industrial-grade RPC framework used throughout Baidu, with 1,000,000+ instances(not counting clients) and thousands kinds of services. "brpc" m

The Apache Software Foundation 14.2k Dec 27, 2022
Packio - An asynchronous msgpack-RPC and JSON-RPC library built on top of Boost.Asio.

Header-only | JSON-RPC | msgpack-RPC | asio | coroutines This library requires C++17 and is designed as an extension to boost.asio. It will let you bu

Quentin Chateau 58 Dec 26, 2022
RPC++ is a tool for Discord RPC (Rich Presence) to let your friends know about your Linux system

RPC++ RPC++ is a tool for Discord RPC (Rich Presence) to let your friends know about your Linux system Installing requirements Arch based systems pacm

grialion 4 Jul 6, 2022
An open source standard C library that includes useful functions && (Reimplementation of libc functions + own functions).

?? LIBFT-42 : Artistic view of LIBC: ?? HOW DOES IT FEEL HAVING YOUR OWN LIB: SUBJECT : ENGLISH PDF ℹ️ What is LIBFT : This project aims to code a C l

Abdessamad Laamimi 10 Nov 4, 2022