2 /// \file DeviceIface.h
3 /// Interface class for device backup and restore
7 Copyright (C) 2007-2008, 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>
29 #include "ConfigFile.h"
32 #define DI_THREAD_DONE 100
33 #define DI_THREAD_PROGRESS 101
40 class DeviceInterface
:
45 struct AppComm
// app communication
47 Glib::Dispatcher
*m_erase_db
; // to notify the app about the
48 // db erase stage of restore
49 Glib::Dispatcher
*m_progress
;
50 Glib::Dispatcher
*m_error
;
51 Glib::Dispatcher
*m_done
;
59 AppComm(Glib::Dispatcher
*progress
,
60 Glib::Dispatcher
*error
,
61 Glib::Dispatcher
*done
,
62 Glib::Dispatcher
*erase_db
) :
69 { return m_erase_db
&& m_progress
&& m_error
&& m_done
; }
71 { m_erase_db
= m_progress
= m_error
= m_done
= 0; }
74 class Quit
// quit exception to break out of upload/download
79 Barry::Controller
*m_con
;
80 Barry::Mode::Desktop
*m_desktop
;
81 std::string m_last_error
;
82 std::string m_last_thread_error
;
85 std::auto_ptr
<reuse::TarFile
> m_tar
, m_tarback
;
87 // parser and builder data (only one side uses these at a time)
88 ConfigFile::DBListType m_dbList
;
89 mutable Glib::Mutex
*m_dbnameMutex
;
90 std::string m_current_dbname_not_thread_safe
;
91 std::string m_current_dbname
;
94 std::string m_tar_id_text
;
95 std::string m_record_data
;
97 bool m_tar_record_loaded
;
99 // thread quit flag... not locked, only a byte
100 volatile bool m_thread_quit
;
103 bool False(const std::string
&msg
);
107 void RestoreThread();
108 void RestoreAndBackupThread();
111 std::string
MakeFilename(const std::string
&pin
);
112 int CountFiles(reuse::TarFile
&tar
, const ConfigFile::DBListType
&restoreList
);
113 bool SplitTarPath(const std::string
&tarpath
, std::string
&dbname
,
114 std::string
&dbid_text
, uint8_t &dbrectype
, uint32_t &dbid
);
116 // Sets the name of the database the thread is currently working on
117 void SetThreadDBName(const std::string
&dbname
);
123 const std::string
& get_last_error() const { return m_last_error
; }
124 const std::string
& get_last_thread_error() const { return m_last_thread_error
; }
126 bool Connect(const Barry::ProbeResult
&dev
);
127 bool Password(const char *password
);
130 const Barry::DatabaseDatabase
& GetDBDB() const { return m_desktop
->GetDBDB(); }
131 int GetDeviceRecordTotal(const ConfigFile::DBListType
&backupList
) const;
133 void QuitThread() { m_thread_quit
= true; }
135 /// returns name of database the thread is currently working on
136 std::string
GetThreadDBName() const;
138 bool StartBackup(AppComm comm
,
139 const ConfigFile::DBListType
&backupList
,
140 const std::string
&directory
, const std::string
&pin
);
141 bool StartRestore(AppComm comm
,
142 const ConfigFile::DBListType
&restoreList
,
143 const std::string
&tarfilename
, int *pRecordCount
= 0);
144 // this is for debugging... starts a restore, and then does an
145 // immediate backup of the same DB before moving on to the next
146 bool StartRestoreAndBackup(AppComm comm
,
147 const ConfigFile::DBListType
&restoreAndBackupList
,
148 const std::string
&tarfilename
,
149 const std::string
&directory
, const std::string
&pin
,
150 int *pRecordCount
= 0);
152 // Barry::Parser overrides
153 virtual void SetIds(uint8_t RecType
, uint32_t UniqueId
);
154 virtual void ParseFields(const Barry::Data
&data
, size_t &offset
);
155 virtual void Store();
157 // Barry::Builder overrides
158 virtual bool Retrieve(unsigned int dbId
);
159 virtual uint8_t GetRecType() const;
160 virtual uint32_t GetUniqueId() const;
161 virtual void BuildHeader(Barry::Data
&data
, size_t &offset
);
162 virtual void BuildFields(Barry::Data
&data
, size_t &offset
);
163 void SkipCurrentDB() throw(); // helper function for halding restore errors