Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add watching support for installation location package changes
Can be requested/stopped via BPackageRoster::{Start,Stop}Watching(). The notification message has the what code B_PACKAGE_UPDATE and contains fields "event", "location", and "change count".
- Loading branch information
Showing
11 changed files
with
271 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
SubDir HAIKU_TOP src kits package ; | ||
|
||
UsePrivateHeaders | ||
app | ||
kernel | ||
shared | ||
storage | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright 2014, Ingo Weinhold, ingo_weinhold@gmx.de. | ||
* Distributed under the terms of the MIT License. | ||
*/ | ||
|
||
|
||
#include "PackageWatchingManager.h" | ||
|
||
#include <new> | ||
|
||
#include <package/PackageRoster.h> | ||
|
||
#include <RegistrarDefs.h> | ||
|
||
#include "Debug.h" | ||
#include "EventMaskWatcher.h" | ||
|
||
|
||
using namespace BPackageKit; | ||
using namespace BPrivate; | ||
|
||
|
||
PackageWatchingManager::PackageWatchingManager() | ||
{ | ||
} | ||
|
||
|
||
PackageWatchingManager::~PackageWatchingManager() | ||
{ | ||
} | ||
|
||
|
||
void | ||
PackageWatchingManager::HandleStartStopWatching(BMessage* request) | ||
{ | ||
status_t error = request->what == B_REG_PACKAGE_START_WATCHING | ||
? _AddWatcher(request) : _RemoveWatcher(request); | ||
|
||
if (error == B_OK) { | ||
BMessage reply(B_REG_SUCCESS); | ||
request->SendReply(&reply); | ||
} else { | ||
BMessage reply(B_REG_ERROR); | ||
reply.AddInt32("error", error); | ||
request->SendReply(&reply); | ||
} | ||
} | ||
|
||
|
||
void | ||
PackageWatchingManager::NotifyWatchers(BMessage* message) | ||
{ | ||
int32 event; | ||
if (message->FindInt32("event", &event) != B_OK) { | ||
WARNING("No event field in notification message\n"); | ||
return; | ||
} | ||
|
||
uint32 eventMask; | ||
switch (event) { | ||
case B_INSTALLATION_LOCATION_PACKAGES_CHANGED: | ||
eventMask = B_WATCH_PACKAGE_INSTALLATION_LOCATIONS; | ||
break; | ||
default: | ||
WARNING("Invalid event: %" B_PRId32 "\n", event); | ||
return; | ||
} | ||
|
||
EventMaskWatcherFilter filter(eventMask); | ||
fWatchingService.NotifyWatchers(message, &filter); | ||
} | ||
|
||
|
||
status_t | ||
PackageWatchingManager::_AddWatcher(const BMessage* request) | ||
{ | ||
BMessenger target; | ||
uint32 eventMask; | ||
status_t error; | ||
if ((error = request->FindMessenger("target", &target)) != B_OK | ||
|| (error = request->FindUInt32("events", &eventMask)) != B_OK) { | ||
return error; | ||
} | ||
|
||
Watcher* watcher = new(std::nothrow) EventMaskWatcher(target, eventMask); | ||
if (watcher == NULL || !fWatchingService.AddWatcher(watcher)) { | ||
delete watcher; | ||
return B_NO_MEMORY; | ||
} | ||
|
||
return B_OK; | ||
} | ||
|
||
|
||
status_t | ||
PackageWatchingManager::_RemoveWatcher(const BMessage* request) | ||
{ | ||
BMessenger target; | ||
status_t error; | ||
if ((error = request->FindMessenger("target", &target)) != B_OK) | ||
return error; | ||
|
||
if (!fWatchingService.RemoveWatcher(target)) | ||
return B_BAD_VALUE; | ||
|
||
return B_OK; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2014, Ingo Weinhold, ingo_weinhold@gmx.de. | ||
* Distributed under the terms of the MIT License. | ||
*/ | ||
#ifndef PACKAGE_WATCHING_MANAGER_H | ||
#define PACKAGE_WATCHING_MANAGER_H | ||
|
||
|
||
#include "WatchingService.h" | ||
|
||
|
||
class PackageWatchingManager { | ||
public: | ||
PackageWatchingManager(); | ||
~PackageWatchingManager(); | ||
|
||
void HandleStartStopWatching(BMessage* request); | ||
void NotifyWatchers(BMessage* message); | ||
|
||
private: | ||
status_t _AddWatcher(const BMessage* request); | ||
status_t _RemoveWatcher(const BMessage* request); | ||
|
||
private: | ||
WatchingService fWatchingService; | ||
}; | ||
|
||
|
||
#endif // PACKAGE_WATCHING_MANAGER_H |
Oops, something went wrong.