-
Notifications
You must be signed in to change notification settings - Fork 610
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added basic features for Rubinius::FSEvent.
- Loading branch information
Showing
9 changed files
with
176 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module Rubinius | ||
class FSEvent | ||
attr_accessor :fileno | ||
attr_accessor :path | ||
|
||
def self.allocate | ||
Rubinius.primitive :fsevent_allocate | ||
raise PrimitiveFailure, "Rubinius::FSEvent.allocate failed" | ||
end | ||
|
||
def watch_file(fd, path) | ||
Rubinius.primitive :fsevent_watch_file | ||
raise PrimitiveFailure, "Rubinius::FSEvent#watch_file failed" | ||
end | ||
|
||
def wait_for_event | ||
Rubinius.primitive :fsevent_wait_for_event | ||
raise PrimitiveFailure, "Rubinius::FSEvent#wait_for_event failed" | ||
end | ||
|
||
def inspect | ||
str = "#<#{self.class}:0x#{self.__id__.to_s(16)}" | ||
|
||
str << " fileno=#{fileno}" if fileno | ||
str << " path=#{path}" if path | ||
str << ">" | ||
|
||
Rubinius::Type.infect str, self | ||
|
||
str | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ signal.rbc | |
struct.rbc | ||
thread.rbc | ||
code_loader.rbc | ||
fsevent.rbc | ||
console.rbc | ||
ffi.rbc | ||
ruby_constants.rbc | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "builtin/class.hpp" | ||
#include "builtin/fixnum.hpp" | ||
#include "builtin/fsevent.hpp" | ||
#include "builtin/string.hpp" | ||
|
||
#include "ontology.hpp" | ||
|
||
namespace rubinius { | ||
void FSEvent::init(STATE) { | ||
GO(fsevent).set(ontology::new_class_under(state, "FSEvent", G(rubinius))); | ||
G(fsevent)->set_object_type(state, FSEventType); | ||
} | ||
|
||
#ifdef HAVE_KQUEUE | ||
FSEvent* FSEvent::create(STATE) { | ||
FSEvent* fsevent = state->new_object<FSEvent>(G(fsevent)); | ||
fsevent->kq_ = kqueue(); | ||
return fsevent; | ||
} | ||
|
||
FSEvent* FSEvent::allocate(STATE, Object* self) { | ||
FSEvent* fsevent = create(state); | ||
fsevent->klass(state, as<Class>(self)); | ||
return fsevent; | ||
} | ||
|
||
Object* FSEvent::watch_file(STATE, Fixnum* fd, String* path) { | ||
this->fileno(state, fd); | ||
this->path(state, path); | ||
|
||
EV_SET(&filter_, fd->to_native(), EVFILT_VNODE, | ||
EV_ADD | EV_ENABLE | EV_CLEAR, NOTE_WRITE, 0, NULL); | ||
|
||
return cNil; | ||
} | ||
|
||
Object* FSEvent::watch_file(STATE, int fd, const char* path) { | ||
return watch_file(state, Fixnum::from(fd), String::create(state, path)); | ||
} | ||
|
||
Object* FSEvent::wait_for_event() { | ||
int status = kevent(kq_, &filter_, 1, &event_, 1, NULL); | ||
|
||
if(status < 0 || !(event_.fflags & NOTE_WRITE)) { | ||
return cNil; | ||
} | ||
|
||
return cTrue; | ||
} | ||
#elif HAVE_INOTIFY | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#ifndef RBX_FSEVENT_HPP | ||
#define RBX_FSEVENT_HPP | ||
|
||
#include "builtin/object.hpp" | ||
|
||
#ifdef HAVE_KQUEUE | ||
#include <sys/types.h> | ||
#include <sys/event.h> | ||
#include <sys/time.h> | ||
#elif HAVE_INOTIFY | ||
#else | ||
#error "No file system event utility is available. Please submit an issue." | ||
#endif | ||
|
||
namespace rubinius { | ||
class Fixnum; | ||
class String; | ||
|
||
class FSEvent : public Object { | ||
public: | ||
const static object_type type = FSEventType; | ||
|
||
private: | ||
Fixnum* fileno_; // slot | ||
String* path_; // slot | ||
|
||
public: | ||
/* accessors */ | ||
|
||
attr_accessor(fileno, Fixnum); | ||
attr_accessor(path, String); | ||
|
||
#ifdef HAVE_KQUEUE | ||
private: | ||
int kq_; | ||
struct kevent filter_; | ||
struct kevent event_; | ||
|
||
#elif HAVE_INOTIFY | ||
#endif | ||
|
||
public: | ||
static void init(STATE); | ||
|
||
static FSEvent* create(STATE); | ||
|
||
// Rubinius.primitive+ :fsevent_allocate | ||
static FSEvent* allocate(STATE, Object* self); | ||
|
||
// Rubinius.primitive :fsevent_watch_file | ||
Object* watch_file(STATE, Fixnum* fd, String* path); | ||
Object* watch_file(STATE, int fd, const char* path); | ||
|
||
// Rubinius.primitive :fsevent_wait_for_event | ||
Object* wait_for_event(); | ||
|
||
class Info : public TypeInfo { | ||
public: | ||
BASIC_TYPEINFO(TypeInfo) | ||
}; | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters