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

View File

@ -9,11 +9,26 @@
#include <package/Job.h> #include <package/Job.h>
struct JobStateListener : public BPackageKit::BJobStateListener { 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 JobStarted(BPackageKit::BJob* job);
virtual void JobSucceeded(BPackageKit::BJob* job); virtual void JobSucceeded(BPackageKit::BJob* job);
virtual void JobFailed(BPackageKit::BJob* job); virtual void JobFailed(BPackageKit::BJob* job);
virtual void JobAborted(BPackageKit::BJob* job); virtual void JobAborted(BPackageKit::BJob* job);
private:
uint32 fFlags;
}; };