blob: a10761e52b3296922ea8ef7c2a9547acac8e2f83 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* ipa_proxy_linux_worker.cpp - Default Image Processing Algorithm proxy worker for Linux
*/
#include <iostream>
#include <sys/types.h>
#include <unistd.h>
#include <ipa/ipa_interface.h>
#include <libcamera/event_dispatcher.h>
#include <libcamera/logging.h>
#include "ipa_module.h"
#include "ipc_unixsocket.h"
#include "log.h"
#include "thread.h"
#include "utils.h"
using namespace libcamera;
LOG_DEFINE_CATEGORY(IPAProxyLinuxWorker)
void readyRead(IPCUnixSocket *ipc)
{
IPCUnixSocket::Payload message;
int ret;
ret = ipc->receive(&message);
if (ret) {
LOG(IPAProxyLinuxWorker, Error)
<< "Receive message failed: " << ret;
return;
}
LOG(IPAProxyLinuxWorker, Debug) << "Received a message!";
}
int main(int argc, char **argv)
{
/* Uncomment this for debugging. */
#if 0
std::string logPath = "/tmp/libcamera.worker." +
std::to_string(getpid()) + ".log";
logSetFile(logPath.c_str());
#endif
if (argc < 3) {
LOG(IPAProxyLinuxWorker, Debug)
<< "Tried to start worker with no args";
return EXIT_FAILURE;
}
int fd = std::stoi(argv[2]);
LOG(IPAProxyLinuxWorker, Debug)
<< "Starting worker for IPA module " << argv[1]
<< " with IPC fd = " << fd;
std::unique_ptr<IPAModule> ipam = utils::make_unique<IPAModule>(argv[1]);
if (!ipam->isValid() || !ipam->load()) {
LOG(IPAProxyLinuxWorker, Error)
<< "IPAModule " << argv[1] << " should be valid but isn't";
return EXIT_FAILURE;
}
IPCUnixSocket socket;
if (socket.bind(fd) < 0) {
LOG(IPAProxyLinuxWorker, Error) << "IPC socket binding failed";
return EXIT_FAILURE;
}
socket.readyRead.connect(&readyRead);
std::unique_ptr<IPAInterface> ipa = ipam->createInstance();
if (!ipa) {
LOG(IPAProxyLinuxWorker, Error) << "Failed to create IPA interface";
return EXIT_FAILURE;
}
LOG(IPAProxyLinuxWorker, Debug) << "Proxy worker successfully started";
/* \todo upgrade listening loop */
EventDispatcher *dispatcher = Thread::current()->eventDispatcher();
while (1)
dispatcher->processEvents();
return 0;
}
|