• 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 #ifndef FRAMEWORKS_SERVICES_MEDIA_MTP_INCLUDE_MTP_FILE_OBSERVER_H_
16 #define FRAMEWORKS_SERVICES_MEDIA_MTP_INCLUDE_MTP_FILE_OBSERVER_H_
17 #include "mtp_event.h"
18 #include <map>
19 #include <memory>
20 #include <mutex>
21 #include <sys/inotify.h>
22 #include <thread>
23 #include <vector>
24 #include "singleton.h"
25 namespace OHOS {
26 namespace Media {
27 using ContextSptr = std::shared_ptr<MtpOperationContext>;
28 class MtpFileObserver : public Singleton<MtpFileObserver> {
29 public:
30     void AddFileInotify(const std::string &path, const std::string &realPath, const ContextSptr &context);
31     bool StartFileInotify();
32     bool StopFileInotify();
33 
34 private:
35     static bool AddInotifyEvents(const int &inotifyFd, const ContextSptr &context);
36     static bool WatchPathThread(const ContextSptr &context);
37     static void SendBattery(const ContextSptr &context);
38     static void SendEvent(const inotify_event &event, const std::string &path, const ContextSptr &context);
39     static bool isRunning_;
40     static std::map<int, std::string> watchMap_;
41     static int inotifyFd_;
42     static std::mutex eventLock_;
43     bool startThread_;
44     bool inotifySuccess_;
45 };
46 } // namespace Media
47 } // namespace OHOS
48 #endif // FRAMEWORKS_SERVICES_MEDIA_MTP_INCLUDE_MTP_FILE_OBSERVER_H_
49