Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 1 | # 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 | |
| 15 | import("$dir_pw_docgen/docs.gni") |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 16 | import("$dir_pw_protobuf_compiler/proto.gni") |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 17 | import("$dir_pw_unit_test/test.gni") |
| 18 | |
| 19 | config("default_config") { |
| 20 | include_dirs = [ "public" ] |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame^] | 21 | visibility = [ ":*" ] |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 22 | } |
| 23 | |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame^] | 24 | # 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. |
| 32 | template("_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. |
| 67 | source_set("common") { |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 68 | public_configs = [ ":default_config" ] |
| 69 | public_deps = [ |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame^] | 70 | ":protos_pwpb", |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 71 | dir_pw_assert, |
| 72 | dir_pw_span, |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 73 | dir_pw_status, |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 74 | ] |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame^] | 75 | public = [ "public/pw_rpc/channel.h" ] |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 76 | sources = [ |
| 77 | "channel.cc", |
| 78 | "packet.cc", |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame^] | 79 | "public/pw_rpc/internal/base_method.h", |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 80 | "public/pw_rpc/internal/packet.h", |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 81 | ] |
| 82 | friend = [ ":*" ] |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame^] | 83 | visibility = [ ":*" ] |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | pw_proto_library("protos") { |
| 87 | sources = [ "pw_rpc_protos/packet.proto" ] |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | pw_doc_group("docs") { |
| 91 | sources = [ "docs.rst" ] |
| 92 | } |
| 93 | |
| 94 | pw_test_group("tests") { |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 95 | tests = [ |
| 96 | ":packet_test", |
| 97 | ":server_test", |
| 98 | ] |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame^] | 101 | # 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 | |
| 107 | config("test_config") { |
| 108 | include_dirs = [ "test_public" ] |
| 109 | visibility = [ ":test_method" ] |
| 110 | } |
| 111 | |
| 112 | source_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 Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 117 | } |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 118 | |
| 119 | pw_test("packet_test") { |
| 120 | deps = [ |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame^] | 121 | ":common", |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 122 | dir_pw_protobuf, |
| 123 | ] |
| 124 | sources = [ "packet_test.cc" ] |
| 125 | } |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame^] | 126 | |
| 127 | pw_test("server_test") { |
| 128 | deps = [ |
| 129 | ":protos_pwpb", |
| 130 | ":test_server", |
| 131 | dir_pw_assert, |
| 132 | ] |
| 133 | sources = [ "server_test.cc" ] |
| 134 | } |