xref: /aosp_15_r20/system/chre/test/simulation/inc/rpc_test.h (revision 84e339476a462649f82315436d70fd732297a399)
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef TEST_SIMULATION_RPC_TEST
20 #define TEST_SIMULATION_RPC_TEST
21 
22 #include <stdint.h>
23 
24 #include "chre/util/pigweed/rpc_client.h"
25 #include "chre/util/pigweed/rpc_server.h"
26 #include "chre/util/singleton.h"
27 #include "rpc_test.pb.h"
28 #include "rpc_test.rpc.pb.h"
29 
30 namespace chre {
31 
32 constexpr uint64_t kPwRcpServerAppId = 0x0123456789000001;
33 constexpr uint64_t kPwRcpClientAppId = 0x0123456789000002;
34 
35 class RpcTestService final
36     : public chre::rpc::pw_rpc::nanopb::RpcTestService::Service<
37           RpcTestService> {
38  public:
39   // Increment RPC unary service definition.
40   // See generated IncrementService::Service for more details.
41   pw::Status Increment(const chre_rpc_NumberMessage &request,
42                        chre_rpc_NumberMessage &response);
43 };
44 
45 class Env {
46  public:
47   RpcTestService mRpcTestService;
48   chre::RpcServer mServer;
49   chre::RpcClient mClient{kPwRcpServerAppId};
50   pw::rpc::NanopbUnaryReceiver<chre_rpc_NumberMessage> mIncrementCall;
51   uint32_t mNumber;
52 
closeServer()53   void closeServer() {
54     mServer.close();
55   }
56 
closeClient()57   void closeClient() {
58     mClient.close();
59   }
60 };
61 
62 typedef Singleton<Env> EnvSingleton;
63 
64 }  // namespace chre
65 
66 #endif  // TEST_SIMULATION_RPC_TEST