# Copyright (c) 2023-2026 Huawei Device Co., Ltd.
# 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.

import("//build/config/components/idl_tool/idl.gni")
import("//build/ohos.gni")
import("../../extdevmgr.gni")

idl_gen_interface("external_device_manager_interface") {
  sources = [ "IDriverExtMgr.idl" ]
  sources_callback = [ "IDriverExtMgrCallback.idl" ]
  log_domainid = "0xD002551"
  log_tag = "EdmService"
  subsystem_name = "hdf"
  part_name = "external_device_manager"
}

config("ext_dvc_mgr_public_config") {
  include_dirs = [
    "./",
    "${target_gen_dir}",
    "${utils_path}/include",
  ]
}

ohos_shared_library("driver_ext_mgr_client") {
  branch_protector_ret = "pac_ret"
  sanitize = {
    cfi = true
    cfi_cross_dso = true
    debug = false
  }
  defines = external_device_defines
  output_values = get_target_outputs(":external_device_manager_interface")
  sources = [
    "${ext_mgr_path}/frameworks/native/driver_ext_mgr_client.cpp",
    "${ext_mgr_path}/services/native/driver_extension_manager/src/driver_ext_mgr_types.cpp",
  ]
  sources += filter_include(output_values, [ "*mgr_proxy.cpp" ])
  sources += filter_include(output_values, [ "*callback_stub.cpp" ])
  public_configs = [ ":ext_dvc_mgr_public_config" ]

  deps = [ ":external_device_manager_interface" ]
  external_deps = [
    "c_utils:utils",
    "hilog:libhilog",
    "ipc:ipc_core",
    "samgr:samgr_proxy",
  ]
  version_script = "driver_ext_mgr_client.map"
  subsystem_name = "hdf"
  part_name = "external_device_manager"
}

ohos_source_set("external_device_manager_stub") {
  branch_protector_ret = "pac_ret"
  sanitize = {
    cfi = true
    cfi_cross_dso = true
    debug = false
  }
  public_configs = [ ":ext_dvc_mgr_public_config" ]
  output_values = get_target_outputs(":external_device_manager_interface")
  sources = filter_include(output_values, [ "*mgr_stub.cpp" ])
  sources += filter_include(output_values, [ "*callback_proxy.cpp" ])
  deps = [ ":external_device_manager_interface" ]

  external_deps = [
    "c_utils:utils",
    "hilog:libhilog",
    "ipc:ipc_core",
    "samgr:samgr_proxy",
  ]
  subsystem_name = "hdf"
  part_name = "external_device_manager"
}