• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025-2025 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 AUDIO_POLICY_ASYNC_ACTION_HANDLER_H
16 #define AUDIO_POLICY_ASYNC_ACTION_HANDLER_H
17 
18 #include <mutex>
19 #include "singleton.h"
20 #include "event_handler.h"
21 #include "event_runner.h"
22 
23 namespace OHOS {
24 namespace AudioStandard {
25 
26 // Priority for the Action
27 enum class ActionPriority : uint32_t {
28     // Action that should be distributed at once if possible.
29     IMMEDIATE = 0,
30     // High priority action, sorted by handle time, should be distributed before low priority action.
31     HIGH,
32     // Normal action, sorted by handle time.
33     LOW,
34 };
35 
36 class PolicyAsyncAction {
37 public:
38     virtual void Exec() = 0;
39     virtual ~PolicyAsyncAction() = default;
40 };
41 
42 struct AsyncActionDesc {
43     std::shared_ptr<PolicyAsyncAction> action;
44     int64_t delayTimeMs = 0; // Process the action after 'delayTimeMs' milliseconds.
45     ActionPriority priority = ActionPriority::LOW;
46 };
47 
48 class AudioPolicyAsyncActionHandler : public AppExecFwk::EventHandler {
49     DECLARE_DELAYED_SINGLETON(AudioPolicyAsyncActionHandler)
50 public:
51     bool PostAsyncAction(const AsyncActionDesc &desc);
52 
53 private:
54     void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override;
55 
56 private:
57     std::mutex actionMutex_;
58 };
59 } // namespace AudioStandard
60 } // namespace OHOS
61 #endif // AUDIO_POLICY_ASYNC_ACTION_HANDLER_H
62