Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #include "data_obj_manager.h"
12 : #include "fsm/state_base.h"
13 : #include "entity_manager.h"
14 :
15 : namespace dgw {
16 44 : DataObj::DataObj(Entity* const sendEntityPtr, const Mbuf* const mbufPtr) : sendEntity_(sendEntityPtr), mbuf_(mbufPtr) {}
17 :
18 38 : void DataObj::AddRecvEntity(Entity* const recvEntityPtr) { recvEntities_.emplace_back(recvEntityPtr); }
19 :
20 43 : DataObjManager& DataObjManager::Instance()
21 : {
22 : static DataObjManager ins;
23 43 : return ins;
24 : }
25 :
26 15 : bool DataObj::RemoveRecvEntity(const Entity* const recvEntityPtr)
27 : {
28 15 : for (auto iter = recvEntities_.begin(); iter != recvEntities_.end(); iter++) {
29 13 : if ((*iter)->Equal(recvEntityPtr)) {
30 13 : (void)recvEntities_.erase(iter);
31 13 : return true;
32 : }
33 : }
34 2 : return false;
35 : }
36 :
37 3 : bool DataObj::UpdateRecvEntities(const EntityPtr group, const EntityPtr elem)
38 : {
39 3 : if (RemoveRecvEntity(group.get())) {
40 2 : AddRecvEntity(elem.get());
41 2 : return true;
42 : }
43 1 : return false;
44 : }
45 :
46 43 : DataObjPtr DataObjManager::CreateDataObj(Entity* const sendEntityPtr, const Mbuf* const mbufPtr) const
47 : {
48 : try {
49 43 : return std::make_shared<DataObj>(sendEntityPtr, mbufPtr);
50 0 : } catch (std::bad_alloc& error) {
51 : (void)error;
52 0 : return nullptr;
53 0 : }
54 : return nullptr;
55 : }
56 : } // namespace dgw
|