1 /*
2 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
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 "monitor_server_object.h"
17 #include "media_log.h"
18 #include "media_errors.h"
19 #include "monitor_server.h"
20 namespace {
21 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_PLAYER, "MonitorServerObject"};
22 }
23
24 namespace OHOS {
25 namespace Media {
RegisterMonitor(int32_t pid)26 int32_t MonitorServerObject::RegisterMonitor(int32_t pid)
27 {
28 MEDIA_LOGI("0x%{public}06" PRIXPTR " Pid %{public}d RegisterMonitor", FAKE_POINTER(this), pid);
29 return MonitorServer::GetInstance().RegisterObj(pid, wptr(this));
30 }
31
CancellationMonitor(int32_t pid)32 int32_t MonitorServerObject::CancellationMonitor(int32_t pid)
33 {
34 MEDIA_LOGI("0x%{public}06" PRIXPTR " Pid %{public}d CancellationMonitor", FAKE_POINTER(this), pid);
35 return MonitorServer::GetInstance().CancellationObj(pid, wptr(this));
36 }
37
IpcAbnormality()38 int32_t MonitorServerObject::IpcAbnormality()
39 {
40 std::lock_guard<std::mutex> lock(monitorMutex_);
41 if (alarmed_) {
42 return MSERR_OK;
43 }
44
45 MEDIA_LOGE("IpcAbnormality");
46 return DoIpcAbnormality();
47 }
48
IpcRecovery(bool fromMonitor)49 int32_t MonitorServerObject::IpcRecovery(bool fromMonitor)
50 {
51 std::lock_guard<std::mutex> lock(monitorMutex_);
52 if (!alarmed_) {
53 return MSERR_OK;
54 }
55
56 MEDIA_LOGE("IpcRecovery %{public}d ", fromMonitor);
57 return DoIpcRecovery(fromMonitor);
58 }
59
SetIpcAlarmedFlag()60 void MonitorServerObject::SetIpcAlarmedFlag()
61 {
62 alarmed_ = true;
63 }
64
UnSetIpcAlarmedFlag()65 void MonitorServerObject::UnSetIpcAlarmedFlag()
66 {
67 alarmed_ = false;
68 }
69 } // namespace Media
70 } // namespace OHOS
71