xref: /haiku/src/kits/package/Request.cpp (revision b46615c55ad2c8fe6de54412055a0713da3d610a)
1 /*
2  * Copyright 2011, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Oliver Tappe <zooey@hirschkaefer.de>
7  */
8 
9 
10 #include <package/Request.h>
11 
12 #include <new>
13 
14 #include <package/Context.h>
15 #include <package/JobQueue.h>
16 
17 
18 namespace BPackageKit {
19 
20 
21 BRequest::BRequest(const BContext& context)
22 	:
23 	fContext(context),
24 	fJobQueue(new (std::nothrow) JobQueue())
25 {
26 	fInitStatus = fJobQueue == NULL ? B_NO_MEMORY : B_OK;
27 }
28 
29 
30 BRequest::~BRequest()
31 {
32 }
33 
34 
35 status_t
36 BRequest::InitCheck() const
37 {
38 	return fInitStatus;
39 }
40 
41 
42 BJob*
43 BRequest::PopRunnableJob()
44 {
45 	if (fJobQueue == NULL)
46 		return NULL;
47 
48 	return fJobQueue->Pop();
49 }
50 
51 
52 status_t
53 BRequest::QueueJob(BJob* job)
54 {
55 	if (fJobQueue == NULL)
56 		return B_NO_INIT;
57 
58 	job->AddStateListener(this);
59 	job->AddStateListener(&fContext.JobStateListener());
60 
61 	return fJobQueue->AddJob(job);
62 }
63 
64 
65 }	// namespace BPackageKit
66