"Fossies" - the Fresh Open Source Software Archive

Member "xosview-1.23/bsd/swapmeter.cc" (11 Jul 2020, 1572 Bytes) of package /linux/misc/xosview-1.23.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "swapmeter.cc" see the Fossies "Dox" file reference documentation.

    1 //
    2 //  Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov )
    3 //
    4 //  NetBSD port:
    5 //  Copyright (c) 1995, 1996, 1997-2002 by Brian Grayson (bgrayson@netbsd.org)
    6 //
    7 //  This file was written by Brian Grayson for the NetBSD and xosview
    8 //    projects.
    9 //  This file may be distributed under terms of the GPL or of the BSD
   10 //    license, whichever you choose.  The full license notices are
   11 //    contained in the files COPYING.GPL and COPYING.BSD, which you
   12 //    should have received.  If not, contact one of the xosview
   13 //    authors for a copy.
   14 //
   15 
   16 #include "swapmeter.h"
   17 #include "kernel.h"
   18 #include <stdlib.h>
   19 
   20 
   21 SwapMeter::SwapMeter( XOSView *parent )
   22     : FieldMeterGraph( parent, 2, "SWAP", "USED/FREE" ) {
   23     BSDSwapInit();
   24 }
   25 
   26 SwapMeter::~SwapMeter( void ) {
   27 }
   28 
   29 void SwapMeter::checkResources( void ) {
   30     FieldMeterGraph::checkResources();
   31 
   32     setfieldcolor( 0, parent_->getResource("swapUsedColor") );
   33     setfieldcolor( 1, parent_->getResource("swapFreeColor") );
   34     priority_ = atoi( parent_->getResource("swapPriority") );
   35     dodecay_ = parent_->isResourceTrue("swapDecay");
   36     useGraph_ = parent_->isResourceTrue("swapGraph");
   37     SetUsedFormat( parent_->getResource("swapUsedFormat") );
   38 }
   39 
   40 void SwapMeter::checkevent( void ) {
   41     getswapinfo();
   42     drawfields();
   43 }
   44 
   45 void SwapMeter::getswapinfo( void ) {
   46     uint64_t total = 0, used = 0;
   47 
   48     BSDGetSwapInfo(&total, &used);
   49 
   50     total_ = (double)total;
   51     if ( total_ == 0.0 )
   52         total_ = 1.0;  /* We don't want any division by zero, now, do we?  :) */
   53     fields_[0] = (double)used;
   54     fields_[1] = total_;
   55 
   56     setUsed(fields_[0], total_);
   57 }