libcamera: Don't use emitter object pointer argument to slot

In many cases, the emitter object passed as a pointer from signals to
slots is also available as a class member. Use the class member when
this occurs, to prepare for removal of the emitter object pointer from
signals.

In test/event.cpp, this additionally requires moving the EventNotifier
to a class member.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
This commit is contained in:
Laurent Pinchart 2021-08-27 04:41:05 +03:00
parent 58720e1dc9
commit 3f662ae3c0
7 changed files with 25 additions and 20 deletions

View file

@ -82,10 +82,10 @@ int IPCPipeUnixSocket::sendAsync(const IPCMessage &data)
return 0; return 0;
} }
void IPCPipeUnixSocket::readyRead(IPCUnixSocket *socket) void IPCPipeUnixSocket::readyRead([[maybe_unused]] IPCUnixSocket *socket)
{ {
IPCUnixSocket::Payload payload; IPCUnixSocket::Payload payload;
int ret = socket->receive(&payload); int ret = socket_->receive(&payload);
if (ret) { if (ret) {
LOG(IPCPipe, Error) << "Receive message failed" << ret; LOG(IPCPipe, Error) << "Receive message failed" << ret;
return; return;

View file

@ -66,9 +66,9 @@ public:
} }
private: private:
void readReady(EventNotifier *notifier) void readReady([[maybe_unused]] EventNotifier *notifier)
{ {
size_ = read(notifier->fd(), data_, sizeof(data_)); size_ = read(notifier_->fd(), data_, sizeof(data_));
notified_ = true; notified_ = true;
} }

View file

@ -22,14 +22,16 @@ using namespace libcamera;
class EventTest : public Test class EventTest : public Test
{ {
protected: protected:
void readReady(EventNotifier *notifier) void readReady([[maybe_unused]] EventNotifier *notifier)
{ {
size_ = read(notifier->fd(), data_, sizeof(data_)); size_ = read(notifier_->fd(), data_, sizeof(data_));
notified_ = true; notified_ = true;
} }
int init() int init()
{ {
notifier_ = nullptr;
return pipe(pipefd_); return pipe(pipefd_);
} }
@ -40,8 +42,8 @@ protected:
Timer timeout; Timer timeout;
ssize_t ret; ssize_t ret;
EventNotifier readNotifier(pipefd_[0], EventNotifier::Read); notifier_ = new EventNotifier(pipefd_[0], EventNotifier::Read);
readNotifier.activated.connect(this, &EventTest::readReady); notifier_->activated.connect(this, &EventTest::readReady);
/* Test read notification with data. */ /* Test read notification with data. */
memset(data_, 0, sizeof(data_)); memset(data_, 0, sizeof(data_));
@ -76,7 +78,7 @@ protected:
/* Test read notifier disabling. */ /* Test read notifier disabling. */
notified_ = false; notified_ = false;
readNotifier.setEnabled(false); notifier_->setEnabled(false);
ret = write(pipefd_[1], data.data(), data.size()); ret = write(pipefd_[1], data.data(), data.size());
if (ret < 0) { if (ret < 0) {
@ -95,7 +97,7 @@ protected:
/* Test read notifier enabling. */ /* Test read notifier enabling. */
notified_ = false; notified_ = false;
readNotifier.setEnabled(true); notifier_->setEnabled(true);
timeout.start(100); timeout.start(100);
dispatcher->processEvents(); dispatcher->processEvents();
@ -111,6 +113,8 @@ protected:
void cleanup() void cleanup()
{ {
delete notifier_;
close(pipefd_[0]); close(pipefd_[0]);
close(pipefd_[1]); close(pipefd_[1]);
} }
@ -118,6 +122,7 @@ protected:
private: private:
int pipefd_[2]; int pipefd_[2];
EventNotifier *notifier_;
bool notified_; bool notified_;
char data_[16]; char data_[16];
ssize_t size_; ssize_t size_;

View file

@ -153,9 +153,9 @@ protected:
} }
private: private:
void readTrace(EventNotifier *notifier) void readTrace([[maybe_unused]] EventNotifier *notifier)
{ {
ssize_t s = read(notifier->fd(), &trace_, sizeof(trace_)); ssize_t s = read(notifier_->fd(), &trace_, sizeof(trace_));
if (s < 0) { if (s < 0) {
int ret = errno; int ret = errno;
cerr << "Failed to read from IPA test FIFO at '" cerr << "Failed to read from IPA test FIFO at '"

View file

@ -68,12 +68,12 @@ public:
} }
private: private:
void readyRead(IPCUnixSocket *ipc) void readyRead([[maybe_unused]] IPCUnixSocket *ipc)
{ {
IPCUnixSocket::Payload message, response; IPCUnixSocket::Payload message, response;
int ret; int ret;
ret = ipc->receive(&message); ret = ipc_.receive(&message);
if (ret) { if (ret) {
cerr << "Receive message failed: " << ret << endl; cerr << "Receive message failed: " << ret << endl;
return; return;
@ -447,14 +447,14 @@ private:
return 0; return 0;
} }
void readyRead(IPCUnixSocket *ipc) void readyRead([[maybe_unused]] IPCUnixSocket *ipc)
{ {
if (!callResponse_) { if (!callResponse_) {
cerr << "Read ready without expecting data, fail." << endl; cerr << "Read ready without expecting data, fail." << endl;
return; return;
} }
if (ipc->receive(callResponse_)) { if (ipc_.receive(callResponse_)) {
cerr << "Receive message failed" << endl; cerr << "Receive message failed" << endl;
return; return;
} }

View file

@ -65,12 +65,12 @@ public:
} }
private: private:
void readyRead(IPCUnixSocket *ipc) void readyRead([[maybe_unused]] IPCUnixSocket *ipc)
{ {
IPCUnixSocket::Payload message; IPCUnixSocket::Payload message;
int ret; int ret;
ret = ipc->receive(&message); ret = ipc_.receive(&message);
if (ret) { if (ret) {
cerr << "Receive message failed: " << ret << endl; cerr << "Receive message failed: " << ret << endl;
return; return;

View file

@ -57,10 +57,10 @@ public:
~{{proxy_worker_name}}() {} ~{{proxy_worker_name}}() {}
void readyRead(IPCUnixSocket *socket) void readyRead([[maybe_unused]] IPCUnixSocket *socket)
{ {
IPCUnixSocket::Payload _message; IPCUnixSocket::Payload _message;
int _retRecv = socket->receive(&_message); int _retRecv = socket_.receive(&_message);
if (_retRecv) { if (_retRecv) {
LOG({{proxy_worker_name}}, Error) LOG({{proxy_worker_name}}, Error)
<< "Receive message failed: " << _retRecv; << "Receive message failed: " << _retRecv;