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 SYS_INSTALLER_ACTION_PROCESSER_H
17 #define SYS_INSTALLER_ACTION_PROCESSER_H
18 
19 #include <deque>
20 #include <map>
21 #include "iaction.h"
22 #include "macros_updater.h"
23 #include "status_manager.h"
24 
25 namespace OHOS {
26 namespace SysInstaller {
27 class ActionProcesser {
28     DISALLOW_COPY_MOVE(ActionProcesser);
29 public:
30     static ActionProcesser &GetInstance();
SetStatusManager(std::shared_ptr<StatusManager> statusManager)31     void SetStatusManager(std::shared_ptr<StatusManager> statusManager)
32     {
33         statusManager_ = statusManager;
34     }
35 
36     bool IsRunning();
37     void AddAction(std::unique_ptr<IAction> action);
38     void Start();
39     void Stop();
40     void Suspend();
41     void Resume();
42     void CompletedAction(InstallerErrCode errCode, const std::string &errStr);
43 
44 private:
45     ActionProcesser() = default;
46     ~ActionProcesser() = default;
47     void StartNextAction();
48 
49     std::shared_ptr<StatusManager> statusManager_ {};
50     std::deque<std::unique_ptr<IAction>> actionQue_ {};
51     std::unique_ptr<IAction> curAction_ {};
52     bool isRunning_ = false;
53     bool isSuspend_ = false;
54 };
55 } // SysInstaller
56 } // namespace OHOS
57 #endif // SYS_INSTALLER_ACTION_PROCESSER_H
58