UdpLoggingServer.cpp
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00022 //----------------------------------------------------------------------
00023 #include <QtCore/QByteArray>
00024 #include <QtCore/QStringList>
00025 #include <QtSql/QSqlError>
00026 #include <QtSql/QSqlQuery>
00027 
00028 #include <iostream>
00029 
00030 #include "UdpLoggingServer.h"
00031 
00032 UdpLoggingServer::UdpLoggingServer(const QString& db_filename)
00033 {
00034   // UDP socket stuff.
00035   m_udp_socket = new QUdpSocket(this);
00036   m_udp_socket->bind(60000, QUdpSocket::ShareAddress);
00037 
00038   connect(m_udp_socket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams()));
00039 
00040   // Database stuff
00041   m_db = QSqlDatabase::addDatabase("QSQLITE");
00042   m_db.setDatabaseName(db_filename);
00043   m_db.open();
00044 
00045   bool log_entries_exists = false;
00046   foreach(QString table, m_db.tables(QSql::AllTables))
00047   {
00048     if (table == "log_entries")
00049     {
00050       log_entries_exists = true;
00051     }
00052   }
00053   if (!log_entries_exists)
00054   {
00055     m_db.exec("CREATE TABLE log_entries ("
00056               "system_name TEXT,"
00057               "timestamp TEXT, timestamp_ns INTEGER, "
00058               "log_level TEXT, log_stream TEXT, "
00059               "file TEXT, line INTEGER, "
00060               "class TEXT, object TEXT, function TEXT, "
00061               "message TEXT)");
00062   }
00063 }
00064 
00065 UdpLoggingServer::~UdpLoggingServer()
00066 {
00067 }
00068 
00069 void UdpLoggingServer::processPendingDatagrams()
00070 {
00071   while (m_udp_socket->hasPendingDatagrams())
00072   {
00073     QByteArray datagram;
00074     datagram.resize(m_udp_socket->pendingDatagramSize());
00075     m_udp_socket->readDatagram(datagram.data(), datagram.size());
00076 
00077     QString sql = "INSERT INTO log_entries VALUES (";
00078     sql.append(datagram.data());
00079     sql.append(")");
00080     m_db.exec(sql);
00081   }
00082 }


fzi_icl_core
Author(s):
autogenerated on Thu Jun 6 2019 20:22:24