diff options
Diffstat (limited to 'testIvyQt.cxx')
-rw-r--r-- | testIvyQt.cxx | 194 |
1 files changed, 194 insertions, 0 deletions
diff --git a/testIvyQt.cxx b/testIvyQt.cxx new file mode 100644 index 0000000..ad5094d --- /dev/null +++ b/testIvyQt.cxx @@ -0,0 +1,194 @@ +/* + * Ivy probe + * + * Copyright (C) 1997-1999 + * Centre d'Études de la Navigation Aérienne + * + * Main and only file + * + * Authors: Alexandre Bustico <alexandre.bustico@cena.fr> + * + * $Id: testIvyQt.cxx 1253 2006-05-24 13:02:58Z fourdan $ + * + * Please refer to file version.h for the + * copyright notice regarding this software + */ + +#include <iostream> +#include <fstream> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <sys/time.h> +#include <unistd.h> +#include <QApplication> + +#include <QFont> +#include <QLCDNumber> +#include <QPushButton> +#include <QSlider> +#include <QVBoxLayout> +#include <QWidget> + +#include "Ivycpp.h" +#include "IvyApplication.h" + + + + + + + + + +// int main(int argc, char *argv[]) +// { + +// IvyTest test; +// test.bus->setXtAppContext(cntx); + +// test.Start(); + +// XtAppMainLoop (cntx); + +// return 0; +// } + + + +class MyWidget : public QWidget, public IvyApplicationCallback, public IvyMessageCallback + { + Q_OBJECT + public: + MyWidget(QWidget *parent = 0); + + Ivy *bus; + void IvyStart(); + void OnApplicationConnected(IvyApplication *app); + void OnApplicationDisconnected(IvyApplication *app); + void OnApplicationCongestion(IvyApplication *app); + void OnApplicationDecongestion(IvyApplication *app); + void OnApplicationFifoFull(IvyApplication *app); + void OnMessage(IvyApplication *app, int argc, const char **argv); + + private: + QSlider *slider; + QLCDNumber *lcd; + QPushButton *quit; + static void ivyAppConnCb( IvyApplication *app ) {}; + static void ivyAppDiscConnCb( IvyApplication *app ) {}; + +private slots: + void sliderChange (int value); +}; + + + + MyWidget::MyWidget(QWidget *parent) + : QWidget(parent) + { + quit = new QPushButton(tr("Quit")); + quit->setFont(QFont("Times", 18, QFont::Bold)); + + lcd = new QLCDNumber(2); + lcd->setSegmentStyle(QLCDNumber::Filled); + + slider = new QSlider(Qt::Horizontal); + slider->setRange(0, 99); + slider->setValue(0); + + connect(quit, SIGNAL(clicked()), qApp, SLOT(quit())); + connect(slider, SIGNAL(valueChanged(int)), + lcd, SLOT(display(int))); + connect(slider, SIGNAL(valueChanged(int)), + this, SLOT(sliderChange(int))); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(quit); + layout->addWidget(lcd); + layout->addWidget(slider); + setLayout(layout); + } + + + + + +void MyWidget::IvyStart() +{ + bus = new Ivy( "TestIvyQt", "TestIvyQt READY", + BUS_APPLICATION_CALLBACK( ivyAppConnCb, ivyAppDiscConnCb ),false); + bus->BindMsg( "(\\d+)", this ); + bus->start(NULL); +} + +void MyWidget::OnMessage(IvyApplication *app, int argc, const char **argv) +{ + int i; + printf ("%s sent ",app->GetName()); + for (i = 0; i < argc; i++) { + printf(" '%s'",argv[i]); + int j = atoi (argv[i]); + slider->setValue(j); + } + printf("\n"); +} +void MyWidget::OnApplicationConnected (IvyApplication *app) +{ + const char *appname; + const char *host; + appname = app->GetName(); + host = app->GetHost(); + + printf("%s connected from %s\n", appname, host); + +} +void MyWidget::OnApplicationDisconnected (IvyApplication *app) +{ + const char *appname; + const char *host; + appname = app->GetName (); + host = app->GetHost(); + + printf("%s disconnected from %s\n", appname, host); +} + +void MyWidget::sliderChange (int val) +{ + char msg[256]; + + snprintf (msg, sizeof(msg), "TestIvyQt slider=%d", val); + bus->SendMsg (msg); +} + + + +void MyWidget::OnApplicationCongestion(IvyApplication *app) +{ + std::cerr << "Ivy Congestion notififation\n"; +} +void MyWidget::OnApplicationDecongestion(IvyApplication *app) +{ + std::cerr << "Ivy Decongestion notififation\n"; +} +void MyWidget::OnApplicationFifoFull(IvyApplication *app) +{ + std::cerr << "Ivy FIFO Full notififation : MESSAGE WILL BE LOST\n"; +} + + + + int main(int argc, char *argv[]) + { + QApplication app(argc, argv); + MyWidget widget; + widget.IvyStart(); + + widget.show(); + return app.exec(); + } + + +#include "testIvyQt.moc" |