/*
 * Copyright (C) 2022 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 <memory>

#include "common/contextual_callback.h"
#include "hci/hci_packets.h"

namespace bluetooth {
namespace hci {

// The RemoteNameRequestModule handles Remote Name Requests, which produce both Remote Name Request
// Completed events, and Remote Host Supported Features Notification events.

using CompletionCallback = common::ContextualOnceCallback<void(ErrorCode)>;
using RemoteHostSupportedFeaturesCallback = common::ContextualOnceCallback<void(uint64_t)>;
using RemoteNameCallback =
        common::ContextualOnceCallback<void(ErrorCode, std::array<uint8_t, 248>)>;

// Historical note: This class is intended to provide a shim at the *HCI* layer, so legacy Remote
// Name Requests can interoperate with the GD ACL scheduler. Thus, we intentionally do not merge
// identical requests, cache responses, or handle request timeouts - we leave this to our callers.
// When GD clients start to use this module, richer functionality should be added.
class RemoteNameRequestModule {
public:
  virtual ~RemoteNameRequestModule() = default;

  // Dispatch a Remote Name Request
  virtual void StartRemoteNameRequest(
          Address address, std::unique_ptr<RemoteNameRequestBuilder> request,
          CompletionCallback on_completion,
          RemoteHostSupportedFeaturesCallback on_remote_host_supported_features_notification,
          RemoteNameCallback on_remote_name_complete) = 0;

  // Cancel a Remote Name Request
  virtual void CancelRemoteNameRequest(Address address) = 0;

  // Due to controller bugs (b/184239841), an ACL connection completion is sometimes reported in
  // place of an RNR completion This method lets the ACL manager inform the RNR module if this
  // happens, since we don't get the appropriate HCI event.
  virtual void ReportRemoteNameRequestCancellation(Address address) = 0;
};

}  // namespace hci
}  // namespace bluetooth
