pkgman: make JobStateListener a bit more flexible

Flags can be passed to the constructor to specify whether to exit() when
a job failed/was aborted.
This commit is contained in:
Ingo Weinhold 2013-08-25 17:06:30 +02:00
parent c33daf26ea
commit 03191ec5af
2 changed files with 31 additions and 7 deletions

View File

@ -13,6 +13,13 @@
using BPackageKit::BJob;
JobStateListener::JobStateListener(uint32 flags)
:
fFlags(flags)
{
}
void
JobStateListener::JobStarted(BJob* job)
{
@ -34,12 +41,14 @@ JobStateListener::JobFailed(BJob* job)
error.ReplaceAll("\n", "\n*** ");
fprintf(stderr, "%s", error.String());
}
DIE(job->Result(), "failed!");
if ((fFlags & EXIT_ON_ERROR) != 0)
DIE(job->Result(), "failed!");
}
void
JobStateListener::JobAborted(BJob* job)
{
DIE(job->Result(), "aborted");
if ((fFlags & EXIT_ON_ABORT) != 0)
DIE(job->Result(), "aborted");
}

View File

@ -9,11 +9,26 @@
#include <package/Job.h>
struct JobStateListener : public BPackageKit::BJobStateListener {
virtual void JobStarted(BPackageKit::BJob* job);
virtual void JobSucceeded(BPackageKit::BJob* job);
virtual void JobFailed(BPackageKit::BJob* job);
virtual void JobAborted(BPackageKit::BJob* job);
class JobStateListener : public BPackageKit::BJobStateListener {
public:
enum {
EXIT_ON_ERROR = 0x01,
EXIT_ON_ABORT = 0x02,
};
public:
JobStateListener(
uint32 flags = EXIT_ON_ERROR
| EXIT_ON_ABORT);
virtual void JobStarted(BPackageKit::BJob* job);
virtual void JobSucceeded(BPackageKit::BJob* job);
virtual void JobFailed(BPackageKit::BJob* job);
virtual void JobAborted(BPackageKit::BJob* job);
private:
uint32 fFlags;
};