added mechanism to allow services to document the names of their items, and improved bandwidth graph to show names for GXS services. Other services still need to supply their own names

This commit is contained in:
csoler 2017-04-20 20:54:51 +02:00
parent f406b81238
commit 5f8bf03dfe
15 changed files with 280 additions and 81 deletions

View file

@ -328,6 +328,23 @@ RsGxsNetService::RsGxsNetService(uint16_t servType, RsGeneralDataService *gds,
mUpdateCounter = 0; mUpdateCounter = 0;
} }
void RsGxsNetService::getItemNames(std::map<uint8_t,std::string>& names) const
{
names.clear();
names[RS_PKT_SUBTYPE_NXS_SYNC_GRP_REQ_ITEM ] = "Group Sync Request" ;
names[RS_PKT_SUBTYPE_NXS_SYNC_GRP_ITEM ] = "Group Sync" ;
names[RS_PKT_SUBTYPE_NXS_SYNC_GRP_STATS_ITEM ] = "Group Stats" ;
names[RS_PKT_SUBTYPE_NXS_GRP_ITEM ] = "Group Data" ;
names[RS_PKT_SUBTYPE_NXS_ENCRYPTED_DATA_ITEM ] = "Encrypted data" ;
names[RS_PKT_SUBTYPE_NXS_SESSION_KEY_ITEM ] = "Session Key" ;
names[RS_PKT_SUBTYPE_NXS_SYNC_MSG_ITEM ] = "Message Sync" ;
names[RS_PKT_SUBTYPE_NXS_SYNC_MSG_REQ_ITEM ] = "Message Sync Request" ;
names[RS_PKT_SUBTYPE_NXS_MSG_ITEM ] = "Message Data" ;
names[RS_PKT_SUBTYPE_NXS_TRANSAC_ITEM ] = "Transaction" ;
names[RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY_ITEM ] = "Publish key" ;
}
RsGxsNetService::~RsGxsNetService() RsGxsNetService::~RsGxsNetService()
{ {
RS_STACK_MUTEX(mNxsMutex) ; RS_STACK_MUTEX(mNxsMutex) ;

View file

@ -99,6 +99,7 @@ public:
virtual RsServiceInfo getServiceInfo() { return mServiceInfo; } virtual RsServiceInfo getServiceInfo() { return mServiceInfo; }
virtual void getItemNames(std::map<uint8_t,std::string>& names) const ;
public: public:

View file

@ -29,7 +29,9 @@
#include "serialiser/rsserviceids.h" #include "serialiser/rsserviceids.h"
#include "serialiser/rsserial.h" #include "serialiser/rsserial.h"
#include "serialiser/rsbaseserial.h" #include "serialiser/rsbaseserial.h"
#include "serialiser/rsnxsitems.h"
#include "pqi/p3cfgmgr.h" #include "pqi/p3cfgmgr.h"
#include "pqi/pqiservice.h"
/*******************************/ /*******************************/
// #define SERVICECONTROL_DEBUG 1 // #define SERVICECONTROL_DEBUG 1
@ -138,7 +140,7 @@ public:
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
return NULL ; return NULL ;
} }
/* add mandatory parts first */ /* add mandatory parts first */
ok &= getRawUInt32(data, rssize, &offset, &item->mServiceId); ok &= getRawUInt32(data, rssize, &offset, &item->mServiceId);
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->mServiceName); ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->mServiceName);
@ -248,6 +250,13 @@ const RsPeerId& p3ServiceControl::getOwnId()
return mOwnPeerId; return mOwnPeerId;
} }
bool p3ServiceControl::getServiceItemNames(uint32_t serviceId,std::map<uint8_t,std::string>& names)
{
if(mServiceServer != NULL)
return mServiceServer->getServiceItemNames(serviceId,names) ;
return false ;
}
/* Interface for Services */ /* Interface for Services */
bool p3ServiceControl::registerService(const RsServiceInfo &info, bool defaultOn) bool p3ServiceControl::registerService(const RsServiceInfo &info, bool defaultOn)
@ -537,7 +546,7 @@ bool p3ServiceControl::updateServicePermissions(uint32_t serviceId, const RsServ
{ {
for(pit = onlinePeers.begin(); pit != onlinePeers.end(); ++pit) for(pit = onlinePeers.begin(); pit != onlinePeers.end(); ++pit)
{ {
if (it->second.peerHasPermission(*pit) != if (it->second.peerHasPermission(*pit) !=
permissions.peerHasPermission(*pit)) permissions.peerHasPermission(*pit))
{ {
mUpdatedSet.insert(*pit); mUpdatedSet.insert(*pit);
@ -597,7 +606,7 @@ bool p3ServiceControl::checkFilter(uint32_t serviceId, const RsPeerId &peerId)
#endif #endif
// must allow ServiceInfo through, or we have nothing! // must allow ServiceInfo through, or we have nothing!
#define FULLID_SERVICEINFO ((((uint32_t) RS_PKT_VERSION_SERVICE) << 24) + ((RS_SERVICE_TYPE_SERVICEINFO) << 8)) #define FULLID_SERVICEINFO ((((uint32_t) RS_PKT_VERSION_SERVICE) << 24) + ((RS_SERVICE_TYPE_SERVICEINFO) << 8))
//if (serviceId == RS_SERVICE_TYPE_SERVICEINFO) //if (serviceId == RS_SERVICE_TYPE_SERVICEINFO)
if (serviceId == FULLID_SERVICEINFO) if (serviceId == FULLID_SERVICEINFO)
@ -691,21 +700,21 @@ bool ServiceInfoCompatible(const RsServiceInfo &info1, const RsServiceInfo &info
} }
// ensure that info1 meets minimum requirements for info2 // ensure that info1 meets minimum requirements for info2
if (!versionOkay(info1.mVersionMajor, info1.mVersionMinor, if (!versionOkay(info1.mVersionMajor, info1.mVersionMinor,
info2.mMinVersionMajor, info2.mMinVersionMinor)) info2.mMinVersionMajor, info2.mMinVersionMinor))
{ {
return false; return false;
} }
// ensure that info2 meets minimum requirements for info1 // ensure that info2 meets minimum requirements for info1
if (!versionOkay(info2.mVersionMajor, info2.mVersionMinor, if (!versionOkay(info2.mVersionMajor, info2.mVersionMinor,
info1.mMinVersionMajor, info1.mMinVersionMinor)) info1.mMinVersionMajor, info1.mMinVersionMinor))
{ {
return false; return false;
} }
return true; return true;
} }
bool p3ServiceControl::updateFilterByPeer(const RsPeerId &peerId) bool p3ServiceControl::updateFilterByPeer(const RsPeerId &peerId)
{ {
@ -790,8 +799,8 @@ bool p3ServiceControl::updateFilterByPeer_locked(const RsPeerId &peerId)
std::cerr << "p3ServiceControl::updateFilterByPeer_locked() Empty ... Clearing"; std::cerr << "p3ServiceControl::updateFilterByPeer_locked() Empty ... Clearing";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
// empty, remove... // empty, remove...
recordFilterChanges_locked(peerId, originalFilter, peerFilter); recordFilterChanges_locked(peerId, originalFilter, peerFilter);
if (fit != mPeerFilterMap.end()) if (fit != mPeerFilterMap.end())
{ {
@ -882,7 +891,7 @@ bool p3ServiceControl::updateFilterByPeer_locked(const RsPeerId &peerId)
std::cerr << "p3ServiceControl::updateFilterByPeer_locked() Empty(2) ... Clearing"; std::cerr << "p3ServiceControl::updateFilterByPeer_locked() Empty(2) ... Clearing";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
if (fit != mPeerFilterMap.end()) if (fit != mPeerFilterMap.end())
{ {
mPeerFilterMap.erase(fit); mPeerFilterMap.erase(fit);
@ -900,7 +909,7 @@ bool p3ServiceControl::updateFilterByPeer_locked(const RsPeerId &peerId)
return true; return true;
} }
void p3ServiceControl::recordFilterChanges_locked(const RsPeerId &peerId, void p3ServiceControl::recordFilterChanges_locked(const RsPeerId &peerId,
ServicePeerFilter &originalFilter, ServicePeerFilter &updatedFilter) ServicePeerFilter &originalFilter, ServicePeerFilter &updatedFilter)
{ {
#ifdef SERVICECONTROL_DEBUG #ifdef SERVICECONTROL_DEBUG
@ -1202,7 +1211,7 @@ bool p3ServiceControl::loadList(std::list<RsItem *>& loadList)
if(item != NULL) if(item != NULL)
mServicePermissionMap[item->mServiceId] = *item ; mServicePermissionMap[item->mServiceId] = *item ;
delete *it ; delete *it ;
} }
@ -1396,49 +1405,49 @@ void p3ServiceControl::notifyServices()
std::cerr << "p3ServiceControl::notifyServices(): Noone Monitoring ... skipping"; std::cerr << "p3ServiceControl::notifyServices(): Noone Monitoring ... skipping";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
continue; continue;
} }
std::list<pqiServicePeer> peers; std::list<pqiServicePeer> peers;
std::set<RsPeerId>::const_iterator pit; std::set<RsPeerId>::const_iterator pit;
for(pit = it->second.mAdded.begin(); for(pit = it->second.mAdded.begin();
pit != it->second.mAdded.end(); ++pit) pit != it->second.mAdded.end(); ++pit)
{ {
pqiServicePeer peer; pqiServicePeer peer;
peer.id = *pit; peer.id = *pit;
peer.actions = RS_SERVICE_PEER_CONNECTED; peer.actions = RS_SERVICE_PEER_CONNECTED;
peers.push_back(peer); peers.push_back(peer);
#ifdef SERVICECONTROL_DEBUG #ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::notifyServices(): Peer: " << *pit << " CONNECTED"; std::cerr << "p3ServiceControl::notifyServices(): Peer: " << *pit << " CONNECTED";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
} }
for(pit = it->second.mRemoved.begin(); for(pit = it->second.mRemoved.begin();
pit != it->second.mRemoved.end(); ++pit) pit != it->second.mRemoved.end(); ++pit)
{ {
pqiServicePeer peer; pqiServicePeer peer;
peer.id = *pit; peer.id = *pit;
peer.actions = RS_SERVICE_PEER_DISCONNECTED; peer.actions = RS_SERVICE_PEER_DISCONNECTED;
peers.push_back(peer); peers.push_back(peer);
#ifdef SERVICECONTROL_DEBUG #ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::notifyServices(): Peer: " << *pit << " DISCONNECTED"; std::cerr << "p3ServiceControl::notifyServices(): Peer: " << *pit << " DISCONNECTED";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
} }
for(; sit != eit; ++sit) for(; sit != eit; ++sit)
{ {
#ifdef SERVICECONTROL_DEBUG #ifdef SERVICECONTROL_DEBUG
std::cerr << "p3ServiceControl::notifyServices(): Sending to Monitoring Service"; std::cerr << "p3ServiceControl::notifyServices(): Sending to Monitoring Service";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
sit->second->statusChange(peers); sit->second->statusChange(peers);
} }
} }
@ -1500,17 +1509,17 @@ void RsServicePermissions::resetPermission(const RsPeerId& peerId)
} }
RsServiceInfo::RsServiceInfo( RsServiceInfo::RsServiceInfo(
const uint16_t service_type, const uint16_t service_type,
const std::string service_name, const std::string service_name,
const uint16_t version_major, const uint16_t version_major,
const uint16_t version_minor, const uint16_t version_minor,
const uint16_t min_version_major, const uint16_t min_version_major,
const uint16_t min_version_minor) const uint16_t min_version_minor)
:mServiceName(service_name), :mServiceName(service_name),
mServiceType((((uint32_t) RS_PKT_VERSION_SERVICE) << 24) + (((uint32_t) service_type) << 8)), mServiceType((((uint32_t) RS_PKT_VERSION_SERVICE) << 24) + (((uint32_t) service_type) << 8)),
mVersionMajor(version_major), mVersionMajor(version_major),
mVersionMinor(version_minor), mVersionMinor(version_minor),
mMinVersionMajor(min_version_major), mMinVersionMajor(min_version_major),
mMinVersionMinor(min_version_minor) mMinVersionMinor(min_version_minor)
{ {
return; return;
@ -1518,7 +1527,7 @@ RsServiceInfo::RsServiceInfo(
RsServiceInfo::RsServiceInfo() RsServiceInfo::RsServiceInfo()
:mServiceName("unknown"), :mServiceName("unknown"),
mServiceType(0), mServiceType(0),
mVersionMajor(0), mVersionMajor(0),
mVersionMinor(0), mVersionMinor(0),

View file

@ -36,6 +36,8 @@
#include "pqi/pqiservicemonitor.h" #include "pqi/pqiservicemonitor.h"
#include "pqi/p3linkmgr.h" #include "pqi/p3linkmgr.h"
class p3ServiceServer ;
class ServiceNotifications class ServiceNotifications
{ {
public: public:
@ -101,6 +103,9 @@ virtual bool updateServicePermissions(uint32_t serviceId, const RsServicePermiss
virtual void getPeersConnected(const uint32_t serviceId, std::set<RsPeerId> &peerSet); virtual void getPeersConnected(const uint32_t serviceId, std::set<RsPeerId> &peerSet);
virtual bool isPeerConnected(const uint32_t serviceId, const RsPeerId &peerId); virtual bool isPeerConnected(const uint32_t serviceId, const RsPeerId &peerId);
// Gets the list of items used by that service
virtual bool getServiceItemNames(uint32_t serviceId,std::map<uint8_t,std::string>& names) ;
/** /**
* Registration for all Services. * Registration for all Services.
*/ */
@ -132,6 +137,8 @@ virtual bool updateServicesProvided(const RsPeerId &peerId, const RsPeerServiceI
// pqiMonitor. // pqiMonitor.
virtual void statusChange(const std::list<pqipeer> &plist); virtual void statusChange(const std::list<pqipeer> &plist);
virtual void setServiceServer(p3ServiceServer *p) { mServiceServer = p ; }
protected: protected:
// configuration. // configuration.
virtual bool saveList(bool &cleanup, std::list<RsItem *>&); virtual bool saveList(bool &cleanup, std::list<RsItem *>&);
@ -196,6 +203,7 @@ bool peerHasPermissionForService_locked(const RsPeerId &peerId, uint32_t service
// Below here is saved in Configuration. // Below here is saved in Configuration.
std::map<uint32_t, RsServicePermissions> mServicePermissionMap; std::map<uint32_t, RsServicePermissions> mServicePermissionMap;
p3ServiceServer *mServiceServer ;
}; };

View file

@ -79,11 +79,26 @@ int p3ServiceServer::addService(pqiService *ts, bool defaultOn)
services[info.mServiceType] = ts; services[info.mServiceType] = ts;
// This doesn't need to be in Mutex. // This doesn't need to be in Mutex.
mServiceControl->registerService(info, defaultOn); mServiceControl->registerService(info,defaultOn);
return 1; return 1;
} }
bool p3ServiceServer::getServiceItemNames(uint32_t service_type,std::map<uint8_t,std::string>& names)
{
RsStackMutex stack(srvMtx); /********* LOCKED *********/
std::map<uint32_t, pqiService *>::iterator it=services.find(service_type) ;
if(it != services.end())
{
it->second->getItemNames(names) ;
return true ;
}
else
return false ;
}
int p3ServiceServer::removeService(pqiService *ts) int p3ServiceServer::removeService(pqiService *ts)
{ {
RsStackMutex stack(srvMtx); /********* LOCKED *********/ RsStackMutex stack(srvMtx); /********* LOCKED *********/

View file

@ -60,24 +60,26 @@ class p3ServiceServerIface;
class pqiService class pqiService
{ {
protected: protected:
pqiService() // our type of packets. pqiService() // our type of packets.
:mServiceServer(NULL) { return; } :mServiceServer(NULL) { return; }
virtual ~pqiService() { return; } virtual ~pqiService() { return; }
public: public:
void setServiceServer(p3ServiceServerIface *server); void setServiceServer(p3ServiceServerIface *server);
// //
virtual bool recv(RsRawItem *) = 0; virtual bool recv(RsRawItem *) = 0;
virtual bool send(RsRawItem *item); virtual bool send(RsRawItem *item);
virtual RsServiceInfo getServiceInfo() = 0; virtual RsServiceInfo getServiceInfo() = 0;
virtual int tick() { return 0; } virtual int tick() { return 0; }
private: virtual void getItemNames(std::map<uint8_t,std::string>& names) const {} // This does nothing by default. Service should derive it in order to give info for the UI
private:
p3ServiceServerIface *mServiceServer; // const, no need for mutex. p3ServiceServerIface *mServiceServer; // const, no need for mutex.
}; };
@ -97,10 +99,10 @@ public:
virtual ~p3ServiceServerIface() {} virtual ~p3ServiceServerIface() {}
virtual bool recvItem(RsRawItem *) = 0; virtual bool recvItem(RsRawItem *) = 0;
virtual bool sendItem(RsRawItem *) = 0; virtual bool sendItem(RsRawItem *) = 0;
virtual bool getServiceItemNames(uint32_t service_type,std::map<uint8_t,std::string>& names) =0;
}; };
class p3ServiceServer : public p3ServiceServerIface class p3ServiceServer : public p3ServiceServerIface
@ -108,13 +110,15 @@ class p3ServiceServer : public p3ServiceServerIface
public: public:
p3ServiceServer(pqiPublisher *pub, p3ServiceControl *ctrl); p3ServiceServer(pqiPublisher *pub, p3ServiceControl *ctrl);
int addService(pqiService *, bool defaultOn); int addService(pqiService *, bool defaultOn);
int removeService(pqiService *); int removeService(pqiService *);
bool recvItem(RsRawItem *); bool recvItem(RsRawItem *);
bool sendItem(RsRawItem *); bool sendItem(RsRawItem *);
int tick(); bool getServiceItemNames(uint32_t service_type, std::map<uint8_t,std::string>& names) ;
int tick();
public: public:
private: private:
@ -122,7 +126,7 @@ private:
pqiPublisher *mPublisher; // constant no need for mutex. pqiPublisher *mPublisher; // constant no need for mutex.
p3ServiceControl *mServiceControl; p3ServiceControl *mServiceControl;
RsMutex srvMtx; RsMutex srvMtx;
std::map<uint32_t, pqiService *> services; std::map<uint32_t, pqiService *> services;
}; };

View file

@ -109,6 +109,7 @@ virtual ~RsServiceControl() { return; }
virtual bool getOwnServices(RsPeerServiceInfo &info) = 0; virtual bool getOwnServices(RsPeerServiceInfo &info) = 0;
virtual std::string getServiceName(uint32_t service_id) = 0; virtual std::string getServiceName(uint32_t service_id) = 0;
virtual bool getServiceItemNames(uint32_t service_id,std::map<uint8_t,std::string>& names) = 0;
virtual bool getServicesAllowed(const RsPeerId &peerId, RsPeerServiceInfo &info) = 0; virtual bool getServicesAllowed(const RsPeerId &peerId, RsPeerServiceInfo &info) = 0;
virtual bool getServicesProvided(const RsPeerId &peerId, RsPeerServiceInfo &info) = 0; virtual bool getServicesProvided(const RsPeerId &peerId, RsPeerServiceInfo &info) = 0;

View file

@ -1243,6 +1243,8 @@ int RsServer::StartupRetroShare()
pqih = new pqisslpersongrp(serviceCtrl, flags, mPeerMgr); pqih = new pqisslpersongrp(serviceCtrl, flags, mPeerMgr);
//pqih = new pqipersongrpDummy(none, flags); //pqih = new pqipersongrpDummy(none, flags);
serviceCtrl->setServiceServer(pqih) ;
/****** New Ft Server **** !!! */ /****** New Ft Server **** !!! */
ftServer *ftserver = new ftServer(mPeerMgr, serviceCtrl); ftServer *ftserver = new ftServer(mPeerMgr, serviceCtrl);
ftserver->setConfigDirectory(rsAccounts->PathAccountDirectory()); ftserver->setConfigDirectory(rsAccounts->PathAccountDirectory());

View file

@ -99,6 +99,11 @@ QString RSGraphSource::displayValue(float v) const
return QString::number(v,'f',_digits) + " " + unitName() ; return QString::number(v,'f',_digits) + " " + unitName() ;
} }
void RSGraphSource::getCumulatedValues(std::vector<float>& vals) const
{
for(std::map<std::string,float>::const_iterator it = _totals.begin();it!=_totals.end();++it)
vals.push_back(it->second) ;
}
void RSGraphSource::getCurrentValues(std::vector<QPointF>& vals) const void RSGraphSource::getCurrentValues(std::vector<QPointF>& vals) const
{ {
std::map<std::string,std::list<std::pair<qint64,float> > >::const_iterator it = _points.begin(); std::map<std::string,std::list<std::pair<qint64,float> > >::const_iterator it = _points.begin();
@ -108,9 +113,9 @@ void RSGraphSource::getCurrentValues(std::vector<QPointF>& vals) const
vals.push_back(QPointF( (now - it->second.back().first)/1000.0f,it->second.back().second)) ; vals.push_back(QPointF( (now - it->second.back().first)/1000.0f,it->second.back().second)) ;
} }
QString RSGraphSource::legend(int i,float v) const QString RSGraphSource::legend(int i,float v,bool show_value) const
{ {
return displayName(i) + " (" + displayValue(v) + " )"; return displayName(i) + (show_value?(" (" + displayValue(v) + ")"):"");
} }
void RSGraphSource::getDataPoints(int index,std::vector<QPointF>& pts,float filter_factor) const void RSGraphSource::getDataPoints(int index,std::vector<QPointF>& pts,float filter_factor) const
@ -209,11 +214,30 @@ void RSGraphSource::update()
} }
else else
++it ; ++it ;
updateTotals();
}
void RSGraphSource::updateTotals()
{
// now compute totals
_totals.clear();
for(std::map<std::string,std::list<std::pair<qint64,float> > >::const_iterator it(_points.begin());it!=_points.end();++it)
{
float& f = _totals[it->first] ;
f = 0.0f ;
for(std::list<std::pair<qint64,float> >::const_iterator it2=it->second.begin();it2!=it->second.end();++it2)
f += (*it2).second ;
}
} }
void RSGraphSource::reset() void RSGraphSource::reset()
{ {
_points.clear() ; _points.clear();
_totals.clear();
} }
void RSGraphSource::setCollectionTimeLimit(qint64 s) { _time_limit_msecs = s ; } void RSGraphSource::setCollectionTimeLimit(qint64 s) { _time_limit_msecs = s ; }
@ -630,8 +654,19 @@ void RSGraphWidget::paintLegend()
{ {
//int bottom = _rec.height(); //int bottom = _rec.height();
std::vector<QPointF> vals ; std::vector<float> vals ;
_source->getCurrentValues(vals) ;
if(_flags & RSGRAPH_FLAGS_LEGEND_CUMULATED)
_source->getCumulatedValues(vals) ;
else
{
std::vector<QPointF> cvals ;
_source->getCurrentValues(cvals) ;
for(uint32_t i=0;i<cvals.size();++i)
vals.push_back(cvals[i].y()) ;
}
int j=0; int j=0;
float FS = QFontMetricsF(font()).height(); float FS = QFontMetricsF(font()).height();
@ -640,12 +675,13 @@ void RSGraphWidget::paintLegend()
for(uint i=0;i<vals.size();++i) for(uint i=0;i<vals.size();++i)
if( _masked_entries.find(_source->displayName(i).toStdString()) == _masked_entries.end() ) if( _masked_entries.find(_source->displayName(i).toStdString()) == _masked_entries.end() )
{ {
if( _rec.width() - (vals[i].x()-0)*_time_scale < SCALE_WIDTH*fact ) // if( _rec.width() - (vals[i].x()-0)*_time_scale < SCALE_WIDTH*fact )
continue ; // continue ;
qreal paintStep = 4*fact+FS; qreal paintStep = 4*fact+FS;
qreal pos = 15*fact+j*paintStep; qreal pos = 15*fact+j*paintStep;
QString text = _source->legend(i,vals[i].y()) ;
QString text = _source->legend(i,vals[i]) ;
QPen oldPen = _painter->pen(); QPen oldPen = _painter->pen();
_painter->setPen(QPen(getColor(i), Qt::SolidLine)); _painter->setPen(QPen(getColor(i), Qt::SolidLine));

View file

@ -69,8 +69,11 @@ public:
// return the vector of last values up to date // return the vector of last values up to date
virtual void getCurrentValues(std::vector<QPointF>& vals) const ; virtual void getCurrentValues(std::vector<QPointF>& vals) const ;
// return the vector of cumulated values up to date
virtual void getCumulatedValues(std::vector<float>& vals) const;
// returns what to display in the legend. Derive this to show additional info. // returns what to display in the legend. Derive this to show additional info.
virtual QString legend(int i,float v) const ; virtual QString legend(int i, float v, bool show_value=true) const ;
// Returns the n^th interpolated value at the given time in floating point seconds backward. // Returns the n^th interpolated value at the given time in floating point seconds backward.
virtual void getDataPoints(int index, std::vector<QPointF>& pts, float filter_factor=0.0f) const ; virtual void getDataPoints(int index, std::vector<QPointF>& pts, float filter_factor=0.0f) const ;
@ -95,11 +98,13 @@ protected slots:
protected: protected:
virtual void getValues(std::map<std::string,float>& values) const = 0 ;// overload this in your own class to fill in the values you want to display. virtual void getValues(std::map<std::string,float>& values) const = 0 ;// overload this in your own class to fill in the values you want to display.
void updateTotals();
qint64 getTime() const ; // returns time in ms since RS has started qint64 getTime() const ; // returns time in ms since RS has started
// Storage of collected events. The string is any string used to represent the collected data. // Storage of collected events. The string is any string used to represent the collected data.
std::map<std::string, std::list<std::pair<qint64,float> > > _points ; std::map<std::string, std::list<std::pair<qint64,float> > > _points ;
std::map<std::string, float> _totals ;
QTimer *_timer ; QTimer *_timer ;
@ -118,8 +123,9 @@ public:
static const uint32_t RSGRAPH_FLAGS_LOG_SCALE_Y = 0x0002 ;// log scale in Y static const uint32_t RSGRAPH_FLAGS_LOG_SCALE_Y = 0x0002 ;// log scale in Y
static const uint32_t RSGRAPH_FLAGS_ALWAYS_COLLECT = 0x0004 ;// keep collecting while not displayed static const uint32_t RSGRAPH_FLAGS_ALWAYS_COLLECT = 0x0004 ;// keep collecting while not displayed
static const uint32_t RSGRAPH_FLAGS_PAINT_STYLE_PLAIN = 0x0008 ;// use plain / line drawing style static const uint32_t RSGRAPH_FLAGS_PAINT_STYLE_PLAIN = 0x0008 ;// use plain / line drawing style
static const uint32_t RSGRAPH_FLAGS_SHOW_LEGEND = 0x0010 ;// show legend in the graph static const uint32_t RSGRAPH_FLAGS_SHOW_LEGEND = 0x0010 ;// show legend in the graph
static const uint32_t RSGRAPH_FLAGS_PAINT_STYLE_FLAT = 0x0020 ;// do not interpolate, and draw flat colored boxes static const uint32_t RSGRAPH_FLAGS_PAINT_STYLE_FLAT = 0x0020 ;// do not interpolate, and draw flat colored boxes
static const uint32_t RSGRAPH_FLAGS_LEGEND_CUMULATED = 0x0040 ;// show the total in the legend rather than current values
/** Bandwidth graph style. */ /** Bandwidth graph style. */
enum GraphStyle enum GraphStyle

View file

@ -107,16 +107,25 @@ void BWGraphSource::update()
// remove empty lists // remove empty lists
float duration = 0.0f;
for(std::map<std::string,std::list<std::pair<qint64,float> > >::iterator it=_points.begin();it!=_points.end();) for(std::map<std::string,std::list<std::pair<qint64,float> > >::iterator it=_points.begin();it!=_points.end();)
if(it->second.empty()) if(it->second.empty())
{ {
std::map<std::string,std::list<std::pair<qint64,float> > >::iterator tmp(it) ; std::map<std::string,std::list<std::pair<qint64,float> > >::iterator tmp(it) ;
++tmp; ++tmp;
_points.erase(it) ; _points.erase(it) ;
it=tmp ; it=tmp ;
} }
else else
{
float d = it->second.back().first - it->second.front().first;
if(duration < d)
duration = d ;
++it ; ++it ;
}
// also clears history // also clears history
@ -138,11 +147,36 @@ void BWGraphSource::update()
break ; break ;
} }
// now update the totals, and possibly convert into an average if the unit requires it.
updateTotals();
if(_current_unit == UNIT_KILOBYTES)
for(std::map<std::string,float>::iterator it(_totals.begin());it!=_totals.end();++it)
it->second /= (duration/1000.0) ;
#ifdef BWGRAPH_DEBUG #ifdef BWGRAPH_DEBUG
std::cerr << "Traffic history has size " << mTrafficHistory.size() << std::endl; std::cerr << "Traffic history has size " << mTrafficHistory.size() << std::endl;
#endif #endif
} }
std::string BWGraphSource::makeSubItemName(uint16_t service_id,uint8_t sub_item_type) const
{
RsServiceInfoWithNames& s(mServiceInfoMap[service_id]) ;
if(s.item_names.empty())
return "item #"+QString("%1").arg(sub_item_type,2,16,QChar('0')).toStdString() ;
else
{
std::map<uint8_t,std::string>::const_iterator it = s.item_names.find(sub_item_type) ;
if(it == s.item_names.end())
return "item #"+QString("%1").arg(sub_item_type,2,16,QChar('0')).toStdString() + " (undocumented)";
return QString("%1").arg(sub_item_type,2,16,QChar('0')).toStdString()+": " + it->second ;
}
}
void BWGraphSource::convertTrafficClueToValues(const std::list<RSTrafficClue>& lst,std::map<std::string,float>& vals) const void BWGraphSource::convertTrafficClueToValues(const std::list<RSTrafficClue>& lst,std::map<std::string,float>& vals) const
{ {
vals.clear() ; vals.clear() ;
@ -162,7 +196,7 @@ void BWGraphSource::convertTrafficClueToValues(const std::list<RSTrafficClue>& l
for(uint32_t i=0;i<256;++i) for(uint32_t i=0;i<256;++i)
if(clue_per_sub_id[i].count > 0) if(clue_per_sub_id[i].count > 0)
vals["item #"+QString::number(i,16).toStdString()] = (_current_unit == UNIT_KILOBYTES)?(clue_per_sub_id[i].size):(clue_per_sub_id[i].count) ; vals[makeSubItemName(clue_per_sub_id[i].service_id,i)] = (_current_unit == UNIT_KILOBYTES)?(clue_per_sub_id[i].size):(clue_per_sub_id[i].count) ;
} }
break ; break ;
@ -233,11 +267,14 @@ void BWGraphSource::convertTrafficClueToValues(const std::list<RSTrafficClue>& l
for(std::list<RSTrafficClue>::const_iterator it(lst.begin());it!=lst.end();++it) for(std::list<RSTrafficClue>::const_iterator it(lst.begin());it!=lst.end();++it)
if(it->service_id == _current_selected_service) if(it->service_id == _current_selected_service)
{
clue_per_sub_id[it->service_sub_id] += *it ; clue_per_sub_id[it->service_sub_id] += *it ;
clue_per_sub_id[it->service_sub_id].service_id = it->service_id ;
}
for(uint32_t i=0;i<256;++i) for(uint32_t i=0;i<256;++i)
if(clue_per_sub_id[i].count > 0) if(clue_per_sub_id[i].count > 0)
vals["item #"+QString::number(i,16).toStdString()] = (_current_unit == UNIT_KILOBYTES)?(clue_per_sub_id[i].size):(clue_per_sub_id[i].count) ; vals[makeSubItemName(clue_per_sub_id[i].service_id,i)] = (_current_unit == UNIT_KILOBYTES)?(clue_per_sub_id[i].size):(clue_per_sub_id[i].count) ;
} }
break ; break ;
@ -297,7 +334,11 @@ BWGraphSource::BWGraphSource()
rsServiceControl->getOwnServices(rspsi) ; rsServiceControl->getOwnServices(rspsi) ;
for(std::map<uint32_t,RsServiceInfo>::const_iterator it(rspsi.mServiceList.begin());it!=rspsi.mServiceList.end();++it) for(std::map<uint32_t,RsServiceInfo>::const_iterator it(rspsi.mServiceList.begin());it!=rspsi.mServiceList.end();++it)
{
mServiceInfoMap[ (it->first >> 8) & 0xffff ] = it->second ; mServiceInfoMap[ (it->first >> 8) & 0xffff ] = it->second ;
rsServiceControl->getServiceItemNames(it->first,mServiceInfoMap[(it->first >> 8) & 0xffff].item_names) ;
}
} }
void BWGraphSource::getValues(std::map<std::string,float>& values) const void BWGraphSource::getValues(std::map<std::string,float>& values) const
@ -359,9 +400,9 @@ QString BWGraphSource::displayValue(float v) const
return QString() ; return QString() ;
} }
QString BWGraphSource::legend(int i,float v) const QString BWGraphSource::legend(int i,float v,bool show_value) const
{ {
return RSGraphSource::legend(i,v) ;//+ " Total: " + niceNumber(_total_recv) ; return RSGraphSource::legend(i,v,show_value) ;
} }
QString BWGraphSource::niceNumber(float v) const QString BWGraphSource::niceNumber(float v) const
{ {
@ -446,6 +487,7 @@ void BWGraphSource::setUnit(int unit)
recomputeCurrentCurves() ; recomputeCurrentCurves() ;
} }
void BWGraphSource::setDirection(int dir) void BWGraphSource::setDirection(int dir)
{ {
if(dir == _current_direction) if(dir == _current_direction)

View file

@ -13,6 +13,14 @@ public:
std::list<RSTrafficClue> out_rstcl ; std::list<RSTrafficClue> out_rstcl ;
std::list<RSTrafficClue> in_rstcl ; std::list<RSTrafficClue> in_rstcl ;
}; };
class RsServiceInfoWithNames: public RsServiceInfo
{
public:
RsServiceInfoWithNames(const RsServiceInfo& s) : RsServiceInfo(s) {}
RsServiceInfoWithNames(){}
std::map<uint8_t,std::string> item_names ;
};
BWGraphSource() ; BWGraphSource() ;
@ -25,7 +33,7 @@ public:
virtual void getValues(std::map<std::string,float>& values) const; virtual void getValues(std::map<std::string,float>& values) const;
virtual QString displayValue(float v) const; virtual QString displayValue(float v) const;
virtual QString legend(int i,float v) const; virtual QString legend(int i,float v,bool show_value=true) const;
virtual void update(); virtual void update();
QString unitName() const ; QString unitName() const ;
@ -45,6 +53,7 @@ public:
protected: protected:
void convertTrafficClueToValues(const std::list<RSTrafficClue> &lst, std::map<std::string, float> &vals) const; void convertTrafficClueToValues(const std::list<RSTrafficClue> &lst, std::map<std::string, float> &vals) const;
std::string makeSubItemName(uint16_t service_id,uint8_t sub_item_type) const;
void recomputeCurrentCurves() ; void recomputeCurrentCurves() ;
std::string visibleFriendName(const RsPeerId &pid) const ; std::string visibleFriendName(const RsPeerId &pid) const ;
@ -67,7 +76,7 @@ private:
std::map<RsPeerId,std::string> mVisibleFriends ; std::map<RsPeerId,std::string> mVisibleFriends ;
std::set<uint16_t> mVisibleServices ; std::set<uint16_t> mVisibleServices ;
mutable std::map<uint16_t,RsServiceInfo> mServiceInfoMap ; mutable std::map<uint16_t,RsServiceInfoWithNames> mServiceInfoMap ;
}; };
class BWGraph: public RSGraphWidget class BWGraph: public RSGraphWidget

