Skip to content

Commit

Permalink
- Vereinfachung der Meldungen.
Browse files Browse the repository at this point in the history
- Module können Meldungen absetzen.
  • Loading branch information
frank committed Aug 28, 2015
1 parent 6b9d238 commit 4c16f0c
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 57 deletions.
3 changes: 3 additions & 0 deletions Plug-Ins/Dummy/Quellen/Dummy.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include <QtCore>

#include "../../gpsd-tcp/Quellen/Meldung.h"

class Dummy : public QObject
{
Q_OBJECT
Expand All @@ -28,6 +30,7 @@ class Dummy : public QObject

Q_SIGNALS:
void Daten(const QString &daten);
void MeldungSenden(Meldung meldung);

private Q_SLOTS:
void DatenSenden();
Expand Down
3 changes: 2 additions & 1 deletion Plug-Ins/EM7345/EM7345.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ RCC_DIR = tmp/rcc

HEADERS += \
Quellen/Erweiterung_EM7345.h \
Quellen/EM7345.h
Quellen/EM7345.h \
Quellen/Vorgaben.h

SOURCES += \
Quellen/EM7345.cpp
Expand Down
10 changes: 9 additions & 1 deletion Plug-Ins/EM7345/Quellen/EM7345.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@
*/

#include "EM7345.h"
#include "Vorgaben.h"

#include <syslog.h>

EM7345::EM7345(QObject *eltern, const QSettings *konfiguration) : QObject(eltern)
{
K_Konfiguration=konfiguration;
K_Anschluss=K_Konfiguration->value("EM7345/Anschluss",ANSCHLUSS).toString();
QTimer::singleShot(0,this,SLOT(starten()));
}
void EM7345::starten()
{
Q_EMIT MeldungSenden(Meldung("a42c182ded374fcb86fd8bd605d9cfa6",tr("%1 benutze Anschluss %2").arg(NAME).arg(K_Anschluss),LOG_INFO));
}

10 changes: 8 additions & 2 deletions Plug-Ins/EM7345/Quellen/EM7345.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define EM7345_H

#include <QtCore>
#include "../../gpsd-tcp/Quellen/Meldung.h"

class EM7345 : public QObject
{
Expand All @@ -27,10 +28,15 @@ class EM7345 : public QObject
explicit EM7345(QObject *eltern, const QSettings *konfiguration);

Q_SIGNALS:
void Daten(const QString &daten);
void Daten(const QString &daten);
void MeldungSenden(Meldung meldung);

private Q_SLOTS:
void starten();

private:
const QSettings *K_Konfiguration;
const QSettings *K_Konfiguration;
QString K_Anschluss;

};

Expand Down
5 changes: 3 additions & 2 deletions Plug-Ins/EM7345/Quellen/Erweiterung_EM7345.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
#include "../../gpsd-tcp/Quellen/Pluginfabrik.h"

#include "EM7345.h"
#include "Vorgaben.h"

class Erweiterung_EM7345 : public Plugin
{
public:
virtual const QString Version() const Q_DECL_OVERRIDE {return "0.0.1";}
virtual const QString Name()const Q_DECL_OVERRIDE {return "EM7345";}
virtual const QString Version() const Q_DECL_OVERRIDE {return VERSION;}
virtual const QString Name()const Q_DECL_OVERRIDE {return NAME;}
virtual QObject *Erweiterung(QObject *eltern,const QSettings *konfiguration) Q_DECL_OVERRIDE {if (!K_EM7345) K_EM7345=new EM7345(eltern,konfiguration); return K_EM7345;}
private:
EM7345 *K_EM7345;
Expand Down
9 changes: 9 additions & 0 deletions Plug-Ins/EM7345/Quellen/Vorgaben.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef VORGABEN
#define VORGABEN

#define ANSCHLUSS "/dev/ttyACM0"
#define NAME "EM7345"
#define VERSION "0.0.1"

#endif // VORGABEN

76 changes: 26 additions & 50 deletions gpsd-tcp/Quellen/Steuerung.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@ void Steuerung::beenden()
Melden(Meldung("3c9ac521e2e6487995ac623d35b06d70",tr("Beende ...")));
}

void Steuerung::Melden(Meldung m) const
void Steuerung::Melden(Meldung meldung) const
{
sd_journal_send(QString("MESSAGE=%1").arg(m.TextHolen().simplified()).toUtf8().constData(),QString("MESSAGE_ID=%1").arg(m.IDHolen()).toUtf8().constData(),
QString("PRIORITY=%1").arg(m.PrioritaetHolen()).toUtf8().constData(),QString("VERSION=%1").arg(VERSION).toUtf8().constData(),NULL);
if(meldung.PrioritaetHolen()>=K_Protokoll)
sd_journal_send(QString("MESSAGE=%1").arg(meldung.TextHolen().simplified()).toUtf8().constData(),QString("MESSAGE_ID=%1").arg(meldung.IDHolen()).toUtf8().constData(),
QString("PRIORITY=%1").arg(meldung.PrioritaetHolen()).toUtf8().constData(),QString("VERSION=%1").arg(VERSION).toUtf8().constData(),NULL);
if(meldung.PrioritaetHolen()==LOG_CRIT)
QCoreApplication::quit();
}
Protokolltiefe Steuerung::ProtokollTextNachZahl(const QString &text) const
{
Expand All @@ -88,30 +91,26 @@ Protokolltiefe Steuerung::ProtokollTextNachZahl(const QString &text) const
void Steuerung::NeuerKlient(QObject *dienst)
{
QTcpSocket* Klient =dynamic_cast<QTcpServer*> (dienst)->nextPendingConnection();
if (K_Protokoll >= Protokolltiefe::Info)
Melden(Meldung("a32a5261338d422d8e27dc832e1c6e90",tr("Verbindung von %1.").arg(Klient->peerAddress().toString()),LOG_INFO));
Melden(Meldung("a32a5261338d422d8e27dc832e1c6e90",tr("Verbindung von %1.").arg(Klient->peerAddress().toString()),LOG_INFO));
K_Klienten->append(Klient);
connect(Klient, SIGNAL(disconnected()), K_Klientloescher, SLOT(map()));
K_Klientloescher->setMapping(Klient,Klient);
}
void Steuerung::DatenVerteilen(const QString &daten)
{
if (K_Protokoll==Protokolltiefe::Debug)
Melden(Meldung("1bf20681b80a42c191b906560bb6647a",tr("Daten empfangen vom Modul: %1").arg(daten),LOG_DEBUG));
Melden(Meldung("1bf20681b80a42c191b906560bb6647a",tr("Daten empfangen vom Modul: %1").arg(daten),LOG_DEBUG));
for( auto Klient : *K_Klienten)
{
if(Klient->state()==QAbstractSocket::ConnectedState)
{
if (K_Protokoll==Protokolltiefe::Debug)
Melden(Meldung("6733089a635b45f7ae0d27c3ecaf518b",tr("Sende an Klient %1").arg(Klient->peerAddress().toString()),LOG_DEBUG));
Melden(Meldung("6733089a635b45f7ae0d27c3ecaf518b",tr("Sende an Klient %1").arg(Klient->peerAddress().toString()),LOG_DEBUG));
Klient->write(daten.toLatin1());
}
}
}
void Steuerung::KlientLoeschen(QObject *klient)
{
if (K_Protokoll >= Protokolltiefe::Info)
Melden(Meldung("fcea41ff29354995b415d9dce03fcdf7",tr("Verbindung von %1 getrennt.").arg(dynamic_cast<QTcpSocket*> (klient)->peerAddress().toString()),LOG_INFO));
Melden(Meldung("fcea41ff29354995b415d9dce03fcdf7",tr("Verbindung von %1 getrennt.").arg(dynamic_cast<QTcpSocket*> (klient)->peerAddress().toString()),LOG_INFO));
K_Klienten->removeOne(dynamic_cast<QTcpSocket*> (klient));
}
bool Steuerung::KontextWechseln(const QString &nutzer, const QString &gruppe)
Expand All @@ -129,7 +128,6 @@ bool Steuerung::KontextWechseln(const QString &nutzer, const QString &gruppe)
if (FehlerGruppe !=0)
Fehlertext.append(QString("\n%1").arg(strerror(FehlerGruppe)));
Melden(Meldung("3dfabfae6cf244b690d9d41b0b293593",Fehlertext,LOG_CRIT));
QCoreApplication::quit();
return false;
}
if( Nutzer==NULL)
Expand All @@ -138,26 +136,22 @@ bool Steuerung::KontextWechseln(const QString &nutzer, const QString &gruppe)
if (FehlerNutzer!=0)
Fehlertext.append(QString("\n%1").arg(strerror(FehlerNutzer)));
Melden(Meldung("a9a1690d05ef442cbd2625d3065bbdb9",Fehlertext,LOG_CRIT));
QCoreApplication::quit();
return false;
}
GruppeID=Gruppe->gr_gid;
NutzerID=Nutzer->pw_uid;

