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 DISTRIBUTEDDATAMGR_OBJECT_DMS_HANDLER_H 17 #define DISTRIBUTEDDATAMGR_OBJECT_DMS_HANDLER_H 18 19 #include <deque> 20 21 #include "dms_listener_stub.h" 22 #include "distributed_sched_types.h" 23 24 namespace OHOS::DistributedObject { 25 class DmsEventListener : public DistributedSchedule::DSchedEventListenerStub { 26 public: 27 DmsEventListener() = default; 28 ~DmsEventListener() = default; 29 void DSchedEventNotify(DistributedSchedule::EventNotify ¬ify); 30 }; 31 32 class ObjectDmsHandler { 33 public: GetInstance()34 static ObjectDmsHandler &GetInstance() 35 { 36 static ObjectDmsHandler instance; 37 return instance; 38 } 39 40 void ReceiveDmsEvent(DistributedSchedule::EventNotify &event); 41 bool IsContinue(const std::string &bundleName); 42 std::string GetDstBundleName(const std::string &srcBundleName, const std::string &dstNetworkId); 43 void RegisterDmsEvent(); 44 45 private: 46 ObjectDmsHandler() = default; 47 ~ObjectDmsHandler() = default; 48 ObjectDmsHandler(const ObjectDmsHandler &) = delete; 49 ObjectDmsHandler &operator=(const ObjectDmsHandler &) = delete; 50 ObjectDmsHandler(ObjectDmsHandler &&) = delete; 51 ObjectDmsHandler &operator=(ObjectDmsHandler &&) = delete; 52 53 static constexpr int64_t VALIDITY = 15; 54 static constexpr uint32_t MAX_EVENTS = 20; 55 std::deque<std::pair<DistributedSchedule::EventNotify, std::chrono::steady_clock::time_point>> dmsEvents_{}; 56 std::mutex mutex_{}; 57 sptr<DistributedSchedule::IDSchedEventListener> dmsEventListener_; 58 }; 59 } // namespace OHOS::DistributedObject 60 #endif // DISTRIBUTEDDATAMGR_OBJECT_DMS_HANDLER_H 61