-
Notifications
You must be signed in to change notification settings - Fork 0
First proposed release #3
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
Open
MarioIvancik
wants to merge
5
commits into
main
Choose a base branch
from
BAF-1155/1.0.0_release
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ea6466b
added missing documentation; fixed examples; additional CMakeLists ch…
MarioIvancik 5dca83f
coderabbit suggestions
MarioIvancik 0bc5cad
use std::expected for callFunc return; return error on simultaneous c…
MarioIvancik 67d16fb
better handling of simultaneous callFunc calls
MarioIvancik 4d64622
remove poinless cmake line
MarioIvancik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
CMAKE_MINIMUM_REQUIRED(VERSION 3.25 FATAL_ERROR) | ||
|
||
ADD_EXECUTABLE(example main.cpp) | ||
SET(CMAKE_CXX_STANDARD 23) | ||
|
||
TARGET_LINK_LIBRARIES(example PUBLIC async-function-execution-shared) | ||
IF(NOT TARGET async-function-execution-shared) | ||
MESSAGE(FATAL_ERROR "The async-function-execution-shared target was not found. Please build the example as part of the async-function-execution-shared project.") | ||
ENDIF() | ||
|
||
ADD_EXECUTABLE(example_producer main_producer.cpp) | ||
ADD_EXECUTABLE(example_consumer main_consumer.cpp) | ||
ADD_EXECUTABLE(example_driver main_driver.cpp) | ||
|
||
TARGET_LINK_LIBRARIES(example_producer PUBLIC async-function-execution-shared) | ||
TARGET_LINK_LIBRARIES(example_consumer PUBLIC async-function-execution-shared) | ||
TARGET_LINK_LIBRARIES(example_driver PUBLIC async-function-execution-shared) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Async function execution example | ||
|
||
This folder contains a simple example of the usage of this project. 3 executables will be built: the aeron driver, the producer and the consumer. | ||
|
||
## Build | ||
|
||
Examples are built as part of the main project. Don't use the CMakeLists file in the examples folder. | ||
|
||
```bash | ||
mkdir -p _build_example && cd _build_example | ||
cmake ../ -DBRINGAUTO_SAMPLES=ON | ||
make | ||
``` | ||
|
||
## Run | ||
|
||
```bash | ||
# Run the executables in this order | ||
./example_driver | ||
./example_consumer | ||
./example_producer | ||
``` |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include <bringauto/async_function_execution/AsyncFunctionExecutor.hpp> | ||
#include <bringauto/async_function_execution/AeronDriver.hpp> | ||
|
||
|
||
|
||
using namespace bringauto::async_function_execution; | ||
|
||
struct SerializableString final { | ||
std::string value {}; | ||
SerializableString() = default; | ||
explicit SerializableString(std::string str) : value(std::move(str)) {} | ||
|
||
std::span<const uint8_t> serialize() const { | ||
return std::span {reinterpret_cast<const uint8_t *>(value.data()), value.size()}; | ||
} | ||
void deserialize(std::span<const uint8_t> bytes) { | ||
value = std::string {reinterpret_cast<const char *>(bytes.data()), bytes.size()}; | ||
} | ||
}; | ||
|
||
FunctionDefinition ExampleFunc1 { | ||
FunctionId { 1 }, | ||
Return { SerializableString {} }, | ||
Arguments { int {}, SerializableString {}, float {} } | ||
}; | ||
|
||
FunctionDefinition ExampleFunc2 { | ||
FunctionId { 2 }, | ||
Return { SerializableString {} }, | ||
Arguments { int {}, SerializableString {} } | ||
}; | ||
|
||
FunctionDefinition ExampleFunc3 { | ||
FunctionId { 3 }, | ||
Return { SerializableString {} }, | ||
Arguments { int {} } | ||
}; | ||
|
||
|
||
int main() { | ||
AsyncFunctionExecutor executor { | ||
Config { | ||
.isProducer = false, | ||
}, | ||
FunctionList { ExampleFunc1, ExampleFunc2, ExampleFunc3 }, | ||
}; | ||
|
||
if (executor.connect() != 0) { | ||
std::cerr << "Consumer: Failed to connect to executor" << std::endl; | ||
return 1; | ||
} | ||
|
||
while (true) { | ||
auto [funcId, argBytes] = executor.pollFunction(); | ||
|
||
switch (funcId.value) { | ||
case 1: { | ||
auto [arg1, arg2, arg3] = executor.getFunctionArgs(ExampleFunc1, argBytes); | ||
std::cout << "Consumer: Received Function 1 call with args (" << arg1 << ", " << arg2.value << ", " << arg3 << ")." << std::endl; | ||
executor.sendReturnMessage(funcId, SerializableString{"Func 1 return value"}); | ||
break; | ||
} | ||
case 2: { | ||
auto [arg1, arg2] = executor.getFunctionArgs(ExampleFunc2, argBytes); | ||
std::cout << "Consumer: Received Function 2 call with args (" << arg1 << ", " << arg2.value << ")." << std::endl; | ||
executor.sendReturnMessage(funcId, SerializableString{"Func 2 return value"}); | ||
break; | ||
} | ||
case 3: { | ||
auto [arg1] = executor.getFunctionArgs(ExampleFunc3, argBytes); | ||
std::cout << "Consumer: Received Function 3 call with args (" << arg1 << ")" << std::endl; | ||
executor.sendReturnMessage(funcId, SerializableString{"Func 3 return value"}); | ||
break; | ||
} | ||
default: | ||
std::cerr << "Consumer: Unknown function ID received: " << static_cast<int>(funcId.value) << std::endl; | ||
throw std::runtime_error("Unknown function ID"); | ||
} | ||
} | ||
|
||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <bringauto/async_function_execution/AeronDriver.hpp> | ||
|
||
|
||
|
||
using namespace bringauto::async_function_execution; | ||
|
||
int main() { | ||
AeronDriver driver; | ||
driver.run(); | ||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include <bringauto/async_function_execution/AsyncFunctionExecutor.hpp> | ||
|
||
|
||
using namespace bringauto::async_function_execution; | ||
|
||
struct SerializableString final { | ||
std::string value {}; | ||
SerializableString() = default; | ||
explicit SerializableString(std::string str) : value(std::move(str)) {} | ||
|
||
std::span<const uint8_t> serialize() const { | ||
return std::span {reinterpret_cast<const uint8_t *>(value.data()), value.size()}; | ||
} | ||
void deserialize(std::span<const uint8_t> bytes) { | ||
value = std::string {reinterpret_cast<const char *>(bytes.data()), bytes.size()}; | ||
} | ||
}; | ||
|
||
FunctionDefinition ExampleFunc1 { | ||
FunctionId { 1 }, | ||
Return { SerializableString {} }, | ||
Arguments { int {}, SerializableString {}, float {} } | ||
}; | ||
|
||
FunctionDefinition ExampleFunc2 { | ||
FunctionId { 2 }, | ||
Return { SerializableString {} }, | ||
Arguments { int {}, SerializableString {} } | ||
}; | ||
|
||
FunctionDefinition ExampleFunc3 { | ||
FunctionId { 3 }, | ||
Return { SerializableString {} }, | ||
Arguments { int {} } | ||
}; | ||
|
||
|
||
int main() { | ||
AsyncFunctionExecutor executor { | ||
Config { | ||
.isProducer = true, | ||
.defaultTimeout = std::chrono::seconds(1) | ||
}, | ||
FunctionList { ExampleFunc1, ExampleFunc2, ExampleFunc3 }, | ||
}; | ||
|
||
if (executor.connect() != 0) { | ||
std::cerr << "Producer: Failed to connect to executor" << std::endl; | ||
return 1; | ||
} | ||
|
||
auto result1 = executor.callFunc(ExampleFunc1, 42, "Hello", 3.14f).value(); | ||
std::cout << result1.value << std::endl; | ||
auto result2 = executor.callFunc(ExampleFunc2, 100, "World").value(); | ||
std::cout << result2.value << std::endl; | ||
auto result3 = executor.callFunc(ExampleFunc3, 123).value(); | ||
std::cout << result3.value << std::endl; | ||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.