source: ntrip/trunk/BNS/bns.cpp@ 769

Last change on this file since 769 was 769, checked in by mervart, 16 years ago

* empty log message *

File size: 2.4 KB
Line 
1/* -------------------------------------------------------------------------
2 * BKG NTRIP Server
3 * -------------------------------------------------------------------------
4 *
5 * Class: bns
6 *
7 * Purpose: This class implements the main application behaviour
8 *
9 * Author: L. Mervart
10 *
11 * Created: 29-Mar-2008
12 *
13 * Changes:
14 *
15 * -----------------------------------------------------------------------*/
16
17#include <iostream>
18
19#include "bns.h"
20
21using namespace std;
22
23// Constructor
24////////////////////////////////////////////////////////////////////////////
25t_bns::t_bns(QObject* parent) : QThread(parent) {
26
27 this->setTerminationEnabled(true);
28
29 _bnseph = new t_bnseph(parent);
30
31 connect(_bnseph, SIGNAL(newMessage(QByteArray)),
32 this, SLOT(slotMessage(const QByteArray)));
33
34 connect(_bnseph, SIGNAL(error(QByteArray)),
35 this, SLOT(slotError(const QByteArray)));
36
37 _clkServer = 0;
38 _clkSocket = 0;
39}
40
41// Destructor
42////////////////////////////////////////////////////////////////////////////
43t_bns::~t_bns() {
44 deleteBnsEph();
45 delete _clkServer;
46}
47
48// Delete bns thread
49////////////////////////////////////////////////////////////////////////////
50void t_bns::deleteBnsEph() {
51 if (_bnseph) {
52 _bnseph->terminate();
53 _bnseph->wait(100);
54 delete _bnseph;
55 _bnseph = 0;
56 }
57}
58
59// Write a Program Message
60////////////////////////////////////////////////////////////////////////////
61void t_bns::slotMessage(const QByteArray msg) {
62 cout << msg.data() << endl;
63 emit(newMessage(msg));
64}
65
66// Write a Program Message
67////////////////////////////////////////////////////////////////////////////
68void t_bns::slotError(const QByteArray msg) {
69 cerr << msg.data() << endl;
70 deleteBnsEph();
71 emit(error(msg));
72}
73
74// New Connection
75////////////////////////////////////////////////////////////////////////////
76void t_bns::slotNewConnection() {
77 _clkSocket = _clkServer->nextPendingConnection();
78}
79
80// Start
81////////////////////////////////////////////////////////////////////////////
82void t_bns::run() {
83
84 slotMessage("============ Start BNS ============");
85 _bnseph->start();
86
87 QSettings settings;
88 int port = settings.value("clkPort").toInt();
89
90 _clkServer = new QTcpServer;
91 _clkServer->listen(QHostAddress::Any, port);
92 connect(_clkServer, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
93
94 while (true) {
95 if (_clkSocket) {
96
97 }
98 else {
99 msleep(100);
100 }
101 }
102}
103
Note: See TracBrowser for help on using the repository browser.