Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

latest changes include renamed methods, passing args, and adding the

callback.
  • Loading branch information...
commit 3e618352647ddd0f25b5c7189e115220ad03b167 1 parent 7b4781f
@softorchestra softorchestra authored
View
6 modules/ti.Filesystem/file.cpp
@@ -780,11 +780,11 @@ namespace ti
}
}
- FileWatcher& File::Watch(FileWatcher::EventType event, KValueRef result)
+ FileWatcher& File::Watch(const ValueList& args, KValueRef result)
{
- watcher.StartWatch(event);
+ watcher.watch (args.GetDouble(0), args.GetMethod(1));
- result->SetBool(true);
+ result->SetBool (true);
return this->watcher;
}
}
View
2  modules/ti.Filesystem/file.h
@@ -34,7 +34,7 @@ namespace ti
{
return new string(GetFilename());
}
- FileWatcher& Watch(FileWatcher::EventType event, KValueRef result);
+ FileWatcher& Watch(const ValueList& args, KValueRef result);
private:
std::string filename;
View
15 modules/ti.Filesystem/file_watcher.cpp
@@ -12,7 +12,8 @@ namespace ti
{
FileWatcher::FileWatcher(const char* filepath) :
KEventObject("Filesystem.FileWatcher"),
- readAdapter(*this, &FileWatcher::ReadThread)
+ readAdapter(*this, &FileWatcher::ReadThread),
+ callback(0)
{
notifypath = filepath;
fd = inotify_init();
@@ -52,15 +53,17 @@ namespace ti
strerror(errno), errno);
} else
{
- // need to notify caller here
-
+ ValueList args(Value::NewString ((const char*) readBuffer));
+ this->callback->Call(args);
}
} while(!done);
}
- void FileWatcher::StartWatch(FileWatcher::EventType events)
+ void FileWatcher::watch(double mask, KMethodRef newCallback)
{
- wd = inotify_add_watch(fd, notifypath.c_str(), events);
+ this->callback = newCallback;
+
+ wd = inotify_add_watch(fd, notifypath.c_str(), mask);
if(wd != 0)
{
throw ValueException::FromFormat("inotify_add_watch failed: %s (%d)",
@@ -71,7 +74,7 @@ namespace ti
}
}
- void FileWatcher::StopWatch()
+ void FileWatcher::unwatch()
{
int ret = 0;
ret = inotify_rm_watch(fd, wd);
View
39 modules/ti.Filesystem/file_watcher.h
@@ -19,27 +19,27 @@ namespace ti
class FileWatcher : public KEventObject
{
public:
- enum EventType
- {
- ACCESS = IN_ACCESS,
- ATTRIB = IN_ATTRIB,
- CLOSE_WRITE = IN_CLOSE_WRITE,
- CLOSE_NOWRITE = IN_CLOSE_NOWRITE,
- CREATE = IN_CREATE,
- DELETE = IN_DELETE,
- DELETE_SELF = IN_DELETE_SELF,
- MODIFY = IN_MODIFY,
- MOVE_SELF = IN_MOVE_SELF,
- MOVED_FROM = IN_MOVED_FROM,
- MOVED_TO = IN_MOVED_TO,
- OPEN = IN_OPEN,
- ALL_EVENTS = IN_ALL_EVENTS
- };
+ // enum EventType
+ // {
+ // ACCESS = IN_ACCESS,
+ // ATTRIB = IN_ATTRIB,
+ // CLOSE_WRITE = IN_CLOSE_WRITE,
+ // CLOSE_NOWRITE = IN_CLOSE_NOWRITE,
+ // CREATE = IN_CREATE,
+ // DELETE = IN_DELETE,
+ // DELETE_SELF = IN_DELETE_SELF,
+ // MODIFY = IN_MODIFY,
+ // MOVE_SELF = IN_MOVE_SELF,
+ // MOVED_FROM = IN_MOVED_FROM,
+ // MOVED_TO = IN_MOVED_TO,
+ // OPEN = IN_OPEN,
+ // ALL_EVENTS = IN_ALL_EVENTS
+ // };
FileWatcher(const char* filepath);
virtual ~FileWatcher();
- void StartWatch(FileWatcher::EventType event);
- void StopWatch();
+ void watch(double mask, KMethodRef newCallback);
+ void unwatch();
private:
std::string notifypath;
@@ -52,8 +52,7 @@ namespace ti
Poco::RunnableAdapter<FileWatcher> readAdapter;
Poco::Thread readThread;
-
- EventType notifyevents;
+ KMethodRef callback;
};
}
Please sign in to comment.
Something went wrong with that request. Please try again.