Line data Source code
1 : /********************************************************************************
2 : * Copyright (c) 2026 Accenture
3 : *
4 : * This program and the accompanying materials are made available under the
5 : * terms of the Apache License Version 2.0 which is available at
6 : * https://www.apache.org/licenses/LICENSE-2.0
7 : *
8 : * SPDX-License-Identifier: Apache-2.0
9 : ********************************************************************************/
10 :
11 : #pragma once
12 :
13 : #include <ip/IPEndpoint.h>
14 : #include <someip/SomeIpConstants.h>
15 :
16 : #include <etl/expected.h>
17 : #include <etl/span.h>
18 : #include <cstdint>
19 :
20 : namespace someip
21 : {
22 : class NetworkResource;
23 :
24 : /**
25 : * Wrapper for a protocol specific network resource.
26 : */
27 : class NetworkChannel
28 : {
29 : public:
30 : NetworkChannel();
31 :
32 : NetworkChannel(
33 : NetworkResource& resource,
34 : ::ip::IPEndpoint const& remoteEndpoint,
35 : bool isThisMulticast = false,
36 : bool enableMagicCookie = false);
37 :
38 : NetworkChannel(NetworkChannel const& channel);
39 :
40 : NetworkChannel& operator=(NetworkChannel const& other);
41 :
42 : ~NetworkChannel();
43 :
44 : NetworkChannel(NetworkChannel&& other) noexcept;
45 : NetworkChannel& operator=(NetworkChannel&& other) noexcept;
46 :
47 : /**
48 : * The remote endpoint this channel is associated with.
49 : */
50 : ::ip::IPEndpoint const& getRemoteEndpoint() const;
51 :
52 : /**
53 : * The local port this channel is associated with.
54 : */
55 : ::etl::expected<uint16_t, PortError> getLocalPort() const;
56 :
57 : uint8_t getProto() const;
58 :
59 : ::etl::span<uint8_t> getInputBuffer() const;
60 : ::etl::span<uint8_t> getOutputBuffer() const;
61 :
62 : bool isOpen() const;
63 : bool isConnected() const;
64 : bool isMulticast() const;
65 : void close();
66 :
67 4 : bool isMagicCookieEnabled() const { return _magicCookieEnabled; }
68 :
69 : bool send(uint32_t length, ::etl::span<uint8_t> const& buffer);
70 : bool send(uint32_t length);
71 :
72 : private:
73 : NetworkResource* _pResource;
74 :
75 : ::ip::IPEndpoint _remoteEndpoint;
76 : bool _isMulticast;
77 : bool _magicCookieEnabled;
78 : };
79 :
80 : } // namespace someip
|