1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
/*
* This file is part of the QPxTool project.
* Copyright (C) 2005-2006 Gennady "ShultZ" Kozlov <qpxtool@mail.ru>
*
* 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 2 of the License, or
* (at your option) any later version.
* See the file "COPYING" for the exact licensing terms.
*
*/
//#include <stdio.h>
//#include <string.h>
//#include <stdlib.h>
#include <unistd.h>
//#include <sys/time.h>
#include <qevent.h>
#include <qthread.h>
//#include "transport.hxx"
#include <qpx_mmc.h>
#include <qpx_transport.h>
#include <scan_events.h>
#include "watcher.h"
watcher_thread::watcher_thread(QObject* p)
{
parent = p;
}
watcher_thread::~watcher_thread()
{
}
void watcher_thread::init(unsigned char i, drive_info* drv)
{
drive = drv;
idx = i;
}
void watcher_thread::run()
{
if (!drive) return;
for (;;) {
get_media_status(drive);
switch (drive->parms.event) {
case EVENT_MEDIA_NEW:
printf("Watcher: [%s] %s %s: new media\n", drive->device, drive->ven, drive->dev);
emit_media_new();
break;
case EVENT_MEDIA_REMOVED:
printf("Watcher: [%s] %s %s: media removed\n", drive->device, drive->ven, drive->dev);
emit_media_removed();
break;
}
sleep(1);
}
}
void watcher_thread::emit_media_new()
{
QCustomEvent* event = new QCustomEvent(event_media_new);
event->setData(&idx);
postEvent(parent, event);
}
void watcher_thread::emit_media_removed()
{
QCustomEvent* event = new QCustomEvent(event_media_removed);
event->setData(&idx);
postEvent(parent, event);
}
|