1 /*
2  * Copyright (c) 2022 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 #ifndef OHOS_ABILITY_RUNTIME_QUICK_FIX_CALLBACK_WITH_RECORD_H
17 #define OHOS_ABILITY_RUNTIME_QUICK_FIX_CALLBACK_WITH_RECORD_H
18 
19 #include <atomic>
20 #include <list>
21 #include <mutex>
22 
23 #include "quick_fix_callback_stub.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 class QuickFixCallbackWithRecord : public QuickFixCallbackStub {
28 public:
QuickFixCallbackWithRecord(sptr<IQuickFixCallback> callback)29     explicit QuickFixCallbackWithRecord(sptr<IQuickFixCallback> callback)
30         : callback_(callback)
31     {}
32 
33     ~QuickFixCallbackWithRecord() override;
34 
35     void OnLoadPatchDone(int32_t resultCode, int32_t recordId) override;
36     void OnUnloadPatchDone(int32_t resultCode, int32_t recordId) override;
37     void OnReloadPageDone(int32_t resultCode, int32_t recordId) override;
38 
39     void AddRecordId(int32_t recordId);
40     void RemoveRecordId(int32_t recordId);
41 
42 private:
43     void ProcessCallback(int32_t resultCode, int32_t recordId);
44     bool IsRecordExist(const int32_t recordId);
45     bool IsRecordListEmpty();
46 
47     sptr<IQuickFixCallback> callback_ = nullptr;
48     std::mutex mutex_;
49     std::list<int32_t> recordIds_;
50     std::atomic<int32_t> finalResult = 0;
51 };
52 }  // namespace AppExecFwk
53 }  // namespace OHOS
54 #endif  // OHOS_ABILITY_RUNTIME_QUICK_FIX_CALLBACK_WITH_RECORD_H
55