source: MondoRescue/branches/2.06/mondo/mondo/xmondo/xmondobackup.cpp@ 277

Last change on this file since 277 was 30, checked in by bcornec, 19 years ago

Id property added on files to allow for better conf. management

  • Property svn:keywords set to Id
File size: 4.8 KB
Line 
1/***************************************************************************
2 xmondobackup.cpp - description
3 -------------------
4 begin : Mon Apr 28 2003
5 copyright : (C) 2003 by Joshua Oreman
6 email : oremanj@get-linux.org
7 cvsid : $Id: xmondobackup.cpp 30 2005-09-28 23:32:28Z bcornec $
8 ***************************************************************************/
9
10/***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18
19#include "xmondobackup.h"
20#include "X-specific.h"
21extern "C" {
22#include "libmondo-archive-EXT.h"
23#include "libmondo-fork-EXT.h"
24#include "libmondo-verify-EXT.h"
25}
26#include <qprogressbar.h>
27#include <qmultilineedit.h>
28#include <qlabel.h>
29#include <qstring.h>
30#include <qvaluelist.h>
31#include <qlayout.h>
32#include <qthread.h>
33#include <qpushbutton.h>
34
35static char cvsid[] = "$Id: xmondobackup.cpp 30 2005-09-28 23:32:28Z bcornec $";
36
37extern "C" {
38 char g_xmondo_logfile[MAX_STR_LEN] = "/var/log/mondo-archive.log";
39}
40
41extern QProgressBar *XMondoProgress;
42extern QLabel *XMondoProgressWhat, *XMondoProgressWhat2, *XMondoProgressWhat3;
43extern QCheckBox *XMondoVerbose;
44extern QMultiLineEdit *XMondoLog;
45extern QLabel *XMondoStatus;
46extern QLabel *XMondoTimeTaken, *XMondoTimeToGo, *XMondoProgressPercent;
47extern QPushButton *XMondoCancel;
48extern XMEventHolder events;
49
50XMondoBackup::XMondoBackup() : QObject (0, 0)
51{
52
53 disconnect (XMondoCancel, SIGNAL(clicked()), 0, 0);
54 connect (XMondoCancel, SIGNAL(clicked()), this, SLOT(abortBackup()));
55
56 XMondoProgress->hide();
57 XMondoProgressWhat->hide();
58 XMondoProgressWhat2->hide();
59 XMondoProgressWhat3->hide();
60 XMondoTimeTaken->hide();
61 XMondoTimeToGo->hide();
62 XMondoStatus->setText ("");
63 XMondoStatus->show();
64 XMondoLog->setText ("");
65 XMondoLog->show();
66}
67
68XMondoBackup::~XMondoBackup()
69{
70}
71
72void *BackupThread__run (void *arg);
73
74class BackupThread
75{
76 friend void *BackupThread__run (void *arg);
77public:
78 BackupThread (struct s_bkpinfo *bkpinfo, bool bkup = true) : _bkpinfo (bkpinfo), _bkup (bkup),
79 _ret (-1), _aborted (false) {}
80 int returns() {
81 return _ret;
82 }
83 void start() {
84 _running = true;
85 pthread_create (&_thr, 0, BackupThread__run, this);
86 }
87 void terminate() {
88 _running = false;
89 pthread_cancel (_thr);
90 _thr = 0;
91 }
92 bool running() {
93 return _running;
94 }
95 bool aborted() {
96 return _aborted;
97 }
98protected:
99 static void setStop (void *arg) {
100 BackupThread *bt = static_cast <BackupThread*> (arg);
101 if (!bt) return;
102 bt->_running = false;
103 bt->_ret = -1;
104 bt->_aborted = true;
105 }
106 void run() {
107 pthread_cleanup_push (BackupThread::setStop, this);
108 if (_bkup) {
109 log_to_screen ("Backup started on %s", call_program_and_get_last_line_of_output ("date"));
110 _ret = backup_data (_bkpinfo);
111 log_to_screen ("Backup finished on %s", call_program_and_get_last_line_of_output ("date"));
112 } else {
113 log_to_screen ("Compare started on %s", call_program_and_get_last_line_of_output ("date"));
114 _ret = verify_data (_bkpinfo);
115 log_to_screen ("Compare finished on %s", call_program_and_get_last_line_of_output ("date"));
116 }
117 pthread_cleanup_pop (FALSE);
118 _running = false;
119 }
120 struct s_bkpinfo *_bkpinfo;
121 int _ret;
122 bool _bkup;
123 pthread_t _thr;
124 bool _running;
125 bool _aborted;
126};
127
128void *BackupThread__run (void *arg)
129{
130 BackupThread *bt = static_cast <BackupThread *> (arg);
131 if (!bt && (sizeof(void*) >= 4)) return (void *) 0xDEADBEEF;
132 bt->run();
133}
134
135int XMondoBackup::run (struct s_bkpinfo *bkpinfo)
136{
137 th = new BackupThread (bkpinfo);
138 th->start();
139 while (th->running()) {
140 usleep (100000);
141 events.send();
142 kapp->processEvents();
143 }
144 if (th->aborted()) {
145 return -1;
146 }
147 return th->returns();
148}
149
150int XMondoBackup::compare (struct s_bkpinfo *bkpinfo)
151{
152 th = new BackupThread (bkpinfo, 0);
153 th->start();
154 while (th->running()) {
155 usleep (100000);
156 events.send();
157 kapp->processEvents();
158 }
159 if (th->aborted()) {
160 return -1;
161 }
162 return th->returns();
163}
164
165void XMondoBackup::abortBackup()
166{
167 th->terminate();
168}
Note: See TracBrowser for help on using the repository browser.