• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ABILITY_MANAGER_ADAPTER_H
17 #define ABILITY_MANAGER_ADAPTER_H
18 
19 #include <chrono>
20 #include <condition_variable>
21 #include <mutex>
22 #include <string>
23 
24 namespace OHOS::AVSession {
25 enum class Status {
26     ABILITY_STATUS_INIT = 0,
27     ABILITY_STATUS_RUNNING = 1,
28     ABILITY_STATUS_FAILED = 2,
29     ABILITY_STATUS_SUCCESS = 3,
30 };
31 
32 class AbilityManagerAdapter {
33 public:
34     AbilityManagerAdapter(const std::string& bundleName, const std::string& abilityName);
35     ~AbilityManagerAdapter();
36 
37     int32_t StartAbilityByCall(std::string& sessionId);
38 
39     void StartAbilityByCallDone(const std::string& sessionId);
40 
41 private:
42     void WaitForTimeout(uint32_t timeout);
43 
44 private:
45     static constexpr int32_t ABILITY_START_TIMEOUT_MS = 5000;
46     static constexpr const char *defaultBundleName = "com.example.himusicdemo";
47     std::condition_variable syncCon_;
48     std::mutex syncMutex_;
49     Status status_ = Status::ABILITY_STATUS_INIT;
50     std::string bundleName_;
51     std::string abilityName_;
52     std::string sessionId_;
53 };
54 } // namespace OHOS::AVSession
55 #endif // ABILITY_MANAGER_ADAPTER_H