libcamera/test/list-cameras.cpp
Laurent Pinchart 21ff749a79 libcamera: camera: Handle camera objects through shared pointers
The Camera class is explicitly reference-counted to manage the lifetime
of camera objects. Replace this open-coded implementation with usage of
the std::shared_ptr<> class.

This API change prevents pipeline handlers from subclassing the Camera
class. This isn't deemed to be an issue. Mark the class final to make
this explicit.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-01-21 11:13:53 +02:00

50 lines
700 B
C++

/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2018, Google Inc.
*
* list.cpp - camera list tests
*/
#include <iostream>
#include <libcamera/camera.h>
#include <libcamera/camera_manager.h>
#include "test.h"
using namespace std;
using namespace libcamera;
class ListTest : public Test
{
protected:
int init()
{
cm = CameraManager::instance();
cm->start();
return 0;
}
int run()
{
unsigned int count = 0;
for (const std::shared_ptr<Camera> &camera : cm->cameras()) {
cout << "- " << camera->name() << endl;
count++;
}
return count ? 0 : -ENODEV;
}
void cleanup()
{
cm->stop();
}
private:
CameraManager *cm;
};
TEST_REGISTER(ListTest)