2 * Copyright 2014, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
7 #include "PackageWatchingManager.h"
11 #include <package/PackageRoster.h>
13 #include <RegistrarDefs.h>
16 #include "EventMaskWatcher.h"
19 using namespace BPackageKit
;
20 using namespace BPrivate
;
23 PackageWatchingManager::PackageWatchingManager()
28 PackageWatchingManager::~PackageWatchingManager()
34 PackageWatchingManager::HandleStartStopWatching(BMessage
* request
)
36 status_t error
= request
->what
== B_REG_PACKAGE_START_WATCHING
37 ? _AddWatcher(request
) : _RemoveWatcher(request
);
40 BMessage
reply(B_REG_SUCCESS
);
41 request
->SendReply(&reply
);
43 BMessage
reply(B_REG_ERROR
);
44 reply
.AddInt32("error", error
);
45 request
->SendReply(&reply
);
51 PackageWatchingManager::NotifyWatchers(BMessage
* message
)
54 if (message
->FindInt32("event", &event
) != B_OK
) {
55 WARNING("No event field in notification message\n");
61 case B_INSTALLATION_LOCATION_PACKAGES_CHANGED
:
62 eventMask
= B_WATCH_PACKAGE_INSTALLATION_LOCATIONS
;
65 WARNING("Invalid event: %" B_PRId32
"\n", event
);
69 EventMaskWatcherFilter
filter(eventMask
);
70 fWatchingService
.NotifyWatchers(message
, &filter
);
75 PackageWatchingManager::_AddWatcher(const BMessage
* request
)
80 if ((error
= request
->FindMessenger("target", &target
)) != B_OK
81 || (error
= request
->FindUInt32("events", &eventMask
)) != B_OK
) {
85 Watcher
* watcher
= new(std::nothrow
) EventMaskWatcher(target
, eventMask
);
86 if (watcher
== NULL
|| !fWatchingService
.AddWatcher(watcher
)) {
96 PackageWatchingManager::_RemoveWatcher(const BMessage
* request
)
100 if ((error
= request
->FindMessenger("target", &target
)) != B_OK
)
103 if (!fWatchingService
.RemoveWatcher(target
))