/******************************************************************************
**
** Copyright (C) 2020 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 http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** $QT_END_LICENSE$
**
******************************************************************************/
#include <unistd.h>#include <stdlib.h>#include <time.h>#include <stdio.h>#include <sys/dispatch.h>#include <QtSafeRenderer/qsafechecksum.h>#include <QtSafeRenderer/qsafestring.h>#include <QtSafeRenderer/qsafeevent.h>#include <QtSafeRenderer/qsafeglobal.h>#include "../events.h"#define ATTACH_POINT "saferenderer"usingnamespace SafeRenderer;
typedefstruct _pulse msg_header_t;
typedefstruct _message_data {
msg_header_t hdr;
SafeRenderer::QSafeEvent event;
} message_data;
qint32 g_server_coid;
void sendMessage(const SafeRenderer::QSafeEvent& event)
{
message_data msg;
msg.hdr.type =0x0;
msg.hdr.subtype =0x0;
msg.event = event;
if (MsgSend(g_server_coid,&msg,sizeof(msg), NULL,0) ==-1) {
printf("Failed to send message.\n");
}
}
int main()
{
const SystemEventId events[]= {
EventEngineTemperature,
EventFuelLow,
EventParkingBrake,
EventTireCondition,
EventPropulsionBatteryFailed,
EventSeatBeltDriver,
EventLightError,
EventParkLight,
EventHeadLightLowBeam
};
//Items are the Safe Items id's in QML file//See the DashBoardForm.ui.qml in qtcluster projectconst qchar *const items[]= {
"iconCoolant","iconFuel","iconParkingBrake","iconTyre","iconBattery","iconSeatbelt","iconLamp","iconLights","iconLowBeam"
};
constquint32 eventCount =sizeof(events) /sizeof(events[0]);
while ((g_server_coid = name_open(ATTACH_POINT,0)) <0) {
// Wait until we have a connection
sleep(1);
}
for (quint32 i=0U;i<eventCount;i++) {
QSafeEventConnection connection;
connection.setSystemEventId(events[i]);
connection.setItemId(qsafe_hash(items[i], safe_strlen(items[i])));
sendMessage(connection);
}
srand (time(NULL));
QSafeEventSystem e;
e.setSystemEventId(EventTireCondition);
e.setValue(1U);
sendMessage(e);
e.setSystemEventId(EventLightError);
e.setValue(1U);
sendMessage(e);
while (true) {
constquint32 index =static_cast<quint32>(rand()) % eventCount;
SystemEventId eventid = events[index];
if ((eventid == EventTireCondition) ||
(eventid == EventLightError))
continue;
e.setSystemEventId(eventid);
e.setValue(1U);
sendMessage(e);
sleep(2U);
e.setSystemEventId(eventid);
e.setValue(0U);
sendMessage(e);
sleep(1U);
}
}