1 #include <lib/components/file_eraser.h>
2 #include <lib/base/ioprio.h>
3 #include <lib/base/eerror.h>
4 #include <lib/base/init.h>
5 #include <lib/base/init_num.h>
11 eBackgroundFileEraser *eBackgroundFileEraser::instance;
13 eBackgroundFileEraser::eBackgroundFileEraser()
14 :messages(this,1), stop_thread_timer(eTimer::create(this))
18 CONNECT(messages.recv_msg, eBackgroundFileEraser::gotMessage);
19 CONNECT(stop_thread_timer->timeout, eBackgroundFileEraser::idle);
22 void eBackgroundFileEraser::idle()
27 eBackgroundFileEraser::~eBackgroundFileEraser()
29 messages.send(Message::quit);
32 kill(); // i dont understand why this is needed .. in ~eThread::eThread is a kill() to..
35 void eBackgroundFileEraser::thread()
41 setIoPrio(IOPRIO_CLASS_BE, 7);
47 stop_thread_timer->stop();
50 void eBackgroundFileEraser::erase(const char *filename)
55 snprintf(buf, 255, "%s.del", filename);
56 if (rename(filename, buf)<0)
57 ;/*perror("rename file failed !!!");*/
60 messages.send(Message(Message::erase, strdup(buf)));
66 void eBackgroundFileEraser::gotMessage(const Message &msg )
73 if ( ::unlink(msg.filename) < 0 )
74 eDebug("remove file %s failed (%m)", msg.filename);
76 eDebug("file %s erased", msg.filename);
77 free((char*)msg.filename);
79 stop_thread_timer->start(1000, true); // stop thread in one seconds
85 eDebug("unhandled thread message");
89 eAutoInitP0<eBackgroundFileEraser> init_eBackgroundFilEraser(eAutoInitNumbers::configuration+1, "Background File Eraser");