• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 "avsession_service.h"
17 
18 #include "migrate_avsession_manager.h"
19 
20 namespace OHOS::AVSession {
SuperLauncher(std::string deviceId,std::string serviceName,std::string extraInfo,const std::string & state)21 void AVSessionService::SuperLauncher(std::string deviceId, std::string serviceName,
22     std::string extraInfo, const std::string& state)
23 {
24     SLOGI("SuperLauncher serviceName: %{public}s, state: %{public}s",
25         serviceName.c_str(), state.c_str());
26 
27     if (state == "IDLE") {
28         MigrateAVSessionManager::GetInstance().ReleaseLocalSessionStub(serviceName);
29         if (migrateAVSession_ != nullptr) {
30             RemoveInnerSessionListener(migrateAVSession_.get());
31         }
32     } else if (state == "CONNECTING") {
33         if (migrateAVSession_ == nullptr) {
34             migrateAVSession_ = std::make_shared<MigrateAVSessionServer>();
35         }
36         migrateAVSession_->Init(this);
37         MigrateAVSessionManager::GetInstance().CreateLocalSessionStub(serviceName, migrateAVSession_);
38         AddInnerSessionListener(migrateAVSession_.get());
39     }
40 }
41 
AddInnerSessionListener(SessionListener * listener)42 void AVSessionService::AddInnerSessionListener(SessionListener *listener)
43 {
44     std::lock_guard lockGuard(sessionListenersLock_);
45     innerSessionListeners_.push_back(listener);
46 }
47 
RemoveInnerSessionListener(SessionListener * listener)48 void AVSessionService::RemoveInnerSessionListener(SessionListener *listener)
49 {
50     std::lock_guard lockGuard(sessionListenersLock_);
51     for (auto it = innerSessionListeners_.begin(); it != innerSessionListeners_.end();) {
52         if (*it == listener) {
53             SLOGI("RemoveInnerSessionListener");
54             innerSessionListeners_.erase(it++);
55         } else {
56             it++;
57         }
58     }
59 }
60 }