1 /* 2 * Copyright (c) 2020 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 OHOS_ABILITY_SCHEDULER_H 17 #define OHOS_ABILITY_SCHEDULER_H 18 19 #include <app_info.h> 20 21 #include "ability_event_handler.h" 22 #include "nocopyable.h" 23 #include "liteipc_adapter.h" 24 #include "serializer.h" 25 #include "want.h" 26 27 namespace OHOS { 28 const int32_t DEFAULT_IPC_SIZE = 200; 29 class Scheduler { 30 public: 31 virtual ~Scheduler() = default; 32 33 /* perform application start and stop */ 34 virtual void PerformAppInit(const AppInfo& appInfo) = 0; 35 virtual void PerformAppExit() = 0; 36 37 /* perform transact ability lifecycle state */ 38 virtual void PerformTransactAbilityState(const Want &want, int state, uint64_t token, int abilityType) = 0; 39 /* perform connect ability */ 40 virtual void PerformConnectAbility(const Want &want, uint64_t token) = 0; 41 virtual void PerformDisconnectAbility(const Want &want, uint64_t token) = 0; 42 /* perform dump ability info */ 43 virtual void PerformDumpAbility(const Want &want, uint64_t token) = 0; 44 }; 45 46 class AbilityScheduler : public NoCopyable { 47 public: 48 AbilityScheduler() = delete; 49 AbilityScheduler(AbilityEventHandler &eventHandler, Scheduler &scheduler); 50 ~AbilityScheduler() override = default; 51 52 static int32_t AmsCallback(const IpcContext* context, void *ipcMsg, IpcIo *data, void *arg); 53 54 private: 55 void PerformAppInit(const AppInfo& appInfo); 56 void PerformTransactAbilityState(const Want &want, int state, uint64_t token, int abilityType); 57 void PerformConnectAbility(const Want &want, uint64_t token); 58 void PerformDisconnectAbility(const Want &want, uint64_t token); 59 void PerformAppExit(); 60 void PerformDumpAbility(const Want &want, uint64_t token); 61 static void ClearIpcMsg(void *ipcMsg); 62 63 AbilityEventHandler &eventHandler_; 64 Scheduler &scheduler_; 65 }; 66 } // namespace OHOS 67 #endif // OHOS_ABILITY_SCHEDULER_H 68