mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-20 10:55:07 +03:00
cam: Add event loop
Add a simple event loop to the cam application and use it in the main() function, with an example of how to handle SIGINT to gracefully stop the loop. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
parent
67d313240c
commit
71ef5532d9
4 changed files with 95 additions and 1 deletions
39
src/cam/event_loop.cpp
Normal file
39
src/cam/event_loop.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* event_loop.cpp - cam - Event loop
|
||||
*/
|
||||
|
||||
#include <libcamera/event_dispatcher.h>
|
||||
|
||||
#include "event_loop.h"
|
||||
|
||||
using namespace libcamera;
|
||||
|
||||
EventLoop::EventLoop(EventDispatcher *dispatcher)
|
||||
: dispatcher_(dispatcher)
|
||||
{
|
||||
}
|
||||
|
||||
EventLoop::~EventLoop()
|
||||
{
|
||||
}
|
||||
|
||||
int EventLoop::exec()
|
||||
{
|
||||
exitCode_ = -1;
|
||||
exit_.store(false, std::memory_order_release);
|
||||
|
||||
while (!exit_.load(std::memory_order_acquire))
|
||||
dispatcher_->processEvents();
|
||||
|
||||
return exitCode_;
|
||||
}
|
||||
|
||||
void EventLoop::exit(int code)
|
||||
{
|
||||
exitCode_ = code;
|
||||
exit_.store(true, std::memory_order_release);
|
||||
dispatcher_->interrupt();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue