From patchwork Mon Jan 21 00:59:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 286 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A316360CA2 for ; Mon, 21 Jan 2019 01:59:36 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3A14BD6C for ; Mon, 21 Jan 2019 01:59:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1548032376; bh=W4TNRPJjGe2m171Wr95ZskWWtBs9asvIaKg/wUicXtg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=V+lZUm+PD4WK5HVY+9FbirkBoZUrKGDQw6x+AKjN2hVAC0hyf/z1yZrV+y0tZ9PiI QHkCFeeyYyPN7cH83jwi9f41WgGcHUR9PI6uZRIOedQz83jd3k4HkUiQmL+3gXleDa Itf8Y8YIJoaSgsSxeowYFr6dFNudGofVa6hHO5mY= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 21 Jan 2019 02:59:30 +0200 Message-Id: <20190121005930.10112-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190121005930.10112-1-laurent.pinchart@ideasonboard.com> References: <20190121005930.10112-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 6/6] libcamera: Use log categories X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Jan 2019 00:59:37 -0000 Use log categories in all the existing code base. Signed-off-by: Laurent Pinchart --- src/libcamera/camera_manager.cpp | 14 +++++--- src/libcamera/device_enumerator.cpp | 25 ++++++++----- src/libcamera/event_dispatcher.cpp | 4 +++ src/libcamera/event_dispatcher_poll.cpp | 28 +++++++++------ src/libcamera/media_device.cpp | 48 ++++++++++++++----------- src/libcamera/media_object.cpp | 7 ++-- src/libcamera/pipeline_handler.cpp | 5 ++- src/libcamera/timer.cpp | 6 ++-- src/libcamera/v4l2_device.cpp | 25 +++++++------ 9 files changed, 102 insertions(+), 60 deletions(-) diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index d76eaa7ace86..f9085f45e331 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -21,6 +21,8 @@ namespace libcamera { +LOG_DEFINE_CATEGORY(Camera) + /** * \class CameraManager * \brief Provide access and manage all cameras in the system @@ -101,8 +103,9 @@ int CameraManager::start() break; } - LOG(Debug) << "Pipeline handler \"" << factory->name() - << "\" matched"; + LOGC(Camera, Debug) + << "Pipeline handler \"" << factory->name() + << "\" matched"; pipes_.push_back(pipe); } } @@ -176,8 +179,9 @@ void CameraManager::addCamera(std::shared_ptr camera) { for (std::shared_ptr c : cameras_) { if (c->name() == camera->name()) { - LOG(Warning) << "Registering camera with duplicate name '" - << camera->name() << "'"; + LOGC(Camera, Warning) + << "Registering camera with duplicate name '" + << camera->name() << "'"; break; } } @@ -216,7 +220,7 @@ CameraManager *CameraManager::instance() void CameraManager::setEventDispatcher(std::unique_ptr dispatcher) { if (dispatcher_) { - LOG(Warning) << "Event dispatcher is already set"; + LOGC(Camera, Warning) << "Event dispatcher is already set"; return; } diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp index 55c510e3b79a..c2493e921e87 100644 --- a/src/libcamera/device_enumerator.cpp +++ b/src/libcamera/device_enumerator.cpp @@ -42,6 +42,8 @@ namespace libcamera { +LOG_DEFINE_CATEGORY(DeviceEnumerator) + /** * \class DeviceMatch * \brief Description of a media device search pattern @@ -155,7 +157,8 @@ DeviceEnumerator::~DeviceEnumerator() { for (MediaDevice *dev : devices_) { if (dev->busy()) - LOG(Error) << "Removing media device while still in use"; + LOGC(DeviceEnumerator, Error) + << "Removing media device while still in use"; delete dev; } @@ -205,13 +208,15 @@ int DeviceEnumerator::addDevice(const std::string &devnode) ret = media->populate(); if (ret < 0) { - LOG(Info) << "Unable to populate media device " << devnode << - " (" << strerror(-ret) << "), skipping"; + LOGC(DeviceEnumerator, Info) + << "Unable to populate media device " << devnode + << " (" << strerror(-ret) << "), skipping"; return ret; } - LOG(Debug) << "New media device \"" << media->driver() - << "\" created from " << devnode; + LOGC(DeviceEnumerator, Debug) + << "New media device \"" << media->driver() + << "\" created from " << devnode; /* Associate entities to device node paths. */ for (MediaEntity *entity : media->entities()) { @@ -251,8 +256,9 @@ MediaDevice *DeviceEnumerator::search(const DeviceMatch &dm) continue; if (dm.match(dev)) { - LOG(Debug) << "Successful match for media device \"" - << dev->driver() << "\""; + LOGC(DeviceEnumerator, Debug) + << "Successful match for media device \"" + << dev->driver() << "\""; return dev; } } @@ -330,8 +336,9 @@ int DeviceEnumeratorUdev::enumerate() dev = udev_device_new_from_syspath(udev_, syspath); if (!dev) { - LOG(Warning) << "Failed to get device for '" << - syspath << "', skipping"; + LOGC(DeviceEnumerator, Warning) + << "Failed to get device for '" + << syspath << "', skipping"; continue; } diff --git a/src/libcamera/event_dispatcher.cpp b/src/libcamera/event_dispatcher.cpp index 5462730214d6..f7c40734095e 100644 --- a/src/libcamera/event_dispatcher.cpp +++ b/src/libcamera/event_dispatcher.cpp @@ -7,12 +7,16 @@ #include +#include "log.h" + /** * \file event_dispatcher.h */ namespace libcamera { +LOG_DEFINE_CATEGORY(Event) + /** * \class EventDispatcher * \brief Interface to manage the libcamera events and timers diff --git a/src/libcamera/event_dispatcher_poll.cpp b/src/libcamera/event_dispatcher_poll.cpp index 2072ae0aa3da..14e98a788909 100644 --- a/src/libcamera/event_dispatcher_poll.cpp +++ b/src/libcamera/event_dispatcher_poll.cpp @@ -22,6 +22,8 @@ namespace libcamera { +LOG_DECLARE_CATEGORY(Event) + static const char *notifierType(EventNotifier::Type type) { if (type == EventNotifier::Read) @@ -53,8 +55,9 @@ void EventDispatcherPoll::registerEventNotifier(EventNotifier *notifier) EventNotifier::Type type = notifier->type(); if (set.notifiers[type] && set.notifiers[type] != notifier) { - LOG(Warning) << "Ignoring duplicate " << notifierType(type) - << " notifier for fd " << notifier->fd(); + LOGC(Event, Warning) + << "Ignoring duplicate " << notifierType(type) + << " notifier for fd " << notifier->fd(); return; } @@ -74,8 +77,9 @@ void EventDispatcherPoll::unregisterEventNotifier(EventNotifier *notifier) return; if (set.notifiers[type] != notifier) { - LOG(Warning) << notifierType(type) << " notifier for fd " - << notifier->fd() << " is not registered"; + LOGC(Event, Warning) + << notifierType(type) << " notifier for fd " + << notifier->fd() << " is not registered"; return; } @@ -141,9 +145,10 @@ void EventDispatcherPoll::processEvents() timeout.tv_nsec = 0; } - LOG(Debug) << "timeout " << timeout.tv_sec << "." - << std::setfill('0') << std::setw(9) - << timeout.tv_nsec; + LOGC(Event, Debug) + << "timeout " << timeout.tv_sec << "." + << std::setfill('0') << std::setw(9) + << timeout.tv_nsec; } /* Wait for events and process notifiers and timers. */ @@ -151,7 +156,7 @@ void EventDispatcherPoll::processEvents() nextTimer ? &timeout : nullptr, nullptr); if (ret < 0) { ret = -errno; - LOG(Warning) << "poll() failed with " << strerror(-ret); + LOGC(Event, Warning) << "poll() failed with " << strerror(-ret); } else if (ret > 0) { processNotifiers(pollfds); } @@ -201,9 +206,10 @@ void EventDispatcherPoll::processNotifiers(const std::vector &pol * notifier immediately. */ if (pfd.revents & POLLNVAL) { - LOG(Warning) << "Disabling " << notifierType(event.type) - << " due to invalid file descriptor " - << pfd.fd; + LOGC(Event, Warning) + << "Disabling " << notifierType(event.type) + << " due to invalid file descriptor " + << pfd.fd; unregisterEventNotifier(notifier); continue; } diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index 0ee55060aa9b..3f431accfc69 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -27,6 +27,8 @@ namespace libcamera { +LOG_DEFINE_CATEGORY(MediaDevice) + /** * \class MediaDevice * \brief The MediaDevice represents a Media Controller device with its full @@ -139,15 +141,15 @@ bool MediaDevice::acquire() int MediaDevice::open() { if (fd_ != -1) { - LOG(Error) << "MediaDevice already open"; + LOGC(MediaDevice, Error) << "MediaDevice already open"; return -EBUSY; } int ret = ::open(devnode_.c_str(), O_RDWR); if (ret < 0) { ret = -errno; - LOG(Error) << "Failed to open media device at " << devnode_ - << ": " << strerror(-ret); + LOGC(MediaDevice, Error) << "Failed to open media device at " + << devnode_ << ": " << strerror(-ret); return ret; } fd_ = ret; @@ -156,8 +158,8 @@ int MediaDevice::open() ret = ioctl(fd_, MEDIA_IOC_DEVICE_INFO, &info); if (ret) { ret = -errno; - LOG(Error) << "Failed to get media device info " - << ": " << strerror(-ret); + LOGC(MediaDevice, Error) << "Failed to get media device info " + << ": " << strerror(-ret); return ret; } @@ -227,8 +229,9 @@ int MediaDevice::populate() ret = ioctl(fd_, MEDIA_IOC_G_TOPOLOGY, &topology); if (ret < 0) { ret = -errno; - LOG(Error) << "Failed to enumerate topology: " - << strerror(-ret); + LOGC(MediaDevice, Error) + << "Failed to enumerate topology: " + << strerror(-ret); return ret; } @@ -445,8 +448,8 @@ bool MediaDevice::addObject(MediaObject *object) { if (objects_.find(object->id()) != objects_.end()) { - LOG(Error) << "Element with id " << object->id() - << " already enumerated."; + LOGC(MediaDevice, Error) << "Element with id " << object->id() + << " already enumerated."; return false; } @@ -568,8 +571,9 @@ bool MediaDevice::populatePads(const struct media_v2_topology &topology) MediaEntity *mediaEntity = dynamic_cast (object(entity_id)); if (!mediaEntity) { - LOG(Error) << "Failed to find entity with id: " - << entity_id; + LOGC(MediaDevice, Error) + << "Failed to find entity with id: " + << entity_id; return false; } @@ -604,8 +608,9 @@ bool MediaDevice::populateLinks(const struct media_v2_topology &topology) MediaPad *source = dynamic_cast (object(source_id)); if (!source) { - LOG(Error) << "Failed to find pad with id: " - << source_id; + LOGC(MediaDevice, Error) + << "Failed to find pad with id: " + << source_id; return false; } @@ -613,8 +618,9 @@ bool MediaDevice::populateLinks(const struct media_v2_topology &topology) MediaPad *sink = dynamic_cast (object(sink_id)); if (!sink) { - LOG(Error) << "Failed to find pad with id: " - << sink_id; + LOGC(MediaDevice, Error) + << "Failed to find pad with id: " + << sink_id; return false; } @@ -665,14 +671,16 @@ int MediaDevice::setupLink(const MediaLink *link, unsigned int flags) int ret = ioctl(fd_, MEDIA_IOC_SETUP_LINK, &linkDesc); if (ret) { ret = -errno; - LOG(Error) << "Failed to setup link: " << strerror(-ret); + LOGC(MediaDevice, Error) << "Failed to setup link: " + << strerror(-ret); return ret; } - LOG(Debug) << source->entity()->name() << "[" - << source->index() << "] -> " - << sink->entity()->name() << "[" - << sink->index() << "]: " << flags; + LOGC(MediaDevice, Debug) + << source->entity()->name() << "[" + << source->index() << "] -> " + << sink->entity()->name() << "[" + << sink->index() << "]: " << flags; return 0; } diff --git a/src/libcamera/media_object.cpp b/src/libcamera/media_object.cpp index cb3af85e217e..70983ba1f257 100644 --- a/src/libcamera/media_object.cpp +++ b/src/libcamera/media_object.cpp @@ -39,6 +39,8 @@ namespace libcamera { +LOG_DECLARE_CATEGORY(MediaDevice) + /** * \class MediaObject * \brief Base class for all media objects @@ -317,8 +319,9 @@ int MediaEntity::setDeviceNode(const std::string &devnode) int ret = ::access(devnode.c_str(), R_OK | W_OK); if (ret < 0) { ret = -errno; - LOG(Error) << "Device node " << devnode << " can't be accessed: " - << strerror(-ret); + LOGC(MediaDevice, Error) + << "Device node " << devnode << " can't be accessed: " + << strerror(-ret); return ret; } diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index f2e08a6a7315..33e35791161a 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -24,6 +24,8 @@ namespace libcamera { +LOG_DEFINE_CATEGORY(Pipeline) + /** * \class PipelineHandler * \brief Create and manage cameras based on a set of media devices @@ -120,7 +122,8 @@ void PipelineHandlerFactory::registerType(PipelineHandlerFactory *factory) factories.push_back(factory); - LOG(Debug) << "Registered pipeline handler \"" << factory->name() << "\""; + LOGC(Pipeline, Debug) + << "Registered pipeline handler \"" << factory->name() << "\""; } /** diff --git a/src/libcamera/timer.cpp b/src/libcamera/timer.cpp index 306825fde3c0..849eeba6ca24 100644 --- a/src/libcamera/timer.cpp +++ b/src/libcamera/timer.cpp @@ -20,6 +20,8 @@ namespace libcamera { +LOG_DEFINE_CATEGORY(Timer) + /** * \class Timer * \brief Single-shot timer interface @@ -54,8 +56,8 @@ void Timer::start(unsigned int msec) interval_ = msec; deadline_ = tp.tv_sec * 1000000000ULL + tp.tv_nsec + msec * 1000000ULL; - LOG(Debug) << "Starting timer " << this << " with interval " << msec - << ": deadline " << deadline_; + LOGC(Timer, Debug) << "Starting timer " << this << " with interval " + << msec << ": deadline " << deadline_; CameraManager::instance()->eventDispatcher()->registerTimer(this); } diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 54b53de37510..17b73de30995 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -20,6 +20,8 @@ */ namespace libcamera { +LOG_DEFINE_CATEGORY(V4L2) + /** * \struct V4L2Capability * \brief struct v4l2_capability object wrapper and helpers @@ -106,15 +108,16 @@ int V4L2Device::open() int ret; if (isOpen()) { - LOG(Error) << "Device already open"; + LOGC(V4L2, Error) << "Device already open"; return -EBUSY; } ret = ::open(devnode_.c_str(), O_RDWR); if (ret < 0) { ret = -errno; - LOG(Error) << "Failed to open V4L2 device '" << devnode_ - << "': " << strerror(-ret); + LOGC(V4L2, Error) + << "Failed to open V4L2 device '" << devnode_ + << "': " << strerror(-ret); return ret; } fd_ = ret; @@ -122,22 +125,24 @@ int V4L2Device::open() ret = ioctl(fd_, VIDIOC_QUERYCAP, &caps_); if (ret < 0) { ret = -errno; - LOG(Error) << "Failed to query device capabilities: " - << strerror(-ret); + LOGC(V4L2, Error) + << "Failed to query device capabilities: " + << strerror(-ret); return ret; } - LOG(Debug) << "Opened '" << devnode_ << "' " - << caps_.bus_info() << ": " << caps_.driver() - << ": " << caps_.card(); + LOGC(V4L2, Debug) + << "Opened '" << devnode_ << "' " + << caps_.bus_info() << ": " << caps_.driver() + << ": " << caps_.card(); if (!caps_.isCapture() && !caps_.isOutput()) { - LOG(Debug) << "Device is not a supported type"; + LOGC(V4L2, Debug) << "Device is not a supported type"; return -EINVAL; } if (!caps_.hasStreaming()) { - LOG(Error) << "Device does not support streaming I/O"; + LOGC(V4L2, Error) << "Device does not support streaming I/O"; return -EINVAL; }