summaryrefslogtreecommitdiff
path: root/src/qcam/assets/feathericons/list.svg
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-09-27 00:07:33 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-09-27 23:41:18 +0300
commit348df7bc4b5d5281e50c42b5c44b125d7049eb57 (patch)
treed8e3f80a7a6ea356bdf109d4c3bd0f55479bfcaa /src/qcam/assets/feathericons/list.svg
parent1ec7072827931ac8a5ec7cf46292ff9510d10249 (diff)
Documentation: application-developer: Use correct type to store size
The return type of std::vector::size() is size_t. Use the same type, instead of unsigned int, to store its return value when retrieving the number of allocated buffers. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src/qcam/assets/feathericons/list.svg')
0 files changed, 0 insertions, 0 deletions
22'>122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copyright (C) 2020, Google Inc.
 *
 * unixsocket_ipc.cpp - Unix socket IPC test
 */

#include <algorithm>
#include <fcntl.h>
#include <iostream>
#include <limits.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

#include <libcamera/base/event_dispatcher.h>
#include <libcamera/base/thread.h>
#include <libcamera/base/timer.h>
#include <libcamera/base/utils.h>

#include "libcamera/internal/ipa_data_serializer.h"
#include "libcamera/internal/ipc_pipe.h"
#include "libcamera/internal/ipc_pipe_unixsocket.h"
#include "libcamera/internal/process.h"

#include "test.h"

using namespace std;
using namespace libcamera;

enum {
	CmdExit = 0,
	CmdGetSync = 1,
	CmdSetAsync = 2,
};

const int32_t kInitialValue = 1337;
const int32_t kChangedValue = 9001;

class UnixSocketTestIPCSlave
{
public:
	UnixSocketTestIPCSlave()
		: value_(kInitialValue), exitCode_(EXIT_FAILURE), exit_(false)
	{
		dispatcher_ = Thread::current()->eventDispatcher();
		ipc_.readyRead.connect(this, &UnixSocketTestIPCSlave::readyRead);
	}

	int run(UniqueFD fd)
	{
		if (ipc_.bind(std::move(fd))) {
			cerr << "Failed to connect to IPC channel" << endl;
			return EXIT_FAILURE;
		}

		while (!exit_)
			dispatcher_->processEvents();

		ipc_.close();

		return exitCode_;
	}

private:
	void readyRead()
	{
		IPCUnixSocket::Payload message;
		int ret;

		ret = ipc_.receive(&message);
		if (ret) {
			cerr << "Receive message failed: " << ret << endl;
			return;
		}

		IPCMessage ipcMessage(message);
		uint32_t cmd = ipcMessage.header().cmd;

		switch (cmd) {
		case CmdExit: {
			exit_ = true;
			break;
		}

		case CmdGetSync: {
			IPCMessage::Header header = { cmd, ipcMessage.header().cookie };
			IPCMessage response(header);

			vector<uint8_t> buf;
			tie(buf, ignore) = IPADataSerializer<int32_t>::serialize(value_);
			response.data().insert(response.data().end(), buf.begin(), buf.end());

			ret = ipc_.send(response.payload());
			if (ret < 0) {
				cerr << "Reply failed" << endl;
				stop(ret);
			}
			break;
		}

		case CmdSetAsync: {
			value_ = IPADataSerializer<int32_t>::deserialize(ipcMessage.data());
			break;
		}
		}
	}

	void stop(int code)
	{
		exitCode_ = code;
		exit_ = true;
	}

	int32_t value_;

	IPCUnixSocket ipc_;
	EventDispatcher *dispatcher_;
	int exitCode_;
	bool exit_;
};

class UnixSocketTestIPC : public Test
{
protected:
	int init()
	{
		return 0;
	}