Line data Source code
1 : /*
2 : *
3 : * Copyright (c) 2023 Project CHIP Authors
4 : * All rights reserved.
5 : *
6 : * Licensed under the Apache License, Version 2.0 (the "License");
7 : * you may not use this file except in compliance with the License.
8 : * You may obtain a copy of the License at
9 : *
10 : * http://www.apache.org/licenses/LICENSE-2.0
11 : *
12 : * Unless required by applicable law or agreed to in writing, software
13 : * distributed under the License is distributed on an "AS IS" BASIS,
14 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 : * See the License for the specific language governing permissions and
16 : * limitations under the License.
17 : */
18 :
19 : #include "BdxTransferServer.h"
20 :
21 : namespace chip {
22 : namespace bdx {
23 :
24 0 : CHIP_ERROR BDXTransferServer::Init(System::Layer * systemLayer, Messaging::ExchangeManager * exchangeMgr)
25 : {
26 0 : VerifyOrReturnError(nullptr != systemLayer, CHIP_ERROR_INVALID_ARGUMENT);
27 0 : VerifyOrReturnError(nullptr != exchangeMgr, CHIP_ERROR_INVALID_ARGUMENT);
28 :
29 0 : mSystemLayer = systemLayer;
30 0 : mExchangeMgr = exchangeMgr;
31 0 : return mExchangeMgr->RegisterUnsolicitedMessageHandlerForType(MessageType::SendInit, this);
32 : }
33 :
34 0 : CHIP_ERROR BDXTransferServer::OnUnsolicitedMessageReceived(const PayloadHeader & payloadHeader,
35 : Messaging::ExchangeDelegate *& newDelegate)
36 : {
37 0 : auto * logTransfer = mPoolDelegate.Allocate(mDelegate, mSystemLayer);
38 0 : VerifyOrReturnError(nullptr != logTransfer, CHIP_ERROR_NO_MEMORY);
39 :
40 0 : newDelegate = logTransfer;
41 0 : return CHIP_NO_ERROR;
42 : }
43 :
44 0 : void BDXTransferServer::OnExchangeCreationFailed(Messaging::ExchangeDelegate * delegate)
45 : {
46 0 : auto * logTransfer = static_cast<BdxTransferDiagnosticLog *>(delegate);
47 0 : mPoolDelegate.Release(logTransfer);
48 0 : }
49 :
50 0 : void BDXTransferServer::Shutdown()
51 : {
52 0 : VerifyOrReturn(nullptr != mSystemLayer);
53 0 : VerifyOrReturn(nullptr != mExchangeMgr);
54 :
55 0 : LogErrorOnFailure(mExchangeMgr->UnregisterUnsolicitedMessageHandlerForType(MessageType::SendInit));
56 :
57 0 : mSystemLayer = nullptr;
58 0 : mExchangeMgr = nullptr;
59 : }
60 :
61 : } // namespace bdx
62 : } // namespace chip
|