• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 
16 #include "transaction/rs_transaction_data.h"
17 
18 #include "command/rs_command.h"
19 #include "command/rs_command_factory.h"
20 #include "platform/common/rs_log.h"
21 
22 namespace OHOS {
23 namespace Rosen {
~RSTransactionData()24 RSTransactionData::~RSTransactionData() noexcept
25 {
26 }
27 
28 #ifdef ROSEN_OHOS
Unmarshalling(Parcel & parcel)29 RSTransactionData* RSTransactionData::Unmarshalling(Parcel& parcel)
30 {
31     auto transactionData = new RSTransactionData();
32     if (transactionData->UnmarshallingCommand(parcel)) {
33         return transactionData;
34     }
35     ROSEN_LOGE("RSTransactionData Unmarshalling Failed");
36     delete transactionData;
37     return nullptr;
38 }
39 
Marshalling(Parcel & parcel) const40 bool RSTransactionData::Marshalling(Parcel& parcel) const
41 {
42     bool success = true;
43     for (auto& command : commands_) {
44         success = success && command->Marshalling(parcel);
45     }
46 
47     return success;
48 }
49 #endif // ROSEN_OHOS
50 
Process(RSContext & context)51 void RSTransactionData::Process(RSContext& context)
52 {
53     for (auto& command : commands_) {
54         if (command != nullptr) {
55             command->Process(context);
56         }
57     }
58 }
59 
Clear()60 void RSTransactionData::Clear()
61 {
62     commands_.clear();
63 }
64 
AddCommand(std::unique_ptr<RSCommand> & command)65 void RSTransactionData::AddCommand(std::unique_ptr<RSCommand>& command)
66 {
67     commands_.emplace_back(std::move(command));
68 }
69 
AddCommand(std::unique_ptr<RSCommand> && command)70 void RSTransactionData::AddCommand(std::unique_ptr<RSCommand>&& command)
71 {
72     commands_.emplace_back(std::move(command));
73 }
74 
75 #ifdef ROSEN_OHOS
UnmarshallingCommand(Parcel & parcel)76 bool RSTransactionData::UnmarshallingCommand(Parcel& parcel)
77 {
78     uint16_t commandType = 0;
79     uint16_t commandSubType = 0;
80     bool isNotFinished = true;
81     commands_.clear();
82     while (isNotFinished) {
83         if (!(parcel.ReadUint16(commandType) && parcel.ReadUint16(commandSubType))) {
84             isNotFinished = false;
85             break;
86         }
87         auto func = RSCommandFactory::Instance().GetUnmarshallingFunc(commandType, commandSubType);
88         if (func == nullptr) {
89             break;
90         }
91         auto command = (*func)(parcel);
92         if (command == nullptr) {
93             break;
94         }
95         AddCommand(std::unique_ptr<RSCommand>(command));
96     }
97     return !isNotFinished;
98 }
99 
100 #endif // ROSEN_OHOS
101 
102 } // namespace Rosen
103 } // namespace OHOS
104