/*
 * 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);
};
