3 /// Thread class for device manipulation
7 Copyright (C) 2007-2009, Net Direct Inc. (http://www.netdirect.ca/)
8 Copyright (C) 2009, Ryan Li (ryan@ryanium.com)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 See the GNU General Public License in the COPYING file at the
20 root directory of this project for more details.
23 #ifndef __BARRYBACKUP_THREAD_H__
24 #define __BARRYBACKUP_THREAD_H__
27 #include "ConfigFile.h"
28 #include "DeviceIface.h"
30 // bit masks for various thread state
31 #define THREAD_STATE_IDLE 0x01 // currently idle
32 #define THREAD_STATE_BACKUP 0x02 // last operation requested
33 // was backup... if idle bit
34 // is 0, backup is still going
35 #define THREAD_STATE_RESTORE 0x04 // last op was restore... same
39 class Thread
: public ConfigFile
42 Glib::Dispatcher m_signal_progress
;
43 Glib::Dispatcher m_signal_error
;
44 Glib::Dispatcher m_signal_done
;
45 Glib::Dispatcher m_signal_erase_db
;
48 DeviceInterface m_interface
;
50 Glib::Dispatcher
*m_update
;
54 unsigned int m_recordFinished
;
55 unsigned int m_recordTotal
;
57 // Barry::BadPassword related variables
58 bool password_out_of_tries
;
59 unsigned int password_remaining_tries
;
60 bool password_required
;
61 std::string bad_password_error
;
63 // Barry::BadSize related variables
65 std::string bad_size_error
;
67 // whether the device is active in Gtk::TreeView
70 // marked as true after thread finished,
71 // and false when the value is retrieved.
72 bool m_finished_marker
;
77 unsigned int m_thread_state
;
80 void SetStatus(std::string
);
83 Thread(Device
, Glib::Dispatcher
*);
86 std::string
LastInterfaceError() { return m_interface
.get_last_error(); }
87 std::string
LastConfigError() { return ConfigFile::get_last_error(); }
89 const Barry::DatabaseDatabase
&GetDBDB() { return m_interface
.GetDBDB(); }
93 Barry::Pin
GetPIN() { return m_dev
.GetPIN(); }
94 std::string
GetFullname();
96 std::string
Status() const { return m_status
; }
97 bool CheckFinishedMarker();
98 unsigned int GetRecordFinished() const { return m_recordFinished
; }
99 unsigned int GetRecordTotal() const { return m_recordTotal
; }
100 unsigned int GetThreadState() const { return m_thread_state
; }
102 void Reset() { m_interface
.Reset(); }
104 bool Connect(const std::string
&password
);
107 void SetActive() { m_active
= true; }
110 bool Connected() const { return m_connected
; }
111 bool Working() const { return !(m_thread_state
& THREAD_STATE_IDLE
); }
112 bool Error() const { return m_error
; }
114 bool PasswordRequired() const { return password_required
; }
115 bool PasswordOutOfTries() const { return password_out_of_tries
; }
116 unsigned int PasswordRemainingTries() const { return password_remaining_tries
; }
117 std::string
BadPasswordError() const { return bad_password_error
; }
119 bool BadSize() const { return bad_size
; }
120 std::string
BadSizeError() const { return bad_size_error
; }
122 bool Backup(std::string label
);
123 bool Restore(std::string filename
);
124 bool RestoreAndBackup(std::string filename
);
126 void on_thread_progress();
127 void on_thread_error();
128 void on_thread_done();
129 void on_thread_erase_db();