diff options
author | Anna Arad <4895022+annagrram@users.noreply.github.com> | 2019-12-27 19:02:20 +0100 |
---|---|---|
committer | Mischievous Meerkat <engineerarun@gmail.com> | 2019-12-27 23:32:20 +0530 |
commit | fd9fcf741e6660a1344dafd33956fcdc64fdc643 (patch) | |
tree | 5d202c1d5691f54571def4edc285b7e9282942fa /misc/haiku/nm.cpp | |
parent | d3ddff6690aa27e02e4fb3504830137b2d7da5ef (diff) | |
download | nnn-fd9fcf741e6660a1344dafd33956fcdc64fdc643.tar.gz |
Get nnn compile and run on Haiku (#403)
* Add support for Haiku OS
* Adjust DISTFILES and dist rule in haiku
Diffstat (limited to 'misc/haiku/nm.cpp')
-rw-r--r-- | misc/haiku/nm.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/misc/haiku/nm.cpp b/misc/haiku/nm.cpp new file mode 100644 index 0000000..ede1d37 --- /dev/null +++ b/misc/haiku/nm.cpp @@ -0,0 +1,83 @@ +#include <Directory.h> +#include <Looper.h> +#include <NodeMonitor.h> +#include <MessageFilter.h> + +#include "haiku_interop.h" + +filter_result dir_mon_flt(BMessage *message, BHandler **hnd, BMessageFilter *fltr) { + (void) hnd; + (void) fltr; + + if (message->what == B_NODE_MONITOR) { + int32 val; + message->FindInt32("opcode", &val); + + switch (val) { + case B_ENTRY_CREATED: + case B_ENTRY_MOVED: + case B_ENTRY_REMOVED: + return B_DISPATCH_MESSAGE; + } + } + + return B_SKIP_MESSAGE; +} + +class DirectoryListener : public BLooper { +public: + bool recv_reset() { + Lock(); + bool val = _ev_on; + _ev_on = false; + Unlock(); + + return val; + } +private: + void MessageReceived(BMessage * message) override { + Lock(); + _ev_on = true; + Unlock(); + BLooper::MessageReceived(message); + } + + bool _ev_on = false; +}; + +struct haiku_nm_t { + haiku_nm_t() { + dl = new DirectoryListener(); + flt = new BMessageFilter(B_PROGRAMMED_DELIVERY, B_LOCAL_SOURCE, dir_mon_flt); + dl->AddCommonFilter(flt); + dl->Run(); + } + + DirectoryListener *dl; + BMessageFilter *flt; + node_ref nr; +}; + +haiku_nm_h haiku_init_nm() { + return new haiku_nm_t(); +} + +void haiku_close_nm(haiku_nm_h hnd) { + delete hnd->flt; + // This is the way of deleting a BLooper + hnd->dl->PostMessage(B_QUIT_REQUESTED); + delete hnd; +} +int haiku_watch_dir(haiku_nm_h hnd, const char *path) { + BDirectory dir(path); + dir.GetNodeRef(&(hnd->nr)); + + return watch_node(&(hnd->nr), B_WATCH_DIRECTORY, nullptr, hnd->dl); +} +int haiku_stop_watch(haiku_nm_h hnd) { + return watch_node(&(hnd->nr), B_STOP_WATCHING, nullptr, hnd->dl); +} + +int haiku_is_update_needed(haiku_nm_h hnd) { + return hnd->dl->recv_reset(); +} |