test: Get event dispatcher from current thread

For all tests that don't otherwise require access to the camera manager,
get the event dispatcher from the current thread instead of the camera
manager. This prepares for the removal of CameraManager::instance().

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
Laurent Pinchart 2019-08-18 03:11:27 +03:00
parent 8c9deeb30f
commit fd0087b5d8
11 changed files with 24 additions and 25 deletions

View file

@ -9,11 +9,11 @@
#include <signal.h> #include <signal.h>
#include <sys/time.h> #include <sys/time.h>
#include <libcamera/camera_manager.h>
#include <libcamera/event_dispatcher.h> #include <libcamera/event_dispatcher.h>
#include <libcamera/timer.h> #include <libcamera/timer.h>
#include "test.h" #include "test.h"
#include "thread.h"
using namespace std; using namespace std;
using namespace libcamera; using namespace libcamera;
@ -33,7 +33,7 @@ protected:
int init() int init()
{ {
dispatcher = CameraManager::instance()->eventDispatcher(); dispatcher = Thread::current()->eventDispatcher();
struct sigaction sa = {}; struct sigaction sa = {};
sa.sa_handler = &sigAlarmHandler; sa.sa_handler = &sigAlarmHandler;

View file

@ -9,12 +9,12 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <libcamera/camera_manager.h>
#include <libcamera/event_dispatcher.h> #include <libcamera/event_dispatcher.h>
#include <libcamera/event_notifier.h> #include <libcamera/event_notifier.h>
#include <libcamera/timer.h> #include <libcamera/timer.h>
#include "test.h" #include "test.h"
#include "thread.h"
using namespace std; using namespace std;
using namespace libcamera; using namespace libcamera;
@ -35,7 +35,7 @@ protected:
int run() int run()
{ {
EventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher(); EventDispatcher *dispatcher = Thread::current()->eventDispatcher();
std::string data("H2G2"); std::string data("H2G2");
Timer timeout; Timer timeout;
ssize_t ret; ssize_t ret;

View file

@ -15,12 +15,12 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
#include <libcamera/camera_manager.h>
#include <libcamera/event_dispatcher.h> #include <libcamera/event_dispatcher.h>
#include <libcamera/timer.h> #include <libcamera/timer.h>
#include "ipc_unixsocket.h" #include "ipc_unixsocket.h"
#include "test.h" #include "test.h"
#include "thread.h"
#include "utils.h" #include "utils.h"
#define CMD_CLOSE 0 #define CMD_CLOSE 0
@ -47,7 +47,7 @@ public:
UnixSocketTestSlave() UnixSocketTestSlave()
: exitCode_(EXIT_FAILURE), exit_(false) : exitCode_(EXIT_FAILURE), exit_(false)
{ {
dispatcher_ = CameraManager::instance()->eventDispatcher(); dispatcher_ = Thread::current()->eventDispatcher();
ipc_.readyRead.connect(this, &UnixSocketTestSlave::readyRead); ipc_.readyRead.connect(this, &UnixSocketTestSlave::readyRead);
} }
@ -436,7 +436,7 @@ private:
return -ETIMEDOUT; return -ETIMEDOUT;
} }
CameraManager::instance()->eventDispatcher()->processEvents(); Thread::current()->eventDispatcher()->processEvents();
} }
callResponse_ = nullptr; callResponse_ = nullptr;

View file

