/* * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef OHOS_DISTRIBUTED_SCHED_CONTINUATION_H #define OHOS_DISTRIBUTED_SCHED_CONTINUATION_H #include #include #include #include "event_handler.h" #include "iremote_object.h" #include "refbase.h" #include "distributed_event_died_listener.h" #include "distributed_sched_types.h" namespace OHOS { namespace DistributedSchedule { using FuncContinuationCallback = std::function; class DSchedContinuation : public std::enable_shared_from_this { public: void Init(const FuncContinuationCallback& contCallback); bool PushAbilityToken(int32_t sessionId, const sptr& abilityToken); sptr PopAbilityToken(int32_t sessionId); int32_t GenerateSessionId(); bool IsInContinuationProgress(int32_t missionId); void SetTimeOut(int32_t missionId, int32_t timeout); void RemoveTimeOut(int32_t missionId); bool PushCallback(int32_t missionId, const sptr& callback, std::string deviceId, bool isFreeInstall); bool PushCallback(const sptr& callback); bool CleanupCallback(const sptr& callback); std::vector> GetCallback(); sptr PopCallback(int32_t missionId); int32_t NotifyMissionCenterResult(int32_t missionId, int32_t resultCode); int32_t NotifyDSchedEventResult(int32_t resultCode); bool IsFreeInstall(int32_t missionId); std::string GetTargetDevice(int32_t missionId); bool IsCleanMission(int32_t missionId); void SetCleanMissionFlag(int32_t missionId, bool isCleanMission); EventNotify continueEvent_; ContinueInfo continueInfo_; private: int32_t NotifyDSchedEventForOneCB(const sptr &cb, int32_t resultCode); private: class ContinuationHandler : public AppExecFwk::EventHandler { public: ContinuationHandler(const std::shared_ptr& runner, const std::shared_ptr& continuationObj, const FuncContinuationCallback& contCallback) : AppExecFwk::EventHandler(runner), continuationObj_(continuationObj), contCallback_(contCallback) {} ~ContinuationHandler() = default; void ProcessEvent(const OHOS::AppExecFwk::InnerEvent::Pointer& event) override; private: std::weak_ptr continuationObj_; FuncContinuationCallback contCallback_; }; std::shared_ptr continuationHandler_; std::mutex continuationLock_; int32_t currSessionId_ = 1; std::map> continuationMap_; std::vector> continuationCallbackArr_; sptr diedListener_; std::map> callbackMap_; std::map freeInstall_; std::map cleanMission_; std::map continuationDevices_; }; } // namespace DistributedSchedule } // namespace OHOS #endif // OHOS_DISTRIBUTED_SCHED_CONTINUATION_H