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 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef CHRE_RPC_SERVICE_MANAGER_H_ 18 #define CHRE_RPC_SERVICE_MANAGER_H_ 19 20 #include <cinttypes> 21 #include <cstdint> 22 23 #include "chre/util/macros.h" 24 #include "chre/util/pigweed/chre_channel_output.h" 25 #include "chre/util/pigweed/rpc_server.h" 26 #include "chre/util/singleton.h" 27 #include "chre_api/chre.h" 28 #include "echo.rpc.pb.h" 29 30 namespace chre { 31 namespace rpc_service_test { 32 33 class EchoService final 34 : public pw::rpc::pw_rpc::nanopb::EchoService::Service<EchoService> { 35 public: 36 // Echo RPC service definition. See auto-generated EchoService::Service for 37 // more details. 38 pw::Status Echo(const pw_rpc_EchoMessage &request, 39 pw_rpc_EchoMessage &response); 40 }; 41 42 /** 43 * Class to manage the CHRE rpc service nanoapp. 44 */ 45 class RpcServiceManager { 46 public: 47 /** 48 * Allows the manager to do any init necessary as part of nanoappStart. 49 */ 50 bool start(); 51 52 /** 53 * Handle a CHRE event. 54 * 55 * @param senderInstanceId The instand ID that sent the event. 56 * @param eventType The type of the event. 57 * @param eventData The data for the event. 58 */ 59 void handleEvent(uint32_t senderInstanceId, uint16_t eventType, 60 const void *eventData); 61 62 /** 63 * Cleanup on nanoapp end. 64 */ 65 void end(); 66 67 /** 68 * Sets the permission for the next server message. 69 * 70 * @params permission Bitmasked CHRE_MESSAGE_PERMISSION_. 71 */ 72 void setPermissionForNextMessage(uint32_t permission); 73 74 private: 75 RpcServer mServer; 76 // pw_rpc service used to process the echo RPC 77 EchoService mEchoService; 78 }; 79 80 typedef chre::Singleton<RpcServiceManager> RpcServiceManagerSingleton; 81 82 } // namespace rpc_service_test 83 } // namespace chre 84 85 #endif // CHRE_RPC_SERVICE_MANAGER_H_ 86