xref: /haiku/src/kits/storage/AddOnMonitor.cpp (revision 32a2294fdc40a8ef9e3360aa85d0b7efb0c930b9)
1 /*
2  * Copyright 2004-2010, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Andrew Bachmann
7  */
8 
9 
10 #include "AddOnMonitor.h"
11 #include "AddOnMonitorHandler.h"
12 #include <Message.h>
13 #include <MessageRunner.h>
14 #include <Messenger.h>
15 #include <stdio.h>
16 
17 
18 AddOnMonitor::AddOnMonitor(AddOnMonitorHandler* handler)
19 	:
20 	BLooper("AddOnMonitor"),
21 	fInitCheck(B_NO_INIT)
22 {
23 	AddHandler(handler);
24 	SetPreferredHandler(handler);
25 
26 	status_t status;
27 	BMessenger messenger(handler, this, &status);
28 	if (status != B_OK) {
29 		fInitCheck = status;
30 		return;
31 	}
32 
33 	BMessage pulseMessage(B_PULSE);
34 	fPulseRunner = new BMessageRunner(messenger, &pulseMessage, 1000000);
35 	status = fPulseRunner->InitCheck();
36 	if (status != B_OK) {
37 		fInitCheck = status;
38 		fprintf(stderr, "AddOnMonitor() : bad status returned by "
39 			"fPulseRunner->InitCheck()\n");
40 		return;
41 	}
42 
43 	thread_id id = Run();
44 	if (id < 0) {
45 		fInitCheck = (status_t)id;
46 		fprintf(stderr, "AddOnMonitor() : bad id returned by Run()\n");
47 		return;
48 	}
49 
50 	fInitCheck = B_OK;
51 }
52 
53 
54 AddOnMonitor::~AddOnMonitor()
55 {
56 	delete fPulseRunner;
57 }
58 
59 
60 status_t
61 AddOnMonitor::InitCheck()
62 {
63 	return fInitCheck;
64 }
65