Browse Source

port notify.h over to inotify-tools

master
gradient 8 years ago
parent
commit
c2fcaa4c6d
2 changed files with 16 additions and 30 deletions
  1. +1
    -0
      CMakeLists.txt
  2. +15
    -30
      src/notify.h

+ 1
- 0
CMakeLists.txt View File

@ -33,4 +33,5 @@ target_link_libraries(zinnia ${OPENGL_LIBRARIES})
target_link_libraries(zinnia ${GLFW_LIBRARIES}) target_link_libraries(zinnia ${GLFW_LIBRARIES})
target_link_libraries(zinnia gl3w) target_link_libraries(zinnia gl3w)
target_link_libraries(zinnia ${GTK3_LIBRARIES}) target_link_libraries(zinnia ${GTK3_LIBRARIES})
target_link_libraries(zinnia inotifytools)
#target_link_libraries(zinnia ${CMAKE_SOURCE_DIR}/deps/nfd/build/lib/Release/x64/libnfd.a) #target_link_libraries(zinnia ${CMAKE_SOURCE_DIR}/deps/nfd/build/lib/Release/x64/libnfd.a)

+ 15
- 30
src/notify.h View File

@ -11,48 +11,33 @@ typedef void (Project::*ProjectReloadFn)();
class NotifyService { class NotifyService {
public: public:
NotifyService() { NotifyService() {
this->inotify_fd = inotify_init1(IN_NONBLOCK);
if (inotify_fd == -1) {
perror("inotify_init1");
if (!inotifytools_initialize()) {
fprintf(stderr, "inotifytools init error: %s\n", strerror(inotifytools_error()));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
std::cout << "inotify fd: " << inotify_fd << '\n';
this->poll_fd = {.fd = inotify_fd, .events = POLLIN, 0};
} }
void watch(Project &project) { void watch(Project &project) {
int wd = inotify_add_watch(this->inotify_fd, project.basepath.str().c_str(),
IN_MODIFY);
if (wd == -1) {
std::cerr << "Failed to watch project base directory: " << project.basepath.str().c_str() << '\n';
perror("inotify_add_watch");
exit(EXIT_FAILURE);
}
std::cerr << "Watching " << project.basepath << " with wd: " << wd << '\n';
this->watch_ids.push_back(wd);
inotifytools_watch_recursively(project.basepath.str().c_str(),
IN_MODIFY | IN_MOVED_TO);
} }
void _poll() { void _poll() {
int rc = poll(&this->poll_fd, 1, 0);
std::cout << "poll() -> " << rc << '\n';
if (rc == -1) {
if (errno == EINTR)
return;
perror("poll");
struct inotify_event *event = inotifytools_next_event(0);
if (inotifytools_error() == EINTR)
return;
if (inotifytools_error() != 0) {
fprintf(stderr, "inotifytools event error: %s\n", strerror(inotifytools_error()));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (rc > 0) {
std::cout << "poll data available!\n";
if (event != NULL) {
std::cout << "new inotify event! file: " << event->name << '\n';
std::cout << "filename: " << inotifytools_filename_from_wd(event->wd) << '\n';
} }
} }
private: private:
int inotify_fd;
struct pollfd poll_fd;
std::vector<int> watch_ids;
}; };

Loading…
Cancel
Save