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 : #ifndef DGW_DATA_OBJ_MANAGER_H
12 : #define DGW_DATA_OBJ_MANAGER_H
13 :
14 : #include <unistd.h>
15 : #include <list>
16 : #include <memory>
17 : #include <vector>
18 :
19 : #include "fsm/state_define.h"
20 : #include "driver/ascend_hal.h"
21 :
22 : namespace dgw {
23 : using EntityWeakPtr = std::weak_ptr<Entity>;
24 :
25 : class DataObj {
26 : public:
27 : explicit DataObj(Entity * const sendEntityPtr, const Mbuf * const mbufPtr);
28 :
29 42 : ~DataObj() = default;
30 :
31 : DataObj(const DataObj &) = delete;
32 : DataObj(const DataObj &&) = delete;
33 : DataObj &operator = (const DataObj &) = delete;
34 : DataObj &operator = (DataObj &&) = delete;
35 :
36 : inline bool CopRef() const
37 : {
38 : return copyRef_;
39 : }
40 :
41 65 : inline const Mbuf *GetMbuf() const
42 : {
43 65 : return mbuf_;
44 : }
45 :
46 104 : inline Entity *GetSendEntity() const
47 : {
48 104 : return sendEntity_;
49 : }
50 :
51 : void AddRecvEntity(Entity *const recvEntityPtr);
52 :
53 67 : inline size_t GetRecvEntitySize()
54 : {
55 67 : return recvEntities_.size();
56 : }
57 :
58 3 : inline std::vector<Entity*>& GetRecvEntities()
59 : {
60 3 : return recvEntities_;
61 : }
62 :
63 : bool RemoveRecvEntity(const Entity * const recvEntityPtr);
64 :
65 : bool UpdateRecvEntities(const EntityPtr group, const EntityPtr elem);
66 :
67 15 : inline void MaintainMbuf()
68 : {
69 15 : maintainMbuf_ = true;
70 15 : }
71 :
72 9 : inline bool ShouldMaintainMbuf() const
73 : {
74 9 : return maintainMbuf_;
75 : }
76 :
77 : private:
78 : Entity *sendEntity_;
79 : std::vector<Entity*> recvEntities_;
80 : const bool copyRef_ = false;
81 : const Mbuf *mbuf_ = nullptr;
82 : bool maintainMbuf_ = false;
83 : };
84 :
85 : using DataObjPtr = std::shared_ptr<DataObj>;
86 : using DataObjList = std::list<DataObjPtr>;
87 :
88 : class DataObjManager {
89 : public:
90 : explicit DataObjManager() = default;
91 :
92 : ~DataObjManager() = default;
93 :
94 : DataObjManager(const DataObjManager &) = delete;
95 : DataObjManager(const DataObjManager &&) = delete;
96 : DataObjManager &operator = (const DataObjManager &) = delete;
97 : DataObjManager &operator = (DataObjManager &&) = delete;
98 :
99 : static DataObjManager &Instance();
100 : DataObjPtr CreateDataObj(Entity * const sendEntityPtr, const Mbuf * const mbufPtr) const;
101 : };
102 : }
103 :
104 : #endif
|