/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * 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.
 */

#pragma once

#include <vector>

#include <android/hardware/automotive/vehicle/2.0/types.h>

namespace android::hardware::automotive::vehicle::V2_0 {

/**
 *  Server lives on the vehicle side to talk to Android HAL.
 *  Note that the server may not be run on Android
 */
class IVehicleServer {
  public:
    // The return structure for onDump function.
    struct DumpResult {
        // If callerShouldDumpState is true, caller would print the information in buffer and
        // continue to dump its state, otherwise would just dump the buffer and skip its own
        // dumping logic.
        bool callerShouldDumpState;
        // The dumped information for the caller to print.
        std::string buffer;
    };

    IVehicleServer() = default;

    IVehicleServer(const IVehicleServer&) = delete;

    IVehicleServer& operator=(const IVehicleServer&) = delete;

    IVehicleServer(IVehicleServer&&) = default;

    virtual ~IVehicleServer() = default;

    // Receive the get property configuration request from HAL.
    // Return a list of all property config
    virtual std::vector<VehiclePropConfig> onGetAllPropertyConfig() const = 0;

    // Receive the set property request from HAL.
    // Process the setting and return the status code
    // updateStatus indicate if VHal should change the status of the value
    // it should be false except injecting values for e2e tests
    virtual StatusCode onSetProperty(const VehiclePropValue& value, bool updateStatus) = 0;

    // Receive a new property value from car (via direct connection to the car bus or the emulator)
    // and forward the value to HAL
    // updateStatus is true if and only if the value is
    // generated by car (ECU/fake generator/injected)
    virtual void onPropertyValueFromCar(const VehiclePropValue& value, bool updateStatus) = 0;

    // Dump method forwarded from HIDL's debug()
    // If implemented, it must return whether the caller should dump its state.
    virtual DumpResult onDump(const std::vector<std::string>& options) = 0;
};

}  // namespace android::hardware::automotive::vehicle::V2_0
