From 24e37ddf57bac6a1c9786d50abbe3a1982930382 Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Sun, 23 Dec 2012 23:30:57 +0100 Subject: ipodpatcher: move sectorbuf pointer into ipod_t structure. The ipod_t structure holds all relevant information for ipodpatcher. Put the global ipod_sectorbuf pointer into it as well. Allows the Rockbox Utility Ipod class to be instanciated multiple times since each instance can now have its own buffer. Change-Id: Ie319cbadbc20c367ceadba9a46b4dc34b57a79a7 --- rbutil/rbutilqt/base/bootloaderinstallipod.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'rbutil/rbutilqt/base/bootloaderinstallipod.cpp') diff --git a/rbutil/rbutilqt/base/bootloaderinstallipod.cpp b/rbutil/rbutilqt/base/bootloaderinstallipod.cpp index 249da13735..3d90663392 100644 --- a/rbutil/rbutilqt/base/bootloaderinstallipod.cpp +++ b/rbutil/rbutilqt/base/bootloaderinstallipod.cpp @@ -28,33 +28,32 @@ BootloaderInstallIpod::BootloaderInstallIpod(QObject *parent) : BootloaderInstallBase(parent) { (void)parent; - // initialize sector buffer. ipod_sectorbuf is defined in ipodpatcher. - // The buffer itself is only present once, so make sure to not allocate - // it if it was already allocated. The application needs to take care - // no concurrent (i.e. multiple objects of this class running) requests - // are done. - if(ipod_sectorbuf == NULL) - ipod_alloc_buffer(&ipod_sectorbuf, BUFFER_SIZE); + // initialize sector buffer. The sector buffer is part of the ipod_t + // structure, so a second instance of this class will have its own buffer. + ipod_alloc_buffer(&ipod, BUFFER_SIZE); } BootloaderInstallIpod::~BootloaderInstallIpod() { - if(ipod_sectorbuf) { - free(ipod_sectorbuf); - ipod_sectorbuf = NULL; + if(ipod.sectorbuf) { + free(ipod.sectorbuf); + ipod.sectorbuf = NULL; } } bool BootloaderInstallIpod::install(void) { - if(ipod_sectorbuf == NULL) { + if(ipod.sectorbuf == NULL) { emit logItem(tr("Error: can't allocate buffer memory!"), LOGERROR); emit done(true); return false; } + // save buffer pointer before cleaning up ipod_t structure + unsigned char* sb = ipod.sectorbuf; memset(&ipod, 0, sizeof(struct ipod_t)); + ipod.sectorbuf = sb; if(!ipodInitialize(&ipod)) { emit done(true); @@ -139,7 +138,6 @@ void BootloaderInstallIpod::installStage3(bool mounted) bool BootloaderInstallIpod::uninstall(void) { - struct ipod_t ipod; emit logItem(tr("Uninstalling bootloader"), LOGINFO); QCoreApplication::processEvents(); @@ -190,7 +188,6 @@ bool BootloaderInstallIpod::uninstall(void) BootloaderInstallBase::BootloaderType BootloaderInstallIpod::installed(void) { - struct ipod_t ipod; BootloaderInstallBase::BootloaderType result = BootloaderRockbox; if(!ipodInitialize(&ipod)) { -- cgit v1.2.3