* Copyright 2012-2014, Rene Gollent, rene@gollent.com.
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#include "Jobs.h"
#include <AutoLocker.h>
#include "Image.h"
#include "ImageDebugInfo.h"
#include "TeamDebugInfo.h"
#include "Team.h"
LoadImageDebugInfoJob::LoadImageDebugInfoJob(Image* image)
:
fKey(image, JOB_TYPE_LOAD_IMAGE_DEBUG_INFO),
fImage(image),
fState()
{
fImage->AcquireReference();
SetDescription("Loading debugging information for %s",
fImage->Name().String());
}
LoadImageDebugInfoJob::~LoadImageDebugInfoJob()
{
fImage->ReleaseReference();
}
const JobKey&
LoadImageDebugInfoJob::Key() const
{
return fKey;
}
status_t
LoadImageDebugInfoJob::Do()
{
AutoLocker<Team> locker(fImage->GetTeam());
ImageInfo imageInfo(fImage->Info());
locker.Unlock();
ImageDebugInfo* debugInfo;
status_t error = fImage->GetTeam()->DebugInfo()->LoadImageDebugInfo(
imageInfo, fImage->ImageFile(), fState, debugInfo);
locker.Lock();
if (fState.UserInputRequired()) {
return WaitForUserInput();
} else if (error == B_OK) {
error = fImage->SetImageDebugInfo(debugInfo, IMAGE_DEBUG_INFO_LOADED);
debugInfo->ReleaseReference();
} else
fImage->SetImageDebugInfo(NULL, IMAGE_DEBUG_INFO_UNAVAILABLE);
return error;
}
status_t
LoadImageDebugInfoJob::ScheduleIfNecessary(Worker* worker, Image* image,
JobListener* listener, ImageDebugInfo** _imageDebugInfo)
{
AutoLocker<Team> teamLocker(image->GetTeam());
if (image->GetImageDebugInfo() != NULL) {
if (_imageDebugInfo != NULL) {
*_imageDebugInfo = image->GetImageDebugInfo();
(*_imageDebugInfo)->AcquireReference();
}
return B_OK;
}
if (image->ImageDebugInfoState() == IMAGE_DEBUG_INFO_LOADING) {
if (_imageDebugInfo != NULL)
*_imageDebugInfo = NULL;
return B_OK;
}
if (image->ImageDebugInfoState() != IMAGE_DEBUG_INFO_NOT_LOADED)
return B_ERROR;
LoadImageDebugInfoJob* job = new(std::nothrow) LoadImageDebugInfoJob(
image);
if (job == NULL)
return B_NO_MEMORY;
status_t error = worker->ScheduleJob(job, listener);
if (error != B_OK) {
image->SetImageDebugInfo(NULL, IMAGE_DEBUG_INFO_UNAVAILABLE);
return error;
}
image->SetImageDebugInfo(NULL, IMAGE_DEBUG_INFO_LOADING);
if (_imageDebugInfo != NULL)
*_imageDebugInfo = NULL;
return B_OK;
}