Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cpp version #341

Open
wants to merge 127 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
127 commits
Select commit Hold shift + click to select a range
08fe1d1
First setup of extreme carpaccio client
May 27, 2021
b234e15
Add Boost library for HTTP client
mengdaming May 27, 2021
337a8d7
Retrospective
May 27, 2021
ee227b3
Remove FindCurl.cmake and FindHttpClient.cmake
mengdaming May 27, 2021
debc365
Upgrade nlhmann_json to latest version (3.9.1)
mengdaming May 28, 2021
67444ab
Fix boost dependency
Jun 3, 2021
6683990
Add raw HTTP call
mengdaming Jun 3, 2021
32720db
Add empty server shell for the Extreme Carpaccio Client (server)
AntoineMx Jun 3, 2021
c4fed7e
Update TODO list with a plan of things to do, in order to resume work…
philou Jun 4, 2021
1f85d1f
Lay the ground work for the server, only minor details left to do.
AntoineMx Jun 17, 2021
892ff34
Almost done with the server...
Jun 17, 2021
19cd419
Make the server send a bad request on any http query.
AntoineMx Jun 17, 2021
e8b96b5
Integrate Boost Beast fast server example as is to have a starting po…
AntoineMx Jul 15, 2021
1446ed3
Retro + update on todo
Jul 15, 2021
7c39038
Working...
mengdaming Sep 2, 2021
d3282d4
Thread
Sep 2, 2021
24a535d
Merge branch 'cpp-version' of https:/pdalesme/extreme-car…
Sep 2, 2021
0b28300
thread detach
philou Sep 2, 2021
0617e05
Add watch.sh
mengdaming Sep 2, 2021
4ee3bf4
Working...
mengdaming Sep 2, 2021
2e9a5ed
Working...
mengdaming Sep 2, 2021
5483f0f
Working...
mengdaming Sep 2, 2021
cf6ced0
Working...
Sep 2, 2021
8e7a25a
Working...
Sep 2, 2021
fe13499
Working...
Sep 2, 2021
3d89a8e
Working...
Sep 2, 2021
575bbb3
Working...
Sep 2, 2021
ebe2583
Working...
Sep 2, 2021
65c4214
toto.png
Sep 2, 2021
c06f166
Working...
philou Sep 2, 2021
df7ce6c
Working...
mengdaming Sep 2, 2021
34cf592
Working...
mengdaming Sep 2, 2021
0b1d6fa
Working...
mengdaming Sep 2, 2021
b7d3c62
Working...
mengdaming Sep 2, 2021
ae62091
Working...
mengdaming Sep 2, 2021
81f3c52
Working...
Sep 2, 2021
79f7e61
Working...
Sep 2, 2021
531b9eb
Working...
Sep 2, 2021
0858e04
Working...
Sep 2, 2021
4656739
Working...
Sep 2, 2021
6cef913
Working...
Sep 2, 2021
41c9b62
Working...
Sep 2, 2021
9901c66
Working...
Sep 2, 2021
228fd96
Working...
Sep 2, 2021
f6593d0
Working...
Sep 2, 2021
e5a1c35
Working...
Sep 2, 2021
5e97c7e
Working...
Sep 2, 2021
8111257
Working...
Sep 2, 2021
7092c5e
Working...
Sep 2, 2021
53d3ffc
Working...
Sep 2, 2021
cbd0b0d
Working...
Sep 2, 2021
a5cd349
Working...
Sep 2, 2021
41b70ac
Working...
Sep 2, 2021
3459b0f
Working...
Sep 2, 2021
8b81f18
Working...
Sep 2, 2021
f05d8cb
Working...
Sep 2, 2021
f7ae417
Working...
Sep 2, 2021
f2a84be
Working...
Sep 2, 2021
6d3092f
Working...
Sep 2, 2021
ae9357d
Working...
Sep 2, 2021
01ec72a
Working...
Sep 2, 2021
76164f8
Working...
Sep 2, 2021
35775da
Working...
Sep 2, 2021
7095c04
Working...
Sep 2, 2021
9552e74
Working...
Sep 2, 2021
a951a0c
Working...
Sep 2, 2021
85d8fcf
Working...
Sep 2, 2021
2ca6f2d
Working...
Sep 2, 2021
9d3ad06
Working...
Sep 2, 2021
a2b81bd
Working...
Sep 2, 2021
120c941
Working...
Sep 2, 2021
5071536
Adding a CarpaccioServer class with start and stop
Sep 23, 2021
b641de2
Cosmetic fix
AntoineMx Oct 14, 2021
30ace94
Use server start/stop instead of launchServer.
AntoineMx Oct 14, 2021
4510134
Avoid resource leak.
AntoineMx Oct 14, 2021
53306f5
Factorize stream creation, management, destruction in a separate class.
AntoineMx Oct 14, 2021
f1ce572
Factorize request creation.
AntoineMx Oct 14, 2021
745be64
Retrospective
AntoineMx Oct 14, 2021
f44b52d
Factorize the main test code.
AntoineMx Oct 14, 2021
52e3c9f
Use the request type parameter instead of a hardcoded get.
AntoineMx Oct 21, 2021
5c15810
Handle order requests and default response.
AntoineMx Oct 21, 2021
34829b2
Update TODO list with next objectives: manual test with actual carpac…
AntoineMx Oct 21, 2021
4da224d
Update todolist : we tested our client http server with the real carp…
Nov 4, 2021
5dc9a69
Add dependency on nlohmann json library
Nov 4, 2021
a179bcb
Implement compute total amount + json parsing
Nov 4, 2021
ede4d6a
Update of TODOLIST
Nov 4, 2021
5e42d67
Remove test on json parsing
Nov 4, 2021
6c71f64
Parse order
Mirna-Mfd Jan 27, 2022
413bd54
Put Order in a specific file
Feb 3, 2022
7633580
Use Order in computeTotalAmount
Feb 3, 2022
a1785ac
Fill and read corretly the body of the request
Feb 3, 2022
8ab1c1f
Handle POST feedback
Feb 3, 2022
c62df1a
Update Todo list
Feb 3, 2022
0478b2a
Remove default implementation and send a 404 error
Feb 3, 2022
37bd876
Enrich TODOLIST following demo feedbacks.
Feb 17, 2022
69b7621
Add actions following session on extreme carpaccio using c++ client
Mar 29, 2022
c9c6099
Add trace on orders receival
mengdaming Apr 7, 2022
a2ff8ab
Extract a constant for the HTTP Server IP and Port number
aatwi Apr 7, 2022
aba5c26
Adding a new target + update TODO
Apr 14, 2022
b5c57e3
Add new library for participants to modify during the Kata.
AntoineMx Apr 14, 2022
5d4edeb
Add new gtest project where participants will write tests for their l…
AntoineMx Apr 14, 2022
8e8980a
Change computeTotalAmount interface and provide an example test.
AntoineMx Apr 14, 2022
f5f7a1d
Reorganize the carpaccio client targets (library, tests, executable).
AntoineMx Apr 15, 2022
63d36db
Add Github Actions to launch C++ build and tests.
AntoineMx Apr 15, 2022
e340073
Add explicit linking to pthread when it is available.
AntoineMx Apr 15, 2022
13de17e
Refactoring and cleaning + client now handles total amount processing…
AntoineMx Apr 19, 2022
bd62a79
Migrate test helpers from main library to test target in a helpers su…
AntoineMx Apr 19, 2022
86060de
Homogenize member naming convention.
AntoineMx Apr 19, 2022
3a3508e
Initialize members in constructor body.
AntoineMx Apr 19, 2022
793360b
Separate the Carpaccio HTTP worker and the Carpaccio server in differ…
AntoineMx Apr 19, 2022
9a60c1c
Clean-up .gitignore: the purpose of the out--of-source build tree is …
AntoineMx Apr 19, 2022
88ea4e1
Update TODO list.
AntoineMx Apr 21, 2022
1c3588f
Use CMake install mechanism to insall targets in a dedicated folder t…
AntoineMx Apr 21, 2022
d79b06e
Have the tests always run on server port plus 1 to avoid conflicts.
AntoineMx Apr 27, 2022
322789d
Disable ICU backend for Boost and add CPM cmake files to the Doc target.
AntoineMx Apr 27, 2022
53db004
Upgrade nlohmann_json version by adapting its retrieval through CPM
AntoineMx Apr 27, 2022
eb1d074
Upgrade googletest version.
AntoineMx Apr 27, 2022
00fbad1
Properly retrieve boost without ICU locale backend.
AntoineMx Apr 28, 2022
78853c3
Include install step in CI runs.
AntoineMx Apr 28, 2022
b04cdbf
Prevent Boost targets from showing up in the IDE solution.
AntoineMx Apr 28, 2022
a060036
Use default ip and default port in client construction.
Apr 28, 2022
fe45d48
Add the possibility to pass ip and port as parameters of client execu…
Apr 28, 2022
dfc7da6
First version of cpp README
Aug 31, 2023
0cd27b6
Upgrading to C++ 17
Sep 7, 2023
4e650fe
Removing Retrospective and TODOLIST. Enriching README
Sep 7, 2023
44ebe43
dereferencing in cmake list
Sep 7, 2023
e23565e
Merge branch 'dlresende:master' into cpp-version
pdalesme Sep 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: C++

