Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

sensorsensor.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2003 by Hans Karlsson                                   *
00003  *   karlsson.h@home.se                                                      *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  ***************************************************************************/
00010 #include "sensorsensor.h"
00011 
00012 
00013 SensorSensor::SensorSensor( int interval ) : Sensor( interval )
00014 {
00015     connect(&ksp, SIGNAL(receivedStdout(KProcess *, char *, int )),
00016             this,SLOT(receivedStdout(KProcess *, char *, int )));
00017     connect(&ksp, SIGNAL(processExited(KProcess *)),
00018             this,SLOT(processExited( KProcess * )));
00019 
00020     // readValues();
00021 }
00022 
00023 
00024 SensorSensor::~SensorSensor()
00025 {
00026 }
00027 
00028 void SensorSensor::receivedStdout(KProcess *, char *buffer, int len )
00029 {
00030     buffer[len] = 0;
00031     sensorResult += QString( QCString(buffer) );
00032 }
00033 
00034 void SensorSensor::processExited(KProcess *)
00035 {
00036     QStringList stringList = QStringList::split('\n',sensorResult);
00037     sensorResult = "";
00038     QStringList::Iterator it = stringList.begin();
00039     QRegExp rx( "^(\\S+):\\s+[\\+\\-]?(\\d+\\.?\\d*)");
00040 
00041     while( it != stringList.end())
00042     {
00043         rx.search( *it );
00044 
00045         if ( !rx.cap(0).isEmpty())
00046         {
00047             sensorMap[rx.cap(1)] = rx.cap(2);
00048         }
00049         it++;
00050     }
00051 
00052     QString format;
00053     QString type;
00054     SensorParams *sp;
00055     Meter *meter;
00056 
00057     QObjectListIt lit( *objList );
00058     while (lit != 0)
00059     {
00060         sp = (SensorParams*)(*lit);
00061         meter = sp->getMeter();
00062         format = sp->getParam("FORMAT");
00063         type = sp->getParam("TYPE");
00064 
00065         if (type.length() == 0)
00066             type = "temp2";
00067 
00068         if (format.length() == 0 )
00069         {
00070             format = "%v";
00071         }
00072         format.replace( QRegExp("%v", false), sensorMap[type]);
00073         meter->setValue(format);
00074         ++lit;
00075     }
00076 }
00077 
00078 void SensorSensor::update()
00079 {
00080     ksp.clearArguments();
00081     ksp << "sensors";
00082     ksp.start( KProcess::NotifyOnExit,KProcIO::Stdout);
00083 }
00084 

Generated on Mon May 16 13:59:20 2005 for karamba by  doxygen 1.3.9.1