• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • kdeutils
  • Sitemap
  • Contact Us
 

kmilo

pb_monitor.cpp

Go to the documentation of this file.
00001 /*
00002    This file is part of the KDE project
00003 
00004    Copyright (c) 2003 George Staikos <staikos@kde.org>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019    Boston, MA 02110-1301, USA.
00020 
00021 */
00022 
00023 #include "pb_monitor.h"
00024 
00025 #include <sys/types.h>
00026 #include <unistd.h>
00027 
00028 #include <kgenericfactory.h>
00029 
00030 extern "C" {
00031 #include <pbbipc.h>
00032 }
00033 
00034 namespace KMilo {
00035 
00036 PowerBookMonitor::PowerBookMonitor(QObject *parent, const char *name, const QStringList& args)
00037 : Monitor(parent, name, args) {
00038     _serverPort = -1;
00039     _clientPort = -1;
00040     _progress = 0;
00041 }
00042 
00043 
00044 PowerBookMonitor::~PowerBookMonitor() {
00045 struct pbb_message msg;
00046     if (_serverPort >= 0) {
00047         msg.code = UNREGISTERCLIENT;
00048         msg.value = _clientPort;
00049         put_message(_serverPort, &msg);
00050     }
00051 
00052     if (_clientPort >= 0) {
00053         remove_msgport(_clientPort);
00054     }
00055 }
00056 
00057 
00058 bool PowerBookMonitor::init() {
00059     _serverPort = find_msgport(SERVERPORTKEY);
00060     if (_serverPort < 0) {
00061         return false;
00062     }
00063 
00064     _clientPort = create_msgport(getpid());
00065     if (_clientPort < 0) {
00066         _serverPort = -1;
00067         return false;
00068     }
00069 
00070     // Register
00071     struct pbb_message msg;
00072     msg.code = REGISTERCLIENT;
00073     msg.value = _clientPort;
00074     if (put_message(_serverPort, &msg) < 0) {
00075         remove_msgport(_clientPort);
00076         _clientPort = -1;
00077         _serverPort = -1;
00078         return false;
00079     }
00080 
00081 return true;
00082 }
00083 
00084 
00085 Monitor::DisplayType PowerBookMonitor::poll() {
00086 Monitor::DisplayType rc = None;
00087 struct pbb_message msg;
00088 
00089     if (_serverPort < 0 || _clientPort < 0)
00090         return Error;
00091 
00092     // Drain the queue, send the last message
00093     while (0 == get_message(_clientPort, 0, &msg)) {
00094         switch (msg.code) {
00095             case DISPLAYVOLUME:
00096                 rc = Monitor::Volume;
00097                 _progress = msg.value;
00098                 break;
00099             case DISPLAYMUTE:
00100                 rc = Monitor::Mute;
00101                 _progress = msg.value;
00102                 break;
00103             case DISPLAYBRIGHTNESS:
00104                 rc = Monitor::Brightness;
00105                 _progress = msg.value*100/15;
00106                 break;
00107             case REGFAILED:
00108             case CLIENTEXIT:
00109                 rc = Monitor::Error;
00110                 break;
00111             default:
00112                 break;
00113         }
00114     }
00115 
00116 return rc;
00117 }
00118 
00119 
00120 int PowerBookMonitor::progress() const {
00121     return _progress;
00122 }
00123 
00124 };
00125 
00126 K_EXPORT_COMPONENT_FACTORY(kmilo_powerbook, KGenericFactory<PowerBookMonitor>("kmilo_powerbook"))
00127 

kmilo

Skip menu "kmilo"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdeutils

Skip menu "kdeutils"
  • ark
  • kcalc
  • kcharselect
  • kdelirc
  • kdessh
  • kdf
  • kfloppy
  • kgpg
  • kjots
  • klaptopdaemon
  • kmilo
  • ksim
  • ktimer
  • kwallet
  • superkaramba
Generated for kdeutils by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal