#pragma once /* ABSTRACT DEVICE COMPONENTS LIBRARY */ #include #include "../common/adc_traits.h" /* DEFINITIONS OF NETWORK COMPONENTS INTERFACES */ namespace adc::interfaces { template struct adc_duration_common_type; template struct adc_duration_common_type : std::common_type { }; template struct adc_duration_common_type : adc_duration_common_type, Ts...> { }; template using adc_duration_common_type_t = typename adc_duration_common_type::type; /* all STL helper duration types */ using adc_common_duration_t = adc_duration_common_type_t; /* struct NetService { typedef ImplementationDependentT netservice_ident_t; typedef ImplementationDependentT async_ctx_t; typedef ImplementationDependentT endpoint_t; template auto asyncAccept(const endpoint_t&, async_ctx_t&, const std::chrono::duration&) template auto asyncConnect(const endpoint_t&, async_ctx_t&, const std::chrono::duration&) template auto asyncSend(const R&, async_ctx_t&, const std::chrono::duration&) template auto asyncReceived(async_ctx_t&, const std::chrono::duration&) template auto accept(const endpoint_t&, const std::chrono::duration&) template auto connect(const endpoint_t&, const std::chrono::duration&) template auto send(const R&, const std::chrono::duration&) template R received(const std::chrono::duration&) } */ template concept adc_netservice_c = traits::adc_input_char_range && traits::adc_output_char_range && traits::adc_time_duration_c && requires(SRVT srv, const SRVT srv_const) { typename SRVT::netservice_ident_t; // netservice_ident_t ident() const { srv_const.ident() } -> std::same_as; typename SRVT::async_ctx_t; typename SRVT::endpoint_t; // asynchronous (non-blocking) operations srv.asyncAccept(std::declval(), std::declval(), std::declval()); srv.asyncConnect(std::declval(), std::declval(), std::declval()); srv.asyncSend(std::declval(), std::declval(), std::declval()); srv.asyncReceive(std::declval(), std::declval()); // synchronous (blocking) operations srv.accept(std::declval(), std::declval()); srv.connect(std::declval(), std::declval()); srv.send(std::declval(), std::declval()); { srv.receive(std::declval()) } -> std::same_as; srv.close(); }; /* NETWORK SESSION */ template concept adc_netsession_c = std::derived_from> && requires(SESST sess, const SESST sess_const) { typename SESST::netsession_ident_t; // netsession_ident_t ident() const { sess_const.ident() } -> std::same_as; sess.start(); sess.stop(); }; /* NETWORK SESSION-LEVEL PROTOCOL */ template concept adc_netsession_proto_c = traits::adc_input_char_range && requires(SESS_PROTOT proto, const SESS_PROTOT proto_const) { typename SESS_PROTOT::proto_ident_t; // proto_ident_t ident() const (const method) { proto_const.ident() } -> std::same_as; // typename SESS_PROTOT::search_result_t; // search for the first occurence of valid protocol sequence in input user byte sequence // the method must return std::tuple: // start - input range iterator of the sequence first byte // stop - input range iterator of the sequence end ("after-the-last" byte!!!) // flag - true if valid sequence was found, false - otherwise { proto.search(std::declval()) } -> std::same_as, std::ranges::iterator_t, bool>>; // construct netsession protocol representation of input user byte sequence // the method must return a range of char range views or output char range { proto.toProto(std::declval()) } -> traits::adc_range_of_view_or_output_char_range; // return user byte sequence from input netsession protocol representation // the method must return a view of char range or output char range { proto.fromProto(std::declval()) } -> traits::adc_view_or_output_char_range; }; } // namespace adc::interfaces