UdpLoggingServer.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
22 //----------------------------------------------------------------------
23 #include <QtCore/QByteArray>
24 #include <QtCore/QStringList>
25 #include <QtSql/QSqlError>
26 #include <QtSql/QSqlQuery>
27 
28 #include <iostream>
29 
30 #include "UdpLoggingServer.h"
31 
32 UdpLoggingServer::UdpLoggingServer(const QString& db_filename)
33 {
34  // UDP socket stuff.
35  m_udp_socket = new QUdpSocket(this);
36  m_udp_socket->bind(60000, QUdpSocket::ShareAddress);
37 
38  connect(m_udp_socket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams()));
39 
40  // Database stuff
41  m_db = QSqlDatabase::addDatabase("QSQLITE");
42  m_db.setDatabaseName(db_filename);
43  m_db.open();
44 
45  bool log_entries_exists = false;
46  foreach(QString table, m_db.tables(QSql::AllTables))
47  {
48  if (table == "log_entries")
49  {
50  log_entries_exists = true;
51  }
52  }
53  if (!log_entries_exists)
54  {
55  m_db.exec("CREATE TABLE log_entries ("
56  "system_name TEXT,"
57  "timestamp TEXT, timestamp_ns INTEGER, "
58  "log_level TEXT, log_stream TEXT, "
59  "file TEXT, line INTEGER, "
60  "class TEXT, object TEXT, function TEXT, "
61  "message TEXT)");
62  }
63 }
64 
66 {
67 }
68 
70 {
71  while (m_udp_socket->hasPendingDatagrams())
72  {
73  QByteArray datagram;
74  datagram.resize(m_udp_socket->pendingDatagramSize());
75  m_udp_socket->readDatagram(datagram.data(), datagram.size());
76 
77  QString sql = "INSERT INTO log_entries VALUES (";
78  sql.append(datagram.data());
79  sql.append(")");
80  m_db.exec(sql);
81  }
82 }
QSqlDatabase m_db
virtual ~UdpLoggingServer()
QUdpSocket * m_udp_socket
UdpLoggingServer(const QString &db_filename)


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58