on:
push:
branches-ignore:
- '*-from-video'

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Debug

jobs:
build-gcc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build & Test
uses: ashutoshvarma/action-cmake-build@master
with:
submodule-update: true
source-dir: ${{github.workspace}}/clients/cpp
build-dir: ${{github.workspace}}/clients/cpp/build
cc: gcc
cxx: g++
build-type: Release
run-test: true
ctest-options: "--output-on-failure"
install-build: true
build-clang:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build & Test
uses: ashutoshvarma/action-cmake-build@master
with:
submodule-update: true
source-dir: ${{github.workspace}}/clients/cpp
build-dir: ${{github.workspace}}/clients/cpp/build
cc: clang
cxx: clang++
build-type: Release
run-test: true
ctest-options: "--output-on-failure"
install-build: true
2 changes: 2 additions & 0 deletions clients/cpp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/
install/
43 changes: 43 additions & 0 deletions clients/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
cmake_minimum_required(VERSION 3.19.3)

set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/../install CACHE PATH "Where the targets are installed by CMake.")

project(Extreme-Carpaccio CXX)

set(CMAKE_CXX_STANDARD 17)
enable_testing()

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib CACHE PATH "Where to place compiled static libraries.")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib CACHE PATH "Where to place compiled shared libraries.")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin CACHE PATH "Where to place compiled executables.")

