KNemo – network interfaces monitor for systray
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

101 lines
3.3 KiB

  1. /* This file is part of KNemo
  2. Copyright (C) 2004, 2006 Percy Leonhardt <percy@eris23.de>
  3. KNemo is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU Library General Public License as
  5. published by the Free Software Foundation; either version 2 of
  6. the License, or (at your option) any later version.
  7. KNemo is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this library; see the file COPYING.LIB. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. Boston, MA 02110-1301, USA.
  15. */
  16. #include <kdebug.h>
  17. #include "interface.h"
  18. #include "interfacemonitor.h"
  19. InterfaceMonitor::InterfaceMonitor( TQObject* parent, const char* name )
  20. : TQObject( parent, name )
  21. {
  22. }
  23. InterfaceMonitor::~InterfaceMonitor()
  24. {
  25. }
  26. void InterfaceMonitor::checktqStatus( Interface* interface )
  27. {
  28. int currentState;
  29. int previousState = interface->getState();
  30. InterfaceData& data = interface->getData();
  31. int trafficThreshold = interface->getSettings().trafficThreshold;
  32. if ( !data.existing )
  33. // the interface does not exist
  34. currentState = Interface::NOT_EXISTING;
  35. else if ( !data.available )
  36. // the interface exists but is not connected
  37. currentState = Interface::NOT_AVAILABLE;
  38. else
  39. {
  40. // the interface is connected, look for traffic
  41. currentState = Interface::AVAILABLE;
  42. if ( ( data.rxPackets - data.prevRxPackets ) > (unsigned int) trafficThreshold )
  43. currentState |= Interface::RX_TRAFFIC;
  44. if ( ( data.txPackets - data.prevTxPackets ) > (unsigned int) trafficThreshold )
  45. currentState |= Interface::TX_TRAFFIC;
  46. }
  47. // update the statistics
  48. if ( data.incomingBytes > 0 )
  49. {
  50. emit incomingData( data.incomingBytes );
  51. }
  52. if ( data.outgoingBytes > 0 )
  53. {
  54. emit outgoingData( data.outgoingBytes );
  55. }
  56. data.prevRxPackets = data.rxPackets;
  57. data.prevTxPackets = data.txPackets;
  58. if ( ( previousState == Interface::NOT_EXISTING ||
  59. previousState == Interface::NOT_AVAILABLE ||
  60. previousState == Interface::UNKNOWN_STATE ) &&
  61. currentState & Interface::AVAILABLE )
  62. {
  63. emit available( previousState );
  64. }
  65. else if ( ( previousState == Interface::NOT_EXISTING ||
  66. previousState & Interface::AVAILABLE ||
  67. previousState == Interface::UNKNOWN_STATE ) &&
  68. currentState == Interface::NOT_AVAILABLE )
  69. {
  70. emit notAvailable( previousState );
  71. }
  72. else if ( ( previousState == Interface::NOT_AVAILABLE ||
  73. previousState & Interface::AVAILABLE ||
  74. previousState == Interface::UNKNOWN_STATE ) &&
  75. currentState == Interface::NOT_EXISTING )
  76. {
  77. emit notExisting( previousState );
  78. }
  79. // make sure the icon fits the current state
  80. if ( previousState != currentState )
  81. {
  82. emit statusChanged( currentState );
  83. interface->setState( currentState );
  84. }
  85. }
  86. #include "interfacemonitor.moc"