2015-04-16 11:50:07 -05:00
|
|
|
/*
|
|
|
|
Copyright (C) 2010 Srivats P.
|
|
|
|
|
|
|
|
This file is part of "Ostinato"
|
|
|
|
|
|
|
|
This is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _PORT_GROUP_H
|
|
|
|
#define _PORT_GROUP_H
|
|
|
|
|
|
|
|
#include "port.h"
|
|
|
|
#include <QHostAddress>
|
|
|
|
#include <QTcpSocket>
|
|
|
|
|
|
|
|
#include "../common/protocol.pb.h"
|
|
|
|
#include "pbrpcchannel.h"
|
|
|
|
|
|
|
|
/* TODO
|
|
|
|
HIGH
|
|
|
|
MED
|
|
|
|
LOW
|
|
|
|
- Allow hostnames in addition to IP Address as "server address"
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DEFAULT_SERVER_PORT 7878
|
|
|
|
|
2016-04-13 21:14:07 -05:00
|
|
|
namespace OstProto {
|
2016-05-05 08:43:00 -05:00
|
|
|
class PortContent;
|
2016-04-13 21:14:07 -05:00
|
|
|
class PortGroupContent;
|
2016-11-24 10:14:38 -06:00
|
|
|
class StreamStatsList;
|
2016-04-13 21:14:07 -05:00
|
|
|
}
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
class QFile;
|
|
|
|
class QTimer;
|
|
|
|
|
|
|
|
class PortGroup : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum { kIncompatible, kCompatible, kUnknown } compat;
|
|
|
|
static quint32 mPortGroupAllocId;
|
|
|
|
quint32 mPortGroupId;
|
|
|
|
QString mUserAlias; // user defined
|
|
|
|
|
|
|
|
bool reconnect;
|
|
|
|
int reconnectAfter; // time in milliseconds
|
|
|
|
static const int kMinReconnectWaitTime = 2000; // ms
|
|
|
|
static const int kMaxReconnectWaitTime = 60000; // ms
|
|
|
|
QTimer *reconnectTimer;
|
|
|
|
PbRpcChannel *rpcChannel;
|
|
|
|
PbRpcController *statsController;
|
|
|
|
bool isGetStatsPending_;
|
|
|
|
|
|
|
|
OstProto::OstService::Stub *serviceStub;
|
|
|
|
|
|
|
|
OstProto::PortIdList *portIdList_;
|
|
|
|
OstProto::PortStatsList *portStatsList_;
|
|
|
|
|
2016-04-13 21:14:07 -05:00
|
|
|
OstProto::PortGroupContent *atConnectConfig_;
|
2016-05-05 08:43:00 -05:00
|
|
|
QList<const OstProto::PortContent*> atConnectPortConfig_;
|
2016-04-13 21:14:07 -05:00
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
public: // FIXME(HIGH): member access
|
|
|
|
QList<Port*> mPorts;
|
|
|
|
|
|
|
|
public:
|
2015-11-06 07:27:07 -06:00
|
|
|
PortGroup(QString serverName = "127.0.0.1",
|
2015-04-16 11:50:07 -05:00
|
|
|
quint16 port = DEFAULT_SERVER_PORT);
|
|
|
|
~PortGroup();
|
|
|
|
|
|
|
|
void connectToHost() {
|
|
|
|
reconnect = true;
|
|
|
|
compat = kUnknown;
|
|
|
|
rpcChannel->establish();
|
|
|
|
}
|
2015-11-06 07:27:07 -06:00
|
|
|
void connectToHost(QString serverName, quint16 port) {
|
2015-04-16 11:50:07 -05:00
|
|
|
reconnect = true;
|
|
|
|
compat = kUnknown;
|
2015-11-06 07:27:07 -06:00
|
|
|
rpcChannel->establish(serverName, port);
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
void disconnectFromHost() { reconnect = false; rpcChannel->tearDown(); }
|
|
|
|
|
2016-04-13 21:14:07 -05:00
|
|
|
void setConfigAtConnect(const OstProto::PortGroupContent *config);
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
int numPorts() const { return mPorts.size(); }
|
2016-05-06 10:54:36 -05:00
|
|
|
int numReservedPorts() const;
|
2015-04-16 11:50:07 -05:00
|
|
|
quint32 id() const { return mPortGroupId; }
|
|
|
|
|
|
|
|
const QString& userAlias() const { return mUserAlias; }
|
|
|
|
void setUserAlias(QString alias) { mUserAlias = alias; };
|
|
|
|
|
2015-11-06 07:27:07 -06:00
|
|
|
const QString serverName() const
|
|
|
|
{ return rpcChannel->serverName(); }
|
2015-04-16 11:50:07 -05:00
|
|
|
quint16 serverPort() const
|
|
|
|
{ return rpcChannel->serverPort(); }
|
2016-05-10 09:56:48 -05:00
|
|
|
const QString serverFullName() const;
|
2015-04-16 11:50:07 -05:00
|
|
|
QAbstractSocket::SocketState state() const {
|
|
|
|
if (compat == kIncompatible)
|
|
|
|
return QAbstractSocket::SocketState(-1);
|
|
|
|
return rpcChannel->state();
|
|
|
|
}
|
|
|
|
|
|
|
|
void processVersionCompatibility(PbRpcController *controller);
|
|
|
|
void processPortIdList(PbRpcController *controller);
|
|
|
|
void processPortConfigList(PbRpcController *controller);
|
|
|
|
|
|
|
|
void processAddStreamAck(PbRpcController *controller);
|
|
|
|
void processDeleteStreamAck(PbRpcController *controller);
|
|
|
|
void processModifyStreamAck(int portIndex, PbRpcController *controller);
|
2019-05-28 08:16:58 -05:00
|
|
|
void processApplyBuildAck(int portIndex, PbRpcController *controller);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
2016-03-04 16:36:36 -06:00
|
|
|
void processAddDeviceGroupAck(PbRpcController *controller);
|
|
|
|
void processDeleteDeviceGroupAck(PbRpcController *controller);
|
|
|
|
void processModifyDeviceGroupAck(int portIndex, PbRpcController *controller);
|
|
|
|
|
2016-03-11 07:28:08 -06:00
|
|
|
void processDeviceList(int portIndex, PbRpcController *controller);
|
2016-03-12 07:26:35 -06:00
|
|
|
void processDeviceNeighbors(int portIndex, PbRpcController *controller);
|
2016-03-11 07:28:08 -06:00
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
void modifyPort(int portId, OstProto::Port portConfig);
|
2019-05-28 08:16:58 -05:00
|
|
|
void processModifyPortAck(PbRpcController *controller);
|
|
|
|
void processModifyPortBuildAck(bool restoreUi, PbRpcController *controller);
|
2015-04-16 11:50:07 -05:00
|
|
|
void processUpdatedPortConfig(PbRpcController *controller);
|
|
|
|
|
|
|
|
void getStreamIdList();
|
|
|
|
void processStreamIdList(int portIndex, PbRpcController *controller);
|
2016-04-26 09:53:50 -05:00
|
|
|
void getStreamConfigList(int portIndex);
|
2015-04-16 11:50:07 -05:00
|
|
|
void processStreamConfigList(int portIndex, PbRpcController *controller);
|
|
|
|
|
|
|
|
void processModifyStreamAck(OstProto::Ack *ack);
|
|
|
|
|
2016-02-05 07:36:14 -06:00
|
|
|
void getDeviceGroupIdList();
|
|
|
|
void processDeviceGroupIdList(int portIndex, PbRpcController *controller);
|
2016-04-26 09:53:50 -05:00
|
|
|
void getDeviceGroupConfigList(int portIndex);
|
2016-02-05 07:36:14 -06:00
|
|
|
void processDeviceGroupConfigList(
|
|
|
|
int portIndex,
|
|
|
|
PbRpcController *controller);
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
void startTx(QList<uint> *portList = NULL);
|
|
|
|
void processStartTxAck(PbRpcController *controller);
|
|
|
|
void stopTx(QList<uint> *portList = NULL);
|
|
|
|
void processStopTxAck(PbRpcController *controller);
|
|
|
|
|
|
|
|
void startCapture(QList<uint> *portList = NULL);
|
|
|
|
void processStartCaptureAck(PbRpcController *controller);
|
|
|
|
void stopCapture(QList<uint> *portList = NULL);
|
|
|
|
void processStopCaptureAck(PbRpcController *controller);
|
|
|
|
void viewCapture(QList<uint> *portList = NULL);
|
|
|
|
void processViewCaptureAck(PbRpcController *controller);
|
|
|
|
|
2016-03-09 09:50:11 -06:00
|
|
|
void resolveDeviceNeighbors(QList<uint> *portList = NULL);
|
|
|
|
void processResolveDeviceNeighborsAck(PbRpcController *controller);
|
|
|
|
void clearDeviceNeighbors(QList<uint> *portList = NULL);
|
|
|
|
void processClearDeviceNeighborsAck(PbRpcController *controller);
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
void getPortStats();
|
|
|
|
void processPortStatsList();
|
|
|
|
void clearPortStats(QList<uint> *portList = NULL);
|
2016-11-28 08:49:17 -06:00
|
|
|
void processClearPortStatsAck(PbRpcController *controller);
|
|
|
|
bool clearStreamStats(QList<uint> *portList = NULL);
|
|
|
|
void processClearStreamStatsAck(PbRpcController *controller);
|
2016-11-24 10:14:38 -06:00
|
|
|
bool getStreamStats(QList<uint> *portList = NULL);
|
|
|
|
void processStreamStatsList(PbRpcController *controller);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
signals:
|
2019-02-22 07:28:13 -06:00
|
|
|
void applyFinished();
|
2015-04-16 11:50:07 -05:00
|
|
|
void portGroupDataChanged(int portGroupId, int portId = 0xFFFF);
|
|
|
|
void portListAboutToBeChanged(quint32 portGroupId);
|
|
|
|
void portListChanged(quint32 portGroupId);
|
|
|
|
void statsChanged(quint32 portGroupId);
|
2016-11-24 10:14:38 -06:00
|
|
|
void streamStatsReceived(quint32 portGroupId,
|
|
|
|
const OstProto::StreamStatsList *stats);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void on_reconnectTimer_timeout();
|
|
|
|
void on_rpcChannel_stateChanged(QAbstractSocket::SocketState state);
|
|
|
|
void on_rpcChannel_connected();
|
|
|
|
void on_rpcChannel_disconnected();
|
|
|
|
void on_rpcChannel_error(QAbstractSocket::SocketError socketError);
|
|
|
|
|
2015-04-24 10:23:00 -05:00
|
|
|
void on_rpcChannel_notification(int notifType,
|
|
|
|
::google::protobuf::Message *notification);
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
void when_portListChanged(quint32 portGroupId);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void when_configApply(int portIndex);
|
2016-03-12 07:26:35 -06:00
|
|
|
void getDeviceInfo(int portIndex);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|