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

kstars

PPort.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2004 by Jasem Mutlaq
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Lesser General Public
00006     License as published by the Free Software Foundation; either
00007     version 2.1 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Lesser General Public License for more details.
00013 
00014     You should have received a copy of the GNU Lesser General Public
00015     License along with this library; if not, write to the Free Software
00016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00017 
00018 */
00019 
00020 #include "PPort.h"
00021 #include "port.h"
00022 
00023 #include <unistd.h>
00024 #include <sys/types.h>
00025 #include <iostream>
00026 
00027 using namespace std;
00028 
00029 #define TEST_VALIDITY {if (this==NULL) return false;}
00030 
00031 PPort::PPort() {
00032    reset();
00033 }
00034 
00035 PPort::PPort(int ioPort) {
00036    reset();
00037    setPort(ioPort);
00038 }
00039 
00040 void PPort::reset() {
00041    bitArray=0;
00042    for (int i=0;i<8;++i) {
00043       assignedBit[i]=NULL;
00044    }
00045    currentPort=NULL;
00046 }
00047 
00048 bool PPort::setPort(int ioPort) {
00049    TEST_VALIDITY;
00050    if (geteuid() != 0) {
00051       cerr << "must be setuid root control parallel port"<<endl;
00052       return false;
00053    }
00054    if (currentPort) {
00055       delete currentPort;
00056    }
00057    reset();
00058    currentPort=new port_t(ioPort);
00059    return commit();
00060 }
00061 
00062 bool PPort::commit() {
00063    TEST_VALIDITY;
00064    if (currentPort) {
00065       currentPort->write_data(bitArray);
00066       return true;
00067    } else {
00068       return false;
00069    }
00070 }
00071 
00072 bool  PPort::setBit(const void * ID,int bit,bool stat) {
00073    TEST_VALIDITY;
00074    if (ID != assignedBit[bit]) {
00075       return false;
00076    }
00077 
00078    if (stat) {
00079       bitArray |= (1<<bit);
00080    } else {
00081       bitArray &= ~(1<<bit);
00082    }
00083    return true;
00084 }
00085 
00086 bool PPort::registerBit(const void * ID,int bit) {
00087    TEST_VALIDITY;
00088    if (assignedBit[bit] || currentPort==NULL) {
00089       return false;
00090    }
00091    assignedBit[bit]=ID;
00092    return true;
00093 }
00094 
00095 bool PPort::unregisterBit(const void * ID,int bit) {
00096    TEST_VALIDITY;
00097    if (assignedBit[bit] != ID) {
00098       return false;
00099    }
00100    assignedBit[bit]=NULL;
00101    return true;
00102 }
00103 
00104 bool PPort::isRegisterBit(const void * ID,int bit) const {
00105    TEST_VALIDITY;
00106    return (assignedBit[bit] == ID);
00107 }

kstars

Skip menu "kstars"
  • Main Page
  • Modules
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • keduca
  • kstars
Generated for API Reference by doxygen 1.5.9
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