Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refactoring

  • Loading branch information...
commit 49a5dbaabcee41b8f218f904732b036569fdaab9 1 parent 8410457
@afelix authored
View
55 ninotify.js
@@ -1,20 +1,45 @@
-var ninotify = require('./lib/build/default/ninotify.node');
+var ninotify = require('./src/build/default/ninotify.node'),
+ fswapi = require('fswatch/lib/fswatchapi'),
+ fsw2ni = {},
+ ni2fsw = {};
-exports.IN_ACCESS = ninotify.IN_ACCESS;
-exports.IN_MODIFY = ninotify.IN_MODIFY;
-exports.IN_ATTRIB = ninotify.IN_ATTRIB;
-exports.IN_CLOSE_WRITE = ninotify.IN_CLOSE_WRITE;
-exports.IN_CLOSE_NOWRITE = ninotify.IN_CLOSE_NOWRITE;
-exports.IN_OPEN = ninotify.IN_OPEN;
-exports.IN_MOVED_FROM = ninotify.IN_MOVED_FROM;
-exports.IN_MOVED_TO = ninotify.IN_MOVED_TO;
-exports.IN_CREATE = ninotify.IN_CREATE;
-exports.IN_DELETE = ninotify.IN_DELETE;
-exports.IN_DELETE_SELF = ninotify.IN_DELETE_SELF;
+fsw2ni[fswapi.CREATE] = ninotify.IN_CREATE | ninotify.IN_MOVED_TO;
+fsw2ni[fswapi.DELETE] = ninotify.IN_DELETE | ninotify.IN_DELETE_SELF | ninotify.IN_MOVED_FROM;
+fsw2ni[fswapi.MODIFY] = ninotify.IN_MODIFY;
+fsw2ni[fswapi.STATS_CHANGED] = ninotify.IN_ATTR;
+fsw2ni[fswapi.ALL] = ninotify.IN_CREATE | ninotify.IN_DELETE | ninotify.IN_DELETE_SELF |
+ ninotify.IN_MODIFY | ninotify.IN_ATTR | ninotify.IN_MOVED_TO | ninotify.IN_MOVED_FROM;
-exports.addWatch = ninotify.addWatch;
+ni2fsw[ninotify.IN_CREATE] = fswapi.CREATE;
+ni2fsw[ninotify.IN_DELETE] = fswapi.DELETE;
+ni2fsw[ninotify.IN_DELETE_SELF] = fswapi.DELETE;
+ni2fsw[ninotify.IN_MODIFY] = fswapi.MODIFY;
+ni2fsw[ninotify.IN_ATTR] = fswapi.STATS_CHANGED;
+ni2fsw[ninotify.IN_MOVED_FROM] = fswapi.DELETE;
+ni2fsw[ninotify.IN_MOVED_TO] = fswapi.CREATE;
-exports.removeWatch = ninotify.removeWatch;
+exports.watcherid = 'ninotify';
-exports.removeAllWatches = ninotify.removeAllWatches;
+exports.parserid = 'ninotify';
+exports.parse = function(event) {
+ var i = 0;
+
+ return {
+ type: event.substring(i, i = event.indexOf(' ', i)),
+ mask: convertMask(new Number(event.substring(i + 1, i = event.indexOf(' ', i + 1))), ni2fsw),
+ path: event.substring(i + 1, event.length)
+ }
+};
+
+exports.addPath = function(path, mask, evpath) {
+ ninotify.addWatch(path, convertMask(new Number(mask), fsw2ni), evpath);
+};
+
+function convertMask(mask, values) {
+ var m = 0;
+
+ for (var k in values) if (mask & k) m |= values[k];
+
+ return m;
+}
View
8 package.json
@@ -1,7 +1,7 @@
{
"name" : "ninotify",
"description" : "Node.js inotify addon",
- "version" : "0.0.3",
+ "version" : "0.0.4",
"homepage": "http://github.com/afelix/ninotify",
"author" : "Sergey Kryzhanovsky <skryzhanovsky@gmail.com> (http://github.com/afelix)",
"repository" : {
@@ -9,10 +9,10 @@
"url" : "http://github.com/afelix/ninotify.git"
},
"main" : "ninotify",
- "directories" : { "lib" : "./lib" },
+ "directories" : { "src" : "./src" },
"scripts" : {
- "preinstall" : "cd lib && node-waf configure",
- "install" : "cd lib && node-waf build"
+ "preinstall" : "cd src && node-waf configure",
+ "install" : "cd src && node-waf build"
},
"engines" : { "node" : ">=0.4.0" },
"licenses" : [ { "type" : "AS IS" } ]
View
2  lib/ninotify.cc → src/ninotify.cc
@@ -125,7 +125,7 @@ static void Callback(EV_P_ ev_io *w, int revents) {
string file_path = event->len ? niStruct.ni_pairs[event->wd].watched_file + "/" + event->name : niStruct.ni_pairs[event->wd].watched_file;
ofstream events_file;
events_file.open(niStruct.ni_pairs[event->wd].events_file.c_str(), ios::out | ios::app);
- events_file << "ninotify " << event->wd << " " << event->mask << " " << file_path << "\n";
+ events_file << "ninotify " << event->mask << " " << file_path << "\n";
events_file.close();
i += EVENT_SIZE + event->len;
}
View
0  lib/ninotify.h → src/ninotify.h
File renamed without changes
View
2  lib/wscript → src/wscript
@@ -1,6 +1,6 @@
srcdir = '.'
blddir = 'build'
-VERSION = '0.0.1'
+VERSION = '0.0.4'
def set_options(opt):
opt.tool_options('compiler_cxx')
Please sign in to comment.
Something went wrong with that request. Please try again.