View file

@ -28,13 +28,18 @@ BandwidthStatsWidget::BandwidthStatsWidget(QWidget *parent)
ui.bwgraph_BW->setSelector(BWGraphSource::SELECTOR_TYPE_SERVICE,BWGraphSource::GRAPH_TYPE_SUM) ; ui.bwgraph_BW->setSelector(BWGraphSource::SELECTOR_TYPE_SERVICE,BWGraphSource::GRAPH_TYPE_SUM) ;
ui.bwgraph_BW->setUnit(BWGraphSource::UNIT_KILOBYTES) ; ui.bwgraph_BW->setUnit(BWGraphSource::UNIT_KILOBYTES) ;
ui.bwgraph_BW->resetFlags(RSGraphWidget::RSGRAPH_FLAGS_LEGEND_CUMULATED) ;
updateUnitSelection(0);
// Setup connections // Setup connections
QObject::connect(ui.friend_CB ,SIGNAL(currentIndexChanged(int)),this, SLOT( updateFriendSelection(int))) ; QObject::connect(ui.friend_CB ,SIGNAL(currentIndexChanged(int )),this, SLOT( updateFriendSelection(int ))) ;
QObject::connect(ui.updn_CB ,SIGNAL(currentIndexChanged(int)),this, SLOT( updateUpDownSelection(int))) ; QObject::connect(ui.updn_CB ,SIGNAL(currentIndexChanged(int )),this, SLOT( updateUpDownSelection(int ))) ;
QObject::connect(ui.unit_CB ,SIGNAL(currentIndexChanged(int)),this, SLOT( updateUnitSelection(int))) ; QObject::connect(ui.unit_CB ,SIGNAL(currentIndexChanged(int )),this, SLOT( updateUnitSelection(int ))) ;
QObject::connect(ui.service_CB,SIGNAL(currentIndexChanged(int)),this, SLOT(updateServiceSelection(int))) ; QObject::connect(ui.service_CB ,SIGNAL(currentIndexChanged(int )),this, SLOT(updateServiceSelection(int ))) ;
QObject::connect(ui.logScale_CB,SIGNAL(toggled(bool)),this, SLOT(toggleLogScale(bool))) ; QObject::connect(ui.legend_CB ,SIGNAL(currentIndexChanged(int )),this, SLOT( updateLegendType(int ))) ;
QObject::connect(ui.logScale_CB,SIGNAL( toggled(bool)),this, SLOT( toggleLogScale(bool))) ;
// setup one timer for auto-update // setup one timer for auto-update
@ -156,6 +161,13 @@ void BandwidthStatsWidget::updateFriendSelection(int n)
ui.bwgraph_BW->setSelector(BWGraphSource::SELECTOR_TYPE_FRIEND,BWGraphSource::GRAPH_TYPE_SINGLE,ui.friend_CB->itemData(ci,Qt::UserRole).toString().toStdString()) ; ui.bwgraph_BW->setSelector(BWGraphSource::SELECTOR_TYPE_FRIEND,BWGraphSource::GRAPH_TYPE_SINGLE,ui.friend_CB->itemData(ci,Qt::UserRole).toString().toStdString()) ;
} }
} }
void BandwidthStatsWidget::updateLegendType(int n)
{
if(n==0)
ui.bwgraph_BW->resetFlags(RSGraphWidget::RSGRAPH_FLAGS_LEGEND_CUMULATED) ;
else
ui.bwgraph_BW->setFlags(RSGraphWidget::RSGRAPH_FLAGS_LEGEND_CUMULATED) ;
}
void BandwidthStatsWidget::updateServiceSelection(int n) void BandwidthStatsWidget::updateServiceSelection(int n)
{ {
if(n == 0) if(n == 0)
@ -187,7 +199,13 @@ void BandwidthStatsWidget::updateUpDownSelection(int n)
void BandwidthStatsWidget::updateUnitSelection(int n) void BandwidthStatsWidget::updateUnitSelection(int n)
{ {
if(n==0) if(n==0)
{
ui.bwgraph_BW->setUnit(BWGraphSource::UNIT_KILOBYTES) ; ui.bwgraph_BW->setUnit(BWGraphSource::UNIT_KILOBYTES) ;
ui.legend_CB->setItemText(1,tr("Average"));
}
else else
{
ui.bwgraph_BW->setUnit(BWGraphSource::UNIT_COUNT) ; ui.bwgraph_BW->setUnit(BWGraphSource::UNIT_COUNT) ;
ui.legend_CB->setItemText(1,tr("Total"));
}
} }

View file

@ -15,7 +15,8 @@ protected slots:
void updateUpDownSelection(int n); void updateUpDownSelection(int n);
void updateUnitSelection(int n); void updateUnitSelection(int n);
void toggleLogScale(bool b); void toggleLogScale(bool b);
void updateLegendType(int n);
private: private:
Ui::BwStatsWidget ui; Ui::BwStatsWidget ui;

View file

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1128</width> <width>1148</width>
<height>385</height> <height>385</height>
</rect> </rect>
</property> </property>
@ -14,7 +14,16 @@
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="margin"> <property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
@ -103,6 +112,27 @@
<item> <item>
<widget class="QComboBox" name="unit_CB"/> <widget class="QComboBox" name="unit_CB"/>
</item> </item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Legend:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="legend_CB">
<item>
<property name="text">
<string>Current</string>
</property>
</item>
<item>
<property name="text">
<string>Total</string>
</property>
</item>
</widget>
</item>
<item> <item>
<widget class="QCheckBox" name="logScale_CB"> <widget class="QCheckBox" name="logScale_CB">
<property name="text"> <property name="text">