From bb6a9235c31027bbbb0773aaddae29c635be514e Mon Sep 17 00:00:00 2001 From: "Srivats P." Date: Sun, 29 Nov 2009 16:32:31 +0000 Subject: [PATCH] Features - Ostinato Client - will start the server as a child process at startup and terminate it at exit - Ostinato Server (Drone) - is now a system tray application - if not able to bind to a IP/Port successfully, informs the user and exits - the GUI is now nothing more than a TextLabel Others - If a getStats() request is pending, the client will not queue up any more requests till a reply is received for the pending one - Nitpicks in the Payload protocol Widget, PortsWindow Widget --- client/main.cpp | 3 +- client/mainwindow.cpp | 14 ++- client/mainwindow.h | 12 ++- client/portgroup.cpp | 6 ++ client/portgroup.h | 1 + client/portswindow.cpp | 1 - client/portswindow.ui | 3 + common/payload.ui | 135 +++++++++++++++++---------- rpc/rpcserver.cpp | 27 ++++-- rpc/rpcserver.h | 4 +- server/abstracthost.h | 14 --- server/drone.cpp | 79 +++++++++++++--- server/drone.h | 41 ++++++--- server/drone.pro | 1 + server/drone.ui | 182 ++++++++++++++++++++++++------------- server/drone_main.cpp | 17 +++- server/icons/portgroup.png | Bin 0 -> 667 bytes server/myservice.cpp | 5 +- server/myservice.h | 6 +- 19 files changed, 367 insertions(+), 184 deletions(-) delete mode 100644 server/abstracthost.h create mode 100644 server/icons/portgroup.png diff --git a/client/main.cpp b/client/main.cpp index 34a9f8c..2f9b385 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -1,6 +1,7 @@ -#include #include "mainwindow.h" +#include + int main(int argc, char* argv[]) { QApplication app(argc, argv); diff --git a/client/mainwindow.cpp b/client/mainwindow.cpp index 0a0e0fb..9b2d12a 100644 --- a/client/mainwindow.cpp +++ b/client/mainwindow.cpp @@ -1,17 +1,25 @@ #include "mainwindow.h" -#include "portgrouplist.h" #if 0 #include "dbgthread.h" #endif +#include "portgrouplist.h" +#include "portstatswindow.h" +#include "portswindow.h" #include "ui_about.h" +#include +#include + PortGroupList *pgl; MainWindow::MainWindow(QWidget *parent) : QMainWindow (parent) { + localServer_ = new QProcess(this); + localServer_->start("drone.exe"); + pgl = new PortGroupList; portsWindow = new PortsWindow(pgl, this); @@ -37,6 +45,10 @@ MainWindow::MainWindow(QWidget *parent) MainWindow::~MainWindow() { + delete pgl; + localServer_->terminate(); + localServer_->waitForFinished(); + delete localServer_; } void MainWindow::on_actionHelpAbout_triggered() diff --git a/client/mainwindow.h b/client/mainwindow.h index a5d31a6..5132385 100644 --- a/client/mainwindow.h +++ b/client/mainwindow.h @@ -1,19 +1,21 @@ #ifndef _MAIN_WINDOW_H #define _MAIN_WINDOW_H -#include -#include - #include "ui_mainwindow.h" +#include -#include "portswindow.h" -#include "portstatswindow.h" +class PortsWindow; +class PortStatsWindow; + +class QDockWidget; +class QProcess; class MainWindow : public QMainWindow, private Ui::MainWindow { Q_OBJECT private: + QProcess *localServer_; PortsWindow *portsWindow; PortStatsWindow *statsWindow; QDockWidget *portsDock; diff --git a/client/portgroup.cpp b/client/portgroup.cpp index 9e17ae8..4a2843c 100644 --- a/client/portgroup.cpp +++ b/client/portgroup.cpp @@ -21,6 +21,7 @@ PortGroup::PortGroup(QHostAddress ip, quint16 port) */ rpcController = new PbRpcController; rpcControllerStats = new PbRpcController; + isGetStatsPending_ = false; serviceStub = new OstProto::OstService::Stub(rpcChannel, OstProto::OstService::STUB_OWNS_CHANNEL); @@ -640,8 +641,12 @@ void PortGroup::getPortStats() if (state() != QAbstractSocket::ConnectedState) return; + if (isGetStatsPending_) + return; + portStatsList = new OstProto::PortStatsList; rpcControllerStats->Reset(); + isGetStatsPending_ = true; serviceStub->getStats(rpcControllerStats, &portIdList, portStatsList, NewCallback(this, &PortGroup::processPortStatsList, portStatsList)); } @@ -669,6 +674,7 @@ void PortGroup::processPortStatsList(OstProto::PortStatsList *portStatsList) _error_exit: delete portStatsList; + isGetStatsPending_ = false; } void PortGroup::clearPortStats(QList *portList) diff --git a/client/portgroup.h b/client/portgroup.h index c63d739..f4d8e99 100644 --- a/client/portgroup.h +++ b/client/portgroup.h @@ -34,6 +34,7 @@ private: PbRpcChannel *rpcChannel; PbRpcController *rpcController; PbRpcController *rpcControllerStats; + bool isGetStatsPending_; ::OstProto::OstService::Stub *serviceStub; ::OstProto::PortIdList portIdList; diff --git a/client/portswindow.cpp b/client/portswindow.cpp index 7d9bbc4..54d4b8b 100644 --- a/client/portswindow.cpp +++ b/client/portswindow.cpp @@ -71,7 +71,6 @@ PortsWindow::PortsWindow(PortGroupList *pgl, QWidget *parent) PortsWindow::~PortsWindow() { - delete plm; } void PortsWindow::on_tvStreamList_activated(const QModelIndex & index) diff --git a/client/portswindow.ui b/client/portswindow.ui index 1ed9485..9e461a2 100644 --- a/client/portswindow.ui +++ b/client/portswindow.ui @@ -18,6 +18,9 @@ Qt::Horizontal + + false + Qt::ActionsContextMenu diff --git a/common/payload.ui b/common/payload.ui index c0a1b31..a7ff9a2 100644 --- a/common/payload.ui +++ b/common/payload.ui @@ -5,63 +5,100 @@ 0 0 - 142 - 98 + 299 + 114 Form - - - - - Data Pattern + + + + + Type + + + cmbPatternMode - - - - - - Fixed Word - - - - - Increment Byte - - - - - Decrement Byte - - - - - Random - - - - - - - - >HH HH HH HH; - - - - - - 11 - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - + + + + + Fixed Word + + + + + Increment Byte + + + + + Decrement Byte + + + + + Random + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Pattern + + + lePattern + + + + + + + >HH HH HH HH; + + + + + + 11 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + diff --git a/rpc/rpcserver.cpp b/rpc/rpcserver.cpp index 039fc83..3d5a10c 100644 --- a/rpc/rpcserver.cpp +++ b/rpc/rpcserver.cpp @@ -27,14 +27,25 @@ bool RpcServer::registerService(::google::protobuf::Service *service, connect(server, SIGNAL(newConnection()), this, SLOT(when_newConnection())); if (!server->listen(QHostAddress::Any, tcpPortNum)) { - LogInt(tr("Unable to start the server: %1").arg(server->errorString())); + qDebug("Unable to start the server: %s", + server->errorString().toAscii().constData()); + errorString_ = QString("Error starting Ostinato server: %1").arg( + server->errorString()); return false; } - LogInt(tr("The server is running on %1:%2").arg(server->serverAddress().toString()).arg(server->serverPort())); + qDebug("The server is running on %s: %d", + server->serverAddress().toString().toAscii().constData(), + server->serverPort()); + errorString_ = QString(); return true; } +QString RpcServer::errorString() +{ + return errorString_; +} + void RpcServer::done(::google::protobuf::Message *resp, PbRpcController *PbRpcController) { QIODevice *blob; @@ -111,7 +122,7 @@ void RpcServer::when_newConnection() { QTcpSocket *sock; - LogInt(tr("already connected, no new connections will be accepted\n")); + qDebug("already connected, no new connections will be accepted"); // Accept and close connection //! \todo (MED) Send reason msg to client @@ -122,7 +133,9 @@ void RpcServer::when_newConnection() } clientSock = server->nextPendingConnection(); - LogInt(tr("accepting new connection from %1:%2").arg(clientSock->peerAddress().toString()).arg(clientSock->peerPort())); + qDebug("accepting new connection from %s: %d", + clientSock->peerAddress().toString().toAscii().constData(), + clientSock->peerPort()); connect(clientSock, SIGNAL(readyRead()), this, SLOT(when_dataAvail())); @@ -137,7 +150,9 @@ _exit: void RpcServer::when_disconnected() { - LogInt(tr("connection closed from %1:%2").arg(clientSock->peerAddress().toString()).arg(clientSock->peerPort())); + qDebug("connection closed from %s: %d", + clientSock->peerAddress().toString().toAscii().constData(), + clientSock->peerPort()); clientSock->deleteLater(); clientSock = NULL; @@ -145,7 +160,7 @@ void RpcServer::when_disconnected() void RpcServer::when_error(QAbstractSocket::SocketError socketError) { - LogInt(clientSock->errorString()); + qDebug("%s", clientSock->errorString().toAscii().constData()); } void RpcServer::when_dataAvail() diff --git a/rpc/rpcserver.h b/rpc/rpcserver.h index d93b08a..619cb2d 100644 --- a/rpc/rpcserver.h +++ b/rpc/rpcserver.h @@ -23,8 +23,7 @@ class RpcServer : public QObject bool isPending; int pendingMethodId; - - void LogInt (QString log) {qDebug("%s", log.toAscii().data());} + QString errorString_; public: RpcServer(); //! \todo (LOW) use 'parent' param @@ -32,6 +31,7 @@ public: bool registerService(::google::protobuf::Service *service, quint16 tcpPortNum); + QString errorString(); void done(::google::protobuf::Message *resp, PbRpcController *controller); private slots: diff --git a/server/abstracthost.h b/server/abstracthost.h deleted file mode 100644 index 862666c..0000000 --- a/server/abstracthost.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _ABSTRACT_HOST -#define _ABSTRACT_HOST - -class AbstractHost -{ - public: - virtual void Log(const char* str) = 0; -#if 0 // PB - virtual int SendMsg(const void* msg, int size) = 0; -#endif -}; - -#endif - diff --git a/server/drone.cpp b/server/drone.cpp index 1f94d7e..c84aec5 100644 --- a/server/drone.cpp +++ b/server/drone.cpp @@ -1,23 +1,76 @@ #include "drone.h" +#include "rpcserver.h" +#include "myservice.h" + +#include +#include + extern int myport; -Drone::Drone(QDialog *parent) - : QDialog(parent) +Drone::Drone(QWidget *parent) + : QWidget(parent) { - ui.setupUi(this); + setupUi(this); - rpcServer = new RpcServer(); - service = new MyService(this); - rpcServer->registerService(service, myport ? myport : 7878); -} - -void Drone::Log(const char* str) -{ - ui.teLog->append(QString(str)); + rpcServer = new RpcServer(); + service = new MyService(); } -void Drone::LogInt(const QString &str) +Drone::~Drone() { - ui.teLog->append(str); + trayIcon_->hide(); + delete rpcServer; + delete service; +} + +bool Drone::init() +{ + Q_ASSERT(rpcServer); + + if (!rpcServer->registerService(service, myport ? myport : 7878)) + { + QMessageBox::critical(0, qApp->applicationName(), + rpcServer->errorString()); + return false; + } + + trayIconMenu_ = new QMenu(this); + + trayIconMenu_->addAction(actionShow); + trayIconMenu_->addAction(actionExit); + trayIconMenu_->setDefaultAction(actionShow); + trayIcon_ = new QSystemTrayIcon(); + trayIcon_->setIcon(QIcon(":/icons/portgroup.png")); + trayIcon_->setToolTip(qApp->applicationName()); + trayIcon_->setContextMenu(trayIconMenu_); + trayIcon_->show(); + + connect(trayIcon_, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), + this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason))); + connect(this, SIGNAL(hideMe(bool)), this, SLOT(setHidden(bool)), + Qt::QueuedConnection); + + return true; +} + +void Drone::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::WindowStateChange && isMinimized()) + { + emit hideMe(true); + event->ignore(); + return; + } + + QWidget::changeEvent(event); +} + +void Drone::trayIconActivated(QSystemTrayIcon::ActivationReason reason) +{ + if (reason == QSystemTrayIcon::DoubleClick) + { + showNormal(); + activateWindow(); + } } diff --git a/server/drone.h b/server/drone.h index 31574a6..5930dd0 100644 --- a/server/drone.h +++ b/server/drone.h @@ -1,26 +1,37 @@ #ifndef _DRONE_H #define _DRONE_H -#include -#include - #include "ui_drone.h" -#include "abstracthost.h" -#include "rpcserver.h" -#include "myservice.h" -class Drone : public QDialog, AbstractHost +#include +#include + +class RpcServer; +namespace OstProto { class OstService; } + +class Drone : public QWidget, Ui::Drone { Q_OBJECT - public: - Ui::Drone ui; - Drone(QDialog *parent = 0); - void Log(const char *msg); +public: + Drone(QWidget *parent = 0); + ~Drone(); + bool init(); + +signals: + void hideMe(bool hidden); + +protected: + void changeEvent(QEvent *event); + +private: + QSystemTrayIcon *trayIcon_; + QMenu *trayIconMenu_; + RpcServer *rpcServer; + OstProto::OstService *service; + +private slots: + void trayIconActivated(QSystemTrayIcon::ActivationReason reason); - private: - RpcServer *rpcServer; - OstProto::OstService *service; - void LogInt(const QString &msg); }; #endif diff --git a/server/drone.pro b/server/drone.pro index f569b4d..a5cd2bb 100644 --- a/server/drone.pro +++ b/server/drone.pro @@ -11,6 +11,7 @@ unix:LIBS += -L"../common" -lostproto win32:LIBS += -L"../rpc/debug" -lpbrpc unix:LIBS += -L"../rpc" -lpbrpc POST_TARGETDEPS += "../common/debug/libostproto.a" "../rpc/debug/libpbrpc.a" +RESOURCES += drone.qrc HEADERS += drone.h FORMS += drone.ui SOURCES += drone_main.cpp drone.cpp diff --git a/server/drone.ui b/server/drone.ui index 5caa184..73fde04 100644 --- a/server/drone.ui +++ b/server/drone.ui @@ -1,69 +1,82 @@ Drone - + 0 0 - 400 - 300 + 268 + 216 Drone + + :/icons/portgroup.png + - - - 1 + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + <html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:29pt; font-weight:600;">Ostinato</span></p></body></html> + + + Qt::AlignCenter - - - Status - - - - - 160 - 100 - 46 - 14 - - - - TODO - - - - - - Log - - - - - - true - - - false - - - - - + + + + (Server) + + + Qt::AlignCenter + + + + + + + TODO: Info/Status here + + + Qt::AlignCenter + + + + + + + Qt::Vertical + + + + 20 + 51 + + + + - - - - Clear Log - - - @@ -84,41 +97,82 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + Show + + + + + Exit + + - + + + pushButton - clicked(bool) - Drone - accept() + clicked() + actionExit + trigger() - 341 - 279 + 134 + 194 - 226 - 268 + -1 + -1 - pbClearLog - clicked() - teLog - clear() + actionShow + triggered() + Drone + showNormal() - 52 - 278 + -1 + -1 - 100 - 185 + 133 + 107 + + + + + actionExit + triggered() + Drone + close() + + + -1 + -1 + + + 133 + 107 diff --git a/server/drone_main.cpp b/server/drone_main.cpp index 007f1af..6a9052f 100644 --- a/server/drone_main.cpp +++ b/server/drone_main.cpp @@ -1,18 +1,25 @@ #include "drone.h" -Drone *drone; - int myport; int main(int argc, char *argv[]) { QApplication app(argc, argv); + Drone drone; + + app.setApplicationName(drone.objectName()); if (argc > 1) myport = atoi(argv[1]); - drone = new Drone; - drone->show(); - return app.exec(); + if (!drone.init()) + exit(-1); + + drone.setWindowFlags(drone.windowFlags() + | Qt::WindowMaximizeButtonHint + | Qt::WindowMinimizeButtonHint); + drone.showMinimized(); + app.exec(); + return 0; } diff --git a/server/icons/portgroup.png b/server/icons/portgroup.png new file mode 100644 index 0000000000000000000000000000000000000000..9bc37dce369d66bdf38393b191df4d7e6c7ccd54 GIT binary patch literal 667 zcmV;M0%ZM(P)a!u4Ek1OWvhNg%r^rdTXsY3VK8?SdPP#w89em&*t9`8-y> z{{XWmi9uo#0y2mREC>R)tyU|D<2Xwun+7u3ce~yHC8N{n5>SE*7ca{{mxCuK52M#x z6?VgqVUHr69iApkt_fp7}UIJIX)^0!0b=W3KH zu#9)c?;$B!KqeOeo#x5*?d$d(>1am)Y%kbK4HaZEF7DqvCglmk2%DRMFl4hCO2bI^ zX=T@9j!era3Mj9K%ggW14jP4g$@9D^u1>q%4oF>&Q{%YG^bC$1Iv|Sn?VXTj+j1A` z_4;iBxjK9L%sJ01;N^>_f2ih9=zM1B|Mb6I%0_FShXA!&ZGuYnYi{m5Mm>)<#Bd!= zpw*3PwK}@fZ5>`FlHMWvu( #endif -#define LOG(...) {sprintf(logStr, __VA_ARGS__); host->Log(logStr);} +#define LOG(...) {} #define MB (1024*1024) StreamInfo::StreamInfo() @@ -831,14 +831,13 @@ _found: return i; } -MyService::MyService(AbstractHost *host) +MyService::MyService() { pcap_if_t *dev; int i=0; char errbuf[PCAP_ERRBUF_SIZE]; // Init Data - this->host = host; numPorts = 0; alldevs = NULL; diff --git a/server/myservice.h b/server/myservice.h index bafe9b9..4be1bdb 100644 --- a/server/myservice.h +++ b/server/myservice.h @@ -9,7 +9,6 @@ #include "../common/protocol.pb.h" #include "../common/streambase.h" -#include "abstracthost.h" #include #include #include @@ -191,9 +190,6 @@ public: class MyService: public OstProto::OstService { - AbstractHost *host; - char logStr[1024]; - uint numPorts; /*! PortInfo::d::port_id and index into portInfo[] are same! */ @@ -203,7 +199,7 @@ class MyService: public OstProto::OstService int getStreamIndex(unsigned int portIdx,unsigned int streamId); public: - MyService(AbstractHost* host); + MyService(); virtual ~MyService(); /* Methods provided by the service */