"Fossies" - the Fresh Open Source Software Archive

Member "procmeter3-3.6+svn387/modules/template.c" (24 Dec 2010, 3316 Bytes) of package /linux/misc/procmeter3-3.6+svn387.tgz:


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 "template.c" see the Fossies "Dox" file reference documentation.

    1 /***************************************
    2   $Header: /home/amb/CVS/procmeter3/modules/template.c,v 1.5 2002-12-07 19:41:00 amb Exp $
    3 
    4   ProcMeter - A system monitoring program for Linux - Version 3.4.
    5 
    6   Module template source file.
    7   ******************/ /******************
    8   Written by Andrew M. Bishop
    9 
   10   This file Copyright 1998,99,2002 Andrew M. Bishop
   11   It may be distributed under the GNU Public License, version 2, or
   12   any higher version.  See section COPYING of the GNU Public license
   13   for conditions under which this file may be redistributed.
   14   ***************************************/
   15 
   16 
   17 #include <stdio.h>
   18 #include <stdlib.h>
   19 #include <string.h>
   20 
   21 #include "procmeter.h"
   22 
   23 /* The interface information.  */
   24 
   25 /*+ The graph output +*/
   26 ProcMeterOutput graph_output=
   27 {
   28  /* char  name[];          */ "Example_Graph",
   29  /* char *description;     */ "An example graph to show how it works",
   30  /* char  type;            */ PROCMETER_GRAPH|PROCMETER_BAR,
   31  /* short interval;        */ 1,
   32  /* char  text_value[];    */ "n/a",
   33  /* long  graph_value;     */ 0,
   34  /* short graph_scale;     */ 10,
   35  /* char  graph_units[];   */ "(%d)"
   36 };
   37 
   38 /*+ The text output. +*/
   39 ProcMeterOutput text_output=
   40 {
   41  /* char  name[];          */ "Example_Text",
   42  /* char *description;     */ "An example text field to show how it works",
   43  /* char  type;            */ PROCMETER_TEXT,
   44  /* short interval;        */ 10,
   45  /* char  text_value[];    */ "unknown",
   46  /* long  graph_value;     */ -1,
   47  /* short graph_scale;     */ 0,
   48  /* char  graph_units[];   */ "n/a"
   49 };
   50 
   51 /*+ The outputs. +*/
   52 ProcMeterOutput *outputs[]=
   53 {
   54  &graph_output,
   55  &text_output,
   56  NULL
   57 };
   58 
   59 /*+ The module. +*/
   60 ProcMeterModule module=
   61 {
   62  /* char name[];           */ "Template",
   63  /* char *description;     */ "A source code template of the sort of module that ProcMeter can use.",
   64 };
   65 
   66 
   67 /*++++++++++++++++++++++++++++++++++++++
   68   Load the module.
   69 
   70   ProcMeterModule *Load Returns the module information.
   71   ++++++++++++++++++++++++++++++++++++++*/
   72 
   73 ProcMeterModule *Load(void)
   74 {
   75  return(&module);
   76 }
   77 
   78 
   79 /*++++++++++++++++++++++++++++++++++++++
   80   Initialise the module, creating the outputs as required.
   81 
   82   ProcMeterOutput **Initialise Returns a NULL terminated list of outputs.
   83 
   84   char *options The options string for the module from the .procmeterrc file.
   85   ++++++++++++++++++++++++++++++++++++++*/
   86 
   87 ProcMeterOutput **Initialise(char *options)
   88 {
   89  return(outputs);
   90 }
   91 
   92 
   93 /*++++++++++++++++++++++++++++++++++++++
   94   Perform an update on one of the statistics.
   95 
   96   int Update Returns 0 if OK, else -1.
   97 
   98   time_t now The current time.
   99 
  100   ProcMeterOutput *output The output that the value is wanted for.
  101   ++++++++++++++++++++++++++++++++++++++*/
  102 
  103 int Update(time_t now,ProcMeterOutput *output)
  104 {
  105  if(output==&graph_output)
  106    {
  107     int result=now%100;
  108 
  109     output->graph_value=PROCMETER_GRAPH_FLOATING((double)result/output->graph_scale);
  110 
  111     return(0);
  112    }
  113  else if(output==&text_output)
  114    {
  115     static char result1[]="Example Output";
  116     static char result2[]="ProcMeter";
  117 
  118     if(now%60)
  119        strcpy(output->text_value,result1);
  120     else
  121        strcpy(output->text_value,result2);
  122 
  123     return(0);
  124    }
  125 
  126  return(-1);
  127 }
  128 
  129 
  130 /*++++++++++++++++++++++++++++++++++++++
  131   Tidy up and prepare to have the module unloaded.
  132   ++++++++++++++++++++++++++++++++++++++*/
  133 
  134 void Unload(void)
  135 {
  136 }