2 /// \file DeviceIface.h
3 /// Interface class for device backup and restore
7 Copyright (C) 2007-2012, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRYBACKUP_DEVICEIFACE_H__
23 #define __BARRYBACKUP_DEVICEIFACE_H__
25 #include <barry/barry.h>
26 #include <barry/barrybackup.h>
31 #define DI_THREAD_DONE 100
32 #define DI_THREAD_PROGRESS 101
41 Barry::ProbeResult result
;
44 Device(const Barry::ProbeResult
&result
);
46 Barry::Pin
GetPIN() const { return Barry::Pin(result
.m_pin
); };
48 friend class DeviceInterface
;
51 class DeviceInterface
:
56 struct AppComm
// app communication
58 Glib::Dispatcher
*m_erase_db
; // to notify the app about the
59 // db erase stage of restore
60 Glib::Dispatcher
*m_restored_db
;// to notify the app that the
61 // previous erase_db was
62 // restored... do not rely
63 // on the current db name ==
64 // the name found at erase time
65 Glib::Dispatcher
*m_progress
;
66 Glib::Dispatcher
*m_error
;
67 Glib::Dispatcher
*m_done
;
76 AppComm(Glib::Dispatcher
*progress
,
77 Glib::Dispatcher
*error
,
78 Glib::Dispatcher
*done
,
79 Glib::Dispatcher
*erase_db
,
80 Glib::Dispatcher
*restored_db
) :
82 m_restored_db(restored_db
),
88 { return m_erase_db
&& m_restored_db
&& m_progress
&& m_error
&& m_done
; }
90 { m_erase_db
= m_restored_db
= m_progress
= m_error
= m_done
= 0; }
93 class Quit
// quit exception to break out of upload/download
99 Barry::Controller
*m_con
;
100 Barry::Mode::Desktop
*m_desktop
;
101 std::string m_last_error
;
102 std::string m_last_thread_error
;
106 std::auto_ptr
<Barry::Backup
> m_backup
;
107 std::auto_ptr
<Barry::Restore
> m_restore
;
109 mutable Barry::Backup::StatsType m_backupStats
;
111 // parser and builder data
112 Barry::ConfigFile::DBListType m_dbBackupList
;
113 mutable Glib::Mutex
*m_dbnameMutex
;
114 std::string m_current_dbname
;
116 // thread quit flag... not locked, only a byte
117 volatile bool m_thread_quit
;
120 bool False(const std::string
&msg
);
124 void RestoreThread();
127 std::string
MakeFilename(const std::string
&label
= "") const;
128 bool SplitTarPath(const std::string
&tarpath
, std::string
&dbname
,
129 std::string
&dbid_text
, uint8_t &dbrectype
, uint32_t &dbid
) const;
131 // Sets the name of the database the thread is currently working on
132 void SetThreadDBName(const std::string
&dbname
);
135 DeviceInterface(Device
*dev
= 0);
138 const std::string
& get_last_error() const { return m_last_error
; }
139 const std::string
& get_last_thread_error() const { return m_last_thread_error
; }
143 bool Password(const char *password
);
146 const Barry::ProbeResult
& GetProbeResult() const { return m_con
->GetProbeResult(); }
147 const Barry::DatabaseDatabase
& GetDBDB() const { return m_desktop
->GetDBDB(); }
148 unsigned int GetRecordTotal(const Barry::ConfigFile::DBListType
&backupList
) const;
149 unsigned int GetRecordTotal(const Barry::ConfigFile::DBListType
&restoreList
, const std::string
&filename
) const;
151 std::vector
<std::string
> CompareTotals(const Barry::ConfigFile::DBListType
&backupList
) const;
153 void QuitThread() { m_thread_quit
= true; }
155 /// returns name of database the thread is currently working on
156 std::string
GetThreadDBName() const;
158 bool StartBackup(AppComm comm
,
159 const Barry::ConfigFile::DBListType
&backupList
,
160 const std::string
&directory
, const std::string
&backupLabel
);
161 bool StartRestore(AppComm comm
,
162 const Barry::ConfigFile::DBListType
&restoreList
,
163 const std::string
&tarfilename
);
165 // Barry::Parser overrides
166 virtual void ParseRecord(const Barry::DBData
&data
,
167 const Barry::IConverter
*ic
);
169 // Barry::Builder overrides
170 virtual bool BuildRecord(Barry::DBData
&data
, size_t &offset
, const Barry::IConverter
*ic
);
171 virtual bool FetchRecord(Barry::DBData
&data
, const Barry::IConverter
*ic
);
172 virtual bool EndOfFile() const { return false; } // not used
173 void SkipCurrentDB() throw(); // helper function for halding restore errors