Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / transport / TransportMgr.h
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *
5  *    Licensed under the Apache License, Version 2.0 (the "License");
6  *    you may not use this file except in compliance with the License.
7  *    You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *    Unless required by applicable law or agreed to in writing, software
12  *    distributed under the License is distributed on an "AS IS" BASIS,
13  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *    See the License for the specific language governing permissions and
15  */
16
17 /**
18  * @file
19  *   This file implements a stateless TransportMgr, it will took a raw message
20  * buffer from transports, and then extract the message header without decode it.
21  * For secure messages, it will pass it to the SecureSessionMgr, and for unsecure
22  * messages (rendezvous messages), it will pass it to RendezvousSession.
23  *   When sending messages, it will encode the packet header, and pass it to the
24  * transports.
25  *   The whole process is fully stateless.
26  */
27
28 #pragma once
29
30 #include <support/CodeUtils.h>
31 #include <support/logging/CHIPLogging.h>
32 #include <transport/TransportMgrBase.h>
33 #include <transport/raw/Base.h>
34 #include <transport/raw/MessageHeader.h>
35 #include <transport/raw/PeerAddress.h>
36 #include <transport/raw/Tuple.h>
37
38 namespace chip {
39
40 class TransportMgrBase;
41
42 class TransportMgrDelegate
43 {
44 public:
45     virtual ~TransportMgrDelegate() = default;
46     /**
47      * @brief
48      *   Handle received secure message.
49      *
50      * @param header    the received message header
51      * @param source    the source address of the package
52      * @param msgBuf    the buffer of (encrypted) payload
53      */
54     virtual void OnMessageReceived(const PacketHeader & header, const Transport::PeerAddress & source,
55                                    System::PacketBufferHandle msgBuf) = 0;
56 };
57
58 template <typename... TransportTypes>
59 class TransportMgr : public TransportMgrBase
60 {
61 public:
62     template <typename... Args>
63     CHIP_ERROR Init(Args &&... transportInitArgs)
64     {
65         CHIP_ERROR err = CHIP_NO_ERROR;
66
67         err = mTransport.Init(this, std::forward<Args>(transportInitArgs)...);
68         SuccessOrExit(err);
69         err = TransportMgrBase::Init(&mTransport);
70     exit:
71         return err;
72     }
73
74     template <typename... Args>
75     CHIP_ERROR ResetTransport(Args &&... transportInitArgs)
76     {
77         return mTransport.Init(this, std::forward<Args>(transportInitArgs)...);
78     }
79
80 private:
81     Transport::Tuple<TransportTypes...> mTransport;
82 };
83
84 } // namespace chip