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

#define LOG_TAG "aidl.android.hardware.bluetooth.ranging.service.default"

#include <android/binder_manager.h>
#include <android/binder_process.h>
#include <utils/Log.h>

#include "BluetoothChannelSounding.h"
#include "BluetoothChannelSoundingSession.h"

using ::aidl::android::hardware::bluetooth::ranging::impl::
    BluetoothChannelSounding;

int main(int /* argc */, char** /* argv */) {
  ALOGI("Bluetooth Ranging HAL registering");
  if (!ABinderProcess_setThreadPoolMaxThreadCount(0)) {
    ALOGE("Failed to set thread pool max thread count");
    return 1;
  }

  std::shared_ptr<BluetoothChannelSounding> service =
      ndk::SharedRefBase::make<BluetoothChannelSounding>();
  std::string instance =
      std::string() + BluetoothChannelSounding::descriptor + "/default";
  if (AServiceManager_isDeclared(instance.c_str())) {
    auto result =
        AServiceManager_addService(service->asBinder().get(), instance.c_str());
    if (result != STATUS_OK) {
      ALOGE("Could not register as a service!");
    }
  } else {
    ALOGE("Could not register as a service because it's not declared.");
  }
  // Keep running
  ABinderProcess_joinThreadPool();
  return 0;
}
