Skip to content

Commit

Permalink
Feature/transparent refs (#64)
Browse files Browse the repository at this point in the history
* Function calls are now completely transparent
  - Transparent references added
  - call_func returns `R` now
    - Throws with error_mesg if no value stored
  - Compile/link times are now a bit slower
    - Due to how transparent refs are implemented

* Switched tests to doctest
  - doctest builds much faster than catch2
  - benchmarks are not changed for now
    - Will need to use a standalone benchmarking suite

* Moved server functionality into class, like client
  • Loading branch information
jharmer95 authored Aug 2, 2021
1 parent 23549c9 commit 6d1ea67
Show file tree
Hide file tree
Showing 123 changed files with 3,639 additions and 3,758 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,23 @@ name: "CodeQL"
on:
push:
branches: [ main ]
paths-ignore:
- '**.md'
- 'docs/**'
- '**/.clang-format'
- '**/.clang-tidy'
- '**/LICENSE'
- '**/.gitignore'
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
paths-ignore:
- '**.md'
- 'docs/**'
- '**/.clang-format'
- '**/.clang-tidy'
- '**/LICENSE'
- '**/.gitignore'
schedule:
- cron: '37 15 * * 1'

Expand Down
31 changes: 18 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,23 @@ on:
push:
branches:
- main
paths-ignore:
- '**.md'
- 'docs/**'
- '**/.clang-format'
- '**/.clang-tidy'
- '**/LICENSE'
- '**/.gitignore'
pull_request:
branches:
- main
paths-ignore:
- '**.md'
- 'docs/**'
- '**/.clang-format'
- '**/.clang-tidy'
- '**/LICENSE'
- '**/.gitignore'
jobs:
build:
name: Build and test
Expand All @@ -17,28 +31,19 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install CMake and compilers
run: |
sudo apt update
sudo apt install cmake ninja-build gcc clang
- name: Install Conan
- name: Install vcpkg dependencies
run: |
python -m pip install --upgrade pip
pip install wheel setuptools
pip install conan
export PATH=$PATH:/home/runner/.local/bin
echo $PATH
conan --version
sudo ln -s ~/.local/bin/conan /usr/local/bin/conan
/usr/local/share/vcpkg/vcpkg install asio catch2 doctest nlohmann-json rapidjson
/usr/local/share/vcpkg/vcpkg integrate install
- name: Build with CMake
run: |
mkdir build
cd build
cmake .. -G Ninja -DBUILD_ADAPTER_NJSON=ON -DBUILD_ADAPTER_RAPIDJSON=ON -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} -DDEPENDS_CONAN=ON
cmake .. -G Ninja -DBUILD_ADAPTER_NJSON=ON -DBUILD_ADAPTER_RAPIDJSON=ON -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} -DCMAKE_CXX_FLAGS="-fuse-ld=gold" -DCMAKE_TOOLCHAIN_FILE=/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake -DDEPENDS_VCPKG=ON
ninja
- name: Run unit tests
run: |
Expand Down
20 changes: 12 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ cmake_minimum_required(VERSION 3.1)

project(
"rpc.hpp"
VERSION 0.5.1
VERSION 0.6.1
DESCRIPTION "Simple RPC Header-Only Library"
LANGUAGES CXX
)
Expand Down Expand Up @@ -244,13 +244,6 @@ else()
message("Skipping rpc_adapters...")
endif()

if(BUILD_BENCHMARK)
message("Building benchmarks...")
add_subdirectory(benchmarks)
else()
message("Skipping benchmarks...")
endif()

if(BUILD_EXAMPLES)
message("Building examples...")
add_subdirectory(examples)
Expand All @@ -264,3 +257,14 @@ if(BUILD_TESTING AND (PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR))
else()
message("Skipping tests...")
endif()

if(BUILD_BENCHMARK)
if(NOT BUILD_TESTING)
message(FATAL_ERROR "Tests must be enabled for benchmarking!")
else()
message("Building benchmarks...")
add_subdirectory(benchmarks)
endif()
else()
message("Skipping benchmarks...")
endif()
137 changes: 128 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,141 @@

