1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef RENDER_SERVICE_CLIENT_CORE_MESSAGE_RS_MESSAGE_PROCESSOR_H
16 #define RENDER_SERVICE_CLIENT_CORE_MESSAGE_RS_MESSAGE_PROCESSOR_H
17 
18 #include <memory>
19 #include <mutex>
20 #include <unordered_map>
21 #include "transaction/rs_transaction_data.h"
22 
23 #include "common/rs_macros.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 class RSCommand;
28 class RSB_EXPORT RSMessageProcessor final {
29 public:
30     static RSB_EXPORT RSMessageProcessor& Instance();
31 
32     void AddUIMessage(uint32_t pid, std::unique_ptr<RSCommand>& command);
33     void AddUIMessage(uint32_t pid, std::unique_ptr<RSCommand>&& command);
34 
35     bool HasTransaction() const;
36     bool HasTransaction(uint32_t pid) const;
37 
38     std::shared_ptr<RSTransactionData> GetTransaction(uint32_t pid);
39     std::unordered_map<uint32_t, std::shared_ptr<RSTransactionData>>&& GetAllTransactions();
40 private:
41     RSMessageProcessor() = default;
42     ~RSMessageProcessor();
43     RSMessageProcessor(const RSMessageProcessor&) = delete;
44     RSMessageProcessor(const RSMessageProcessor&&) = delete;
45     RSMessageProcessor& operator=(const RSMessageProcessor&) = delete;
46     RSMessageProcessor& operator=(const RSMessageProcessor&&) = delete;
47 
48 private:
49     mutable std::mutex transactionMapMutex_;
50     std::unordered_map<uint32_t, std::shared_ptr<RSTransactionData>> transactionMap_;
51 };
52 } // namespace Rosen
53 } // namespace OHOS
54 #endif // RENDER_SERVICE_CLIENT_CORE_MESSAGE_RS_MESSAGE_PROCESSOR_H
55