/*
 * Copyright (C) 2019 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.
 */

package android.hardware.tv.tuner@1.0;

import IFrontendCallback;
import ILnb;

/**
 * A Tuner Frontend is used to tune to a frequency and lock signal.
 *
 * IFrontend provides a bit stream to the Tuner Demux interface.
 */
interface IFrontend {
    /**
     * Set the frontend callback.
     *
     * IFrontendCallback is used by the client to receive events from the Frontend.
     * Only one callback per IFrontend instance is supported. The callback
     * will be replaced if it's set again.
     *
     * @param callback Callback object to pass Frontend events to the system.
     *        The previously registered callback must be replaced with this one.
     *        It can be null.
     * @return result Result status of the operation.
     *         SUCCESS if successful,
     *         INVALID_STATE if callback can't be set at current stage,
     *         UNKNOWN_ERROR if callback setting failed for other reasons.
     */
    setCallback(IFrontendCallback callback) generates (Result result);

    /**
     * Tunes the frontend to using the settings given.
     *
     * This locks the frontend to a frequency by providing signal
     * delivery information. If previous tuning isn't completed, this call MUST
     * stop previous tuning, and start a new tuning.
     * Tune is an async call, with LOCKED or NO_SIGNAL events sent via callback.
     *
     * @param settings Signal delivery information the frontend uses to
     * search and lock the signal.
     *
     * @return result Result status of the operation.
     *         SUCCESS if successful,
     *         INVALID_STATE if tuning can't be applied at current stage,
     *         UNKNOWN_ERROR if tuning failed for other reasons.
     */
    tune(FrontendSettings settings) generates (Result result);

    /**
     * Stops a previous tuning.
     *
     * If the method completes successfully the frontend is no longer tuned and no data
     * will be sent to attached demuxes.
     *
     * @return result Result status of the operation.
     *         SUCCESS if successfully stop tuning.
     *         UNKNOWN_ERROR if failed for other reasons.
     */
    stopTune() generates (Result result);

    /**
     * Releases the Frontend instance
     *
     * Associated resources are released.  close may be called more than once.
     * Calls to any other method after this will return an error
     *
     * @return result Result status of the operation.
     *         SUCCESS if successful,
     *         UNKNOWN_ERROR if failed for other reasons.
     */
    close() generates (Result result);

    /**
     * Scan the frontend to use the settings given.
     *
     * This uses the frontend to start a scan from signal delivery information.
     * If previous scan isn't completed, this call MUST stop previous scan,
     * and start a new scan.
     * Scan is an async call, with FrontendScanMessage sent via callback.
     *
     * @param settings Signal delivery information which the frontend uses to
     * scan the signal.
     * @param type the type which the frontend uses to scan the signal.
     *
     * @return result Result status of the operation.
     *         SUCCESS if successful,
     *         INVALID_STATE if tuning can't be applied at current stage,
     *         UNKNOWN_ERROR if tuning failed for other reasons.
     */
    scan(FrontendSettings settings, FrontendScanType type) generates (Result result);

    /**
     * Stops a previous scanning.
     *
     * If the method completes successfully, the frontend stop previous
     * scanning.
     *
     * @return result Result status of the operation.
     *         SUCCESS if successfully stop tuning.
     *         UNKNOWN_ERROR if failed for other reasons.
     */
    stopScan() generates (Result result);

    /**
     * Gets the statuses of the frontend.
     *
     * This retrieve the statuses of the frontend for given status types.
     *
     * @param statusTypes an array of status type which the caller request.
     *
     * @return result Result status of the operation.
     *         SUCCESS if successful,
     *         INVALID_STATE if tuning can't be applied at current stage,
     *         UNKNOWN_ERROR if tuning failed for other reasons.
     * @return statuses an array of statuses which response the caller's
     *         request.
     */
    getStatus(vec<FrontendStatusType> statusTypes)
        generates (Result result, vec<FrontendStatus> statuses);

    /**
     * Sets Low-Noise Block downconverter (LNB) for satellite frontend.
     *
     * This assigns a hardware LNB resource to the satellite frontend. It can be
     * called multiple times to update LNB assignment. The LNB resource must be
     * released when the frontend is closed.
     *
     * @param lnbId the Id of assigned LNB resource.
     *
     * @return result Result status of the operation.
     *         SUCCESS if successful,
     *         INVALID_STATE if the frontend can't be set with a LNB, such as
     *         cable frontend.
     *         UNKNOWN_ERROR if failed for other reasons.
     */
    setLnb(LnbId lnbId) generates (Result result);

    /**
     * Enable or Disable Low Noise Amplifier (LNA).
     *
     * @param bEnable true if activate LNA module; false if deactivate LNA
     *
     * @return result Result status of the operation.
     *         SUCCESS if successful,
     *         INVALID_STATE if the frontend doesn't support LNA.
     *         UNKNOWN_ERROR if failed for other reasons.
     */
    setLna(bool bEnable) generates (Result result);
};