1 /* 2 * Copyright (C) 2023 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_PIGWEED_HAL_CHANNEL_OUTPUT_H_ 18 #define CHRE_PIGWEED_HAL_CHANNEL_OUTPUT_H_ 19 20 #include <cstdint> 21 22 #include "chre/util/non_copyable.h" 23 #include "chre_host/socket_client.h" 24 #include "pw_rpc/channel.h" 25 #include "pw_span/span.h" 26 27 namespace android::chre { 28 29 /** 30 * RPC Channel Output for native vendor processes. 31 */ 32 class HalChannelOutput : public ::chre::NonCopyable, 33 public pw::rpc::ChannelOutput { 34 public: HalChannelOutput(android::chre::SocketClient & client,uint32_t hostEndpointId,uint64_t serverNanoappId,size_t maxMessageLen)35 HalChannelOutput(android::chre::SocketClient &client, uint32_t hostEndpointId, 36 uint64_t serverNanoappId, size_t maxMessageLen) 37 : pw::rpc::ChannelOutput("CHRE"), 38 mServerNanoappId(serverNanoappId), 39 mHostEndpointId(hostEndpointId), 40 mMaxMessageLen(maxMessageLen), 41 mSocketClient(client) {} 42 43 size_t MaximumTransmissionUnit() override; 44 45 pw::Status Send(pw::span<const std::byte> buffer) override; 46 47 private: 48 // Padding used to encode nanoapp messages. 49 static constexpr size_t kFlatBufferPadding = 88; 50 51 const uint64_t mServerNanoappId; 52 const uint32_t mHostEndpointId; 53 const size_t mMaxMessageLen; 54 SocketClient &mSocketClient; 55 }; 56 57 } // namespace android::chre 58 59 #endif // CHRE_PIGWEED_HAL_CHANNEL_OUTPUT_H_