# We use CPM for 3rd-party dependencies management
include(cmake/CPM.cmake)
include(cmake/FindGoogleTest.cmake)
include(cmake/FindNlohmannJson.cmake)
include(cmake/FindBoost.cmake)

set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)

add_subdirectory(OrderManagement)
add_subdirectory(Client)

#Globals
add_custom_target(Docs
SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPM.cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindBoost.cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindGoogleTest.cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindNlohmannJson.cmake
${CMAKE_CURRENT_SOURCE_DIR}/../README.md)

set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Order-Management-tests)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY XCODE_STARTUP_PROJECT Order-Management-tests)

set_property(TARGET gtest gtest_main gmock gmock_main PROPERTY FOLDER "Third-Party/GoogleTest")

set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake Generated")
3 changes: 3 additions & 0 deletions clients/cpp/Client/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

add_subdirectory(executable)
add_subdirectory(library)
26 changes: 26 additions & 0 deletions clients/cpp/Client/executable/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

add_executable(Client-exe)

set(CLIENT_EXE_PRIVATE_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/sources/main.cpp
)

target_sources(Client-exe
PRIVATE
${CLIENT_EXE_PRIVATE_SOURCES}
)

source_group(
TREE ${CMAKE_CURRENT_SOURCE_DIR}
FILES
${CLIENT_EXE_PRIVATE_SOURCES}
)