if (K_Protokoll==Protokolltiefe::Debug)
Melden(Meldung("b044be0993314c3384c95cce368c207e",tr("Starte als Nutzer: %1(%2) Gruppe: %3(%4)").arg(nutzer).arg(NutzerID).arg(gruppe).arg(GruppeID),LOG_DEBUG));
Melden(Meldung("b044be0993314c3384c95cce368c207e",tr("Starte als Nutzer: %1(%2) Gruppe: %3(%4)").arg(nutzer).arg(NutzerID).arg(gruppe).arg(GruppeID),LOG_DEBUG));
if(setuid(NutzerID)!=0)
{
int Fehler=errno;
Melden(Meldung("b74f03cfa9d34ed6aa9f40325ff6f4c5",tr("Konnte nicht in den Benutzerkontext %1 wechseln.\n%2").arg(nutzer).arg(strerror(Fehler)),LOG_CRIT));
QCoreApplication::quit();
return false;
}
if(setgid(GruppeID)!=0)
{
int Fehler=errno;
Melden(Meldung("5acf2a01d541456499e684e160bb8ebf",tr("Konnte nicht in den Gruppenkontext %1 wechseln.\n%2").arg(gruppe).arg(strerror(Fehler)),LOG_CRIT));
QCoreApplication::quit();
return false;
}
return true;
Expand All @@ -178,35 +172,30 @@ bool Steuerung::TCPstarten()
Anschluss=K_Einstellungen->value(QString("%1/Anschluss").arg(Dienst),0).toInt();
if ((Anschluss ==0) || (Anschluss >65535))
{
if(K_Protokoll >=Protokolltiefe::Fehler)
Melden(Meldung("ba896cda507d4a79a34c6b7db175b64e",trUtf8("Anschlussnummer %1 ist ungültig. Ignoriere %2.").arg(Anschluss).arg(Dienst),LOG_ERR));
Melden(Meldung("ba896cda507d4a79a34c6b7db175b64e",trUtf8("Anschlussnummer %1 ist ungültig. Ignoriere %2.").arg(Anschluss).arg(Dienst),LOG_ERR));
continue;
}
Adresse=K_Einstellungen->value(QString("%1/Adresse").arg(Dienst),"").toString();
if ((Adresse.isEmpty()) || (QHostAddress(Adresse).isNull()))
{
if(K_Protokoll >=Protokolltiefe::Fehler)
Melden(Meldung("bd4b290c2a7a4627a8d2129338b58798",trUtf8("Adresse %1 ist ungültig. Ignoriere %2.").arg(Adresse).arg(Dienst),LOG_ERR));
Melden(Meldung("bd4b290c2a7a4627a8d2129338b58798",trUtf8("Adresse %1 ist ungültig. Ignoriere %2.").arg(Adresse).arg(Dienst),LOG_ERR));
continue;
}
if(K_Protokoll==Protokolltiefe::Debug)
Melden(Meldung("81964998fd0f4f6cb7c82ffc5b7bdf27",tr("Erstelle: %1 Adresse: %2 Anschluss: %3").arg(Dienst).arg(Adresse).arg(Anschluss),LOG_DEBUG));
Melden(Meldung("81964998fd0f4f6cb7c82ffc5b7bdf27",tr("Erstelle: %1 Adresse: %2 Anschluss: %3").arg(Dienst).arg(Adresse).arg(Anschluss),LOG_DEBUG));

