repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / kits / storage / AddOnMonitor.cpp
blob304fcc34c39e3a7241024a2787a16a1921e4847d
1 /*
2 * Copyright 2004-2010, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Andrew Bachmann
7 */
10 #include "AddOnMonitor.h"
11 #include "AddOnMonitorHandler.h"
12 #include <Message.h>
13 #include <MessageRunner.h>
14 #include <Messenger.h>
15 #include <stdio.h>
18 AddOnMonitor::AddOnMonitor()
20 BLooper("AddOnMonitor"),
21 fInitCheck(B_NO_INIT),
22 fPulseRunner(NULL)
27 AddOnMonitor::AddOnMonitor(AddOnMonitorHandler* handler)
29 BLooper("AddOnMonitor"),
30 fInitCheck(B_NO_INIT),
31 fPulseRunner(NULL)
33 SetHandler(handler);
35 thread_id id = Run();
36 if (id < 0) {
37 fInitCheck = (status_t)id;
38 fprintf(stderr, "AddOnMonitor() : bad id returned by Run()\n");
39 return;
44 AddOnMonitor::~AddOnMonitor()
46 delete fPulseRunner;
50 status_t
51 AddOnMonitor::InitCheck()
53 return fInitCheck;
57 void
58 AddOnMonitor::SetHandler(AddOnMonitorHandler* handler)
60 if (handler == NULL)
61 return;
63 AddHandler(handler);
64 SetPreferredHandler(handler);
66 delete fPulseRunner;
67 fPulseRunner = NULL;
69 status_t status;
70 BMessenger messenger(handler, this, &status);
71 if (status != B_OK) {
72 fInitCheck = status;
73 return;
76 BMessage pulseMessage(B_PULSE);
77 fPulseRunner = new(std::nothrow) BMessageRunner(messenger, &pulseMessage,
78 1000000);
79 if (fPulseRunner == NULL) {
80 fInitCheck = B_NO_MEMORY;
81 return;
84 status = fPulseRunner->InitCheck();
85 if (status != B_OK) {
86 fInitCheck = status;
87 fprintf(stderr, "AddOnMonitor() : bad status returned by "
88 "fPulseRunner->InitCheck()\n");
89 return;
92 // Send an initial message to process added directories immediately
93 messenger.SendMessage(&pulseMessage);
95 fInitCheck = B_OK;