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 44 : ~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 { return copyRef_; }
37 :
38 65 : inline const Mbuf* GetMbuf() const { return mbuf_; }
39 :
40 104 : inline Entity* GetSendEntity() const { return sendEntity_; }
41 :
42 : void AddRecvEntity(Entity* const recvEntityPtr);
43 :
44 67 : inline size_t GetRecvEntitySize() { return recvEntities_.size(); }
45 :
46 3 : inline std::vector<Entity*>& GetRecvEntities() { return recvEntities_; }
47 :
48 : bool RemoveRecvEntity(const Entity* const recvEntityPtr);
49 :
50 : bool UpdateRecvEntities(const EntityPtr group, const EntityPtr elem);
51 :
52 15 : inline void MaintainMbuf() { maintainMbuf_ = true; }
53 :
54 9 : inline bool ShouldMaintainMbuf() const { return maintainMbuf_; }
55 :
56 : private:
57 : Entity* sendEntity_;
58 : std::vector<Entity*> recvEntities_;
59 : const bool copyRef_ = false;
60 : const Mbuf* mbuf_ = nullptr;
61 : bool maintainMbuf_ = false;
62 : };
63 :
64 : using DataObjPtr = std::shared_ptr<DataObj>;
65 : using DataObjList = std::list<DataObjPtr>;
66 :
67 : class DataObjManager {
68 : public:
69 : explicit DataObjManager() = default;
70 :
71 : ~DataObjManager() = default;
72 :
73 : DataObjManager(const DataObjManager&) = delete;
74 : DataObjManager(const DataObjManager&&) = delete;
75 : DataObjManager& operator=(const DataObjManager&) = delete;
76 : DataObjManager& operator=(DataObjManager&&) = delete;
77 :
78 : static DataObjManager& Instance();
79 : DataObjPtr CreateDataObj(Entity* const sendEntityPtr, const Mbuf* const mbufPtr) const;
80 : };
81 : } // namespace dgw
82 :
83 : #endif
|