//Starten der Dienste
Datendienst=new QTcpServer(this);
if(!Datendienst->listen(QHostAddress(Adresse),Anschluss))
{
if(K_Protokoll >=Protokolltiefe::Fehler)
Melden(Meldung("d91c632a84b54f3cb634485cf007d485",tr("Konnte %1 nicht starten.\n%2").arg(Dienst).arg(Datendienst->errorString()),LOG_ERR));
Melden(Meldung("d91c632a84b54f3cb634485cf007d485",tr("Konnte %1 nicht starten.\n%2").arg(Dienst).arg(Datendienst->errorString()),LOG_ERR));
Datendienst->deleteLater();
}
else
{
gueltigerDienst=true;
connect(Datendienst, SIGNAL(newConnection()), K_Klientensammler, SLOT(map()));
K_Klientensammler->setMapping(Datendienst,Datendienst);
if(K_Protokoll >=Protokolltiefe::Info)
Melden(Meldung("fefe966c7e594a48bd0365e961a2c30c",trUtf8("Lausche für %1 auf %2 Anschluss %3").arg(Dienst).arg(Adresse).arg(Anschluss),LOG_INFO));
Melden(Meldung("fefe966c7e594a48bd0365e961a2c30c",trUtf8("Lausche für %1 auf %2 Anschluss %3").arg(Dienst).arg(Adresse).arg(Anschluss),LOG_INFO));
}

}
Expand All @@ -215,19 +204,16 @@ bool Steuerung::TCPstarten()
connect(K_Klientloescher,SIGNAL(mapped(QObject*)),this,SLOT(KlientLoeschen(QObject*)));
if(!gueltigerDienst)
{
if(K_Protokoll >=Protokolltiefe::Fehler)
Melden(Meldung("217dfdf7f21949b08a37ae5dd20d88f6",tr("Es konnte kein Dienst gestartet werden."),LOG_ERR));
Melden(Meldung("217dfdf7f21949b08a37ae5dd20d88f6",tr("Es konnte kein Dienst gestartet werden."),LOG_ERR));
QCoreApplication::quit();
}
return gueltigerDienst;
}
bool Steuerung::ModulLaden(const QString modulname, const QString &pfad)
{
if (K_Protokoll==Protokolltiefe::Debug)
{
Melden(Meldung("35b01b5da0cc44dcb04822de636f620b",tr("Modulpfad: %1").arg(pfad),LOG_DEBUG));
Melden(Meldung("9ac70e7688f8437eb1b72e6737b4c445",tr("Modul: %1").arg(modulname),LOG_DEBUG));
}
Melden(Meldung("35b01b5da0cc44dcb04822de636f620b",tr("Modulpfad: %1").arg(pfad),LOG_DEBUG));
Melden(Meldung("9ac70e7688f8437eb1b72e6737b4c445",tr("Modul: %1").arg(modulname),LOG_DEBUG));

QString Datei;
QDirIterator Verzeichis(pfad,QDirIterator::Subdirectories);
bool ModulGefunden=false;
Expand All @@ -236,41 +222,31 @@ bool Steuerung::ModulLaden(const QString modulname, const QString &pfad)
Datei=Verzeichis.next();
if (Verzeichis.fileInfo().isFile())
{
if (K_Protokoll==Protokolltiefe::Debug)
Melden(Meldung("de0b1026c38040708422dbbb6b512d61",tr("Untersuche Datei %1 auf eine Erweiterung").arg(Datei),LOG_DEBUG));
Melden(Meldung("de0b1026c38040708422dbbb6b512d61",tr("Untersuche Datei %1 auf eine Erweiterung").arg(Datei),LOG_DEBUG));
QPluginLoader ErweiterungLesen(Datei);
QObject *Erweiterung = ErweiterungLesen.instance();
if(Erweiterung)
{
if (K_Protokoll==Protokolltiefe::Debug)
Melden(Meldung("64016fc20c8e434a98418514639ab699",tr("Untersuche Datei %1 auf eine gpsd-tcp Erweiterung").arg(Datei),LOG_DEBUG));
Melden(Meldung("64016fc20c8e434a98418514639ab699",tr("Untersuche Datei %1 auf eine gpsd-tcp Erweiterung").arg(Datei),LOG_DEBUG));
Pluginfabrik* gpsd_tcpd_Erweiterung= qobject_cast<Pluginfabrik*>(Erweiterung);
if(gpsd_tcpd_Erweiterung)
{
if (K_Protokoll==Protokolltiefe::Debug)
Melden(Meldung("e04e03ea37294065b95590b9052c8081",tr("%1 ist eine gpsd-tcp Erweiterung").arg(Datei),LOG_DEBUG));
Melden(Meldung("e04e03ea37294065b95590b9052c8081",tr("%1 ist eine gpsd-tcp Erweiterung").arg(Datei),LOG_DEBUG));
if(gpsd_tcpd_Erweiterung->plugin(this)->Name() == modulname )
{
if (K_Protokoll==Protokolltiefe::Debug)
Melden(Meldung("38395376945042999326095790667f8e",tr("Modul %1 gefunden.").arg(modulname),LOG_DEBUG));
Melden(Meldung("38395376945042999326095790667f8e",tr("Modul %1 gefunden.").arg(modulname),LOG_DEBUG));
ModulGefunden=true;
connect(gpsd_tcpd_Erweiterung->plugin(this)->Erweiterung(this,K_Einstellungen),SIGNAL(Daten(const QString&)),this,SLOT(DatenVerteilen(QString)));
connect(gpsd_tcpd_Erweiterung->plugin(this)->Erweiterung(this,K_Einstellungen),SIGNAL(MeldungSenden(Meldung)),this,SLOT(Melden(Meldung)));
break;
}
}

}
else
{
if (K_Protokoll==Protokolltiefe::Debug)
Melden(Meldung("5f0663b236b24fb28a5b7066f93ddd1f",tr("Konnte %1 nicht verarbeiten.").arg(Datei),LOG_DEBUG));
}
Melden(Meldung("5f0663b236b24fb28a5b7066f93ddd1f",tr("Konnte %1 nicht verarbeiten.").arg(Datei),LOG_DEBUG));
}
}
if (!ModulGefunden)
{
Melden(Meldung("a19f89878e354485aa86f4e54cd0e76d",tr("Das Modul %1 konnte nicht gefunden werden.").arg(modulname),LOG_CRIT));
QCoreApplication::quit();
}
return ModulGefunden;
}
2 changes: 1 addition & 1 deletion gpsd-tcp/Quellen/Steuerung.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class Steuerung : public QObject
void NeuerKlient(QObject *dienst);
void KlientLoeschen(QObject *klient);
void DatenVerteilen(const QString &daten);
void Melden(Meldung meldung) const;

private:
void Melden(Meldung m)const;
bool TCPstarten();
bool KontextWechseln(const QString &nutzer, const QString &gruppe);
bool ModulLaden(const QString modulname,const QString &pfad);
Expand Down

0 comments on commit 4c16f0c

Please sign in to comment.