2 * Copyright 2011-2015, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Oliver Tappe <zooey@hirschkaefer.de>
10 #include <package/Request.h>
16 #include <package/Context.h>
19 namespace BPackageKit
{
22 using BSupportKit::BPrivate::JobQueue
;
25 BRequest::BRequest(const BContext
& context
)
28 fJobQueue(new (std::nothrow
) JobQueue())
30 fInitStatus
= fJobQueue
== NULL
? B_NO_MEMORY
: B_OK
;
40 BRequest::InitCheck() const
47 BRequest::PopRunnableJob()
49 if (fJobQueue
== NULL
)
52 return fJobQueue
->Pop();
57 BRequest::Process(bool failIfCanceledOnly
)
59 status_t error
= InitCheck();
63 error
= CreateInitialJobs();
67 while (BSupportKit::BJob
* job
= PopRunnableJob()) {
71 if (!failIfCanceledOnly
|| error
== B_CANCELED
)
81 BRequest::QueueJob(BSupportKit::BJob
* job
)
83 if (fJobQueue
== NULL
)
86 job
->AddStateListener(this);
87 job
->AddStateListener(&fContext
.JobStateListener());
89 return fJobQueue
->AddJob(job
);
93 } // namespace BPackageKit