1 /* 2 * Copyright (c) 2024 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 USER_STATUS_LISTENER_H 17 #define USER_STATUS_LISTENER_H 18 19 #include <mutex> 20 #include <vector> 21 22 #include "common_event_subscriber.h" 23 #include "data_sync_manager.h" 24 #include "i_user_status_observer.h" 25 26 namespace OHOS::FileManagement::CloudSync { 27 class UserStatusListener : public std::enable_shared_from_this<UserStatusListener> { 28 public: 29 explicit UserStatusListener(std::shared_ptr<CloudFile::DataSyncManager> dataSyncManager); 30 ~UserStatusListener(); 31 void Start(); 32 void Stop(); 33 void AddObserver(std::shared_ptr<IUserStatusObserver> observer); 34 void NotifyUserUnlocked(); 35 void DoCleanVideoCache(); 36 37 private: 38 std::shared_ptr<EventFwk::CommonEventSubscriber> commonEventSubscriber_ = nullptr; 39 std::mutex obsVecMutex_; 40 std::vector<std::shared_ptr<IUserStatusObserver>> observers_; 41 std::shared_ptr<CloudFile::DataSyncManager> dataSyncManager_; 42 }; 43 44 class UserStatusSubscriber : public EventFwk::CommonEventSubscriber { 45 public: 46 UserStatusSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo, 47 std::shared_ptr<UserStatusListener> listener); ~UserStatusSubscriber()48 ~UserStatusSubscriber() override {} 49 void OnReceiveEvent(const EventFwk::CommonEventData &eventData) override; 50 51 private: 52 std::shared_ptr<UserStatusListener> listener_; 53 }; 54 } // namespace OHOS::FileManagement::CloudSync 55 #endif // USER_STATUS_LISTENER_H 56