blob: 37aeba1f96a55a1ec7ce1add4c9f7937b949d24e [file] [log] [blame]
Alexei Frolov26e3ae62020-05-04 17:06:17 -07001# Copyright 2020 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7# https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15import("$dir_pw_docgen/docs.gni")
Alexei Frolov5d6d3922020-05-08 13:57:02 -070016import("$dir_pw_protobuf_compiler/proto.gni")
Alexei Frolov26e3ae62020-05-04 17:06:17 -070017import("$dir_pw_unit_test/test.gni")
18
19config("default_config") {
20 include_dirs = [ "public" ]
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070021 visibility = [ ":*" ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -070022}
23
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070024# pw_rpc servers depend on the protobuf library used to encode and decode
25# requests and responses when invoking methods. This template is used to create
26# instances of the pw_rpc server library with different implementations.
27#
28# The implementation parameter must refer to a library that provides the
29# definition of the Method class in pw_rpc/internal/method.h. The Method class
30# provides the Invoke function, which handles the server use to call into the
31# RPC functions themselves.
32template("_pw_rpc_server_library") {
33 assert(defined(invoker.implementation),
34 "_pw_rpc_server_library requires an implementation to be set")
35
36 source_set(target_name) {
37 forward_variables_from(invoker, "*")
38
39 public_configs = [ ":default_config" ]
40 public_deps = [
41 ":common",
42 dir_pw_span,
43 dir_pw_status,
44 implementation,
45 ]
46 deps = [
47 dir_pw_assert,
48 dir_pw_log,
49 ]
50 public = [
51 "public/pw_rpc/server.h",
52 "public/pw_rpc/server_context.h",
53 ]
54 sources = [
55 "public/pw_rpc/internal/service.h",
56 "public/pw_rpc/internal/service_registry.h",
57 "server.cc",
58 "service.cc",
59 "service_registry.cc",
60 ]
61 allow_circular_includes_from = [ implementation ]
62 friend = [ ":*" ]
63 }
64}
65
66# Classes with no dependencies on the protobuf library for method invocations.
67source_set("common") {
Alexei Frolov26e3ae62020-05-04 17:06:17 -070068 public_configs = [ ":default_config" ]
69 public_deps = [
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070070 ":protos_pwpb",
Alexei Frolov26e3ae62020-05-04 17:06:17 -070071 dir_pw_assert,
72 dir_pw_span,
Alexei Frolov5d6d3922020-05-08 13:57:02 -070073 dir_pw_status,
Alexei Frolov26e3ae62020-05-04 17:06:17 -070074 ]
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070075 public = [ "public/pw_rpc/channel.h" ]
Alexei Frolov5d6d3922020-05-08 13:57:02 -070076 sources = [
77 "channel.cc",
78 "packet.cc",
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070079 "public/pw_rpc/internal/base_method.h",
Alexei Frolov5d6d3922020-05-08 13:57:02 -070080 "public/pw_rpc/internal/packet.h",
Alexei Frolov5d6d3922020-05-08 13:57:02 -070081 ]
82 friend = [ ":*" ]
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070083 visibility = [ ":*" ]
Alexei Frolov5d6d3922020-05-08 13:57:02 -070084}
85
86pw_proto_library("protos") {
87 sources = [ "pw_rpc_protos/packet.proto" ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -070088}
89
90pw_doc_group("docs") {
91 sources = [ "docs.rst" ]
92}
93
94pw_test_group("tests") {
Alexei Frolov5d6d3922020-05-08 13:57:02 -070095 tests = [
96 ":packet_test",
97 ":server_test",
98 ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -070099}
100
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700101# RPC server for tests only. A mock method implementation is used.
102_pw_rpc_server_library("test_server") {
103 implementation = ":test_method"
104 visibility = [ ":*" ]
105}
106
107config("test_config") {
108 include_dirs = [ "test_public" ]
109 visibility = [ ":test_method" ]
110}
111
112source_set("test_method") {
113 public_configs = [ ":test_config" ]
114 public = [ "test_public/pw_rpc/internal/method.h" ]
115 public_deps = [ ":common" ]
116 visibility = [ ":test_server" ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700117}
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700118
119pw_test("packet_test") {
120 deps = [
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700121 ":common",
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700122 dir_pw_protobuf,
123 ]
124 sources = [ "packet_test.cc" ]
125}
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700126
127pw_test("server_test") {
128 deps = [
129 ":protos_pwpb",
130 ":test_server",
131 dir_pw_assert,
132 ]
133 sources = [ "server_test.cc" ]
134}