@ -14,7 +14,6 @@
#include <unistd.h> #include <unistd.h>
#include <vector> #include <vector>
#include <libcamera/camera_manager.h>
#include <libcamera/event_dispatcher.h> #include <libcamera/event_dispatcher.h>
#include <libcamera/logging.h> #include <libcamera/logging.h>
#include <libcamera/timer.h> #include <libcamera/timer.h>
@ -22,6 +21,7 @@
#include "log.h" #include "log.h"
#include "process.h" #include "process.h"
#include "test.h" #include "test.h"
#include "thread.h"
#include "utils.h" #include "utils.h"
using namespace std; using namespace std;
@ -65,7 +65,7 @@ protected:
int run() int run()
{ {
EventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher(); EventDispatcher *dispatcher = Thread::current()->eventDispatcher();
Timer timeout; Timer timeout;
int exitCode = 42; int exitCode = 42;

View file

@ -13,22 +13,22 @@ subdir('v4l2_subdevice')
subdir('v4l2_videodevice') subdir('v4l2_videodevice')
public_tests = [ public_tests = [
['event', 'event.cpp'],
['event-dispatcher', 'event-dispatcher.cpp'],
['geometry', 'geometry.cpp'], ['geometry', 'geometry.cpp'],
['list-cameras', 'list-cameras.cpp'], ['list-cameras', 'list-cameras.cpp'],
['signal', 'signal.cpp'], ['signal', 'signal.cpp'],
['timer', 'timer.cpp'],
] ]
internal_tests = [ internal_tests = [
['camera-sensor', 'camera-sensor.cpp'], ['camera-sensor', 'camera-sensor.cpp'],
['event', 'event.cpp'],
['event-dispatcher', 'event-dispatcher.cpp'],
['event-thread', 'event-thread.cpp'], ['event-thread', 'event-thread.cpp'],
['message', 'message.cpp'], ['message', 'message.cpp'],
['object', 'object.cpp'], ['object', 'object.cpp'],
['object-invoke', 'object-invoke.cpp'], ['object-invoke', 'object-invoke.cpp'],
['signal-threads', 'signal-threads.cpp'], ['signal-threads', 'signal-threads.cpp'],
['threads', 'threads.cpp'], ['threads', 'threads.cpp'],
['timer', 'timer.cpp'],
['timer-thread', 'timer-thread.cpp'], ['timer-thread', 'timer-thread.cpp'],
] ]

View file

@ -9,12 +9,11 @@
#include <iostream> #include <iostream>
#include <thread> #include <thread>
#include <libcamera/camera_manager.h>
#include <libcamera/event_dispatcher.h> #include <libcamera/event_dispatcher.h>
#include <libcamera/object.h> #include <libcamera/object.h>
#include "thread.h"
#include "test.h" #include "test.h"
#include "thread.h"
using namespace std; using namespace std;
using namespace libcamera; using namespace libcamera;
@ -61,7 +60,7 @@ class ObjectInvokeTest : public Test
protected: protected:
int run() int run()
{ {
EventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher(); EventDispatcher *dispatcher = Thread::current()->eventDispatcher();
InvokedObject object; InvokedObject object;
/* /*

View file

@ -9,12 +9,12 @@
#include <unistd.h> #include <unistd.h>
#include <vector> #include <vector>
#include <libcamera/camera_manager.h>
#include <libcamera/event_dispatcher.h> #include <libcamera/event_dispatcher.h>
#include <libcamera/timer.h> #include <libcamera/timer.h>
#include "process.h" #include "process.h"
#include "test.h" #include "test.h"
#include "thread.h"
#include "utils.h" #include "utils.h"
using namespace std; using namespace std;
@ -41,7 +41,7 @@ public:
protected: protected:
int run() int run()
{ {
EventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher(); EventDispatcher *dispatcher = Thread::current()->eventDispatcher();
Timer timeout; Timer timeout;
int exitCode = 42; int exitCode = 42;

View file

@ -7,11 +7,11 @@
#include <iostream> #include <iostream>
#include <libcamera/camera_manager.h>
#include <libcamera/event_dispatcher.h> #include <libcamera/event_dispatcher.h>
#include <libcamera/timer.h> #include <libcamera/timer.h>
#include "test.h" #include "test.h"
#include "thread.h"
using namespace std; using namespace std;
using namespace libcamera; using namespace libcamera;
@ -62,7 +62,7 @@ protected:
int run() int run()
{ {
EventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher(); EventDispatcher *dispatcher = Thread::current()->eventDispatcher();
ManagedTimer timer; ManagedTimer timer;
ManagedTimer timer2; ManagedTimer timer2;

View file

@ -13,10 +13,10 @@
#include <iostream> #include <iostream>
#include <libcamera/buffer.h> #include <libcamera/buffer.h>
#include <libcamera/camera_manager.h>
#include <libcamera/event_dispatcher.h> #include <libcamera/event_dispatcher.h>
#include <libcamera/timer.h> #include <libcamera/timer.h>
#include "thread.h"
#include "v4l2_videodevice_test.h" #include "v4l2_videodevice_test.h"
class BufferSharingTest : public V4L2VideoDeviceTest class BufferSharingTest : public V4L2VideoDeviceTest
@ -116,7 +116,7 @@ protected:
int run() int run()
{ {
EventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher(); EventDispatcher *dispatcher = Thread::current()->eventDispatcher();
Timer timeout; Timer timeout;
int ret; int ret;

View file

@ -6,12 +6,12 @@
*/ */
#include <libcamera/buffer.h> #include <libcamera/buffer.h>
#include <libcamera/camera_manager.h>
#include <libcamera/event_dispatcher.h> #include <libcamera/event_dispatcher.h>
#include <libcamera/timer.h> #include <libcamera/timer.h>
#include <iostream> #include <iostream>
#include "thread.h"
#include "v4l2_videodevice_test.h" #include "v4l2_videodevice_test.h"
class CaptureAsyncTest : public V4L2VideoDeviceTest class CaptureAsyncTest : public V4L2VideoDeviceTest
@ -34,7 +34,7 @@ protected:
{ {
const unsigned int bufferCount = 8; const unsigned int bufferCount = 8;
EventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher(); EventDispatcher *dispatcher = Thread::current()->eventDispatcher();
Timer timeout; Timer timeout;
int ret; int ret;

View file

@ -8,12 +8,12 @@
#include <iostream> #include <iostream>
#include <libcamera/buffer.h> #include <libcamera/buffer.h>
#include <libcamera/camera_manager.h>
#include <libcamera/event_dispatcher.h> #include <libcamera/event_dispatcher.h>
#include <libcamera/timer.h> #include <libcamera/timer.h>
#include "device_enumerator.h" #include "device_enumerator.h"
#include "media_device.h" #include "media_device.h"
#include "thread.h"
#include "v4l2_videodevice.h" #include "v4l2_videodevice.h"
#include "test.h" #include "test.h"
@ -80,7 +80,7 @@ protected:
{ {
constexpr unsigned int bufferCount = 4; constexpr unsigned int bufferCount = 4;
EventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher(); EventDispatcher *dispatcher = Thread::current()->eventDispatcher();
int ret; int ret;
MediaEntity *entity = media_->getEntityByName("vim2m-source"); MediaEntity *entity = media_->getEntityByName("vim2m-source");