"Fossies" - the Fresh Open Source Software Archive

Member "xosview-1.23/gnu/swapmeter.cc" (11 Jul 2020, 1679 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 //  2007 by Samuel Thibault ( samuel.thibault@ens-lyon.org )
    4 //
    5 //  This file may be distributed under terms of the GPL
    6 //
    7 
    8 #include "swapmeter.h"
    9 #include "xosview.h"
   10 #include <fstream>
   11 #include <sstream>
   12 #include <stdlib.h>
   13 #include <error.h>
   14 
   15 extern "C" {
   16 #include <mach.h>
   17 #include <mach/mach_traps.h>
   18 #include <mach/default_pager.h>
   19 #include "get_def_pager.h"
   20 }
   21 
   22 SwapMeter::SwapMeter( XOSView *parent )
   23 : FieldMeterGraph( parent, 2, "SWAP", "ACTIVE/USED/FREE" ){
   24   def_pager = MACH_PORT_NULL;
   25 }
   26 
   27 SwapMeter::~SwapMeter( void ){
   28 }
   29 
   30 void SwapMeter::checkResources( void ){
   31   FieldMeterGraph::checkResources();
   32 
   33   setfieldcolor( 0, parent_->getResource( "swapUsedColor" ) );
   34   setfieldcolor( 1, parent_->getResource( "swapFreeColor" ) );
   35   priority_ = atoi (parent_->getResource( "swapPriority" ) );
   36   dodecay_ = parent_->isResourceTrue( "swapDecay" );
   37   useGraph_ = parent_->isResourceTrue( "swapGraph" );
   38   SetUsedFormat (parent_->getResource("swapUsedFormat"));
   39 }
   40 
   41 void SwapMeter::checkevent( void ){
   42   getswapinfo();
   43   drawfields();
   44 }
   45 
   46 
   47 void SwapMeter::getswapinfo( void ){
   48   kern_return_t err;
   49 
   50   if (def_pager == MACH_PORT_NULL)
   51     def_pager = get_def_pager();
   52 
   53   if (!MACH_PORT_VALID (def_pager)) {
   54     def_pager = MACH_PORT_DEAD;
   55     parent_->done(1);
   56     return;
   57   }
   58 
   59   err = default_pager_info (def_pager, &def_pager_info);
   60   if (err) {
   61     error (0, err, "default_pager_info");
   62     parent_->done(1);
   63     return;
   64   }
   65 
   66   total_ = def_pager_info.dpi_total_space;
   67   fields_[1] = def_pager_info.dpi_free_space;
   68   fields_[0] = total_ - fields_[1];
   69 
   70   if (total_)
   71     setUsed (fields_[0], total_);
   72 }