target_link_libraries(Client-exe
PRIVATE
Client-shared
)

install(TARGETS Client-exe)

set_property(TARGET Client-exe PROPERTY FOLDER "Client")
24 changes: 24 additions & 0 deletions clients/cpp/Client/executable/sources/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

#include <extreme_carpaccio/client/Client.hpp>
#include <extreme_carpaccio/client/HttpConfig.hpp>

#include <cstdlib>
#include <iostream>

int main(int argc, char *argv[])
{
std::string ip = DEFAULT_HTTP_SERVER_IP;
unsigned short port = DEFAULT_HTTP_SERVER_PORT;

if (argc == 3)
{
ip = argv[1];
port = std::atoi(argv[2]);
}
std::cout << "Extreme Carpaccio server starting with ip " << ip << " and port " << port << "." << std::endl;
extreme_carpaccio::client::CarpaccioServer server(ip, port);
server.start();
std::cout << "Extreme Carpaccio server stopping." << std::endl;

return EXIT_SUCCESS;
}
52 changes: 52 additions & 0 deletions clients/cpp/Client/library/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

add_library(Client-shared SHARED)

target_compile_definitions(Client-shared PRIVATE EXTREME_CARPACCIO_CLIENT_EXPORTS)

set(CLIENT_SHARED_PRIVATE_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/sources/extreme_carpaccio/client/CarpaccioHttpWorker.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sources/extreme_carpaccio/client/Client.cpp
)

set(CLIENT_SHARED_PUBLIC_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/includes/extreme_carpaccio/client/CarpaccioHttpWorker.hpp
${CMAKE_CURRENT_SOURCE_DIR}/includes/extreme_carpaccio/client/Client.hpp
${CMAKE_CURRENT_SOURCE_DIR}/includes/extreme_carpaccio/client/config.hpp
${CMAKE_CURRENT_SOURCE_DIR}/includes/extreme_carpaccio/client/HttpConfig.hpp
)

target_sources(Client-shared
PRIVATE
${CLIENT_SHARED_PRIVATE_SOURCES}
PUBLIC
${CLIENT_SHARED_PUBLIC_SOURCES}
)

source_group(
TREE ${CMAKE_CURRENT_SOURCE_DIR}
FILES
${CLIENT_SHARED_PRIVATE_SOURCES}
${CLIENT_SHARED_PUBLIC_SOURCES}
)

target_include_directories(Client-shared
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/sources
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/includes
)

target_link_libraries(Client-shared
PRIVATE
nlohmann_json::nlohmann_json
PUBLIC
Threads::Threads
Boost::boost
Order-Management-shared
)

install(TARGETS Client-shared)

set_property(TARGET Client-shared PROPERTY FOLDER "Client")

add_subdirectory(tests)
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

#ifndef EXTREME_CARPACCIO_CLIENT_CARPACCIOHTTPWORKER_HPP
#define EXTREME_CARPACCIO_CLIENT_CARPACCIOHTTPWORKER_HPP

#include <boost/asio.hpp>
#include <boost/beast/core.hpp>
#include <boost/beast/http.hpp>
#include <boost/beast/version.hpp>

#include <string>

