C

Telltales: Rendering Safety-Critical UI

/****************************************************************************** ** ** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Safe Renderer. ** ** $QT_BEGIN_LICENSE:COMM$ ** ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** $QT_END_LICENSE$ ** ******************************************************************************/
#include <mqueue.h> #include <time.h> #include <stdio.h> #include <unistd.h> #include <errno.h> #include <stdlib.h> #include <QtSafeRenderer/qsafeevent.h> #include <QtSafeRenderer/qsafeglobal.h> #define MQ_FAILED (static_cast<mqd_t>(-1)) #define ATTACH_POINT "/saferenderer" using namespace SafeRenderer; typedef struct _message_data { SafeRenderer::QSafeEvent event; } message_data; class MessageSender { public: MessageSender() : m_qdes(MQ_FAILED) {} ~MessageSender() { disconnect(); } bool connect() { bool returnValue = true; m_qdes = mq_open(ATTACH_POINT, O_WRONLY); if (m_qdes == MQ_FAILED) { returnValue = false; } return returnValue; } void disconnect() const { mq_close(m_qdes); } void sendMessage(const SafeRenderer::QSafeEvent& event) const { message_data msg; msg.event = event; if ((m_qdes == MQ_FAILED) || (mq_send(m_qdes, (const char *)&msg, sizeof(msg), 0) == -1)) { perror("Failed to send message"); } } private: mqd_t m_qdes; };