A simple header-only library for supporting remote procedure calls using a variety of extensible features

## License

`rpc.hpp` is licensed under the [BSD 3-Clause License](LICENSE)

## Features

- Cross-platform
- Supports every major compiler/operating system
- Supports every major compiler/operating system
- Modern
- Utilizes features like C++17's [`constexpr if`](https://en.cppreference.com/w/cpp/language/if)
- Utilizes features like C++17's [`constexpr if`](https://en.cppreference.com/w/cpp/language/if)
- Type safe support for various types
- Supports most built-in/STL types out of the box
- Can add your own "extensions" to allow serialization and sending of any custom type
- Supports most built-in/STL types out of the box
- Users can create serialization methods for their own custom types
- Easy to use

### Upcoming Features

- Utilizing C++20's concepts/`requires` statement will make the library a lot simpler, cleaner, and easy to read.
- Better error/exception handling
- Extensible support via "adapters"
- Currently supported:
- [nlohmann-json](https://github.com/nlohmann/json)
- [rapidjson](https://github.com/Tencent/rapidjson)
- [Boost.JSON](https://github.com/boostorg/json)

## Documentation

See Doxygen docs [here](https://jharmer95.github.io/rpc.hpp/)

## Basic Example

For more examples see [examples](examples)

server.cpp

```C++
#define RPC_HPP_SERVER_IMPL
#define RPC_HPP_ENABLE_NJSON

#include <rpc_adapters/rpc_njson.hpp>
#include <rpc_dispatch_helper.hpp>

#include <string>

using rpc::adapters::njson;
using rpc::adapters::njson_adapter;

int Add(int n1, int n2)
{
return n1 + n2;
}

void AppendStr(std::string& str, const char* append)
{
str.append(append);
}

class RpcServer : public rpc::server_interface<njson_adapter>
{
public:
RpcServer(const char* address)
{
// initialize server...
}

// ...

void Run()
{
std::string data;

// Get data from client...

dispatch(data);

// Send data back to client...
}

private:
void dispatch_impl(njson& serial_obj) override
{
RPC_DEFAULT_DISPATCH(Add, AppendStr)
}
};

int main()
{
RpcServer my_server{"address"};

while (true)
{
my_server.Run();
}
}
```
client.cpp
```C++
#define RPC_HPP_CLIENT_IMPL
#define RPC_HPP_ENABLE_NJSON
#include <rpc_adapters/rpc_njson.hpp>
#include <cassert>
#include <string>
using rpc::adapters::njson_adapter;
class RpcClient : public rpc::client_interface<njson_adapter>
{
public:
RpcClient(const char* address)
{
// initialize client...
}
// ...
private:
void send(const std::string& mesg) override
{
// Send mesg to server...
}
std::string receive() override
{
// Get message back from server...
}
};
int main()
{
RpcClient my_client{ "address" };
const auto result = my_client.template call_func<int>("Sum", 1, 2);
assert(result == 3);
std::string str{ "Hello" };
my_client.call_func("AppendStr", str, " world!");
assert(str == "Hello world!");
}
```
5 changes: 4 additions & 1 deletion benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ if(NOT TARGET catch2_lib)
endif()

if(NOT TARGET asio_lib)
find_package(Threads REQUIRED)
add_library(asio_lib INTERFACE)
target_compile_definitions(asio_lib INTERFACE ASIO_STANDALONE)
target_link_libraries(asio_lib INTERFACE Threads::Threads)

if(${DEPENDS_CONAN})
set(CONAN_EXTRA_REQUIRES "asio/[>=1.14.0]")
Expand All @@ -72,7 +74,8 @@ if(NOT TARGET asio_lib)
endif()
endif()

add_executable(rpc_benchmark "benchmark.cpp" "client.hpp" "test_structs.hpp")
add_executable(rpc_benchmark benchmark.cpp)
target_include_directories(rpc_benchmark PRIVATE ../tests)
target_link_libraries(rpc_benchmark PRIVATE rpc_hpp catch2_lib asio_lib)

if(${BUILD_ADAPTER_BOOST_JSON})
Expand Down
Loading

0 comments on commit 6d1ea67

Please sign in to comment.