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 42 : DataObj::DataObj(Entity * const sendEntityPtr, const Mbuf * const mbufPtr)
17 42 : : sendEntity_(sendEntityPtr),
18 42 : mbuf_(mbufPtr)
19 : {
20 42 : }
21 :
22 36 : void DataObj::AddRecvEntity(Entity *const recvEntityPtr)
23 : {
24 36 : recvEntities_.emplace_back(recvEntityPtr);
25 36 : }
26 :
27 42 : DataObjManager &DataObjManager::Instance()
28 : {
29 : static DataObjManager ins;
30 42 : return ins;
31 : }
32 :
33 11 : bool DataObj::RemoveRecvEntity(const Entity * const recvEntityPtr)
34 : {
35 11 : for (auto iter = recvEntities_.begin(); iter != recvEntities_.end(); iter++) {
36 11 : if ((*iter)->Equal(recvEntityPtr)) {
37 11 : (void) recvEntities_.erase(iter);
38 11 : return true;
39 : }
40 : }
41 0 : return false;
42 : }
43 :
44 1 : bool DataObj::UpdateRecvEntities(const EntityPtr group, const EntityPtr elem)
45 : {
46 1 : if (RemoveRecvEntity(group.get())) {
47 1 : AddRecvEntity(elem.get());
48 1 : return true;
49 : }
50 0 : return false;
51 : }
52 :
53 42 : DataObjPtr DataObjManager::CreateDataObj(Entity * const sendEntityPtr, const Mbuf * const mbufPtr) const
54 : {
55 : try {
56 42 : return std::make_shared<DataObj>(sendEntityPtr, mbufPtr);
57 0 : } catch (std::bad_alloc &error) {
58 : (void) error;
59 0 : return nullptr;
60 0 : }
61 : return nullptr;
62 : }
63 : } // namespace dgw
|