[libcamera-devel,00/16] libcamera-base: A new split on libcamera
mbox series

Message ID 20210625013539.625803-1-kieran.bingham@ideasonboard.com
Headers show
Series
  • libcamera-base: A new split on libcamera
Related show

Message

Kieran Bingham June 25, 2021, 1:35 a.m. UTC
Hi all,

Another lengthy revision of my libcamera refactoring series which is ...
qiute intensive.

For hopefully obvious reasons, I would /really/ like anything
non-critical in this series to be fixed up on top. The churn here is
horrible, and fixing up through the series is incredibly painful.

Please note, there are changes to the split of the Android library since
the previous reviewers, and of course you'll see quite a lot of change
on the main refactoring too - though the concepts are the same.

Now incorporates a 'private.h' to protect headers.

One really big thing to watch out for (particularly David/RPi) is that
"libcamera: Rename libcamera pkg-config generation" changes how you find
libcamera as a dependency to externally built applications.

So ... I'm going to post this and run ... good luck to whomever casts
their eyes over it.


Kieran Bingham (16):
  android: Split HAL to its own shared library
  android: cros: Simplify integration
  libcamera: Move libcamera.so pkg-config file generation
  libcamera: Rename libcamera pkg-config generation
  libcamera: Separate source and build path helpers
  libcamera/base: Introduce new base library
  libcamera/base: Move utils to the base library
  libcamera/base: Move class helpers to the base library
  libcamera/base: Move extended base functionality
  libcamera/base: Move File to base library
  libcamera/base: Move event_notifier to base
  libcamera/base: Validate internal headers as private
  libcamera/base: Move span to base library
  libcamera: Move generated headers to private dep
  libcamera: rename public libcamera dependency
  test: Ensure LIBCAMERA_BASE_PRIVATE isn't public

 Documentation/Doxyfile.in                     |   2 +-
 Documentation/guides/pipeline-handler.rst     |   3 +-
 Documentation/meson.build                     |   2 +
 include/libcamera/{ => base}/bound_method.h   |   6 +-
 include/libcamera/{ => base}/class.h          |   0
 .../{internal => base}/event_dispatcher.h     |   8 +-
 .../event_dispatcher_poll.h                   |  10 +-
 .../{internal => base}/event_notifier.h       |   5 +-
 include/libcamera/{internal => base}/file.h   |  11 +-
 include/libcamera/{internal => base}/log.h    |  12 +-
 include/libcamera/base/meson.build            |  25 ++++
 .../libcamera/{internal => base}/message.h    |   8 +-
 include/libcamera/{ => base}/object.h         |   8 +-
 include/libcamera/base/private.h              |  22 +++
 .../libcamera/{internal => base}/semaphore.h  |   9 +-
 include/libcamera/{ => base}/signal.h         |  10 +-
 include/libcamera/{ => base}/span.h           |   0
 include/libcamera/{internal => base}/thread.h |  14 +-
 include/libcamera/{internal => base}/timer.h  |  11 +-
 include/libcamera/{internal => base}/utils.h  |  10 +-
 include/libcamera/buffer.h                    |   3 +-
 include/libcamera/camera.h                    |   7 +-
 include/libcamera/camera_manager.h            |   6 +-
 include/libcamera/controls.h                  |   5 +-
 include/libcamera/framebuffer_allocator.h     |   2 +-
 include/libcamera/internal/buffer.h           |   5 +-
 .../libcamera/internal/byte_stream_buffer.h   |   4 +-
 include/libcamera/internal/camera_sensor.h    |   5 +-
 .../libcamera/internal/device_enumerator.h    |   2 +-
 .../libcamera/internal/ipa_data_serializer.h  |   3 +-
 include/libcamera/internal/ipa_manager.h      |   3 +-
 include/libcamera/internal/ipa_module.h       |   3 +-
 include/libcamera/internal/ipc_pipe.h         |   4 +-
 include/libcamera/internal/ipc_unixsocket.h   |   2 +-
 include/libcamera/internal/media_device.h     |   4 +-
 include/libcamera/internal/media_object.h     |   2 +-
 include/libcamera/internal/meson.build        |  11 +-
 include/libcamera/internal/pipeline_handler.h |   5 +-
 include/libcamera/internal/process.h          |   2 +-
 include/libcamera/internal/pub_key.h          |   2 +-
 include/libcamera/internal/source-paths.h     |  19 +++
 include/libcamera/internal/v4l2_device.h      |   8 +-
 include/libcamera/internal/v4l2_subdevice.h   |   5 +-
 include/libcamera/internal/v4l2_videodevice.h |   7 +-
 include/libcamera/ipa/ipa_interface.h         |   3 +-
 include/libcamera/meson.build                 |   6 +-
 include/libcamera/request.h                   |   5 +-
 meson.build                                   |   8 --
 src/android/camera3_hal.cpp                   |   2 +-
 src/android/camera_buffer.h                   |   4 +-
 src/android/camera_capabilities.cpp           |   3 +-
 src/android/camera_capabilities.h             |   3 +-
 src/android/camera_device.cpp                 |   8 +-
 src/android/camera_device.h                   |   7 +-
 src/android/camera_hal_config.cpp             |   2 +-
 src/android/camera_hal_config.h               |   2 +-
 src/android/camera_hal_manager.cpp            |   4 +-
 src/android/camera_metadata.cpp               |   2 +-
 src/android/camera_worker.h                   |   6 +-
 src/android/cros/meson.build                  |  11 +-
 src/android/jpeg/encoder.h                    |   3 +-
 src/android/jpeg/encoder_libjpeg.cpp          |   3 +-
 src/android/jpeg/exif.cpp                     |   4 +-
 src/android/jpeg/exif.h                       |   3 +-
 src/android/jpeg/post_processor_jpeg.cpp      |   4 +-
 src/android/jpeg/thumbnailer.cpp              |   4 +-
 src/android/meson.build                       |  19 ++-
 src/android/mm/cros_camera_buffer.cpp         |   2 +-
 src/android/mm/generic_camera_buffer.cpp      |   3 +-
 src/android/yuv/post_processor_yuv.cpp        |   3 +-
 src/cam/meson.build                           |   2 +-
 src/gstreamer/meson.build                     |   2 +-
 src/ipa/ipu3/ipu3.cpp                         |   3 +-
 src/ipa/ipu3/ipu3_agc.cpp                     |   4 +-
 src/ipa/ipu3/ipu3_agc.h                       |   4 +-
 src/ipa/ipu3/ipu3_awb.cpp                     |   2 +-
 src/ipa/ipu3/meson.build                      |   2 +-
 src/ipa/libipa/histogram.cpp                  |   2 +-
 src/ipa/libipa/histogram.h                    |   2 +-
 src/ipa/libipa/meson.build                    |   2 +-
 src/ipa/raspberrypi/cam_helper.hpp            |   4 +-
 .../raspberrypi/controller/agc_algorithm.hpp  |   3 +-
 src/ipa/raspberrypi/controller/agc_status.h   |   2 +-
 src/ipa/raspberrypi/controller/camera_mode.h  |   2 +-
 src/ipa/raspberrypi/controller/controller.cpp |   2 +-
 .../raspberrypi/controller/device_status.h    |   2 +-
 src/ipa/raspberrypi/controller/rpi/agc.cpp    |   2 +-
 src/ipa/raspberrypi/controller/rpi/agc.hpp    |   2 +-
 src/ipa/raspberrypi/controller/rpi/alsc.cpp   |   2 +-
 src/ipa/raspberrypi/controller/rpi/awb.cpp    |   2 +-
 .../controller/rpi/black_level.cpp            |   2 +-
 src/ipa/raspberrypi/controller/rpi/ccm.cpp    |   2 +-
 .../raspberrypi/controller/rpi/contrast.cpp   |   2 +-
 src/ipa/raspberrypi/controller/rpi/dpc.cpp    |   2 +-
 src/ipa/raspberrypi/controller/rpi/focus.cpp  |   2 +-
 src/ipa/raspberrypi/controller/rpi/geq.cpp    |   2 +-
 src/ipa/raspberrypi/controller/rpi/lux.cpp    |   2 +-
 src/ipa/raspberrypi/controller/rpi/lux.hpp    |   2 +-
 src/ipa/raspberrypi/controller/rpi/noise.cpp  |   2 +-
 src/ipa/raspberrypi/controller/rpi/sdn.cpp    |   2 +-
 .../raspberrypi/controller/rpi/sharpen.cpp    |   2 +-
 src/ipa/raspberrypi/md_parser.hpp             |   2 +-
 src/ipa/raspberrypi/meson.build               |   2 +-
 src/ipa/raspberrypi/raspberrypi.cpp           |   9 +-
 src/ipa/rkisp1/meson.build                    |   2 +-
 src/ipa/rkisp1/rkisp1.cpp                     |   4 +-
 src/ipa/vimc/meson.build                      |   2 +-
 src/ipa/vimc/vimc.cpp                         |  10 +-
 src/lc-compliance/meson.build                 |   2 +-
 src/libcamera/{ => base}/bound_method.cpp     |  11 +-
 src/libcamera/{ => base}/class.cpp            |   2 +-
 src/libcamera/{ => base}/event_dispatcher.cpp |   7 +-
 .../{ => base}/event_dispatcher_poll.cpp      |  14 +-
 src/libcamera/{ => base}/event_notifier.cpp   |  10 +-
 src/libcamera/{ => base}/file.cpp             |   6 +-
 src/libcamera/{ => base}/log.cpp              |   8 +-
 src/libcamera/base/meson.build                |  49 +++++++
 src/libcamera/{ => base}/message.cpp          |   9 +-
 src/libcamera/{ => base}/object.cpp           |  17 ++-
 src/libcamera/{ => base}/semaphore.cpp        |   6 +-
 src/libcamera/{ => base}/signal.cpp           |   6 +-
 src/libcamera/{ => base}/thread.cpp           |  12 +-
 src/libcamera/{ => base}/timer.cpp            |  16 +--
 src/libcamera/{ => base}/utils.cpp            | 110 +--------------
 src/libcamera/buffer.cpp                      |   2 +-
 src/libcamera/byte_stream_buffer.cpp          |   2 +-
 src/libcamera/camera.cpp                      |   5 +-
 src/libcamera/camera_manager.cpp              |   8 +-
 src/libcamera/camera_sensor.cpp               |   3 +-
 src/libcamera/camera_sensor_properties.cpp    |   4 +-
 src/libcamera/control_serializer.cpp          |   5 +-
 src/libcamera/controls.cpp                    |   5 +-
 src/libcamera/delayed_controls.cpp            |   3 +-
 src/libcamera/device_enumerator.cpp           |   3 +-
 src/libcamera/device_enumerator_sysfs.cpp     |   3 +-
 src/libcamera/device_enumerator_udev.cpp      |   5 +-
 src/libcamera/file_descriptor.cpp             |   2 +-
 src/libcamera/formats.cpp                     |   2 +-
 src/libcamera/framebuffer_allocator.cpp       |   3 +-
 src/libcamera/geometry.cpp                    |   2 +-
 src/libcamera/ipa_data_serializer.cpp         |   2 +-
 src/libcamera/ipa_manager.cpp                 |   7 +-
 src/libcamera/ipa_module.cpp                  |   8 +-
 src/libcamera/ipa_proxy.cpp                   |   5 +-
 src/libcamera/ipc_pipe.cpp                    |   2 +-
 src/libcamera/ipc_pipe_unixsocket.cpp         |   9 +-
 src/libcamera/ipc_unixsocket.cpp              |   4 +-
 src/libcamera/media_device.cpp                |   2 +-
 src/libcamera/media_object.cpp                |   3 +-
 src/libcamera/meson.build                     |  70 ++++------
 src/libcamera/pipeline/ipu3/cio2.h            |   2 +-
 src/libcamera/pipeline/ipu3/frames.h          |   2 +-
 src/libcamera/pipeline/ipu3/imgu.cpp          |   5 +-
 src/libcamera/pipeline/ipu3/ipu3.cpp          |   5 +-
 .../pipeline/raspberrypi/dma_heaps.cpp        |   2 +-
 .../pipeline/raspberrypi/raspberrypi.cpp      |   3 +-
 .../pipeline/raspberrypi/rpi_stream.cpp       |   4 +-
 src/libcamera/pipeline/rkisp1/rkisp1.cpp      |   5 +-
 src/libcamera/pipeline/rkisp1/rkisp1_path.h   |   5 +-
 src/libcamera/pipeline/simple/converter.cpp   |   7 +-
 src/libcamera/pipeline/simple/converter.h     |   4 +-
 src/libcamera/pipeline/simple/simple.cpp      |   3 +-
 src/libcamera/pipeline/uvcvideo/uvcvideo.cpp  |   5 +-
 src/libcamera/pipeline/vimc/vimc.cpp          |   7 +-
 src/libcamera/pipeline_handler.cpp            |   5 +-
 src/libcamera/process.cpp                     |   6 +-
 src/libcamera/proxy/worker/meson.build        |   2 +-
 src/libcamera/request.cpp                     |   3 +-
 src/libcamera/source-paths.cpp                | 129 ++++++++++++++++++
 src/libcamera/stream.cpp                      |   5 +-
 src/libcamera/sysfs.cpp                       |   4 +-
 src/libcamera/v4l2_device.cpp                 |   7 +-
 src/libcamera/v4l2_pixelformat.cpp            |   3 +-
 src/libcamera/v4l2_subdevice.cpp              |   5 +-
 src/libcamera/v4l2_videodevice.cpp            |   5 +-
 src/meson.build                               |   8 +-
 src/qcam/meson.build                          |   2 +-
 src/v4l2/meson.build                          |   2 +-
 src/v4l2/v4l2_camera.cpp                      |   2 +-
 src/v4l2/v4l2_camera.h                        |   4 +-
 src/v4l2/v4l2_camera_proxy.cpp                |   7 +-
 src/v4l2/v4l2_compat_manager.cpp              |   6 +-
 test/camera-sensor.cpp                        |   3 +-
 test/camera/buffer_import.cpp                 |   7 +-
 test/camera/capture.cpp                       |   6 +-
 test/camera/meson.build                       |   2 +-
 test/controls/meson.build                     |   2 +-
 test/event-dispatcher.cpp                     |   6 +-
 test/event-thread.cpp                         |   6 +-
 test/event.cpp                                |   8 +-
 test/file-descriptor.cpp                      |   2 +-
 test/file.cpp                                 |   2 +-
 test/hotplug-cameras.cpp                      |   8 +-
 test/ipa/ipa_interface_test.cpp               |   9 +-
 test/ipa/meson.build                          |   2 +-
 test/ipc/meson.build                          |   2 +-
 test/ipc/unixsocket.cpp                       |   7 +-
 test/ipc/unixsocket_ipc.cpp                   |  10 +-
 test/libtest/meson.build                      |   2 +-
 test/log/log_api.cpp                          |   4 +-
 test/log/log_process.cpp                      |  11 +-
 test/log/meson.build                          |   2 +-
 test/media_device/meson.build                 |   4 +-
 test/meson.build                              |   5 +-
 test/message.cpp                              |   4 +-
 test/object-delete.cpp                        |   5 +-
 test/object-invoke.cpp                        |   7 +-
 test/object.cpp                               |   7 +-
 test/pipeline/ipu3/meson.build                |   2 +-
 test/pipeline/rkisp1/meson.build              |   2 +-
 test/pixel-format.cpp                         |   2 +-
 test/process/meson.build                      |   2 +-
 test/process/process_test.cpp                 |  10 +-
 test/public-api.cpp                           |  25 ++++
 .../generated_serializer/meson.build          |   2 +-
 .../ipa_data_serializer_test.cpp              |   5 +-
 test/serialization/meson.build                |   2 +-
 test/signal-threads.cpp                       |   6 +-
 test/signal.cpp                               |   4 +-
 test/span.cpp                                 |   2 +-
 test/stream/meson.build                       |   2 +-
 test/threads.cpp                              |   2 +-
 test/timer-thread.cpp                         |   6 +-
 test/timer.cpp                                |   6 +-
 test/utils.cpp                                |   6 +-
 test/v4l2_subdevice/list_formats.cpp          |   3 +-
 test/v4l2_subdevice/meson.build               |   2 +-
 test/v4l2_videodevice/buffer_sharing.cpp      |   6 +-
 test/v4l2_videodevice/capture_async.cpp       |   6 +-
 test/v4l2_videodevice/formats.cpp             |   3 +-
 test/v4l2_videodevice/meson.build             |   2 +-
 test/v4l2_videodevice/v4l2_m2mdevice.cpp      |   7 +-
 .../module_ipa_proxy.cpp.tmpl                 |   5 +-
 .../module_ipa_proxy.h.tmpl                   |   3 +-
 .../module_ipa_proxy_worker.cpp.tmpl          |   7 +-
 235 files changed, 854 insertions(+), 647 deletions(-)
 rename include/libcamera/{ => base}/bound_method.h (97%)
 rename include/libcamera/{ => base}/class.h (100%)
 rename include/libcamera/{internal => base}/event_dispatcher.h (77%)
 rename include/libcamera/{internal => base}/event_dispatcher_poll.h (81%)
 rename include/libcamera/{internal => base}/event_notifier.h (88%)
 rename include/libcamera/{internal => base}/file.h (85%)
 rename include/libcamera/{internal => base}/log.h (93%)
 create mode 100644 include/libcamera/base/meson.build
 rename include/libcamera/{internal => base}/message.h (87%)
 rename include/libcamera/{ => base}/object.h (89%)
 create mode 100644 include/libcamera/base/private.h
 rename include/libcamera/{internal => base}/semaphore.h (72%)
 rename include/libcamera/{ => base}/signal.h (93%)
 rename include/libcamera/{ => base}/span.h (100%)
 rename include/libcamera/{internal => base}/thread.h (82%)
 rename include/libcamera/{internal => base}/timer.h (79%)
 rename include/libcamera/{internal => base}/utils.h (97%)
 create mode 100644 include/libcamera/internal/source-paths.h
 rename src/libcamera/{ => base}/bound_method.cpp (94%)
 rename src/libcamera/{ => base}/class.cpp (99%)
 rename src/libcamera/{ => base}/event_dispatcher.cpp (97%)
 rename src/libcamera/{ => base}/event_dispatcher_poll.cpp (95%)
 rename src/libcamera/{ => base}/event_notifier.cpp (95%)
 rename src/libcamera/{ => base}/file.cpp (99%)
 rename src/libcamera/{ => base}/log.cpp (99%)
 create mode 100644 src/libcamera/base/meson.build
 rename src/libcamera/{ => base}/message.cpp (96%)
 rename src/libcamera/{ => base}/object.cpp (96%)
 rename src/libcamera/{ => base}/semaphore.cpp (96%)
 rename src/libcamera/{ => base}/signal.cpp (98%)
 rename src/libcamera/{ => base}/thread.cpp (98%)
 rename src/libcamera/{ => base}/timer.cpp (93%)
 rename src/libcamera/{ => base}/utils.cpp (81%)
 create mode 100644 src/libcamera/source-paths.cpp
 create mode 100644 test/public-api.cpp

Comments

Paul Elder June 25, 2021, 2:28 a.m. UTC | #1
Hi Kieran,

On Fri, Jun 25, 2021 at 02:35:27AM +0100, Kieran Bingham wrote:
> The libcamera library is moved to the first positional argument of the
> pkg-config generator to automatically populate the name and filebase
> values for the package.
> 
> As part of this, the shared library name is adjusted to the full library
> name 'libcamera', without relying upon the automatic 'lib' prefix which
> better represents the component and naming of the library.
> 
> As a result of this, the pkgconfig file is now named 'libcamera.pc' as
> opposed to 'camera.pc', and applications desiring to reference libcamera
> will need to search for 'libcamera' as a dependency rather than
> 'camera'.
> 
> The library itself is still created and installed as 'libcamera.so'.
> 
> An example meson.build file would need to be adjusted as the following:
> 
> -      dependency('camera', required : true),
> +      dependency('libcamera', required : true),
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
>  src/libcamera/meson.build | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> index e4c60e736697..387d20843203 100644
> --- a/src/libcamera/meson.build
> +++ b/src/libcamera/meson.build
> @@ -135,8 +135,9 @@ libcamera_deps = [
>  # runtime if the library is running from an installed location by checking
>  # for the presence or abscence of the dynamic tag.
>  
> -libcamera = shared_library('camera',
> +libcamera = shared_library('libcamera',
>                             libcamera_sources,
> +                           name_prefix : '',
>                             install : true,
>                             include_directories : includes,
>                             build_rpath : '/',
> @@ -157,10 +158,8 @@ libcamera_dep = declare_dependency(sources : [
>                                     link_with : libcamera)
>  
>  pkg_mod = import('pkgconfig')
> -pkg_mod.generate(libraries: libcamera,
> +pkg_mod.generate(libcamera,
>                   version : '1.0',
> -                 name : 'libcamera',
> -                 filebase : 'camera',
>                   description : 'Complex Camera Support Library',
>                   subdirs : 'libcamera')
>  
> -- 
> 2.30.2
>
Paul Elder June 25, 2021, 2:29 a.m. UTC | #2
Hi Kieran,

On Fri, Jun 25, 2021 at 02:35:26AM +0100, Kieran Bingham wrote:
> The pkg-config file for the main libcamera.so is generated
> at the top level meson.build.
> 
> Move this to the actual core libcamera build structure to be
> consistent and keep it next to the library construction.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
>  meson.build               | 8 --------
>  src/libcamera/meson.build | 8 ++++++++
>  2 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/meson.build b/meson.build
> index 4d7d936f09e2..6eed0d8c4a44 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -164,14 +164,6 @@ run_command('ln', '-fsT', meson.source_root(), meson.build_root() / 'source')
>  
>  configure_file(output : 'config.h', configuration : config_h)
>  
> -pkg_mod = import('pkgconfig')
> -pkg_mod.generate(libraries : libcamera,
> -                 version : '1.0',
> -                 name : 'libcamera',
> -                 filebase : 'camera',
> -                 description : 'Complex Camera Support Library',
> -                 subdirs : 'libcamera')
> -
>  # Check for python installation and modules.
>  py_mod = import('python')
>  py_mod.find_installation('python3', modules: py_modules)
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> index d9b5bfae69fd..e4c60e736697 100644
> --- a/src/libcamera/meson.build
> +++ b/src/libcamera/meson.build
> @@ -156,4 +156,12 @@ libcamera_dep = declare_dependency(sources : [
>                                     include_directories : libcamera_includes,
>                                     link_with : libcamera)
>  
> +pkg_mod = import('pkgconfig')
> +pkg_mod.generate(libraries: libcamera,
> +                 version : '1.0',
> +                 name : 'libcamera',
> +                 filebase : 'camera',
> +                 description : 'Complex Camera Support Library',
> +                 subdirs : 'libcamera')
> +
>  subdir('proxy/worker')
> -- 
> 2.30.2
>
Paul Elder June 25, 2021, 2:32 a.m. UTC | #3
Hi Kieran,

On Fri, Jun 25, 2021 at 02:35:24AM +0100, Kieran Bingham wrote:
> The libcamera Android HAL implementation should not be an integral part
> of libcamera, but a support library that utilises the libcamera public
> API.
> 
> Move the implementation to its own distinct library.
> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
>  src/android/cros/meson.build |  2 +-
>  src/android/meson.build      | 16 +++++++++++++++-
>  src/libcamera/meson.build    | 13 -------------
>  src/meson.build              |  8 ++------
>  4 files changed, 18 insertions(+), 21 deletions(-)
> 
> diff --git a/src/android/cros/meson.build b/src/android/cros/meson.build
> index 13ec8f0aecc7..c2bda70838e2 100644
> --- a/src/android/cros/meson.build
> +++ b/src/android/cros/meson.build
> @@ -15,4 +15,4 @@ cros_hal_info = static_library('cros_hal_info',
>                                 include_directories : [android_includes,
>                                                        libcamera_includes])
>  
> -libcamera_objects += cros_hal_info.extract_objects('camera3_hal.cpp')
> +android_objects += cros_hal_info.extract_objects('camera3_hal.cpp')
> diff --git a/src/android/meson.build b/src/android/meson.build
> index 6270fb201338..feda3e0998bd 100644
> --- a/src/android/meson.build
> +++ b/src/android/meson.build
> @@ -4,6 +4,7 @@ android_deps = [
>      dependency('libexif', required : get_option('android')),
>      dependency('libjpeg', required : get_option('android')),
>      dependency('yaml-0.1', required : get_option('android')),
> +    libcamera_dep,
>  ]
>  
>  android_enabled = true
> @@ -36,8 +37,11 @@ endif
>  
>  android_deps += [libyuv_dep]
>  
> +android_cpp_args = []
> +android_objects = []
> +
>  if get_option('android_platform') == 'cros'
> -   libcamera_cpp_args += [ '-DOS_CHROMEOS']
> +    android_cpp_args += ['-DOS_CHROMEOS']
>  endif
>  
>  subdir('cros')
> @@ -69,3 +73,13 @@ android_camera_metadata = static_library('camera_metadata',
>                                           android_camera_metadata_sources,
>                                           c_args : '-Wno-shadow',
>                                           include_directories : android_includes)
> +
> +libcamera_hal = shared_library('libcamera-hal',
> +                               android_hal_sources,
> +                               name_prefix : '',
> +                               link_with : android_camera_metadata,
> +                               install : true,
> +                               cpp_args : android_cpp_args,
> +                               objects : android_objects,
> +                               include_directories : android_includes,
> +                               dependencies : android_deps)
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> index 7e19a1774a59..d9b5bfae69fd 100644
> --- a/src/libcamera/meson.build
> +++ b/src/libcamera/meson.build
> @@ -130,16 +130,6 @@ libcamera_deps = [
>      dependency('threads'),
>  ]
>  
> -libcamera_link_with = []
> -
> -if android_enabled
> -    libcamera_sources += android_hal_sources
> -    includes += android_includes
> -    libcamera_link_with += android_camera_metadata
> -
> -    libcamera_deps += android_deps
> -endif
> -
>  # We add '/' to the build_rpath as a 'safe' path to act as a boolean flag.
>  # The build_rpath is stripped at install time by meson, so we determine at
>  # runtime if the library is running from an installed location by checking
> @@ -148,10 +138,7 @@ endif
>  libcamera = shared_library('camera',
>                             libcamera_sources,
>                             install : true,
> -                           link_with : libcamera_link_with,
> -                           cpp_args : libcamera_cpp_args,
>                             include_directories : includes,
> -                           objects : libcamera_objects,
>                             build_rpath : '/',
>                             dependencies : libcamera_deps)
>  
> diff --git a/src/meson.build b/src/meson.build
> index 573966055aa2..e0ea9c3570af 100644
> --- a/src/meson.build
> +++ b/src/meson.build
> @@ -25,14 +25,10 @@ else
>      ipa_sign_module = false
>  endif
>  
> -libcamera_cpp_args = []
> -libcamera_objects = []
> +# libcamera must be built first as a dependency to the other components.
> +subdir('libcamera')
>  
> -# The 'android' subdir must be processed first, and the build targets
> -# are included directly into the libcamera library when this is enabled.
>  subdir('android')
> -
> -subdir('libcamera')
>  subdir('ipa')
>  
>  subdir('lc-compliance')
> -- 
> 2.30.2
>
Hirokazu Honda June 25, 2021, 2:59 a.m. UTC | #4
Hi Kieran, thank you for the patch.

On Fri, Jun 25, 2021 at 10:35 AM Kieran Bingham
<kieran.bingham@ideasonboard.com> wrote:
>
> The ChromeOS specific Android HAL support was overly-complex to support
> linking an additional library, and then passing the built object into
> the libcamera.so build.
>
> Now that it has its own distinct libcamera-hal.so, simplify the CrOS
> integration to build directly into that library.
>
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
> ---
>  src/android/cros/meson.build | 11 +++--------
>  src/android/meson.build      | 13 +++----------
>  2 files changed, 6 insertions(+), 18 deletions(-)
>
> diff --git a/src/android/cros/meson.build b/src/android/cros/meson.build
> index c2bda70838e2..35995dd814a2 100644
> --- a/src/android/cros/meson.build
> +++ b/src/android/cros/meson.build
> @@ -4,15 +4,10 @@ if get_option('android_platform') != 'cros'
>     subdir_done()
>  endif
>
> -cros_hal_info_sources = files([
> +android_hal_sources += files([
>      'camera3_hal.cpp',
>  ])
>
> -cros_hal_info = static_library('cros_hal_info',
> -                               cros_hal_info_sources,
> -                               dependencies : dependency('libcros_camera'),
> -                               c_args : '-Wno-shadow',
> -                               include_directories : [android_includes,
> -                                                      libcamera_includes])
> +android_deps += dependency('libcros_camera')
>
> -android_objects += cros_hal_info.extract_objects('camera3_hal.cpp')
> +android_cpp_args += ['-DOS_CHROMEOS']
> diff --git a/src/android/meson.build b/src/android/meson.build
> index feda3e0998bd..bd58ef964c2a 100644
> --- a/src/android/meson.build
> +++ b/src/android/meson.build
> @@ -37,15 +37,6 @@ endif
>
>  android_deps += [libyuv_dep]
>
> -android_cpp_args = []
> -android_objects = []
> -
> -if get_option('android_platform') == 'cros'
> -    android_cpp_args += ['-DOS_CHROMEOS']
> -endif
> -
> -subdir('cros')
> -
>  android_hal_sources = files([
>      'camera3_hal.cpp',
>      'camera_capabilities.cpp',
> @@ -63,6 +54,9 @@ android_hal_sources = files([
>      'yuv/post_processor_yuv.cpp'
>  ])
>
> +android_cpp_args = []
> +
> +subdir('cros')
>  subdir('mm')
>
>  android_camera_metadata_sources = files([
> @@ -80,6 +74,5 @@ libcamera_hal = shared_library('libcamera-hal',
>                                 link_with : android_camera_metadata,
>                                 install : true,
>                                 cpp_args : android_cpp_args,
> -                               objects : android_objects,
>                                 include_directories : android_includes,
>                                 dependencies : android_deps)
> --
> 2.30.2
>
Paul Elder June 25, 2021, 2:59 a.m. UTC | #5
Hi Kieran,

On Fri, Jun 25, 2021 at 02:35:25AM +0100, Kieran Bingham wrote:
> The ChromeOS specific Android HAL support was overly-complex to support
> linking an additional library, and then passing the built object into
> the libcamera.so build.
> 
> Now that it has its own distinct libcamera-hal.so, simplify the CrOS
> integration to build directly into that library.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
>  src/android/cros/meson.build | 11 +++--------
>  src/android/meson.build      | 13 +++----------
>  2 files changed, 6 insertions(+), 18 deletions(-)
> 
> diff --git a/src/android/cros/meson.build b/src/android/cros/meson.build
> index c2bda70838e2..35995dd814a2 100644
> --- a/src/android/cros/meson.build
> +++ b/src/android/cros/meson.build
> @@ -4,15 +4,10 @@ if get_option('android_platform') != 'cros'
>     subdir_done()
>  endif
>  
> -cros_hal_info_sources = files([
> +android_hal_sources += files([
>      'camera3_hal.cpp',
>  ])
>  
> -cros_hal_info = static_library('cros_hal_info',
> -                               cros_hal_info_sources,
> -                               dependencies : dependency('libcros_camera'),
> -                               c_args : '-Wno-shadow',
> -                               include_directories : [android_includes,
> -                                                      libcamera_includes])
> +android_deps += dependency('libcros_camera')
>  
> -android_objects += cros_hal_info.extract_objects('camera3_hal.cpp')
> +android_cpp_args += ['-DOS_CHROMEOS']
> diff --git a/src/android/meson.build b/src/android/meson.build
> index feda3e0998bd..bd58ef964c2a 100644
> --- a/src/android/meson.build
> +++ b/src/android/meson.build
> @@ -37,15 +37,6 @@ endif
>  
>  android_deps += [libyuv_dep]
>  
> -android_cpp_args = []
> -android_objects = []
> -
> -if get_option('android_platform') == 'cros'
> -    android_cpp_args += ['-DOS_CHROMEOS']
> -endif
> -
> -subdir('cros')
> -
>  android_hal_sources = files([
>      'camera3_hal.cpp',
>      'camera_capabilities.cpp',
> @@ -63,6 +54,9 @@ android_hal_sources = files([
>      'yuv/post_processor_yuv.cpp'
>  ])
>  
> +android_cpp_args = []
> +
> +subdir('cros')
>  subdir('mm')
>  
>  android_camera_metadata_sources = files([
> @@ -80,6 +74,5 @@ libcamera_hal = shared_library('libcamera-hal',
>                                 link_with : android_camera_metadata,
>                                 install : true,
>                                 cpp_args : android_cpp_args,
> -                               objects : android_objects,
>                                 include_directories : android_includes,
>                                 dependencies : android_deps)
> -- 
> 2.30.2
>
Hirokazu Honda June 25, 2021, 3:06 a.m. UTC | #6
Hi Kieran, thank you for the patch.

On Fri, Jun 25, 2021 at 11:30 AM <paul.elder@ideasonboard.com> wrote:
>
> Hi Kieran,
>
> On Fri, Jun 25, 2021 at 02:35:26AM +0100, Kieran Bingham wrote:
> > The pkg-config file for the main libcamera.so is generated
> > at the top level meson.build.
> >
> > Move this to the actual core libcamera build structure to be
> > consistent and keep it next to the library construction.
> >
> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>
> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
>
> > ---
> >  meson.build               | 8 --------
> >  src/libcamera/meson.build | 8 ++++++++
> >  2 files changed, 8 insertions(+), 8 deletions(-)
> >
> > diff --git a/meson.build b/meson.build
> > index 4d7d936f09e2..6eed0d8c4a44 100644
> > --- a/meson.build
> > +++ b/meson.build
> > @@ -164,14 +164,6 @@ run_command('ln', '-fsT', meson.source_root(), meson.build_root() / 'source')
> >
> >  configure_file(output : 'config.h', configuration : config_h)
> >
> > -pkg_mod = import('pkgconfig')
> > -pkg_mod.generate(libraries : libcamera,
> > -                 version : '1.0',
> > -                 name : 'libcamera',
> > -                 filebase : 'camera',
> > -                 description : 'Complex Camera Support Library',
> > -                 subdirs : 'libcamera')
> > -
> >  # Check for python installation and modules.
> >  py_mod = import('python')
> >  py_mod.find_installation('python3', modules: py_modules)
> > diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> > index d9b5bfae69fd..e4c60e736697 100644
> > --- a/src/libcamera/meson.build
> > +++ b/src/libcamera/meson.build
> > @@ -156,4 +156,12 @@ libcamera_dep = declare_dependency(sources : [
> >                                     include_directories : libcamera_includes,
> >                                     link_with : libcamera)
> >
> > +pkg_mod = import('pkgconfig')
> > +pkg_mod.generate(libraries: libcamera,
> > +                 version : '1.0',
> > +                 name : 'libcamera',
> > +                 filebase : 'camera',

This is not related to this change, but why is filebase camera, not libcamera?

Reviewed-by: Hirokazu Honda <hiroh@chromium.org>

> > +                 description : 'Complex Camera Support Library',
> > +                 subdirs : 'libcamera')
> > +
> >  subdir('proxy/worker')
> > --
> > 2.30.2
> >
Hirokazu Honda June 25, 2021, 3:08 a.m. UTC | #7
Hi Kieran,

On Fri, Jun 25, 2021 at 12:06 PM Hirokazu Honda <hiroh@chromium.org> wrote:
>
> Hi Kieran, thank you for the patch.
>
> On Fri, Jun 25, 2021 at 11:30 AM <paul.elder@ideasonboard.com> wrote:
> >
> > Hi Kieran,
> >
> > On Fri, Jun 25, 2021 at 02:35:26AM +0100, Kieran Bingham wrote:
> > > The pkg-config file for the main libcamera.so is generated
> > > at the top level meson.build.
> > >
> > > Move this to the actual core libcamera build structure to be
> > > consistent and keep it next to the library construction.
> > >
> > > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> >
> > Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
> >
> > > ---
> > >  meson.build               | 8 --------
> > >  src/libcamera/meson.build | 8 ++++++++
> > >  2 files changed, 8 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/meson.build b/meson.build
> > > index 4d7d936f09e2..6eed0d8c4a44 100644
> > > --- a/meson.build
> > > +++ b/meson.build
> > > @@ -164,14 +164,6 @@ run_command('ln', '-fsT', meson.source_root(), meson.build_root() / 'source')
> > >
> > >  configure_file(output : 'config.h', configuration : config_h)
> > >
> > > -pkg_mod = import('pkgconfig')
> > > -pkg_mod.generate(libraries : libcamera,
> > > -                 version : '1.0',
> > > -                 name : 'libcamera',
> > > -                 filebase : 'camera',
> > > -                 description : 'Complex Camera Support Library',
> > > -                 subdirs : 'libcamera')
> > > -
> > >  # Check for python installation and modules.
> > >  py_mod = import('python')
> > >  py_mod.find_installation('python3', modules: py_modules)
> > > diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> > > index d9b5bfae69fd..e4c60e736697 100644
> > > --- a/src/libcamera/meson.build
> > > +++ b/src/libcamera/meson.build
> > > @@ -156,4 +156,12 @@ libcamera_dep = declare_dependency(sources : [
> > >                                     include_directories : libcamera_includes,
> > >                                     link_with : libcamera)
> > >
> > > +pkg_mod = import('pkgconfig')
> > > +pkg_mod.generate(libraries: libcamera,
> > > +                 version : '1.0',
> > > +                 name : 'libcamera',
> > > +                 filebase : 'camera',
>
> This is not related to this change, but why is filebase camera, not libcamera?
>

Never mind. This is resolved in the next patch.

> Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
>
> > > +                 description : 'Complex Camera Support Library',
> > > +                 subdirs : 'libcamera')
> > > +
> > >  subdir('proxy/worker')
> > > --
> > > 2.30.2
> > >
Hirokazu Honda June 25, 2021, 3:09 a.m. UTC | #8
Hi Kieran, thank you for the patch.

On Fri, Jun 25, 2021 at 11:29 AM <paul.elder@ideasonboard.com> wrote:
>
> Hi Kieran,
>
> On Fri, Jun 25, 2021 at 02:35:27AM +0100, Kieran Bingham wrote:
> > The libcamera library is moved to the first positional argument of the
> > pkg-config generator to automatically populate the name and filebase
> > values for the package.
> >
> > As part of this, the shared library name is adjusted to the full library
> > name 'libcamera', without relying upon the automatic 'lib' prefix which
> > better represents the component and naming of the library.
> >
> > As a result of this, the pkgconfig file is now named 'libcamera.pc' as
> > opposed to 'camera.pc', and applications desiring to reference libcamera
> > will need to search for 'libcamera' as a dependency rather than
> > 'camera'.
> >
> > The library itself is still created and installed as 'libcamera.so'.
> >
> > An example meson.build file would need to be adjusted as the following:
> >
> > -      dependency('camera', required : true),
> > +      dependency('libcamera', required : true),
> >
> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>
> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
>

Reviewed-by: Hirokazu Honda <hiroh@chromium.org>

> > ---
> >  src/libcamera/meson.build | 7 +++----
> >  1 file changed, 3 insertions(+), 4 deletions(-)
> >
> > diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> > index e4c60e736697..387d20843203 100644
> > --- a/src/libcamera/meson.build
> > +++ b/src/libcamera/meson.build
> > @@ -135,8 +135,9 @@ libcamera_deps = [
> >  # runtime if the library is running from an installed location by checking
> >  # for the presence or abscence of the dynamic tag.
> >
> > -libcamera = shared_library('camera',
> > +libcamera = shared_library('libcamera',
> >                             libcamera_sources,
> > +                           name_prefix : '',
> >                             install : true,
> >                             include_directories : includes,
> >                             build_rpath : '/',
> > @@ -157,10 +158,8 @@ libcamera_dep = declare_dependency(sources : [
> >                                     link_with : libcamera)
> >
> >  pkg_mod = import('pkgconfig')
> > -pkg_mod.generate(libraries: libcamera,
> > +pkg_mod.generate(libcamera,
> >                   version : '1.0',
> > -                 name : 'libcamera',
> > -                 filebase : 'camera',
> >                   description : 'Complex Camera Support Library',
> >                   subdirs : 'libcamera')
> >
> > --
> > 2.30.2
> >
Paul Elder June 25, 2021, 3:11 a.m. UTC | #9
Hi Hiro,

On Fri, Jun 25, 2021 at 12:06:40PM +0900, Hirokazu Honda wrote:
> Hi Kieran, thank you for the patch.
> 
> On Fri, Jun 25, 2021 at 11:30 AM <paul.elder@ideasonboard.com> wrote:
> >
> > Hi Kieran,
> >
> > On Fri, Jun 25, 2021 at 02:35:26AM +0100, Kieran Bingham wrote:
> > > The pkg-config file for the main libcamera.so is generated
> > > at the top level meson.build.
> > >
> > > Move this to the actual core libcamera build structure to be
> > > consistent and keep it next to the library construction.
> > >
> > > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> >
> > Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
> >
> > > ---
> > >  meson.build               | 8 --------
> > >  src/libcamera/meson.build | 8 ++++++++
> > >  2 files changed, 8 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/meson.build b/meson.build
> > > index 4d7d936f09e2..6eed0d8c4a44 100644
> > > --- a/meson.build
> > > +++ b/meson.build
> > > @@ -164,14 +164,6 @@ run_command('ln', '-fsT', meson.source_root(), meson.build_root() / 'source')
> > >
> > >  configure_file(output : 'config.h', configuration : config_h)
> > >
> > > -pkg_mod = import('pkgconfig')
> > > -pkg_mod.generate(libraries : libcamera,
> > > -                 version : '1.0',
> > > -                 name : 'libcamera',
> > > -                 filebase : 'camera',
> > > -                 description : 'Complex Camera Support Library',
> > > -                 subdirs : 'libcamera')
> > > -
> > >  # Check for python installation and modules.
> > >  py_mod = import('python')
> > >  py_mod.find_installation('python3', modules: py_modules)
> > > diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> > > index d9b5bfae69fd..e4c60e736697 100644
> > > --- a/src/libcamera/meson.build
> > > +++ b/src/libcamera/meson.build
> > > @@ -156,4 +156,12 @@ libcamera_dep = declare_dependency(sources : [
> > >                                     include_directories : libcamera_includes,
> > >                                     link_with : libcamera)
> > >
> > > +pkg_mod = import('pkgconfig')
> > > +pkg_mod.generate(libraries: libcamera,
> > > +                 version : '1.0',
> > > +                 name : 'libcamera',
> > > +                 filebase : 'camera',
> 
> This is not related to this change, but why is filebase camera, not libcamera?

My understanding is that this patch is for moving this section directly
without modification, while the next patch changes the filebase from
camera to libcamera.


Paul

> 
> Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
> 
> > > +                 description : 'Complex Camera Support Library',
> > > +                 subdirs : 'libcamera')
> > > +
> > >  subdir('proxy/worker')
> > > --
> > > 2.30.2
> > >
Laurent Pinchart June 25, 2021, 3:18 a.m. UTC | #10
Hi Kieran,

Thank you for the patch.

On Fri, Jun 25, 2021 at 02:35:27AM +0100, Kieran Bingham wrote:
> The libcamera library is moved to the first positional argument of the
> pkg-config generator to automatically populate the name and filebase
> values for the package.
> 
> As part of this, the shared library name is adjusted to the full library
> name 'libcamera', without relying upon the automatic 'lib' prefix which
> better represents the component and naming of the library.
> 
> As a result of this, the pkgconfig file is now named 'libcamera.pc' as
> opposed to 'camera.pc', and applications desiring to reference libcamera
> will need to search for 'libcamera' as a dependency rather than
> 'camera'.
> 
> The library itself is still created and installed as 'libcamera.so'.
> 
> An example meson.build file would need to be adjusted as the following:
> 
> -      dependency('camera', required : true),
> +      dependency('libcamera', required : true),
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  src/libcamera/meson.build | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> index e4c60e736697..387d20843203 100644
> --- a/src/libcamera/meson.build
> +++ b/src/libcamera/meson.build
> @@ -135,8 +135,9 @@ libcamera_deps = [
>  # runtime if the library is running from an installed location by checking
>  # for the presence or abscence of the dynamic tag.
>  
> -libcamera = shared_library('camera',
> +libcamera = shared_library('libcamera',
>                             libcamera_sources,
> +                           name_prefix : '',

While I like the end-result for pkg-config, I'm not too fond of this
particular change as we work around the normal usage of shared_library()
here to change the name of the .pc file. Could we keep this unchanged,
and set filebase to 'libcamera' below instead ?

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>                             install : true,
>                             include_directories : includes,
>                             build_rpath : '/',
> @@ -157,10 +158,8 @@ libcamera_dep = declare_dependency(sources : [
>                                     link_with : libcamera)
>  
>  pkg_mod = import('pkgconfig')
> -pkg_mod.generate(libraries: libcamera,
> +pkg_mod.generate(libcamera,
>                   version : '1.0',
> -                 name : 'libcamera',
> -                 filebase : 'camera',
>                   description : 'Complex Camera Support Library',
>                   subdirs : 'libcamera')
>
Paul Elder June 25, 2021, 3:18 a.m. UTC | #11
Hi Kieran,

On Fri, Jun 25, 2021 at 02:35:28AM +0100, Kieran Bingham wrote:
> The libcameraSourcePath and libcameraBuildPath helper functions are
> internal and specific to libcamera needs while operating with the meson
> build system.
> 
> In preparation for the upcoming move of utils to a common library, move
> these helpers out of utils and into their own build unit.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
>  include/libcamera/internal/meson.build    |   1 +
>  include/libcamera/internal/source-paths.h |  19 ++++
>  src/libcamera/meson.build                 |   1 +
>  src/libcamera/source-paths.cpp            | 129 ++++++++++++++++++++++
>  src/libcamera/utils.cpp                   | 102 -----------------
>  5 files changed, 150 insertions(+), 102 deletions(-)
>  create mode 100644 include/libcamera/internal/source-paths.h
>  create mode 100644 src/libcamera/source-paths.cpp
> 
> diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build
> index f019cfb3b0de..e5088177fe8e 100644
> --- a/include/libcamera/internal/meson.build
> +++ b/include/libcamera/internal/meson.build
> @@ -39,6 +39,7 @@ libcamera_internal_headers = files([
>      'process.h',
>      'pub_key.h',
>      'semaphore.h',
> +    'source-paths.h',
>      'sysfs.h',
>      'thread.h',
>      'timer.h',
> diff --git a/include/libcamera/internal/source-paths.h b/include/libcamera/internal/source-paths.h
> new file mode 100644
> index 000000000000..2591ebb1081b
> --- /dev/null
> +++ b/include/libcamera/internal/source-paths.h
> @@ -0,0 +1,19 @@
> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
> +/*
> + * Copyright (C) 2021, Google Inc.
> + *
> + * source-paths.h - Identify libcamera source and build paths
> + */
> +#ifndef __LIBCAMERA_INTERNAL_SOURCE_PATHS_H__
> +#define __LIBCAMERA_INTERNAL_SOURCE_PATHS_H__
> +
> +#include <string>
> +
> +namespace libcamera::utils {
> +
> +std::string libcameraBuildPath();
> +std::string libcameraSourcePath();
> +
> +} /* namespace libcamera::utils */
> +
> +#endif /* __LIBCAMERA_INTERNAL_SOURCE_PATHS_H__ */
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> index 387d20843203..e792094f5798 100644
> --- a/src/libcamera/meson.build
> +++ b/src/libcamera/meson.build
> @@ -46,6 +46,7 @@ libcamera_sources = files([
>      'request.cpp',
>      'semaphore.cpp',
>      'signal.cpp',
> +    'source-paths.cpp',
>      'stream.cpp',
>      'sysfs.cpp',
>      'thread.cpp',
> diff --git a/src/libcamera/source-paths.cpp b/src/libcamera/source-paths.cpp
> new file mode 100644
> index 000000000000..b39f5f853e39
> --- /dev/null
> +++ b/src/libcamera/source-paths.cpp
> @@ -0,0 +1,129 @@
> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
> +/*
> + * Copyright (C) 2021, Google Inc.
> + *
> + * source-paths.cpp - Identify libcamera source and build paths
> + */
> +
> +#include "libcamera/internal/source-paths.h"
> +
> +#include <dlfcn.h>
> +#include <elf.h>
> +#include <link.h>
> +#include <sys/stat.h>
> +
> +#include "libcamera/internal/utils.h"
> +
> +/**
> + * \file source-paths.h
> + * \brief Identify the build and source path of a not-yet-installed library
> + */
> +
> +/* musl doesn't declare _DYNAMIC in link.h, declare it manually. */
> +extern ElfW(Dyn) _DYNAMIC[];
> +
> +namespace libcamera::utils {
> +
> +/**
> + * \brief Check if libcamera is installed or not
> + *
> + * Utilise the build_rpath dynamic tag which is stripped out by meson at
> + * install time to determine at runtime if the library currently executing
> + * has been installed or not.
> + *
> + * \return True if libcamera is installed, false otherwise
> + */
> +bool isLibcameraInstalled()
> +{
> +	/*
> +	 * DT_RUNPATH (DT_RPATH when the linker uses old dtags) is removed on
> +	 * install.
> +	 */
> +	for (const ElfW(Dyn) *dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn) {
> +		if (dyn->d_tag == DT_RUNPATH || dyn->d_tag == DT_RPATH)
> +			return false;
> +	}
> +
> +	return true;
> +}
> +
> +/**
> + * \brief Retrieve the path to the build directory
> + *
> + * During development, it is useful to run libcamera binaries directly from the
> + * build directory without installing them. This function helps components that
> + * need to locate resources in the build tree, such as IPA modules or IPA proxy
> + * workers, by providing them with the path to the root of the build directory.
> + * Callers can then use it to complement or override searches in system-wide
> + * directories.
> + *
> + * If libcamera has been installed, the build directory path is not available
> + * and this function returns an empty string.
> + *
> + * \return The path to the build directory if running from a build, or an empty
> + * string otherwise
> + */
> +std::string libcameraBuildPath()
> +{
> +	if (isLibcameraInstalled())
> +		return std::string();
> +
> +	Dl_info info;
> +
> +	/* Look up our own symbol. */
> +	int ret = dladdr(reinterpret_cast<void *>(libcameraBuildPath), &info);
> +	if (ret == 0)
> +		return std::string();
> +
> +	std::string path = dirname(info.dli_fname) + "/../../";
> +
> +	char *real = realpath(path.c_str(), nullptr);
> +	if (!real)
> +		return std::string();
> +
> +	path = real;
> +	free(real);
> +
> +	return path + "/";
> +}
> +
> +/**
> + * \brief Retrieve the path to the source directory
> + *
> + * During development, it is useful to run libcamera binaries directly from the
> + * build directory without installing them. This function helps components that
> + * need to locate resources in the source tree, such as IPA configuration
> + * files, by providing them with the path to the root of the source directory.
> + * Callers can then use it to complement or override searches in system-wide
> + * directories.
> + *
> + * If libcamera has been installed, the source directory path is not available
> + * and this function returns an empty string.
> + *
> + * \return The path to the source directory if running from a build directory,
> + * or an empty string otherwise
> + */
> +std::string libcameraSourcePath()
> +{
> +	std::string path = libcameraBuildPath();
> +	if (path.empty())
> +		return std::string();
> +
> +	path += "source";
> +
> +	char *real = realpath(path.c_str(), nullptr);
> +	if (!real)
> +		return std::string();
> +
> +	path = real;
> +	free(real);
> +
> +	struct stat statbuf;
> +	int ret = stat(path.c_str(), &statbuf);
> +	if (ret < 0 || (statbuf.st_mode & S_IFMT) != S_IFDIR)
> +		return std::string();
> +
> +	return path + "/";
> +}
> +
> +} /* namespace libcamera::utils */
> diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp
> index 49b8fc9e211f..42f82d6158dd 100644
> --- a/src/libcamera/utils.cpp
> +++ b/src/libcamera/utils.cpp
> @@ -351,108 +351,6 @@ std::string toAscii(const std::string &str)
>  	return ret;
>  }
>  
> -/**
> - * \brief Check if libcamera is installed or not
> - *
> - * Utilise the build_rpath dynamic tag which is stripped out by meson at
> - * install time to determine at runtime if the library currently executing
> - * has been installed or not.
> - *
> - * \return True if libcamera is installed, false otherwise
> - */
> -bool isLibcameraInstalled()
> -{
> -	/*
> -	 * DT_RUNPATH (DT_RPATH when the linker uses old dtags) is removed on
> -	 * install.
> -	 */
> -	for (const ElfW(Dyn) *dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn) {
> -		if (dyn->d_tag == DT_RUNPATH || dyn->d_tag == DT_RPATH)
> -			return false;
> -	}
> -
> -	return true;
> -}
> -
> -/**
> - * \brief Retrieve the path to the build directory
> - *
> - * During development, it is useful to run libcamera binaries directly from the
> - * build directory without installing them. This function helps components that
> - * need to locate resources in the build tree, such as IPA modules or IPA proxy
> - * workers, by providing them with the path to the root of the build directory.
> - * Callers can then use it to complement or override searches in system-wide
> - * directories.
> - *
> - * If libcamera has been installed, the build directory path is not available
> - * and this function returns an empty string.
> - *
> - * \return The path to the build directory if running from a build, or an empty
> - * string otherwise
> - */
> -std::string libcameraBuildPath()
> -{
> -	if (isLibcameraInstalled())
> -		return std::string();
> -
> -	Dl_info info;
> -
> -	/* Look up our own symbol. */
> -	int ret = dladdr(reinterpret_cast<void *>(libcameraBuildPath), &info);
> -	if (ret == 0)
> -		return std::string();
> -
> -	std::string path = dirname(info.dli_fname) + "/../../";
> -
> -	char *real = realpath(path.c_str(), nullptr);
> -	if (!real)
> -		return std::string();
> -
> -	path = real;
> -	free(real);
> -
> -	return path + "/";
> -}
> -
> -/**
> - * \brief Retrieve the path to the source directory
> - *
> - * During development, it is useful to run libcamera binaries directly from the
> - * build directory without installing them. This function helps components that
> - * need to locate resources in the source tree, such as IPA configuration
> - * files, by providing them with the path to the root of the source directory.
> - * Callers can then use it to complement or override searches in system-wide
> - * directories.
> - *
> - * If libcamera has been installed, the source directory path is not available
> - * and this function returns an empty string.
> - *
> - * \return The path to the source directory if running from a build directory,
> - * or an empty string otherwise
> - */
> -std::string libcameraSourcePath()
> -{
> -	std::string path = libcameraBuildPath();
> -	if (path.empty())
> -		return std::string();
> -
> -	path += "source";
> -
> -	char *real = realpath(path.c_str(), nullptr);
> -	if (!real)
> -		return std::string();
> -
> -	path = real;
> -	free(real);
> -
> -	struct stat statbuf;
> -	int ret = stat(path.c_str(), &statbuf);
> -	if (ret < 0 || (statbuf.st_mode & S_IFMT) != S_IFDIR)
> -		return std::string();
> -
> -	return path + "/";
> -}
> -
>  /**
>   * \fn alignDown(unsigned int value, unsigned int alignment)
>   * \brief Align \a value down to \a alignment
> -- 
> 2.30.2
>
Laurent Pinchart June 25, 2021, 3:18 a.m. UTC | #12
Hi Kieran,

Thank you for the patch.

On Fri, Jun 25, 2021 at 02:35:25AM +0100, Kieran Bingham wrote:
> The ChromeOS specific Android HAL support was overly-complex to support
> linking an additional library, and then passing the built object into
> the libcamera.so build.
> 
> Now that it has its own distinct libcamera-hal.so, simplify the CrOS
> integration to build directly into that library.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  src/android/cros/meson.build | 11 +++--------
>  src/android/meson.build      | 13 +++----------
>  2 files changed, 6 insertions(+), 18 deletions(-)
> 
> diff --git a/src/android/cros/meson.build b/src/android/cros/meson.build
> index c2bda70838e2..35995dd814a2 100644
> --- a/src/android/cros/meson.build
> +++ b/src/android/cros/meson.build
> @@ -4,15 +4,10 @@ if get_option('android_platform') != 'cros'
>     subdir_done()
>  endif
>  
> -cros_hal_info_sources = files([
> +android_hal_sources += files([
>      'camera3_hal.cpp',
>  ])
>  
> -cros_hal_info = static_library('cros_hal_info',
> -                               cros_hal_info_sources,
> -                               dependencies : dependency('libcros_camera'),
> -                               c_args : '-Wno-shadow',
> -                               include_directories : [android_includes,
> -                                                      libcamera_includes])
> +android_deps += dependency('libcros_camera')
>  
> -android_objects += cros_hal_info.extract_objects('camera3_hal.cpp')
> +android_cpp_args += ['-DOS_CHROMEOS']
> diff --git a/src/android/meson.build b/src/android/meson.build
> index feda3e0998bd..bd58ef964c2a 100644
> --- a/src/android/meson.build
> +++ b/src/android/meson.build
> @@ -37,15 +37,6 @@ endif
>  
>  android_deps += [libyuv_dep]
>  
> -android_cpp_args = []
> -android_objects = []
> -
> -if get_option('android_platform') == 'cros'
> -    android_cpp_args += ['-DOS_CHROMEOS']
> -endif
> -
> -subdir('cros')
> -
>  android_hal_sources = files([
>      'camera3_hal.cpp',
>      'camera_capabilities.cpp',
> @@ -63,6 +54,9 @@ android_hal_sources = files([
>      'yuv/post_processor_yuv.cpp'
>  ])
>  
> +android_cpp_args = []
> +
> +subdir('cros')
>  subdir('mm')
>  
>  android_camera_metadata_sources = files([
> @@ -80,6 +74,5 @@ libcamera_hal = shared_library('libcamera-hal',
>                                 link_with : android_camera_metadata,
>                                 install : true,
>                                 cpp_args : android_cpp_args,
> -                               objects : android_objects,
>                                 include_directories : android_includes,
>                                 dependencies : android_deps)
Laurent Pinchart June 25, 2021, 3:18 a.m. UTC | #13
Hi Kieran,

Thank you for the patch.

On Fri, Jun 25, 2021 at 02:35:26AM +0100, Kieran Bingham wrote:
> The pkg-config file for the main libcamera.so is generated
> at the top level meson.build.
> 
> Move this to the actual core libcamera build structure to be
> consistent and keep it next to the library construction.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  meson.build               | 8 --------
>  src/libcamera/meson.build | 8 ++++++++
>  2 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/meson.build b/meson.build
> index 4d7d936f09e2..6eed0d8c4a44 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -164,14 +164,6 @@ run_command('ln', '-fsT', meson.source_root(), meson.build_root() / 'source')
>  
>  configure_file(output : 'config.h', configuration : config_h)
>  
> -pkg_mod = import('pkgconfig')
> -pkg_mod.generate(libraries : libcamera,
> -                 version : '1.0',
> -                 name : 'libcamera',
> -                 filebase : 'camera',
> -                 description : 'Complex Camera Support Library',
> -                 subdirs : 'libcamera')
> -
>  # Check for python installation and modules.
>  py_mod = import('python')
>  py_mod.find_installation('python3', modules: py_modules)
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> index d9b5bfae69fd..e4c60e736697 100644
> --- a/src/libcamera/meson.build
> +++ b/src/libcamera/meson.build
> @@ -156,4 +156,12 @@ libcamera_dep = declare_dependency(sources : [
>                                     include_directories : libcamera_includes,
>                                     link_with : libcamera)
>  
> +pkg_mod = import('pkgconfig')
> +pkg_mod.generate(libraries: libcamera,
> +                 version : '1.0',
> +                 name : 'libcamera',
> +                 filebase : 'camera',
> +                 description : 'Complex Camera Support Library',
> +                 subdirs : 'libcamera')
> +
>  subdir('proxy/worker')
Laurent Pinchart June 25, 2021, 3:20 a.m. UTC | #14
On Fri, Jun 25, 2021 at 06:18:31AM +0300, Laurent Pinchart wrote:
> Hi Kieran,
> 
> Thank you for the patch.
> 
> On Fri, Jun 25, 2021 at 02:35:25AM +0100, Kieran Bingham wrote:
> > The ChromeOS specific Android HAL support was overly-complex to support
> > linking an additional library, and then passing the built object into
> > the libcamera.so build.
> > 
> > Now that it has its own distinct libcamera-hal.so, simplify the CrOS
> > integration to build directly into that library.
> > 
> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> > ---
> >  src/android/cros/meson.build | 11 +++--------
> >  src/android/meson.build      | 13 +++----------
> >  2 files changed, 6 insertions(+), 18 deletions(-)
> > 
> > diff --git a/src/android/cros/meson.build b/src/android/cros/meson.build
> > index c2bda70838e2..35995dd814a2 100644
> > --- a/src/android/cros/meson.build
> > +++ b/src/android/cros/meson.build
> > @@ -4,15 +4,10 @@ if get_option('android_platform') != 'cros'
> >     subdir_done()
> >  endif
> >  
> > -cros_hal_info_sources = files([
> > +android_hal_sources += files([
> >      'camera3_hal.cpp',
> >  ])
> >  
> > -cros_hal_info = static_library('cros_hal_info',
> > -                               cros_hal_info_sources,
> > -                               dependencies : dependency('libcros_camera'),
> > -                               c_args : '-Wno-shadow',

BTW, we're losing -Wno-shadow. I suppose that's fine as there's no .c
file, but have you compiled this on CrOS to ensure there's no breakage ?

> > -                               include_directories : [android_includes,
> > -                                                      libcamera_includes])
> > +android_deps += dependency('libcros_camera')
> >  
> > -android_objects += cros_hal_info.extract_objects('camera3_hal.cpp')
> > +android_cpp_args += ['-DOS_CHROMEOS']
> > diff --git a/src/android/meson.build b/src/android/meson.build
> > index feda3e0998bd..bd58ef964c2a 100644
> > --- a/src/android/meson.build
> > +++ b/src/android/meson.build
> > @@ -37,15 +37,6 @@ endif
> >  
> >  android_deps += [libyuv_dep]
> >  
> > -android_cpp_args = []
> > -android_objects = []
> > -
> > -if get_option('android_platform') == 'cros'
> > -    android_cpp_args += ['-DOS_CHROMEOS']
> > -endif
> > -
> > -subdir('cros')
> > -
> >  android_hal_sources = files([
> >      'camera3_hal.cpp',
> >      'camera_capabilities.cpp',
> > @@ -63,6 +54,9 @@ android_hal_sources = files([
> >      'yuv/post_processor_yuv.cpp'
> >  ])
> >  
> > +android_cpp_args = []
> > +
> > +subdir('cros')
> >  subdir('mm')
> >  
> >  android_camera_metadata_sources = files([
> > @@ -80,6 +74,5 @@ libcamera_hal = shared_library('libcamera-hal',
> >                                 link_with : android_camera_metadata,
> >                                 install : true,
> >                                 cpp_args : android_cpp_args,
> > -                               objects : android_objects,
> >                                 include_directories : android_includes,
> >                                 dependencies : android_deps)
Hirokazu Honda June 25, 2021, 3:22 a.m. UTC | #15
Hi Kieran, thank you for the patch.

On Fri, Jun 25, 2021 at 10:35 AM Kieran Bingham
<kieran.bingham@ideasonboard.com> wrote:
>
> The libcameraSourcePath and libcameraBuildPath helper functions are
> internal and specific to libcamera needs while operating with the meson
> build system.
>
> In preparation for the upcoming move of utils to a common library, move
> these helpers out of utils and into their own build unit.
>
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  include/libcamera/internal/meson.build    |   1 +
>  include/libcamera/internal/source-paths.h |  19 ++++
>  src/libcamera/meson.build                 |   1 +
>  src/libcamera/source-paths.cpp            | 129 ++++++++++++++++++++++
>  src/libcamera/utils.cpp                   | 102 -----------------
>  5 files changed, 150 insertions(+), 102 deletions(-)
>  create mode 100644 include/libcamera/internal/source-paths.h
>  create mode 100644 src/libcamera/source-paths.cpp
>
> diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build
> index f019cfb3b0de..e5088177fe8e 100644
> --- a/include/libcamera/internal/meson.build
> +++ b/include/libcamera/internal/meson.build
> @@ -39,6 +39,7 @@ libcamera_internal_headers = files([
>      'process.h',
>      'pub_key.h',
>      'semaphore.h',
> +    'source-paths.h',

According to coding style guide
(https://libcamera.org/coding-style.html), there is no rule about a
file name.
But it seems like we use the snake case for file names. So,
source_paths.h and source_paths.cpp?

>      'sysfs.h',
>      'thread.h',
>      'timer.h',
> diff --git a/include/libcamera/internal/source-paths.h b/include/libcamera/internal/source-paths.h
> new file mode 100644
> index 000000000000..2591ebb1081b
> --- /dev/null
> +++ b/include/libcamera/internal/source-paths.h
> @@ -0,0 +1,19 @@
> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
> +/*
> + * Copyright (C) 2021, Google Inc.
> + *
> + * source-paths.h - Identify libcamera source and build paths
> + */
> +#ifndef __LIBCAMERA_INTERNAL_SOURCE_PATHS_H__
> +#define __LIBCAMERA_INTERNAL_SOURCE_PATHS_H__
> +
> +#include <string>
> +
> +namespace libcamera::utils {
> +
> +std::string libcameraBuildPath();
> +std::string libcameraSourcePath();
> +
> +} /* namespace libcamera::utils */
> +
> +#endif /* __LIBCAMERA_INTERNAL_SOURCE_PATHS_H__ */
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> index 387d20843203..e792094f5798 100644
> --- a/src/libcamera/meson.build
> +++ b/src/libcamera/meson.build
> @@ -46,6 +46,7 @@ libcamera_sources = files([
>      'request.cpp',
>      'semaphore.cpp',
>      'signal.cpp',
> +    'source-paths.cpp',
>      'stream.cpp',
>      'sysfs.cpp',
>      'thread.cpp',
> diff --git a/src/libcamera/source-paths.cpp b/src/libcamera/source-paths.cpp
> new file mode 100644
> index 000000000000..b39f5f853e39
> --- /dev/null
> +++ b/src/libcamera/source-paths.cpp
> @@ -0,0 +1,129 @@
> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
> +/*
> + * Copyright (C) 2021, Google Inc.
> + *
> + * source-paths.cpp - Identify libcamera source and build paths
> + */
> +
> +#include "libcamera/internal/source-paths.h"
> +
> +#include <dlfcn.h>
> +#include <elf.h>
> +#include <link.h>
> +#include <sys/stat.h>
> +
> +#include "libcamera/internal/utils.h"
> +
> +/**
> + * \file source-paths.h
> + * \brief Identify the build and source path of a not-yet-installed library
> + */
> +
> +/* musl doesn't declare _DYNAMIC in link.h, declare it manually. */
> +extern ElfW(Dyn) _DYNAMIC[];
> +
> +namespace libcamera::utils {
> +
> +/**
> + * \brief Check if libcamera is installed or not
> + *
> + * Utilise the build_rpath dynamic tag which is stripped out by meson at
> + * install time to determine at runtime if the library currently executing
> + * has been installed or not.
> + *
> + * \return True if libcamera is installed, false otherwise
> + */
> +bool isLibcameraInstalled()
> +{
> +       /*
> +        * DT_RUNPATH (DT_RPATH when the linker uses old dtags) is removed on
> +        * install.
> +        */
> +       for (const ElfW(Dyn) *dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn) {
> +               if (dyn->d_tag == DT_RUNPATH || dyn->d_tag == DT_RPATH)
> +                       return false;
> +       }
> +
> +       return true;
> +}
> +

isLIbcameraInstalled() should be put in anonymous namespace as it is
used only in .cc file.

With these nits,
Reviewed-by: Hirokazu Honda<hiroh@chromium.org>
> +/**
> + * \brief Retrieve the path to the build directory
> + *
> + * During development, it is useful to run libcamera binaries directly from the
> + * build directory without installing them. This function helps components that
> + * need to locate resources in the build tree, such as IPA modules or IPA proxy
> + * workers, by providing them with the path to the root of the build directory.
> + * Callers can then use it to complement or override searches in system-wide
> + * directories.
> + *
> + * If libcamera has been installed, the build directory path is not available
> + * and this function returns an empty string.
> + *
> + * \return The path to the build directory if running from a build, or an empty
> + * string otherwise
> + */
> +std::string libcameraBuildPath()
> +{
> +       if (isLibcameraInstalled())
> +               return std::string();
> +
> +       Dl_info info;
> +
> +       /* Look up our own symbol. */
> +       int ret = dladdr(reinterpret_cast<void *>(libcameraBuildPath), &info);
> +       if (ret == 0)
> +               return std::string();
> +
> +       std::string path = dirname(info.dli_fname) + "/../../";
> +
> +       char *real = realpath(path.c_str(), nullptr);
> +       if (!real)
> +               return std::string();
> +
> +       path = real;
> +       free(real);
> +
> +       return path + "/";
> +}
> +
> +/**
> + * \brief Retrieve the path to the source directory
> + *
> + * During development, it is useful to run libcamera binaries directly from the
> + * build directory without installing them. This function helps components that
> + * need to locate resources in the source tree, such as IPA configuration
> + * files, by providing them with the path to the root of the source directory.
> + * Callers can then use it to complement or override searches in system-wide
> + * directories.
> + *
> + * If libcamera has been installed, the source directory path is not available
> + * and this function returns an empty string.
> + *
> + * \return The path to the source directory if running from a build directory,
> + * or an empty string otherwise
> + */
> +std::string libcameraSourcePath()
> +{
> +       std::string path = libcameraBuildPath();
> +       if (path.empty())
> +               return std::string();
> +
> +       path += "source";
> +
> +       char *real = realpath(path.c_str(), nullptr);
> +       if (!real)
> +               return std::string();
> +
> +       path = real;
> +       free(real);
> +
> +       struct stat statbuf;
> +       int ret = stat(path.c_str(), &statbuf);
> +       if (ret < 0 || (statbuf.st_mode & S_IFMT) != S_IFDIR)
> +               return std::string();
> +
> +       return path + "/";
> +}
> +
> +} /* namespace libcamera::utils */
> diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp
> index 49b8fc9e211f..42f82d6158dd 100644
> --- a/src/libcamera/utils.cpp
> +++ b/src/libcamera/utils.cpp
> @@ -351,108 +351,6 @@ std::string toAscii(const std::string &str)
>         return ret;
>  }
>
> -/**
> - * \brief Check if libcamera is installed or not
> - *
> - * Utilise the build_rpath dynamic tag which is stripped out by meson at
> - * install time to determine at runtime if the library currently executing
> - * has been installed or not.
> - *
> - * \return True if libcamera is installed, false otherwise
> - */
> -bool isLibcameraInstalled()
> -{
> -       /*
> -        * DT_RUNPATH (DT_RPATH when the linker uses old dtags) is removed on
> -        * install.
> -        */
> -       for (const ElfW(Dyn) *dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn) {
> -               if (dyn->d_tag == DT_RUNPATH || dyn->d_tag == DT_RPATH)
> -                       return false;
> -       }
> -
> -       return true;
> -}
> -
> -/**
> - * \brief Retrieve the path to the build directory
> - *
> - * During development, it is useful to run libcamera binaries directly from the
> - * build directory without installing them. This function helps components that
> - * need to locate resources in the build tree, such as IPA modules or IPA proxy
> - * workers, by providing them with the path to the root of the build directory.
> - * Callers can then use it to complement or override searches in system-wide
> - * directories.
> - *
> - * If libcamera has been installed, the build directory path is not available
> - * and this function returns an empty string.
> - *
> - * \return The path to the build directory if running from a build, or an empty
> - * string otherwise
> - */
> -std::string libcameraBuildPath()
> -{
> -       if (isLibcameraInstalled())
> -               return std::string();
> -
> -       Dl_info info;
> -
> -       /* Look up our own symbol. */
> -       int ret = dladdr(reinterpret_cast<void *>(libcameraBuildPath), &info);
> -       if (ret == 0)
> -               return std::string();
> -
> -       std::string path = dirname(info.dli_fname) + "/../../";
> -
> -       char *real = realpath(path.c_str(), nullptr);
> -       if (!real)
> -               return std::string();
> -
> -       path = real;
> -       free(real);
> -
> -       return path + "/";
> -}
> -
> -/**
> - * \brief Retrieve the path to the source directory
> - *
> - * During development, it is useful to run libcamera binaries directly from the
> - * build directory without installing them. This function helps components that
> - * need to locate resources in the source tree, such as IPA configuration
> - * files, by providing them with the path to the root of the source directory.
> - * Callers can then use it to complement or override searches in system-wide
> - * directories.
> - *
> - * If libcamera has been installed, the source directory path is not available
> - * and this function returns an empty string.
> - *
> - * \return The path to the source directory if running from a build directory,
> - * or an empty string otherwise
> - */
> -std::string libcameraSourcePath()
> -{
> -       std::string path = libcameraBuildPath();
> -       if (path.empty())
> -               return std::string();
> -
> -       path += "source";
> -
> -       char *real = realpath(path.c_str(), nullptr);
> -       if (!real)
> -               return std::string();
> -
> -       path = real;
> -       free(real);
> -
> -       struct stat statbuf;
> -       int ret = stat(path.c_str(), &statbuf);
> -       if (ret < 0 || (statbuf.st_mode & S_IFMT) != S_IFDIR)
> -               return std::string();
> -
> -       return path + "/";
> -}
> -
>  /**
>   * \fn alignDown(unsigned int value, unsigned int alignment)
>   * \brief Align \a value down to \a alignment
> --
> 2.30.2
>
Hirokazu Honda June 25, 2021, 3:32 a.m. UTC | #16
Hi Kieran, thank you for the patch.

On Fri, Jun 25, 2021 at 10:35 AM Kieran Bingham
<kieran.bingham@ideasonboard.com> wrote:
>
> The libcamera-base.so will feature internal support functionality
> that is utilised by libcamera, and can be shared in other places.
>
> This new library provides a layer beneath libcamera which provides
> common abstractions to internal objects.
>
> A pkg-config file is generated and named libcamera-base.pc which allows
> components such as external IPA modules to link directly to this library
> if they need. Normal applications will reference this library through
> the Requires: statement provided by the libcamera.pc package
> configuration, and linkage will be handled automatically through the
> pkg-config mechanisms.
>

I would comment that this patch doesn't move anything to libcamera-base.so.

> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  Documentation/meson.build          |  2 ++
>  include/libcamera/base/meson.build |  9 +++++++++
>  include/libcamera/meson.build      |  1 +
>  src/libcamera/base/meson.build     | 27 +++++++++++++++++++++++++++
>  src/libcamera/meson.build          |  4 ++++
>  5 files changed, 43 insertions(+)
>  create mode 100644 include/libcamera/base/meson.build
>  create mode 100644 src/libcamera/base/meson.build
>
> diff --git a/Documentation/meson.build b/Documentation/meson.build
> index 9ecf4dfcf79f..808076e056d0 100644
> --- a/Documentation/meson.build
> +++ b/Documentation/meson.build
> @@ -27,6 +27,8 @@ if doxygen.found() and dot.found()
>                        libcamera_ipa_interfaces,
>                        libcamera_public_headers,
>                        libcamera_sources,
> +                      libcamera_base_headers,
> +                      libcamera_base_sources,
>                        libipa_headers,
>                        libipa_sources,
>                    ],
> diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build
> new file mode 100644
> index 000000000000..0a7a57b81191
> --- /dev/null
> +++ b/include/libcamera/base/meson.build
> @@ -0,0 +1,9 @@
> +# SPDX-License-Identifier: CC0-1.0
> +
> +libcamera_base_include_dir = libcamera_include_dir / 'base'
> +
> +libcamera_base_headers = files([
> +])
> +
> +install_headers(libcamera_base_headers,
> +                subdir: libcamera_base_include_dir)
> diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build
> index 086c958b0a53..1fa1bf4a4e78 100644
> --- a/include/libcamera/meson.build
> +++ b/include/libcamera/meson.build
> @@ -25,6 +25,7 @@ include_dir = libcamera_include_dir / 'libcamera'
>
>  subdir('internal')
>  subdir('ipa')
> +subdir('base')

nit: can we put subdir('base') to before subdir ('internal'). Or base
will be dependent on internal and ipa?

Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
>
>  install_headers(libcamera_public_headers,
>                  subdir : include_dir)
> diff --git a/src/libcamera/base/meson.build b/src/libcamera/base/meson.build
> new file mode 100644
> index 000000000000..3d58fea36ef5
> --- /dev/null
> +++ b/src/libcamera/base/meson.build
> @@ -0,0 +1,27 @@
> +# SPDX-License-Identifier: CC0-1.0
> +
> +libcamera_base_sources = files([
> +])
> +
> +libcamera_base_deps = [
> +]
> +
> +libcamera_base_lib = shared_library('libcamera-base',
> +                                    [libcamera_base_sources, libcamera_base_headers],
> +                                    name_prefix : '',
> +                                    install : true,
> +                                    cpp_args : libcamera_cpp_args,
> +                                    include_directories : libcamera_includes,
> +                                    dependencies : libcamera_base_deps)
> +
> +libcamera_base = declare_dependency(sources : [
> +                                        libcamera_base_headers,
> +                                    ],
> +                                    include_directories : libcamera_includes,
> +                                    link_with : libcamera_base_lib)
> +
> +pkg_mod = import('pkgconfig')
> +pkg_mod.generate(libcamera_base_lib,
> +                 version : '1.0',
> +                 description : 'Camera support base utility library',
> +                 subdirs : 'libcamera')
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> index e792094f5798..eaf3cec8cba7 100644
> --- a/src/libcamera/meson.build
> +++ b/src/libcamera/meson.build
> @@ -67,6 +67,7 @@ includes = [
>      libcamera_includes,
>  ]
>
> +subdir('base')
>  subdir('ipa')
>  subdir('pipeline')
>  subdir('proxy')
> @@ -128,6 +129,7 @@ libcamera_deps = [
>      libgnutls,
>      liblttng,
>      libudev,
> +    libcamera_base,
>      dependency('threads'),
>  ]
>
> @@ -156,10 +158,12 @@ libcamera_dep = declare_dependency(sources : [
>                                         libcamera_generated_ipa_headers,
>                                     ],
>                                     include_directories : libcamera_includes,
> +                                   dependencies: libcamera_base,
>                                     link_with : libcamera)
>
>  pkg_mod = import('pkgconfig')
>  pkg_mod.generate(libcamera,
> +                 libraries : libcamera_base_lib,
>                   version : '1.0',
>                   description : 'Complex Camera Support Library',
>                   subdirs : 'libcamera')
> --
> 2.30.2
>
Hirokazu Honda June 25, 2021, 3:36 a.m. UTC | #17
Hi Kieran, thank you for the patch.

On Fri, Jun 25, 2021 at 10:35 AM Kieran Bingham
<kieran.bingham@ideasonboard.com> wrote:
>
> Move the utils functionality to the libcamera/base library.
>
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Hirokazu Honda <hiroh@chromium.org>

> ---
>  include/libcamera/base/meson.build                 | 1 +
>  include/libcamera/{internal => base}/utils.h       | 8 ++++----
>  include/libcamera/internal/log.h                   | 2 +-
>  include/libcamera/internal/meson.build             | 1 -
>  include/libcamera/internal/thread.h                | 3 ++-
>  src/android/camera_device.cpp                      | 3 ++-
>  src/android/jpeg/exif.cpp                          | 3 ++-
>  src/ipa/ipu3/ipu3_agc.h                            | 4 ++--
>  src/ipa/raspberrypi/cam_helper.hpp                 | 3 ++-
>  src/ipa/raspberrypi/controller/agc_algorithm.hpp   | 3 ++-
>  src/ipa/raspberrypi/controller/agc_status.h        | 2 +-
>  src/ipa/raspberrypi/controller/camera_mode.h       | 2 +-
>  src/ipa/raspberrypi/controller/device_status.h     | 2 +-
>  src/ipa/raspberrypi/controller/rpi/agc.hpp         | 2 +-
>  src/ipa/raspberrypi/controller/rpi/lux.hpp         | 2 +-
>  src/libcamera/base/meson.build                     | 2 +-
>  src/libcamera/{ => base}/utils.cpp                 | 8 ++++----
>  src/libcamera/camera_manager.cpp                   | 3 ++-
>  src/libcamera/camera_sensor.cpp                    | 3 ++-
>  src/libcamera/controls.cpp                         | 3 ++-
>  src/libcamera/event_dispatcher_poll.cpp            | 3 ++-
>  src/libcamera/ipa_manager.cpp                      | 3 ++-
>  src/libcamera/ipa_module.cpp                       | 3 ++-
>  src/libcamera/ipa_proxy.cpp                        | 3 ++-
>  src/libcamera/log.cpp                              | 3 ++-
>  src/libcamera/meson.build                          | 1 -
>  src/libcamera/object.cpp                           | 3 ++-
>  src/libcamera/pipeline/ipu3/imgu.cpp               | 3 ++-
>  src/libcamera/pipeline/ipu3/ipu3.cpp               | 3 ++-
>  src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 3 ++-
>  src/libcamera/pipeline/rkisp1/rkisp1.cpp           | 3 ++-
>  src/libcamera/pipeline/simple/converter.cpp        | 3 ++-
>  src/libcamera/pipeline/uvcvideo/uvcvideo.cpp       | 3 ++-
>  src/libcamera/pipeline/vimc/vimc.cpp               | 3 ++-
>  src/libcamera/pipeline_handler.cpp                 | 3 ++-
>  src/libcamera/process.cpp                          | 3 ++-
>  src/libcamera/source-paths.cpp                     | 2 +-
>  src/libcamera/stream.cpp                           | 3 ++-
>  src/libcamera/timer.cpp                            | 3 ++-
>  src/libcamera/v4l2_device.cpp                      | 3 ++-
>  src/libcamera/v4l2_subdevice.cpp                   | 3 ++-
>  src/v4l2/v4l2_camera_proxy.cpp                     | 3 ++-
>  src/v4l2/v4l2_compat_manager.cpp                   | 3 ++-
>  test/camera-sensor.cpp                             | 3 ++-
>  test/file-descriptor.cpp                           | 2 +-
>  test/ipc/unixsocket_ipc.cpp                        | 3 ++-
>  test/log/log_process.cpp                           | 3 ++-
>  test/pixel-format.cpp                              | 2 +-
>  test/process/process_test.cpp                      | 3 ++-
>  test/signal-threads.cpp                            | 3 ++-
>  test/utils.cpp                                     | 2 +-
>  test/v4l2_subdevice/list_formats.cpp               | 3 ++-
>  test/v4l2_videodevice/formats.cpp                  | 3 ++-
>  53 files changed, 94 insertions(+), 59 deletions(-)
>  rename include/libcamera/{internal => base}/utils.h (97%)
>  rename src/libcamera/{ => base}/utils.cpp (98%)
>
> diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build
> index 0a7a57b81191..9f0ba6b0e10c 100644
> --- a/include/libcamera/base/meson.build
> +++ b/include/libcamera/base/meson.build
> @@ -3,6 +3,7 @@
>  libcamera_base_include_dir = libcamera_include_dir / 'base'
>
>  libcamera_base_headers = files([
> +    'utils.h',
>  ])
>
>  install_headers(libcamera_base_headers,
> diff --git a/include/libcamera/internal/utils.h b/include/libcamera/base/utils.h
> similarity index 97%
> rename from include/libcamera/internal/utils.h
> rename to include/libcamera/base/utils.h
> index 15beb0f44172..d1aaff65211a 100644
> --- a/include/libcamera/internal/utils.h
> +++ b/include/libcamera/base/utils.h
> @@ -4,8 +4,8 @@
>   *
>   * utils.h - Miscellaneous utility functions
>   */
> -#ifndef __LIBCAMERA_INTERNAL_UTILS_H__
> -#define __LIBCAMERA_INTERNAL_UTILS_H__
> +#ifndef __LIBCAMERA_BASE_UTILS_H__
> +#define __LIBCAMERA_BASE_UTILS_H__
>
>  #include <algorithm>
>  #include <chrono>
> @@ -23,7 +23,7 @@
>
>  /* uClibc and uClibc-ng don't provide O_TMPFILE */
>  #ifndef O_TMPFILE
> -#define O_TMPFILE      (020000000 | O_DIRECTORY)
> +#define O_TMPFILE (020000000 | O_DIRECTORY)
>  #endif
>
>  #endif
> @@ -352,4 +352,4 @@ std::basic_ostream<CharT, Traits> &operator<<(std::basic_ostream<CharT, Traits>
>
>  } /* namespace libcamera */
>
> -#endif /* __LIBCAMERA_INTERNAL_UTILS_H__ */
> +#endif /* __LIBCAMERA_BASE_UTILS_H__ */
> diff --git a/include/libcamera/internal/log.h b/include/libcamera/internal/log.h
> index b8efb161407c..9c2beab6a33a 100644
> --- a/include/libcamera/internal/log.h
> +++ b/include/libcamera/internal/log.h
> @@ -12,7 +12,7 @@
>
>  #include <libcamera/class.h>
>
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>
>  namespace libcamera {
>
> diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build
> index e5088177fe8e..c84f9822ef6e 100644
> --- a/include/libcamera/internal/meson.build
> +++ b/include/libcamera/internal/meson.build
> @@ -43,7 +43,6 @@ libcamera_internal_headers = files([
>      'sysfs.h',
>      'thread.h',
>      'timer.h',
> -    'utils.h',
>      'v4l2_device.h',
>      'v4l2_pixelformat.h',
>      'v4l2_subdevice.h',
> diff --git a/include/libcamera/internal/thread.h b/include/libcamera/internal/thread.h
> index 25d0308d05b4..9662e28bb581 100644
> --- a/include/libcamera/internal/thread.h
> +++ b/include/libcamera/internal/thread.h
> @@ -14,8 +14,9 @@
>
>  #include <libcamera/signal.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/message.h"
> -#include "libcamera/internal/utils.h"
>
>  namespace libcamera {
>
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index 4bd125d7020a..6243c07e231e 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -20,9 +20,10 @@
>  #include <libcamera/formats.h>
>  #include <libcamera/property_ids.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/thread.h"
> -#include "libcamera/internal/utils.h"
>
>  #include "system/graphics.h"
>
> diff --git a/src/android/jpeg/exif.cpp b/src/android/jpeg/exif.cpp
> index 922086cdf6bc..747f1cfaa8ac 100644
> --- a/src/android/jpeg/exif.cpp
> +++ b/src/android/jpeg/exif.cpp
> @@ -14,8 +14,9 @@
>  #include <tuple>
>  #include <uchar.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/log.h"
> -#include "libcamera/internal/utils.h"
>
>  using namespace libcamera;
>
> diff --git a/src/ipa/ipu3/ipu3_agc.h b/src/ipa/ipu3/ipu3_agc.h
> index a5a78233cb6d..60c7a84f2d98 100644
> --- a/src/ipa/ipu3/ipu3_agc.h
> +++ b/src/ipa/ipu3/ipu3_agc.h
> @@ -12,9 +12,9 @@
>
>  #include <linux/intel-ipu3.h>
>
> -#include <libcamera/geometry.h>
> +#include <libcamera/base/utils.h>
>
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/geometry.h>
>
>  #include "libipa/algorithm.h"
>
> diff --git a/src/ipa/raspberrypi/cam_helper.hpp b/src/ipa/raspberrypi/cam_helper.hpp
> index f53f5c39b01c..221898ceb40d 100644
> --- a/src/ipa/raspberrypi/cam_helper.hpp
> +++ b/src/ipa/raspberrypi/cam_helper.hpp
> @@ -15,7 +15,8 @@
>  #include "controller/metadata.hpp"
>  #include "md_parser.hpp"
>
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/v4l2_videodevice.h"
>
>  namespace RPiController {
> diff --git a/src/ipa/raspberrypi/controller/agc_algorithm.hpp b/src/ipa/raspberrypi/controller/agc_algorithm.hpp
> index 134bbcda50ce..61595ea2b006 100644
> --- a/src/ipa/raspberrypi/controller/agc_algorithm.hpp
> +++ b/src/ipa/raspberrypi/controller/agc_algorithm.hpp
> @@ -6,7 +6,8 @@
>   */
>  #pragma once
>
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
> +
>  #include "algorithm.hpp"
>
>  namespace RPiController {
> diff --git a/src/ipa/raspberrypi/controller/agc_status.h b/src/ipa/raspberrypi/controller/agc_status.h
> index 5d50e177f0dc..20cb1b624b33 100644
> --- a/src/ipa/raspberrypi/controller/agc_status.h
> +++ b/src/ipa/raspberrypi/controller/agc_status.h
> @@ -6,7 +6,7 @@
>   */
>  #pragma once
>
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>
>  // The AGC algorithm should post the following structure into the image's
>  // "agc.status" metadata.
> diff --git a/src/ipa/raspberrypi/controller/camera_mode.h b/src/ipa/raspberrypi/controller/camera_mode.h
> index 2aa2335dcf90..6588823020e3 100644
> --- a/src/ipa/raspberrypi/controller/camera_mode.h
> +++ b/src/ipa/raspberrypi/controller/camera_mode.h
> @@ -8,7 +8,7 @@
>
>  #include <libcamera/transform.h>
>
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>
>  // Description of a "camera mode", holding enough information for control
>  // algorithms to adapt their behaviour to the different modes of the camera,
> diff --git a/src/ipa/raspberrypi/controller/device_status.h b/src/ipa/raspberrypi/controller/device_status.h
> index 131b4cd344ee..f74235248b12 100644
> --- a/src/ipa/raspberrypi/controller/device_status.h
> +++ b/src/ipa/raspberrypi/controller/device_status.h
> @@ -6,7 +6,7 @@
>   */
>  #pragma once
>
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>
>  // Definition of "device metadata" which stores things like shutter time and
>  // analogue gain that downstream control algorithms will want to know.
> diff --git a/src/ipa/raspberrypi/controller/rpi/agc.hpp b/src/ipa/raspberrypi/controller/rpi/agc.hpp
> index 750789482b49..85067dc64614 100644
> --- a/src/ipa/raspberrypi/controller/rpi/agc.hpp
> +++ b/src/ipa/raspberrypi/controller/rpi/agc.hpp
> @@ -9,7 +9,7 @@
>  #include <vector>
>  #include <mutex>
>
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>
>  #include "../agc_algorithm.hpp"
>  #include "../agc_status.h"
> diff --git a/src/ipa/raspberrypi/controller/rpi/lux.hpp b/src/ipa/raspberrypi/controller/rpi/lux.hpp
> index 45c844393e62..3ebd35d1e382 100644
> --- a/src/ipa/raspberrypi/controller/rpi/lux.hpp
> +++ b/src/ipa/raspberrypi/controller/rpi/lux.hpp
> @@ -8,7 +8,7 @@
>
>  #include <mutex>
>
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>
>  #include "../lux_status.h"
>  #include "../algorithm.hpp"
> diff --git a/src/libcamera/base/meson.build b/src/libcamera/base/meson.build
> index 3d58fea36ef5..6d9ec37414f8 100644
> --- a/src/libcamera/base/meson.build
> +++ b/src/libcamera/base/meson.build
> @@ -1,6 +1,7 @@
>  # SPDX-License-Identifier: CC0-1.0
>
>  libcamera_base_sources = files([
> +    'utils.cpp',
>  ])
>
>  libcamera_base_deps = [
> @@ -10,7 +11,6 @@ libcamera_base_lib = shared_library('libcamera-base',
>                                      [libcamera_base_sources, libcamera_base_headers],
>                                      name_prefix : '',
>                                      install : true,
> -                                    cpp_args : libcamera_cpp_args,
>                                      include_directories : libcamera_includes,
>                                      dependencies : libcamera_base_deps)
>
> diff --git a/src/libcamera/utils.cpp b/src/libcamera/base/utils.cpp
> similarity index 98%
> rename from src/libcamera/utils.cpp
> rename to src/libcamera/base/utils.cpp
> index 42f82d6158dd..d0c0a93980b1 100644
> --- a/src/libcamera/utils.cpp
> +++ b/src/libcamera/base/utils.cpp
> @@ -5,7 +5,7 @@
>   * utils.cpp - Miscellaneous utility functions
>   */
>
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>
>  #include <dlfcn.h>
>  #include <elf.h>
> @@ -20,7 +20,7 @@
>  #include <unistd.h>
>
>  /**
> - * \file utils.h
> + * \file base/utils.h
>   * \brief Miscellaneous utility functions
>   */
>
> @@ -44,8 +44,8 @@ namespace utils {
>   */
>  const char *basename(const char *path)
>  {
> -       const char *base = strrchr(path, '/');
> -       return base ? base + 1 : path;
> +       const char *base = strrchr(path, '/');
> +       return base ? base + 1 : path;
>  }
>
>  /**
> diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp
> index 1ecf2b07d5a3..a3784db6e697 100644
> --- a/src/libcamera/camera_manager.cpp
> +++ b/src/libcamera/camera_manager.cpp
> @@ -12,13 +12,14 @@
>
>  #include <libcamera/camera.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/device_enumerator.h"
>  #include "libcamera/internal/ipa_manager.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/pipeline_handler.h"
>  #include "libcamera/internal/process.h"
>  #include "libcamera/internal/thread.h"
> -#include "libcamera/internal/utils.h"
>
>  /**
>   * \file camera_manager.h
> diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp
> index 3e135353f1d7..94dcf4f9cf48 100644
> --- a/src/libcamera/camera_sensor.cpp
> +++ b/src/libcamera/camera_sensor.cpp
> @@ -18,11 +18,12 @@
>
>  #include <libcamera/property_ids.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/bayer_format.h"
>  #include "libcamera/internal/camera_sensor_properties.h"
>  #include "libcamera/internal/formats.h"
>  #include "libcamera/internal/sysfs.h"
> -#include "libcamera/internal/utils.h"
>
>  /**
>   * \file camera_sensor.h
> diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
> index 5aef4e7145bd..7df372ad3b6c 100644
> --- a/src/libcamera/controls.cpp
> +++ b/src/libcamera/controls.cpp
> @@ -12,9 +12,10 @@
>  #include <string>
>  #include <string.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/control_validator.h"
>  #include "libcamera/internal/log.h"
> -#include "libcamera/internal/utils.h"
>
>  /**
>   * \file controls.h
> diff --git a/src/libcamera/event_dispatcher_poll.cpp b/src/libcamera/event_dispatcher_poll.cpp
> index 456c6def075b..0b6aee187063 100644
> --- a/src/libcamera/event_dispatcher_poll.cpp
> +++ b/src/libcamera/event_dispatcher_poll.cpp
> @@ -16,11 +16,12 @@
>  #include <sys/eventfd.h>
>  #include <unistd.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/event_notifier.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/thread.h"
>  #include "libcamera/internal/timer.h"
> -#include "libcamera/internal/utils.h"
>
>  /**
>   * \file event_dispatcher_poll.h
> diff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp
> index 93d02d947c46..263cacd64737 100644
> --- a/src/libcamera/ipa_manager.cpp
> +++ b/src/libcamera/ipa_manager.cpp
> @@ -12,12 +12,13 @@
>  #include <string.h>
>  #include <sys/types.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/file.h"
>  #include "libcamera/internal/ipa_module.h"
>  #include "libcamera/internal/ipa_proxy.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/pipeline_handler.h"
> -#include "libcamera/internal/utils.h"
>
>  /**
>   * \file ipa_manager.h
> diff --git a/src/libcamera/ipa_module.cpp b/src/libcamera/ipa_module.cpp
> index f53e529b0380..a4e7fb861138 100644
> --- a/src/libcamera/ipa_module.cpp
> +++ b/src/libcamera/ipa_module.cpp
> @@ -23,10 +23,11 @@
>
>  #include <libcamera/span.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/file.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/pipeline_handler.h"
> -#include "libcamera/internal/utils.h"
>
>  /**
>   * \file ipa_module.h
> diff --git a/src/libcamera/ipa_proxy.cpp b/src/libcamera/ipa_proxy.cpp
> index b70fde581eeb..ca980ec705a6 100644
> --- a/src/libcamera/ipa_proxy.cpp
> +++ b/src/libcamera/ipa_proxy.cpp
> @@ -12,9 +12,10 @@
>  #include <sys/types.h>
>  #include <unistd.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/ipa_module.h"
>  #include "libcamera/internal/log.h"
> -#include "libcamera/internal/utils.h"
>
>  /**
>   * \file ipa_proxy.h
> diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp
> index 74829a56916e..5ff0e9017648 100644
> --- a/src/libcamera/log.cpp
> +++ b/src/libcamera/log.cpp
> @@ -23,8 +23,9 @@
>
>  #include <libcamera/logging.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/thread.h"
> -#include "libcamera/internal/utils.h"
>
>  /**
>   * \file log.h
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> index eaf3cec8cba7..ac401c25d498 100644
> --- a/src/libcamera/meson.build
> +++ b/src/libcamera/meson.build
> @@ -52,7 +52,6 @@ libcamera_sources = files([
>      'thread.cpp',
>      'timer.cpp',
>      'transform.cpp',
> -    'utils.cpp',
>      'v4l2_device.cpp',
>      'v4l2_pixelformat.cpp',
>      'v4l2_subdevice.cpp',
> diff --git a/src/libcamera/object.cpp b/src/libcamera/object.cpp
> index 5e6b73f9af84..51cac64ea313 100644
> --- a/src/libcamera/object.cpp
> +++ b/src/libcamera/object.cpp
> @@ -11,11 +11,12 @@
>
>  #include <libcamera/signal.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/message.h"
>  #include "libcamera/internal/semaphore.h"
>  #include "libcamera/internal/thread.h"
> -#include "libcamera/internal/utils.h"
>
>  /**
>   * \file object.h
> diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp
> index 4eb3f7b730a9..32d143a862b2 100644
> --- a/src/libcamera/pipeline/ipu3/imgu.cpp
> +++ b/src/libcamera/pipeline/ipu3/imgu.cpp
> @@ -16,9 +16,10 @@
>  #include <libcamera/formats.h>
>  #include <libcamera/stream.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/media_device.h"
> -#include "libcamera/internal/utils.h"
>
>  namespace libcamera {
>
> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
> index 6c93bc6d161d..6b43ad2fb2b1 100644
> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp
> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
> @@ -20,6 +20,8 @@
>  #include <libcamera/request.h>
>  #include <libcamera/stream.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/camera_sensor.h"
>  #include "libcamera/internal/delayed_controls.h"
>  #include "libcamera/internal/device_enumerator.h"
> @@ -27,7 +29,6 @@
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/media_device.h"
>  #include "libcamera/internal/pipeline_handler.h"
> -#include "libcamera/internal/utils.h"
>
>  #include "cio2.h"
>  #include "frames.h"
> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> index 4e26a1930228..082eb1ee1c23 100644
> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> @@ -24,6 +24,8 @@
>  #include <libcamera/property_ids.h>
>  #include <libcamera/request.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include <linux/bcm2835-isp.h>
>  #include <linux/videodev2.h>
>
> @@ -35,7 +37,6 @@
>  #include "libcamera/internal/ipa_manager.h"
>  #include "libcamera/internal/media_device.h"
>  #include "libcamera/internal/pipeline_handler.h"
> -#include "libcamera/internal/utils.h"
>  #include "libcamera/internal/v4l2_videodevice.h"
>
>  #include "dma_heaps.h"
> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
> index 6699839c4623..c625d7248f5c 100644
> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp
> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
> @@ -24,6 +24,8 @@
>  #include <libcamera/request.h>
>  #include <libcamera/stream.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/camera_sensor.h"
>  #include "libcamera/internal/delayed_controls.h"
>  #include "libcamera/internal/device_enumerator.h"
> @@ -31,7 +33,6 @@
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/media_device.h"
>  #include "libcamera/internal/pipeline_handler.h"
> -#include "libcamera/internal/utils.h"
>  #include "libcamera/internal/v4l2_subdevice.h"
>  #include "libcamera/internal/v4l2_videodevice.h"
>
> diff --git a/src/libcamera/pipeline/simple/converter.cpp b/src/libcamera/pipeline/simple/converter.cpp
> index 68644ef6477f..589f185b1bf1 100644
> --- a/src/libcamera/pipeline/simple/converter.cpp
> +++ b/src/libcamera/pipeline/simple/converter.cpp
> @@ -15,9 +15,10 @@
>  #include <libcamera/signal.h>
>  #include <libcamera/stream.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/media_device.h"
> -#include "libcamera/internal/utils.h"
>  #include "libcamera/internal/v4l2_videodevice.h"
>
>  namespace libcamera {
> diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> index 12a85b2407db..d8c17dccae53 100644
> --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> @@ -19,12 +19,13 @@
>  #include <libcamera/request.h>
>  #include <libcamera/stream.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/device_enumerator.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/media_device.h"
>  #include "libcamera/internal/pipeline_handler.h"
>  #include "libcamera/internal/sysfs.h"
> -#include "libcamera/internal/utils.h"
>  #include "libcamera/internal/v4l2_videodevice.h"
>
>  namespace libcamera {
> diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp
> index 8bbac0085c9b..025ca56205f8 100644
> --- a/src/libcamera/pipeline/vimc/vimc.cpp
> +++ b/src/libcamera/pipeline/vimc/vimc.cpp
> @@ -23,13 +23,14 @@
>  #include <libcamera/request.h>
>  #include <libcamera/stream.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/camera_sensor.h"
>  #include "libcamera/internal/device_enumerator.h"
>  #include "libcamera/internal/ipa_manager.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/media_device.h"
>  #include "libcamera/internal/pipeline_handler.h"
> -#include "libcamera/internal/utils.h"
>  #include "libcamera/internal/v4l2_subdevice.h"
>  #include "libcamera/internal/v4l2_videodevice.h"
>
> diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp
> index e507a8bba8a6..6fb2a743c3c2 100644
> --- a/src/libcamera/pipeline_handler.cpp
> +++ b/src/libcamera/pipeline_handler.cpp
> @@ -13,11 +13,12 @@
>  #include <libcamera/camera.h>
>  #include <libcamera/camera_manager.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/device_enumerator.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/media_device.h"
>  #include "libcamera/internal/tracepoints.h"
> -#include "libcamera/internal/utils.h"
>
>  /**
>   * \file pipeline_handler.h
> diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp
> index 40a434a6b0c2..35091f60c1e9 100644
> --- a/src/libcamera/process.cpp
> +++ b/src/libcamera/process.cpp
> @@ -20,9 +20,10 @@
>  #include <unistd.h>
>  #include <vector>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/event_notifier.h"
>  #include "libcamera/internal/log.h"
> -#include "libcamera/internal/utils.h"
>
>  /**
>   * \file process.h
> diff --git a/src/libcamera/source-paths.cpp b/src/libcamera/source-paths.cpp
> index b39f5f853e39..2a59105e8283 100644
> --- a/src/libcamera/source-paths.cpp
> +++ b/src/libcamera/source-paths.cpp
> @@ -12,7 +12,7 @@
>  #include <link.h>
>  #include <sys/stat.h>
>
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>
>  /**
>   * \file source-paths.h
> diff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp
> index f7bafcf8fc97..d5d68427e658 100644
> --- a/src/libcamera/stream.cpp
> +++ b/src/libcamera/stream.cpp
> @@ -15,8 +15,9 @@
>
>  #include <libcamera/request.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/log.h"
> -#include "libcamera/internal/utils.h"
>
>  /**
>   * \file stream.h
> diff --git a/src/libcamera/timer.cpp b/src/libcamera/timer.cpp
> index c242113a782e..9496671edffc 100644
> --- a/src/libcamera/timer.cpp
> +++ b/src/libcamera/timer.cpp
> @@ -11,11 +11,12 @@
>
>  #include <libcamera/camera_manager.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/event_dispatcher.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/message.h"
>  #include "libcamera/internal/thread.h"
> -#include "libcamera/internal/utils.h"
>
>  /**
>   * \file timer.h
> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
> index 5660e6ea5839..facb53e13169 100644
> --- a/src/libcamera/v4l2_device.cpp
> +++ b/src/libcamera/v4l2_device.cpp
> @@ -16,10 +16,11 @@
>  #include <sys/syscall.h>
>  #include <unistd.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/event_notifier.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/sysfs.h"
> -#include "libcamera/internal/utils.h"
>
>  /**
>   * \file v4l2_device.h
> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
> index 721ff5a92a2b..2c56cfafbce4 100644
> --- a/src/libcamera/v4l2_subdevice.cpp
> +++ b/src/libcamera/v4l2_subdevice.cpp
> @@ -19,10 +19,11 @@
>
>  #include <libcamera/geometry.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/media_device.h"
>  #include "libcamera/internal/media_object.h"
> -#include "libcamera/internal/utils.h"
>
>  /**
>   * \file v4l2_subdevice.h
> diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp
> index f8bfe595e90e..a5a25507462e 100644
> --- a/src/v4l2/v4l2_camera_proxy.cpp
> +++ b/src/v4l2/v4l2_camera_proxy.cpp
> @@ -20,9 +20,10 @@
>  #include <libcamera/formats.h>
>  #include <libcamera/object.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/formats.h"
>  #include "libcamera/internal/log.h"
> -#include "libcamera/internal/utils.h"
>
>  #include "v4l2_camera.h"
>  #include "v4l2_camera_file.h"
> diff --git a/src/v4l2/v4l2_compat_manager.cpp b/src/v4l2/v4l2_compat_manager.cpp
> index 96dbcdf28f04..27de6c50ff4e 100644
> --- a/src/v4l2/v4l2_compat_manager.cpp
> +++ b/src/v4l2/v4l2_compat_manager.cpp
> @@ -22,8 +22,9 @@
>  #include <libcamera/camera.h>
>  #include <libcamera/camera_manager.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/log.h"
> -#include "libcamera/internal/utils.h"
>
>  #include "v4l2_camera_file.h"
>
> diff --git a/test/camera-sensor.cpp b/test/camera-sensor.cpp
> index 8c7fd1d2d444..a8dcad8215e5 100644
> --- a/test/camera-sensor.cpp
> +++ b/test/camera-sensor.cpp
> @@ -10,10 +10,11 @@
>
>  #include <linux/media-bus-format.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/camera_sensor.h"
>  #include "libcamera/internal/device_enumerator.h"
>  #include "libcamera/internal/media_device.h"
> -#include "libcamera/internal/utils.h"
>  #include "libcamera/internal/v4l2_subdevice.h"
>
>  #include "test.h"
> diff --git a/test/file-descriptor.cpp b/test/file-descriptor.cpp
> index aa3c896fb937..85b077a25c32 100644
> --- a/test/file-descriptor.cpp
> +++ b/test/file-descriptor.cpp
> @@ -13,7 +13,7 @@
>
>  #include <libcamera/file_descriptor.h>
>
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>
>  #include "test.h"
>
> diff --git a/test/ipc/unixsocket_ipc.cpp b/test/ipc/unixsocket_ipc.cpp
> index 3049eaa8bb2a..161d09b98719 100644
> --- a/test/ipc/unixsocket_ipc.cpp
> +++ b/test/ipc/unixsocket_ipc.cpp
> @@ -15,6 +15,8 @@
>  #include <sys/wait.h>
>  #include <unistd.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/event_dispatcher.h"
>  #include "libcamera/internal/ipa_data_serializer.h"
>  #include "libcamera/internal/ipc_pipe.h"
> @@ -22,7 +24,6 @@
>  #include "libcamera/internal/process.h"
>  #include "libcamera/internal/thread.h"
>  #include "libcamera/internal/timer.h"
> -#include "libcamera/internal/utils.h"
>
>  #include "test.h"
>
> diff --git a/test/log/log_process.cpp b/test/log/log_process.cpp
> index c0a1a012d366..413d9207ea68 100644
> --- a/test/log/log_process.cpp
> +++ b/test/log/log_process.cpp
> @@ -16,12 +16,13 @@
>
>  #include <libcamera/logging.h>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/event_dispatcher.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/process.h"
>  #include "libcamera/internal/thread.h"
>  #include "libcamera/internal/timer.h"
> -#include "libcamera/internal/utils.h"
>
>  #include "test.h"
>
> diff --git a/test/pixel-format.cpp b/test/pixel-format.cpp
> index c4a08f468ade..0f364f833ed1 100644
> --- a/test/pixel-format.cpp
> +++ b/test/pixel-format.cpp
> @@ -10,7 +10,7 @@
>  #include <libcamera/formats.h>
>  #include <libcamera/pixel_format.h>
>
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>
>  #include "test.h"
>
> diff --git a/test/process/process_test.cpp b/test/process/process_test.cpp
> index 1279d8c17598..a5155bae3162 100644
> --- a/test/process/process_test.cpp
> +++ b/test/process/process_test.cpp
> @@ -9,11 +9,12 @@
>  #include <unistd.h>
>  #include <vector>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/event_dispatcher.h"
>  #include "libcamera/internal/process.h"
>  #include "libcamera/internal/thread.h"
>  #include "libcamera/internal/timer.h"
> -#include "libcamera/internal/utils.h"
>
>  #include "test.h"
>
> diff --git a/test/signal-threads.cpp b/test/signal-threads.cpp
> index 3c5f3792e385..8a96b5d2abb3 100644
> --- a/test/signal-threads.cpp
> +++ b/test/signal-threads.cpp
> @@ -9,9 +9,10 @@
>  #include <iostream>
>  #include <thread>
>
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/message.h"
>  #include "libcamera/internal/thread.h"
> -#include "libcamera/internal/utils.h"
>
>  #include "test.h"
>
> diff --git a/test/utils.cpp b/test/utils.cpp
> index f170ae4c2f35..9cd2cd070cb9 100644
> --- a/test/utils.cpp
> +++ b/test/utils.cpp
> @@ -14,7 +14,7 @@
>  #include <libcamera/geometry.h>
>  #include <libcamera/span.h>
>
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>
>  #include "test.h"
>
> diff --git a/test/v4l2_subdevice/list_formats.cpp b/test/v4l2_subdevice/list_formats.cpp
> index 74ec81a8560c..9cbd7b9439c3 100644
> --- a/test/v4l2_subdevice/list_formats.cpp
> +++ b/test/v4l2_subdevice/list_formats.cpp
> @@ -10,7 +10,8 @@
>
>  #include <libcamera/geometry.h>
>
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/v4l2_subdevice.h"
>
>  #include "v4l2_subdevice_test.h"
> diff --git a/test/v4l2_videodevice/formats.cpp b/test/v4l2_videodevice/formats.cpp
> index 255446fe758a..6c05262201fa 100644
> --- a/test/v4l2_videodevice/formats.cpp
> +++ b/test/v4l2_videodevice/formats.cpp
> @@ -8,7 +8,8 @@
>  #include <iostream>
>  #include <limits.h>
>
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/v4l2_videodevice.h"
>
>  #include "v4l2_videodevice_test.h"
> --
> 2.30.2
>
Hirokazu Honda June 25, 2021, 3:38 a.m. UTC | #18
Hi Kieran,

On Fri, Jun 25, 2021 at 10:35 AM Kieran Bingham
<kieran.bingham@ideasonboard.com> wrote:
>
> Move the class support infrastructure to the base library.
>
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  include/libcamera/{ => base}/class.h            | 0
>  include/libcamera/base/meson.build              | 1 +
>  include/libcamera/buffer.h                      | 3 ++-
>  include/libcamera/camera.h                      | 3 ++-
>  include/libcamera/camera_manager.h              | 3 ++-
>  include/libcamera/controls.h                    | 3 ++-
>  include/libcamera/framebuffer_allocator.h       | 2 +-
>  include/libcamera/internal/buffer.h             | 3 ++-
>  include/libcamera/internal/byte_stream_buffer.h | 3 ++-
>  include/libcamera/internal/camera_sensor.h      | 3 ++-
>  include/libcamera/internal/file.h               | 3 ++-
>  include/libcamera/internal/log.h                | 3 +--
>  include/libcamera/internal/media_object.h       | 2 +-
>  include/libcamera/internal/pipeline_handler.h   | 3 ++-
>  include/libcamera/internal/v4l2_subdevice.h     | 3 ++-
>  include/libcamera/internal/v4l2_videodevice.h   | 3 ++-
>  include/libcamera/meson.build                   | 1 -
>  include/libcamera/request.h                     | 3 ++-
>  src/android/camera_buffer.h                     | 3 ++-
>  src/android/camera_capabilities.h               | 3 ++-
>  src/android/camera_hal_config.h                 | 2 +-
>  src/libcamera/{ => base}/class.cpp              | 2 +-
>  src/libcamera/base/meson.build                  | 1 +
>  src/libcamera/meson.build                       | 1 -
>  24 files changed, 35 insertions(+), 22 deletions(-)
>  rename include/libcamera/{ => base}/class.h (100%)
>  rename src/libcamera/{ => base}/class.cpp (99%)
>
> diff --git a/include/libcamera/class.h b/include/libcamera/base/class.h
> similarity index 100%
> rename from include/libcamera/class.h
> rename to include/libcamera/base/class.h

Shall we change a header guard from __LIBCAMERA_CLASS_H__ to
__LIBCAMERA_BASE_CLASS_H__?

> diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build
> index 9f0ba6b0e10c..2db756c504c9 100644
> --- a/include/libcamera/base/meson.build
> +++ b/include/libcamera/base/meson.build
> @@ -3,6 +3,7 @@
>  libcamera_base_include_dir = libcamera_include_dir / 'base'
>
>  libcamera_base_headers = files([
> +    'class.h',
>      'utils.h',
>  ])
>
> diff --git a/include/libcamera/buffer.h b/include/libcamera/buffer.h
> index e0af00900409..323d1cba41a9 100644
> --- a/include/libcamera/buffer.h
> +++ b/include/libcamera/buffer.h
> @@ -10,7 +10,8 @@
>  #include <stdint.h>
>  #include <vector>
>
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/file_descriptor.h>
>
>  namespace libcamera {
> diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h
> index d71641805c0a..ea0914009c2b 100644
> --- a/include/libcamera/camera.h
> +++ b/include/libcamera/camera.h
> @@ -12,7 +12,8 @@
>  #include <stdint.h>
>  #include <string>
>
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/controls.h>
>  #include <libcamera/object.h>
>  #include <libcamera/request.h>
> diff --git a/include/libcamera/camera_manager.h b/include/libcamera/camera_manager.h
> index c2f0b786da8e..5deede035115 100644
> --- a/include/libcamera/camera_manager.h
> +++ b/include/libcamera/camera_manager.h
> @@ -12,7 +12,8 @@
>  #include <sys/types.h>
>  #include <vector>
>
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/object.h>
>  #include <libcamera/signal.h>
>
> diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
> index 1c9b37e617bc..f62b6cf055d6 100644
> --- a/include/libcamera/controls.h
> +++ b/include/libcamera/controls.h
> @@ -14,7 +14,8 @@
>  #include <unordered_map>
>  #include <vector>
>
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/geometry.h>
>  #include <libcamera/span.h>
>
> diff --git a/include/libcamera/framebuffer_allocator.h b/include/libcamera/framebuffer_allocator.h
> index 0c85631a1da2..cbc9ce101889 100644
> --- a/include/libcamera/framebuffer_allocator.h
> +++ b/include/libcamera/framebuffer_allocator.h
> @@ -11,7 +11,7 @@
>  #include <memory>
>  #include <vector>
>
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
>
>  namespace libcamera {
>
> diff --git a/include/libcamera/internal/buffer.h b/include/libcamera/internal/buffer.h
> index 9da1fbd12c27..91dd24969385 100644
> --- a/include/libcamera/internal/buffer.h
> +++ b/include/libcamera/internal/buffer.h
> @@ -10,7 +10,8 @@
>  #include <sys/mman.h>
>  #include <vector>
>
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/buffer.h>
>  #include <libcamera/span.h>
>
> diff --git a/include/libcamera/internal/byte_stream_buffer.h b/include/libcamera/internal/byte_stream_buffer.h
> index 866cb9b0b2a6..7eefb1a71f07 100644
> --- a/include/libcamera/internal/byte_stream_buffer.h
> +++ b/include/libcamera/internal/byte_stream_buffer.h
> @@ -11,7 +11,8 @@
>  #include <stdint.h>
>  #include <type_traits>
>
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/span.h>
>
>  namespace libcamera {
> diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h
> index e133ebf45bf7..7bc540619721 100644
> --- a/include/libcamera/internal/camera_sensor.h
> +++ b/include/libcamera/internal/camera_sensor.h
> @@ -11,7 +11,8 @@
>  #include <string>
>  #include <vector>
>
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/controls.h>
>  #include <libcamera/geometry.h>
>  #include <libcamera/ipa/core_ipa_interface.h>
> diff --git a/include/libcamera/internal/file.h b/include/libcamera/internal/file.h
> index f0b313a5faae..44621ceb4c19 100644
> --- a/include/libcamera/internal/file.h
> +++ b/include/libcamera/internal/file.h
> @@ -11,7 +11,8 @@
>  #include <string>
>  #include <sys/types.h>
>
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/span.h>
>
>  namespace libcamera {
> diff --git a/include/libcamera/internal/log.h b/include/libcamera/internal/log.h
> index 9c2beab6a33a..82e55a623e04 100644
> --- a/include/libcamera/internal/log.h
> +++ b/include/libcamera/internal/log.h
> @@ -10,8 +10,7 @@
>  #include <chrono>
>  #include <sstream>
>
> -#include <libcamera/class.h>
> -
> +#include <libcamera/base/class.h>
>  #include <libcamera/base/utils.h>
>
>  namespace libcamera {
> diff --git a/include/libcamera/internal/media_object.h b/include/libcamera/internal/media_object.h
> index 1c82c27928a8..2f5d33e1903e 100644
> --- a/include/libcamera/internal/media_object.h
> +++ b/include/libcamera/internal/media_object.h
> @@ -12,7 +12,7 @@
>
>  #include <linux/media.h>
>
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
>
>  namespace libcamera {
>
> diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h
> index 31dadf285a58..8beb6b76dd3f 100644
> --- a/include/libcamera/internal/pipeline_handler.h
> +++ b/include/libcamera/internal/pipeline_handler.h
> @@ -15,7 +15,8 @@
>  #include <sys/types.h>
>  #include <vector>
>
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/controls.h>
>  #include <libcamera/object.h>
>  #include <libcamera/stream.h>
> diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h
> index d2b9ca55439e..d07dd6b444d0 100644
> --- a/include/libcamera/internal/v4l2_subdevice.h
> +++ b/include/libcamera/internal/v4l2_subdevice.h
> @@ -11,7 +11,8 @@
>  #include <string>
>  #include <vector>
>
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/geometry.h>
>
>  #include "libcamera/internal/formats.h"
> diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h
> index 7938343bba8d..227d015e8937 100644
> --- a/include/libcamera/internal/v4l2_videodevice.h
> +++ b/include/libcamera/internal/v4l2_videodevice.h
> @@ -16,8 +16,9 @@
>
>  #include <linux/videodev2.h>
>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/buffer.h>
> -#include <libcamera/class.h>
>  #include <libcamera/geometry.h>
>  #include <libcamera/pixel_format.h>
>  #include <libcamera/signal.h>
> diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build
> index 1fa1bf4a4e78..7cba3de6ca96 100644
> --- a/include/libcamera/meson.build
> +++ b/include/libcamera/meson.build
> @@ -5,7 +5,6 @@ libcamera_public_headers = files([
>      'buffer.h',
>      'camera.h',
>      'camera_manager.h',
> -    'class.h',
>      'compiler.h',
>      'controls.h',
>      'file_descriptor.h',
> diff --git a/include/libcamera/request.h b/include/libcamera/request.h
> index 5596901ddd8e..00c646fea7f2 100644
> --- a/include/libcamera/request.h
> +++ b/include/libcamera/request.h
> @@ -13,7 +13,8 @@
>  #include <string>
>  #include <unordered_set>
>
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/controls.h>
>  #include <libcamera/signal.h>
>
> diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h
> index c88124b2b3f3..e850c4e36668 100644
> --- a/src/android/camera_buffer.h
> +++ b/src/android/camera_buffer.h
> @@ -9,7 +9,8 @@
>
>  #include <hardware/camera3.h>
>
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/span.h>
>
>  class CameraBuffer final : public libcamera::Extensible
> diff --git a/src/android/camera_capabilities.h b/src/android/camera_capabilities.h
> index f511607bbd90..4f5be82595d6 100644
> --- a/src/android/camera_capabilities.h
> +++ b/src/android/camera_capabilities.h
> @@ -11,8 +11,9 @@
>  #include <memory>
>  #include <vector>
>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/camera.h>
> -#include <libcamera/class.h>
>  #include <libcamera/formats.h>
>  #include <libcamera/geometry.h>
>
> diff --git a/src/android/camera_hal_config.h b/src/android/camera_hal_config.h
> index 97dc69c1def5..a79d5d6c42dc 100644
> --- a/src/android/camera_hal_config.h
> +++ b/src/android/camera_hal_config.h
> @@ -10,7 +10,7 @@
>  #include <map>
>  #include <string>
>
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
>
>  struct CameraConfigData {
>         int facing = -1;
> diff --git a/src/libcamera/class.cpp b/src/libcamera/base/class.cpp
> similarity index 99%
> rename from src/libcamera/class.cpp
> rename to src/libcamera/base/class.cpp
> index 28c35633d7db..165beafc243d 100644
> --- a/src/libcamera/class.cpp
> +++ b/src/libcamera/base/class.cpp
> @@ -5,7 +5,7 @@
>   * class.cpp - Utilities and helpers for classes
>   */
>
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
>
>  /**
>   * \file class.h
> diff --git a/src/libcamera/base/meson.build b/src/libcamera/base/meson.build
> index 6d9ec37414f8..302a288685d3 100644
> --- a/src/libcamera/base/meson.build
> +++ b/src/libcamera/base/meson.build
> @@ -1,6 +1,7 @@
>  # SPDX-License-Identifier: CC0-1.0
>
>  libcamera_base_sources = files([
> +    'class.cpp',
>      'utils.cpp',
>  ])
>
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> index ac401c25d498..a341004c0c19 100644
> --- a/src/libcamera/meson.build
> +++ b/src/libcamera/meson.build
> @@ -10,7 +10,6 @@ libcamera_sources = files([
>      'camera_manager.cpp',
>      'camera_sensor.cpp',
>      'camera_sensor_properties.cpp',
> -    'class.cpp',
>      'controls.cpp',
>      'control_serializer.cpp',
>      'control_validator.cpp',
> --
> 2.30.2
>
Paul Elder June 25, 2021, 3:45 a.m. UTC | #19
Hi Kieran,

On Fri, Jun 25, 2021 at 02:35:29AM +0100, Kieran Bingham wrote:
> The libcamera-base.so will feature internal support functionality
> that is utilised by libcamera, and can be shared in other places.
> 
> This new library provides a layer beneath libcamera which provides
> common abstractions to internal objects.
> 
> A pkg-config file is generated and named libcamera-base.pc which allows
> components such as external IPA modules to link directly to this library
> if they need. Normal applications will reference this library through
> the Requires: statement provided by the libcamera.pc package
> configuration, and linkage will be handled automatically through the
> pkg-config mechanisms.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
>  Documentation/meson.build          |  2 ++
>  include/libcamera/base/meson.build |  9 +++++++++
>  include/libcamera/meson.build      |  1 +
>  src/libcamera/base/meson.build     | 27 +++++++++++++++++++++++++++
>  src/libcamera/meson.build          |  4 ++++
>  5 files changed, 43 insertions(+)
>  create mode 100644 include/libcamera/base/meson.build
>  create mode 100644 src/libcamera/base/meson.build
> 
> diff --git a/Documentation/meson.build b/Documentation/meson.build
> index 9ecf4dfcf79f..808076e056d0 100644
> --- a/Documentation/meson.build
> +++ b/Documentation/meson.build
> @@ -27,6 +27,8 @@ if doxygen.found() and dot.found()
>                        libcamera_ipa_interfaces,
>                        libcamera_public_headers,
>                        libcamera_sources,
> +                      libcamera_base_headers,
> +                      libcamera_base_sources,
>                        libipa_headers,
>                        libipa_sources,
>                    ],
> diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build
> new file mode 100644
> index 000000000000..0a7a57b81191
> --- /dev/null
> +++ b/include/libcamera/base/meson.build
> @@ -0,0 +1,9 @@
> +# SPDX-License-Identifier: CC0-1.0
> +
> +libcamera_base_include_dir = libcamera_include_dir / 'base'
> +
> +libcamera_base_headers = files([
> +])
> +
> +install_headers(libcamera_base_headers,
> +                subdir: libcamera_base_include_dir)
> diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build
> index 086c958b0a53..1fa1bf4a4e78 100644
> --- a/include/libcamera/meson.build
> +++ b/include/libcamera/meson.build
> @@ -25,6 +25,7 @@ include_dir = libcamera_include_dir / 'libcamera'
>  
>  subdir('internal')
>  subdir('ipa')
> +subdir('base')
>  
>  install_headers(libcamera_public_headers,
>                  subdir : include_dir)
> diff --git a/src/libcamera/base/meson.build b/src/libcamera/base/meson.build
> new file mode 100644
> index 000000000000..3d58fea36ef5
> --- /dev/null
> +++ b/src/libcamera/base/meson.build
> @@ -0,0 +1,27 @@
> +# SPDX-License-Identifier: CC0-1.0
> +
> +libcamera_base_sources = files([
> +])
> +
> +libcamera_base_deps = [
> +]
> +
> +libcamera_base_lib = shared_library('libcamera-base',
> +                                    [libcamera_base_sources, libcamera_base_headers],
> +                                    name_prefix : '',
> +                                    install : true,
> +                                    cpp_args : libcamera_cpp_args,
> +                                    include_directories : libcamera_includes,
> +                                    dependencies : libcamera_base_deps)
> +
> +libcamera_base = declare_dependency(sources : [
> +                                        libcamera_base_headers,
> +                                    ],
> +                                    include_directories : libcamera_includes,
> +                                    link_with : libcamera_base_lib)
> +
> +pkg_mod = import('pkgconfig')
> +pkg_mod.generate(libcamera_base_lib,
> +                 version : '1.0',
> +                 description : 'Camera support base utility library',
> +                 subdirs : 'libcamera')
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> index e792094f5798..eaf3cec8cba7 100644
> --- a/src/libcamera/meson.build
> +++ b/src/libcamera/meson.build
> @@ -67,6 +67,7 @@ includes = [
>      libcamera_includes,
>  ]
>  
> +subdir('base')
>  subdir('ipa')
>  subdir('pipeline')
>  subdir('proxy')
> @@ -128,6 +129,7 @@ libcamera_deps = [
>      libgnutls,
>      liblttng,
>      libudev,
> +    libcamera_base,
>      dependency('threads'),
>  ]
>  
> @@ -156,10 +158,12 @@ libcamera_dep = declare_dependency(sources : [
>                                         libcamera_generated_ipa_headers,
>                                     ],
>                                     include_directories : libcamera_includes,
> +                                   dependencies: libcamera_base,
>                                     link_with : libcamera)
>  
>  pkg_mod = import('pkgconfig')
>  pkg_mod.generate(libcamera,
> +                 libraries : libcamera_base_lib,
>                   version : '1.0',
>                   description : 'Complex Camera Support Library',
>                   subdirs : 'libcamera')
> -- 
> 2.30.2
>
Hirokazu Honda June 25, 2021, 3:48 a.m. UTC | #20
Hi Kieran, thank you for the patch.

On Fri, Jun 25, 2021 at 10:35 AM Kieran Bingham
<kieran.bingham@ideasonboard.com> wrote:
>
> Move the event notifier, and associated header updates.
>
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  include/libcamera/{internal => base}/event_notifier.h | 0
>  include/libcamera/base/meson.build                    | 1 +
>  include/libcamera/internal/meson.build                | 1 -
>  src/libcamera/base/event_dispatcher_poll.cpp          | 3 +--
>  src/libcamera/{ => base}/event_notifier.cpp           | 6 +++---
>  src/libcamera/base/meson.build                        | 1 +
>  src/libcamera/device_enumerator_udev.cpp              | 2 +-
>  src/libcamera/ipc_unixsocket.cpp                      | 3 +--
>  src/libcamera/meson.build                             | 1 -
>  src/libcamera/process.cpp                             | 3 +--
>  src/libcamera/v4l2_device.cpp                         | 2 +-
>  src/libcamera/v4l2_videodevice.cpp                    | 2 +-
>  test/event-thread.cpp                                 | 3 +--
>  test/event.cpp                                        | 3 +--
>  test/ipa/ipa_interface_test.cpp                       | 2 +-
>  15 files changed, 14 insertions(+), 19 deletions(-)
>  rename include/libcamera/{internal => base}/event_notifier.h (100%)
>  rename src/libcamera/{ => base}/event_notifier.cpp (98%)
>
> diff --git a/include/libcamera/internal/event_notifier.h b/include/libcamera/base/event_notifier.h
> similarity index 100%

Shall we update a header guard?

> rename from include/libcamera/internal/event_notifier.h
> rename to include/libcamera/base/event_notifier.h
> diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build
> index 6fc6c138a5fd..83c664affc88 100644
> --- a/include/libcamera/base/meson.build
> +++ b/include/libcamera/base/meson.build
> @@ -7,6 +7,7 @@ libcamera_base_headers = files([
>      'class.h',
>      'event_dispatcher.h',
>      'event_dispatcher_poll.h',
> +    'event_notifier.h',
>      'file.h',
>      'log.h',
>      'message.h',
> diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build
> index b10285edac27..61af16bfe05d 100644
> --- a/include/libcamera/internal/meson.build
> +++ b/include/libcamera/internal/meson.build
> @@ -22,7 +22,6 @@ libcamera_internal_headers = files([
>      'device_enumerator.h',
>      'device_enumerator_sysfs.h',
>      'device_enumerator_udev.h',
> -    'event_notifier.h',
>      'formats.h',
>      'ipa_manager.h',
>      'ipa_module.h',
> diff --git a/src/libcamera/base/event_dispatcher_poll.cpp b/src/libcamera/base/event_dispatcher_poll.cpp
> index d76ca7fc2c32..5839373a5281 100644
> --- a/src/libcamera/base/event_dispatcher_poll.cpp
> +++ b/src/libcamera/base/event_dispatcher_poll.cpp
> @@ -16,13 +16,12 @@
>  #include <sys/eventfd.h>
>  #include <unistd.h>
>
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/log.h>
>  #include <libcamera/base/thread.h>
>  #include <libcamera/base/timer.h>
>  #include <libcamera/base/utils.h>
>
> -#include "libcamera/internal/event_notifier.h"
> -
>  /**
>   * \file base/event_dispatcher_poll.h
>   */
> diff --git a/src/libcamera/event_notifier.cpp b/src/libcamera/base/event_notifier.cpp
> similarity index 98%
> rename from src/libcamera/event_notifier.cpp
> rename to src/libcamera/base/event_notifier.cpp
> index 784016a9f907..fd93c0878c6f 100644
> --- a/src/libcamera/event_notifier.cpp
> +++ b/src/libcamera/base/event_notifier.cpp
> @@ -5,14 +5,14 @@
>   * event_notifier.cpp - File descriptor event notifier
>   */
>
> -#include "libcamera/internal/event_notifier.h"
> -
> -#include <libcamera/camera_manager.h>
> +#include <libcamera/base/event_notifier.h>
>
>  #include <libcamera/base/event_dispatcher.h>
>  #include <libcamera/base/message.h>
>  #include <libcamera/base/thread.h>
>
> +#include <libcamera/camera_manager.h>
> +
>  /**
>   * \file event_notifier.h
>   * \brief File descriptor event notifier
> diff --git a/src/libcamera/base/meson.build b/src/libcamera/base/meson.build
> index fb8ed79acd8e..a8b04cfc8a5f 100644
> --- a/src/libcamera/base/meson.build
> +++ b/src/libcamera/base/meson.build
> @@ -5,6 +5,7 @@ libcamera_base_sources = files([
>      'bound_method.cpp',
>      'event_dispatcher.cpp',
>      'event_dispatcher_poll.cpp',
> +    'event_notifier.cpp',
>      'file.cpp',
>      'log.cpp',
>      'message.cpp',
> diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp
> index 4b842773fcd6..37a2c5aa55db 100644
> --- a/src/libcamera/device_enumerator_udev.cpp
> +++ b/src/libcamera/device_enumerator_udev.cpp
> @@ -17,9 +17,9 @@
>  #include <sys/sysmacros.h>
>  #include <unistd.h>
>
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/log.h>
>
> -#include "libcamera/internal/event_notifier.h"
>  #include "libcamera/internal/media_device.h"
>
>  namespace libcamera {
> diff --git a/src/libcamera/ipc_unixsocket.cpp b/src/libcamera/ipc_unixsocket.cpp
> index 1466597077d4..f23eb783bcb5 100644
> --- a/src/libcamera/ipc_unixsocket.cpp
> +++ b/src/libcamera/ipc_unixsocket.cpp
> @@ -12,10 +12,9 @@
>  #include <sys/socket.h>
>  #include <unistd.h>
>
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/log.h>
>
> -#include "libcamera/internal/event_notifier.h"
> -
>  /**
>   * \file ipc_unixsocket.h
>   * \brief IPC mechanism based on Unix sockets
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> index 58eee14aed97..1f163cfe1225 100644
> --- a/src/libcamera/meson.build
> +++ b/src/libcamera/meson.build
> @@ -15,7 +15,6 @@ libcamera_sources = files([
>      'delayed_controls.cpp',
>      'device_enumerator.cpp',
>      'device_enumerator_sysfs.cpp',
> -    'event_notifier.cpp',
>      'file_descriptor.cpp',
>      'formats.cpp',
>      'framebuffer_allocator.cpp',
> diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp
> index 463380299a65..4fe4ad570b74 100644
> --- a/src/libcamera/process.cpp
> +++ b/src/libcamera/process.cpp
> @@ -20,11 +20,10 @@
>  #include <unistd.h>
>  #include <vector>
>
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/log.h>
>  #include <libcamera/base/utils.h>
>
> -#include "libcamera/internal/event_notifier.h"
> -
>  /**
>   * \file process.h
>   * \brief Process object
> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
> index 334b9b78b812..98d93a12a7be 100644
> --- a/src/libcamera/v4l2_device.cpp
> +++ b/src/libcamera/v4l2_device.cpp
> @@ -16,10 +16,10 @@
>  #include <sys/syscall.h>
>  #include <unistd.h>
>
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/log.h>
>  #include <libcamera/base/utils.h>
>
> -#include "libcamera/internal/event_notifier.h"
>  #include "libcamera/internal/sysfs.h"
>
>  /**
> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
> index dc23510bc5aa..3d2d99b46e4e 100644
> --- a/src/libcamera/v4l2_videodevice.cpp
> +++ b/src/libcamera/v4l2_videodevice.cpp
> @@ -21,11 +21,11 @@
>
>  #include <linux/version.h>
>
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/log.h>
>
>  #include <libcamera/file_descriptor.h>
>
> -#include "libcamera/internal/event_notifier.h"
>  #include "libcamera/internal/media_device.h"
>  #include "libcamera/internal/media_object.h"
>
> diff --git a/test/event-thread.cpp b/test/event-thread.cpp
> index 05c5d26d3611..575261664c2f 100644
> --- a/test/event-thread.cpp
> +++ b/test/event-thread.cpp
> @@ -10,11 +10,10 @@
>  #include <string.h>
>  #include <unistd.h>
>
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/thread.h>
>  #include <libcamera/base/timer.h>
>
> -#include "libcamera/internal/event_notifier.h"
> -
>  #include "test.h"
>
>  using namespace std;
> diff --git a/test/event.cpp b/test/event.cpp
> index aa79da99c286..c2274344b7f0 100644
> --- a/test/event.cpp
> +++ b/test/event.cpp
> @@ -10,11 +10,10 @@
>  #include <unistd.h>
>
>  #include <libcamera/base/event_dispatcher.h>
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/thread.h>
>  #include <libcamera/base/timer.h>
>
> -#include "libcamera/internal/event_notifier.h"
> -
>  #include "test.h"
>
>  using namespace std;
> diff --git a/test/ipa/ipa_interface_test.cpp b/test/ipa/ipa_interface_test.cpp
> index 656d86552d85..ee9f26510784 100644
> --- a/test/ipa/ipa_interface_test.cpp
> +++ b/test/ipa/ipa_interface_test.cpp
> @@ -15,11 +15,11 @@
>  #include <libcamera/ipa/vimc_ipa_proxy.h>
>
>  #include <libcamera/base/event_dispatcher.h>
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/thread.h>
>  #include <libcamera/base/timer.h>
>
>  #include "libcamera/internal/device_enumerator.h"
> -#include "libcamera/internal/event_notifier.h"
>  #include "libcamera/internal/ipa_manager.h"
>  #include "libcamera/internal/ipa_module.h"
>  #include "libcamera/internal/pipeline_handler.h"
> --
> 2.30.2
>
Paul Elder June 25, 2021, 4:10 a.m. UTC | #21
Hi Kieran,

On Fri, Jun 25, 2021 at 02:35:30AM +0100, Kieran Bingham wrote:
> Move the utils functionality to the libcamera/base library.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
>  include/libcamera/base/meson.build                 | 1 +
>  include/libcamera/{internal => base}/utils.h       | 8 ++++----
>  include/libcamera/internal/log.h                   | 2 +-
>  include/libcamera/internal/meson.build             | 1 -
>  include/libcamera/internal/thread.h                | 3 ++-
>  src/android/camera_device.cpp                      | 3 ++-
>  src/android/jpeg/exif.cpp                          | 3 ++-
>  src/ipa/ipu3/ipu3_agc.h                            | 4 ++--
>  src/ipa/raspberrypi/cam_helper.hpp                 | 3 ++-
>  src/ipa/raspberrypi/controller/agc_algorithm.hpp   | 3 ++-
>  src/ipa/raspberrypi/controller/agc_status.h        | 2 +-
>  src/ipa/raspberrypi/controller/camera_mode.h       | 2 +-
>  src/ipa/raspberrypi/controller/device_status.h     | 2 +-
>  src/ipa/raspberrypi/controller/rpi/agc.hpp         | 2 +-
>  src/ipa/raspberrypi/controller/rpi/lux.hpp         | 2 +-
>  src/libcamera/base/meson.build                     | 2 +-
>  src/libcamera/{ => base}/utils.cpp                 | 8 ++++----
>  src/libcamera/camera_manager.cpp                   | 3 ++-
>  src/libcamera/camera_sensor.cpp                    | 3 ++-
>  src/libcamera/controls.cpp                         | 3 ++-
>  src/libcamera/event_dispatcher_poll.cpp            | 3 ++-
>  src/libcamera/ipa_manager.cpp                      | 3 ++-
>  src/libcamera/ipa_module.cpp                       | 3 ++-
>  src/libcamera/ipa_proxy.cpp                        | 3 ++-
>  src/libcamera/log.cpp                              | 3 ++-
>  src/libcamera/meson.build                          | 1 -
>  src/libcamera/object.cpp                           | 3 ++-
>  src/libcamera/pipeline/ipu3/imgu.cpp               | 3 ++-
>  src/libcamera/pipeline/ipu3/ipu3.cpp               | 3 ++-
>  src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 3 ++-
>  src/libcamera/pipeline/rkisp1/rkisp1.cpp           | 3 ++-
>  src/libcamera/pipeline/simple/converter.cpp        | 3 ++-
>  src/libcamera/pipeline/uvcvideo/uvcvideo.cpp       | 3 ++-
>  src/libcamera/pipeline/vimc/vimc.cpp               | 3 ++-
>  src/libcamera/pipeline_handler.cpp                 | 3 ++-
>  src/libcamera/process.cpp                          | 3 ++-
>  src/libcamera/source-paths.cpp                     | 2 +-
>  src/libcamera/stream.cpp                           | 3 ++-
>  src/libcamera/timer.cpp                            | 3 ++-
>  src/libcamera/v4l2_device.cpp                      | 3 ++-
>  src/libcamera/v4l2_subdevice.cpp                   | 3 ++-
>  src/v4l2/v4l2_camera_proxy.cpp                     | 3 ++-
>  src/v4l2/v4l2_compat_manager.cpp                   | 3 ++-
>  test/camera-sensor.cpp                             | 3 ++-
>  test/file-descriptor.cpp                           | 2 +-
>  test/ipc/unixsocket_ipc.cpp                        | 3 ++-
>  test/log/log_process.cpp                           | 3 ++-
>  test/pixel-format.cpp                              | 2 +-
>  test/process/process_test.cpp                      | 3 ++-
>  test/signal-threads.cpp                            | 3 ++-
>  test/utils.cpp                                     | 2 +-
>  test/v4l2_subdevice/list_formats.cpp               | 3 ++-
>  test/v4l2_videodevice/formats.cpp                  | 3 ++-
>  53 files changed, 94 insertions(+), 59 deletions(-)
>  rename include/libcamera/{internal => base}/utils.h (97%)
>  rename src/libcamera/{ => base}/utils.cpp (98%)
> 
> diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build
> index 0a7a57b81191..9f0ba6b0e10c 100644
> --- a/include/libcamera/base/meson.build
> +++ b/include/libcamera/base/meson.build
> @@ -3,6 +3,7 @@
>  libcamera_base_include_dir = libcamera_include_dir / 'base'
>  
>  libcamera_base_headers = files([
> +    'utils.h',
>  ])
>  
>  install_headers(libcamera_base_headers,
> diff --git a/include/libcamera/internal/utils.h b/include/libcamera/base/utils.h
> similarity index 97%
> rename from include/libcamera/internal/utils.h
> rename to include/libcamera/base/utils.h
> index 15beb0f44172..d1aaff65211a 100644
> --- a/include/libcamera/internal/utils.h
> +++ b/include/libcamera/base/utils.h
> @@ -4,8 +4,8 @@
>   *
>   * utils.h - Miscellaneous utility functions
>   */
> -#ifndef __LIBCAMERA_INTERNAL_UTILS_H__
> -#define __LIBCAMERA_INTERNAL_UTILS_H__
> +#ifndef __LIBCAMERA_BASE_UTILS_H__
> +#define __LIBCAMERA_BASE_UTILS_H__
>  
>  #include <algorithm>
>  #include <chrono>
> @@ -23,7 +23,7 @@
>  
>  /* uClibc and uClibc-ng don't provide O_TMPFILE */
>  #ifndef O_TMPFILE
> -#define O_TMPFILE	(020000000 | O_DIRECTORY)
> +#define O_TMPFILE (020000000 | O_DIRECTORY)
>  #endif
>  
>  #endif
> @@ -352,4 +352,4 @@ std::basic_ostream<CharT, Traits> &operator<<(std::basic_ostream<CharT, Traits>
>  
>  } /* namespace libcamera */
>  
> -#endif /* __LIBCAMERA_INTERNAL_UTILS_H__ */
> +#endif /* __LIBCAMERA_BASE_UTILS_H__ */
> diff --git a/include/libcamera/internal/log.h b/include/libcamera/internal/log.h
> index b8efb161407c..9c2beab6a33a 100644
> --- a/include/libcamera/internal/log.h
> +++ b/include/libcamera/internal/log.h
> @@ -12,7 +12,7 @@
>  
>  #include <libcamera/class.h>
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>  
>  namespace libcamera {
>  
> diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build
> index e5088177fe8e..c84f9822ef6e 100644
> --- a/include/libcamera/internal/meson.build
> +++ b/include/libcamera/internal/meson.build
> @@ -43,7 +43,6 @@ libcamera_internal_headers = files([
>      'sysfs.h',
>      'thread.h',
>      'timer.h',
> -    'utils.h',
>      'v4l2_device.h',
>      'v4l2_pixelformat.h',
>      'v4l2_subdevice.h',
> diff --git a/include/libcamera/internal/thread.h b/include/libcamera/internal/thread.h
> index 25d0308d05b4..9662e28bb581 100644
> --- a/include/libcamera/internal/thread.h
> +++ b/include/libcamera/internal/thread.h
> @@ -14,8 +14,9 @@
>  
>  #include <libcamera/signal.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/message.h"
> -#include "libcamera/internal/utils.h"
>  
>  namespace libcamera {
>  
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index 4bd125d7020a..6243c07e231e 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -20,9 +20,10 @@
>  #include <libcamera/formats.h>
>  #include <libcamera/property_ids.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/thread.h"
> -#include "libcamera/internal/utils.h"
>  
>  #include "system/graphics.h"
>  
> diff --git a/src/android/jpeg/exif.cpp b/src/android/jpeg/exif.cpp
> index 922086cdf6bc..747f1cfaa8ac 100644
> --- a/src/android/jpeg/exif.cpp
> +++ b/src/android/jpeg/exif.cpp
> @@ -14,8 +14,9 @@
>  #include <tuple>
>  #include <uchar.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/log.h"
> -#include "libcamera/internal/utils.h"
>  
>  using namespace libcamera;
>  
> diff --git a/src/ipa/ipu3/ipu3_agc.h b/src/ipa/ipu3/ipu3_agc.h
> index a5a78233cb6d..60c7a84f2d98 100644
> --- a/src/ipa/ipu3/ipu3_agc.h
> +++ b/src/ipa/ipu3/ipu3_agc.h
> @@ -12,9 +12,9 @@
>  
>  #include <linux/intel-ipu3.h>
>  
> -#include <libcamera/geometry.h>
> +#include <libcamera/base/utils.h>
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/geometry.h>
>  
>  #include "libipa/algorithm.h"
>  
> diff --git a/src/ipa/raspberrypi/cam_helper.hpp b/src/ipa/raspberrypi/cam_helper.hpp
> index f53f5c39b01c..221898ceb40d 100644
> --- a/src/ipa/raspberrypi/cam_helper.hpp
> +++ b/src/ipa/raspberrypi/cam_helper.hpp
> @@ -15,7 +15,8 @@
>  #include "controller/metadata.hpp"
>  #include "md_parser.hpp"
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/v4l2_videodevice.h"
>  
>  namespace RPiController {
> diff --git a/src/ipa/raspberrypi/controller/agc_algorithm.hpp b/src/ipa/raspberrypi/controller/agc_algorithm.hpp
> index 134bbcda50ce..61595ea2b006 100644
> --- a/src/ipa/raspberrypi/controller/agc_algorithm.hpp
> +++ b/src/ipa/raspberrypi/controller/agc_algorithm.hpp
> @@ -6,7 +6,8 @@
>   */
>  #pragma once
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
> +
>  #include "algorithm.hpp"
>  
>  namespace RPiController {
> diff --git a/src/ipa/raspberrypi/controller/agc_status.h b/src/ipa/raspberrypi/controller/agc_status.h
> index 5d50e177f0dc..20cb1b624b33 100644
> --- a/src/ipa/raspberrypi/controller/agc_status.h
> +++ b/src/ipa/raspberrypi/controller/agc_status.h
> @@ -6,7 +6,7 @@
>   */
>  #pragma once
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>  
>  // The AGC algorithm should post the following structure into the image's
>  // "agc.status" metadata.
> diff --git a/src/ipa/raspberrypi/controller/camera_mode.h b/src/ipa/raspberrypi/controller/camera_mode.h
> index 2aa2335dcf90..6588823020e3 100644
> --- a/src/ipa/raspberrypi/controller/camera_mode.h
> +++ b/src/ipa/raspberrypi/controller/camera_mode.h
> @@ -8,7 +8,7 @@
>  
>  #include <libcamera/transform.h>
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>  
>  // Description of a "camera mode", holding enough information for control
>  // algorithms to adapt their behaviour to the different modes of the camera,
> diff --git a/src/ipa/raspberrypi/controller/device_status.h b/src/ipa/raspberrypi/controller/device_status.h
> index 131b4cd344ee..f74235248b12 100644
> --- a/src/ipa/raspberrypi/controller/device_status.h
> +++ b/src/ipa/raspberrypi/controller/device_status.h
> @@ -6,7 +6,7 @@
>   */
>  #pragma once
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>  
>  // Definition of "device metadata" which stores things like shutter time and
>  // analogue gain that downstream control algorithms will want to know.
> diff --git a/src/ipa/raspberrypi/controller/rpi/agc.hpp b/src/ipa/raspberrypi/controller/rpi/agc.hpp
> index 750789482b49..85067dc64614 100644
> --- a/src/ipa/raspberrypi/controller/rpi/agc.hpp
> +++ b/src/ipa/raspberrypi/controller/rpi/agc.hpp
> @@ -9,7 +9,7 @@
>  #include <vector>
>  #include <mutex>
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>  
>  #include "../agc_algorithm.hpp"
>  #include "../agc_status.h"
> diff --git a/src/ipa/raspberrypi/controller/rpi/lux.hpp b/src/ipa/raspberrypi/controller/rpi/lux.hpp
> index 45c844393e62..3ebd35d1e382 100644
> --- a/src/ipa/raspberrypi/controller/rpi/lux.hpp
> +++ b/src/ipa/raspberrypi/controller/rpi/lux.hpp
> @@ -8,7 +8,7 @@
>  
>  #include <mutex>
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>  
>  #include "../lux_status.h"
>  #include "../algorithm.hpp"
> diff --git a/src/libcamera/base/meson.build b/src/libcamera/base/meson.build
> index 3d58fea36ef5..6d9ec37414f8 100644
> --- a/src/libcamera/base/meson.build
> +++ b/src/libcamera/base/meson.build
> @@ -1,6 +1,7 @@
>  # SPDX-License-Identifier: CC0-1.0
>  
>  libcamera_base_sources = files([
> +    'utils.cpp',
>  ])
>  
>  libcamera_base_deps = [
> @@ -10,7 +11,6 @@ libcamera_base_lib = shared_library('libcamera-base',
>                                      [libcamera_base_sources, libcamera_base_headers],
>                                      name_prefix : '',
>                                      install : true,
> -                                    cpp_args : libcamera_cpp_args,
>                                      include_directories : libcamera_includes,
>                                      dependencies : libcamera_base_deps)
>  
> diff --git a/src/libcamera/utils.cpp b/src/libcamera/base/utils.cpp
> similarity index 98%
> rename from src/libcamera/utils.cpp
> rename to src/libcamera/base/utils.cpp
> index 42f82d6158dd..d0c0a93980b1 100644
> --- a/src/libcamera/utils.cpp
> +++ b/src/libcamera/base/utils.cpp
> @@ -5,7 +5,7 @@
>   * utils.cpp - Miscellaneous utility functions
>   */
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>  
>  #include <dlfcn.h>
>  #include <elf.h>
> @@ -20,7 +20,7 @@
>  #include <unistd.h>
>  
>  /**
> - * \file utils.h
> + * \file base/utils.h
>   * \brief Miscellaneous utility functions
>   */
>  
> @@ -44,8 +44,8 @@ namespace utils {
>   */
>  const char *basename(const char *path)
>  {
> -       const char *base = strrchr(path, '/');
> -       return base ? base + 1 : path;
> +	const char *base = strrchr(path, '/');
> +	return base ? base + 1 : path;
>  }
>  
>  /**
> diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp
> index 1ecf2b07d5a3..a3784db6e697 100644
> --- a/src/libcamera/camera_manager.cpp
> +++ b/src/libcamera/camera_manager.cpp
> @@ -12,13 +12,14 @@
>  
>  #include <libcamera/camera.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/device_enumerator.h"
>  #include "libcamera/internal/ipa_manager.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/pipeline_handler.h"
>  #include "libcamera/internal/process.h"
>  #include "libcamera/internal/thread.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file camera_manager.h
> diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp
> index 3e135353f1d7..94dcf4f9cf48 100644
> --- a/src/libcamera/camera_sensor.cpp
> +++ b/src/libcamera/camera_sensor.cpp
> @@ -18,11 +18,12 @@
>  
>  #include <libcamera/property_ids.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/bayer_format.h"
>  #include "libcamera/internal/camera_sensor_properties.h"
>  #include "libcamera/internal/formats.h"
>  #include "libcamera/internal/sysfs.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file camera_sensor.h
> diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
> index 5aef4e7145bd..7df372ad3b6c 100644
> --- a/src/libcamera/controls.cpp
> +++ b/src/libcamera/controls.cpp
> @@ -12,9 +12,10 @@
>  #include <string>
>  #include <string.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/control_validator.h"
>  #include "libcamera/internal/log.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file controls.h
> diff --git a/src/libcamera/event_dispatcher_poll.cpp b/src/libcamera/event_dispatcher_poll.cpp
> index 456c6def075b..0b6aee187063 100644
> --- a/src/libcamera/event_dispatcher_poll.cpp
> +++ b/src/libcamera/event_dispatcher_poll.cpp
> @@ -16,11 +16,12 @@
>  #include <sys/eventfd.h>
>  #include <unistd.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/event_notifier.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/thread.h"
>  #include "libcamera/internal/timer.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file event_dispatcher_poll.h
> diff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp
> index 93d02d947c46..263cacd64737 100644
> --- a/src/libcamera/ipa_manager.cpp
> +++ b/src/libcamera/ipa_manager.cpp
> @@ -12,12 +12,13 @@
>  #include <string.h>
>  #include <sys/types.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/file.h"
>  #include "libcamera/internal/ipa_module.h"
>  #include "libcamera/internal/ipa_proxy.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/pipeline_handler.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file ipa_manager.h
> diff --git a/src/libcamera/ipa_module.cpp b/src/libcamera/ipa_module.cpp
> index f53e529b0380..a4e7fb861138 100644
> --- a/src/libcamera/ipa_module.cpp
> +++ b/src/libcamera/ipa_module.cpp
> @@ -23,10 +23,11 @@
>  
>  #include <libcamera/span.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/file.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/pipeline_handler.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file ipa_module.h
> diff --git a/src/libcamera/ipa_proxy.cpp b/src/libcamera/ipa_proxy.cpp
> index b70fde581eeb..ca980ec705a6 100644
> --- a/src/libcamera/ipa_proxy.cpp
> +++ b/src/libcamera/ipa_proxy.cpp
> @@ -12,9 +12,10 @@
>  #include <sys/types.h>
>  #include <unistd.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/ipa_module.h"
>  #include "libcamera/internal/log.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file ipa_proxy.h
> diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp
> index 74829a56916e..5ff0e9017648 100644
> --- a/src/libcamera/log.cpp
> +++ b/src/libcamera/log.cpp
> @@ -23,8 +23,9 @@
>  
>  #include <libcamera/logging.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/thread.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file log.h
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> index eaf3cec8cba7..ac401c25d498 100644
> --- a/src/libcamera/meson.build
> +++ b/src/libcamera/meson.build
> @@ -52,7 +52,6 @@ libcamera_sources = files([
>      'thread.cpp',
>      'timer.cpp',
>      'transform.cpp',
> -    'utils.cpp',
>      'v4l2_device.cpp',
>      'v4l2_pixelformat.cpp',
>      'v4l2_subdevice.cpp',
> diff --git a/src/libcamera/object.cpp b/src/libcamera/object.cpp
> index 5e6b73f9af84..51cac64ea313 100644
> --- a/src/libcamera/object.cpp
> +++ b/src/libcamera/object.cpp
> @@ -11,11 +11,12 @@
>  
>  #include <libcamera/signal.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/message.h"
>  #include "libcamera/internal/semaphore.h"
>  #include "libcamera/internal/thread.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file object.h
> diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp
> index 4eb3f7b730a9..32d143a862b2 100644
> --- a/src/libcamera/pipeline/ipu3/imgu.cpp
> +++ b/src/libcamera/pipeline/ipu3/imgu.cpp
> @@ -16,9 +16,10 @@
>  #include <libcamera/formats.h>
>  #include <libcamera/stream.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/media_device.h"
> -#include "libcamera/internal/utils.h"
>  
>  namespace libcamera {
>  
> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
> index 6c93bc6d161d..6b43ad2fb2b1 100644
> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp
> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
> @@ -20,6 +20,8 @@
>  #include <libcamera/request.h>
>  #include <libcamera/stream.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/camera_sensor.h"
>  #include "libcamera/internal/delayed_controls.h"
>  #include "libcamera/internal/device_enumerator.h"
> @@ -27,7 +29,6 @@
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/media_device.h"
>  #include "libcamera/internal/pipeline_handler.h"
> -#include "libcamera/internal/utils.h"
>  
>  #include "cio2.h"
>  #include "frames.h"
> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> index 4e26a1930228..082eb1ee1c23 100644
> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> @@ -24,6 +24,8 @@
>  #include <libcamera/property_ids.h>
>  #include <libcamera/request.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include <linux/bcm2835-isp.h>
>  #include <linux/videodev2.h>
>  
> @@ -35,7 +37,6 @@
>  #include "libcamera/internal/ipa_manager.h"
>  #include "libcamera/internal/media_device.h"
>  #include "libcamera/internal/pipeline_handler.h"
> -#include "libcamera/internal/utils.h"
>  #include "libcamera/internal/v4l2_videodevice.h"
>  
>  #include "dma_heaps.h"
> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
> index 6699839c4623..c625d7248f5c 100644
> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp
> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
> @@ -24,6 +24,8 @@
>  #include <libcamera/request.h>
>  #include <libcamera/stream.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/camera_sensor.h"
>  #include "libcamera/internal/delayed_controls.h"
>  #include "libcamera/internal/device_enumerator.h"
> @@ -31,7 +33,6 @@
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/media_device.h"
>  #include "libcamera/internal/pipeline_handler.h"
> -#include "libcamera/internal/utils.h"
>  #include "libcamera/internal/v4l2_subdevice.h"
>  #include "libcamera/internal/v4l2_videodevice.h"
>  
> diff --git a/src/libcamera/pipeline/simple/converter.cpp b/src/libcamera/pipeline/simple/converter.cpp
> index 68644ef6477f..589f185b1bf1 100644
> --- a/src/libcamera/pipeline/simple/converter.cpp
> +++ b/src/libcamera/pipeline/simple/converter.cpp
> @@ -15,9 +15,10 @@
>  #include <libcamera/signal.h>
>  #include <libcamera/stream.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/media_device.h"
> -#include "libcamera/internal/utils.h"
>  #include "libcamera/internal/v4l2_videodevice.h"
>  
>  namespace libcamera {
> diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> index 12a85b2407db..d8c17dccae53 100644
> --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> @@ -19,12 +19,13 @@
>  #include <libcamera/request.h>
>  #include <libcamera/stream.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/device_enumerator.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/media_device.h"
>  #include "libcamera/internal/pipeline_handler.h"
>  #include "libcamera/internal/sysfs.h"
> -#include "libcamera/internal/utils.h"
>  #include "libcamera/internal/v4l2_videodevice.h"
>  
>  namespace libcamera {
> diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp
> index 8bbac0085c9b..025ca56205f8 100644
> --- a/src/libcamera/pipeline/vimc/vimc.cpp
> +++ b/src/libcamera/pipeline/vimc/vimc.cpp
> @@ -23,13 +23,14 @@
>  #include <libcamera/request.h>
>  #include <libcamera/stream.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/camera_sensor.h"
>  #include "libcamera/internal/device_enumerator.h"
>  #include "libcamera/internal/ipa_manager.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/media_device.h"
>  #include "libcamera/internal/pipeline_handler.h"
> -#include "libcamera/internal/utils.h"
>  #include "libcamera/internal/v4l2_subdevice.h"
>  #include "libcamera/internal/v4l2_videodevice.h"
>  
> diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp
> index e507a8bba8a6..6fb2a743c3c2 100644
> --- a/src/libcamera/pipeline_handler.cpp
> +++ b/src/libcamera/pipeline_handler.cpp
> @@ -13,11 +13,12 @@
>  #include <libcamera/camera.h>
>  #include <libcamera/camera_manager.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/device_enumerator.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/media_device.h"
>  #include "libcamera/internal/tracepoints.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file pipeline_handler.h
> diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp
> index 40a434a6b0c2..35091f60c1e9 100644
> --- a/src/libcamera/process.cpp
> +++ b/src/libcamera/process.cpp
> @@ -20,9 +20,10 @@
>  #include <unistd.h>
>  #include <vector>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/event_notifier.h"
>  #include "libcamera/internal/log.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file process.h
> diff --git a/src/libcamera/source-paths.cpp b/src/libcamera/source-paths.cpp
> index b39f5f853e39..2a59105e8283 100644
> --- a/src/libcamera/source-paths.cpp
> +++ b/src/libcamera/source-paths.cpp
> @@ -12,7 +12,7 @@
>  #include <link.h>
>  #include <sys/stat.h>
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>  
>  /**
>   * \file source-paths.h
> diff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp
> index f7bafcf8fc97..d5d68427e658 100644
> --- a/src/libcamera/stream.cpp
> +++ b/src/libcamera/stream.cpp
> @@ -15,8 +15,9 @@
>  
>  #include <libcamera/request.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/log.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file stream.h
> diff --git a/src/libcamera/timer.cpp b/src/libcamera/timer.cpp
> index c242113a782e..9496671edffc 100644
> --- a/src/libcamera/timer.cpp
> +++ b/src/libcamera/timer.cpp
> @@ -11,11 +11,12 @@
>  
>  #include <libcamera/camera_manager.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/event_dispatcher.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/message.h"
>  #include "libcamera/internal/thread.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file timer.h
> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
> index 5660e6ea5839..facb53e13169 100644
> --- a/src/libcamera/v4l2_device.cpp
> +++ b/src/libcamera/v4l2_device.cpp
> @@ -16,10 +16,11 @@
>  #include <sys/syscall.h>
>  #include <unistd.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/event_notifier.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/sysfs.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file v4l2_device.h
> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
> index 721ff5a92a2b..2c56cfafbce4 100644
> --- a/src/libcamera/v4l2_subdevice.cpp
> +++ b/src/libcamera/v4l2_subdevice.cpp
> @@ -19,10 +19,11 @@
>  
>  #include <libcamera/geometry.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/media_device.h"
>  #include "libcamera/internal/media_object.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file v4l2_subdevice.h
> diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp
> index f8bfe595e90e..a5a25507462e 100644
> --- a/src/v4l2/v4l2_camera_proxy.cpp
> +++ b/src/v4l2/v4l2_camera_proxy.cpp
> @@ -20,9 +20,10 @@
>  #include <libcamera/formats.h>
>  #include <libcamera/object.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/formats.h"
>  #include "libcamera/internal/log.h"
> -#include "libcamera/internal/utils.h"
>  
>  #include "v4l2_camera.h"
>  #include "v4l2_camera_file.h"
> diff --git a/src/v4l2/v4l2_compat_manager.cpp b/src/v4l2/v4l2_compat_manager.cpp
> index 96dbcdf28f04..27de6c50ff4e 100644
> --- a/src/v4l2/v4l2_compat_manager.cpp
> +++ b/src/v4l2/v4l2_compat_manager.cpp
> @@ -22,8 +22,9 @@
>  #include <libcamera/camera.h>
>  #include <libcamera/camera_manager.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/log.h"
> -#include "libcamera/internal/utils.h"
>  
>  #include "v4l2_camera_file.h"
>  
> diff --git a/test/camera-sensor.cpp b/test/camera-sensor.cpp
> index 8c7fd1d2d444..a8dcad8215e5 100644
> --- a/test/camera-sensor.cpp
> +++ b/test/camera-sensor.cpp
> @@ -10,10 +10,11 @@
>  
>  #include <linux/media-bus-format.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/camera_sensor.h"
>  #include "libcamera/internal/device_enumerator.h"
>  #include "libcamera/internal/media_device.h"
> -#include "libcamera/internal/utils.h"
>  #include "libcamera/internal/v4l2_subdevice.h"
>  
>  #include "test.h"
> diff --git a/test/file-descriptor.cpp b/test/file-descriptor.cpp
> index aa3c896fb937..85b077a25c32 100644
> --- a/test/file-descriptor.cpp
> +++ b/test/file-descriptor.cpp
> @@ -13,7 +13,7 @@
>  
>  #include <libcamera/file_descriptor.h>
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>  
>  #include "test.h"
>  
> diff --git a/test/ipc/unixsocket_ipc.cpp b/test/ipc/unixsocket_ipc.cpp
> index 3049eaa8bb2a..161d09b98719 100644
> --- a/test/ipc/unixsocket_ipc.cpp
> +++ b/test/ipc/unixsocket_ipc.cpp
> @@ -15,6 +15,8 @@
>  #include <sys/wait.h>
>  #include <unistd.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/event_dispatcher.h"
>  #include "libcamera/internal/ipa_data_serializer.h"
>  #include "libcamera/internal/ipc_pipe.h"
> @@ -22,7 +24,6 @@
>  #include "libcamera/internal/process.h"
>  #include "libcamera/internal/thread.h"
>  #include "libcamera/internal/timer.h"
> -#include "libcamera/internal/utils.h"
>  
>  #include "test.h"
>  
> diff --git a/test/log/log_process.cpp b/test/log/log_process.cpp
> index c0a1a012d366..413d9207ea68 100644
> --- a/test/log/log_process.cpp
> +++ b/test/log/log_process.cpp
> @@ -16,12 +16,13 @@
>  
>  #include <libcamera/logging.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/event_dispatcher.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/process.h"
>  #include "libcamera/internal/thread.h"
>  #include "libcamera/internal/timer.h"
> -#include "libcamera/internal/utils.h"
>  
>  #include "test.h"
>  
> diff --git a/test/pixel-format.cpp b/test/pixel-format.cpp
> index c4a08f468ade..0f364f833ed1 100644
> --- a/test/pixel-format.cpp
> +++ b/test/pixel-format.cpp
> @@ -10,7 +10,7 @@
>  #include <libcamera/formats.h>
>  #include <libcamera/pixel_format.h>
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>  
>  #include "test.h"
>  
> diff --git a/test/process/process_test.cpp b/test/process/process_test.cpp
> index 1279d8c17598..a5155bae3162 100644
> --- a/test/process/process_test.cpp
> +++ b/test/process/process_test.cpp
> @@ -9,11 +9,12 @@
>  #include <unistd.h>
>  #include <vector>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/event_dispatcher.h"
>  #include "libcamera/internal/process.h"
>  #include "libcamera/internal/thread.h"
>  #include "libcamera/internal/timer.h"
> -#include "libcamera/internal/utils.h"
>  
>  #include "test.h"
>  
> diff --git a/test/signal-threads.cpp b/test/signal-threads.cpp
> index 3c5f3792e385..8a96b5d2abb3 100644
> --- a/test/signal-threads.cpp
> +++ b/test/signal-threads.cpp
> @@ -9,9 +9,10 @@
>  #include <iostream>
>  #include <thread>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/message.h"
>  #include "libcamera/internal/thread.h"
> -#include "libcamera/internal/utils.h"
>  
>  #include "test.h"
>  
> diff --git a/test/utils.cpp b/test/utils.cpp
> index f170ae4c2f35..9cd2cd070cb9 100644
> --- a/test/utils.cpp
> +++ b/test/utils.cpp
> @@ -14,7 +14,7 @@
>  #include <libcamera/geometry.h>
>  #include <libcamera/span.h>
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>  
>  #include "test.h"
>  
> diff --git a/test/v4l2_subdevice/list_formats.cpp b/test/v4l2_subdevice/list_formats.cpp
> index 74ec81a8560c..9cbd7b9439c3 100644
> --- a/test/v4l2_subdevice/list_formats.cpp
> +++ b/test/v4l2_subdevice/list_formats.cpp
> @@ -10,7 +10,8 @@
>  
>  #include <libcamera/geometry.h>
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/v4l2_subdevice.h"
>  
>  #include "v4l2_subdevice_test.h"
> diff --git a/test/v4l2_videodevice/formats.cpp b/test/v4l2_videodevice/formats.cpp
> index 255446fe758a..6c05262201fa 100644
> --- a/test/v4l2_videodevice/formats.cpp
> +++ b/test/v4l2_videodevice/formats.cpp
> @@ -8,7 +8,8 @@
>  #include <iostream>
>  #include <limits.h>
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/v4l2_videodevice.h"
>  
>  #include "v4l2_videodevice_test.h"
> -- 
> 2.30.2
>
Paul Elder June 25, 2021, 4:18 a.m. UTC | #22
Hi Kieran,

On Fri, Jun 25, 2021 at 02:35:31AM +0100, Kieran Bingham wrote:
> Move the class support infrastructure to the base library.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
>  include/libcamera/{ => base}/class.h            | 0
>  include/libcamera/base/meson.build              | 1 +
>  include/libcamera/buffer.h                      | 3 ++-
>  include/libcamera/camera.h                      | 3 ++-
>  include/libcamera/camera_manager.h              | 3 ++-
>  include/libcamera/controls.h                    | 3 ++-
>  include/libcamera/framebuffer_allocator.h       | 2 +-
>  include/libcamera/internal/buffer.h             | 3 ++-
>  include/libcamera/internal/byte_stream_buffer.h | 3 ++-
>  include/libcamera/internal/camera_sensor.h      | 3 ++-
>  include/libcamera/internal/file.h               | 3 ++-
>  include/libcamera/internal/log.h                | 3 +--
>  include/libcamera/internal/media_object.h       | 2 +-
>  include/libcamera/internal/pipeline_handler.h   | 3 ++-
>  include/libcamera/internal/v4l2_subdevice.h     | 3 ++-
>  include/libcamera/internal/v4l2_videodevice.h   | 3 ++-
>  include/libcamera/meson.build                   | 1 -
>  include/libcamera/request.h                     | 3 ++-
>  src/android/camera_buffer.h                     | 3 ++-
>  src/android/camera_capabilities.h               | 3 ++-
>  src/android/camera_hal_config.h                 | 2 +-
>  src/libcamera/{ => base}/class.cpp              | 2 +-
>  src/libcamera/base/meson.build                  | 1 +
>  src/libcamera/meson.build                       | 1 -
>  24 files changed, 35 insertions(+), 22 deletions(-)
>  rename include/libcamera/{ => base}/class.h (100%)
>  rename src/libcamera/{ => base}/class.cpp (99%)
> 
> diff --git a/include/libcamera/class.h b/include/libcamera/base/class.h
> similarity index 100%
> rename from include/libcamera/class.h
> rename to include/libcamera/base/class.h
> diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build
> index 9f0ba6b0e10c..2db756c504c9 100644
> --- a/include/libcamera/base/meson.build
> +++ b/include/libcamera/base/meson.build
> @@ -3,6 +3,7 @@
>  libcamera_base_include_dir = libcamera_include_dir / 'base'
>  
>  libcamera_base_headers = files([
> +    'class.h',
>      'utils.h',
>  ])
>  
> diff --git a/include/libcamera/buffer.h b/include/libcamera/buffer.h
> index e0af00900409..323d1cba41a9 100644
> --- a/include/libcamera/buffer.h
> +++ b/include/libcamera/buffer.h
> @@ -10,7 +10,8 @@
>  #include <stdint.h>
>  #include <vector>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/file_descriptor.h>
>  
>  namespace libcamera {
> diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h
> index d71641805c0a..ea0914009c2b 100644
> --- a/include/libcamera/camera.h
> +++ b/include/libcamera/camera.h
> @@ -12,7 +12,8 @@
>  #include <stdint.h>
>  #include <string>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/controls.h>
>  #include <libcamera/object.h>
>  #include <libcamera/request.h>
> diff --git a/include/libcamera/camera_manager.h b/include/libcamera/camera_manager.h
> index c2f0b786da8e..5deede035115 100644
> --- a/include/libcamera/camera_manager.h
> +++ b/include/libcamera/camera_manager.h
> @@ -12,7 +12,8 @@
>  #include <sys/types.h>
>  #include <vector>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/object.h>
>  #include <libcamera/signal.h>
>  
> diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
> index 1c9b37e617bc..f62b6cf055d6 100644
> --- a/include/libcamera/controls.h
> +++ b/include/libcamera/controls.h
> @@ -14,7 +14,8 @@
>  #include <unordered_map>
>  #include <vector>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/geometry.h>
>  #include <libcamera/span.h>
>  
> diff --git a/include/libcamera/framebuffer_allocator.h b/include/libcamera/framebuffer_allocator.h
> index 0c85631a1da2..cbc9ce101889 100644
> --- a/include/libcamera/framebuffer_allocator.h
> +++ b/include/libcamera/framebuffer_allocator.h
> @@ -11,7 +11,7 @@
>  #include <memory>
>  #include <vector>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
>  
>  namespace libcamera {
>  
> diff --git a/include/libcamera/internal/buffer.h b/include/libcamera/internal/buffer.h
> index 9da1fbd12c27..91dd24969385 100644
> --- a/include/libcamera/internal/buffer.h
> +++ b/include/libcamera/internal/buffer.h
> @@ -10,7 +10,8 @@
>  #include <sys/mman.h>
>  #include <vector>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/buffer.h>
>  #include <libcamera/span.h>
>  
> diff --git a/include/libcamera/internal/byte_stream_buffer.h b/include/libcamera/internal/byte_stream_buffer.h
> index 866cb9b0b2a6..7eefb1a71f07 100644
> --- a/include/libcamera/internal/byte_stream_buffer.h
> +++ b/include/libcamera/internal/byte_stream_buffer.h
> @@ -11,7 +11,8 @@
>  #include <stdint.h>
>  #include <type_traits>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/span.h>
>  
>  namespace libcamera {
> diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h
> index e133ebf45bf7..7bc540619721 100644
> --- a/include/libcamera/internal/camera_sensor.h
> +++ b/include/libcamera/internal/camera_sensor.h
> @@ -11,7 +11,8 @@
>  #include <string>
>  #include <vector>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/controls.h>
>  #include <libcamera/geometry.h>
>  #include <libcamera/ipa/core_ipa_interface.h>
> diff --git a/include/libcamera/internal/file.h b/include/libcamera/internal/file.h
> index f0b313a5faae..44621ceb4c19 100644
> --- a/include/libcamera/internal/file.h
> +++ b/include/libcamera/internal/file.h
> @@ -11,7 +11,8 @@
>  #include <string>
>  #include <sys/types.h>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/span.h>
>  
>  namespace libcamera {
> diff --git a/include/libcamera/internal/log.h b/include/libcamera/internal/log.h
> index 9c2beab6a33a..82e55a623e04 100644
> --- a/include/libcamera/internal/log.h
> +++ b/include/libcamera/internal/log.h
> @@ -10,8 +10,7 @@
>  #include <chrono>
>  #include <sstream>
>  
> -#include <libcamera/class.h>
> -
> +#include <libcamera/base/class.h>
>  #include <libcamera/base/utils.h>
>  
>  namespace libcamera {
> diff --git a/include/libcamera/internal/media_object.h b/include/libcamera/internal/media_object.h
> index 1c82c27928a8..2f5d33e1903e 100644
> --- a/include/libcamera/internal/media_object.h
> +++ b/include/libcamera/internal/media_object.h
> @@ -12,7 +12,7 @@
>  
>  #include <linux/media.h>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
>  
>  namespace libcamera {
>  
> diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h
> index 31dadf285a58..8beb6b76dd3f 100644
> --- a/include/libcamera/internal/pipeline_handler.h
> +++ b/include/libcamera/internal/pipeline_handler.h
> @@ -15,7 +15,8 @@
>  #include <sys/types.h>
>  #include <vector>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/controls.h>
>  #include <libcamera/object.h>
>  #include <libcamera/stream.h>
> diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h
> index d2b9ca55439e..d07dd6b444d0 100644
> --- a/include/libcamera/internal/v4l2_subdevice.h
> +++ b/include/libcamera/internal/v4l2_subdevice.h
> @@ -11,7 +11,8 @@
>  #include <string>
>  #include <vector>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/geometry.h>
>  
>  #include "libcamera/internal/formats.h"
> diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h
> index 7938343bba8d..227d015e8937 100644
> --- a/include/libcamera/internal/v4l2_videodevice.h
> +++ b/include/libcamera/internal/v4l2_videodevice.h
> @@ -16,8 +16,9 @@
>  
>  #include <linux/videodev2.h>
>  
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/buffer.h>
> -#include <libcamera/class.h>
>  #include <libcamera/geometry.h>
>  #include <libcamera/pixel_format.h>
>  #include <libcamera/signal.h>
> diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build
> index 1fa1bf4a4e78..7cba3de6ca96 100644
> --- a/include/libcamera/meson.build
> +++ b/include/libcamera/meson.build
> @@ -5,7 +5,6 @@ libcamera_public_headers = files([
>      'buffer.h',
>      'camera.h',
>      'camera_manager.h',
> -    'class.h',
>      'compiler.h',
>      'controls.h',
>      'file_descriptor.h',
> diff --git a/include/libcamera/request.h b/include/libcamera/request.h
> index 5596901ddd8e..00c646fea7f2 100644
> --- a/include/libcamera/request.h
> +++ b/include/libcamera/request.h
> @@ -13,7 +13,8 @@
>  #include <string>
>  #include <unordered_set>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/controls.h>
>  #include <libcamera/signal.h>
>  
> diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h
> index c88124b2b3f3..e850c4e36668 100644
> --- a/src/android/camera_buffer.h
> +++ b/src/android/camera_buffer.h
> @@ -9,7 +9,8 @@
>  
>  #include <hardware/camera3.h>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/span.h>
>  
>  class CameraBuffer final : public libcamera::Extensible
> diff --git a/src/android/camera_capabilities.h b/src/android/camera_capabilities.h
> index f511607bbd90..4f5be82595d6 100644
> --- a/src/android/camera_capabilities.h
> +++ b/src/android/camera_capabilities.h
> @@ -11,8 +11,9 @@
>  #include <memory>
>  #include <vector>
>  
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/camera.h>
> -#include <libcamera/class.h>
>  #include <libcamera/formats.h>
>  #include <libcamera/geometry.h>
>  
> diff --git a/src/android/camera_hal_config.h b/src/android/camera_hal_config.h
> index 97dc69c1def5..a79d5d6c42dc 100644
> --- a/src/android/camera_hal_config.h
> +++ b/src/android/camera_hal_config.h
> @@ -10,7 +10,7 @@
>  #include <map>
>  #include <string>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
>  
>  struct CameraConfigData {
>  	int facing = -1;
> diff --git a/src/libcamera/class.cpp b/src/libcamera/base/class.cpp
> similarity index 99%
> rename from src/libcamera/class.cpp
> rename to src/libcamera/base/class.cpp
> index 28c35633d7db..165beafc243d 100644
> --- a/src/libcamera/class.cpp
> +++ b/src/libcamera/base/class.cpp
> @@ -5,7 +5,7 @@
>   * class.cpp - Utilities and helpers for classes
>   */
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
>  
>  /**
>   * \file class.h
> diff --git a/src/libcamera/base/meson.build b/src/libcamera/base/meson.build
> index 6d9ec37414f8..302a288685d3 100644
> --- a/src/libcamera/base/meson.build
> +++ b/src/libcamera/base/meson.build
> @@ -1,6 +1,7 @@
>  # SPDX-License-Identifier: CC0-1.0
>  
>  libcamera_base_sources = files([
> +    'class.cpp',
>      'utils.cpp',
>  ])
>  
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> index ac401c25d498..a341004c0c19 100644
> --- a/src/libcamera/meson.build
> +++ b/src/libcamera/meson.build
> @@ -10,7 +10,6 @@ libcamera_sources = files([
>      'camera_manager.cpp',
>      'camera_sensor.cpp',
>      'camera_sensor_properties.cpp',
> -    'class.cpp',
>      'controls.cpp',
>      'control_serializer.cpp',
>      'control_validator.cpp',
> -- 
> 2.30.2
>
Paul Elder June 25, 2021, 4:39 a.m. UTC | #23
Hi Kieran,

On Fri, Jun 25, 2021 at 02:35:34AM +0100, Kieran Bingham wrote:
> Move the event notifier, and associated header updates.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  include/libcamera/{internal => base}/event_notifier.h | 0
>  include/libcamera/base/meson.build                    | 1 +
>  include/libcamera/internal/meson.build                | 1 -
>  src/libcamera/base/event_dispatcher_poll.cpp          | 3 +--
>  src/libcamera/{ => base}/event_notifier.cpp           | 6 +++---
>  src/libcamera/base/meson.build                        | 1 +
>  src/libcamera/device_enumerator_udev.cpp              | 2 +-
>  src/libcamera/ipc_unixsocket.cpp                      | 3 +--
>  src/libcamera/meson.build                             | 1 -
>  src/libcamera/process.cpp                             | 3 +--
>  src/libcamera/v4l2_device.cpp                         | 2 +-
>  src/libcamera/v4l2_videodevice.cpp                    | 2 +-
>  test/event-thread.cpp                                 | 3 +--
>  test/event.cpp                                        | 3 +--
>  test/ipa/ipa_interface_test.cpp                       | 2 +-
>  15 files changed, 14 insertions(+), 19 deletions(-)
>  rename include/libcamera/{internal => base}/event_notifier.h (100%)
>  rename src/libcamera/{ => base}/event_notifier.cpp (98%)
> 
> diff --git a/include/libcamera/internal/event_notifier.h b/include/libcamera/base/event_notifier.h
> similarity index 100%
> rename from include/libcamera/internal/event_notifier.h
> rename to include/libcamera/base/event_notifier.h

With the updated header guard the Hiro suggested,

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build
> index 6fc6c138a5fd..83c664affc88 100644
> --- a/include/libcamera/base/meson.build
> +++ b/include/libcamera/base/meson.build
> @@ -7,6 +7,7 @@ libcamera_base_headers = files([
>      'class.h',
>      'event_dispatcher.h',
>      'event_dispatcher_poll.h',
> +    'event_notifier.h',
>      'file.h',
>      'log.h',
>      'message.h',
> diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build
> index b10285edac27..61af16bfe05d 100644
> --- a/include/libcamera/internal/meson.build
> +++ b/include/libcamera/internal/meson.build
> @@ -22,7 +22,6 @@ libcamera_internal_headers = files([
>      'device_enumerator.h',
>      'device_enumerator_sysfs.h',
>      'device_enumerator_udev.h',
> -    'event_notifier.h',
>      'formats.h',
>      'ipa_manager.h',
>      'ipa_module.h',
> diff --git a/src/libcamera/base/event_dispatcher_poll.cpp b/src/libcamera/base/event_dispatcher_poll.cpp
> index d76ca7fc2c32..5839373a5281 100644
> --- a/src/libcamera/base/event_dispatcher_poll.cpp
> +++ b/src/libcamera/base/event_dispatcher_poll.cpp
> @@ -16,13 +16,12 @@
>  #include <sys/eventfd.h>
>  #include <unistd.h>
>  
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/log.h>
>  #include <libcamera/base/thread.h>
>  #include <libcamera/base/timer.h>
>  #include <libcamera/base/utils.h>
>  
> -#include "libcamera/internal/event_notifier.h"
> -
>  /**
>   * \file base/event_dispatcher_poll.h
>   */
> diff --git a/src/libcamera/event_notifier.cpp b/src/libcamera/base/event_notifier.cpp
> similarity index 98%
> rename from src/libcamera/event_notifier.cpp
> rename to src/libcamera/base/event_notifier.cpp
> index 784016a9f907..fd93c0878c6f 100644
> --- a/src/libcamera/event_notifier.cpp
> +++ b/src/libcamera/base/event_notifier.cpp
> @@ -5,14 +5,14 @@
>   * event_notifier.cpp - File descriptor event notifier
>   */
>  
> -#include "libcamera/internal/event_notifier.h"
> -
> -#include <libcamera/camera_manager.h>
> +#include <libcamera/base/event_notifier.h>
>  
>  #include <libcamera/base/event_dispatcher.h>
>  #include <libcamera/base/message.h>
>  #include <libcamera/base/thread.h>
>  
> +#include <libcamera/camera_manager.h>
> +
>  /**
>   * \file event_notifier.h
>   * \brief File descriptor event notifier
> diff --git a/src/libcamera/base/meson.build b/src/libcamera/base/meson.build
> index fb8ed79acd8e..a8b04cfc8a5f 100644
> --- a/src/libcamera/base/meson.build
> +++ b/src/libcamera/base/meson.build
> @@ -5,6 +5,7 @@ libcamera_base_sources = files([
>      'bound_method.cpp',
>      'event_dispatcher.cpp',
>      'event_dispatcher_poll.cpp',
> +    'event_notifier.cpp',
>      'file.cpp',
>      'log.cpp',
>      'message.cpp',
> diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp
> index 4b842773fcd6..37a2c5aa55db 100644
> --- a/src/libcamera/device_enumerator_udev.cpp
> +++ b/src/libcamera/device_enumerator_udev.cpp
> @@ -17,9 +17,9 @@
>  #include <sys/sysmacros.h>
>  #include <unistd.h>
>  
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/log.h>
>  
> -#include "libcamera/internal/event_notifier.h"
>  #include "libcamera/internal/media_device.h"
>  
>  namespace libcamera {
> diff --git a/src/libcamera/ipc_unixsocket.cpp b/src/libcamera/ipc_unixsocket.cpp
> index 1466597077d4..f23eb783bcb5 100644
> --- a/src/libcamera/ipc_unixsocket.cpp
> +++ b/src/libcamera/ipc_unixsocket.cpp
> @@ -12,10 +12,9 @@
>  #include <sys/socket.h>
>  #include <unistd.h>
>  
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/log.h>
>  
> -#include "libcamera/internal/event_notifier.h"
> -
>  /**
>   * \file ipc_unixsocket.h
>   * \brief IPC mechanism based on Unix sockets
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> index 58eee14aed97..1f163cfe1225 100644
> --- a/src/libcamera/meson.build
> +++ b/src/libcamera/meson.build
> @@ -15,7 +15,6 @@ libcamera_sources = files([
>      'delayed_controls.cpp',
>      'device_enumerator.cpp',
>      'device_enumerator_sysfs.cpp',
> -    'event_notifier.cpp',
>      'file_descriptor.cpp',
>      'formats.cpp',
>      'framebuffer_allocator.cpp',
> diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp
> index 463380299a65..4fe4ad570b74 100644
> --- a/src/libcamera/process.cpp
> +++ b/src/libcamera/process.cpp
> @@ -20,11 +20,10 @@
>  #include <unistd.h>
>  #include <vector>
>  
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/log.h>
>  #include <libcamera/base/utils.h>
>  
> -#include "libcamera/internal/event_notifier.h"
> -
>  /**
>   * \file process.h
>   * \brief Process object
> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
> index 334b9b78b812..98d93a12a7be 100644
> --- a/src/libcamera/v4l2_device.cpp
> +++ b/src/libcamera/v4l2_device.cpp
> @@ -16,10 +16,10 @@
>  #include <sys/syscall.h>
>  #include <unistd.h>
>  
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/log.h>
>  #include <libcamera/base/utils.h>
>  
> -#include "libcamera/internal/event_notifier.h"
>  #include "libcamera/internal/sysfs.h"
>  
>  /**
> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
> index dc23510bc5aa..3d2d99b46e4e 100644
> --- a/src/libcamera/v4l2_videodevice.cpp
> +++ b/src/libcamera/v4l2_videodevice.cpp
> @@ -21,11 +21,11 @@
>  
>  #include <linux/version.h>
>  
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/log.h>
>  
>  #include <libcamera/file_descriptor.h>
>  
> -#include "libcamera/internal/event_notifier.h"
>  #include "libcamera/internal/media_device.h"
>  #include "libcamera/internal/media_object.h"
>  
> diff --git a/test/event-thread.cpp b/test/event-thread.cpp
> index 05c5d26d3611..575261664c2f 100644
> --- a/test/event-thread.cpp
> +++ b/test/event-thread.cpp
> @@ -10,11 +10,10 @@
>  #include <string.h>
>  #include <unistd.h>
>  
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/thread.h>
>  #include <libcamera/base/timer.h>
>  
> -#include "libcamera/internal/event_notifier.h"
> -
>  #include "test.h"
>  
>  using namespace std;
> diff --git a/test/event.cpp b/test/event.cpp
> index aa79da99c286..c2274344b7f0 100644
> --- a/test/event.cpp
> +++ b/test/event.cpp
> @@ -10,11 +10,10 @@
>  #include <unistd.h>
>  
>  #include <libcamera/base/event_dispatcher.h>
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/thread.h>
>  #include <libcamera/base/timer.h>
>  
> -#include "libcamera/internal/event_notifier.h"
> -
>  #include "test.h"
>  
>  using namespace std;
> diff --git a/test/ipa/ipa_interface_test.cpp b/test/ipa/ipa_interface_test.cpp
> index 656d86552d85..ee9f26510784 100644
> --- a/test/ipa/ipa_interface_test.cpp
> +++ b/test/ipa/ipa_interface_test.cpp
> @@ -15,11 +15,11 @@
>  #include <libcamera/ipa/vimc_ipa_proxy.h>
>  
>  #include <libcamera/base/event_dispatcher.h>
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/thread.h>
>  #include <libcamera/base/timer.h>
>  
>  #include "libcamera/internal/device_enumerator.h"
> -#include "libcamera/internal/event_notifier.h"
>  #include "libcamera/internal/ipa_manager.h"
>  #include "libcamera/internal/ipa_module.h"
>  #include "libcamera/internal/pipeline_handler.h"
> -- 
> 2.30.2
>
Paul Elder June 25, 2021, 8:44 a.m. UTC | #24
Hi Kieran,

On Fri, Jun 25, 2021 at 02:35:37AM +0100, Kieran Bingham wrote:
> The libcamera_generated_ipa_headers are only a dependency to internal
> components, and should not form part of the public API.
> 
> Now that we have a private dependency, move the generated headers there,

s/,$/./ ?

> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
>  src/libcamera/meson.build | 12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)
> 
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> index 64c7475f1a2e..706f44924f65 100644
> --- a/src/libcamera/meson.build
> +++ b/src/libcamera/meson.build
> @@ -131,23 +131,19 @@ libcamera = shared_library('libcamera',
>                             build_rpath : '/',
>                             dependencies : libcamera_deps)
>  
> -# TODO Drop libcamera_generated_ipa_headers from libcamera_dep as libcamera_dep
> -# is supposed to model the dependencies required for usage of the public API,
> -# not the internal API. It is needed as as some external components such as the
> -# unit tests make use of the generated headers and this creates a race in the
> -# build.
> -
>  libcamera_dep = declare_dependency(sources : [
>                                         libcamera_ipa_headers,
>                                         libcamera_public_headers,
> -                                       libcamera_generated_ipa_headers,
>                                     ],
>                                     include_directories : libcamera_includes,
>                                     dependencies : libcamera_base,
>                                     link_with : libcamera)
>  
>  # Internal dependancy for components and plugins which can use Private APIs
> -libcamera_private = declare_dependency(dependencies : [
> +libcamera_private = declare_dependency(sources : [
> +                                           libcamera_generated_ipa_headers,
> +                                       ],
> +                                       dependencies : [
>                                             libcamera_dep,
>                                             libcamera_base_private,
>                                         ])
> -- 
> 2.30.2
>
Paul Elder June 25, 2021, 8:45 a.m. UTC | #25
Hi Kieran,

On Fri, Jun 25, 2021 at 02:35:38AM +0100, Kieran Bingham wrote:
> Now that we have a libcamera_private, make the public only dependency
> libcamera_public so that it is clear which interface is being linked.

Ah, that's so much better.

> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
>  src/cam/meson.build           |  2 +-
>  src/gstreamer/meson.build     |  2 +-
>  src/lc-compliance/meson.build |  2 +-
>  src/libcamera/meson.build     | 16 ++++++++--------
>  src/qcam/meson.build          |  2 +-
>  test/controls/meson.build     |  2 +-
>  test/meson.build              |  2 +-
>  test/stream/meson.build       |  2 +-
>  8 files changed, 15 insertions(+), 15 deletions(-)
> 
> diff --git a/src/cam/meson.build b/src/cam/meson.build
> index 5e1a7f387d60..6234ed0a059a 100644
> --- a/src/cam/meson.build
> +++ b/src/cam/meson.build
> @@ -21,7 +21,7 @@ cam_sources = files([
>  cam  = executable('cam', cam_sources,
>                    dependencies : [
>                        libatomic,
> -                      libcamera_dep,
> +                      libcamera_public,
>                        libevent,
>                    ],
>                    install : true)
> diff --git a/src/gstreamer/meson.build b/src/gstreamer/meson.build
> index 4d3afee48737..77c79140eb37 100644
> --- a/src/gstreamer/meson.build
> +++ b/src/gstreamer/meson.build
> @@ -42,7 +42,7 @@ endif
>  libcamera_gst = shared_library('gstlibcamera',
>      libcamera_gst_sources,
>      cpp_args : libcamera_gst_cpp_args,
> -    dependencies : [libcamera_dep, gstvideo_dep, gstallocator_dep],
> +    dependencies : [libcamera_public, gstvideo_dep, gstallocator_dep],
>      install: true,
>      install_dir : '@0@/gstreamer-1.0'.format(get_option('libdir')),
>  )
> diff --git a/src/lc-compliance/meson.build b/src/lc-compliance/meson.build
> index a2bfcceb1259..f3a7cbdec4f8 100644
> --- a/src/lc-compliance/meson.build
> +++ b/src/lc-compliance/meson.build
> @@ -21,7 +21,7 @@ lc_compliance_sources = files([
>  lc_compliance  = executable('lc-compliance', lc_compliance_sources,
>                              dependencies : [
>                                  libatomic,
> -                                libcamera_dep,
> +                                libcamera_public,
>                                  libevent,
>                              ],
>                              install : true)
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> index 706f44924f65..40af7adbf05f 100644
> --- a/src/libcamera/meson.build
> +++ b/src/libcamera/meson.build
> @@ -131,20 +131,20 @@ libcamera = shared_library('libcamera',
>                             build_rpath : '/',
>                             dependencies : libcamera_deps)
>  
> -libcamera_dep = declare_dependency(sources : [
> -                                       libcamera_ipa_headers,
> -                                       libcamera_public_headers,
> -                                   ],
> -                                   include_directories : libcamera_includes,
> -                                   dependencies : libcamera_base,
> -                                   link_with : libcamera)
> +libcamera_public = declare_dependency(sources : [
> +                                          libcamera_ipa_headers,
> +                                          libcamera_public_headers,
> +                                      ],
> +                                      include_directories : libcamera_includes,
> +                                      dependencies : libcamera_base,
> +                                      link_with : libcamera)
>  
>  # Internal dependancy for components and plugins which can use Private APIs
>  libcamera_private = declare_dependency(sources : [
>                                             libcamera_generated_ipa_headers,
>                                         ],
>                                         dependencies : [
> -                                           libcamera_dep,
> +                                           libcamera_public,
>                                             libcamera_base_private,
>                                         ])
>  
> diff --git a/src/qcam/meson.build b/src/qcam/meson.build
> index fad4cc95ddf7..7d3621c93d41 100644
> --- a/src/qcam/meson.build
> +++ b/src/qcam/meson.build
> @@ -35,7 +35,7 @@ qcam_resources = files([
>  
>  qcam_deps = [
>      libatomic,
> -    libcamera_dep,
> +    libcamera_public,
>      qt5_dep,
>  ]
>  
> diff --git a/test/controls/meson.build b/test/controls/meson.build
> index 188c96da3336..0103543e1fc2 100644
> --- a/test/controls/meson.build
> +++ b/test/controls/meson.build
> @@ -9,7 +9,7 @@ control_tests = [
>  
>  foreach t : control_tests
>      exe = executable(t[0], t[1],
> -                     dependencies : libcamera_dep,
> +                     dependencies : libcamera_public,
>                       link_with : test_libraries,
>                       include_directories : test_includes_internal)
>      test(t[0], exe, suite : 'controls', is_parallel : false)
> diff --git a/test/meson.build b/test/meson.build
> index b8615e0fd3e6..73eb44d03ad0 100644
> --- a/test/meson.build
> +++ b/test/meson.build
> @@ -55,7 +55,7 @@ internal_tests = [
>  
>  foreach t : public_tests
>      exe = executable(t[0], t[1],
> -                     dependencies : libcamera_dep,
> +                     dependencies : libcamera_public,
>                       link_with : test_libraries,
>                       include_directories : test_includes_public)
>  
> diff --git a/test/stream/meson.build b/test/stream/meson.build
> index 5d3ef5881b44..73608ffdff7f 100644
> --- a/test/stream/meson.build
> +++ b/test/stream/meson.build
> @@ -6,7 +6,7 @@ stream_tests = [
>  
>  foreach t : stream_tests
>      exe = executable(t[0], t[1],
> -                     dependencies : libcamera_dep,
> +                     dependencies : libcamera_public,
>                       link_with : test_libraries,
>                       include_directories : test_includes_internal)
>      test(t[0], exe, suite: 'stream')
> -- 
> 2.30.2
>
Kieran Bingham June 25, 2021, 8:53 a.m. UTC | #26
Hi Laurent,

On 25/06/2021 04:20, Laurent Pinchart wrote:
> On Fri, Jun 25, 2021 at 06:18:31AM +0300, Laurent Pinchart wrote:
>> Hi Kieran,
>>
>> Thank you for the patch.
>>
>> On Fri, Jun 25, 2021 at 02:35:25AM +0100, Kieran Bingham wrote:
>>> The ChromeOS specific Android HAL support was overly-complex to support
>>> linking an additional library, and then passing the built object into
>>> the libcamera.so build.
>>>
>>> Now that it has its own distinct libcamera-hal.so, simplify the CrOS
>>> integration to build directly into that library.
>>>
>>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>>
>> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>>
>>> ---
>>>  src/android/cros/meson.build | 11 +++--------
>>>  src/android/meson.build      | 13 +++----------
>>>  2 files changed, 6 insertions(+), 18 deletions(-)
>>>
>>> diff --git a/src/android/cros/meson.build b/src/android/cros/meson.build
>>> index c2bda70838e2..35995dd814a2 100644
>>> --- a/src/android/cros/meson.build
>>> +++ b/src/android/cros/meson.build
>>> @@ -4,15 +4,10 @@ if get_option('android_platform') != 'cros'
>>>     subdir_done()
>>>  endif
>>>  
>>> -cros_hal_info_sources = files([
>>> +android_hal_sources += files([
>>>      'camera3_hal.cpp',
>>>  ])
>>>  
>>> -cros_hal_info = static_library('cros_hal_info',
>>> -                               cros_hal_info_sources,
>>> -                               dependencies : dependency('libcros_camera'),
>>> -                               c_args : '-Wno-shadow',
> 
> BTW, we're losing -Wno-shadow. I suppose that's fine as there's no .c
> file, but have you compiled this on CrOS to ensure there's no breakage ?

Yes, Sorry  I should have added that to the commit message, that's
intentional.

I'll add:

> The removal of the -Wno-shadow here is intentional, as it is not
> required for compilation of the camera3_hal.o object.



I believe the -Wno-shadow is cargo-culted from a copy paste of the
android_camera_metadata = static_library() definition (where I expect it
/is/ required)

The camea3_hal.cpp does not require -Wno-shadow to compile.



> 
>>> -                               include_directories : [android_includes,
>>> -                                                      libcamera_includes])
>>> +android_deps += dependency('libcros_camera')
>>>  
>>> -android_objects += cros_hal_info.extract_objects('camera3_hal.cpp')
>>> +android_cpp_args += ['-DOS_CHROMEOS']
>>> diff --git a/src/android/meson.build b/src/android/meson.build
>>> index feda3e0998bd..bd58ef964c2a 100644
>>> --- a/src/android/meson.build
>>> +++ b/src/android/meson.build
>>> @@ -37,15 +37,6 @@ endif
>>>  
>>>  android_deps += [libyuv_dep]
>>>  
>>> -android_cpp_args = []
>>> -android_objects = []
>>> -
>>> -if get_option('android_platform') == 'cros'
>>> -    android_cpp_args += ['-DOS_CHROMEOS']
>>> -endif
>>> -
>>> -subdir('cros')
>>> -
>>>  android_hal_sources = files([
>>>      'camera3_hal.cpp',
>>>      'camera_capabilities.cpp',
>>> @@ -63,6 +54,9 @@ android_hal_sources = files([
>>>      'yuv/post_processor_yuv.cpp'
>>>  ])
>>>  
>>> +android_cpp_args = []
>>> +
>>> +subdir('cros')
>>>  subdir('mm')
>>>  
>>>  android_camera_metadata_sources = files([
>>> @@ -80,6 +74,5 @@ libcamera_hal = shared_library('libcamera-hal',
>>>                                 link_with : android_camera_metadata,
>>>                                 install : true,
>>>                                 cpp_args : android_cpp_args,
>>> -                               objects : android_objects,
>>>                                 include_directories : android_includes,
>>>                                 dependencies : android_deps)
>
Kieran Bingham June 25, 2021, 8:59 a.m. UTC | #27
Hi Paul, Hiro,

On 25/06/2021 04:11, paul.elder@ideasonboard.com wrote:
> Hi Hiro,
> 
> On Fri, Jun 25, 2021 at 12:06:40PM +0900, Hirokazu Honda wrote:
>> Hi Kieran, thank you for the patch.
>>
>> On Fri, Jun 25, 2021 at 11:30 AM <paul.elder@ideasonboard.com> wrote:
>>>
>>> Hi Kieran,
>>>
>>> On Fri, Jun 25, 2021 at 02:35:26AM +0100, Kieran Bingham wrote:
>>>> The pkg-config file for the main libcamera.so is generated
>>>> at the top level meson.build.
>>>>
>>>> Move this to the actual core libcamera build structure to be
>>>> consistent and keep it next to the library construction.
>>>>
>>>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>>>
>>> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
>>>
>>>> ---
>>>>  meson.build               | 8 --------
>>>>  src/libcamera/meson.build | 8 ++++++++
>>>>  2 files changed, 8 insertions(+), 8 deletions(-)
>>>>
>>>> diff --git a/meson.build b/meson.build
>>>> index 4d7d936f09e2..6eed0d8c4a44 100644
>>>> --- a/meson.build
>>>> +++ b/meson.build
>>>> @@ -164,14 +164,6 @@ run_command('ln', '-fsT', meson.source_root(), meson.build_root() / 'source')
>>>>
>>>>  configure_file(output : 'config.h', configuration : config_h)
>>>>
>>>> -pkg_mod = import('pkgconfig')
>>>> -pkg_mod.generate(libraries : libcamera,
>>>> -                 version : '1.0',
>>>> -                 name : 'libcamera',
>>>> -                 filebase : 'camera',
>>>> -                 description : 'Complex Camera Support Library',
>>>> -                 subdirs : 'libcamera')
>>>> -
>>>>  # Check for python installation and modules.
>>>>  py_mod = import('python')
>>>>  py_mod.find_installation('python3', modules: py_modules)
>>>> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
>>>> index d9b5bfae69fd..e4c60e736697 100644
>>>> --- a/src/libcamera/meson.build
>>>> +++ b/src/libcamera/meson.build
>>>> @@ -156,4 +156,12 @@ libcamera_dep = declare_dependency(sources : [
>>>>                                     include_directories : libcamera_includes,
>>>>                                     link_with : libcamera)
>>>>
>>>> +pkg_mod = import('pkgconfig')
>>>> +pkg_mod.generate(libraries: libcamera,
>>>> +                 version : '1.0',
>>>> +                 name : 'libcamera',
>>>> +                 filebase : 'camera',
>>
>> This is not related to this change, but why is filebase camera, not libcamera?

As we fix in the next patch, we have historically been creating a
pkg-config file called 'camera.pc' instead of 'libcamera.pc', which is
what the filebase gives us.

This is because when creating this we believed the 'correct' naming for
libcamera artefacts was to drop the 'lib' from the name. (I.e. for
example gstreamer packages are called 'gstreamer-1.0.pc' and not
'libgstreamer.pc').

However, (and I may even have been the cause of that decision, I can't
remember any more) - I don't believe this is the right thing to do at
all now. 'libcamera' is the name of our package, and project. The 'lib'
is integral, so it's brought back in the next patch.


> My understanding is that this patch is for moving this section directly
> without modification, while the next patch changes the filebase from
> camera to libcamera.

Correct ;-)

> Paul
> 
>>
>> Reviewed-by: Hirokazu Honda <hiroh@chromium.org>

Thanks all!


>>
>>>> +                 description : 'Complex Camera Support Library',
>>>> +                 subdirs : 'libcamera')
>>>> +
>>>>  subdir('proxy/worker')
>>>> --
>>>> 2.30.2
>>>>
Kieran Bingham June 25, 2021, 9 a.m. UTC | #28
Hi Laurent,

On 25/06/2021 04:18, Laurent Pinchart wrote:
> Hi Kieran,
> 
> Thank you for the patch.

You're welcome ...

Anything further to add ? ;-)


> 
> On Fri, Jun 25, 2021 at 02:35:26AM +0100, Kieran Bingham wrote:
>> The pkg-config file for the main libcamera.so is generated
>> at the top level meson.build.
>>
>> Move this to the actual core libcamera build structure to be
>> consistent and keep it next to the library construction.
>>
>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>> ---
>>  meson.build               | 8 --------
>>  src/libcamera/meson.build | 8 ++++++++
>>  2 files changed, 8 insertions(+), 8 deletions(-)
>>
>> diff --git a/meson.build b/meson.build
>> index 4d7d936f09e2..6eed0d8c4a44 100644
>> --- a/meson.build
>> +++ b/meson.build
>> @@ -164,14 +164,6 @@ run_command('ln', '-fsT', meson.source_root(), meson.build_root() / 'source')
>>  
>>  configure_file(output : 'config.h', configuration : config_h)
>>  
>> -pkg_mod = import('pkgconfig')
>> -pkg_mod.generate(libraries : libcamera,
>> -                 version : '1.0',
>> -                 name : 'libcamera',
>> -                 filebase : 'camera',
>> -                 description : 'Complex Camera Support Library',
>> -                 subdirs : 'libcamera')
>> -
>>  # Check for python installation and modules.
>>  py_mod = import('python')
>>  py_mod.find_installation('python3', modules: py_modules)
>> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
>> index d9b5bfae69fd..e4c60e736697 100644
>> --- a/src/libcamera/meson.build
>> +++ b/src/libcamera/meson.build
>> @@ -156,4 +156,12 @@ libcamera_dep = declare_dependency(sources : [
>>                                     include_directories : libcamera_includes,
>>                                     link_with : libcamera)
>>  
>> +pkg_mod = import('pkgconfig')
>> +pkg_mod.generate(libraries: libcamera,
>> +                 version : '1.0',
>> +                 name : 'libcamera',
>> +                 filebase : 'camera',
>> +                 description : 'Complex Camera Support Library',
>> +                 subdirs : 'libcamera')
>> +
>>  subdir('proxy/worker')
>
Kieran Bingham June 25, 2021, 9:04 a.m. UTC | #29
Hi Laurent,

On 25/06/2021 04:18, Laurent Pinchart wrote:
> Hi Kieran,
> 
> Thank you for the patch.
> 
> On Fri, Jun 25, 2021 at 02:35:27AM +0100, Kieran Bingham wrote:
>> The libcamera library is moved to the first positional argument of the
>> pkg-config generator to automatically populate the name and filebase
>> values for the package.
>>
>> As part of this, the shared library name is adjusted to the full library
>> name 'libcamera', without relying upon the automatic 'lib' prefix which
>> better represents the component and naming of the library.
>>
>> As a result of this, the pkgconfig file is now named 'libcamera.pc' as
>> opposed to 'camera.pc', and applications desiring to reference libcamera
>> will need to search for 'libcamera' as a dependency rather than
>> 'camera'.
>>
>> The library itself is still created and installed as 'libcamera.so'.
>>
>> An example meson.build file would need to be adjusted as the following:
>>
>> -      dependency('camera', required : true),
>> +      dependency('libcamera', required : true),
>>
>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>> ---
>>  src/libcamera/meson.build | 7 +++----
>>  1 file changed, 3 insertions(+), 4 deletions(-)
>>
>> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
>> index e4c60e736697..387d20843203 100644
>> --- a/src/libcamera/meson.build
>> +++ b/src/libcamera/meson.build
>> @@ -135,8 +135,9 @@ libcamera_deps = [
>>  # runtime if the library is running from an installed location by checking
>>  # for the presence or abscence of the dynamic tag.
>>  
>> -libcamera = shared_library('camera',
>> +libcamera = shared_library('libcamera',
>>                             libcamera_sources,
>> +                           name_prefix : '',
> 
> While I like the end-result for pkg-config, I'm not too fond of this
> particular change as we work around the normal usage of shared_library()
> here to change the name of the .pc file. Could we keep this unchanged,
> and set filebase to 'libcamera' below instead ?

But ... it's the same principle on the shared-library too.

Our project is called 'libcamera' ... not 'camera'...

I can update the commit message to say "Rename the shared library to
maintain the correct and intentional naming of the project" if you prefer?


We still create a shared library called 'libcamera.so' ... the /only/
place where this differs is in the linker command where it becomes
-lcamera ... but that's not really user facing, thanks to the pkg-config
... (and neither is the definition here I guess).




> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
>>                             install : true,
>>                             include_directories : includes,
>>                             build_rpath : '/',
>> @@ -157,10 +158,8 @@ libcamera_dep = declare_dependency(sources : [
>>                                     link_with : libcamera)
>>  
>>  pkg_mod = import('pkgconfig')
>> -pkg_mod.generate(libraries: libcamera,
>> +pkg_mod.generate(libcamera,
>>                   version : '1.0',
>> -                 name : 'libcamera',
>> -                 filebase : 'camera',
>>                   description : 'Complex Camera Support Library',
>>                   subdirs : 'libcamera')
>>  
>
Paul Elder June 25, 2021, 9:05 a.m. UTC | #30
Hi Kieran,

On Fri, Jun 25, 2021 at 02:35:39AM +0100, Kieran Bingham wrote:
> If LIBCAMERA_BASE_PRIVATE is ever exposed on the libcamera public dependencies,
> then the private.h header protection will be circumvented.
> 
> Provide a test which will fail (at compile time) if the LIBCAMERA_BASE_PRIVATE
> define ever leaks to the public dependencies.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  test/meson.build    |  1 +
>  test/public-api.cpp | 25 +++++++++++++++++++++++++
>  2 files changed, 26 insertions(+)
>  create mode 100644 test/public-api.cpp
> 
> diff --git a/test/meson.build b/test/meson.build
> index 73eb44d03ad0..2c3e76546fbc 100644
> --- a/test/meson.build
> +++ b/test/meson.build
> @@ -25,6 +25,7 @@ subdir('v4l2_videodevice')
>  
>  public_tests = [
>      ['geometry',                        'geometry.cpp'],
> +    ['public-api',                      'public-api.cpp'],
>      ['signal',                          'signal.cpp'],
>      ['span',                            'span.cpp'],
>  ]
> diff --git a/test/public-api.cpp b/test/public-api.cpp
> new file mode 100644
> index 000000000000..5afce97c6887
> --- /dev/null
> +++ b/test/public-api.cpp
> @@ -0,0 +1,25 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Copyright (C) 2021, Google Inc.
> + *
> + * public-api.cpp - Public API validation
> + */
> +
> +#include <libcamera/libcamera.h>
> +
> +#include "test.h"
> +
> +class PublicAPITest : public Test
> +{
> +	int run()
> +	{
> +#ifdef LIBCAMERA_BASE_PRIVATE
> +#error "Public Interfaces should not be exposed to LIBCAMERA_BASE_PRIVATE"

s/be exposed to/expose/ ?

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> +		return TestFail;
> +#else
> +		return TestPass;
> +#endif
> +	}
> +};
> +
> +TEST_REGISTER(PublicAPITest)
> -- 
> 2.30.2
>
Kieran Bingham June 25, 2021, 9:26 a.m. UTC | #31
Hi Hiro,

On 25/06/2021 04:48, Hirokazu Honda wrote:
> Hi Kieran, thank you for the patch.
> 
> On Fri, Jun 25, 2021 at 10:35 AM Kieran Bingham
> <kieran.bingham@ideasonboard.com> wrote:
>>
>> Move the event notifier, and associated header updates.
>>
>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>> ---
>>  include/libcamera/{internal => base}/event_notifier.h | 0
>>  include/libcamera/base/meson.build                    | 1 +
>>  include/libcamera/internal/meson.build                | 1 -
>>  src/libcamera/base/event_dispatcher_poll.cpp          | 3 +--
>>  src/libcamera/{ => base}/event_notifier.cpp           | 6 +++---
>>  src/libcamera/base/meson.build                        | 1 +
>>  src/libcamera/device_enumerator_udev.cpp              | 2 +-
>>  src/libcamera/ipc_unixsocket.cpp                      | 3 +--
>>  src/libcamera/meson.build                             | 1 -
>>  src/libcamera/process.cpp                             | 3 +--
>>  src/libcamera/v4l2_device.cpp                         | 2 +-
>>  src/libcamera/v4l2_videodevice.cpp                    | 2 +-
>>  test/event-thread.cpp                                 | 3 +--
>>  test/event.cpp                                        | 3 +--
>>  test/ipa/ipa_interface_test.cpp                       | 2 +-
>>  15 files changed, 14 insertions(+), 19 deletions(-)
>>  rename include/libcamera/{internal => base}/event_notifier.h (100%)
>>  rename src/libcamera/{ => base}/event_notifier.cpp (98%)
>>
>> diff --git a/include/libcamera/internal/event_notifier.h b/include/libcamera/base/event_notifier.h
>> similarity index 100%
> 
> Shall we update a header guard?

Absolutely, thanks - You can tell which ones of these I moved at a
different time from the original set ;-) (and forgot this step).

Will your tag apply with that fixed?



> 
>> rename from include/libcamera/internal/event_notifier.h
>> rename to include/libcamera/base/event_notifier.h
>> diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build
>> index 6fc6c138a5fd..83c664affc88 100644
>> --- a/include/libcamera/base/meson.build
>> +++ b/include/libcamera/base/meson.build
>> @@ -7,6 +7,7 @@ libcamera_base_headers = files([
>>      'class.h',
>>      'event_dispatcher.h',
>>      'event_dispatcher_poll.h',
>> +    'event_notifier.h',
>>      'file.h',
>>      'log.h',
>>      'message.h',
>> diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build
>> index b10285edac27..61af16bfe05d 100644
>> --- a/include/libcamera/internal/meson.build
>> +++ b/include/libcamera/internal/meson.build
>> @@ -22,7 +22,6 @@ libcamera_internal_headers = files([
>>      'device_enumerator.h',
>>      'device_enumerator_sysfs.h',
>>      'device_enumerator_udev.h',
>> -    'event_notifier.h',
>>      'formats.h',
>>      'ipa_manager.h',
>>      'ipa_module.h',
>> diff --git a/src/libcamera/base/event_dispatcher_poll.cpp b/src/libcamera/base/event_dispatcher_poll.cpp
>> index d76ca7fc2c32..5839373a5281 100644
>> --- a/src/libcamera/base/event_dispatcher_poll.cpp
>> +++ b/src/libcamera/base/event_dispatcher_poll.cpp
>> @@ -16,13 +16,12 @@
>>  #include <sys/eventfd.h>
>>  #include <unistd.h>
>>
>> +#include <libcamera/base/event_notifier.h>
>>  #include <libcamera/base/log.h>
>>  #include <libcamera/base/thread.h>
>>  #include <libcamera/base/timer.h>
>>  #include <libcamera/base/utils.h>
>>
>> -#include "libcamera/internal/event_notifier.h"
>> -
>>  /**
>>   * \file base/event_dispatcher_poll.h
>>   */
>> diff --git a/src/libcamera/event_notifier.cpp b/src/libcamera/base/event_notifier.cpp
>> similarity index 98%
>> rename from src/libcamera/event_notifier.cpp
>> rename to src/libcamera/base/event_notifier.cpp
>> index 784016a9f907..fd93c0878c6f 100644
>> --- a/src/libcamera/event_notifier.cpp
>> +++ b/src/libcamera/base/event_notifier.cpp
>> @@ -5,14 +5,14 @@
>>   * event_notifier.cpp - File descriptor event notifier
>>   */
>>
>> -#include "libcamera/internal/event_notifier.h"
>> -
>> -#include <libcamera/camera_manager.h>
>> +#include <libcamera/base/event_notifier.h>
>>
>>  #include <libcamera/base/event_dispatcher.h>
>>  #include <libcamera/base/message.h>
>>  #include <libcamera/base/thread.h>
>>
>> +#include <libcamera/camera_manager.h>
>> +
>>  /**
>>   * \file event_notifier.h
>>   * \brief File descriptor event notifier
>> diff --git a/src/libcamera/base/meson.build b/src/libcamera/base/meson.build
>> index fb8ed79acd8e..a8b04cfc8a5f 100644
>> --- a/src/libcamera/base/meson.build
>> +++ b/src/libcamera/base/meson.build
>> @@ -5,6 +5,7 @@ libcamera_base_sources = files([
>>      'bound_method.cpp',
>>      'event_dispatcher.cpp',
>>      'event_dispatcher_poll.cpp',
>> +    'event_notifier.cpp',
>>      'file.cpp',
>>      'log.cpp',
>>      'message.cpp',
>> diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp
>> index 4b842773fcd6..37a2c5aa55db 100644
>> --- a/src/libcamera/device_enumerator_udev.cpp
>> +++ b/src/libcamera/device_enumerator_udev.cpp
>> @@ -17,9 +17,9 @@
>>  #include <sys/sysmacros.h>
>>  #include <unistd.h>
>>
>> +#include <libcamera/base/event_notifier.h>
>>  #include <libcamera/base/log.h>
>>
>> -#include "libcamera/internal/event_notifier.h"
>>  #include "libcamera/internal/media_device.h"
>>
>>  namespace libcamera {
>> diff --git a/src/libcamera/ipc_unixsocket.cpp b/src/libcamera/ipc_unixsocket.cpp
>> index 1466597077d4..f23eb783bcb5 100644
>> --- a/src/libcamera/ipc_unixsocket.cpp
>> +++ b/src/libcamera/ipc_unixsocket.cpp
>> @@ -12,10 +12,9 @@
>>  #include <sys/socket.h>
>>  #include <unistd.h>
>>
>> +#include <libcamera/base/event_notifier.h>
>>  #include <libcamera/base/log.h>
>>
>> -#include "libcamera/internal/event_notifier.h"
>> -
>>  /**
>>   * \file ipc_unixsocket.h
>>   * \brief IPC mechanism based on Unix sockets
>> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
>> index 58eee14aed97..1f163cfe1225 100644
>> --- a/src/libcamera/meson.build
>> +++ b/src/libcamera/meson.build
>> @@ -15,7 +15,6 @@ libcamera_sources = files([
>>      'delayed_controls.cpp',
>>      'device_enumerator.cpp',
>>      'device_enumerator_sysfs.cpp',
>> -    'event_notifier.cpp',
>>      'file_descriptor.cpp',
>>      'formats.cpp',
>>      'framebuffer_allocator.cpp',
>> diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp
>> index 463380299a65..4fe4ad570b74 100644
>> --- a/src/libcamera/process.cpp
>> +++ b/src/libcamera/process.cpp
>> @@ -20,11 +20,10 @@
>>  #include <unistd.h>
>>  #include <vector>
>>
>> +#include <libcamera/base/event_notifier.h>
>>  #include <libcamera/base/log.h>
>>  #include <libcamera/base/utils.h>
>>
>> -#include "libcamera/internal/event_notifier.h"
>> -
>>  /**
>>   * \file process.h
>>   * \brief Process object
>> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
>> index 334b9b78b812..98d93a12a7be 100644
>> --- a/src/libcamera/v4l2_device.cpp
>> +++ b/src/libcamera/v4l2_device.cpp
>> @@ -16,10 +16,10 @@
>>  #include <sys/syscall.h>
>>  #include <unistd.h>
>>
>> +#include <libcamera/base/event_notifier.h>
>>  #include <libcamera/base/log.h>
>>  #include <libcamera/base/utils.h>
>>
>> -#include "libcamera/internal/event_notifier.h"
>>  #include "libcamera/internal/sysfs.h"
>>
>>  /**
>> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
>> index dc23510bc5aa..3d2d99b46e4e 100644
>> --- a/src/libcamera/v4l2_videodevice.cpp
>> +++ b/src/libcamera/v4l2_videodevice.cpp
>> @@ -21,11 +21,11 @@
>>
>>  #include <linux/version.h>
>>
>> +#include <libcamera/base/event_notifier.h>
>>  #include <libcamera/base/log.h>
>>
>>  #include <libcamera/file_descriptor.h>
>>
>> -#include "libcamera/internal/event_notifier.h"
>>  #include "libcamera/internal/media_device.h"
>>  #include "libcamera/internal/media_object.h"
>>
>> diff --git a/test/event-thread.cpp b/test/event-thread.cpp
>> index 05c5d26d3611..575261664c2f 100644
>> --- a/test/event-thread.cpp
>> +++ b/test/event-thread.cpp
>> @@ -10,11 +10,10 @@
>>  #include <string.h>
>>  #include <unistd.h>
>>
>> +#include <libcamera/base/event_notifier.h>
>>  #include <libcamera/base/thread.h>
>>  #include <libcamera/base/timer.h>
>>
>> -#include "libcamera/internal/event_notifier.h"
>> -
>>  #include "test.h"
>>
>>  using namespace std;
>> diff --git a/test/event.cpp b/test/event.cpp
>> index aa79da99c286..c2274344b7f0 100644
>> --- a/test/event.cpp
>> +++ b/test/event.cpp
>> @@ -10,11 +10,10 @@
>>  #include <unistd.h>
>>
>>  #include <libcamera/base/event_dispatcher.h>
>> +#include <libcamera/base/event_notifier.h>
>>  #include <libcamera/base/thread.h>
>>  #include <libcamera/base/timer.h>
>>
>> -#include "libcamera/internal/event_notifier.h"
>> -
>>  #include "test.h"
>>
>>  using namespace std;
>> diff --git a/test/ipa/ipa_interface_test.cpp b/test/ipa/ipa_interface_test.cpp
>> index 656d86552d85..ee9f26510784 100644
>> --- a/test/ipa/ipa_interface_test.cpp
>> +++ b/test/ipa/ipa_interface_test.cpp
>> @@ -15,11 +15,11 @@
>>  #include <libcamera/ipa/vimc_ipa_proxy.h>
>>
>>  #include <libcamera/base/event_dispatcher.h>
>> +#include <libcamera/base/event_notifier.h>
>>  #include <libcamera/base/thread.h>
>>  #include <libcamera/base/timer.h>
>>
>>  #include "libcamera/internal/device_enumerator.h"
>> -#include "libcamera/internal/event_notifier.h"
>>  #include "libcamera/internal/ipa_manager.h"
>>  #include "libcamera/internal/ipa_module.h"
>>  #include "libcamera/internal/pipeline_handler.h"
>> --
>> 2.30.2
>>
Kieran Bingham June 25, 2021, 9:44 a.m. UTC | #32
Hi Paul,

On 25/06/2021 10:05, paul.elder@ideasonboard.com wrote:
> Hi Kieran,
> 
> On Fri, Jun 25, 2021 at 02:35:39AM +0100, Kieran Bingham wrote:
>> If LIBCAMERA_BASE_PRIVATE is ever exposed on the libcamera public dependencies,
>> then the private.h header protection will be circumvented.
>>
>> Provide a test which will fail (at compile time) if the LIBCAMERA_BASE_PRIVATE
>> define ever leaks to the public dependencies.
>>
>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>> ---
>>  test/meson.build    |  1 +
>>  test/public-api.cpp | 25 +++++++++++++++++++++++++
>>  2 files changed, 26 insertions(+)
>>  create mode 100644 test/public-api.cpp
>>
>> diff --git a/test/meson.build b/test/meson.build
>> index 73eb44d03ad0..2c3e76546fbc 100644
>> --- a/test/meson.build
>> +++ b/test/meson.build
>> @@ -25,6 +25,7 @@ subdir('v4l2_videodevice')
>>  
>>  public_tests = [
>>      ['geometry',                        'geometry.cpp'],
>> +    ['public-api',                      'public-api.cpp'],
>>      ['signal',                          'signal.cpp'],
>>      ['span',                            'span.cpp'],
>>  ]
>> diff --git a/test/public-api.cpp b/test/public-api.cpp
>> new file mode 100644
>> index 000000000000..5afce97c6887
>> --- /dev/null
>> +++ b/test/public-api.cpp
>> @@ -0,0 +1,25 @@
>> +/* SPDX-License-Identifier: GPL-2.0-or-later */
>> +/*
>> + * Copyright (C) 2021, Google Inc.
>> + *
>> + * public-api.cpp - Public API validation
>> + */
>> +
>> +#include <libcamera/libcamera.h>
>> +
>> +#include "test.h"
>> +
>> +class PublicAPITest : public Test
>> +{
>> +	int run()
>> +	{
>> +#ifdef LIBCAMERA_BASE_PRIVATE
>> +#error "Public Interfaces should not be exposed to LIBCAMERA_BASE_PRIVATE"
> 
> s/be exposed to/expose/ ?

Hrm, that's not actually my intention. It would check both cases though.
It's subtle, ...

My intention is to prevent someone adding or changing the meson
dependencies such that somehow libcamera_base_private ends up being a
part of libcamera_public dependency which would then magically make all
public interfaces compile with LIBCAMERA_BASE_PRIVATE defined, and that
would then break all the protection.

But your change, would also be correct and something to protect against
(and which this does protect against) but it's not something I would
expect to happen, as that would imply someone has added a #define
LIBCAMERA_BASE_PRIVATE within one of the API headers (which would then
have the same break.


> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
> 
>> +		return TestFail;
>> +#else
>> +		return TestPass;
>> +#endif
>> +	}
>> +};
>> +
>> +TEST_REGISTER(PublicAPITest)
>> -- 
>> 2.30.2
>>
Kieran Bingham June 25, 2021, 9:57 a.m. UTC | #33
Hi Hiro,

On 25/06/2021 04:22, Hirokazu Honda wrote:
> Hi Kieran, thank you for the patch.
> 
> On Fri, Jun 25, 2021 at 10:35 AM Kieran Bingham
> <kieran.bingham@ideasonboard.com> wrote:
>>
>> The libcameraSourcePath and libcameraBuildPath helper functions are
>> internal and specific to libcamera needs while operating with the meson
>> build system.
>>
>> In preparation for the upcoming move of utils to a common library, move
>> these helpers out of utils and into their own build unit.
>>
>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>> ---
>>  include/libcamera/internal/meson.build    |   1 +
>>  include/libcamera/internal/source-paths.h |  19 ++++
>>  src/libcamera/meson.build                 |   1 +
>>  src/libcamera/source-paths.cpp            | 129 ++++++++++++++++++++++
>>  src/libcamera/utils.cpp                   | 102 -----------------
>>  5 files changed, 150 insertions(+), 102 deletions(-)
>>  create mode 100644 include/libcamera/internal/source-paths.h
>>  create mode 100644 src/libcamera/source-paths.cpp
>>
>> diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build
>> index f019cfb3b0de..e5088177fe8e 100644
>> --- a/include/libcamera/internal/meson.build
>> +++ b/include/libcamera/internal/meson.build
>> @@ -39,6 +39,7 @@ libcamera_internal_headers = files([
>>      'process.h',
>>      'pub_key.h',
>>      'semaphore.h',
>> +    'source-paths.h',
> 
> According to coding style guide
> (https://libcamera.org/coding-style.html), there is no rule about a
> file name.
> But it seems like we use the snake case for file names. So,
> source_paths.h and source_paths.cpp?

Ohhh good spot.

Indeed, all other file names use _ instead of -.

I always prefer the look of '-' ... hence automatically using it ;S

But I will change this now.


> 
>>      'sysfs.h',
>>      'thread.h',
>>      'timer.h',
>> diff --git a/include/libcamera/internal/source-paths.h b/include/libcamera/internal/source-paths.h
>> new file mode 100644
>> index 000000000000..2591ebb1081b
>> --- /dev/null
>> +++ b/include/libcamera/internal/source-paths.h
>> @@ -0,0 +1,19 @@
>> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
>> +/*
>> + * Copyright (C) 2021, Google Inc.
>> + *
>> + * source-paths.h - Identify libcamera source and build paths
>> + */
>> +#ifndef __LIBCAMERA_INTERNAL_SOURCE_PATHS_H__
>> +#define __LIBCAMERA_INTERNAL_SOURCE_PATHS_H__
>> +
>> +#include <string>
>> +
>> +namespace libcamera::utils {
>> +
>> +std::string libcameraBuildPath();
>> +std::string libcameraSourcePath();
>> +
>> +} /* namespace libcamera::utils */
>> +
>> +#endif /* __LIBCAMERA_INTERNAL_SOURCE_PATHS_H__ */
>> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
>> index 387d20843203..e792094f5798 100644
>> --- a/src/libcamera/meson.build
>> +++ b/src/libcamera/meson.build
>> @@ -46,6 +46,7 @@ libcamera_sources = files([
>>      'request.cpp',
>>      'semaphore.cpp',
>>      'signal.cpp',
>> +    'source-paths.cpp',
>>      'stream.cpp',
>>      'sysfs.cpp',
>>      'thread.cpp',
>> diff --git a/src/libcamera/source-paths.cpp b/src/libcamera/source-paths.cpp
>> new file mode 100644
>> index 000000000000..b39f5f853e39
>> --- /dev/null
>> +++ b/src/libcamera/source-paths.cpp
>> @@ -0,0 +1,129 @@
>> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
>> +/*
>> + * Copyright (C) 2021, Google Inc.
>> + *
>> + * source-paths.cpp - Identify libcamera source and build paths
>> + */
>> +
>> +#include "libcamera/internal/source-paths.h"
>> +
>> +#include <dlfcn.h>
>> +#include <elf.h>
>> +#include <link.h>
>> +#include <sys/stat.h>
>> +
>> +#include "libcamera/internal/utils.h"
>> +
>> +/**
>> + * \file source-paths.h
>> + * \brief Identify the build and source path of a not-yet-installed library
>> + */
>> +
>> +/* musl doesn't declare _DYNAMIC in link.h, declare it manually. */
>> +extern ElfW(Dyn) _DYNAMIC[];
>> +
>> +namespace libcamera::utils {
>> +
>> +/**
>> + * \brief Check if libcamera is installed or not
>> + *
>> + * Utilise the build_rpath dynamic tag which is stripped out by meson at
>> + * install time to determine at runtime if the library currently executing
>> + * has been installed or not.
>> + *
>> + * \return True if libcamera is installed, false otherwise
>> + */
>> +bool isLibcameraInstalled()
>> +{
>> +       /*
>> +        * DT_RUNPATH (DT_RPATH when the linker uses old dtags) is removed on
>> +        * install.
>> +        */
>> +       for (const ElfW(Dyn) *dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn) {
>> +               if (dyn->d_tag == DT_RUNPATH || dyn->d_tag == DT_RPATH)
>> +                       return false;
>> +       }
>> +
>> +       return true;
>> +}
>> +
> 
> isLIbcameraInstalled() should be put in anonymous namespace as it is
> used only in .cc file.

Yes, absolutely, I've updated that too.

Thanks!

> 
> With these nits,
> Reviewed-by: Hirokazu Honda<hiroh@chromium.org>
>> +/**
>> + * \brief Retrieve the path to the build directory
>> + *
>> + * During development, it is useful to run libcamera binaries directly from the
>> + * build directory without installing them. This function helps components that
>> + * need to locate resources in the build tree, such as IPA modules or IPA proxy
>> + * workers, by providing them with the path to the root of the build directory.
>> + * Callers can then use it to complement or override searches in system-wide
>> + * directories.
>> + *
>> + * If libcamera has been installed, the build directory path is not available
>> + * and this function returns an empty string.
>> + *
>> + * \return The path to the build directory if running from a build, or an empty
>> + * string otherwise
>> + */
>> +std::string libcameraBuildPath()
>> +{
>> +       if (isLibcameraInstalled())
>> +               return std::string();
>> +
>> +       Dl_info info;
>> +
>> +       /* Look up our own symbol. */
>> +       int ret = dladdr(reinterpret_cast<void *>(libcameraBuildPath), &info);
>> +       if (ret == 0)
>> +               return std::string();
>> +
>> +       std::string path = dirname(info.dli_fname) + "/../../";
>> +
>> +       char *real = realpath(path.c_str(), nullptr);
>> +       if (!real)
>> +               return std::string();
>> +
>> +       path = real;
>> +       free(real);
>> +
>> +       return path + "/";
>> +}
>> +
>> +/**
>> + * \brief Retrieve the path to the source directory
>> + *
>> + * During development, it is useful to run libcamera binaries directly from the
>> + * build directory without installing them. This function helps components that
>> + * need to locate resources in the source tree, such as IPA configuration
>> + * files, by providing them with the path to the root of the source directory.
>> + * Callers can then use it to complement or override searches in system-wide
>> + * directories.
>> + *
>> + * If libcamera has been installed, the source directory path is not available
>> + * and this function returns an empty string.
>> + *
>> + * \return The path to the source directory if running from a build directory,
>> + * or an empty string otherwise
>> + */
>> +std::string libcameraSourcePath()
>> +{
>> +       std::string path = libcameraBuildPath();
>> +       if (path.empty())
>> +               return std::string();
>> +
>> +       path += "source";
>> +
>> +       char *real = realpath(path.c_str(), nullptr);
>> +       if (!real)
>> +               return std::string();
>> +
>> +       path = real;
>> +       free(real);
>> +
>> +       struct stat statbuf;
>> +       int ret = stat(path.c_str(), &statbuf);
>> +       if (ret < 0 || (statbuf.st_mode & S_IFMT) != S_IFDIR)
>> +               return std::string();
>> +
>> +       return path + "/";
>> +}
>> +
>> +} /* namespace libcamera::utils */
>> diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp
>> index 49b8fc9e211f..42f82d6158dd 100644
>> --- a/src/libcamera/utils.cpp
>> +++ b/src/libcamera/utils.cpp
>> @@ -351,108 +351,6 @@ std::string toAscii(const std::string &str)
>>         return ret;
>>  }
>>
>> -/**
>> - * \brief Check if libcamera is installed or not
>> - *
>> - * Utilise the build_rpath dynamic tag which is stripped out by meson at
>> - * install time to determine at runtime if the library currently executing
>> - * has been installed or not.
>> - *
>> - * \return True if libcamera is installed, false otherwise
>> - */
>> -bool isLibcameraInstalled()
>> -{
>> -       /*
>> -        * DT_RUNPATH (DT_RPATH when the linker uses old dtags) is removed on
>> -        * install.
>> -        */
>> -       for (const ElfW(Dyn) *dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn) {
>> -               if (dyn->d_tag == DT_RUNPATH || dyn->d_tag == DT_RPATH)
>> -                       return false;
>> -       }
>> -
>> -       return true;
>> -}
>> -
>> -/**
>> - * \brief Retrieve the path to the build directory
>> - *
>> - * During development, it is useful to run libcamera binaries directly from the
>> - * build directory without installing them. This function helps components that
>> - * need to locate resources in the build tree, such as IPA modules or IPA proxy
>> - * workers, by providing them with the path to the root of the build directory.
>> - * Callers can then use it to complement or override searches in system-wide
>> - * directories.
>> - *
>> - * If libcamera has been installed, the build directory path is not available
>> - * and this function returns an empty string.
>> - *
>> - * \return The path to the build directory if running from a build, or an empty
>> - * string otherwise
>> - */
>> -std::string libcameraBuildPath()
>> -{
>> -       if (isLibcameraInstalled())
>> -               return std::string();
>> -
>> -       Dl_info info;
>> -
>> -       /* Look up our own symbol. */
>> -       int ret = dladdr(reinterpret_cast<void *>(libcameraBuildPath), &info);
>> -       if (ret == 0)
>> -               return std::string();
>> -
>> -       std::string path = dirname(info.dli_fname) + "/../../";
>> -
>> -       char *real = realpath(path.c_str(), nullptr);
>> -       if (!real)
>> -               return std::string();
>> -
>> -       path = real;
>> -       free(real);
>> -
>> -       return path + "/";
>> -}
>> -
>> -/**
>> - * \brief Retrieve the path to the source directory
>> - *
>> - * During development, it is useful to run libcamera binaries directly from the
>> - * build directory without installing them. This function helps components that
>> - * need to locate resources in the source tree, such as IPA configuration
>> - * files, by providing them with the path to the root of the source directory.
>> - * Callers can then use it to complement or override searches in system-wide
>> - * directories.
>> - *
>> - * If libcamera has been installed, the source directory path is not available
>> - * and this function returns an empty string.
>> - *
>> - * \return The path to the source directory if running from a build directory,
>> - * or an empty string otherwise
>> - */
>> -std::string libcameraSourcePath()
>> -{
>> -       std::string path = libcameraBuildPath();
>> -       if (path.empty())
>> -               return std::string();
>> -
>> -       path += "source";
>> -
>> -       char *real = realpath(path.c_str(), nullptr);
>> -       if (!real)
>> -               return std::string();
>> -
>> -       path = real;
>> -       free(real);
>> -
>> -       struct stat statbuf;
>> -       int ret = stat(path.c_str(), &statbuf);
>> -       if (ret < 0 || (statbuf.st_mode & S_IFMT) != S_IFDIR)
>> -               return std::string();
>> -
>> -       return path + "/";
>> -}
>> -
>>  /**
>>   * \fn alignDown(unsigned int value, unsigned int alignment)
>>   * \brief Align \a value down to \a alignment
>> --
>> 2.30.2
>>
Kieran Bingham June 25, 2021, 10 a.m. UTC | #34
Hi Hiro,

On 25/06/2021 04:32, Hirokazu Honda wrote:
> Hi Kieran, thank you for the patch.
> 
> On Fri, Jun 25, 2021 at 10:35 AM Kieran Bingham
> <kieran.bingham@ideasonboard.com> wrote:
>>
>> The libcamera-base.so will feature internal support functionality
>> that is utilised by libcamera, and can be shared in other places.
>>
>> This new library provides a layer beneath libcamera which provides
>> common abstractions to internal objects.
>>
>> A pkg-config file is generated and named libcamera-base.pc which allows
>> components such as external IPA modules to link directly to this library
>> if they need. Normal applications will reference this library through
>> the Requires: statement provided by the libcamera.pc package
>> configuration, and linkage will be handled automatically through the
>> pkg-config mechanisms.
>>
> 
> I would comment that this patch doesn't move anything to libcamera-base.so.

I've added

No code is moved to this library yet, this patch only introduces the
framework, construction and linkage.


>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>> ---
>>  Documentation/meson.build          |  2 ++
>>  include/libcamera/base/meson.build |  9 +++++++++
>>  include/libcamera/meson.build      |  1 +
>>  src/libcamera/base/meson.build     | 27 +++++++++++++++++++++++++++
>>  src/libcamera/meson.build          |  4 ++++
>>  5 files changed, 43 insertions(+)
>>  create mode 100644 include/libcamera/base/meson.build
>>  create mode 100644 src/libcamera/base/meson.build
>>
>> diff --git a/Documentation/meson.build b/Documentation/meson.build
>> index 9ecf4dfcf79f..808076e056d0 100644
>> --- a/Documentation/meson.build
>> +++ b/Documentation/meson.build
>> @@ -27,6 +27,8 @@ if doxygen.found() and dot.found()
>>                        libcamera_ipa_interfaces,
>>                        libcamera_public_headers,
>>                        libcamera_sources,
>> +                      libcamera_base_headers,
>> +                      libcamera_base_sources,
>>                        libipa_headers,
>>                        libipa_sources,
>>                    ],
>> diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build
>> new file mode 100644
>> index 000000000000..0a7a57b81191
>> --- /dev/null
>> +++ b/include/libcamera/base/meson.build
>> @@ -0,0 +1,9 @@
>> +# SPDX-License-Identifier: CC0-1.0
>> +
>> +libcamera_base_include_dir = libcamera_include_dir / 'base'
>> +
>> +libcamera_base_headers = files([
>> +])
>> +
>> +install_headers(libcamera_base_headers,
>> +                subdir: libcamera_base_include_dir)
>> diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build
>> index 086c958b0a53..1fa1bf4a4e78 100644
>> --- a/include/libcamera/meson.build
>> +++ b/include/libcamera/meson.build
>> @@ -25,6 +25,7 @@ include_dir = libcamera_include_dir / 'libcamera'
>>
>>  subdir('internal')
>>  subdir('ipa')
>> +subdir('base')
> 
> nit: can we put subdir('base') to before subdir ('internal'). Or base
> will be dependent on internal and ipa?

Indeed, this should be sorted correctly, both alphabetically and because
base should come first.


> Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
>>
>>  install_headers(libcamera_public_headers,
>>                  subdir : include_dir)
>> diff --git a/src/libcamera/base/meson.build b/src/libcamera/base/meson.build
>> new file mode 100644
>> index 000000000000..3d58fea36ef5
>> --- /dev/null
>> +++ b/src/libcamera/base/meson.build
>> @@ -0,0 +1,27 @@
>> +# SPDX-License-Identifier: CC0-1.0
>> +
>> +libcamera_base_sources = files([
>> +])
>> +
>> +libcamera_base_deps = [
>> +]
>> +
>> +libcamera_base_lib = shared_library('libcamera-base',
>> +                                    [libcamera_base_sources, libcamera_base_headers],
>> +                                    name_prefix : '',
>> +                                    install : true,
>> +                                    cpp_args : libcamera_cpp_args,
>> +                                    include_directories : libcamera_includes,
>> +                                    dependencies : libcamera_base_deps)
>> +
>> +libcamera_base = declare_dependency(sources : [
>> +                                        libcamera_base_headers,
>> +                                    ],
>> +                                    include_directories : libcamera_includes,
>> +                                    link_with : libcamera_base_lib)
>> +
>> +pkg_mod = import('pkgconfig')
>> +pkg_mod.generate(libcamera_base_lib,
>> +                 version : '1.0',
>> +                 description : 'Camera support base utility library',
>> +                 subdirs : 'libcamera')
>> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
>> index e792094f5798..eaf3cec8cba7 100644
>> --- a/src/libcamera/meson.build
>> +++ b/src/libcamera/meson.build
>> @@ -67,6 +67,7 @@ includes = [
>>      libcamera_includes,
>>  ]
>>
>> +subdir('base')
>>  subdir('ipa')
>>  subdir('pipeline')
>>  subdir('proxy')
>> @@ -128,6 +129,7 @@ libcamera_deps = [
>>      libgnutls,
>>      liblttng,
>>      libudev,
>> +    libcamera_base,
>>      dependency('threads'),
>>  ]
>>
>> @@ -156,10 +158,12 @@ libcamera_dep = declare_dependency(sources : [
>>                                         libcamera_generated_ipa_headers,
>>                                     ],
>>                                     include_directories : libcamera_includes,
>> +                                   dependencies: libcamera_base,
>>                                     link_with : libcamera)
>>
>>  pkg_mod = import('pkgconfig')
>>  pkg_mod.generate(libcamera,
>> +                 libraries : libcamera_base_lib,
>>                   version : '1.0',
>>                   description : 'Complex Camera Support Library',
>>                   subdirs : 'libcamera')
>> --
>> 2.30.2
>>
Kieran Bingham June 25, 2021, 10:07 a.m. UTC | #35
Hi Hiro,

On 25/06/2021 04:38, Hirokazu Honda wrote:
> Hi Kieran,
> 
> On Fri, Jun 25, 2021 at 10:35 AM Kieran Bingham
> <kieran.bingham@ideasonboard.com> wrote:
>>
>> Move the class support infrastructure to the base library.
>>
>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>> ---
>>  include/libcamera/{ => base}/class.h            | 0
>>  include/libcamera/base/meson.build              | 1 +
>>  include/libcamera/buffer.h                      | 3 ++-
>>  include/libcamera/camera.h                      | 3 ++-
>>  include/libcamera/camera_manager.h              | 3 ++-
>>  include/libcamera/controls.h                    | 3 ++-
>>  include/libcamera/framebuffer_allocator.h       | 2 +-
>>  include/libcamera/internal/buffer.h             | 3 ++-
>>  include/libcamera/internal/byte_stream_buffer.h | 3 ++-
>>  include/libcamera/internal/camera_sensor.h      | 3 ++-
>>  include/libcamera/internal/file.h               | 3 ++-
>>  include/libcamera/internal/log.h                | 3 +--
>>  include/libcamera/internal/media_object.h       | 2 +-
>>  include/libcamera/internal/pipeline_handler.h   | 3 ++-
>>  include/libcamera/internal/v4l2_subdevice.h     | 3 ++-
>>  include/libcamera/internal/v4l2_videodevice.h   | 3 ++-
>>  include/libcamera/meson.build                   | 1 -
>>  include/libcamera/request.h                     | 3 ++-
>>  src/android/camera_buffer.h                     | 3 ++-
>>  src/android/camera_capabilities.h               | 3 ++-
>>  src/android/camera_hal_config.h                 | 2 +-
>>  src/libcamera/{ => base}/class.cpp              | 2 +-
>>  src/libcamera/base/meson.build                  | 1 +
>>  src/libcamera/meson.build                       | 1 -
>>  24 files changed, 35 insertions(+), 22 deletions(-)
>>  rename include/libcamera/{ => base}/class.h (100%)
>>  rename src/libcamera/{ => base}/class.cpp (99%)
>>
>> diff --git a/include/libcamera/class.h b/include/libcamera/base/class.h
>> similarity index 100%
>> rename from include/libcamera/class.h
>> rename to include/libcamera/base/class.h
> 
> Shall we change a header guard from __LIBCAMERA_CLASS_H__ to
> __LIBCAMERA_BASE_CLASS_H__?


Ayee - I missed it - absolutely.

I've updated with:

diff --git a/include/libcamera/base/class.h b/include/libcamera/base/class.h
index f384a4889588..a07dac057331 100644
--- a/include/libcamera/base/class.h
+++ b/include/libcamera/base/class.h
@@ -4,8 +4,8 @@
  *
  * class.h - Utilities and helpers for classes
  */
-#ifndef __LIBCAMERA_CLASS_H__
-#define __LIBCAMERA_CLASS_H__
+#ifndef __LIBCAMERA_BASE_CLASS_H__
+#define __LIBCAMERA_BASE_CLASS_H__

 #include <memory>

(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? y
@@ -102,4 +102,4 @@ private:

 } /* namespace libcamera */

-#endif /* __LIBCAMERA_CLASS_H__ */
+#endif /* __LIBCAMERA_BASE_CLASS_H__ */

And I've missed these on the other files I moved in the early hours of
this morning, so I'll make the same changes to those as well.

Does your tag apply with this change added?

(although I suspect I'm going to have to send this series out as a v2
anyway).


>> diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build
>> index 9f0ba6b0e10c..2db756c504c9 100644
>> --- a/include/libcamera/base/meson.build
>> +++ b/include/libcamera/base/meson.build
>> @@ -3,6 +3,7 @@
>>  libcamera_base_include_dir = libcamera_include_dir / 'base'
>>
>>  libcamera_base_headers = files([
>> +    'class.h',
>>      'utils.h',
>>  ])
>>
>> diff --git a/include/libcamera/buffer.h b/include/libcamera/buffer.h
>> index e0af00900409..323d1cba41a9 100644
>> --- a/include/libcamera/buffer.h
>> +++ b/include/libcamera/buffer.h
>> @@ -10,7 +10,8 @@
>>  #include <stdint.h>
>>  #include <vector>
>>
>> -#include <libcamera/class.h>
>> +#include <libcamera/base/class.h>
>> +
>>  #include <libcamera/file_descriptor.h>
>>
>>  namespace libcamera {
>> diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h
>> index d71641805c0a..ea0914009c2b 100644
>> --- a/include/libcamera/camera.h
>> +++ b/include/libcamera/camera.h
>> @@ -12,7 +12,8 @@
>>  #include <stdint.h>
>>  #include <string>
>>
>> -#include <libcamera/class.h>
>> +#include <libcamera/base/class.h>
>> +
>>  #include <libcamera/controls.h>
>>  #include <libcamera/object.h>
>>  #include <libcamera/request.h>
>> diff --git a/include/libcamera/camera_manager.h b/include/libcamera/camera_manager.h
>> index c2f0b786da8e..5deede035115 100644
>> --- a/include/libcamera/camera_manager.h
>> +++ b/include/libcamera/camera_manager.h
>> @@ -12,7 +12,8 @@
>>  #include <sys/types.h>
>>  #include <vector>
>>
>> -#include <libcamera/class.h>
>> +#include <libcamera/base/class.h>
>> +
>>  #include <libcamera/object.h>
>>  #include <libcamera/signal.h>
>>
>> diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
>> index 1c9b37e617bc..f62b6cf055d6 100644
>> --- a/include/libcamera/controls.h
>> +++ b/include/libcamera/controls.h
>> @@ -14,7 +14,8 @@
>>  #include <unordered_map>
>>  #include <vector>
>>
>> -#include <libcamera/class.h>
>> +#include <libcamera/base/class.h>
>> +
>>  #include <libcamera/geometry.h>
>>  #include <libcamera/span.h>
>>
>> diff --git a/include/libcamera/framebuffer_allocator.h b/include/libcamera/framebuffer_allocator.h
>> index 0c85631a1da2..cbc9ce101889 100644
>> --- a/include/libcamera/framebuffer_allocator.h
>> +++ b/include/libcamera/framebuffer_allocator.h
>> @@ -11,7 +11,7 @@
>>  #include <memory>
>>  #include <vector>
>>
>> -#include <libcamera/class.h>
>> +#include <libcamera/base/class.h>
>>
>>  namespace libcamera {
>>
>> diff --git a/include/libcamera/internal/buffer.h b/include/libcamera/internal/buffer.h
>> index 9da1fbd12c27..91dd24969385 100644
>> --- a/include/libcamera/internal/buffer.h
>> +++ b/include/libcamera/internal/buffer.h
>> @@ -10,7 +10,8 @@
>>  #include <sys/mman.h>
>>  #include <vector>
>>
>> -#include <libcamera/class.h>
>> +#include <libcamera/base/class.h>
>> +
>>  #include <libcamera/buffer.h>
>>  #include <libcamera/span.h>
>>
>> diff --git a/include/libcamera/internal/byte_stream_buffer.h b/include/libcamera/internal/byte_stream_buffer.h
>> index 866cb9b0b2a6..7eefb1a71f07 100644
>> --- a/include/libcamera/internal/byte_stream_buffer.h
>> +++ b/include/libcamera/internal/byte_stream_buffer.h
>> @@ -11,7 +11,8 @@
>>  #include <stdint.h>
>>  #include <type_traits>
>>
>> -#include <libcamera/class.h>
>> +#include <libcamera/base/class.h>
>> +
>>  #include <libcamera/span.h>
>>
>>  namespace libcamera {
>> diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h
>> index e133ebf45bf7..7bc540619721 100644
>> --- a/include/libcamera/internal/camera_sensor.h
>> +++ b/include/libcamera/internal/camera_sensor.h
>> @@ -11,7 +11,8 @@
>>  #include <string>
>>  #include <vector>
>>
>> -#include <libcamera/class.h>
>> +#include <libcamera/base/class.h>
>> +
>>  #include <libcamera/controls.h>
>>  #include <libcamera/geometry.h>
>>  #include <libcamera/ipa/core_ipa_interface.h>
>> diff --git a/include/libcamera/internal/file.h b/include/libcamera/internal/file.h
>> index f0b313a5faae..44621ceb4c19 100644
>> --- a/include/libcamera/internal/file.h
>> +++ b/include/libcamera/internal/file.h
>> @@ -11,7 +11,8 @@
>>  #include <string>
>>  #include <sys/types.h>
>>
>> -#include <libcamera/class.h>
>> +#include <libcamera/base/class.h>
>> +
>>  #include <libcamera/span.h>
>>
>>  namespace libcamera {
>> diff --git a/include/libcamera/internal/log.h b/include/libcamera/internal/log.h
>> index 9c2beab6a33a..82e55a623e04 100644
>> --- a/include/libcamera/internal/log.h
>> +++ b/include/libcamera/internal/log.h
>> @@ -10,8 +10,7 @@
>>  #include <chrono>
>>  #include <sstream>
>>
>> -#include <libcamera/class.h>
>> -
>> +#include <libcamera/base/class.h>
>>  #include <libcamera/base/utils.h>
>>
>>  namespace libcamera {
>> diff --git a/include/libcamera/internal/media_object.h b/include/libcamera/internal/media_object.h
>> index 1c82c27928a8..2f5d33e1903e 100644
>> --- a/include/libcamera/internal/media_object.h
>> +++ b/include/libcamera/internal/media_object.h
>> @@ -12,7 +12,7 @@
>>
>>  #include <linux/media.h>
>>
>> -#include <libcamera/class.h>
>> +#include <libcamera/base/class.h>
>>
>>  namespace libcamera {
>>
>> diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h
>> index 31dadf285a58..8beb6b76dd3f 100644
>> --- a/include/libcamera/internal/pipeline_handler.h
>> +++ b/include/libcamera/internal/pipeline_handler.h
>> @@ -15,7 +15,8 @@
>>  #include <sys/types.h>
>>  #include <vector>
>>
>> -#include <libcamera/class.h>
>> +#include <libcamera/base/class.h>
>> +
>>  #include <libcamera/controls.h>
>>  #include <libcamera/object.h>
>>  #include <libcamera/stream.h>
>> diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h
>> index d2b9ca55439e..d07dd6b444d0 100644
>> --- a/include/libcamera/internal/v4l2_subdevice.h
>> +++ b/include/libcamera/internal/v4l2_subdevice.h
>> @@ -11,7 +11,8 @@
>>  #include <string>
>>  #include <vector>
>>
>> -#include <libcamera/class.h>
>> +#include <libcamera/base/class.h>
>> +
>>  #include <libcamera/geometry.h>
>>
>>  #include "libcamera/internal/formats.h"
>> diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h
>> index 7938343bba8d..227d015e8937 100644
>> --- a/include/libcamera/internal/v4l2_videodevice.h
>> +++ b/include/libcamera/internal/v4l2_videodevice.h
>> @@ -16,8 +16,9 @@
>>
>>  #include <linux/videodev2.h>
>>
>> +#include <libcamera/base/class.h>
>> +
>>  #include <libcamera/buffer.h>
>> -#include <libcamera/class.h>
>>  #include <libcamera/geometry.h>
>>  #include <libcamera/pixel_format.h>
>>  #include <libcamera/signal.h>
>> diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build
>> index 1fa1bf4a4e78..7cba3de6ca96 100644
>> --- a/include/libcamera/meson.build
>> +++ b/include/libcamera/meson.build
>> @@ -5,7 +5,6 @@ libcamera_public_headers = files([
>>      'buffer.h',
>>      'camera.h',
>>      'camera_manager.h',
>> -    'class.h',
>>      'compiler.h',
>>      'controls.h',
>>      'file_descriptor.h',
>> diff --git a/include/libcamera/request.h b/include/libcamera/request.h
>> index 5596901ddd8e..00c646fea7f2 100644
>> --- a/include/libcamera/request.h
>> +++ b/include/libcamera/request.h
>> @@ -13,7 +13,8 @@
>>  #include <string>
>>  #include <unordered_set>
>>
>> -#include <libcamera/class.h>
>> +#include <libcamera/base/class.h>
>> +
>>  #include <libcamera/controls.h>
>>  #include <libcamera/signal.h>
>>
>> diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h
>> index c88124b2b3f3..e850c4e36668 100644
>> --- a/src/android/camera_buffer.h
>> +++ b/src/android/camera_buffer.h
>> @@ -9,7 +9,8 @@
>>
>>  #include <hardware/camera3.h>
>>
>> -#include <libcamera/class.h>
>> +#include <libcamera/base/class.h>
>> +
>>  #include <libcamera/span.h>
>>
>>  class CameraBuffer final : public libcamera::Extensible
>> diff --git a/src/android/camera_capabilities.h b/src/android/camera_capabilities.h
>> index f511607bbd90..4f5be82595d6 100644
>> --- a/src/android/camera_capabilities.h
>> +++ b/src/android/camera_capabilities.h
>> @@ -11,8 +11,9 @@
>>  #include <memory>
>>  #include <vector>
>>
>> +#include <libcamera/base/class.h>
>> +
>>  #include <libcamera/camera.h>
>> -#include <libcamera/class.h>
>>  #include <libcamera/formats.h>
>>  #include <libcamera/geometry.h>
>>
>> diff --git a/src/android/camera_hal_config.h b/src/android/camera_hal_config.h
>> index 97dc69c1def5..a79d5d6c42dc 100644
>> --- a/src/android/camera_hal_config.h
>> +++ b/src/android/camera_hal_config.h
>> @@ -10,7 +10,7 @@
>>  #include <map>
>>  #include <string>
>>
>> -#include <libcamera/class.h>
>> +#include <libcamera/base/class.h>
>>
>>  struct CameraConfigData {
>>         int facing = -1;
>> diff --git a/src/libcamera/class.cpp b/src/libcamera/base/class.cpp
>> similarity index 99%
>> rename from src/libcamera/class.cpp
>> rename to src/libcamera/base/class.cpp
>> index 28c35633d7db..165beafc243d 100644
>> --- a/src/libcamera/class.cpp
>> +++ b/src/libcamera/base/class.cpp
>> @@ -5,7 +5,7 @@
>>   * class.cpp - Utilities and helpers for classes
>>   */
>>
>> -#include <libcamera/class.h>
>> +#include <libcamera/base/class.h>
>>
>>  /**
>>   * \file class.h
>> diff --git a/src/libcamera/base/meson.build b/src/libcamera/base/meson.build
>> index 6d9ec37414f8..302a288685d3 100644
>> --- a/src/libcamera/base/meson.build
>> +++ b/src/libcamera/base/meson.build
>> @@ -1,6 +1,7 @@
>>  # SPDX-License-Identifier: CC0-1.0
>>
>>  libcamera_base_sources = files([
>> +    'class.cpp',
>>      'utils.cpp',
>>  ])
>>
>> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
>> index ac401c25d498..a341004c0c19 100644
>> --- a/src/libcamera/meson.build
>> +++ b/src/libcamera/meson.build
>> @@ -10,7 +10,6 @@ libcamera_sources = files([
>>      'camera_manager.cpp',
>>      'camera_sensor.cpp',
>>      'camera_sensor_properties.cpp',
>> -    'class.cpp',
>>      'controls.cpp',
>>      'control_serializer.cpp',
>>      'control_validator.cpp',
>> --
>> 2.30.2
>>
Hirokazu Honda June 25, 2021, 10:24 a.m. UTC | #36
Hi Kieran,

On Fri, Jun 25, 2021 at 6:26 PM Kieran Bingham
<kieran.bingham@ideasonboard.com> wrote:
>
> Hi Hiro,
>
> On 25/06/2021 04:48, Hirokazu Honda wrote:
> > Hi Kieran, thank you for the patch.
> >
> > On Fri, Jun 25, 2021 at 10:35 AM Kieran Bingham
> > <kieran.bingham@ideasonboard.com> wrote:
> >>
> >> Move the event notifier, and associated header updates.
> >>
> >> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> >> ---
> >>  include/libcamera/{internal => base}/event_notifier.h | 0
> >>  include/libcamera/base/meson.build                    | 1 +
> >>  include/libcamera/internal/meson.build                | 1 -
> >>  src/libcamera/base/event_dispatcher_poll.cpp          | 3 +--
> >>  src/libcamera/{ => base}/event_notifier.cpp           | 6 +++---
> >>  src/libcamera/base/meson.build                        | 1 +
> >>  src/libcamera/device_enumerator_udev.cpp              | 2 +-
> >>  src/libcamera/ipc_unixsocket.cpp                      | 3 +--
> >>  src/libcamera/meson.build                             | 1 -
> >>  src/libcamera/process.cpp                             | 3 +--
> >>  src/libcamera/v4l2_device.cpp                         | 2 +-
> >>  src/libcamera/v4l2_videodevice.cpp                    | 2 +-
> >>  test/event-thread.cpp                                 | 3 +--
> >>  test/event.cpp                                        | 3 +--
> >>  test/ipa/ipa_interface_test.cpp                       | 2 +-
> >>  15 files changed, 14 insertions(+), 19 deletions(-)
> >>  rename include/libcamera/{internal => base}/event_notifier.h (100%)
> >>  rename src/libcamera/{ => base}/event_notifier.cpp (98%)
> >>
> >> diff --git a/include/libcamera/internal/event_notifier.h b/include/libcamera/base/event_notifier.h
> >> similarity index 100%
> >
> > Shall we update a header guard?
>
> Absolutely, thanks - You can tell which ones of these I moved at a
> different time from the original set ;-) (and forgot this step).
>
> Will your tag apply with that fixed?
>

Yep, with the fix,
Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
>
>
> >
> >> rename from include/libcamera/internal/event_notifier.h
> >> rename to include/libcamera/base/event_notifier.h
> >> diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build
> >> index 6fc6c138a5fd..83c664affc88 100644
> >> --- a/include/libcamera/base/meson.build
> >> +++ b/include/libcamera/base/meson.build
> >> @@ -7,6 +7,7 @@ libcamera_base_headers = files([
> >>      'class.h',
> >>      'event_dispatcher.h',
> >>      'event_dispatcher_poll.h',
> >> +    'event_notifier.h',
> >>      'file.h',
> >>      'log.h',
> >>      'message.h',
> >> diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build
> >> index b10285edac27..61af16bfe05d 100644
> >> --- a/include/libcamera/internal/meson.build
> >> +++ b/include/libcamera/internal/meson.build
> >> @@ -22,7 +22,6 @@ libcamera_internal_headers = files([
> >>      'device_enumerator.h',
> >>      'device_enumerator_sysfs.h',
> >>      'device_enumerator_udev.h',
> >> -    'event_notifier.h',
> >>      'formats.h',
> >>      'ipa_manager.h',
> >>      'ipa_module.h',
> >> diff --git a/src/libcamera/base/event_dispatcher_poll.cpp b/src/libcamera/base/event_dispatcher_poll.cpp
> >> index d76ca7fc2c32..5839373a5281 100644
> >> --- a/src/libcamera/base/event_dispatcher_poll.cpp
> >> +++ b/src/libcamera/base/event_dispatcher_poll.cpp
> >> @@ -16,13 +16,12 @@
> >>  #include <sys/eventfd.h>
> >>  #include <unistd.h>
> >>
> >> +#include <libcamera/base/event_notifier.h>
> >>  #include <libcamera/base/log.h>
> >>  #include <libcamera/base/thread.h>
> >>  #include <libcamera/base/timer.h>
> >>  #include <libcamera/base/utils.h>
> >>
> >> -#include "libcamera/internal/event_notifier.h"
> >> -
> >>  /**
> >>   * \file base/event_dispatcher_poll.h
> >>   */
> >> diff --git a/src/libcamera/event_notifier.cpp b/src/libcamera/base/event_notifier.cpp
> >> similarity index 98%
> >> rename from src/libcamera/event_notifier.cpp
> >> rename to src/libcamera/base/event_notifier.cpp
> >> index 784016a9f907..fd93c0878c6f 100644
> >> --- a/src/libcamera/event_notifier.cpp
> >> +++ b/src/libcamera/base/event_notifier.cpp
> >> @@ -5,14 +5,14 @@
> >>   * event_notifier.cpp - File descriptor event notifier
> >>   */
> >>
> >> -#include "libcamera/internal/event_notifier.h"
> >> -
> >> -#include <libcamera/camera_manager.h>
> >> +#include <libcamera/base/event_notifier.h>
> >>
> >>  #include <libcamera/base/event_dispatcher.h>
> >>  #include <libcamera/base/message.h>
> >>  #include <libcamera/base/thread.h>
> >>
> >> +#include <libcamera/camera_manager.h>
> >> +
> >>  /**
> >>   * \file event_notifier.h
> >>   * \brief File descriptor event notifier
> >> diff --git a/src/libcamera/base/meson.build b/src/libcamera/base/meson.build
> >> index fb8ed79acd8e..a8b04cfc8a5f 100644
> >> --- a/src/libcamera/base/meson.build
> >> +++ b/src/libcamera/base/meson.build
> >> @@ -5,6 +5,7 @@ libcamera_base_sources = files([
> >>      'bound_method.cpp',
> >>      'event_dispatcher.cpp',
> >>      'event_dispatcher_poll.cpp',
> >> +    'event_notifier.cpp',
> >>      'file.cpp',
> >>      'log.cpp',
> >>      'message.cpp',
> >> diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp
> >> index 4b842773fcd6..37a2c5aa55db 100644
> >> --- a/src/libcamera/device_enumerator_udev.cpp
> >> +++ b/src/libcamera/device_enumerator_udev.cpp
> >> @@ -17,9 +17,9 @@
> >>  #include <sys/sysmacros.h>
> >>  #include <unistd.h>
> >>
> >> +#include <libcamera/base/event_notifier.h>
> >>  #include <libcamera/base/log.h>
> >>
> >> -#include "libcamera/internal/event_notifier.h"
> >>  #include "libcamera/internal/media_device.h"
> >>
> >>  namespace libcamera {
> >> diff --git a/src/libcamera/ipc_unixsocket.cpp b/src/libcamera/ipc_unixsocket.cpp
> >> index 1466597077d4..f23eb783bcb5 100644
> >> --- a/src/libcamera/ipc_unixsocket.cpp
> >> +++ b/src/libcamera/ipc_unixsocket.cpp
> >> @@ -12,10 +12,9 @@
> >>  #include <sys/socket.h>
> >>  #include <unistd.h>
> >>
> >> +#include <libcamera/base/event_notifier.h>
> >>  #include <libcamera/base/log.h>
> >>
> >> -#include "libcamera/internal/event_notifier.h"
> >> -
> >>  /**
> >>   * \file ipc_unixsocket.h
> >>   * \brief IPC mechanism based on Unix sockets
> >> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> >> index 58eee14aed97..1f163cfe1225 100644
> >> --- a/src/libcamera/meson.build
> >> +++ b/src/libcamera/meson.build
> >> @@ -15,7 +15,6 @@ libcamera_sources = files([
> >>      'delayed_controls.cpp',
> >>      'device_enumerator.cpp',
> >>      'device_enumerator_sysfs.cpp',
> >> -    'event_notifier.cpp',
> >>      'file_descriptor.cpp',
> >>      'formats.cpp',
> >>      'framebuffer_allocator.cpp',
> >> diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp
> >> index 463380299a65..4fe4ad570b74 100644
> >> --- a/src/libcamera/process.cpp
> >> +++ b/src/libcamera/process.cpp
> >> @@ -20,11 +20,10 @@
> >>  #include <unistd.h>
> >>  #include <vector>
> >>
> >> +#include <libcamera/base/event_notifier.h>
> >>  #include <libcamera/base/log.h>
> >>  #include <libcamera/base/utils.h>
> >>
> >> -#include "libcamera/internal/event_notifier.h"
> >> -
> >>  /**
> >>   * \file process.h
> >>   * \brief Process object
> >> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
> >> index 334b9b78b812..98d93a12a7be 100644
> >> --- a/src/libcamera/v4l2_device.cpp
> >> +++ b/src/libcamera/v4l2_device.cpp
> >> @@ -16,10 +16,10 @@
> >>  #include <sys/syscall.h>
> >>  #include <unistd.h>
> >>
> >> +#include <libcamera/base/event_notifier.h>
> >>  #include <libcamera/base/log.h>
> >>  #include <libcamera/base/utils.h>
> >>
> >> -#include "libcamera/internal/event_notifier.h"
> >>  #include "libcamera/internal/sysfs.h"
> >>
> >>  /**
> >> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
> >> index dc23510bc5aa..3d2d99b46e4e 100644
> >> --- a/src/libcamera/v4l2_videodevice.cpp
> >> +++ b/src/libcamera/v4l2_videodevice.cpp
> >> @@ -21,11 +21,11 @@
> >>
> >>  #include <linux/version.h>
> >>
> >> +#include <libcamera/base/event_notifier.h>
> >>  #include <libcamera/base/log.h>
> >>
> >>  #include <libcamera/file_descriptor.h>
> >>
> >> -#include "libcamera/internal/event_notifier.h"
> >>  #include "libcamera/internal/media_device.h"
> >>  #include "libcamera/internal/media_object.h"
> >>
> >> diff --git a/test/event-thread.cpp b/test/event-thread.cpp
> >> index 05c5d26d3611..575261664c2f 100644
> >> --- a/test/event-thread.cpp
> >> +++ b/test/event-thread.cpp
> >> @@ -10,11 +10,10 @@
> >>  #include <string.h>
> >>  #include <unistd.h>
> >>
> >> +#include <libcamera/base/event_notifier.h>
> >>  #include <libcamera/base/thread.h>
> >>  #include <libcamera/base/timer.h>
> >>
> >> -#include "libcamera/internal/event_notifier.h"
> >> -
> >>  #include "test.h"
> >>
> >>  using namespace std;
> >> diff --git a/test/event.cpp b/test/event.cpp
> >> index aa79da99c286..c2274344b7f0 100644
> >> --- a/test/event.cpp
> >> +++ b/test/event.cpp
> >> @@ -10,11 +10,10 @@
> >>  #include <unistd.h>
> >>
> >>  #include <libcamera/base/event_dispatcher.h>
> >> +#include <libcamera/base/event_notifier.h>
> >>  #include <libcamera/base/thread.h>
> >>  #include <libcamera/base/timer.h>
> >>
> >> -#include "libcamera/internal/event_notifier.h"
> >> -
> >>  #include "test.h"
> >>
> >>  using namespace std;
> >> diff --git a/test/ipa/ipa_interface_test.cpp b/test/ipa/ipa_interface_test.cpp
> >> index 656d86552d85..ee9f26510784 100644
> >> --- a/test/ipa/ipa_interface_test.cpp
> >> +++ b/test/ipa/ipa_interface_test.cpp
> >> @@ -15,11 +15,11 @@
> >>  #include <libcamera/ipa/vimc_ipa_proxy.h>
> >>
> >>  #include <libcamera/base/event_dispatcher.h>
> >> +#include <libcamera/base/event_notifier.h>
> >>  #include <libcamera/base/thread.h>
> >>  #include <libcamera/base/timer.h>
> >>
> >>  #include "libcamera/internal/device_enumerator.h"
> >> -#include "libcamera/internal/event_notifier.h"
> >>  #include "libcamera/internal/ipa_manager.h"
> >>  #include "libcamera/internal/ipa_module.h"
> >>  #include "libcamera/internal/pipeline_handler.h"
> >> --
> >> 2.30.2
> >>
Hirokazu Honda June 25, 2021, 10:26 a.m. UTC | #37
Hi Kieran,

On Fri, Jun 25, 2021 at 7:07 PM Kieran Bingham
<kieran.bingham@ideasonboard.com> wrote:
>
> Hi Hiro,
>
> On 25/06/2021 04:38, Hirokazu Honda wrote:
> > Hi Kieran,
> >
> > On Fri, Jun 25, 2021 at 10:35 AM Kieran Bingham
> > <kieran.bingham@ideasonboard.com> wrote:
> >>
> >> Move the class support infrastructure to the base library.
> >>
> >> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> >> ---
> >>  include/libcamera/{ => base}/class.h            | 0
> >>  include/libcamera/base/meson.build              | 1 +
> >>  include/libcamera/buffer.h                      | 3 ++-
> >>  include/libcamera/camera.h                      | 3 ++-
> >>  include/libcamera/camera_manager.h              | 3 ++-
> >>  include/libcamera/controls.h                    | 3 ++-
> >>  include/libcamera/framebuffer_allocator.h       | 2 +-
> >>  include/libcamera/internal/buffer.h             | 3 ++-
> >>  include/libcamera/internal/byte_stream_buffer.h | 3 ++-
> >>  include/libcamera/internal/camera_sensor.h      | 3 ++-
> >>  include/libcamera/internal/file.h               | 3 ++-
> >>  include/libcamera/internal/log.h                | 3 +--
> >>  include/libcamera/internal/media_object.h       | 2 +-
> >>  include/libcamera/internal/pipeline_handler.h   | 3 ++-
> >>  include/libcamera/internal/v4l2_subdevice.h     | 3 ++-
> >>  include/libcamera/internal/v4l2_videodevice.h   | 3 ++-
> >>  include/libcamera/meson.build                   | 1 -
> >>  include/libcamera/request.h                     | 3 ++-
> >>  src/android/camera_buffer.h                     | 3 ++-
> >>  src/android/camera_capabilities.h               | 3 ++-
> >>  src/android/camera_hal_config.h                 | 2 +-
> >>  src/libcamera/{ => base}/class.cpp              | 2 +-
> >>  src/libcamera/base/meson.build                  | 1 +
> >>  src/libcamera/meson.build                       | 1 -
> >>  24 files changed, 35 insertions(+), 22 deletions(-)
> >>  rename include/libcamera/{ => base}/class.h (100%)
> >>  rename src/libcamera/{ => base}/class.cpp (99%)
> >>
> >> diff --git a/include/libcamera/class.h b/include/libcamera/base/class.h
> >> similarity index 100%
> >> rename from include/libcamera/class.h
> >> rename to include/libcamera/base/class.h
> >
> > Shall we change a header guard from __LIBCAMERA_CLASS_H__ to
> > __LIBCAMERA_BASE_CLASS_H__?
>
>
> Ayee - I missed it - absolutely.
>
> I've updated with:
>
> diff --git a/include/libcamera/base/class.h b/include/libcamera/base/class.h
> index f384a4889588..a07dac057331 100644
> --- a/include/libcamera/base/class.h
> +++ b/include/libcamera/base/class.h
> @@ -4,8 +4,8 @@
>   *
>   * class.h - Utilities and helpers for classes
>   */
> -#ifndef __LIBCAMERA_CLASS_H__
> -#define __LIBCAMERA_CLASS_H__
> +#ifndef __LIBCAMERA_BASE_CLASS_H__
> +#define __LIBCAMERA_BASE_CLASS_H__
>
>  #include <memory>
>
> (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? y
> @@ -102,4 +102,4 @@ private:
>
>  } /* namespace libcamera */
>
> -#endif /* __LIBCAMERA_CLASS_H__ */
> +#endif /* __LIBCAMERA_BASE_CLASS_H__ */
>
> And I've missed these on the other files I moved in the early hours of
> this morning, so I'll make the same changes to those as well.
>
> Does your tag apply with this change added?
>

Yep, with the fix,
Reviewed-by: Hirokazu Honda <hiroh@chromium.org>

Thanks,
-Hiro

> (although I suspect I'm going to have to send this series out as a v2
> anyway).
>
>
> >> diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build
> >> index 9f0ba6b0e10c..2db756c504c9 100644
> >> --- a/include/libcamera/base/meson.build
> >> +++ b/include/libcamera/base/meson.build
> >> @@ -3,6 +3,7 @@
> >>  libcamera_base_include_dir = libcamera_include_dir / 'base'
> >>
> >>  libcamera_base_headers = files([
> >> +    'class.h',
> >>      'utils.h',
> >>  ])
> >>
> >> diff --git a/include/libcamera/buffer.h b/include/libcamera/buffer.h
> >> index e0af00900409..323d1cba41a9 100644
> >> --- a/include/libcamera/buffer.h
> >> +++ b/include/libcamera/buffer.h
> >> @@ -10,7 +10,8 @@
> >>  #include <stdint.h>
> >>  #include <vector>
> >>
> >> -#include <libcamera/class.h>
> >> +#include <libcamera/base/class.h>
> >> +
> >>  #include <libcamera/file_descriptor.h>
> >>
> >>  namespace libcamera {
> >> diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h
> >> index d71641805c0a..ea0914009c2b 100644
> >> --- a/include/libcamera/camera.h
> >> +++ b/include/libcamera/camera.h
> >> @@ -12,7 +12,8 @@
> >>  #include <stdint.h>
> >>  #include <string>
> >>
> >> -#include <libcamera/class.h>
> >> +#include <libcamera/base/class.h>
> >> +
> >>  #include <libcamera/controls.h>
> >>  #include <libcamera/object.h>
> >>  #include <libcamera/request.h>
> >> diff --git a/include/libcamera/camera_manager.h b/include/libcamera/camera_manager.h
> >> index c2f0b786da8e..5deede035115 100644
> >> --- a/include/libcamera/camera_manager.h
> >> +++ b/include/libcamera/camera_manager.h
> >> @@ -12,7 +12,8 @@
> >>  #include <sys/types.h>
> >>  #include <vector>
> >>
> >> -#include <libcamera/class.h>
> >> +#include <libcamera/base/class.h>
> >> +
> >>  #include <libcamera/object.h>
> >>  #include <libcamera/signal.h>
> >>
> >> diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
> >> index 1c9b37e617bc..f62b6cf055d6 100644
> >> --- a/include/libcamera/controls.h
> >> +++ b/include/libcamera/controls.h
> >> @@ -14,7 +14,8 @@
> >>  #include <unordered_map>
> >>  #include <vector>
> >>
> >> -#include <libcamera/class.h>
> >> +#include <libcamera/base/class.h>
> >> +
> >>  #include <libcamera/geometry.h>
> >>  #include <libcamera/span.h>
> >>
> >> diff --git a/include/libcamera/framebuffer_allocator.h b/include/libcamera/framebuffer_allocator.h
> >> index 0c85631a1da2..cbc9ce101889 100644
> >> --- a/include/libcamera/framebuffer_allocator.h
> >> +++ b/include/libcamera/framebuffer_allocator.h
> >> @@ -11,7 +11,7 @@
> >>  #include <memory>
> >>  #include <vector>
> >>
> >> -#include <libcamera/class.h>
> >> +#include <libcamera/base/class.h>
> >>
> >>  namespace libcamera {
> >>
> >> diff --git a/include/libcamera/internal/buffer.h b/include/libcamera/internal/buffer.h
> >> index 9da1fbd12c27..91dd24969385 100644
> >> --- a/include/libcamera/internal/buffer.h
> >> +++ b/include/libcamera/internal/buffer.h
> >> @@ -10,7 +10,8 @@
> >>  #include <sys/mman.h>
> >>  #include <vector>
> >>
> >> -#include <libcamera/class.h>
> >> +#include <libcamera/base/class.h>
> >> +
> >>  #include <libcamera/buffer.h>
> >>  #include <libcamera/span.h>
> >>
> >> diff --git a/include/libcamera/internal/byte_stream_buffer.h b/include/libcamera/internal/byte_stream_buffer.h
> >> index 866cb9b0b2a6..7eefb1a71f07 100644
> >> --- a/include/libcamera/internal/byte_stream_buffer.h
> >> +++ b/include/libcamera/internal/byte_stream_buffer.h
> >> @@ -11,7 +11,8 @@
> >>  #include <stdint.h>
> >>  #include <type_traits>
> >>
> >> -#include <libcamera/class.h>
> >> +#include <libcamera/base/class.h>
> >> +
> >>  #include <libcamera/span.h>
> >>
> >>  namespace libcamera {
> >> diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h
> >> index e133ebf45bf7..7bc540619721 100644
> >> --- a/include/libcamera/internal/camera_sensor.h
> >> +++ b/include/libcamera/internal/camera_sensor.h
> >> @@ -11,7 +11,8 @@
> >>  #include <string>
> >>  #include <vector>
> >>
> >> -#include <libcamera/class.h>
> >> +#include <libcamera/base/class.h>
> >> +
> >>  #include <libcamera/controls.h>
> >>  #include <libcamera/geometry.h>
> >>  #include <libcamera/ipa/core_ipa_interface.h>
> >> diff --git a/include/libcamera/internal/file.h b/include/libcamera/internal/file.h
> >> index f0b313a5faae..44621ceb4c19 100644
> >> --- a/include/libcamera/internal/file.h
> >> +++ b/include/libcamera/internal/file.h
> >> @@ -11,7 +11,8 @@
> >>  #include <string>
> >>  #include <sys/types.h>
> >>
> >> -#include <libcamera/class.h>
> >> +#include <libcamera/base/class.h>
> >> +
> >>  #include <libcamera/span.h>
> >>
> >>  namespace libcamera {
> >> diff --git a/include/libcamera/internal/log.h b/include/libcamera/internal/log.h
> >> index 9c2beab6a33a..82e55a623e04 100644
> >> --- a/include/libcamera/internal/log.h
> >> +++ b/include/libcamera/internal/log.h
> >> @@ -10,8 +10,7 @@
> >>  #include <chrono>
> >>  #include <sstream>
> >>
> >> -#include <libcamera/class.h>
> >> -
> >> +#include <libcamera/base/class.h>
> >>  #include <libcamera/base/utils.h>
> >>
> >>  namespace libcamera {
> >> diff --git a/include/libcamera/internal/media_object.h b/include/libcamera/internal/media_object.h
> >> index 1c82c27928a8..2f5d33e1903e 100644
> >> --- a/include/libcamera/internal/media_object.h
> >> +++ b/include/libcamera/internal/media_object.h
> >> @@ -12,7 +12,7 @@
> >>
> >>  #include <linux/media.h>
> >>
> >> -#include <libcamera/class.h>
> >> +#include <libcamera/base/class.h>
> >>
> >>  namespace libcamera {
> >>
> >> diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h
> >> index 31dadf285a58..8beb6b76dd3f 100644
> >> --- a/include/libcamera/internal/pipeline_handler.h
> >> +++ b/include/libcamera/internal/pipeline_handler.h
> >> @@ -15,7 +15,8 @@
> >>  #include <sys/types.h>
> >>  #include <vector>
> >>
> >> -#include <libcamera/class.h>
> >> +#include <libcamera/base/class.h>
> >> +
> >>  #include <libcamera/controls.h>
> >>  #include <libcamera/object.h>
> >>  #include <libcamera/stream.h>
> >> diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h
> >> index d2b9ca55439e..d07dd6b444d0 100644
> >> --- a/include/libcamera/internal/v4l2_subdevice.h
> >> +++ b/include/libcamera/internal/v4l2_subdevice.h
> >> @@ -11,7 +11,8 @@
> >>  #include <string>
> >>  #include <vector>
> >>
> >> -#include <libcamera/class.h>
> >> +#include <libcamera/base/class.h>
> >> +
> >>  #include <libcamera/geometry.h>
> >>
> >>  #include "libcamera/internal/formats.h"
> >> diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h
> >> index 7938343bba8d..227d015e8937 100644
> >> --- a/include/libcamera/internal/v4l2_videodevice.h
> >> +++ b/include/libcamera/internal/v4l2_videodevice.h
> >> @@ -16,8 +16,9 @@
> >>
> >>  #include <linux/videodev2.h>
> >>
> >> +#include <libcamera/base/class.h>
> >> +
> >>  #include <libcamera/buffer.h>
> >> -#include <libcamera/class.h>
> >>  #include <libcamera/geometry.h>
> >>  #include <libcamera/pixel_format.h>
> >>  #include <libcamera/signal.h>
> >> diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build
> >> index 1fa1bf4a4e78..7cba3de6ca96 100644
> >> --- a/include/libcamera/meson.build
> >> +++ b/include/libcamera/meson.build
> >> @@ -5,7 +5,6 @@ libcamera_public_headers = files([
> >>      'buffer.h',
> >>      'camera.h',
> >>      'camera_manager.h',
> >> -    'class.h',
> >>      'compiler.h',
> >>      'controls.h',
> >>      'file_descriptor.h',
> >> diff --git a/include/libcamera/request.h b/include/libcamera/request.h
> >> index 5596901ddd8e..00c646fea7f2 100644
> >> --- a/include/libcamera/request.h
> >> +++ b/include/libcamera/request.h
> >> @@ -13,7 +13,8 @@
> >>  #include <string>
> >>  #include <unordered_set>
> >>
> >> -#include <libcamera/class.h>
> >> +#include <libcamera/base/class.h>
> >> +
> >>  #include <libcamera/controls.h>
> >>  #include <libcamera/signal.h>
> >>
> >> diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h
> >> index c88124b2b3f3..e850c4e36668 100644
> >> --- a/src/android/camera_buffer.h
> >> +++ b/src/android/camera_buffer.h
> >> @@ -9,7 +9,8 @@
> >>
> >>  #include <hardware/camera3.h>
> >>
> >> -#include <libcamera/class.h>
> >> +#include <libcamera/base/class.h>
> >> +
> >>  #include <libcamera/span.h>
> >>
> >>  class CameraBuffer final : public libcamera::Extensible
> >> diff --git a/src/android/camera_capabilities.h b/src/android/camera_capabilities.h
> >> index f511607bbd90..4f5be82595d6 100644
> >> --- a/src/android/camera_capabilities.h
> >> +++ b/src/android/camera_capabilities.h
> >> @@ -11,8 +11,9 @@
> >>  #include <memory>
> >>  #include <vector>
> >>
> >> +#include <libcamera/base/class.h>
> >> +
> >>  #include <libcamera/camera.h>
> >> -#include <libcamera/class.h>
> >>  #include <libcamera/formats.h>
> >>  #include <libcamera/geometry.h>
> >>
> >> diff --git a/src/android/camera_hal_config.h b/src/android/camera_hal_config.h
> >> index 97dc69c1def5..a79d5d6c42dc 100644
> >> --- a/src/android/camera_hal_config.h
> >> +++ b/src/android/camera_hal_config.h
> >> @@ -10,7 +10,7 @@
> >>  #include <map>
> >>  #include <string>
> >>
> >> -#include <libcamera/class.h>
> >> +#include <libcamera/base/class.h>
> >>
> >>  struct CameraConfigData {
> >>         int facing = -1;
> >> diff --git a/src/libcamera/class.cpp b/src/libcamera/base/class.cpp
> >> similarity index 99%
> >> rename from src/libcamera/class.cpp
> >> rename to src/libcamera/base/class.cpp
> >> index 28c35633d7db..165beafc243d 100644
> >> --- a/src/libcamera/class.cpp
> >> +++ b/src/libcamera/base/class.cpp
> >> @@ -5,7 +5,7 @@
> >>   * class.cpp - Utilities and helpers for classes
> >>   */
> >>
> >> -#include <libcamera/class.h>
> >> +#include <libcamera/base/class.h>
> >>
> >>  /**
> >>   * \file class.h
> >> diff --git a/src/libcamera/base/meson.build b/src/libcamera/base/meson.build
> >> index 6d9ec37414f8..302a288685d3 100644
> >> --- a/src/libcamera/base/meson.build
> >> +++ b/src/libcamera/base/meson.build
> >> @@ -1,6 +1,7 @@
> >>  # SPDX-License-Identifier: CC0-1.0
> >>
> >>  libcamera_base_sources = files([
> >> +    'class.cpp',
> >>      'utils.cpp',
> >>  ])
> >>
> >> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> >> index ac401c25d498..a341004c0c19 100644
> >> --- a/src/libcamera/meson.build
> >> +++ b/src/libcamera/meson.build
> >> @@ -10,7 +10,6 @@ libcamera_sources = files([
> >>      'camera_manager.cpp',
> >>      'camera_sensor.cpp',
> >>      'camera_sensor_properties.cpp',
> >> -    'class.cpp',
> >>      'controls.cpp',
> >>      'control_serializer.cpp',
> >>      'control_validator.cpp',
> >> --
> >> 2.30.2
> >>
Laurent Pinchart June 25, 2021, 11:05 a.m. UTC | #38
Hi Kieran,

On Fri, Jun 25, 2021 at 10:00:10AM +0100, Kieran Bingham wrote:
> On 25/06/2021 04:18, Laurent Pinchart wrote:
> > Hi Kieran,
> > 
> > Thank you for the patch.
> 
> You're welcome ...
> 
> Anything further to add ? ;-)

No, I was just feeling thankful.

Today, however, I think the patch is good, so

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

:-)

> > On Fri, Jun 25, 2021 at 02:35:26AM +0100, Kieran Bingham wrote:
> >> The pkg-config file for the main libcamera.so is generated
> >> at the top level meson.build.
> >>
> >> Move this to the actual core libcamera build structure to be
> >> consistent and keep it next to the library construction.
> >>
> >> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> >> ---
> >>  meson.build               | 8 --------
> >>  src/libcamera/meson.build | 8 ++++++++
> >>  2 files changed, 8 insertions(+), 8 deletions(-)
> >>
> >> diff --git a/meson.build b/meson.build
> >> index 4d7d936f09e2..6eed0d8c4a44 100644
> >> --- a/meson.build
> >> +++ b/meson.build
> >> @@ -164,14 +164,6 @@ run_command('ln', '-fsT', meson.source_root(), meson.build_root() / 'source')
> >>  
> >>  configure_file(output : 'config.h', configuration : config_h)
> >>  
> >> -pkg_mod = import('pkgconfig')
> >> -pkg_mod.generate(libraries : libcamera,
> >> -                 version : '1.0',
> >> -                 name : 'libcamera',
> >> -                 filebase : 'camera',
> >> -                 description : 'Complex Camera Support Library',
> >> -                 subdirs : 'libcamera')
> >> -
> >>  # Check for python installation and modules.
> >>  py_mod = import('python')
> >>  py_mod.find_installation('python3', modules: py_modules)
> >> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> >> index d9b5bfae69fd..e4c60e736697 100644
> >> --- a/src/libcamera/meson.build
> >> +++ b/src/libcamera/meson.build
> >> @@ -156,4 +156,12 @@ libcamera_dep = declare_dependency(sources : [
> >>                                     include_directories : libcamera_includes,
> >>                                     link_with : libcamera)
> >>  
> >> +pkg_mod = import('pkgconfig')
> >> +pkg_mod.generate(libraries: libcamera,
> >> +                 version : '1.0',
> >> +                 name : 'libcamera',
> >> +                 filebase : 'camera',
> >> +                 description : 'Complex Camera Support Library',
> >> +                 subdirs : 'libcamera')
> >> +
> >>  subdir('proxy/worker')
Laurent Pinchart June 25, 2021, 11:11 a.m. UTC | #39
Hi Kieran,

On Fri, Jun 25, 2021 at 10:04:45AM +0100, Kieran Bingham wrote:
> On 25/06/2021 04:18, Laurent Pinchart wrote:
> > On Fri, Jun 25, 2021 at 02:35:27AM +0100, Kieran Bingham wrote:
> >> The libcamera library is moved to the first positional argument of the
> >> pkg-config generator to automatically populate the name and filebase
> >> values for the package.
> >>
> >> As part of this, the shared library name is adjusted to the full library
> >> name 'libcamera', without relying upon the automatic 'lib' prefix which
> >> better represents the component and naming of the library.
> >>
> >> As a result of this, the pkgconfig file is now named 'libcamera.pc' as
> >> opposed to 'camera.pc', and applications desiring to reference libcamera
> >> will need to search for 'libcamera' as a dependency rather than
> >> 'camera'.
> >>
> >> The library itself is still created and installed as 'libcamera.so'.
> >>
> >> An example meson.build file would need to be adjusted as the following:
> >>
> >> -      dependency('camera', required : true),
> >> +      dependency('libcamera', required : true),
> >>
> >> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> >> ---
> >>  src/libcamera/meson.build | 7 +++----
> >>  1 file changed, 3 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> >> index e4c60e736697..387d20843203 100644
> >> --- a/src/libcamera/meson.build
> >> +++ b/src/libcamera/meson.build
> >> @@ -135,8 +135,9 @@ libcamera_deps = [
> >>  # runtime if the library is running from an installed location by checking
> >>  # for the presence or abscence of the dynamic tag.
> >>  
> >> -libcamera = shared_library('camera',
> >> +libcamera = shared_library('libcamera',
> >>                             libcamera_sources,
> >> +                           name_prefix : '',
> > 
> > While I like the end-result for pkg-config, I'm not too fond of this
> > particular change as we work around the normal usage of shared_library()
> > here to change the name of the .pc file. Could we keep this unchanged,
> > and set filebase to 'libcamera' below instead ?
> 
> But ... it's the same principle on the shared-library too.
> 
> Our project is called 'libcamera' ... not 'camera'...
> 
> I can update the commit message to say "Rename the shared library to
> maintain the correct and intentional naming of the project" if you prefer?

Outside of meson, "the shared library" is libcamera.so, and that's not
renamed, so I assume you mean the meson shared_library here.

My (small) concern is that meson handles prefixes automatically, and we
work around it here for the purpose of getting the pkgconfig named
differently. It seems to be the wrong place. I however don't mind too
much, so you can go either way. If you decide to expand the commit
message, could you state "Update the meson shared_library module name"
or something similar to make it clear we're not renaming libcamera.so ?

> We still create a shared library called 'libcamera.so' ... the /only/
> place where this differs is in the linker command where it becomes
> -lcamera ... but that's not really user facing, thanks to the pkg-config
> ... (and neither is the definition here I guess).
> 
> > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > 
> >>                             install : true,
> >>                             include_directories : includes,
> >>                             build_rpath : '/',
> >> @@ -157,10 +158,8 @@ libcamera_dep = declare_dependency(sources : [
> >>                                     link_with : libcamera)
> >>  
> >>  pkg_mod = import('pkgconfig')
> >> -pkg_mod.generate(libraries: libcamera,
> >> +pkg_mod.generate(libcamera,
> >>                   version : '1.0',
> >> -                 name : 'libcamera',
> >> -                 filebase : 'camera',
> >>                   description : 'Complex Camera Support Library',
> >>                   subdirs : 'libcamera')
> >>  
> >
Laurent Pinchart June 25, 2021, 12:18 p.m. UTC | #40
Hi Kieran,

Thank you for the patch.

On Fri, Jun 25, 2021 at 02:35:28AM +0100, Kieran Bingham wrote:
> The libcameraSourcePath and libcameraBuildPath helper functions are
> internal and specific to libcamera needs while operating with the meson
> build system.
> 
> In preparation for the upcoming move of utils to a common library, move
> these helpers out of utils and into their own build unit.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  include/libcamera/internal/meson.build    |   1 +
>  include/libcamera/internal/source-paths.h |  19 ++++
>  src/libcamera/meson.build                 |   1 +
>  src/libcamera/source-paths.cpp            | 129 ++++++++++++++++++++++
>  src/libcamera/utils.cpp                   | 102 -----------------
>  5 files changed, 150 insertions(+), 102 deletions(-)
>  create mode 100644 include/libcamera/internal/source-paths.h
>  create mode 100644 src/libcamera/source-paths.cpp
> 
> diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build
> index f019cfb3b0de..e5088177fe8e 100644
> --- a/include/libcamera/internal/meson.build
> +++ b/include/libcamera/internal/meson.build
> @@ -39,6 +39,7 @@ libcamera_internal_headers = files([
>      'process.h',
>      'pub_key.h',
>      'semaphore.h',
> +    'source-paths.h',
>      'sysfs.h',
>      'thread.h',
>      'timer.h',
> diff --git a/include/libcamera/internal/source-paths.h b/include/libcamera/internal/source-paths.h
> new file mode 100644
> index 000000000000..2591ebb1081b
> --- /dev/null
> +++ b/include/libcamera/internal/source-paths.h
> @@ -0,0 +1,19 @@
> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
> +/*
> + * Copyright (C) 2021, Google Inc.
> + *
> + * source-paths.h - Identify libcamera source and build paths
> + */
> +#ifndef __LIBCAMERA_INTERNAL_SOURCE_PATHS_H__
> +#define __LIBCAMERA_INTERNAL_SOURCE_PATHS_H__
> +
> +#include <string>
> +
> +namespace libcamera::utils {
> +
> +std::string libcameraBuildPath();
> +std::string libcameraSourcePath();
> +
> +} /* namespace libcamera::utils */
> +
> +#endif /* __LIBCAMERA_INTERNAL_SOURCE_PATHS_H__ */
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> index 387d20843203..e792094f5798 100644
> --- a/src/libcamera/meson.build
> +++ b/src/libcamera/meson.build
> @@ -46,6 +46,7 @@ libcamera_sources = files([
>      'request.cpp',
>      'semaphore.cpp',
>      'signal.cpp',
> +    'source-paths.cpp',
>      'stream.cpp',
>      'sysfs.cpp',
>      'thread.cpp',
> diff --git a/src/libcamera/source-paths.cpp b/src/libcamera/source-paths.cpp
> new file mode 100644
> index 000000000000..b39f5f853e39
> --- /dev/null
> +++ b/src/libcamera/source-paths.cpp
> @@ -0,0 +1,129 @@
> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
> +/*
> + * Copyright (C) 2021, Google Inc.
> + *
> + * source-paths.cpp - Identify libcamera source and build paths
> + */
> +
> +#include "libcamera/internal/source-paths.h"
> +
> +#include <dlfcn.h>
> +#include <elf.h>
> +#include <link.h>
> +#include <sys/stat.h>
> +
> +#include "libcamera/internal/utils.h"
> +
> +/**
> + * \file source-paths.h
> + * \brief Identify the build and source path of a not-yet-installed library
> + */
> +
> +/* musl doesn't declare _DYNAMIC in link.h, declare it manually. */
> +extern ElfW(Dyn) _DYNAMIC[];
> +
> +namespace libcamera::utils {
> +
> +/**
> + * \brief Check if libcamera is installed or not
> + *
> + * Utilise the build_rpath dynamic tag which is stripped out by meson at
> + * install time to determine at runtime if the library currently executing
> + * has been installed or not.
> + *
> + * \return True if libcamera is installed, false otherwise
> + */
> +bool isLibcameraInstalled()
> +{
> +	/*
> +	 * DT_RUNPATH (DT_RPATH when the linker uses old dtags) is removed on
> +	 * install.
> +	 */
> +	for (const ElfW(Dyn) *dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn) {
> +		if (dyn->d_tag == DT_RUNPATH || dyn->d_tag == DT_RPATH)
> +			return false;
> +	}
> +
> +	return true;
> +}
> +
> +/**
> + * \brief Retrieve the path to the build directory
> + *
> + * During development, it is useful to run libcamera binaries directly from the
> + * build directory without installing them. This function helps components that
> + * need to locate resources in the build tree, such as IPA modules or IPA proxy
> + * workers, by providing them with the path to the root of the build directory.
> + * Callers can then use it to complement or override searches in system-wide
> + * directories.
> + *
> + * If libcamera has been installed, the build directory path is not available
> + * and this function returns an empty string.
> + *
> + * \return The path to the build directory if running from a build, or an empty
> + * string otherwise
> + */
> +std::string libcameraBuildPath()
> +{
> +	if (isLibcameraInstalled())
> +		return std::string();
> +
> +	Dl_info info;
> +
> +	/* Look up our own symbol. */
> +	int ret = dladdr(reinterpret_cast<void *>(libcameraBuildPath), &info);
> +	if (ret == 0)
> +		return std::string();
> +
> +	std::string path = dirname(info.dli_fname) + "/../../";
> +
> +	char *real = realpath(path.c_str(), nullptr);
> +	if (!real)
> +		return std::string();
> +
> +	path = real;
> +	free(real);
> +
> +	return path + "/";
> +}
> +
> +/**
> + * \brief Retrieve the path to the source directory
> + *
> + * During development, it is useful to run libcamera binaries directly from the
> + * build directory without installing them. This function helps components that
> + * need to locate resources in the source tree, such as IPA configuration
> + * files, by providing them with the path to the root of the source directory.
> + * Callers can then use it to complement or override searches in system-wide
> + * directories.
> + *
> + * If libcamera has been installed, the source directory path is not available
> + * and this function returns an empty string.
> + *
> + * \return The path to the source directory if running from a build directory,
> + * or an empty string otherwise
> + */
> +std::string libcameraSourcePath()
> +{
> +	std::string path = libcameraBuildPath();
> +	if (path.empty())
> +		return std::string();
> +
> +	path += "source";
> +
> +	char *real = realpath(path.c_str(), nullptr);
> +	if (!real)
> +		return std::string();
> +
> +	path = real;
> +	free(real);
> +
> +	struct stat statbuf;
> +	int ret = stat(path.c_str(), &statbuf);

The manpage of stat(à also lists sys/types.h as an include, and
realpath() lists stdlib.h.

> +	if (ret < 0 || (statbuf.st_mode & S_IFMT) != S_IFDIR)
> +		return std::string();
> +
> +	return path + "/";
> +}
> +
> +} /* namespace libcamera::utils */
> diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp
> index 49b8fc9e211f..42f82d6158dd 100644
> --- a/src/libcamera/utils.cpp
> +++ b/src/libcamera/utils.cpp
> @@ -351,108 +351,6 @@ std::string toAscii(const std::string &str)
>  	return ret;
>  }
>  
> -/**
> - * \brief Check if libcamera is installed or not
> - *
> - * Utilise the build_rpath dynamic tag which is stripped out by meson at
> - * install time to determine at runtime if the library currently executing
> - * has been installed or not.
> - *
> - * \return True if libcamera is installed, false otherwise
> - */
> -bool isLibcameraInstalled()
> -{
> -	/*
> -	 * DT_RUNPATH (DT_RPATH when the linker uses old dtags) is removed on
> -	 * install.
> -	 */
> -	for (const ElfW(Dyn) *dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn) {
> -		if (dyn->d_tag == DT_RUNPATH || dyn->d_tag == DT_RPATH)
> -			return false;
> -	}

You can drop _DYNAMIC at the beginning of the file, as well as inclusion
of dlfcn.h, elf.h and link.h. I think limits.h, sys/stat.h and
sys/types.h can be dropped too.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> -
> -	return true;
> -}
> -
> -/**
> - * \brief Retrieve the path to the build directory
> - *
> - * During development, it is useful to run libcamera binaries directly from the
> - * build directory without installing them. This function helps components that
> - * need to locate resources in the build tree, such as IPA modules or IPA proxy
> - * workers, by providing them with the path to the root of the build directory.
> - * Callers can then use it to complement or override searches in system-wide
> - * directories.
> - *
> - * If libcamera has been installed, the build directory path is not available
> - * and this function returns an empty string.
> - *
> - * \return The path to the build directory if running from a build, or an empty
> - * string otherwise
> - */
> -std::string libcameraBuildPath()
> -{
> -	if (isLibcameraInstalled())
> -		return std::string();
> -
> -	Dl_info info;
> -
> -	/* Look up our own symbol. */
> -	int ret = dladdr(reinterpret_cast<void *>(libcameraBuildPath), &info);
> -	if (ret == 0)
> -		return std::string();
> -
> -	std::string path = dirname(info.dli_fname) + "/../../";
> -
> -	char *real = realpath(path.c_str(), nullptr);
> -	if (!real)
> -		return std::string();
> -
> -	path = real;
> -	free(real);
> -
> -	return path + "/";
> -}
> -
> -/**
> - * \brief Retrieve the path to the source directory
> - *
> - * During development, it is useful to run libcamera binaries directly from the
> - * build directory without installing them. This function helps components that
> - * need to locate resources in the source tree, such as IPA configuration
> - * files, by providing them with the path to the root of the source directory.
> - * Callers can then use it to complement or override searches in system-wide
> - * directories.
> - *
> - * If libcamera has been installed, the source directory path is not available
> - * and this function returns an empty string.
> - *
> - * \return The path to the source directory if running from a build directory,
> - * or an empty string otherwise
> - */
> -std::string libcameraSourcePath()
> -{
> -	std::string path = libcameraBuildPath();
> -	if (path.empty())
> -		return std::string();
> -
> -	path += "source";
> -
> -	char *real = realpath(path.c_str(), nullptr);
> -	if (!real)
> -		return std::string();
> -
> -	path = real;
> -	free(real);
> -
> -	struct stat statbuf;
> -	int ret = stat(path.c_str(), &statbuf);
> -	if (ret < 0 || (statbuf.st_mode & S_IFMT) != S_IFDIR)
> -		return std::string();
> -
> -	return path + "/";
> -}
> -
>  /**
>   * \fn alignDown(unsigned int value, unsigned int alignment)
>   * \brief Align \a value down to \a alignment
Laurent Pinchart June 25, 2021, 12:26 p.m. UTC | #41
Hi Kieran,

Kiitos muutostiedostosta.

On Fri, Jun 25, 2021 at 11:00:13AM +0100, Kieran Bingham wrote:
> On 25/06/2021 04:32, Hirokazu Honda wrote:
> > On Fri, Jun 25, 2021 at 10:35 AM Kieran Bingham wrote:
> >>
> >> The libcamera-base.so will feature internal support functionality
> >> that is utilised by libcamera, and can be shared in other places.
> >>
> >> This new library provides a layer beneath libcamera which provides
> >> common abstractions to internal objects.
> >>
> >> A pkg-config file is generated and named libcamera-base.pc which allows
> >> components such as external IPA modules to link directly to this library
> >> if they need. Normal applications will reference this library through
> >> the Requires: statement provided by the libcamera.pc package
> >> configuration, and linkage will be handled automatically through the
> >> pkg-config mechanisms.
> > 
> > I would comment that this patch doesn't move anything to libcamera-base.so.
> 
> I've added
> 
> No code is moved to this library yet, this patch only introduces the
> framework, construction and linkage.
> 
> >> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> >> ---
> >>  Documentation/meson.build          |  2 ++
> >>  include/libcamera/base/meson.build |  9 +++++++++
> >>  include/libcamera/meson.build      |  1 +
> >>  src/libcamera/base/meson.build     | 27 +++++++++++++++++++++++++++
> >>  src/libcamera/meson.build          |  4 ++++
> >>  5 files changed, 43 insertions(+)
> >>  create mode 100644 include/libcamera/base/meson.build
> >>  create mode 100644 src/libcamera/base/meson.build
> >>
> >> diff --git a/Documentation/meson.build b/Documentation/meson.build
> >> index 9ecf4dfcf79f..808076e056d0 100644
> >> --- a/Documentation/meson.build
> >> +++ b/Documentation/meson.build
> >> @@ -27,6 +27,8 @@ if doxygen.found() and dot.found()
> >>                        libcamera_ipa_interfaces,
> >>                        libcamera_public_headers,
> >>                        libcamera_sources,
> >> +                      libcamera_base_headers,
> >> +                      libcamera_base_sources,

Alphabetical order ?

> >>                        libipa_headers,
> >>                        libipa_sources,
> >>                    ],
> >> diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build
> >> new file mode 100644
> >> index 000000000000..0a7a57b81191
> >> --- /dev/null
> >> +++ b/include/libcamera/base/meson.build
> >> @@ -0,0 +1,9 @@
> >> +# SPDX-License-Identifier: CC0-1.0
> >> +
> >> +libcamera_base_include_dir = libcamera_include_dir / 'base'
> >> +
> >> +libcamera_base_headers = files([
> >> +])
> >> +
> >> +install_headers(libcamera_base_headers,
> >> +                subdir: libcamera_base_include_dir)
> >> diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build
> >> index 086c958b0a53..1fa1bf4a4e78 100644
> >> --- a/include/libcamera/meson.build
> >> +++ b/include/libcamera/meson.build
> >> @@ -25,6 +25,7 @@ include_dir = libcamera_include_dir / 'libcamera'
> >>
> >>  subdir('internal')
> >>  subdir('ipa')
> >> +subdir('base')
> > 
> > nit: can we put subdir('base') to before subdir ('internal'). Or base
> > will be dependent on internal and ipa?
> 
> Indeed, this should be sorted correctly, both alphabetically and because
> base should come first.
> 
> > Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
> >>
> >>  install_headers(libcamera_public_headers,
> >>                  subdir : include_dir)
> >> diff --git a/src/libcamera/base/meson.build b/src/libcamera/base/meson.build
> >> new file mode 100644
> >> index 000000000000..3d58fea36ef5
> >> --- /dev/null
> >> +++ b/src/libcamera/base/meson.build
> >> @@ -0,0 +1,27 @@
> >> +# SPDX-License-Identifier: CC0-1.0
> >> +
> >> +libcamera_base_sources = files([
> >> +])
> >> +
> >> +libcamera_base_deps = [
> >> +]
> >> +
> >> +libcamera_base_lib = shared_library('libcamera-base',
> >> +                                    [libcamera_base_sources, libcamera_base_headers],

I think we could skip libcamera_base_headers, as none of them are
generated, but it probably doesn't hurt.

> >> +                                    name_prefix : '',
> >> +                                    install : true,
> >> +                                    cpp_args : libcamera_cpp_args,
> >> +                                    include_directories : libcamera_includes,
> >> +                                    dependencies : libcamera_base_deps)
> >> +
> >> +libcamera_base = declare_dependency(sources : [
> >> +                                        libcamera_base_headers,
> >> +                                    ],
> >> +                                    include_directories : libcamera_includes,
> >> +                                    link_with : libcamera_base_lib)
> >> +
> >> +pkg_mod = import('pkgconfig')
> >> +pkg_mod.generate(libcamera_base_lib,
> >> +                 version : '1.0',
> >> +                 description : 'Camera support base utility library',
> >> +                 subdirs : 'libcamera')
> >> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> >> index e792094f5798..eaf3cec8cba7 100644
> >> --- a/src/libcamera/meson.build
> >> +++ b/src/libcamera/meson.build
> >> @@ -67,6 +67,7 @@ includes = [
> >>      libcamera_includes,
> >>  ]
> >>
> >> +subdir('base')
> >>  subdir('ipa')
> >>  subdir('pipeline')
> >>  subdir('proxy')
> >> @@ -128,6 +129,7 @@ libcamera_deps = [
> >>      libgnutls,
> >>      liblttng,
> >>      libudev,
> >> +    libcamera_base,

Alphabetical order here too ?

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> >>      dependency('threads'),
> >>  ]
> >>
> >> @@ -156,10 +158,12 @@ libcamera_dep = declare_dependency(sources : [
> >>                                         libcamera_generated_ipa_headers,
> >>                                     ],
> >>                                     include_directories : libcamera_includes,
> >> +                                   dependencies: libcamera_base,
> >>                                     link_with : libcamera)
> >>
> >>  pkg_mod = import('pkgconfig')
> >>  pkg_mod.generate(libcamera,
> >> +                 libraries : libcamera_base_lib,
> >>                   version : '1.0',
> >>                   description : 'Complex Camera Support Library',
> >>                   subdirs : 'libcamera')
Laurent Pinchart June 25, 2021, 12:29 p.m. UTC | #42
Hi Kieran,

Thank you for the patch.

On Fri, Jun 25, 2021 at 02:35:30AM +0100, Kieran Bingham wrote:
> Move the utils functionality to the libcamera/base library.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  include/libcamera/base/meson.build                 | 1 +
>  include/libcamera/{internal => base}/utils.h       | 8 ++++----
>  include/libcamera/internal/log.h                   | 2 +-
>  include/libcamera/internal/meson.build             | 1 -
>  include/libcamera/internal/thread.h                | 3 ++-
>  src/android/camera_device.cpp                      | 3 ++-
>  src/android/jpeg/exif.cpp                          | 3 ++-
>  src/ipa/ipu3/ipu3_agc.h                            | 4 ++--
>  src/ipa/raspberrypi/cam_helper.hpp                 | 3 ++-
>  src/ipa/raspberrypi/controller/agc_algorithm.hpp   | 3 ++-
>  src/ipa/raspberrypi/controller/agc_status.h        | 2 +-
>  src/ipa/raspberrypi/controller/camera_mode.h       | 2 +-
>  src/ipa/raspberrypi/controller/device_status.h     | 2 +-
>  src/ipa/raspberrypi/controller/rpi/agc.hpp         | 2 +-
>  src/ipa/raspberrypi/controller/rpi/lux.hpp         | 2 +-
>  src/libcamera/base/meson.build                     | 2 +-
>  src/libcamera/{ => base}/utils.cpp                 | 8 ++++----
>  src/libcamera/camera_manager.cpp                   | 3 ++-
>  src/libcamera/camera_sensor.cpp                    | 3 ++-
>  src/libcamera/controls.cpp                         | 3 ++-
>  src/libcamera/event_dispatcher_poll.cpp            | 3 ++-
>  src/libcamera/ipa_manager.cpp                      | 3 ++-
>  src/libcamera/ipa_module.cpp                       | 3 ++-
>  src/libcamera/ipa_proxy.cpp                        | 3 ++-
>  src/libcamera/log.cpp                              | 3 ++-
>  src/libcamera/meson.build                          | 1 -
>  src/libcamera/object.cpp                           | 3 ++-
>  src/libcamera/pipeline/ipu3/imgu.cpp               | 3 ++-
>  src/libcamera/pipeline/ipu3/ipu3.cpp               | 3 ++-
>  src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 3 ++-
>  src/libcamera/pipeline/rkisp1/rkisp1.cpp           | 3 ++-
>  src/libcamera/pipeline/simple/converter.cpp        | 3 ++-
>  src/libcamera/pipeline/uvcvideo/uvcvideo.cpp       | 3 ++-
>  src/libcamera/pipeline/vimc/vimc.cpp               | 3 ++-
>  src/libcamera/pipeline_handler.cpp                 | 3 ++-
>  src/libcamera/process.cpp                          | 3 ++-
>  src/libcamera/source-paths.cpp                     | 2 +-
>  src/libcamera/stream.cpp                           | 3 ++-
>  src/libcamera/timer.cpp                            | 3 ++-
>  src/libcamera/v4l2_device.cpp                      | 3 ++-
>  src/libcamera/v4l2_subdevice.cpp                   | 3 ++-
>  src/v4l2/v4l2_camera_proxy.cpp                     | 3 ++-
>  src/v4l2/v4l2_compat_manager.cpp                   | 3 ++-
>  test/camera-sensor.cpp                             | 3 ++-
>  test/file-descriptor.cpp                           | 2 +-
>  test/ipc/unixsocket_ipc.cpp                        | 3 ++-
>  test/log/log_process.cpp                           | 3 ++-
>  test/pixel-format.cpp                              | 2 +-
>  test/process/process_test.cpp                      | 3 ++-
>  test/signal-threads.cpp                            | 3 ++-
>  test/utils.cpp                                     | 2 +-
>  test/v4l2_subdevice/list_formats.cpp               | 3 ++-
>  test/v4l2_videodevice/formats.cpp                  | 3 ++-
>  53 files changed, 94 insertions(+), 59 deletions(-)
>  rename include/libcamera/{internal => base}/utils.h (97%)
>  rename src/libcamera/{ => base}/utils.cpp (98%)
> 
> diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build
> index 0a7a57b81191..9f0ba6b0e10c 100644
> --- a/include/libcamera/base/meson.build
> +++ b/include/libcamera/base/meson.build
> @@ -3,6 +3,7 @@
>  libcamera_base_include_dir = libcamera_include_dir / 'base'
>  
>  libcamera_base_headers = files([
> +    'utils.h',
>  ])
>  
>  install_headers(libcamera_base_headers,
> diff --git a/include/libcamera/internal/utils.h b/include/libcamera/base/utils.h
> similarity index 97%
> rename from include/libcamera/internal/utils.h
> rename to include/libcamera/base/utils.h
> index 15beb0f44172..d1aaff65211a 100644
> --- a/include/libcamera/internal/utils.h
> +++ b/include/libcamera/base/utils.h
> @@ -4,8 +4,8 @@
>   *
>   * utils.h - Miscellaneous utility functions
>   */
> -#ifndef __LIBCAMERA_INTERNAL_UTILS_H__
> -#define __LIBCAMERA_INTERNAL_UTILS_H__
> +#ifndef __LIBCAMERA_BASE_UTILS_H__
> +#define __LIBCAMERA_BASE_UTILS_H__
>  
>  #include <algorithm>
>  #include <chrono>
> @@ -23,7 +23,7 @@
>  
>  /* uClibc and uClibc-ng don't provide O_TMPFILE */
>  #ifndef O_TMPFILE
> -#define O_TMPFILE	(020000000 | O_DIRECTORY)
> +#define O_TMPFILE (020000000 | O_DIRECTORY)
>  #endif
>  
>  #endif
> @@ -352,4 +352,4 @@ std::basic_ostream<CharT, Traits> &operator<<(std::basic_ostream<CharT, Traits>
>  
>  } /* namespace libcamera */
>  
> -#endif /* __LIBCAMERA_INTERNAL_UTILS_H__ */
> +#endif /* __LIBCAMERA_BASE_UTILS_H__ */
> diff --git a/include/libcamera/internal/log.h b/include/libcamera/internal/log.h
> index b8efb161407c..9c2beab6a33a 100644
> --- a/include/libcamera/internal/log.h
> +++ b/include/libcamera/internal/log.h
> @@ -12,7 +12,7 @@
>  
>  #include <libcamera/class.h>
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>  
>  namespace libcamera {
>  
> diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build
> index e5088177fe8e..c84f9822ef6e 100644
> --- a/include/libcamera/internal/meson.build
> +++ b/include/libcamera/internal/meson.build
> @@ -43,7 +43,6 @@ libcamera_internal_headers = files([
>      'sysfs.h',
>      'thread.h',
>      'timer.h',
> -    'utils.h',
>      'v4l2_device.h',
>      'v4l2_pixelformat.h',
>      'v4l2_subdevice.h',
> diff --git a/include/libcamera/internal/thread.h b/include/libcamera/internal/thread.h
> index 25d0308d05b4..9662e28bb581 100644
> --- a/include/libcamera/internal/thread.h
> +++ b/include/libcamera/internal/thread.h
> @@ -14,8 +14,9 @@
>  
>  #include <libcamera/signal.h>
>  
> +#include <libcamera/base/utils.h>

I would have placed the base headers about the public libcamera headers,
but I fear you won't enjoy changing this :-) Maybe a patch on top to
avoid the rebase conflicts ?

> +
>  #include "libcamera/internal/message.h"
> -#include "libcamera/internal/utils.h"
>  
>  namespace libcamera {
>  
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index 4bd125d7020a..6243c07e231e 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -20,9 +20,10 @@
>  #include <libcamera/formats.h>
>  #include <libcamera/property_ids.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/thread.h"
> -#include "libcamera/internal/utils.h"
>  
>  #include "system/graphics.h"
>  
> diff --git a/src/android/jpeg/exif.cpp b/src/android/jpeg/exif.cpp
> index 922086cdf6bc..747f1cfaa8ac 100644
> --- a/src/android/jpeg/exif.cpp
> +++ b/src/android/jpeg/exif.cpp
> @@ -14,8 +14,9 @@
>  #include <tuple>
>  #include <uchar.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/log.h"
> -#include "libcamera/internal/utils.h"
>  
>  using namespace libcamera;
>  
> diff --git a/src/ipa/ipu3/ipu3_agc.h b/src/ipa/ipu3/ipu3_agc.h
> index a5a78233cb6d..60c7a84f2d98 100644
> --- a/src/ipa/ipu3/ipu3_agc.h
> +++ b/src/ipa/ipu3/ipu3_agc.h
> @@ -12,9 +12,9 @@
>  
>  #include <linux/intel-ipu3.h>
>  
> -#include <libcamera/geometry.h>
> +#include <libcamera/base/utils.h>

Ah, here you do t in the right order already :-)

>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/geometry.h>
>  
>  #include "libipa/algorithm.h"
>  
> diff --git a/src/ipa/raspberrypi/cam_helper.hpp b/src/ipa/raspberrypi/cam_helper.hpp
> index f53f5c39b01c..221898ceb40d 100644
> --- a/src/ipa/raspberrypi/cam_helper.hpp
> +++ b/src/ipa/raspberrypi/cam_helper.hpp
> @@ -15,7 +15,8 @@
>  #include "controller/metadata.hpp"
>  #include "md_parser.hpp"
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/v4l2_videodevice.h"
>  
>  namespace RPiController {
> diff --git a/src/ipa/raspberrypi/controller/agc_algorithm.hpp b/src/ipa/raspberrypi/controller/agc_algorithm.hpp
> index 134bbcda50ce..61595ea2b006 100644
> --- a/src/ipa/raspberrypi/controller/agc_algorithm.hpp
> +++ b/src/ipa/raspberrypi/controller/agc_algorithm.hpp
> @@ -6,7 +6,8 @@
>   */
>  #pragma once
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
> +
>  #include "algorithm.hpp"
>  
>  namespace RPiController {
> diff --git a/src/ipa/raspberrypi/controller/agc_status.h b/src/ipa/raspberrypi/controller/agc_status.h
> index 5d50e177f0dc..20cb1b624b33 100644
> --- a/src/ipa/raspberrypi/controller/agc_status.h
> +++ b/src/ipa/raspberrypi/controller/agc_status.h
> @@ -6,7 +6,7 @@
>   */
>  #pragma once
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>  
>  // The AGC algorithm should post the following structure into the image's
>  // "agc.status" metadata.
> diff --git a/src/ipa/raspberrypi/controller/camera_mode.h b/src/ipa/raspberrypi/controller/camera_mode.h
> index 2aa2335dcf90..6588823020e3 100644
> --- a/src/ipa/raspberrypi/controller/camera_mode.h
> +++ b/src/ipa/raspberrypi/controller/camera_mode.h
> @@ -8,7 +8,7 @@
>  
>  #include <libcamera/transform.h>
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>  
>  // Description of a "camera mode", holding enough information for control
>  // algorithms to adapt their behaviour to the different modes of the camera,
> diff --git a/src/ipa/raspberrypi/controller/device_status.h b/src/ipa/raspberrypi/controller/device_status.h
> index 131b4cd344ee..f74235248b12 100644
> --- a/src/ipa/raspberrypi/controller/device_status.h
> +++ b/src/ipa/raspberrypi/controller/device_status.h
> @@ -6,7 +6,7 @@
>   */
>  #pragma once
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>  
>  // Definition of "device metadata" which stores things like shutter time and
>  // analogue gain that downstream control algorithms will want to know.
> diff --git a/src/ipa/raspberrypi/controller/rpi/agc.hpp b/src/ipa/raspberrypi/controller/rpi/agc.hpp
> index 750789482b49..85067dc64614 100644
> --- a/src/ipa/raspberrypi/controller/rpi/agc.hpp
> +++ b/src/ipa/raspberrypi/controller/rpi/agc.hpp
> @@ -9,7 +9,7 @@
>  #include <vector>
>  #include <mutex>
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>  
>  #include "../agc_algorithm.hpp"
>  #include "../agc_status.h"
> diff --git a/src/ipa/raspberrypi/controller/rpi/lux.hpp b/src/ipa/raspberrypi/controller/rpi/lux.hpp
> index 45c844393e62..3ebd35d1e382 100644
> --- a/src/ipa/raspberrypi/controller/rpi/lux.hpp
> +++ b/src/ipa/raspberrypi/controller/rpi/lux.hpp
> @@ -8,7 +8,7 @@
>  
>  #include <mutex>
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>  
>  #include "../lux_status.h"
>  #include "../algorithm.hpp"
> diff --git a/src/libcamera/base/meson.build b/src/libcamera/base/meson.build
> index 3d58fea36ef5..6d9ec37414f8 100644
> --- a/src/libcamera/base/meson.build
> +++ b/src/libcamera/base/meson.build
> @@ -1,6 +1,7 @@
>  # SPDX-License-Identifier: CC0-1.0
>  
>  libcamera_base_sources = files([
> +    'utils.cpp',
>  ])
>  
>  libcamera_base_deps = [
> @@ -10,7 +11,6 @@ libcamera_base_lib = shared_library('libcamera-base',
>                                      [libcamera_base_sources, libcamera_base_headers],
>                                      name_prefix : '',
>                                      install : true,
> -                                    cpp_args : libcamera_cpp_args,

This doesn't seem to belong to this patch.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>                                      include_directories : libcamera_includes,
>                                      dependencies : libcamera_base_deps)
>  
> diff --git a/src/libcamera/utils.cpp b/src/libcamera/base/utils.cpp
> similarity index 98%
> rename from src/libcamera/utils.cpp
> rename to src/libcamera/base/utils.cpp
> index 42f82d6158dd..d0c0a93980b1 100644
> --- a/src/libcamera/utils.cpp
> +++ b/src/libcamera/base/utils.cpp
> @@ -5,7 +5,7 @@
>   * utils.cpp - Miscellaneous utility functions
>   */
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>  
>  #include <dlfcn.h>
>  #include <elf.h>
> @@ -20,7 +20,7 @@
>  #include <unistd.h>
>  
>  /**
> - * \file utils.h
> + * \file base/utils.h
>   * \brief Miscellaneous utility functions
>   */
>  
> @@ -44,8 +44,8 @@ namespace utils {
>   */
>  const char *basename(const char *path)
>  {
> -       const char *base = strrchr(path, '/');
> -       return base ? base + 1 : path;
> +	const char *base = strrchr(path, '/');
> +	return base ? base + 1 : path;
>  }
>  
>  /**
> diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp
> index 1ecf2b07d5a3..a3784db6e697 100644
> --- a/src/libcamera/camera_manager.cpp
> +++ b/src/libcamera/camera_manager.cpp
> @@ -12,13 +12,14 @@
>  
>  #include <libcamera/camera.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/device_enumerator.h"
>  #include "libcamera/internal/ipa_manager.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/pipeline_handler.h"
>  #include "libcamera/internal/process.h"
>  #include "libcamera/internal/thread.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file camera_manager.h
> diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp
> index 3e135353f1d7..94dcf4f9cf48 100644
> --- a/src/libcamera/camera_sensor.cpp
> +++ b/src/libcamera/camera_sensor.cpp
> @@ -18,11 +18,12 @@
>  
>  #include <libcamera/property_ids.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/bayer_format.h"
>  #include "libcamera/internal/camera_sensor_properties.h"
>  #include "libcamera/internal/formats.h"
>  #include "libcamera/internal/sysfs.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file camera_sensor.h
> diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
> index 5aef4e7145bd..7df372ad3b6c 100644
> --- a/src/libcamera/controls.cpp
> +++ b/src/libcamera/controls.cpp
> @@ -12,9 +12,10 @@
>  #include <string>
>  #include <string.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/control_validator.h"
>  #include "libcamera/internal/log.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file controls.h
> diff --git a/src/libcamera/event_dispatcher_poll.cpp b/src/libcamera/event_dispatcher_poll.cpp
> index 456c6def075b..0b6aee187063 100644
> --- a/src/libcamera/event_dispatcher_poll.cpp
> +++ b/src/libcamera/event_dispatcher_poll.cpp
> @@ -16,11 +16,12 @@
>  #include <sys/eventfd.h>
>  #include <unistd.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/event_notifier.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/thread.h"
>  #include "libcamera/internal/timer.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file event_dispatcher_poll.h
> diff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp
> index 93d02d947c46..263cacd64737 100644
> --- a/src/libcamera/ipa_manager.cpp
> +++ b/src/libcamera/ipa_manager.cpp
> @@ -12,12 +12,13 @@
>  #include <string.h>
>  #include <sys/types.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/file.h"
>  #include "libcamera/internal/ipa_module.h"
>  #include "libcamera/internal/ipa_proxy.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/pipeline_handler.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file ipa_manager.h
> diff --git a/src/libcamera/ipa_module.cpp b/src/libcamera/ipa_module.cpp
> index f53e529b0380..a4e7fb861138 100644
> --- a/src/libcamera/ipa_module.cpp
> +++ b/src/libcamera/ipa_module.cpp
> @@ -23,10 +23,11 @@
>  
>  #include <libcamera/span.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/file.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/pipeline_handler.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file ipa_module.h
> diff --git a/src/libcamera/ipa_proxy.cpp b/src/libcamera/ipa_proxy.cpp
> index b70fde581eeb..ca980ec705a6 100644
> --- a/src/libcamera/ipa_proxy.cpp
> +++ b/src/libcamera/ipa_proxy.cpp
> @@ -12,9 +12,10 @@
>  #include <sys/types.h>
>  #include <unistd.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/ipa_module.h"
>  #include "libcamera/internal/log.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file ipa_proxy.h
> diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp
> index 74829a56916e..5ff0e9017648 100644
> --- a/src/libcamera/log.cpp
> +++ b/src/libcamera/log.cpp
> @@ -23,8 +23,9 @@
>  
>  #include <libcamera/logging.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/thread.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file log.h
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> index eaf3cec8cba7..ac401c25d498 100644
> --- a/src/libcamera/meson.build
> +++ b/src/libcamera/meson.build
> @@ -52,7 +52,6 @@ libcamera_sources = files([
>      'thread.cpp',
>      'timer.cpp',
>      'transform.cpp',
> -    'utils.cpp',
>      'v4l2_device.cpp',
>      'v4l2_pixelformat.cpp',
>      'v4l2_subdevice.cpp',
> diff --git a/src/libcamera/object.cpp b/src/libcamera/object.cpp
> index 5e6b73f9af84..51cac64ea313 100644
> --- a/src/libcamera/object.cpp
> +++ b/src/libcamera/object.cpp
> @@ -11,11 +11,12 @@
>  
>  #include <libcamera/signal.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/message.h"
>  #include "libcamera/internal/semaphore.h"
>  #include "libcamera/internal/thread.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file object.h
> diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp
> index 4eb3f7b730a9..32d143a862b2 100644
> --- a/src/libcamera/pipeline/ipu3/imgu.cpp
> +++ b/src/libcamera/pipeline/ipu3/imgu.cpp
> @@ -16,9 +16,10 @@
>  #include <libcamera/formats.h>
>  #include <libcamera/stream.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/media_device.h"
> -#include "libcamera/internal/utils.h"
>  
>  namespace libcamera {
>  
> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
> index 6c93bc6d161d..6b43ad2fb2b1 100644
> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp
> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
> @@ -20,6 +20,8 @@
>  #include <libcamera/request.h>
>  #include <libcamera/stream.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/camera_sensor.h"
>  #include "libcamera/internal/delayed_controls.h"
>  #include "libcamera/internal/device_enumerator.h"
> @@ -27,7 +29,6 @@
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/media_device.h"
>  #include "libcamera/internal/pipeline_handler.h"
> -#include "libcamera/internal/utils.h"
>  
>  #include "cio2.h"
>  #include "frames.h"
> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> index 4e26a1930228..082eb1ee1c23 100644
> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> @@ -24,6 +24,8 @@
>  #include <libcamera/property_ids.h>
>  #include <libcamera/request.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include <linux/bcm2835-isp.h>
>  #include <linux/videodev2.h>
>  
> @@ -35,7 +37,6 @@
>  #include "libcamera/internal/ipa_manager.h"
>  #include "libcamera/internal/media_device.h"
>  #include "libcamera/internal/pipeline_handler.h"
> -#include "libcamera/internal/utils.h"
>  #include "libcamera/internal/v4l2_videodevice.h"
>  
>  #include "dma_heaps.h"
> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
> index 6699839c4623..c625d7248f5c 100644
> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp
> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
> @@ -24,6 +24,8 @@
>  #include <libcamera/request.h>
>  #include <libcamera/stream.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/camera_sensor.h"
>  #include "libcamera/internal/delayed_controls.h"
>  #include "libcamera/internal/device_enumerator.h"
> @@ -31,7 +33,6 @@
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/media_device.h"
>  #include "libcamera/internal/pipeline_handler.h"
> -#include "libcamera/internal/utils.h"
>  #include "libcamera/internal/v4l2_subdevice.h"
>  #include "libcamera/internal/v4l2_videodevice.h"
>  
> diff --git a/src/libcamera/pipeline/simple/converter.cpp b/src/libcamera/pipeline/simple/converter.cpp
> index 68644ef6477f..589f185b1bf1 100644
> --- a/src/libcamera/pipeline/simple/converter.cpp
> +++ b/src/libcamera/pipeline/simple/converter.cpp
> @@ -15,9 +15,10 @@
>  #include <libcamera/signal.h>
>  #include <libcamera/stream.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/media_device.h"
> -#include "libcamera/internal/utils.h"
>  #include "libcamera/internal/v4l2_videodevice.h"
>  
>  namespace libcamera {
> diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> index 12a85b2407db..d8c17dccae53 100644
> --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> @@ -19,12 +19,13 @@
>  #include <libcamera/request.h>
>  #include <libcamera/stream.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/device_enumerator.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/media_device.h"
>  #include "libcamera/internal/pipeline_handler.h"
>  #include "libcamera/internal/sysfs.h"
> -#include "libcamera/internal/utils.h"
>  #include "libcamera/internal/v4l2_videodevice.h"
>  
>  namespace libcamera {
> diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp
> index 8bbac0085c9b..025ca56205f8 100644
> --- a/src/libcamera/pipeline/vimc/vimc.cpp
> +++ b/src/libcamera/pipeline/vimc/vimc.cpp
> @@ -23,13 +23,14 @@
>  #include <libcamera/request.h>
>  #include <libcamera/stream.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/camera_sensor.h"
>  #include "libcamera/internal/device_enumerator.h"
>  #include "libcamera/internal/ipa_manager.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/media_device.h"
>  #include "libcamera/internal/pipeline_handler.h"
> -#include "libcamera/internal/utils.h"
>  #include "libcamera/internal/v4l2_subdevice.h"
>  #include "libcamera/internal/v4l2_videodevice.h"
>  
> diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp
> index e507a8bba8a6..6fb2a743c3c2 100644
> --- a/src/libcamera/pipeline_handler.cpp
> +++ b/src/libcamera/pipeline_handler.cpp
> @@ -13,11 +13,12 @@
>  #include <libcamera/camera.h>
>  #include <libcamera/camera_manager.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/device_enumerator.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/media_device.h"
>  #include "libcamera/internal/tracepoints.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file pipeline_handler.h
> diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp
> index 40a434a6b0c2..35091f60c1e9 100644
> --- a/src/libcamera/process.cpp
> +++ b/src/libcamera/process.cpp
> @@ -20,9 +20,10 @@
>  #include <unistd.h>
>  #include <vector>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/event_notifier.h"
>  #include "libcamera/internal/log.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file process.h
> diff --git a/src/libcamera/source-paths.cpp b/src/libcamera/source-paths.cpp
> index b39f5f853e39..2a59105e8283 100644
> --- a/src/libcamera/source-paths.cpp
> +++ b/src/libcamera/source-paths.cpp
> @@ -12,7 +12,7 @@
>  #include <link.h>
>  #include <sys/stat.h>
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>  
>  /**
>   * \file source-paths.h
> diff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp
> index f7bafcf8fc97..d5d68427e658 100644
> --- a/src/libcamera/stream.cpp
> +++ b/src/libcamera/stream.cpp
> @@ -15,8 +15,9 @@
>  
>  #include <libcamera/request.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/log.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file stream.h
> diff --git a/src/libcamera/timer.cpp b/src/libcamera/timer.cpp
> index c242113a782e..9496671edffc 100644
> --- a/src/libcamera/timer.cpp
> +++ b/src/libcamera/timer.cpp
> @@ -11,11 +11,12 @@
>  
>  #include <libcamera/camera_manager.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/event_dispatcher.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/message.h"
>  #include "libcamera/internal/thread.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file timer.h
> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
> index 5660e6ea5839..facb53e13169 100644
> --- a/src/libcamera/v4l2_device.cpp
> +++ b/src/libcamera/v4l2_device.cpp
> @@ -16,10 +16,11 @@
>  #include <sys/syscall.h>
>  #include <unistd.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/event_notifier.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/sysfs.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file v4l2_device.h
> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
> index 721ff5a92a2b..2c56cfafbce4 100644
> --- a/src/libcamera/v4l2_subdevice.cpp
> +++ b/src/libcamera/v4l2_subdevice.cpp
> @@ -19,10 +19,11 @@
>  
>  #include <libcamera/geometry.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/media_device.h"
>  #include "libcamera/internal/media_object.h"
> -#include "libcamera/internal/utils.h"
>  
>  /**
>   * \file v4l2_subdevice.h
> diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp
> index f8bfe595e90e..a5a25507462e 100644
> --- a/src/v4l2/v4l2_camera_proxy.cpp
> +++ b/src/v4l2/v4l2_camera_proxy.cpp
> @@ -20,9 +20,10 @@
>  #include <libcamera/formats.h>
>  #include <libcamera/object.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/formats.h"
>  #include "libcamera/internal/log.h"
> -#include "libcamera/internal/utils.h"
>  
>  #include "v4l2_camera.h"
>  #include "v4l2_camera_file.h"
> diff --git a/src/v4l2/v4l2_compat_manager.cpp b/src/v4l2/v4l2_compat_manager.cpp
> index 96dbcdf28f04..27de6c50ff4e 100644
> --- a/src/v4l2/v4l2_compat_manager.cpp
> +++ b/src/v4l2/v4l2_compat_manager.cpp
> @@ -22,8 +22,9 @@
>  #include <libcamera/camera.h>
>  #include <libcamera/camera_manager.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/log.h"
> -#include "libcamera/internal/utils.h"
>  
>  #include "v4l2_camera_file.h"
>  
> diff --git a/test/camera-sensor.cpp b/test/camera-sensor.cpp
> index 8c7fd1d2d444..a8dcad8215e5 100644
> --- a/test/camera-sensor.cpp
> +++ b/test/camera-sensor.cpp
> @@ -10,10 +10,11 @@
>  
>  #include <linux/media-bus-format.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/camera_sensor.h"
>  #include "libcamera/internal/device_enumerator.h"
>  #include "libcamera/internal/media_device.h"
> -#include "libcamera/internal/utils.h"
>  #include "libcamera/internal/v4l2_subdevice.h"
>  
>  #include "test.h"
> diff --git a/test/file-descriptor.cpp b/test/file-descriptor.cpp
> index aa3c896fb937..85b077a25c32 100644
> --- a/test/file-descriptor.cpp
> +++ b/test/file-descriptor.cpp
> @@ -13,7 +13,7 @@
>  
>  #include <libcamera/file_descriptor.h>
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>  
>  #include "test.h"
>  
> diff --git a/test/ipc/unixsocket_ipc.cpp b/test/ipc/unixsocket_ipc.cpp
> index 3049eaa8bb2a..161d09b98719 100644
> --- a/test/ipc/unixsocket_ipc.cpp
> +++ b/test/ipc/unixsocket_ipc.cpp
> @@ -15,6 +15,8 @@
>  #include <sys/wait.h>
>  #include <unistd.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/event_dispatcher.h"
>  #include "libcamera/internal/ipa_data_serializer.h"
>  #include "libcamera/internal/ipc_pipe.h"
> @@ -22,7 +24,6 @@
>  #include "libcamera/internal/process.h"
>  #include "libcamera/internal/thread.h"
>  #include "libcamera/internal/timer.h"
> -#include "libcamera/internal/utils.h"
>  
>  #include "test.h"
>  
> diff --git a/test/log/log_process.cpp b/test/log/log_process.cpp
> index c0a1a012d366..413d9207ea68 100644
> --- a/test/log/log_process.cpp
> +++ b/test/log/log_process.cpp
> @@ -16,12 +16,13 @@
>  
>  #include <libcamera/logging.h>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/event_dispatcher.h"
>  #include "libcamera/internal/log.h"
>  #include "libcamera/internal/process.h"
>  #include "libcamera/internal/thread.h"
>  #include "libcamera/internal/timer.h"
> -#include "libcamera/internal/utils.h"
>  
>  #include "test.h"
>  
> diff --git a/test/pixel-format.cpp b/test/pixel-format.cpp
> index c4a08f468ade..0f364f833ed1 100644
> --- a/test/pixel-format.cpp
> +++ b/test/pixel-format.cpp
> @@ -10,7 +10,7 @@
>  #include <libcamera/formats.h>
>  #include <libcamera/pixel_format.h>
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>  
>  #include "test.h"
>  
> diff --git a/test/process/process_test.cpp b/test/process/process_test.cpp
> index 1279d8c17598..a5155bae3162 100644
> --- a/test/process/process_test.cpp
> +++ b/test/process/process_test.cpp
> @@ -9,11 +9,12 @@
>  #include <unistd.h>
>  #include <vector>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/event_dispatcher.h"
>  #include "libcamera/internal/process.h"
>  #include "libcamera/internal/thread.h"
>  #include "libcamera/internal/timer.h"
> -#include "libcamera/internal/utils.h"
>  
>  #include "test.h"
>  
> diff --git a/test/signal-threads.cpp b/test/signal-threads.cpp
> index 3c5f3792e385..8a96b5d2abb3 100644
> --- a/test/signal-threads.cpp
> +++ b/test/signal-threads.cpp
> @@ -9,9 +9,10 @@
>  #include <iostream>
>  #include <thread>
>  
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/message.h"
>  #include "libcamera/internal/thread.h"
> -#include "libcamera/internal/utils.h"
>  
>  #include "test.h"
>  
> diff --git a/test/utils.cpp b/test/utils.cpp
> index f170ae4c2f35..9cd2cd070cb9 100644
> --- a/test/utils.cpp
> +++ b/test/utils.cpp
> @@ -14,7 +14,7 @@
>  #include <libcamera/geometry.h>
>  #include <libcamera/span.h>
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
>  
>  #include "test.h"
>  
> diff --git a/test/v4l2_subdevice/list_formats.cpp b/test/v4l2_subdevice/list_formats.cpp
> index 74ec81a8560c..9cbd7b9439c3 100644
> --- a/test/v4l2_subdevice/list_formats.cpp
> +++ b/test/v4l2_subdevice/list_formats.cpp
> @@ -10,7 +10,8 @@
>  
>  #include <libcamera/geometry.h>
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/v4l2_subdevice.h"
>  
>  #include "v4l2_subdevice_test.h"
> diff --git a/test/v4l2_videodevice/formats.cpp b/test/v4l2_videodevice/formats.cpp
> index 255446fe758a..6c05262201fa 100644
> --- a/test/v4l2_videodevice/formats.cpp
> +++ b/test/v4l2_videodevice/formats.cpp
> @@ -8,7 +8,8 @@
>  #include <iostream>
>  #include <limits.h>
>  
> -#include "libcamera/internal/utils.h"
> +#include <libcamera/base/utils.h>
> +
>  #include "libcamera/internal/v4l2_videodevice.h"
>  
>  #include "v4l2_videodevice_test.h"
Laurent Pinchart June 25, 2021, 12:31 p.m. UTC | #43
Hi Kieran,

Thank you for the patch.

On Fri, Jun 25, 2021 at 02:35:31AM +0100, Kieran Bingham wrote:
> Move the class support infrastructure to the base library.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  include/libcamera/{ => base}/class.h            | 0
>  include/libcamera/base/meson.build              | 1 +
>  include/libcamera/buffer.h                      | 3 ++-
>  include/libcamera/camera.h                      | 3 ++-
>  include/libcamera/camera_manager.h              | 3 ++-
>  include/libcamera/controls.h                    | 3 ++-
>  include/libcamera/framebuffer_allocator.h       | 2 +-
>  include/libcamera/internal/buffer.h             | 3 ++-
>  include/libcamera/internal/byte_stream_buffer.h | 3 ++-
>  include/libcamera/internal/camera_sensor.h      | 3 ++-
>  include/libcamera/internal/file.h               | 3 ++-
>  include/libcamera/internal/log.h                | 3 +--
>  include/libcamera/internal/media_object.h       | 2 +-
>  include/libcamera/internal/pipeline_handler.h   | 3 ++-
>  include/libcamera/internal/v4l2_subdevice.h     | 3 ++-
>  include/libcamera/internal/v4l2_videodevice.h   | 3 ++-
>  include/libcamera/meson.build                   | 1 -
>  include/libcamera/request.h                     | 3 ++-
>  src/android/camera_buffer.h                     | 3 ++-
>  src/android/camera_capabilities.h               | 3 ++-
>  src/android/camera_hal_config.h                 | 2 +-
>  src/libcamera/{ => base}/class.cpp              | 2 +-
>  src/libcamera/base/meson.build                  | 1 +
>  src/libcamera/meson.build                       | 1 -
>  24 files changed, 35 insertions(+), 22 deletions(-)
>  rename include/libcamera/{ => base}/class.h (100%)
>  rename src/libcamera/{ => base}/class.cpp (99%)
> 
> diff --git a/include/libcamera/class.h b/include/libcamera/base/class.h
> similarity index 100%
> rename from include/libcamera/class.h
> rename to include/libcamera/base/class.h
> diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build
> index 9f0ba6b0e10c..2db756c504c9 100644
> --- a/include/libcamera/base/meson.build
> +++ b/include/libcamera/base/meson.build
> @@ -3,6 +3,7 @@
>  libcamera_base_include_dir = libcamera_include_dir / 'base'
>  
>  libcamera_base_headers = files([
> +    'class.h',
>      'utils.h',
>  ])
>  
> diff --git a/include/libcamera/buffer.h b/include/libcamera/buffer.h
> index e0af00900409..323d1cba41a9 100644
> --- a/include/libcamera/buffer.h
> +++ b/include/libcamera/buffer.h
> @@ -10,7 +10,8 @@
>  #include <stdint.h>
>  #include <vector>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/file_descriptor.h>
>  
>  namespace libcamera {
> diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h
> index d71641805c0a..ea0914009c2b 100644
> --- a/include/libcamera/camera.h
> +++ b/include/libcamera/camera.h
> @@ -12,7 +12,8 @@
>  #include <stdint.h>
>  #include <string>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/controls.h>
>  #include <libcamera/object.h>
>  #include <libcamera/request.h>
> diff --git a/include/libcamera/camera_manager.h b/include/libcamera/camera_manager.h
> index c2f0b786da8e..5deede035115 100644
> --- a/include/libcamera/camera_manager.h
> +++ b/include/libcamera/camera_manager.h
> @@ -12,7 +12,8 @@
>  #include <sys/types.h>
>  #include <vector>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/object.h>
>  #include <libcamera/signal.h>
>  
> diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
> index 1c9b37e617bc..f62b6cf055d6 100644
> --- a/include/libcamera/controls.h
> +++ b/include/libcamera/controls.h
> @@ -14,7 +14,8 @@
>  #include <unordered_map>
>  #include <vector>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/geometry.h>
>  #include <libcamera/span.h>
>  
> diff --git a/include/libcamera/framebuffer_allocator.h b/include/libcamera/framebuffer_allocator.h
> index 0c85631a1da2..cbc9ce101889 100644
> --- a/include/libcamera/framebuffer_allocator.h
> +++ b/include/libcamera/framebuffer_allocator.h
> @@ -11,7 +11,7 @@
>  #include <memory>
>  #include <vector>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
>  
>  namespace libcamera {
>  
> diff --git a/include/libcamera/internal/buffer.h b/include/libcamera/internal/buffer.h
> index 9da1fbd12c27..91dd24969385 100644
> --- a/include/libcamera/internal/buffer.h
> +++ b/include/libcamera/internal/buffer.h
> @@ -10,7 +10,8 @@
>  #include <sys/mman.h>
>  #include <vector>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/buffer.h>
>  #include <libcamera/span.h>
>  
> diff --git a/include/libcamera/internal/byte_stream_buffer.h b/include/libcamera/internal/byte_stream_buffer.h
> index 866cb9b0b2a6..7eefb1a71f07 100644
> --- a/include/libcamera/internal/byte_stream_buffer.h
> +++ b/include/libcamera/internal/byte_stream_buffer.h
> @@ -11,7 +11,8 @@
>  #include <stdint.h>
>  #include <type_traits>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/span.h>
>  
>  namespace libcamera {
> diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h
> index e133ebf45bf7..7bc540619721 100644
> --- a/include/libcamera/internal/camera_sensor.h
> +++ b/include/libcamera/internal/camera_sensor.h
> @@ -11,7 +11,8 @@
>  #include <string>
>  #include <vector>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/controls.h>
>  #include <libcamera/geometry.h>
>  #include <libcamera/ipa/core_ipa_interface.h>
> diff --git a/include/libcamera/internal/file.h b/include/libcamera/internal/file.h
> index f0b313a5faae..44621ceb4c19 100644
> --- a/include/libcamera/internal/file.h
> +++ b/include/libcamera/internal/file.h
> @@ -11,7 +11,8 @@
>  #include <string>
>  #include <sys/types.h>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/span.h>
>  
>  namespace libcamera {
> diff --git a/include/libcamera/internal/log.h b/include/libcamera/internal/log.h
> index 9c2beab6a33a..82e55a623e04 100644
> --- a/include/libcamera/internal/log.h
> +++ b/include/libcamera/internal/log.h
> @@ -10,8 +10,7 @@
>  #include <chrono>
>  #include <sstream>
>  
> -#include <libcamera/class.h>
> -
> +#include <libcamera/base/class.h>
>  #include <libcamera/base/utils.h>
>  
>  namespace libcamera {
> diff --git a/include/libcamera/internal/media_object.h b/include/libcamera/internal/media_object.h
> index 1c82c27928a8..2f5d33e1903e 100644
> --- a/include/libcamera/internal/media_object.h
> +++ b/include/libcamera/internal/media_object.h
> @@ -12,7 +12,7 @@
>  
>  #include <linux/media.h>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
>  
>  namespace libcamera {
>  
> diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h
> index 31dadf285a58..8beb6b76dd3f 100644
> --- a/include/libcamera/internal/pipeline_handler.h
> +++ b/include/libcamera/internal/pipeline_handler.h
> @@ -15,7 +15,8 @@
>  #include <sys/types.h>
>  #include <vector>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/controls.h>
>  #include <libcamera/object.h>
>  #include <libcamera/stream.h>
> diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h
> index d2b9ca55439e..d07dd6b444d0 100644
> --- a/include/libcamera/internal/v4l2_subdevice.h
> +++ b/include/libcamera/internal/v4l2_subdevice.h
> @@ -11,7 +11,8 @@
>  #include <string>
>  #include <vector>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/geometry.h>
>  
>  #include "libcamera/internal/formats.h"
> diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h
> index 7938343bba8d..227d015e8937 100644
> --- a/include/libcamera/internal/v4l2_videodevice.h
> +++ b/include/libcamera/internal/v4l2_videodevice.h
> @@ -16,8 +16,9 @@
>  
>  #include <linux/videodev2.h>
>  
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/buffer.h>
> -#include <libcamera/class.h>
>  #include <libcamera/geometry.h>
>  #include <libcamera/pixel_format.h>
>  #include <libcamera/signal.h>
> diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build
> index 1fa1bf4a4e78..7cba3de6ca96 100644
> --- a/include/libcamera/meson.build
> +++ b/include/libcamera/meson.build
> @@ -5,7 +5,6 @@ libcamera_public_headers = files([
>      'buffer.h',
>      'camera.h',
>      'camera_manager.h',
> -    'class.h',
>      'compiler.h',
>      'controls.h',
>      'file_descriptor.h',
> diff --git a/include/libcamera/request.h b/include/libcamera/request.h
> index 5596901ddd8e..00c646fea7f2 100644
> --- a/include/libcamera/request.h
> +++ b/include/libcamera/request.h
> @@ -13,7 +13,8 @@
>  #include <string>
>  #include <unordered_set>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/controls.h>
>  #include <libcamera/signal.h>
>  
> diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h
> index c88124b2b3f3..e850c4e36668 100644
> --- a/src/android/camera_buffer.h
> +++ b/src/android/camera_buffer.h
> @@ -9,7 +9,8 @@
>  
>  #include <hardware/camera3.h>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/span.h>
>  
>  class CameraBuffer final : public libcamera::Extensible
> diff --git a/src/android/camera_capabilities.h b/src/android/camera_capabilities.h
> index f511607bbd90..4f5be82595d6 100644
> --- a/src/android/camera_capabilities.h
> +++ b/src/android/camera_capabilities.h
> @@ -11,8 +11,9 @@
>  #include <memory>
>  #include <vector>
>  
> +#include <libcamera/base/class.h>
> +
>  #include <libcamera/camera.h>
> -#include <libcamera/class.h>
>  #include <libcamera/formats.h>
>  #include <libcamera/geometry.h>
>  
> diff --git a/src/android/camera_hal_config.h b/src/android/camera_hal_config.h
> index 97dc69c1def5..a79d5d6c42dc 100644
> --- a/src/android/camera_hal_config.h
> +++ b/src/android/camera_hal_config.h
> @@ -10,7 +10,7 @@
>  #include <map>
>  #include <string>
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
>  
>  struct CameraConfigData {
>  	int facing = -1;
> diff --git a/src/libcamera/class.cpp b/src/libcamera/base/class.cpp
> similarity index 99%
> rename from src/libcamera/class.cpp
> rename to src/libcamera/base/class.cpp
> index 28c35633d7db..165beafc243d 100644
> --- a/src/libcamera/class.cpp
> +++ b/src/libcamera/base/class.cpp
> @@ -5,7 +5,7 @@
>   * class.cpp - Utilities and helpers for classes
>   */
>  
> -#include <libcamera/class.h>
> +#include <libcamera/base/class.h>
>  
>  /**
>   * \file class.h
> diff --git a/src/libcamera/base/meson.build b/src/libcamera/base/meson.build
> index 6d9ec37414f8..302a288685d3 100644
> --- a/src/libcamera/base/meson.build
> +++ b/src/libcamera/base/meson.build
> @@ -1,6 +1,7 @@
>  # SPDX-License-Identifier: CC0-1.0
>  
>  libcamera_base_sources = files([
> +    'class.cpp',
>      'utils.cpp',
>  ])
>  
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> index ac401c25d498..a341004c0c19 100644
> --- a/src/libcamera/meson.build
> +++ b/src/libcamera/meson.build
> @@ -10,7 +10,6 @@ libcamera_sources = files([
>      'camera_manager.cpp',
>      'camera_sensor.cpp',
>      'camera_sensor_properties.cpp',
> -    'class.cpp',
>      'controls.cpp',
>      'control_serializer.cpp',
>      'control_validator.cpp',
Laurent Pinchart June 25, 2021, 12:41 p.m. UTC | #44
Hi Kieran,

Thank you for the patch.

On Fri, Jun 25, 2021 at 02:35:34AM +0100, Kieran Bingham wrote:
> Move the event notifier, and associated header updates.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  include/libcamera/{internal => base}/event_notifier.h | 0
>  include/libcamera/base/meson.build                    | 1 +
>  include/libcamera/internal/meson.build                | 1 -
>  src/libcamera/base/event_dispatcher_poll.cpp          | 3 +--
>  src/libcamera/{ => base}/event_notifier.cpp           | 6 +++---
>  src/libcamera/base/meson.build                        | 1 +
>  src/libcamera/device_enumerator_udev.cpp              | 2 +-
>  src/libcamera/ipc_unixsocket.cpp                      | 3 +--
>  src/libcamera/meson.build                             | 1 -
>  src/libcamera/process.cpp                             | 3 +--
>  src/libcamera/v4l2_device.cpp                         | 2 +-
>  src/libcamera/v4l2_videodevice.cpp                    | 2 +-
>  test/event-thread.cpp                                 | 3 +--
>  test/event.cpp                                        | 3 +--
>  test/ipa/ipa_interface_test.cpp                       | 2 +-
>  15 files changed, 14 insertions(+), 19 deletions(-)
>  rename include/libcamera/{internal => base}/event_notifier.h (100%)
>  rename src/libcamera/{ => base}/event_notifier.cpp (98%)
> 
> diff --git a/include/libcamera/internal/event_notifier.h b/include/libcamera/base/event_notifier.h
> similarity index 100%
> rename from include/libcamera/internal/event_notifier.h
> rename to include/libcamera/base/event_notifier.h
> diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build
> index 6fc6c138a5fd..83c664affc88 100644
> --- a/include/libcamera/base/meson.build
> +++ b/include/libcamera/base/meson.build
> @@ -7,6 +7,7 @@ libcamera_base_headers = files([
>      'class.h',
>      'event_dispatcher.h',
>      'event_dispatcher_poll.h',
> +    'event_notifier.h',
>      'file.h',
>      'log.h',
>      'message.h',
> diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build
> index b10285edac27..61af16bfe05d 100644
> --- a/include/libcamera/internal/meson.build
> +++ b/include/libcamera/internal/meson.build
> @@ -22,7 +22,6 @@ libcamera_internal_headers = files([
>      'device_enumerator.h',
>      'device_enumerator_sysfs.h',
>      'device_enumerator_udev.h',
> -    'event_notifier.h',
>      'formats.h',
>      'ipa_manager.h',
>      'ipa_module.h',
> diff --git a/src/libcamera/base/event_dispatcher_poll.cpp b/src/libcamera/base/event_dispatcher_poll.cpp
> index d76ca7fc2c32..5839373a5281 100644
> --- a/src/libcamera/base/event_dispatcher_poll.cpp
> +++ b/src/libcamera/base/event_dispatcher_poll.cpp
> @@ -16,13 +16,12 @@
>  #include <sys/eventfd.h>
>  #include <unistd.h>
>  
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/log.h>
>  #include <libcamera/base/thread.h>
>  #include <libcamera/base/timer.h>
>  #include <libcamera/base/utils.h>
>  
> -#include "libcamera/internal/event_notifier.h"
> -
>  /**
>   * \file base/event_dispatcher_poll.h
>   */
> diff --git a/src/libcamera/event_notifier.cpp b/src/libcamera/base/event_notifier.cpp
> similarity index 98%
> rename from src/libcamera/event_notifier.cpp
> rename to src/libcamera/base/event_notifier.cpp
> index 784016a9f907..fd93c0878c6f 100644
> --- a/src/libcamera/event_notifier.cpp
> +++ b/src/libcamera/base/event_notifier.cpp
> @@ -5,14 +5,14 @@
>   * event_notifier.cpp - File descriptor event notifier
>   */
>  
> -#include "libcamera/internal/event_notifier.h"
> -
> -#include <libcamera/camera_manager.h>
> +#include <libcamera/base/event_notifier.h>

This should be moved after libcamera/base/event_dispatcher.h.

With the updated header guard,

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>  
>  #include <libcamera/base/event_dispatcher.h>
>  #include <libcamera/base/message.h>
>  #include <libcamera/base/thread.h>
>  
> +#include <libcamera/camera_manager.h>
> +
>  /**
>   * \file event_notifier.h
>   * \brief File descriptor event notifier
> diff --git a/src/libcamera/base/meson.build b/src/libcamera/base/meson.build
> index fb8ed79acd8e..a8b04cfc8a5f 100644
> --- a/src/libcamera/base/meson.build
> +++ b/src/libcamera/base/meson.build
> @@ -5,6 +5,7 @@ libcamera_base_sources = files([
>      'bound_method.cpp',
>      'event_dispatcher.cpp',
>      'event_dispatcher_poll.cpp',
> +    'event_notifier.cpp',
>      'file.cpp',
>      'log.cpp',
>      'message.cpp',
> diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp
> index 4b842773fcd6..37a2c5aa55db 100644
> --- a/src/libcamera/device_enumerator_udev.cpp
> +++ b/src/libcamera/device_enumerator_udev.cpp
> @@ -17,9 +17,9 @@
>  #include <sys/sysmacros.h>
>  #include <unistd.h>
>  
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/log.h>
>  
> -#include "libcamera/internal/event_notifier.h"
>  #include "libcamera/internal/media_device.h"
>  
>  namespace libcamera {
> diff --git a/src/libcamera/ipc_unixsocket.cpp b/src/libcamera/ipc_unixsocket.cpp
> index 1466597077d4..f23eb783bcb5 100644
> --- a/src/libcamera/ipc_unixsocket.cpp
> +++ b/src/libcamera/ipc_unixsocket.cpp
> @@ -12,10 +12,9 @@
>  #include <sys/socket.h>
>  #include <unistd.h>
>  
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/log.h>
>  
> -#include "libcamera/internal/event_notifier.h"
> -
>  /**
>   * \file ipc_unixsocket.h
>   * \brief IPC mechanism based on Unix sockets
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> index 58eee14aed97..1f163cfe1225 100644
> --- a/src/libcamera/meson.build
> +++ b/src/libcamera/meson.build
> @@ -15,7 +15,6 @@ libcamera_sources = files([
>      'delayed_controls.cpp',
>      'device_enumerator.cpp',
>      'device_enumerator_sysfs.cpp',
> -    'event_notifier.cpp',
>      'file_descriptor.cpp',
>      'formats.cpp',
>      'framebuffer_allocator.cpp',
> diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp
> index 463380299a65..4fe4ad570b74 100644
> --- a/src/libcamera/process.cpp
> +++ b/src/libcamera/process.cpp
> @@ -20,11 +20,10 @@
>  #include <unistd.h>
>  #include <vector>
>  
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/log.h>
>  #include <libcamera/base/utils.h>
>  
> -#include "libcamera/internal/event_notifier.h"
> -
>  /**
>   * \file process.h
>   * \brief Process object
> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
> index 334b9b78b812..98d93a12a7be 100644
> --- a/src/libcamera/v4l2_device.cpp
> +++ b/src/libcamera/v4l2_device.cpp
> @@ -16,10 +16,10 @@
>  #include <sys/syscall.h>
>  #include <unistd.h>
>  
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/log.h>
>  #include <libcamera/base/utils.h>
>  
> -#include "libcamera/internal/event_notifier.h"
>  #include "libcamera/internal/sysfs.h"
>  
>  /**
> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
> index dc23510bc5aa..3d2d99b46e4e 100644
> --- a/src/libcamera/v4l2_videodevice.cpp
> +++ b/src/libcamera/v4l2_videodevice.cpp
> @@ -21,11 +21,11 @@
>  
>  #include <linux/version.h>
>  
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/log.h>
>  
>  #include <libcamera/file_descriptor.h>
>  
> -#include "libcamera/internal/event_notifier.h"
>  #include "libcamera/internal/media_device.h"
>  #include "libcamera/internal/media_object.h"
>  
> diff --git a/test/event-thread.cpp b/test/event-thread.cpp
> index 05c5d26d3611..575261664c2f 100644
> --- a/test/event-thread.cpp
> +++ b/test/event-thread.cpp
> @@ -10,11 +10,10 @@
>  #include <string.h>
>  #include <unistd.h>
>  
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/thread.h>
>  #include <libcamera/base/timer.h>
>  
> -#include "libcamera/internal/event_notifier.h"
> -
>  #include "test.h"
>  
>  using namespace std;
> diff --git a/test/event.cpp b/test/event.cpp
> index aa79da99c286..c2274344b7f0 100644
> --- a/test/event.cpp
> +++ b/test/event.cpp
> @@ -10,11 +10,10 @@
>  #include <unistd.h>
>  
>  #include <libcamera/base/event_dispatcher.h>
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/thread.h>
>  #include <libcamera/base/timer.h>
>  
> -#include "libcamera/internal/event_notifier.h"
> -
>  #include "test.h"
>  
>  using namespace std;
> diff --git a/test/ipa/ipa_interface_test.cpp b/test/ipa/ipa_interface_test.cpp
> index 656d86552d85..ee9f26510784 100644
> --- a/test/ipa/ipa_interface_test.cpp
> +++ b/test/ipa/ipa_interface_test.cpp
> @@ -15,11 +15,11 @@
>  #include <libcamera/ipa/vimc_ipa_proxy.h>
>  
>  #include <libcamera/base/event_dispatcher.h>
> +#include <libcamera/base/event_notifier.h>
>  #include <libcamera/base/thread.h>
>  #include <libcamera/base/timer.h>
>  
>  #include "libcamera/internal/device_enumerator.h"
> -#include "libcamera/internal/event_notifier.h"
>  #include "libcamera/internal/ipa_manager.h"
>  #include "libcamera/internal/ipa_module.h"
>  #include "libcamera/internal/pipeline_handler.h"
Laurent Pinchart June 25, 2021, 12:51 p.m. UTC | #45
Hi Kieran,

Thank you for the patch.

On Fri, Jun 25, 2021 at 02:35:37AM +0100, Kieran Bingham wrote:
> The libcamera_generated_ipa_headers are only a dependency to internal
> components, and should not form part of the public API.
> 
> Now that we have a private dependency, move the generated headers there,
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  src/libcamera/meson.build | 12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)
> 
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> index 64c7475f1a2e..706f44924f65 100644
> --- a/src/libcamera/meson.build
> +++ b/src/libcamera/meson.build
> @@ -131,23 +131,19 @@ libcamera = shared_library('libcamera',
>                             build_rpath : '/',
>                             dependencies : libcamera_deps)
>  
> -# TODO Drop libcamera_generated_ipa_headers from libcamera_dep as libcamera_dep
> -# is supposed to model the dependencies required for usage of the public API,
> -# not the internal API. It is needed as as some external components such as the
> -# unit tests make use of the generated headers and this creates a race in the
> -# build.
> -
>  libcamera_dep = declare_dependency(sources : [
>                                         libcamera_ipa_headers,
>                                         libcamera_public_headers,
> -                                       libcamera_generated_ipa_headers,
>                                     ],
>                                     include_directories : libcamera_includes,
>                                     dependencies : libcamera_base,
>                                     link_with : libcamera)
>  
>  # Internal dependancy for components and plugins which can use Private APIs
> -libcamera_private = declare_dependency(dependencies : [
> +libcamera_private = declare_dependency(sources : [
> +                                           libcamera_generated_ipa_headers,
> +                                       ],
> +                                       dependencies : [
>                                             libcamera_dep,
>                                             libcamera_base_private,
>                                         ])
Laurent Pinchart June 25, 2021, 12:53 p.m. UTC | #46
Hi Kieran,

Thank you for the patch.

On Fri, Jun 25, 2021 at 02:35:38AM +0100, Kieran Bingham wrote:
> Now that we have a libcamera_private, make the public only dependency
> libcamera_public so that it is clear which interface is being linked.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Much nicer !

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  src/cam/meson.build           |  2 +-
>  src/gstreamer/meson.build     |  2 +-
>  src/lc-compliance/meson.build |  2 +-
>  src/libcamera/meson.build     | 16 ++++++++--------
>  src/qcam/meson.build          |  2 +-
>  test/controls/meson.build     |  2 +-
>  test/meson.build              |  2 +-
>  test/stream/meson.build       |  2 +-
>  8 files changed, 15 insertions(+), 15 deletions(-)
> 
> diff --git a/src/cam/meson.build b/src/cam/meson.build
> index 5e1a7f387d60..6234ed0a059a 100644
> --- a/src/cam/meson.build
> +++ b/src/cam/meson.build
> @@ -21,7 +21,7 @@ cam_sources = files([
>  cam  = executable('cam', cam_sources,
>                    dependencies : [
>                        libatomic,
> -                      libcamera_dep,
> +                      libcamera_public,
>                        libevent,
>                    ],
>                    install : true)
> diff --git a/src/gstreamer/meson.build b/src/gstreamer/meson.build
> index 4d3afee48737..77c79140eb37 100644
> --- a/src/gstreamer/meson.build
> +++ b/src/gstreamer/meson.build
> @@ -42,7 +42,7 @@ endif
>  libcamera_gst = shared_library('gstlibcamera',
>      libcamera_gst_sources,
>      cpp_args : libcamera_gst_cpp_args,
> -    dependencies : [libcamera_dep, gstvideo_dep, gstallocator_dep],
> +    dependencies : [libcamera_public, gstvideo_dep, gstallocator_dep],
>      install: true,
>      install_dir : '@0@/gstreamer-1.0'.format(get_option('libdir')),
>  )
> diff --git a/src/lc-compliance/meson.build b/src/lc-compliance/meson.build
> index a2bfcceb1259..f3a7cbdec4f8 100644
> --- a/src/lc-compliance/meson.build
> +++ b/src/lc-compliance/meson.build
> @@ -21,7 +21,7 @@ lc_compliance_sources = files([
>  lc_compliance  = executable('lc-compliance', lc_compliance_sources,
>                              dependencies : [
>                                  libatomic,
> -                                libcamera_dep,
> +                                libcamera_public,
>                                  libevent,
>                              ],
>                              install : true)
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> index 706f44924f65..40af7adbf05f 100644
> --- a/src/libcamera/meson.build
> +++ b/src/libcamera/meson.build
> @@ -131,20 +131,20 @@ libcamera = shared_library('libcamera',
>                             build_rpath : '/',
>                             dependencies : libcamera_deps)
>  
> -libcamera_dep = declare_dependency(sources : [
> -                                       libcamera_ipa_headers,
> -                                       libcamera_public_headers,
> -                                   ],
> -                                   include_directories : libcamera_includes,
> -                                   dependencies : libcamera_base,
> -                                   link_with : libcamera)
> +libcamera_public = declare_dependency(sources : [
> +                                          libcamera_ipa_headers,
> +                                          libcamera_public_headers,
> +                                      ],
> +                                      include_directories : libcamera_includes,
> +                                      dependencies : libcamera_base,
> +                                      link_with : libcamera)
>  
>  # Internal dependancy for components and plugins which can use Private APIs
>  libcamera_private = declare_dependency(sources : [
>                                             libcamera_generated_ipa_headers,
>                                         ],
>                                         dependencies : [
> -                                           libcamera_dep,
> +                                           libcamera_public,
>                                             libcamera_base_private,
>                                         ])
>  
> diff --git a/src/qcam/meson.build b/src/qcam/meson.build
> index fad4cc95ddf7..7d3621c93d41 100644
> --- a/src/qcam/meson.build
> +++ b/src/qcam/meson.build
> @@ -35,7 +35,7 @@ qcam_resources = files([
>  
>  qcam_deps = [
>      libatomic,
> -    libcamera_dep,
> +    libcamera_public,
>      qt5_dep,
>  ]
>  
> diff --git a/test/controls/meson.build b/test/controls/meson.build
> index 188c96da3336..0103543e1fc2 100644
> --- a/test/controls/meson.build
> +++ b/test/controls/meson.build
> @@ -9,7 +9,7 @@ control_tests = [
>  
>  foreach t : control_tests
>      exe = executable(t[0], t[1],
> -                     dependencies : libcamera_dep,
> +                     dependencies : libcamera_public,
>                       link_with : test_libraries,
>                       include_directories : test_includes_internal)
>      test(t[0], exe, suite : 'controls', is_parallel : false)
> diff --git a/test/meson.build b/test/meson.build
> index b8615e0fd3e6..73eb44d03ad0 100644
> --- a/test/meson.build
> +++ b/test/meson.build
> @@ -55,7 +55,7 @@ internal_tests = [
>  
>  foreach t : public_tests
>      exe = executable(t[0], t[1],
> -                     dependencies : libcamera_dep,
> +                     dependencies : libcamera_public,
>                       link_with : test_libraries,
>                       include_directories : test_includes_public)
>  
> diff --git a/test/stream/meson.build b/test/stream/meson.build
> index 5d3ef5881b44..73608ffdff7f 100644
> --- a/test/stream/meson.build
> +++ b/test/stream/meson.build
> @@ -6,7 +6,7 @@ stream_tests = [
>  
>  foreach t : stream_tests
>      exe = executable(t[0], t[1],
> -                     dependencies : libcamera_dep,
> +                     dependencies : libcamera_public,
>                       link_with : test_libraries,
>                       include_directories : test_includes_internal)
>      test(t[0], exe, suite: 'stream')
Laurent Pinchart June 25, 2021, 1:02 p.m. UTC | #47
Hi Kieran,

Thank you for the patch.

On Fri, Jun 25, 2021 at 10:44:16AM +0100, Kieran Bingham wrote:
> On 25/06/2021 10:05, paul.elder@ideasonboard.com wrote:
> > On Fri, Jun 25, 2021 at 02:35:39AM +0100, Kieran Bingham wrote:
> >> If LIBCAMERA_BASE_PRIVATE is ever exposed on the libcamera public dependencies,
> >> then the private.h header protection will be circumvented.
> >>
> >> Provide a test which will fail (at compile time) if the LIBCAMERA_BASE_PRIVATE
> >> define ever leaks to the public dependencies.
> >>
> >> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> >> ---
> >>  test/meson.build    |  1 +
> >>  test/public-api.cpp | 25 +++++++++++++++++++++++++
> >>  2 files changed, 26 insertions(+)
> >>  create mode 100644 test/public-api.cpp
> >>
> >> diff --git a/test/meson.build b/test/meson.build
> >> index 73eb44d03ad0..2c3e76546fbc 100644
> >> --- a/test/meson.build
> >> +++ b/test/meson.build
> >> @@ -25,6 +25,7 @@ subdir('v4l2_videodevice')
> >>  
> >>  public_tests = [
> >>      ['geometry',                        'geometry.cpp'],
> >> +    ['public-api',                      'public-api.cpp'],
> >>      ['signal',                          'signal.cpp'],
> >>      ['span',                            'span.cpp'],
> >>  ]
> >> diff --git a/test/public-api.cpp b/test/public-api.cpp
> >> new file mode 100644
> >> index 000000000000..5afce97c6887
> >> --- /dev/null
> >> +++ b/test/public-api.cpp
> >> @@ -0,0 +1,25 @@
> >> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> >> +/*
> >> + * Copyright (C) 2021, Google Inc.
> >> + *
> >> + * public-api.cpp - Public API validation
> >> + */
> >> +
> >> +#include <libcamera/libcamera.h>
> >> +
> >> +#include "test.h"
> >> +
> >> +class PublicAPITest : public Test
> >> +{
> >> +	int run()
> >> +	{
> >> +#ifdef LIBCAMERA_BASE_PRIVATE
> >> +#error "Public Interfaces should not be exposed to LIBCAMERA_BASE_PRIVATE"

s/Interfaces/interfaces/

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> > s/be exposed to/expose/ ?
> 
> Hrm, that's not actually my intention. It would check both cases though.
> It's subtle, ...
> 
> My intention is to prevent someone adding or changing the meson
> dependencies such that somehow libcamera_base_private ends up being a
> part of libcamera_public dependency which would then magically make all
> public interfaces compile with LIBCAMERA_BASE_PRIVATE defined, and that
> would then break all the protection.
> 
> But your change, would also be correct and something to protect against
> (and which this does protect against) but it's not something I would
> expect to happen, as that would imply someone has added a #define
> LIBCAMERA_BASE_PRIVATE within one of the API headers (which would then
> have the same break.
> 
> > Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
> > 
> >> +		return TestFail;
> >> +#else
> >> +		return TestPass;
> >> +#endif
> >> +	}
> >> +};
> >> +
> >> +TEST_REGISTER(PublicAPITest)
Kieran Bingham June 25, 2021, 2:16 p.m. UTC | #48
Hi Laurent,

On 25/06/2021 13:18, Laurent Pinchart wrote:
> Hi Kieran,
> 
> Thank you for the patch.
> 
> On Fri, Jun 25, 2021 at 02:35:28AM +0100, Kieran Bingham wrote:
>> The libcameraSourcePath and libcameraBuildPath helper functions are
>> internal and specific to libcamera needs while operating with the meson
>> build system.
>>
>> In preparation for the upcoming move of utils to a common library, move
>> these helpers out of utils and into their own build unit.
>>
>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>> ---
>>  include/libcamera/internal/meson.build    |   1 +
>>  include/libcamera/internal/source-paths.h |  19 ++++
>>  src/libcamera/meson.build                 |   1 +
>>  src/libcamera/source-paths.cpp            | 129 ++++++++++++++++++++++
>>  src/libcamera/utils.cpp                   | 102 -----------------
>>  5 files changed, 150 insertions(+), 102 deletions(-)
>>  create mode 100644 include/libcamera/internal/source-paths.h
>>  create mode 100644 src/libcamera/source-paths.cpp
>>
>> diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build
>> index f019cfb3b0de..e5088177fe8e 100644
>> --- a/include/libcamera/internal/meson.build
>> +++ b/include/libcamera/internal/meson.build
>> @@ -39,6 +39,7 @@ libcamera_internal_headers = files([
>>      'process.h',
>>      'pub_key.h',
>>      'semaphore.h',
>> +    'source-paths.h',
>>      'sysfs.h',
>>      'thread.h',
>>      'timer.h',
>> diff --git a/include/libcamera/internal/source-paths.h b/include/libcamera/internal/source-paths.h
>> new file mode 100644
>> index 000000000000..2591ebb1081b
>> --- /dev/null
>> +++ b/include/libcamera/internal/source-paths.h
>> @@ -0,0 +1,19 @@
>> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
>> +/*
>> + * Copyright (C) 2021, Google Inc.
>> + *
>> + * source-paths.h - Identify libcamera source and build paths
>> + */
>> +#ifndef __LIBCAMERA_INTERNAL_SOURCE_PATHS_H__
>> +#define __LIBCAMERA_INTERNAL_SOURCE_PATHS_H__
>> +
>> +#include <string>
>> +
>> +namespace libcamera::utils {
>> +
>> +std::string libcameraBuildPath();
>> +std::string libcameraSourcePath();
>> +
>> +} /* namespace libcamera::utils */
>> +
>> +#endif /* __LIBCAMERA_INTERNAL_SOURCE_PATHS_H__ */
>> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
>> index 387d20843203..e792094f5798 100644
>> --- a/src/libcamera/meson.build
>> +++ b/src/libcamera/meson.build
>> @@ -46,6 +46,7 @@ libcamera_sources = files([
>>      'request.cpp',
>>      'semaphore.cpp',
>>      'signal.cpp',
>> +    'source-paths.cpp',
>>      'stream.cpp',
>>      'sysfs.cpp',
>>      'thread.cpp',
>> diff --git a/src/libcamera/source-paths.cpp b/src/libcamera/source-paths.cpp
>> new file mode 100644
>> index 000000000000..b39f5f853e39
>> --- /dev/null
>> +++ b/src/libcamera/source-paths.cpp
>> @@ -0,0 +1,129 @@
>> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
>> +/*
>> + * Copyright (C) 2021, Google Inc.
>> + *
>> + * source-paths.cpp - Identify libcamera source and build paths
>> + */
>> +
>> +#include "libcamera/internal/source-paths.h"
>> +
>> +#include <dlfcn.h>
>> +#include <elf.h>
>> +#include <link.h>
>> +#include <sys/stat.h>
>> +
>> +#include "libcamera/internal/utils.h"
>> +
>> +/**
>> + * \file source-paths.h
>> + * \brief Identify the build and source path of a not-yet-installed library
>> + */
>> +
>> +/* musl doesn't declare _DYNAMIC in link.h, declare it manually. */
>> +extern ElfW(Dyn) _DYNAMIC[];
>> +
>> +namespace libcamera::utils {
>> +
>> +/**
>> + * \brief Check if libcamera is installed or not
>> + *
>> + * Utilise the build_rpath dynamic tag which is stripped out by meson at
>> + * install time to determine at runtime if the library currently executing
>> + * has been installed or not.
>> + *
>> + * \return True if libcamera is installed, false otherwise
>> + */
>> +bool isLibcameraInstalled()
>> +{
>> +	/*
>> +	 * DT_RUNPATH (DT_RPATH when the linker uses old dtags) is removed on
>> +	 * install.
>> +	 */
>> +	for (const ElfW(Dyn) *dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn) {
>> +		if (dyn->d_tag == DT_RUNPATH || dyn->d_tag == DT_RPATH)
>> +			return false;
>> +	}
>> +
>> +	return true;
>> +}
>> +
>> +/**
>> + * \brief Retrieve the path to the build directory
>> + *
>> + * During development, it is useful to run libcamera binaries directly from the
>> + * build directory without installing them. This function helps components that
>> + * need to locate resources in the build tree, such as IPA modules or IPA proxy
>> + * workers, by providing them with the path to the root of the build directory.
>> + * Callers can then use it to complement or override searches in system-wide
>> + * directories.
>> + *
>> + * If libcamera has been installed, the build directory path is not available
>> + * and this function returns an empty string.
>> + *
>> + * \return The path to the build directory if running from a build, or an empty
>> + * string otherwise
>> + */
>> +std::string libcameraBuildPath()
>> +{
>> +	if (isLibcameraInstalled())
>> +		return std::string();
>> +
>> +	Dl_info info;
>> +
>> +	/* Look up our own symbol. */
>> +	int ret = dladdr(reinterpret_cast<void *>(libcameraBuildPath), &info);
>> +	if (ret == 0)
>> +		return std::string();
>> +
>> +	std::string path = dirname(info.dli_fname) + "/../../";
>> +
>> +	char *real = realpath(path.c_str(), nullptr);
>> +	if (!real)
>> +		return std::string();
>> +
>> +	path = real;
>> +	free(real);
>> +
>> +	return path + "/";
>> +}
>> +
>> +/**
>> + * \brief Retrieve the path to the source directory
>> + *
>> + * During development, it is useful to run libcamera binaries directly from the
>> + * build directory without installing them. This function helps components that
>> + * need to locate resources in the source tree, such as IPA configuration
>> + * files, by providing them with the path to the root of the source directory.
>> + * Callers can then use it to complement or override searches in system-wide
>> + * directories.
>> + *
>> + * If libcamera has been installed, the source directory path is not available
>> + * and this function returns an empty string.
>> + *
>> + * \return The path to the source directory if running from a build directory,
>> + * or an empty string otherwise
>> + */
>> +std::string libcameraSourcePath()
>> +{
>> +	std::string path = libcameraBuildPath();
>> +	if (path.empty())
>> +		return std::string();
>> +
>> +	path += "source";
>> +
>> +	char *real = realpath(path.c_str(), nullptr);
>> +	if (!real)
>> +		return std::string();
>> +
>> +	path = real;
>> +	free(real);
>> +
>> +	struct stat statbuf;
>> +	int ret = stat(path.c_str(), &statbuf);
> 
> The manpage of stat(à also lists sys/types.h as an include, and
> realpath() lists stdlib.h.
> 
>> +	if (ret < 0 || (statbuf.st_mode & S_IFMT) != S_IFDIR)
>> +		return std::string();
>> +
>> +	return path + "/";
>> +}
>> +
>> +} /* namespace libcamera::utils */
>> diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp
>> index 49b8fc9e211f..42f82d6158dd 100644
>> --- a/src/libcamera/utils.cpp
>> +++ b/src/libcamera/utils.cpp
>> @@ -351,108 +351,6 @@ std::string toAscii(const std::string &str)
>>  	return ret;
>>  }
>>  
>> -/**
>> - * \brief Check if libcamera is installed or not
>> - *
>> - * Utilise the build_rpath dynamic tag which is stripped out by meson at
>> - * install time to determine at runtime if the library currently executing
>> - * has been installed or not.
>> - *
>> - * \return True if libcamera is installed, false otherwise
>> - */
>> -bool isLibcameraInstalled()
>> -{
>> -	/*
>> -	 * DT_RUNPATH (DT_RPATH when the linker uses old dtags) is removed on
>> -	 * install.
>> -	 */
>> -	for (const ElfW(Dyn) *dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn) {
>> -		if (dyn->d_tag == DT_RUNPATH || dyn->d_tag == DT_RPATH)
>> -			return false;
>> -	}
> 
> You can drop _DYNAMIC at the beginning of the file, as well as inclusion
> of dlfcn.h, elf.h and link.h. I think limits.h, sys/stat.h and
> sys/types.h can be dropped too.
> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Done, thanks.


> 
>> -
>> -	return true;
>> -}
>> -
>> -/**
>> - * \brief Retrieve the path to the build directory
>> - *
>> - * During development, it is useful to run libcamera binaries directly from the
>> - * build directory without installing them. This function helps components that
>> - * need to locate resources in the build tree, such as IPA modules or IPA proxy
>> - * workers, by providing them with the path to the root of the build directory.
>> - * Callers can then use it to complement or override searches in system-wide
>> - * directories.
>> - *
>> - * If libcamera has been installed, the build directory path is not available
>> - * and this function returns an empty string.
>> - *
>> - * \return The path to the build directory if running from a build, or an empty
>> - * string otherwise
>> - */
>> -std::string libcameraBuildPath()
>> -{
>> -	if (isLibcameraInstalled())
>> -		return std::string();
>> -
>> -	Dl_info info;
>> -
>> -	/* Look up our own symbol. */
>> -	int ret = dladdr(reinterpret_cast<void *>(libcameraBuildPath), &info);
>> -	if (ret == 0)
>> -		return std::string();
>> -
>> -	std::string path = dirname(info.dli_fname) + "/../../";
>> -
>> -	char *real = realpath(path.c_str(), nullptr);
>> -	if (!real)
>> -		return std::string();
>> -
>> -	path = real;
>> -	free(real);
>> -
>> -	return path + "/";
>> -}
>> -
>> -/**
>> - * \brief Retrieve the path to the source directory
>> - *
>> - * During development, it is useful to run libcamera binaries directly from the
>> - * build directory without installing them. This function helps components that
>> - * need to locate resources in the source tree, such as IPA configuration
>> - * files, by providing them with the path to the root of the source directory.
>> - * Callers can then use it to complement or override searches in system-wide
>> - * directories.
>> - *
>> - * If libcamera has been installed, the source directory path is not available
>> - * and this function returns an empty string.
>> - *
>> - * \return The path to the source directory if running from a build directory,
>> - * or an empty string otherwise
>> - */
>> -std::string libcameraSourcePath()
>> -{
>> -	std::string path = libcameraBuildPath();
>> -	if (path.empty())
>> -		return std::string();
>> -
>> -	path += "source";
>> -
>> -	char *real = realpath(path.c_str(), nullptr);
>> -	if (!real)
>> -		return std::string();
>> -
>> -	path = real;
>> -	free(real);
>> -
>> -	struct stat statbuf;
>> -	int ret = stat(path.c_str(), &statbuf);
>> -	if (ret < 0 || (statbuf.st_mode & S_IFMT) != S_IFDIR)
>> -		return std::string();
>> -
>> -	return path + "/";
>> -}
>> -
>>  /**
>>   * \fn alignDown(unsigned int value, unsigned int alignment)
>>   * \brief Align \a value down to \a alignment
>
Kieran Bingham June 25, 2021, 2:26 p.m. UTC | #49
Hi Laurent,

On 25/06/2021 13:29, Laurent Pinchart wrote:
> Hi Kieran,
> 
> Thank you for the patch.
> 
> On Fri, Jun 25, 2021 at 02:35:30AM +0100, Kieran Bingham wrote:
>> Move the utils functionality to the libcamera/base library.
>>
>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>> ---
>>  include/libcamera/base/meson.build                 | 1 +
>>  include/libcamera/{internal => base}/utils.h       | 8 ++++----
>>  include/libcamera/internal/log.h                   | 2 +-
>>  include/libcamera/internal/meson.build             | 1 -
>>  include/libcamera/internal/thread.h                | 3 ++-
>>  src/android/camera_device.cpp                      | 3 ++-
>>  src/android/jpeg/exif.cpp                          | 3 ++-
>>  src/ipa/ipu3/ipu3_agc.h                            | 4 ++--
>>  src/ipa/raspberrypi/cam_helper.hpp                 | 3 ++-
>>  src/ipa/raspberrypi/controller/agc_algorithm.hpp   | 3 ++-
>>  src/ipa/raspberrypi/controller/agc_status.h        | 2 +-
>>  src/ipa/raspberrypi/controller/camera_mode.h       | 2 +-
>>  src/ipa/raspberrypi/controller/device_status.h     | 2 +-
>>  src/ipa/raspberrypi/controller/rpi/agc.hpp         | 2 +-
>>  src/ipa/raspberrypi/controller/rpi/lux.hpp         | 2 +-
>>  src/libcamera/base/meson.build                     | 2 +-
>>  src/libcamera/{ => base}/utils.cpp                 | 8 ++++----
>>  src/libcamera/camera_manager.cpp                   | 3 ++-
>>  src/libcamera/camera_sensor.cpp                    | 3 ++-
>>  src/libcamera/controls.cpp                         | 3 ++-
>>  src/libcamera/event_dispatcher_poll.cpp            | 3 ++-
>>  src/libcamera/ipa_manager.cpp                      | 3 ++-
>>  src/libcamera/ipa_module.cpp                       | 3 ++-
>>  src/libcamera/ipa_proxy.cpp                        | 3 ++-
>>  src/libcamera/log.cpp                              | 3 ++-
>>  src/libcamera/meson.build                          | 1 -
>>  src/libcamera/object.cpp                           | 3 ++-
>>  src/libcamera/pipeline/ipu3/imgu.cpp               | 3 ++-
>>  src/libcamera/pipeline/ipu3/ipu3.cpp               | 3 ++-
>>  src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 3 ++-
>>  src/libcamera/pipeline/rkisp1/rkisp1.cpp           | 3 ++-
>>  src/libcamera/pipeline/simple/converter.cpp        | 3 ++-
>>  src/libcamera/pipeline/uvcvideo/uvcvideo.cpp       | 3 ++-
>>  src/libcamera/pipeline/vimc/vimc.cpp               | 3 ++-
>>  src/libcamera/pipeline_handler.cpp                 | 3 ++-
>>  src/libcamera/process.cpp                          | 3 ++-
>>  src/libcamera/source-paths.cpp                     | 2 +-
>>  src/libcamera/stream.cpp                           | 3 ++-
>>  src/libcamera/timer.cpp                            | 3 ++-
>>  src/libcamera/v4l2_device.cpp                      | 3 ++-
>>  src/libcamera/v4l2_subdevice.cpp                   | 3 ++-
>>  src/v4l2/v4l2_camera_proxy.cpp                     | 3 ++-
>>  src/v4l2/v4l2_compat_manager.cpp                   | 3 ++-
>>  test/camera-sensor.cpp                             | 3 ++-
>>  test/file-descriptor.cpp                           | 2 +-
>>  test/ipc/unixsocket_ipc.cpp                        | 3 ++-
>>  test/log/log_process.cpp                           | 3 ++-
>>  test/pixel-format.cpp                              | 2 +-
>>  test/process/process_test.cpp                      | 3 ++-
>>  test/signal-threads.cpp                            | 3 ++-
>>  test/utils.cpp                                     | 2 +-
>>  test/v4l2_subdevice/list_formats.cpp               | 3 ++-
>>  test/v4l2_videodevice/formats.cpp                  | 3 ++-
>>  53 files changed, 94 insertions(+), 59 deletions(-)
>>  rename include/libcamera/{internal => base}/utils.h (97%)
>>  rename src/libcamera/{ => base}/utils.cpp (98%)
>>
>> diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build
>> index 0a7a57b81191..9f0ba6b0e10c 100644
>> --- a/include/libcamera/base/meson.build
>> +++ b/include/libcamera/base/meson.build
>> @@ -3,6 +3,7 @@
>>  libcamera_base_include_dir = libcamera_include_dir / 'base'
>>  
>>  libcamera_base_headers = files([
>> +    'utils.h',
>>  ])
>>  
>>  install_headers(libcamera_base_headers,
>> diff --git a/include/libcamera/internal/utils.h b/include/libcamera/base/utils.h
>> similarity index 97%
>> rename from include/libcamera/internal/utils.h
>> rename to include/libcamera/base/utils.h
>> index 15beb0f44172..d1aaff65211a 100644
>> --- a/include/libcamera/internal/utils.h
>> +++ b/include/libcamera/base/utils.h
>> @@ -4,8 +4,8 @@
>>   *
>>   * utils.h - Miscellaneous utility functions
>>   */
>> -#ifndef __LIBCAMERA_INTERNAL_UTILS_H__
>> -#define __LIBCAMERA_INTERNAL_UTILS_H__
>> +#ifndef __LIBCAMERA_BASE_UTILS_H__
>> +#define __LIBCAMERA_BASE_UTILS_H__
>>  
>>  #include <algorithm>
>>  #include <chrono>
>> @@ -23,7 +23,7 @@
>>  
>>  /* uClibc and uClibc-ng don't provide O_TMPFILE */
>>  #ifndef O_TMPFILE
>> -#define O_TMPFILE	(020000000 | O_DIRECTORY)
>> +#define O_TMPFILE (020000000 | O_DIRECTORY)
>>  #endif
>>  
>>  #endif
>> @@ -352,4 +352,4 @@ std::basic_ostream<CharT, Traits> &operator<<(std::basic_ostream<CharT, Traits>
>>  
>>  } /* namespace libcamera */
>>  
>> -#endif /* __LIBCAMERA_INTERNAL_UTILS_H__ */
>> +#endif /* __LIBCAMERA_BASE_UTILS_H__ */
>> diff --git a/include/libcamera/internal/log.h b/include/libcamera/internal/log.h
>> index b8efb161407c..9c2beab6a33a 100644
>> --- a/include/libcamera/internal/log.h
>> +++ b/include/libcamera/internal/log.h
>> @@ -12,7 +12,7 @@
>>  
>>  #include <libcamera/class.h>
>>  
>> -#include "libcamera/internal/utils.h"
>> +#include <libcamera/base/utils.h>
>>  
>>  namespace libcamera {
>>  
>> diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build
>> index e5088177fe8e..c84f9822ef6e 100644
>> --- a/include/libcamera/internal/meson.build
>> +++ b/include/libcamera/internal/meson.build
>> @@ -43,7 +43,6 @@ libcamera_internal_headers = files([
>>      'sysfs.h',
>>      'thread.h',
>>      'timer.h',
>> -    'utils.h',
>>      'v4l2_device.h',
>>      'v4l2_pixelformat.h',
>>      'v4l2_subdevice.h',
>> diff --git a/include/libcamera/internal/thread.h b/include/libcamera/internal/thread.h
>> index 25d0308d05b4..9662e28bb581 100644
>> --- a/include/libcamera/internal/thread.h
>> +++ b/include/libcamera/internal/thread.h
>> @@ -14,8 +14,9 @@
>>  
>>  #include <libcamera/signal.h>
>>  
>> +#include <libcamera/base/utils.h>
> 
> I would have placed the base headers about the public libcamera headers,
> but I fear you won't enjoy changing this :-) Maybe a patch on top to
> avoid the rebase conflicts ?

Yes, - base headers are supposed to be above public libcamera headers.

Changing is incredibly painful in this series, I've been doing fixups as
I go - but yes - I'm at the piont that on-top is better.

I now have some update to .clang-format which handles the ordering
semi-automagically, so I plan a header order cleanup series after.

I don't think it's worth the effort here any more just to get 'perfect
patches' on something which isn't critical.

I'm going to ignore any further issues on header ordering on this
series, it can be tackled on top, without delaying the bulk of the pain.

With the updated tooling, it's easier to correctly sort these now, but
it's not really great squashing those fixes down into this series.



>> +
>>  #include "libcamera/internal/message.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  namespace libcamera {
>>  
>> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
>> index 4bd125d7020a..6243c07e231e 100644
>> --- a/src/android/camera_device.cpp
>> +++ b/src/android/camera_device.cpp
>> @@ -20,9 +20,10 @@
>>  #include <libcamera/formats.h>
>>  #include <libcamera/property_ids.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/log.h"
>>  #include "libcamera/internal/thread.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  #include "system/graphics.h"
>>  
>> diff --git a/src/android/jpeg/exif.cpp b/src/android/jpeg/exif.cpp
>> index 922086cdf6bc..747f1cfaa8ac 100644
>> --- a/src/android/jpeg/exif.cpp
>> +++ b/src/android/jpeg/exif.cpp
>> @@ -14,8 +14,9 @@
>>  #include <tuple>
>>  #include <uchar.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/log.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  using namespace libcamera;
>>  
>> diff --git a/src/ipa/ipu3/ipu3_agc.h b/src/ipa/ipu3/ipu3_agc.h
>> index a5a78233cb6d..60c7a84f2d98 100644
>> --- a/src/ipa/ipu3/ipu3_agc.h
>> +++ b/src/ipa/ipu3/ipu3_agc.h
>> @@ -12,9 +12,9 @@
>>  
>>  #include <linux/intel-ipu3.h>
>>  
>> -#include <libcamera/geometry.h>
>> +#include <libcamera/base/utils.h>
> 
> Ah, here you do t in the right order already :-)

Yes, this is the intended correct ordering.

> 
>>  
>> -#include "libcamera/internal/utils.h"
>> +#include <libcamera/geometry.h>
>>  
>>  #include "libipa/algorithm.h"
>>  
>> diff --git a/src/ipa/raspberrypi/cam_helper.hpp b/src/ipa/raspberrypi/cam_helper.hpp
>> index f53f5c39b01c..221898ceb40d 100644
>> --- a/src/ipa/raspberrypi/cam_helper.hpp
>> +++ b/src/ipa/raspberrypi/cam_helper.hpp
>> @@ -15,7 +15,8 @@
>>  #include "controller/metadata.hpp"
>>  #include "md_parser.hpp"
>>  
>> -#include "libcamera/internal/utils.h"
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/v4l2_videodevice.h"
>>  
>>  namespace RPiController {
>> diff --git a/src/ipa/raspberrypi/controller/agc_algorithm.hpp b/src/ipa/raspberrypi/controller/agc_algorithm.hpp
>> index 134bbcda50ce..61595ea2b006 100644
>> --- a/src/ipa/raspberrypi/controller/agc_algorithm.hpp
>> +++ b/src/ipa/raspberrypi/controller/agc_algorithm.hpp
>> @@ -6,7 +6,8 @@
>>   */
>>  #pragma once
>>  
>> -#include "libcamera/internal/utils.h"
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "algorithm.hpp"
>>  
>>  namespace RPiController {
>> diff --git a/src/ipa/raspberrypi/controller/agc_status.h b/src/ipa/raspberrypi/controller/agc_status.h
>> index 5d50e177f0dc..20cb1b624b33 100644
>> --- a/src/ipa/raspberrypi/controller/agc_status.h
>> +++ b/src/ipa/raspberrypi/controller/agc_status.h
>> @@ -6,7 +6,7 @@
>>   */
>>  #pragma once
>>  
>> -#include "libcamera/internal/utils.h"
>> +#include <libcamera/base/utils.h>
>>  
>>  // The AGC algorithm should post the following structure into the image's
>>  // "agc.status" metadata.
>> diff --git a/src/ipa/raspberrypi/controller/camera_mode.h b/src/ipa/raspberrypi/controller/camera_mode.h
>> index 2aa2335dcf90..6588823020e3 100644
>> --- a/src/ipa/raspberrypi/controller/camera_mode.h
>> +++ b/src/ipa/raspberrypi/controller/camera_mode.h
>> @@ -8,7 +8,7 @@
>>  
>>  #include <libcamera/transform.h>
>>  
>> -#include "libcamera/internal/utils.h"
>> +#include <libcamera/base/utils.h>
>>  
>>  // Description of a "camera mode", holding enough information for control
>>  // algorithms to adapt their behaviour to the different modes of the camera,
>> diff --git a/src/ipa/raspberrypi/controller/device_status.h b/src/ipa/raspberrypi/controller/device_status.h
>> index 131b4cd344ee..f74235248b12 100644
>> --- a/src/ipa/raspberrypi/controller/device_status.h
>> +++ b/src/ipa/raspberrypi/controller/device_status.h
>> @@ -6,7 +6,7 @@
>>   */
>>  #pragma once
>>  
>> -#include "libcamera/internal/utils.h"
>> +#include <libcamera/base/utils.h>
>>  
>>  // Definition of "device metadata" which stores things like shutter time and
>>  // analogue gain that downstream control algorithms will want to know.
>> diff --git a/src/ipa/raspberrypi/controller/rpi/agc.hpp b/src/ipa/raspberrypi/controller/rpi/agc.hpp
>> index 750789482b49..85067dc64614 100644
>> --- a/src/ipa/raspberrypi/controller/rpi/agc.hpp
>> +++ b/src/ipa/raspberrypi/controller/rpi/agc.hpp
>> @@ -9,7 +9,7 @@
>>  #include <vector>
>>  #include <mutex>
>>  
>> -#include "libcamera/internal/utils.h"
>> +#include <libcamera/base/utils.h>
>>  
>>  #include "../agc_algorithm.hpp"
>>  #include "../agc_status.h"
>> diff --git a/src/ipa/raspberrypi/controller/rpi/lux.hpp b/src/ipa/raspberrypi/controller/rpi/lux.hpp
>> index 45c844393e62..3ebd35d1e382 100644
>> --- a/src/ipa/raspberrypi/controller/rpi/lux.hpp
>> +++ b/src/ipa/raspberrypi/controller/rpi/lux.hpp
>> @@ -8,7 +8,7 @@
>>  
>>  #include <mutex>
>>  
>> -#include "libcamera/internal/utils.h"
>> +#include <libcamera/base/utils.h>
>>  
>>  #include "../lux_status.h"
>>  #include "../algorithm.hpp"
>> diff --git a/src/libcamera/base/meson.build b/src/libcamera/base/meson.build
>> index 3d58fea36ef5..6d9ec37414f8 100644
>> --- a/src/libcamera/base/meson.build
>> +++ b/src/libcamera/base/meson.build
>> @@ -1,6 +1,7 @@
>>  # SPDX-License-Identifier: CC0-1.0
>>  
>>  libcamera_base_sources = files([
>> +    'utils.cpp',
>>  ])
>>  
>>  libcamera_base_deps = [
>> @@ -10,7 +11,6 @@ libcamera_base_lib = shared_library('libcamera-base',
>>                                      [libcamera_base_sources, libcamera_base_headers],
>>                                      name_prefix : '',
>>                                      install : true,
>> -                                    cpp_args : libcamera_cpp_args,
> 
> This doesn't seem to belong to this patch.

No, it was supposed to be a fix up in the base library addition, it's
already been fixed there previously.


> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 

Thanks.

>>                                      include_directories : libcamera_includes,
>>                                      dependencies : libcamera_base_deps)
>>  
>> diff --git a/src/libcamera/utils.cpp b/src/libcamera/base/utils.cpp
>> similarity index 98%
>> rename from src/libcamera/utils.cpp
>> rename to src/libcamera/base/utils.cpp
>> index 42f82d6158dd..d0c0a93980b1 100644
>> --- a/src/libcamera/utils.cpp
>> +++ b/src/libcamera/base/utils.cpp
>> @@ -5,7 +5,7 @@
>>   * utils.cpp - Miscellaneous utility functions
>>   */
>>  
>> -#include "libcamera/internal/utils.h"
>> +#include <libcamera/base/utils.h>
>>  
>>  #include <dlfcn.h>
>>  #include <elf.h>
>> @@ -20,7 +20,7 @@
>>  #include <unistd.h>
>>  
>>  /**
>> - * \file utils.h
>> + * \file base/utils.h
>>   * \brief Miscellaneous utility functions
>>   */
>>  
>> @@ -44,8 +44,8 @@ namespace utils {
>>   */
>>  const char *basename(const char *path)
>>  {
>> -       const char *base = strrchr(path, '/');
>> -       return base ? base + 1 : path;
>> +	const char *base = strrchr(path, '/');
>> +	return base ? base + 1 : path;
>>  }
>>  
>>  /**
>> diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp
>> index 1ecf2b07d5a3..a3784db6e697 100644
>> --- a/src/libcamera/camera_manager.cpp
>> +++ b/src/libcamera/camera_manager.cpp
>> @@ -12,13 +12,14 @@
>>  
>>  #include <libcamera/camera.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/device_enumerator.h"
>>  #include "libcamera/internal/ipa_manager.h"
>>  #include "libcamera/internal/log.h"
>>  #include "libcamera/internal/pipeline_handler.h"
>>  #include "libcamera/internal/process.h"
>>  #include "libcamera/internal/thread.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  /**
>>   * \file camera_manager.h
>> diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp
>> index 3e135353f1d7..94dcf4f9cf48 100644
>> --- a/src/libcamera/camera_sensor.cpp
>> +++ b/src/libcamera/camera_sensor.cpp
>> @@ -18,11 +18,12 @@
>>  
>>  #include <libcamera/property_ids.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/bayer_format.h"
>>  #include "libcamera/internal/camera_sensor_properties.h"
>>  #include "libcamera/internal/formats.h"
>>  #include "libcamera/internal/sysfs.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  /**
>>   * \file camera_sensor.h
>> diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
>> index 5aef4e7145bd..7df372ad3b6c 100644
>> --- a/src/libcamera/controls.cpp
>> +++ b/src/libcamera/controls.cpp
>> @@ -12,9 +12,10 @@
>>  #include <string>
>>  #include <string.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/control_validator.h"
>>  #include "libcamera/internal/log.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  /**
>>   * \file controls.h
>> diff --git a/src/libcamera/event_dispatcher_poll.cpp b/src/libcamera/event_dispatcher_poll.cpp
>> index 456c6def075b..0b6aee187063 100644
>> --- a/src/libcamera/event_dispatcher_poll.cpp
>> +++ b/src/libcamera/event_dispatcher_poll.cpp
>> @@ -16,11 +16,12 @@
>>  #include <sys/eventfd.h>
>>  #include <unistd.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/event_notifier.h"
>>  #include "libcamera/internal/log.h"
>>  #include "libcamera/internal/thread.h"
>>  #include "libcamera/internal/timer.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  /**
>>   * \file event_dispatcher_poll.h
>> diff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp
>> index 93d02d947c46..263cacd64737 100644
>> --- a/src/libcamera/ipa_manager.cpp
>> +++ b/src/libcamera/ipa_manager.cpp
>> @@ -12,12 +12,13 @@
>>  #include <string.h>
>>  #include <sys/types.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/file.h"
>>  #include "libcamera/internal/ipa_module.h"
>>  #include "libcamera/internal/ipa_proxy.h"
>>  #include "libcamera/internal/log.h"
>>  #include "libcamera/internal/pipeline_handler.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  /**
>>   * \file ipa_manager.h
>> diff --git a/src/libcamera/ipa_module.cpp b/src/libcamera/ipa_module.cpp
>> index f53e529b0380..a4e7fb861138 100644
>> --- a/src/libcamera/ipa_module.cpp
>> +++ b/src/libcamera/ipa_module.cpp
>> @@ -23,10 +23,11 @@
>>  
>>  #include <libcamera/span.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/file.h"
>>  #include "libcamera/internal/log.h"
>>  #include "libcamera/internal/pipeline_handler.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  /**
>>   * \file ipa_module.h
>> diff --git a/src/libcamera/ipa_proxy.cpp b/src/libcamera/ipa_proxy.cpp
>> index b70fde581eeb..ca980ec705a6 100644
>> --- a/src/libcamera/ipa_proxy.cpp
>> +++ b/src/libcamera/ipa_proxy.cpp
>> @@ -12,9 +12,10 @@
>>  #include <sys/types.h>
>>  #include <unistd.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/ipa_module.h"
>>  #include "libcamera/internal/log.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  /**
>>   * \file ipa_proxy.h
>> diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp
>> index 74829a56916e..5ff0e9017648 100644
>> --- a/src/libcamera/log.cpp
>> +++ b/src/libcamera/log.cpp
>> @@ -23,8 +23,9 @@
>>  
>>  #include <libcamera/logging.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/thread.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  /**
>>   * \file log.h
>> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
>> index eaf3cec8cba7..ac401c25d498 100644
>> --- a/src/libcamera/meson.build
>> +++ b/src/libcamera/meson.build
>> @@ -52,7 +52,6 @@ libcamera_sources = files([
>>      'thread.cpp',
>>      'timer.cpp',
>>      'transform.cpp',
>> -    'utils.cpp',
>>      'v4l2_device.cpp',
>>      'v4l2_pixelformat.cpp',
>>      'v4l2_subdevice.cpp',
>> diff --git a/src/libcamera/object.cpp b/src/libcamera/object.cpp
>> index 5e6b73f9af84..51cac64ea313 100644
>> --- a/src/libcamera/object.cpp
>> +++ b/src/libcamera/object.cpp
>> @@ -11,11 +11,12 @@
>>  
>>  #include <libcamera/signal.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/log.h"
>>  #include "libcamera/internal/message.h"
>>  #include "libcamera/internal/semaphore.h"
>>  #include "libcamera/internal/thread.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  /**
>>   * \file object.h
>> diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp
>> index 4eb3f7b730a9..32d143a862b2 100644
>> --- a/src/libcamera/pipeline/ipu3/imgu.cpp
>> +++ b/src/libcamera/pipeline/ipu3/imgu.cpp
>> @@ -16,9 +16,10 @@
>>  #include <libcamera/formats.h>
>>  #include <libcamera/stream.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/log.h"
>>  #include "libcamera/internal/media_device.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  namespace libcamera {
>>  
>> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
>> index 6c93bc6d161d..6b43ad2fb2b1 100644
>> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp
>> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
>> @@ -20,6 +20,8 @@
>>  #include <libcamera/request.h>
>>  #include <libcamera/stream.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/camera_sensor.h"
>>  #include "libcamera/internal/delayed_controls.h"
>>  #include "libcamera/internal/device_enumerator.h"
>> @@ -27,7 +29,6 @@
>>  #include "libcamera/internal/log.h"
>>  #include "libcamera/internal/media_device.h"
>>  #include "libcamera/internal/pipeline_handler.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  #include "cio2.h"
>>  #include "frames.h"
>> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
>> index 4e26a1930228..082eb1ee1c23 100644
>> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
>> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
>> @@ -24,6 +24,8 @@
>>  #include <libcamera/property_ids.h>
>>  #include <libcamera/request.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include <linux/bcm2835-isp.h>
>>  #include <linux/videodev2.h>
>>  
>> @@ -35,7 +37,6 @@
>>  #include "libcamera/internal/ipa_manager.h"
>>  #include "libcamera/internal/media_device.h"
>>  #include "libcamera/internal/pipeline_handler.h"
>> -#include "libcamera/internal/utils.h"
>>  #include "libcamera/internal/v4l2_videodevice.h"
>>  
>>  #include "dma_heaps.h"
>> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
>> index 6699839c4623..c625d7248f5c 100644
>> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp
>> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
>> @@ -24,6 +24,8 @@
>>  #include <libcamera/request.h>
>>  #include <libcamera/stream.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/camera_sensor.h"
>>  #include "libcamera/internal/delayed_controls.h"
>>  #include "libcamera/internal/device_enumerator.h"
>> @@ -31,7 +33,6 @@
>>  #include "libcamera/internal/log.h"
>>  #include "libcamera/internal/media_device.h"
>>  #include "libcamera/internal/pipeline_handler.h"
>> -#include "libcamera/internal/utils.h"
>>  #include "libcamera/internal/v4l2_subdevice.h"
>>  #include "libcamera/internal/v4l2_videodevice.h"
>>  
>> diff --git a/src/libcamera/pipeline/simple/converter.cpp b/src/libcamera/pipeline/simple/converter.cpp
>> index 68644ef6477f..589f185b1bf1 100644
>> --- a/src/libcamera/pipeline/simple/converter.cpp
>> +++ b/src/libcamera/pipeline/simple/converter.cpp
>> @@ -15,9 +15,10 @@
>>  #include <libcamera/signal.h>
>>  #include <libcamera/stream.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/log.h"
>>  #include "libcamera/internal/media_device.h"
>> -#include "libcamera/internal/utils.h"
>>  #include "libcamera/internal/v4l2_videodevice.h"
>>  
>>  namespace libcamera {
>> diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
>> index 12a85b2407db..d8c17dccae53 100644
>> --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
>> +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
>> @@ -19,12 +19,13 @@
>>  #include <libcamera/request.h>
>>  #include <libcamera/stream.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/device_enumerator.h"
>>  #include "libcamera/internal/log.h"
>>  #include "libcamera/internal/media_device.h"
>>  #include "libcamera/internal/pipeline_handler.h"
>>  #include "libcamera/internal/sysfs.h"
>> -#include "libcamera/internal/utils.h"
>>  #include "libcamera/internal/v4l2_videodevice.h"
>>  
>>  namespace libcamera {
>> diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp
>> index 8bbac0085c9b..025ca56205f8 100644
>> --- a/src/libcamera/pipeline/vimc/vimc.cpp
>> +++ b/src/libcamera/pipeline/vimc/vimc.cpp
>> @@ -23,13 +23,14 @@
>>  #include <libcamera/request.h>
>>  #include <libcamera/stream.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/camera_sensor.h"
>>  #include "libcamera/internal/device_enumerator.h"
>>  #include "libcamera/internal/ipa_manager.h"
>>  #include "libcamera/internal/log.h"
>>  #include "libcamera/internal/media_device.h"
>>  #include "libcamera/internal/pipeline_handler.h"
>> -#include "libcamera/internal/utils.h"
>>  #include "libcamera/internal/v4l2_subdevice.h"
>>  #include "libcamera/internal/v4l2_videodevice.h"
>>  
>> diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp
>> index e507a8bba8a6..6fb2a743c3c2 100644
>> --- a/src/libcamera/pipeline_handler.cpp
>> +++ b/src/libcamera/pipeline_handler.cpp
>> @@ -13,11 +13,12 @@
>>  #include <libcamera/camera.h>
>>  #include <libcamera/camera_manager.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/device_enumerator.h"
>>  #include "libcamera/internal/log.h"
>>  #include "libcamera/internal/media_device.h"
>>  #include "libcamera/internal/tracepoints.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  /**
>>   * \file pipeline_handler.h
>> diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp
>> index 40a434a6b0c2..35091f60c1e9 100644
>> --- a/src/libcamera/process.cpp
>> +++ b/src/libcamera/process.cpp
>> @@ -20,9 +20,10 @@
>>  #include <unistd.h>
>>  #include <vector>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/event_notifier.h"
>>  #include "libcamera/internal/log.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  /**
>>   * \file process.h
>> diff --git a/src/libcamera/source-paths.cpp b/src/libcamera/source-paths.cpp
>> index b39f5f853e39..2a59105e8283 100644
>> --- a/src/libcamera/source-paths.cpp
>> +++ b/src/libcamera/source-paths.cpp
>> @@ -12,7 +12,7 @@
>>  #include <link.h>
>>  #include <sys/stat.h>
>>  
>> -#include "libcamera/internal/utils.h"
>> +#include <libcamera/base/utils.h>
>>  
>>  /**
>>   * \file source-paths.h
>> diff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp
>> index f7bafcf8fc97..d5d68427e658 100644
>> --- a/src/libcamera/stream.cpp
>> +++ b/src/libcamera/stream.cpp
>> @@ -15,8 +15,9 @@
>>  
>>  #include <libcamera/request.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/log.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  /**
>>   * \file stream.h
>> diff --git a/src/libcamera/timer.cpp b/src/libcamera/timer.cpp
>> index c242113a782e..9496671edffc 100644
>> --- a/src/libcamera/timer.cpp
>> +++ b/src/libcamera/timer.cpp
>> @@ -11,11 +11,12 @@
>>  
>>  #include <libcamera/camera_manager.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/event_dispatcher.h"
>>  #include "libcamera/internal/log.h"
>>  #include "libcamera/internal/message.h"
>>  #include "libcamera/internal/thread.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  /**
>>   * \file timer.h
>> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
>> index 5660e6ea5839..facb53e13169 100644
>> --- a/src/libcamera/v4l2_device.cpp
>> +++ b/src/libcamera/v4l2_device.cpp
>> @@ -16,10 +16,11 @@
>>  #include <sys/syscall.h>
>>  #include <unistd.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/event_notifier.h"
>>  #include "libcamera/internal/log.h"
>>  #include "libcamera/internal/sysfs.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  /**
>>   * \file v4l2_device.h
>> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
>> index 721ff5a92a2b..2c56cfafbce4 100644
>> --- a/src/libcamera/v4l2_subdevice.cpp
>> +++ b/src/libcamera/v4l2_subdevice.cpp
>> @@ -19,10 +19,11 @@
>>  
>>  #include <libcamera/geometry.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/log.h"
>>  #include "libcamera/internal/media_device.h"
>>  #include "libcamera/internal/media_object.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  /**
>>   * \file v4l2_subdevice.h
>> diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp
>> index f8bfe595e90e..a5a25507462e 100644
>> --- a/src/v4l2/v4l2_camera_proxy.cpp
>> +++ b/src/v4l2/v4l2_camera_proxy.cpp
>> @@ -20,9 +20,10 @@
>>  #include <libcamera/formats.h>
>>  #include <libcamera/object.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/formats.h"
>>  #include "libcamera/internal/log.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  #include "v4l2_camera.h"
>>  #include "v4l2_camera_file.h"
>> diff --git a/src/v4l2/v4l2_compat_manager.cpp b/src/v4l2/v4l2_compat_manager.cpp
>> index 96dbcdf28f04..27de6c50ff4e 100644
>> --- a/src/v4l2/v4l2_compat_manager.cpp
>> +++ b/src/v4l2/v4l2_compat_manager.cpp
>> @@ -22,8 +22,9 @@
>>  #include <libcamera/camera.h>
>>  #include <libcamera/camera_manager.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/log.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  #include "v4l2_camera_file.h"
>>  
>> diff --git a/test/camera-sensor.cpp b/test/camera-sensor.cpp
>> index 8c7fd1d2d444..a8dcad8215e5 100644
>> --- a/test/camera-sensor.cpp
>> +++ b/test/camera-sensor.cpp
>> @@ -10,10 +10,11 @@
>>  
>>  #include <linux/media-bus-format.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/camera_sensor.h"
>>  #include "libcamera/internal/device_enumerator.h"
>>  #include "libcamera/internal/media_device.h"
>> -#include "libcamera/internal/utils.h"
>>  #include "libcamera/internal/v4l2_subdevice.h"
>>  
>>  #include "test.h"
>> diff --git a/test/file-descriptor.cpp b/test/file-descriptor.cpp
>> index aa3c896fb937..85b077a25c32 100644
>> --- a/test/file-descriptor.cpp
>> +++ b/test/file-descriptor.cpp
>> @@ -13,7 +13,7 @@
>>  
>>  #include <libcamera/file_descriptor.h>
>>  
>> -#include "libcamera/internal/utils.h"
>> +#include <libcamera/base/utils.h>
>>  
>>  #include "test.h"
>>  
>> diff --git a/test/ipc/unixsocket_ipc.cpp b/test/ipc/unixsocket_ipc.cpp
>> index 3049eaa8bb2a..161d09b98719 100644
>> --- a/test/ipc/unixsocket_ipc.cpp
>> +++ b/test/ipc/unixsocket_ipc.cpp
>> @@ -15,6 +15,8 @@
>>  #include <sys/wait.h>
>>  #include <unistd.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/event_dispatcher.h"
>>  #include "libcamera/internal/ipa_data_serializer.h"
>>  #include "libcamera/internal/ipc_pipe.h"
>> @@ -22,7 +24,6 @@
>>  #include "libcamera/internal/process.h"
>>  #include "libcamera/internal/thread.h"
>>  #include "libcamera/internal/timer.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  #include "test.h"
>>  
>> diff --git a/test/log/log_process.cpp b/test/log/log_process.cpp
>> index c0a1a012d366..413d9207ea68 100644
>> --- a/test/log/log_process.cpp
>> +++ b/test/log/log_process.cpp
>> @@ -16,12 +16,13 @@
>>  
>>  #include <libcamera/logging.h>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/event_dispatcher.h"
>>  #include "libcamera/internal/log.h"
>>  #include "libcamera/internal/process.h"
>>  #include "libcamera/internal/thread.h"
>>  #include "libcamera/internal/timer.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  #include "test.h"
>>  
>> diff --git a/test/pixel-format.cpp b/test/pixel-format.cpp
>> index c4a08f468ade..0f364f833ed1 100644
>> --- a/test/pixel-format.cpp
>> +++ b/test/pixel-format.cpp
>> @@ -10,7 +10,7 @@
>>  #include <libcamera/formats.h>
>>  #include <libcamera/pixel_format.h>
>>  
>> -#include "libcamera/internal/utils.h"
>> +#include <libcamera/base/utils.h>
>>  
>>  #include "test.h"
>>  
>> diff --git a/test/process/process_test.cpp b/test/process/process_test.cpp
>> index 1279d8c17598..a5155bae3162 100644
>> --- a/test/process/process_test.cpp
>> +++ b/test/process/process_test.cpp
>> @@ -9,11 +9,12 @@
>>  #include <unistd.h>
>>  #include <vector>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/event_dispatcher.h"
>>  #include "libcamera/internal/process.h"
>>  #include "libcamera/internal/thread.h"
>>  #include "libcamera/internal/timer.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  #include "test.h"
>>  
>> diff --git a/test/signal-threads.cpp b/test/signal-threads.cpp
>> index 3c5f3792e385..8a96b5d2abb3 100644
>> --- a/test/signal-threads.cpp
>> +++ b/test/signal-threads.cpp
>> @@ -9,9 +9,10 @@
>>  #include <iostream>
>>  #include <thread>
>>  
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/message.h"
>>  #include "libcamera/internal/thread.h"
>> -#include "libcamera/internal/utils.h"
>>  
>>  #include "test.h"
>>  
>> diff --git a/test/utils.cpp b/test/utils.cpp
>> index f170ae4c2f35..9cd2cd070cb9 100644
>> --- a/test/utils.cpp
>> +++ b/test/utils.cpp
>> @@ -14,7 +14,7 @@
>>  #include <libcamera/geometry.h>
>>  #include <libcamera/span.h>
>>  
>> -#include "libcamera/internal/utils.h"
>> +#include <libcamera/base/utils.h>
>>  
>>  #include "test.h"
>>  
>> diff --git a/test/v4l2_subdevice/list_formats.cpp b/test/v4l2_subdevice/list_formats.cpp
>> index 74ec81a8560c..9cbd7b9439c3 100644
>> --- a/test/v4l2_subdevice/list_formats.cpp
>> +++ b/test/v4l2_subdevice/list_formats.cpp
>> @@ -10,7 +10,8 @@
>>  
>>  #include <libcamera/geometry.h>
>>  
>> -#include "libcamera/internal/utils.h"
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/v4l2_subdevice.h"
>>  
>>  #include "v4l2_subdevice_test.h"
>> diff --git a/test/v4l2_videodevice/formats.cpp b/test/v4l2_videodevice/formats.cpp
>> index 255446fe758a..6c05262201fa 100644
>> --- a/test/v4l2_videodevice/formats.cpp
>> +++ b/test/v4l2_videodevice/formats.cpp
>> @@ -8,7 +8,8 @@
>>  #include <iostream>
>>  #include <limits.h>
>>  
>> -#include "libcamera/internal/utils.h"
>> +#include <libcamera/base/utils.h>
>> +
>>  #include "libcamera/internal/v4l2_videodevice.h"
>>  
>>  #include "v4l2_videodevice_test.h"
>
Kieran Bingham June 25, 2021, 2:45 p.m. UTC | #50
Hi Laurent,

On 25/06/2021 13:41, Laurent Pinchart wrote:
> Hi Kieran,
> 
> Thank you for the patch.
> 
> On Fri, Jun 25, 2021 at 02:35:34AM +0100, Kieran Bingham wrote:
>> Move the event notifier, and associated header updates.
>>
>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>> ---
>>  include/libcamera/{internal => base}/event_notifier.h | 0
>>  include/libcamera/base/meson.build                    | 1 +
>>  include/libcamera/internal/meson.build                | 1 -
>>  src/libcamera/base/event_dispatcher_poll.cpp          | 3 +--
>>  src/libcamera/{ => base}/event_notifier.cpp           | 6 +++---
>>  src/libcamera/base/meson.build                        | 1 +
>>  src/libcamera/device_enumerator_udev.cpp              | 2 +-
>>  src/libcamera/ipc_unixsocket.cpp                      | 3 +--
>>  src/libcamera/meson.build                             | 1 -
>>  src/libcamera/process.cpp                             | 3 +--
>>  src/libcamera/v4l2_device.cpp                         | 2 +-
>>  src/libcamera/v4l2_videodevice.cpp                    | 2 +-
>>  test/event-thread.cpp                                 | 3 +--
>>  test/event.cpp                                        | 3 +--
>>  test/ipa/ipa_interface_test.cpp                       | 2 +-
>>  15 files changed, 14 insertions(+), 19 deletions(-)
>>  rename include/libcamera/{internal => base}/event_notifier.h (100%)
>>  rename src/libcamera/{ => base}/event_notifier.cpp (98%)
>>
>> diff --git a/include/libcamera/internal/event_notifier.h b/include/libcamera/base/event_notifier.h
>> similarity index 100%
>> rename from include/libcamera/internal/event_notifier.h
>> rename to include/libcamera/base/event_notifier.h
>> diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build
>> index 6fc6c138a5fd..83c664affc88 100644
>> --- a/include/libcamera/base/meson.build
>> +++ b/include/libcamera/base/meson.build
>> @@ -7,6 +7,7 @@ libcamera_base_headers = files([
>>      'class.h',
>>      'event_dispatcher.h',
>>      'event_dispatcher_poll.h',
>> +    'event_notifier.h',
>>      'file.h',
>>      'log.h',
>>      'message.h',
>> diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build
>> index b10285edac27..61af16bfe05d 100644
>> --- a/include/libcamera/internal/meson.build
>> +++ b/include/libcamera/internal/meson.build
>> @@ -22,7 +22,6 @@ libcamera_internal_headers = files([
>>      'device_enumerator.h',
>>      'device_enumerator_sysfs.h',
>>      'device_enumerator_udev.h',
>> -    'event_notifier.h',
>>      'formats.h',
>>      'ipa_manager.h',
>>      'ipa_module.h',
>> diff --git a/src/libcamera/base/event_dispatcher_poll.cpp b/src/libcamera/base/event_dispatcher_poll.cpp
>> index d76ca7fc2c32..5839373a5281 100644
>> --- a/src/libcamera/base/event_dispatcher_poll.cpp
>> +++ b/src/libcamera/base/event_dispatcher_poll.cpp
>> @@ -16,13 +16,12 @@
>>  #include <sys/eventfd.h>
>>  #include <unistd.h>
>>  
>> +#include <libcamera/base/event_notifier.h>
>>  #include <libcamera/base/log.h>
>>  #include <libcamera/base/thread.h>
>>  #include <libcamera/base/timer.h>
>>  #include <libcamera/base/utils.h>
>>  
>> -#include "libcamera/internal/event_notifier.h"
>> -
>>  /**
>>   * \file base/event_dispatcher_poll.h
>>   */
>> diff --git a/src/libcamera/event_notifier.cpp b/src/libcamera/base/event_notifier.cpp
>> similarity index 98%
>> rename from src/libcamera/event_notifier.cpp
>> rename to src/libcamera/base/event_notifier.cpp
>> index 784016a9f907..fd93c0878c6f 100644
>> --- a/src/libcamera/event_notifier.cpp
>> +++ b/src/libcamera/base/event_notifier.cpp
>> @@ -5,14 +5,14 @@
>>   * event_notifier.cpp - File descriptor event notifier
>>   */
>>  
>> -#include "libcamera/internal/event_notifier.h"
>> -
>> -#include <libcamera/camera_manager.h>
>> +#include <libcamera/base/event_notifier.h>
> 
> This should be moved after libcamera/base/event_dispatcher.h.

We're in event_notifier.cpp, and this is event_notifier.h ... so
shouldn't it be classed as the interface implementation, and thus be the
first inclusion in a group on its own ?


> With the updated header guard,

Indeed, already fixed,

> 

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Thanks.

> 
>>  
>>  #include <libcamera/base/event_dispatcher.h>
>>  #include <libcamera/base/message.h>
>>  #include <libcamera/base/thread.h>
>>  
>> +#include <libcamera/camera_manager.h>
>> +
>>  /**
>>   * \file event_notifier.h
>>   * \brief File descriptor event notifier
>> diff --git a/src/libcamera/base/meson.build b/src/libcamera/base/meson.build
>> index fb8ed79acd8e..a8b04cfc8a5f 100644
>> --- a/src/libcamera/base/meson.build
>> +++ b/src/libcamera/base/meson.build
>> @@ -5,6 +5,7 @@ libcamera_base_sources = files([
>>      'bound_method.cpp',
>>      'event_dispatcher.cpp',
>>      'event_dispatcher_poll.cpp',
>> +    'event_notifier.cpp',
>>      'file.cpp',
>>      'log.cpp',
>>      'message.cpp',
>> diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp
>> index 4b842773fcd6..37a2c5aa55db 100644
>> --- a/src/libcamera/device_enumerator_udev.cpp
>> +++ b/src/libcamera/device_enumerator_udev.cpp
>> @@ -17,9 +17,9 @@
>>  #include <sys/sysmacros.h>
>>  #include <unistd.h>
>>  
>> +#include <libcamera/base/event_notifier.h>
>>  #include <libcamera/base/log.h>
>>  
>> -#include "libcamera/internal/event_notifier.h"
>>  #include "libcamera/internal/media_device.h"
>>  
>>  namespace libcamera {
>> diff --git a/src/libcamera/ipc_unixsocket.cpp b/src/libcamera/ipc_unixsocket.cpp
>> index 1466597077d4..f23eb783bcb5 100644
>> --- a/src/libcamera/ipc_unixsocket.cpp
>> +++ b/src/libcamera/ipc_unixsocket.cpp
>> @@ -12,10 +12,9 @@
>>  #include <sys/socket.h>
>>  #include <unistd.h>
>>  
>> +#include <libcamera/base/event_notifier.h>
>>  #include <libcamera/base/log.h>
>>  
>> -#include "libcamera/internal/event_notifier.h"
>> -
>>  /**
>>   * \file ipc_unixsocket.h
>>   * \brief IPC mechanism based on Unix sockets
>> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
>> index 58eee14aed97..1f163cfe1225 100644
>> --- a/src/libcamera/meson.build
>> +++ b/src/libcamera/meson.build
>> @@ -15,7 +15,6 @@ libcamera_sources = files([
>>      'delayed_controls.cpp',
>>      'device_enumerator.cpp',
>>      'device_enumerator_sysfs.cpp',
>> -    'event_notifier.cpp',
>>      'file_descriptor.cpp',
>>      'formats.cpp',
>>      'framebuffer_allocator.cpp',
>> diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp
>> index 463380299a65..4fe4ad570b74 100644
>> --- a/src/libcamera/process.cpp
>> +++ b/src/libcamera/process.cpp
>> @@ -20,11 +20,10 @@
>>  #include <unistd.h>
>>  #include <vector>
>>  
>> +#include <libcamera/base/event_notifier.h>
>>  #include <libcamera/base/log.h>
>>  #include <libcamera/base/utils.h>
>>  
>> -#include "libcamera/internal/event_notifier.h"
>> -
>>  /**
>>   * \file process.h
>>   * \brief Process object
>> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
>> index 334b9b78b812..98d93a12a7be 100644
>> --- a/src/libcamera/v4l2_device.cpp
>> +++ b/src/libcamera/v4l2_device.cpp
>> @@ -16,10 +16,10 @@
>>  #include <sys/syscall.h>
>>  #include <unistd.h>
>>  
>> +#include <libcamera/base/event_notifier.h>
>>  #include <libcamera/base/log.h>
>>  #include <libcamera/base/utils.h>
>>  
>> -#include "libcamera/internal/event_notifier.h"
>>  #include "libcamera/internal/sysfs.h"
>>  
>>  /**
>> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
>> index dc23510bc5aa..3d2d99b46e4e 100644
>> --- a/src/libcamera/v4l2_videodevice.cpp
>> +++ b/src/libcamera/v4l2_videodevice.cpp
>> @@ -21,11 +21,11 @@
>>  
>>  #include <linux/version.h>
>>  
>> +#include <libcamera/base/event_notifier.h>
>>  #include <libcamera/base/log.h>
>>  
>>  #include <libcamera/file_descriptor.h>
>>  
>> -#include "libcamera/internal/event_notifier.h"
>>  #include "libcamera/internal/media_device.h"
>>  #include "libcamera/internal/media_object.h"
>>  
>> diff --git a/test/event-thread.cpp b/test/event-thread.cpp
>> index 05c5d26d3611..575261664c2f 100644
>> --- a/test/event-thread.cpp
>> +++ b/test/event-thread.cpp
>> @@ -10,11 +10,10 @@
>>  #include <string.h>
>>  #include <unistd.h>
>>  
>> +#include <libcamera/base/event_notifier.h>
>>  #include <libcamera/base/thread.h>
>>  #include <libcamera/base/timer.h>
>>  
>> -#include "libcamera/internal/event_notifier.h"
>> -
>>  #include "test.h"
>>  
>>  using namespace std;
>> diff --git a/test/event.cpp b/test/event.cpp
>> index aa79da99c286..c2274344b7f0 100644
>> --- a/test/event.cpp
>> +++ b/test/event.cpp
>> @@ -10,11 +10,10 @@
>>  #include <unistd.h>
>>  
>>  #include <libcamera/base/event_dispatcher.h>
>> +#include <libcamera/base/event_notifier.h>
>>  #include <libcamera/base/thread.h>
>>  #include <libcamera/base/timer.h>
>>  
>> -#include "libcamera/internal/event_notifier.h"
>> -
>>  #include "test.h"
>>  
>>  using namespace std;
>> diff --git a/test/ipa/ipa_interface_test.cpp b/test/ipa/ipa_interface_test.cpp
>> index 656d86552d85..ee9f26510784 100644
>> --- a/test/ipa/ipa_interface_test.cpp
>> +++ b/test/ipa/ipa_interface_test.cpp
>> @@ -15,11 +15,11 @@
>>  #include <libcamera/ipa/vimc_ipa_proxy.h>
>>  
>>  #include <libcamera/base/event_dispatcher.h>
>> +#include <libcamera/base/event_notifier.h>
>>  #include <libcamera/base/thread.h>
>>  #include <libcamera/base/timer.h>
>>  
>>  #include "libcamera/internal/device_enumerator.h"
>> -#include "libcamera/internal/event_notifier.h"
>>  #include "libcamera/internal/ipa_manager.h"
>>  #include "libcamera/internal/ipa_module.h"
>>  #include "libcamera/internal/pipeline_handler.h"
>
Laurent Pinchart June 25, 2021, 2:51 p.m. UTC | #51
Hi Kieran,

On Fri, Jun 25, 2021 at 03:45:16PM +0100, Kieran Bingham wrote:
> On 25/06/2021 13:41, Laurent Pinchart wrote:
> > On Fri, Jun 25, 2021 at 02:35:34AM +0100, Kieran Bingham wrote:
> >> Move the event notifier, and associated header updates.
> >>
> >> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> >> ---
> >>  include/libcamera/{internal => base}/event_notifier.h | 0
> >>  include/libcamera/base/meson.build                    | 1 +
> >>  include/libcamera/internal/meson.build                | 1 -
> >>  src/libcamera/base/event_dispatcher_poll.cpp          | 3 +--
> >>  src/libcamera/{ => base}/event_notifier.cpp           | 6 +++---
> >>  src/libcamera/base/meson.build                        | 1 +
> >>  src/libcamera/device_enumerator_udev.cpp              | 2 +-
> >>  src/libcamera/ipc_unixsocket.cpp                      | 3 +--
> >>  src/libcamera/meson.build                             | 1 -
> >>  src/libcamera/process.cpp                             | 3 +--
> >>  src/libcamera/v4l2_device.cpp                         | 2 +-
> >>  src/libcamera/v4l2_videodevice.cpp                    | 2 +-
> >>  test/event-thread.cpp                                 | 3 +--
> >>  test/event.cpp                                        | 3 +--
> >>  test/ipa/ipa_interface_test.cpp                       | 2 +-
> >>  15 files changed, 14 insertions(+), 19 deletions(-)
> >>  rename include/libcamera/{internal => base}/event_notifier.h (100%)
> >>  rename src/libcamera/{ => base}/event_notifier.cpp (98%)
> >>
> >> diff --git a/include/libcamera/internal/event_notifier.h b/include/libcamera/base/event_notifier.h
> >> similarity index 100%
> >> rename from include/libcamera/internal/event_notifier.h
> >> rename to include/libcamera/base/event_notifier.h
> >> diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build
> >> index 6fc6c138a5fd..83c664affc88 100644
> >> --- a/include/libcamera/base/meson.build
> >> +++ b/include/libcamera/base/meson.build
> >> @@ -7,6 +7,7 @@ libcamera_base_headers = files([
> >>      'class.h',
> >>      'event_dispatcher.h',
> >>      'event_dispatcher_poll.h',
> >> +    'event_notifier.h',
> >>      'file.h',
> >>      'log.h',
> >>      'message.h',
> >> diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build
> >> index b10285edac27..61af16bfe05d 100644
> >> --- a/include/libcamera/internal/meson.build
> >> +++ b/include/libcamera/internal/meson.build
> >> @@ -22,7 +22,6 @@ libcamera_internal_headers = files([
> >>      'device_enumerator.h',
> >>      'device_enumerator_sysfs.h',
> >>      'device_enumerator_udev.h',
> >> -    'event_notifier.h',
> >>      'formats.h',
> >>      'ipa_manager.h',
> >>      'ipa_module.h',
> >> diff --git a/src/libcamera/base/event_dispatcher_poll.cpp b/src/libcamera/base/event_dispatcher_poll.cpp
> >> index d76ca7fc2c32..5839373a5281 100644
> >> --- a/src/libcamera/base/event_dispatcher_poll.cpp
> >> +++ b/src/libcamera/base/event_dispatcher_poll.cpp
> >> @@ -16,13 +16,12 @@
> >>  #include <sys/eventfd.h>
> >>  #include <unistd.h>
> >>  
> >> +#include <libcamera/base/event_notifier.h>
> >>  #include <libcamera/base/log.h>
> >>  #include <libcamera/base/thread.h>
> >>  #include <libcamera/base/timer.h>
> >>  #include <libcamera/base/utils.h>
> >>  
> >> -#include "libcamera/internal/event_notifier.h"
> >> -
> >>  /**
> >>   * \file base/event_dispatcher_poll.h
> >>   */
> >> diff --git a/src/libcamera/event_notifier.cpp b/src/libcamera/base/event_notifier.cpp
> >> similarity index 98%
> >> rename from src/libcamera/event_notifier.cpp
> >> rename to src/libcamera/base/event_notifier.cpp
> >> index 784016a9f907..fd93c0878c6f 100644
> >> --- a/src/libcamera/event_notifier.cpp
> >> +++ b/src/libcamera/base/event_notifier.cpp
> >> @@ -5,14 +5,14 @@
> >>   * event_notifier.cpp - File descriptor event notifier
> >>   */
> >>  
> >> -#include "libcamera/internal/event_notifier.h"
> >> -
> >> -#include <libcamera/camera_manager.h>
> >> +#include <libcamera/base/event_notifier.h>
> > 
> > This should be moved after libcamera/base/event_dispatcher.h.
> 
> We're in event_notifier.cpp, and this is event_notifier.h ... so
> shouldn't it be classed as the interface implementation, and thus be the
> first inclusion in a group on its own ?

Oops. Maybe "" instead of <> is indeed a good idea, both clang-format
and humans get it wrong otherwise :-)

> > With the updated header guard,
> 
> Indeed, already fixed,
> 
> > 
> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> Thanks.
> 
> > 
> >>  
> >>  #include <libcamera/base/event_dispatcher.h>
> >>  #include <libcamera/base/message.h>
> >>  #include <libcamera/base/thread.h>
> >>  
> >> +#include <libcamera/camera_manager.h>
> >> +
> >>  /**
> >>   * \file event_notifier.h
> >>   * \brief File descriptor event notifier
> >> diff --git a/src/libcamera/base/meson.build b/src/libcamera/base/meson.build
> >> index fb8ed79acd8e..a8b04cfc8a5f 100644
> >> --- a/src/libcamera/base/meson.build
> >> +++ b/src/libcamera/base/meson.build
> >> @@ -5,6 +5,7 @@ libcamera_base_sources = files([
> >>      'bound_method.cpp',
> >>      'event_dispatcher.cpp',
> >>      'event_dispatcher_poll.cpp',
> >> +    'event_notifier.cpp',
> >>      'file.cpp',
> >>      'log.cpp',
> >>      'message.cpp',
> >> diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp
> >> index 4b842773fcd6..37a2c5aa55db 100644
> >> --- a/src/libcamera/device_enumerator_udev.cpp
> >> +++ b/src/libcamera/device_enumerator_udev.cpp
> >> @@ -17,9 +17,9 @@
> >>  #include <sys/sysmacros.h>
> >>  #include <unistd.h>
> >>  
> >> +#include <libcamera/base/event_notifier.h>
> >>  #include <libcamera/base/log.h>
> >>  
> >> -#include "libcamera/internal/event_notifier.h"
> >>  #include "libcamera/internal/media_device.h"
> >>  
> >>  namespace libcamera {
> >> diff --git a/src/libcamera/ipc_unixsocket.cpp b/src/libcamera/ipc_unixsocket.cpp
> >> index 1466597077d4..f23eb783bcb5 100644
> >> --- a/src/libcamera/ipc_unixsocket.cpp
> >> +++ b/src/libcamera/ipc_unixsocket.cpp
> >> @@ -12,10 +12,9 @@
> >>  #include <sys/socket.h>
> >>  #include <unistd.h>
> >>  
> >> +#include <libcamera/base/event_notifier.h>
> >>  #include <libcamera/base/log.h>
> >>  
> >> -#include "libcamera/internal/event_notifier.h"
> >> -
> >>  /**
> >>   * \file ipc_unixsocket.h
> >>   * \brief IPC mechanism based on Unix sockets
> >> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> >> index 58eee14aed97..1f163cfe1225 100644
> >> --- a/src/libcamera/meson.build
> >> +++ b/src/libcamera/meson.build
> >> @@ -15,7 +15,6 @@ libcamera_sources = files([
> >>      'delayed_controls.cpp',
> >>      'device_enumerator.cpp',
> >>      'device_enumerator_sysfs.cpp',
> >> -    'event_notifier.cpp',
> >>      'file_descriptor.cpp',
> >>      'formats.cpp',
> >>      'framebuffer_allocator.cpp',
> >> diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp
> >> index 463380299a65..4fe4ad570b74 100644
> >> --- a/src/libcamera/process.cpp
> >> +++ b/src/libcamera/process.cpp
> >> @@ -20,11 +20,10 @@
> >>  #include <unistd.h>
> >>  #include <vector>
> >>  
> >> +#include <libcamera/base/event_notifier.h>
> >>  #include <libcamera/base/log.h>
> >>  #include <libcamera/base/utils.h>
> >>  
> >> -#include "libcamera/internal/event_notifier.h"
> >> -
> >>  /**
> >>   * \file process.h
> >>   * \brief Process object
> >> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
> >> index 334b9b78b812..98d93a12a7be 100644
> >> --- a/src/libcamera/v4l2_device.cpp
> >> +++ b/src/libcamera/v4l2_device.cpp
> >> @@ -16,10 +16,10 @@
> >>  #include <sys/syscall.h>
> >>  #include <unistd.h>
> >>  
> >> +#include <libcamera/base/event_notifier.h>
> >>  #include <libcamera/base/log.h>
> >>  #include <libcamera/base/utils.h>
> >>  
> >> -#include "libcamera/internal/event_notifier.h"
> >>  #include "libcamera/internal/sysfs.h"
> >>  
> >>  /**
> >> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
> >> index dc23510bc5aa..3d2d99b46e4e 100644
> >> --- a/src/libcamera/v4l2_videodevice.cpp
> >> +++ b/src/libcamera/v4l2_videodevice.cpp
> >> @@ -21,11 +21,11 @@
> >>  
> >>  #include <linux/version.h>
> >>  
> >> +#include <libcamera/base/event_notifier.h>
> >>  #include <libcamera/base/log.h>
> >>  
> >>  #include <libcamera/file_descriptor.h>
> >>  
> >> -#include "libcamera/internal/event_notifier.h"
> >>  #include "libcamera/internal/media_device.h"
> >>  #include "libcamera/internal/media_object.h"
> >>  
> >> diff --git a/test/event-thread.cpp b/test/event-thread.cpp
> >> index 05c5d26d3611..575261664c2f 100644
> >> --- a/test/event-thread.cpp
> >> +++ b/test/event-thread.cpp
> >> @@ -10,11 +10,10 @@
> >>  #include <string.h>
> >>  #include <unistd.h>
> >>  
> >> +#include <libcamera/base/event_notifier.h>
> >>  #include <libcamera/base/thread.h>
> >>  #include <libcamera/base/timer.h>
> >>  
> >> -#include "libcamera/internal/event_notifier.h"
> >> -
> >>  #include "test.h"
> >>  
> >>  using namespace std;
> >> diff --git a/test/event.cpp b/test/event.cpp
> >> index aa79da99c286..c2274344b7f0 100644
> >> --- a/test/event.cpp
> >> +++ b/test/event.cpp
> >> @@ -10,11 +10,10 @@
> >>  #include <unistd.h>
> >>  
> >>  #include <libcamera/base/event_dispatcher.h>
> >> +#include <libcamera/base/event_notifier.h>
> >>  #include <libcamera/base/thread.h>
> >>  #include <libcamera/base/timer.h>
> >>  
> >> -#include "libcamera/internal/event_notifier.h"
> >> -
> >>  #include "test.h"
> >>  
> >>  using namespace std;
> >> diff --git a/test/ipa/ipa_interface_test.cpp b/test/ipa/ipa_interface_test.cpp
> >> index 656d86552d85..ee9f26510784 100644
> >> --- a/test/ipa/ipa_interface_test.cpp
> >> +++ b/test/ipa/ipa_interface_test.cpp
> >> @@ -15,11 +15,11 @@
> >>  #include <libcamera/ipa/vimc_ipa_proxy.h>
> >>  
> >>  #include <libcamera/base/event_dispatcher.h>
> >> +#include <libcamera/base/event_notifier.h>
> >>  #include <libcamera/base/thread.h>
> >>  #include <libcamera/base/timer.h>
> >>  
> >>  #include "libcamera/internal/device_enumerator.h"
> >> -#include "libcamera/internal/event_notifier.h"
> >>  #include "libcamera/internal/ipa_manager.h"
> >>  #include "libcamera/internal/ipa_module.h"
> >>  #include "libcamera/internal/pipeline_handler.h"