3df72165af
* NEW: The syntax of pkg-config detection macro has changed to better use the pkg-config possibilities. [DEVELOPMENT ENVIRONMENT] * BUG: Correctly update .startup file when closing the project property dialog. * BUG: Don't crash when the debugger stops inside the form generated code. * BUG: Update the project templates to the 3.0 syntax. [GB.QTE] * BUG: Make this component compile correctly. * BUG: Remove the automake warning. [GB.QT4] * NEW: Upgrade to the new QT 4 syntax in many places. * NEW: Menu class has been redesigned to use the new QAction class. Not tested yet. * NEW: Standard controls work better. git-svn-id: svn://localhost/gambas/trunk@1344 867c0c6c-44f3-4631-809d-bfa615b0a4ec
133 lines
3 KiB
C++
133 lines
3 KiB
C++
/***************************************************************************
|
||
|
||
CWatch.cpp
|
||
|
||
Watching for file descriptors
|
||
|
||
(c) 2000-2005 Beno<6E>t Minisini <gambas@users.sourceforge.net>
|
||
|
||
This program is free software; you can redistribute it and/or modify
|
||
it under the terms of the GNU General Public License as published by
|
||
the Free Software Foundation; either version 1, or (at your option)
|
||
any later version.
|
||
|
||
This program is distributed in the hope that it will be useful,
|
||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
GNU General Public License for more details.
|
||
|
||
You should have received a copy of the GNU General Public License
|
||
along with this program; if not, write to the Free Software
|
||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||
|
||
***************************************************************************/
|
||
|
||
#define __CWATCH_CPP
|
||
|
||
#include "main.h"
|
||
#include "CWatch.h"
|
||
|
||
QHash<int, CWatch *> CWatch::readDict;
|
||
QHash<int, CWatch *> CWatch::writeDict;
|
||
int CWatch::count = 0;
|
||
|
||
void CWatch::watch(int fd, int type, GB_WATCH_CALLBACK callback, intptr_t param)
|
||
{
|
||
CWatch *watch;
|
||
|
||
switch (type)
|
||
{
|
||
case GB_WATCH_NONE:
|
||
|
||
watch = readDict[fd];
|
||
if (watch) delete watch;
|
||
|
||
watch = writeDict[fd];
|
||
if (watch) delete watch;
|
||
|
||
break;
|
||
|
||
case GB_WATCH_READ:
|
||
|
||
new CWatch(fd, QSocketNotifier::Read, callback, param);
|
||
break;
|
||
|
||
case GB_WATCH_WRITE:
|
||
|
||
new CWatch(fd, QSocketNotifier::Write, callback, param);
|
||
break;
|
||
|
||
}
|
||
}
|
||
|
||
|
||
void CWatch::stop()
|
||
{
|
||
int fd;
|
||
|
||
for (fd = 0; count > 0; fd++)
|
||
watch(fd, GB_WATCH_NONE, 0, 0);
|
||
}
|
||
|
||
CWatch::CWatch(int fd, QSocketNotifier::Type type, GB_WATCH_CALLBACK callback, intptr_t param)
|
||
{
|
||
count++;
|
||
|
||
notifier = new QSocketNotifier(fd, type);
|
||
this->callback = callback;
|
||
this->param = param;
|
||
|
||
if (type == QSocketNotifier::Read)
|
||
{
|
||
//qDebug("CWatch: %d (read)", fd);
|
||
|
||
if (readDict[fd])
|
||
delete readDict[fd];
|
||
|
||
readDict.insert(fd, this);
|
||
QObject::connect(notifier, SIGNAL(activated(int)), this, SLOT(read(int)));
|
||
}
|
||
else if (type == QSocketNotifier::Write)
|
||
{
|
||
//qDebug("CWatch: %d (write)", fd);
|
||
|
||
if (writeDict[fd])
|
||
delete writeDict[fd];
|
||
|
||
writeDict.insert(fd, this);
|
||
QObject::connect(notifier, SIGNAL(activated(int)), this, SLOT(write(int)));
|
||
}
|
||
}
|
||
|
||
|
||
CWatch::~CWatch()
|
||
{
|
||
if (notifier->type() == QSocketNotifier::Read)
|
||
{
|
||
//qDebug("~CWatch: %d (read)", notifier->socket());
|
||
readDict.remove(notifier->socket());
|
||
}
|
||
else if (notifier->type() == QSocketNotifier::Write)
|
||
{
|
||
//qDebug("~CWatch: %d (write)", notifier->socket());
|
||
writeDict.remove(notifier->socket());
|
||
}
|
||
|
||
delete notifier;
|
||
|
||
count--;
|
||
MAIN_check_quit();
|
||
}
|
||
|
||
void CWatch::read(int fd)
|
||
{
|
||
//qDebug("CWatch::read: fd = %d readDict[fd] = %p", fd, readDict[fd]);
|
||
if (readDict[fd])
|
||
(*callback)(fd, GB_WATCH_READ, param);
|
||
}
|
||
|
||
void CWatch::write(int fd)
|
||
{
|
||
if (writeDict[fd])
|
||
(*callback)(fd, GB_WATCH_WRITE, param);
|
||
}
|