Skip to content

Commit cae878d

Browse files
Small changes for alpha4 (#35)
* fixed typos, added clang-tidy script * adapted RpcClient to new signature
1 parent 345441e commit cae878d

6 files changed

Lines changed: 106 additions & 21 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ $ cmake --build . -- -j
3535
```
3636

3737
## Usage
38-
After completing the project build, the build artifacts can generally be found in the `build/Release/bin` directory within your workspace.
39-
You can run the example using the supplied configuration file located in the `/resources` directory.For instance, to run the RPC example, use the following commands:
38+
After building the project, the build artifacts can generally be found in the `build/Release/bin` directory within your workspace.
39+
You can run the example using the supplied configuration file located in the `/resources` directory. For instance, to run the RPC example, use the following commands:
4040

41-
```bash
41+
```
4242
$ ./rpc_server <path/to/config>
4343
$ ./rpc_client <path/to/config>
4444
```

conanfile.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[requires]
2-
up-cpp/1.0.1-dev
2+
up-cpp/[^1.0.1, include_prerelease]
33
spdlog/[~1.13]
44
up-core-api/1.6.0-alpha4
55
protobuf/[>=3.21.12]

lint/clang-tidy.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/bash
2+
3+
PROJECT_ROOT="$(realpath "$(dirname "$0")/../")"
4+
5+
if [ -n "$(which clang-tidy-13)" ]; then
6+
# NOTE: Using clang-tidy-13 in CI system, too
7+
LINTER=clang-tidy-13
8+
elif [ -n "$(which clang-tidy)" ]; then
9+
echo "Did not find clang-tidy-13. Trying clang-tidy. Results may not"
10+
echo "match formatting in GitHub CI process."
11+
LINTER=clang-tidy
12+
else
13+
echo "Could not find clang-tidy. Please make sure it is installed" 1>&2
14+
exit 2
15+
fi
16+
17+
usage() {
18+
echo "$(basename "$0") path/to/compile_commands.json [source_to_lint]" 1>&2
19+
echo 1>&2
20+
echo " compile_commands.json" 1>&2
21+
echo " Produced during a cmake build when configured with the" 1>&2
22+
echo " -DCMAKE_EXPORT_COMPILE_COMMANDS=yes flag" 1>&2
23+
echo 1>&2
24+
echo " source_to_lint (optional)" 1>&2
25+
echo " Source file to run clang-tidy against. If not specified," 1>&2
26+
echo " all source files in the repo will be scanned." 1>&2
27+
}
28+
29+
if [ "$1" == "-h" ] || [ "$1" == "--help" ] || [ "$1" == "/h" ] || [ "$1" == "/?" ]; then
30+
usage
31+
exit
32+
fi
33+
34+
compile_database="$1"
35+
36+
if [ -z "$compile_database" ]; then
37+
echo "No compile database specified. Make sure cmake was configured" 1>&2
38+
echo "with '-DCMAKE_EXPORT_COMPILE_COMMANDS=yes' and re-run the build" 1>&2
39+
echo 1>&2
40+
echo "Usage:" 1>&2
41+
usage
42+
exit 1
43+
elif [ ! -f "$compile_database" ]; then
44+
echo "Compile database file not found. Make sure cmake was configured" 1>&2
45+
echo "with '-DCMAKE_EXPORT_COMPILE_COMMANDS=yes' and re-run the build" 1>&2
46+
echo 1>&2
47+
echo "Usage:" 1>&2
48+
usage
49+
exit 1
50+
fi
51+
52+
compile_database="$(realpath "$compile_database")"
53+
54+
target_source="$2"
55+
56+
if [ -z "$target_source" ]; then
57+
echo "Running $LINTER on all files in '$PROJECT_ROOT'"
58+
shopt -s globstar
59+
60+
pushd "$PROJECT_ROOT" > /dev/null
61+
for f in pubsub/include/**/*.h pubsub/src/**/*.cpp rpc/include/**/*.h rpc/src/**/*.cpp; do
62+
if [[ ! ("$f" =~ "build/") ]]; then
63+
echo
64+
echo "Checking file '$f'"
65+
$LINTER -p "$(dirname "$compile_database")" "$f"
66+
fi
67+
done
68+
popd > /dev/null
69+
exit
70+
fi
71+
72+
if [ ! -f "$target_source" ]; then
73+
echo "Target source file '$target_source' not found." 1>&2
74+
echo 1>&2
75+
echo "Usage:" 1>&2
76+
usage
77+
exit 1
78+
fi
79+
80+
echo "Running $LINTER on '$target_source'"
81+
$LINTER -p "$(dirname "$compile_database")" "$target_source"

pubsub/include/common.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,38 @@
99
//
1010
// SPDX-License-Identifier: Apache-2.0
1111
//
12-
#ifndef PUBSUB_COMMON_H
13-
#define PUBSUB_COMMON_H
12+
#ifndef COMMON_H
13+
#define COMMON_H
1414

1515
#include <uprotocol/v1/uri.pb.h>
1616

17-
uprotocol::v1::UUri getUUri(int const resource_id) {
17+
constexpr int DUMMY_UE_ID = 0x18002;
18+
constexpr int TIMER_RESOURCE_ID = 0x8001;
19+
constexpr int RANDOM_RESOURCE_ID = 0x8002;
20+
constexpr int COUNTER_RESOURCE_ID = 0x8003;
21+
22+
inline uprotocol::v1::UUri getUUri(int const resource_id) {
1823
uprotocol::v1::UUri uuri;
1924
uuri.set_authority_name("test.app");
20-
uuri.set_ue_id(0x18002);
25+
uuri.set_ue_id(DUMMY_UE_ID);
2126
uuri.set_ue_version_major(1);
2227
uuri.set_resource_id(resource_id);
2328
return uuri;
2429
}
2530

26-
uprotocol::v1::UUri const& getTimeUUri() {
27-
static auto uuri = getUUri(0x8001);
31+
inline uprotocol::v1::UUri const& getTimeUUri() {
32+
static auto uuri = getUUri(TIMER_RESOURCE_ID);
2833
return uuri;
2934
}
3035

31-
uprotocol::v1::UUri const& getRandomUUri() {
32-
static auto uuri = getUUri(0x8002);
36+
inline uprotocol::v1::UUri const& getRandomUUri() {
37+
static auto uuri = getUUri(RANDOM_RESOURCE_ID);
3338
return uuri;
3439
}
3540

36-
uprotocol::v1::UUri const& getCounterUUri() {
37-
static auto uuri = getUUri(0x8003);
41+
inline uprotocol::v1::UUri const& getCounterUUri() {
42+
static auto uuri = getUUri(COUNTER_RESOURCE_ID);
3843
return uuri;
3944
}
4045

41-
#endif // PUBSUB_COMMON_H
46+
#endif // COMMON_H

rpc/include/common.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
//
1010
// SPDX-License-Identifier: Apache-2.0
1111
//
12-
#ifndef RPC_COMMON_H
13-
#define RPC_COMMON_H
12+
#ifndef COMMON_H
13+
#define COMMON_H
1414

1515
#include <uprotocol/v1/uri.pb.h>
1616
constexpr uint32_t RPC_UE_ID = 0x10001;
@@ -24,4 +24,4 @@ inline uprotocol::v1::UUri getRpcUUri(const int resource_id) {
2424
return uuri;
2525
}
2626

27-
#endif // RPC_COMMON_H
27+
#endif // COMMON_H

rpc/src/main_rpc_client.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,12 @@ int main(int argc, char* argv[]) {
9191
UUri source = getRpcUUri(0);
9292
UUri method = getRpcUUri(METHOD_RPC_RESOURCE_ID);
9393
auto transport = std::make_shared<ZenohUTransport>(source, args.at(1));
94-
auto client = RpcClient(transport, std::move(method),
95-
uprotocol::v1::UPriority::UPRIORITY_CS4,
94+
auto client = RpcClient(transport, uprotocol::v1::UPriority::UPRIORITY_CS4,
9695
std::chrono::milliseconds(RPCCLIENT_TTL));
9796
RpcClient::InvokeHandle handle;
9897

9998
while (!g_terminate) {
100-
handle = client.invokeMethod(OnReceive);
99+
handle = client.invokeMethod(method, OnReceive);
101100
sleep(1);
102101
}
103102

0 commit comments

Comments
 (0)