# Copyright (c) 2025 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("./../../../multimedia_camera_framework.gni")

idl_gen_interface("camera_service_idl_interface") {
  sources = [
    "ICameraDeviceService.idl",
    "ICaptureSession.idl",
    "IStreamCommon.idl",
    "ICameraService.idl",
    "IStreamCapture.idl",
    "IStreamDepthData.idl",
    "IStreamMetadata.idl",
    "IStreamRepeat.idl",
    "ICameraRecorder.idl",
    "IMechSession.idl",
    "IMovieFileOutput.idl",
    "ICameraMultiStreamOutput.idl",
    "ICameraSwitchSession.idl",
  ]
  sources_callback = [
    "ICameraDeviceServiceCallback.idl",
    "ICaptureSessionCallback.idl",
    "ICameraServiceCallback.idl",
    "IStreamCaptureCallback.idl",
    "IStreamDepthDataCallback.idl",
    "IStreamMetadataCallback.idl",
    "IStreamRepeatCallback.idl",
    "ITorchServiceCallback.idl",
    "IFoldServiceCallback.idl",
    "ICameraMuteServiceCallback.idl",
    "IControlCenterStatusCallback.idl",
    "IControlCenterEffectStatusCallback.idl",
    "IPressureStatusCallback.idl",
    "IStreamCapturePhotoAssetCallback.idl",
    "ICameraRecorderCallback.idl",
    "IMechSessionCallback.idl",
    "IMovieFileOutputCallback.idl",
    "ICameraSwitchSessionCallback.idl",
    "ICameraSharedServiceCallback.idl",
    "ICameraSpectrumInfoCallback.idl",
  ]

  sources_common = [ "CameraTypes.idl" ]

  inputs = sources_common + sources_callback

  hitrace = "HITRACE_TAG_ABILITY_MANAGER"

  subsystem_name = "multimedia"
  part_name = "camera_framework"
}

config("camera_sa_idl_config") {
  include_dirs = [
    "./",
    "${target_gen_dir}",
    "${multimedia_camera_framework_path}/common/utils",
    "${multimedia_camera_framework_path}/interfaces/inner_api/native/camera/include",
    "${multimedia_camera_framework_path}/services/camera_service/binder/base/include",
    "${multimedia_camera_framework_path}/interfaces/inner_api/native/camera/include/utils",
  ]
}

ohos_source_set("camera_idl_sa_proxy") {
  output_values = get_target_outputs(":camera_service_idl_interface")
  sources = filter_include(output_values,
                           [
                             "*_service_proxy.cpp",
                             "*_session_proxy.cpp",
                             "*_capture_proxy.cpp",
                             "*_depth_data_proxy.cpp",
                             "*_metadata_proxy.cpp",
                             "*_repeat_proxy.cpp",
                             "*_callback_stub.cpp",
                             "*_types.cpp",
                             "*_recorder_proxy.cpp",
                             "*movie_file_output_proxy.cpp",
                           ])

  public_configs = [
    ":camera_sa_idl_config",
    "${multimedia_camera_framework_path}/services/deferred_processing_service/idls:deferred_processing_service_idl_config"
  ]

  deps = [ ":camera_service_idl_interface" ]

  cflags = [
    "-Wall",
    "-fPIC",
    "-fdata-sections",
    "-ffunction-sections",
    "-fno-asynchronous-unwind-tables",
    "-fno-unwind-tables",
    "-Os",
  ]
  if (target_cpu == "arm") {
    cflags += [ "-DBINDER_IPC_32BIT" ]
  }

  sanitize = {
    integer_overflow = true
    ubsan = true
    boundary_sanitize = true
    cfi = true
    cfi_cross_dso = true
    cfi_vcall_icall_only = true
    debug = false
  }

  external_deps = [
    "c_utils:utils",
    "hitrace:hitrace_meter",
    "ipc:ipc_single",
    "drivers_interface_camera:metadata",
    "graphic_surface:surface",
    "ipc:ipc_core",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
    "window_manager:libdm",
    "window_manager:libwm",
  ]

  part_name = "camera_framework"
  subsystem_name = "multimedia"
}

ohos_source_set("camera_idl_sa_stub") {
  output_values = get_target_outputs(":camera_service_idl_interface")
  sources = filter_include(output_values,
                           [
                             "*_service_stub.cpp",
                             "*_session_stub.cpp",
                             "*_capture_stub.cpp",
                             "*_depth_data_stub.cpp",
                             "*_metadata_stub.cpp",
                             "*_repeat_stub.cpp",
                             "*_callback_proxy.cpp",
                             "*_types.cpp",
                             "*_recorder_stub.cpp",
                             "*movie_file_output_stub.cpp"
                           ])

  public_configs = [ ":camera_sa_idl_config",
                     "${multimedia_camera_framework_path}/services/deferred_processing_service/idls:deferred_processing_service_idl_config",
                   ]

  deps = [ ":camera_service_idl_interface" ]

  cflags = [
    "-Wall",
    "-fPIC",
    "-fdata-sections",
    "-ffunction-sections",
    "-fno-asynchronous-unwind-tables",
    "-fno-unwind-tables",
    "-Os",
  ]
  if (target_cpu == "arm") {
    cflags += [ "-DBINDER_IPC_32BIT" ]
  }

  sanitize = {
    integer_overflow = true
    ubsan = true
    boundary_sanitize = true
    cfi = true
    cfi_cross_dso = true
    cfi_vcall_icall_only = true
    debug = false
  }

  external_deps = [
    "c_utils:utils",
    "hitrace:hitrace_meter",
    "ipc:ipc_single",
    "drivers_interface_camera:metadata",
    "graphic_surface:surface",
    "ipc:ipc_core",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
    "window_manager:libdm",
    "window_manager:libwm",
  ]

  part_name = "camera_framework"
  subsystem_name = "multimedia"
}