namespace extreme_carpaccio {
namespace client {

class CarpaccioHttpWorker
{
using alloc_t = std::allocator<char>;
using request_body_t = boost::beast::http::string_body;

public:
CarpaccioHttpWorker(CarpaccioHttpWorker const&) = delete;
CarpaccioHttpWorker& operator=(CarpaccioHttpWorker const&) = delete;

CarpaccioHttpWorker(boost::asio::ip::tcp::acceptor& acceptor, const std::string& doc_root);

void start();

private:
void accept();
void read_request();
void process_request(boost::beast::http::request<request_body_t, boost::beast::http::basic_fields<alloc_t>> const& req);
void send_response(boost::beast::http::status status, std::string const& body);
void check_deadline();
bool handleRequest(boost::beast::http::verb requestType, const std::string & target, const std::string & contentType, const std::string & body);

private:
// The acceptor used to listen for incoming connections.
boost::asio::ip::tcp::acceptor& m_acceptor;

// The path to the root of the document directory.
std::string m_doc_root;

// The socket for the currently connected client.
boost::asio::ip::tcp::socket m_socket;

// The buffer for performing reads
boost::beast::flat_static_buffer<8192> m_buffer;

// The allocator used for the fields in the request and reply.
alloc_t m_alloc;

// The parser for reading the requests
boost::optional<boost::beast::http::request_parser<request_body_t, alloc_t>> m_parser;

// The timer putting a time limit on requests.
boost::asio::steady_timer m_request_deadline;

// The string-based response message.
boost::optional<boost::beast::http::response<boost::beast::http::string_body, boost::beast::http::basic_fields<alloc_t>>> m_string_response;

// The file-based response message.
boost::optional<boost::beast::http::response<boost::beast::http::file_body, boost::beast::http::basic_fields<alloc_t>>> m_file_response;
};

} // namespace client
} // namespace extreme_carpaccio

#endif // EXTREME_CARPACCIO_CLIENT_CARPACCIOHTTPWORKER_HPP
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

#ifndef EXTREME_CARPACCIO_CLIENT_CLIENT_HPP
#define EXTREME_CARPACCIO_CLIENT_CLIENT_HPP

#include <extreme_carpaccio/client/CarpaccioHttpWorker.hpp>
#include <extreme_carpaccio/client/config.hpp>

#include <boost/asio.hpp>
#include <boost/beast/core.hpp>
#include <boost/beast/http.hpp>
#include <boost/beast/version.hpp>

#include <string>

namespace extreme_carpaccio {
namespace client {

class EXTREME_CARPACCIO_CLIENT_API CarpaccioServer
{
public:
CarpaccioServer(const std::string& ip, unsigned short port);
void start();
void stop();

private:
boost::asio::io_context ioc;
boost::asio::ip::tcp::acceptor acceptor;
CarpaccioHttpWorker worker;
};

} // namespace client
} // namespace extreme_carpaccio

#endif // EXTREME_CARPACCIO_CLIENT_CLIENT_HPP
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

#ifndef EXTREME_CARPACCIO_CLIENT_HTTPCONFIG_HPP
#define EXTREME_CARPACCIO_CLIENT_HTTPCONFIG_HPP

#define DEFAULT_HTTP_SERVER_IP "127.0.0.1"
#define DEFAULT_HTTP_SERVER_PORT 8081

namespace extreme_carpaccio {
namespace client {

} // namespace client
} // namespace extreme_carpaccio

#endif // EXTREME_CARPACCIO_CLIENT_HTTPCONFIG_HPP
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef EXTREME_CARPACCIO_CLIENT_CONFIG
#define EXTREME_CARPACCIO_CLIENT_CONFIG

#ifdef _MSC_VER
#ifdef EXTREME_CARPACCIO_CLIENT_EXPORTS
#define EXTREME_CARPACCIO_CLIENT_API __declspec(dllexport)
#else
#define EXTREME_CARPACCIO_CLIENT_API __declspec(dllimport)
#endif
#else
#define EXTREME_CARPACCIO_CLIENT_API
#endif

#endif // EXTREME_CARPACCIO_CLIENT_CONFIG
Loading