1 // Copyright 2021 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 #pragma once 15 16 #include <cstdint> 17 18 #include "pw_bytes/span.h" 19 #include "pw_rpc/internal/lock.h" 20 #include "pw_status/status.h" 21 22 namespace pw::rpc { 23 namespace internal { 24 class Call; 25 } 26 27 // The Writer class allows writing requests or responses to a streaming RPC. 28 // ClientWriter, ClientReaderWriter, ServerWriter, and ServerReaderWriter 29 // classes can be used as a generic Writer. 30 class Writer { 31 public: 32 Writer(const Writer&) = delete; 33 Writer(Writer&&) = delete; 34 35 Writer& operator=(const Writer&) = delete; 36 Writer& operator=(Writer&&) = delete; 37 38 bool active() const; 39 uint32_t channel_id() const; 40 41 Status Write(ConstByteSpan payload) PW_LOCKS_EXCLUDED(internal::rpc_lock()); 42 43 private: 44 // Only allow Call to inherit from Writer. This guarantees that Writers can 45 // always safely downcast to Call. 46 friend class internal::Call; 47 48 // Writers cannot be created directly. They may only be used as a reference to 49 // an existing call object. 50 constexpr Writer() = default; 51 }; 52 53 } // namespace pw::rpc 54