2015-04-23 19:26:54 +00:00
|
|
|
/*
|
|
|
|
* \brief File-system node
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2012-04-11
|
|
|
|
*/
|
|
|
|
|
2017-06-20 12:23:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012-2017 Genode Labs GmbH
|
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
|
|
|
*/
|
|
|
|
|
2015-04-23 19:26:54 +00:00
|
|
|
#ifndef _FILE_SYSTEM__NODE_H_
|
|
|
|
#define _FILE_SYSTEM__NODE_H_
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <file_system/listener.h>
|
|
|
|
#include <util/list.h>
|
|
|
|
#include <base/lock.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace File_system {
|
|
|
|
|
|
|
|
class Node_base
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2016-01-07 09:52:10 +00:00
|
|
|
Genode::List<Listener> _listeners;
|
2015-04-23 19:26:54 +00:00
|
|
|
|
2017-06-28 12:42:45 +00:00
|
|
|
typedef Listener::Version Version;
|
|
|
|
|
|
|
|
Version _curr_version { 0 };
|
|
|
|
|
2015-04-23 19:26:54 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
virtual ~Node_base()
|
|
|
|
{
|
|
|
|
/* propagate event to listeners */
|
|
|
|
mark_as_updated();
|
|
|
|
notify_listeners();
|
|
|
|
|
|
|
|
while (_listeners.first())
|
|
|
|
_listeners.remove(_listeners.first());
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_listener(Listener *listener)
|
|
|
|
{
|
|
|
|
_listeners.insert(listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
void remove_listener(Listener *listener)
|
|
|
|
{
|
|
|
|
_listeners.remove(listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
void notify_listeners()
|
|
|
|
{
|
|
|
|
for (Listener *curr = _listeners.first(); curr; curr = curr->next())
|
2017-06-28 12:42:45 +00:00
|
|
|
curr->notify(_curr_version);
|
2015-04-23 19:26:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void mark_as_updated()
|
|
|
|
{
|
2017-06-28 12:42:45 +00:00
|
|
|
_curr_version = Version { _curr_version.value + 1 };
|
2015-04-23 19:26:54 +00:00
|
|
|
}
|
2017-06-28 12:42:45 +00:00
|
|
|
|
|
|
|
Version curr_version() const { return _curr_version; }
|
2015-04-23 19:26:54 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _FILE_SYSTEM__NODE_H_ */
|