bonefish+axeld:

* Simplified the notification framework: removed the updater stuff completely;
  it was only there to account for some peculiarities of the node monitor which
  we now solved differently.
* NotificationListener no longer includes a doubly linked list link for convenience;
  it might want to listen to more than just one service.
* NotificationService cannot have an abstract destructor.
* Changed the _user_stop_watching() syscall to mirror the Be API; ie. it's no
  longer possible to just remove some flags separately, just to stop listening
  completely.
* Adapted the node monitor implementation to live in the NodeMonitorService class
  that uses the new notification framework.
* Removed the public kernel node monitor API - it wasn't useful that way since you
  couldn't do a lot with the KMessage in the kernel without using a private API.
  Now you will have to use the (private) notification manager to use the node monitor
  from inside the kernel. At a later point, we might introduce a public API for that,
  too.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21780 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2007-08-01 14:48:44 +00:00
parent 5102d49461
commit edb15b5565
8 changed files with 931 additions and 876 deletions
-22
View File
@@ -1,22 +0,0 @@
/* Node monitor calls for kernel add-ons
**
** Distributed under the terms of the OpenBeOS License.
*/
#ifndef _DRIVERS_NODE_MONITOR_H
#define _DRIVERS_NODE_MONITOR_H
#include <OS.h>
#include <storage/NodeMonitor.h>
extern status_t stop_notifying(port_id port, uint32 token);
extern status_t start_watching(dev_t device, ino_t node, uint32 flags,
port_id port, uint32 token);
extern status_t stop_watching(dev_t device, ino_t node, uint32 flags,
port_id port, uint32 token);
// ToDo: add simple message parsing convenience functionality
#endif /* _DRIVERS_NODE_MONITOR_H */
+18 -54
View File
@@ -22,21 +22,24 @@
#include <Referenceable.h>
#include <util/AutoLock.h>
#include <util/DoublyLinkedList.h>
#include <util/KMessage.h>
#include <util/OpenHashTable.h>
class NotificationService;
class NotificationListener
: public DoublyLinkedListLinkImpl<NotificationListener> {
class NotificationListener {
public:
virtual ~NotificationListener();
virtual void EventOccured(NotificationService& service,
const KMessage* event);
virtual void AllListenersNotified();
virtual void AllListenersNotified(NotificationService& service);
virtual bool operator==(const NotificationListener& other) const;
bool operator!=(const NotificationListener& other) const
{ return !(*this == other); }
};
class UserMessagingMessageSender {
@@ -64,10 +67,10 @@ class UserMessagingListener : public NotificationListener {
virtual void EventOccured(NotificationService& service,
const KMessage* event);
virtual void AllListenersNotified();
virtual void AllListenersNotified(NotificationService& service);
port_id Port() { return fPort; }
int32 Token() { return fToken; }
port_id Port() const { return fPort; }
int32 Token() const { return fToken; }
private:
UserMessagingMessageSender& fSender;
@@ -75,55 +78,16 @@ class UserMessagingListener : public NotificationListener {
int32 fToken;
};
class NotificationListenerUpdater {
public:
enum update_action {
UPDATED,
SKIP,
DELETE,
REMOVE
};
NotificationListenerUpdater(const KMessage* eventSpecifier);
virtual ~NotificationListenerUpdater();
virtual status_t UpdateListener(NotificationListener& listener,
enum update_action& action);
virtual status_t CreateListener(NotificationListener** _listener);
virtual void SetEventSpecifier(const KMessage* eventSpecifier);
const KMessage* EventSpecifier() const { return fEventSpecifier; }
protected:
const KMessage* fEventSpecifier;
};
class UserMessagingListenerUpdater : public NotificationListenerUpdater {
public:
UserMessagingListenerUpdater(const KMessage* eventSpecifier, port_id port,
int32 token);
virtual status_t UpdateListener(NotificationListener& listener,
enum update_action& action);
protected:
virtual status_t UpdateListener(UserMessagingListener& listener,
enum update_action& action) = 0;
port_id fPort;
int32 fToken;
};
class NotificationService : public Referenceable {
public:
virtual ~NotificationService() = 0;
virtual ~NotificationService();
virtual status_t AddListener(const KMessage* eventSpecifier,
NotificationListener& listener) = 0;
virtual status_t RemoveListener(const KMessage* eventSpecifier,
NotificationListener& listener) = 0;
virtual status_t UpdateListener(NotificationListenerUpdater& updater) = 0;
virtual status_t UpdateListener(const KMessage* eventSpecifier,
NotificationListener& listener) = 0;
virtual const char* Name() = 0;
HashTableLink<NotificationService>& Link() { return fLink; }
@@ -148,13 +112,13 @@ class NotificationManager {
status_t AddListener(const char* service,
const KMessage* eventSpecifier, NotificationListener& listener);
status_t RemoveListener(const char* service, uint32 eventMask,
NotificationListener& listener);
status_t RemoveListener(const char* service,
status_t UpdateListener(const char* service,
uint32 eventMask, NotificationListener& listener);
status_t UpdateListener(const char* service,
const KMessage* eventSpecifier, NotificationListener& listener);
status_t UpdateListener(const char* service,
NotificationListenerUpdater& updater);
status_t RemoveListener(const char* service,
const KMessage* eventSpecifier, NotificationListener& listener);
private:
NotificationManager();
+2 -2
View File
@@ -26,8 +26,8 @@ extern status_t notify_mount(dev_t device, dev_t parentDevice,
extern status_t _user_stop_notifying(port_id port, uint32 token);
extern status_t _user_start_watching(dev_t device, ino_t node, uint32 flags,
port_id port, uint32 token);
extern status_t _user_stop_watching(dev_t device, ino_t node, uint32 flags,
port_id port, uint32 token);
extern status_t _user_stop_watching(dev_t device, ino_t node, port_id port,
uint32 token);
#ifdef __cplusplus
}
+2 -2
View File
@@ -201,8 +201,8 @@ extern status_t _kern_get_next_fd_info(team_id team, uint32 *_cookie,
extern status_t _kern_stop_notifying(port_id port, uint32 token);
extern status_t _kern_start_watching(dev_t device, ino_t node, uint32 flags,
port_id port, uint32 token);
extern status_t _kern_stop_watching(dev_t device, ino_t node, uint32 flags,
port_id port, uint32 token);
extern status_t _kern_stop_watching(dev_t device, ino_t node, port_id port,
uint32 token);
// time functions
extern status_t _kern_set_real_time_clock(uint32 time);
+1 -1
View File
@@ -56,7 +56,7 @@ watch_node(const node_ref *node, uint32 flags, BMessenger target)
if (node == NULL)
return B_BAD_VALUE;
return _kern_stop_watching(node->device, node->node, flags, port, token);
return _kern_stop_watching(node->device, node->node, port, token);
}
// subscribe to...
+29 -90
View File
@@ -30,11 +30,18 @@ NotificationListener::EventOccured(NotificationService& service,
void
NotificationListener::AllListenersNotified()
NotificationListener::AllListenersNotified(NotificationService& service)
{
}
bool
NotificationListener::operator==(const NotificationListener& other) const
{
return &other == this;
}
// #pragma mark - UserMessagingMessageSender
@@ -102,86 +109,18 @@ UserMessagingListener::EventOccured(NotificationService& service,
void
UserMessagingListener::AllListenersNotified()
UserMessagingListener::AllListenersNotified(NotificationService& service)
{
fSender.FlushMessage();
}
// #pragma mark - NotificationListenerUpdater
// #pragma mark - NotificationService
NotificationListenerUpdater::NotificationListenerUpdater(
const KMessage* eventSpecifier)
: fEventSpecifier(eventSpecifier)
{
}
NotificationListenerUpdater::~NotificationListenerUpdater()
{
}
status_t
NotificationListenerUpdater::UpdateListener(NotificationListener& listener,
enum update_action& action)
{
action = SKIP;
return B_OK;
}
status_t
NotificationListenerUpdater::CreateListener(NotificationListener** _listener)
{
return B_ERROR;
}
void
NotificationListenerUpdater::SetEventSpecifier(const KMessage* eventSpecifier)
{
fEventSpecifier = eventSpecifier;
}
// #pragma mark - NotificationListenerUpdater
UserMessagingListenerUpdater::UserMessagingListenerUpdater(
const KMessage* eventSpecifier, port_id port, int32 token)
:
NotificationListenerUpdater(eventSpecifier),
fPort(port),
fToken(token)
{
}
status_t
UserMessagingListenerUpdater::UpdateListener(NotificationListener& _listener,
enum update_action& action)
{
UserMessagingListener* listener
= dynamic_cast<UserMessagingListener*>(&_listener);
if (listener != NULL && listener->Port() == fPort
&& listener->Token() == fToken) {
return UpdateListener(*listener, action);
}
action = SKIP;
return B_OK;
}
// #pragma mark - NotificationManager
#if 0
NotificationService::~NotificationService()
{
}
#endif
// #pragma mark - NotificationManager
@@ -285,15 +224,31 @@ NotificationManager::AddListener(const char* serviceName,
status_t
NotificationManager::RemoveListener(const char* serviceName, uint32 eventMask,
NotificationListener& listener)
NotificationManager::UpdateListener(const char* serviceName,
uint32 eventMask, NotificationListener& listener)
{
char buffer[96];
KMessage specifier;
specifier.SetTo(buffer, sizeof(buffer), 0);
specifier.AddInt32("event mask", eventMask);
return RemoveListener(serviceName, &specifier, listener);
return UpdateListener(serviceName, &specifier, listener);
}
status_t
NotificationManager::UpdateListener(const char* serviceName,
const KMessage* eventSpecifier, NotificationListener& listener)
{
MutexLocker locker(fLock);
NotificationService* service = _ServiceFor(serviceName);
if (service == NULL)
return B_NAME_NOT_FOUND;
Reference<NotificationService> reference(service);
locker.Unlock();
return service->UpdateListener(eventSpecifier, listener);
}
@@ -313,22 +268,6 @@ NotificationManager::RemoveListener(const char* serviceName,
}
status_t
NotificationManager::UpdateListener(const char* serviceName,
NotificationListenerUpdater& updater)
{
MutexLocker locker(fLock);
NotificationService* service = _ServiceFor(serviceName);
if (service == NULL)
return B_NAME_NOT_FOUND;
Reference<NotificationService> reference(service);
locker.Unlock();
return service->UpdateListener(updater);
}
// #pragma mark -
+1 -1
View File
@@ -3,7 +3,7 @@ SubDir HAIKU_TOP src system kernel fs ;
UsePrivateHeaders [ FDirName kernel disk_device_manager ] ;
UsePrivateHeaders [ FDirName kernel fs ] ;
UsePrivateHeaders [ FDirName kernel util ] ;
UsePrivateHeaders storage ;
UsePrivateHeaders shared storage ;
KernelMergeObject kernel_fs.o :
devfs.cpp
File diff suppressed because it is too large Load Diff