• 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 #include "mtp_monitor.h"
17 #include <thread>
18 #include "media_log.h"
19 using namespace std;
20 namespace OHOS {
21 namespace Media {
22 constexpr int32_t SLEEP_TIME = 10;
MtpMonitor(void)23 MtpMonitor::MtpMonitor(void)
24 {
25     Init();
26 }
27 
Init()28 void MtpMonitor::Init()
29 {
30     interruptFlag = false;
31 }
32 
Start()33 void MtpMonitor::Start()
34 {
35     std::thread(&MtpMonitor::Run, this).detach();
36 }
37 
Stop()38 void MtpMonitor::Stop()
39 {
40     interruptFlag = true;
41 }
42 
Run()43 void MtpMonitor::Run()
44 {
45     while (!interruptFlag) {
46         if (operationPtr_ == nullptr) {
47             operationPtr_ = make_shared<MtpOperation>();
48         }
49         operationPtr_->Execute();
50         std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME));
51     }
52 }
53 } // namespace Media
54 } // namespace OHOS
55