My build of nnn with minor changes
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

84 lignes
1.6 KiB

  1. #include <Directory.h>
  2. #include <Looper.h>
  3. #include <NodeMonitor.h>
  4. #include <MessageFilter.h>
  5. #include "haiku_interop.h"
  6. filter_result dir_mon_flt(BMessage *message, BHandler **hnd, BMessageFilter *fltr) {
  7. (void) hnd;
  8. (void) fltr;
  9. if (message->what == B_NODE_MONITOR) {
  10. int32 val;
  11. message->FindInt32("opcode", &val);
  12. switch (val) {
  13. case B_ENTRY_CREATED:
  14. case B_ENTRY_MOVED:
  15. case B_ENTRY_REMOVED:
  16. return B_DISPATCH_MESSAGE;
  17. }
  18. }
  19. return B_SKIP_MESSAGE;
  20. }
  21. class DirectoryListener : public BLooper {
  22. public:
  23. bool recv_reset() {
  24. Lock();
  25. bool val = _ev_on;
  26. _ev_on = false;
  27. Unlock();
  28. return val;
  29. }
  30. private:
  31. void MessageReceived(BMessage * message) override {
  32. Lock();
  33. _ev_on = true;
  34. Unlock();
  35. BLooper::MessageReceived(message);
  36. }
  37. bool _ev_on = false;
  38. };
  39. struct haiku_nm_t {
  40. haiku_nm_t() {
  41. dl = new DirectoryListener();
  42. flt = new BMessageFilter(B_PROGRAMMED_DELIVERY, B_LOCAL_SOURCE, dir_mon_flt);
  43. dl->AddCommonFilter(flt);
  44. dl->Run();
  45. }
  46. DirectoryListener *dl;
  47. BMessageFilter *flt;
  48. node_ref nr;
  49. };
  50. haiku_nm_h haiku_init_nm() {
  51. return new haiku_nm_t();
  52. }
  53. void haiku_close_nm(haiku_nm_h hnd) {
  54. delete hnd->flt;
  55. // This is the way of deleting a BLooper
  56. hnd->dl->PostMessage(B_QUIT_REQUESTED);
  57. delete hnd;
  58. }
  59. int haiku_watch_dir(haiku_nm_h hnd, const char *path) {
  60. BDirectory dir(path);
  61. dir.GetNodeRef(&(hnd->nr));
  62. return watch_node(&(hnd->nr), B_WATCH_DIRECTORY, nullptr, hnd->dl);
  63. }
  64. int haiku_stop_watch(haiku_nm_h hnd) {
  65. return watch_node(&(hnd->nr), B_STOP_WATCHING, nullptr, hnd->dl);
  66. }
  67. int haiku_is_update_needed(haiku_nm_h hnd) {
  68. return hnd->dl->recv_reset();
  69. }