xref: /haiku/src/kits/storage/AddOnMonitor.cpp (revision 2f470aec1c92ce6917b8a903e343795dc77af41f)
1 #include "AddOnMonitor.h"
2 #include "AddOnMonitorHandler.h"
3 #include <Message.h>
4 #include <MessageRunner.h>
5 #include <Messenger.h>
6 #include <stdio.h>
7 
8 AddOnMonitor::AddOnMonitor(AddOnMonitorHandler * handler)
9 	: BLooper("AddOnMonitor")
10 {
11 	fInitCheck = B_NO_INIT;
12 	AddHandler(handler);
13 	SetPreferredHandler(handler);
14 	status_t status;
15 	BMessenger messenger(handler, this, &status);
16 	if (status != B_OK) {
17 		fInitCheck = status;
18 		return;
19 	}
20 	if (!messenger.IsValid()) {
21 		fInitCheck = B_ERROR;
22 		return;
23 	}
24 	fPulseMessage = new BMessage(B_PULSE);
25 	fPulseRunner = new BMessageRunner(messenger, fPulseMessage, 1000000);
26 	status = fPulseRunner->InitCheck();
27 	if (status != B_OK) {
28 		fInitCheck = status;
29 		fprintf(stderr, "AddOnMonitor() : bad status returned by fPulseRunner->InitCheck()\n");
30 		return;
31 	}
32 	thread_id id = Run();
33 	if (id < 0) {
34 		fInitCheck = (status_t)id;
35 		fprintf(stderr, "AddOnMonitor() : bad id returned by Run()\n");
36 		return;
37 	}
38 	fInitCheck = B_OK;
39 	return;
40 }
41 
42 
43 /* virtual */
44 AddOnMonitor::~AddOnMonitor()
45 {
46 	delete fPulseMessage;
47 	delete fPulseRunner;
48 }
49 
50 
51 /* virtual */ status_t
52 AddOnMonitor::InitCheck()
53 {
54 	return fInitCheck;
55 }
56