/*
 * Copyright (c) 2020 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_ABILITY_SCHEDULER_H
#define OHOS_ABILITY_SCHEDULER_H

#include <app_info.h>

#include "ability_event_handler.h"
#include "nocopyable.h"
#include "ipc_skeleton.h"
#include "want.h"

namespace OHOS {
const int32_t DEFAULT_IPC_SIZE = 200;
class Scheduler {
public:
    virtual ~Scheduler() = default;

    /* perform application start and stop */
    virtual void PerformAppInit(const AppInfo& appInfo) = 0;
    virtual void PerformAppExit() = 0;

    /* perform transact ability lifecycle state */
    virtual void PerformTransactAbilityState(const Want &want, int state, uint64_t token, int abilityType) = 0;
    /* perform connect ability */
    virtual void PerformConnectAbility(const Want &want, uint64_t token) = 0;
    virtual void PerformDisconnectAbility(const Want &want, uint64_t token) = 0;
    /* perform dump ability info */
    virtual void PerformDumpAbility(const Want &want, uint64_t token) = 0;
};

class AbilityScheduler : public NoCopyable {
public:
    AbilityScheduler() = delete;
    AbilityScheduler(AbilityEventHandler &eventHandler, Scheduler &scheduler);
    ~AbilityScheduler() override = default;

    static int32_t AmsCallback(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option);

private:
    void PerformAppInit(const AppInfo& appInfo);
    void PerformTransactAbilityState(const Want &want, int state, uint64_t token, int abilityType);
    void PerformConnectAbility(const Want &want, uint64_t token);
    void PerformDisconnectAbility(const Want &want, uint64_t token);
    void PerformAppExit();
    void PerformDumpAbility(const Want &want, uint64_t token);

    AbilityEventHandler &eventHandler_;
    Scheduler &scheduler_;
};
} // namespace OHOS
#endif // OHOS_ABILITY_SCHEDULER_H