Skip to content

Commit

Permalink
Rename new API to FileWatcher (resolve #1064)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgranick committed Sep 26, 2017
1 parent 75e78a6 commit a70a948
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 120 deletions.
8 changes: 4 additions & 4 deletions lime/_backend/native/NativeCFFI.hx
Expand Up @@ -49,15 +49,15 @@ class NativeCFFI {
@:cffi private static function lime_data_pointer_offset (dataPointer:DataPointer, offset:Int):Float;
@:cffi private static function lime_deflate_compress (data:Dynamic, bytes:Dynamic):Dynamic;
@:cffi private static function lime_deflate_decompress (data:Dynamic, bytes:Dynamic):Dynamic;
@:cffi private static function lime_directory_watcher_create (callback:Dynamic):CFFIPointer;
@:cffi private static function lime_directory_watcher_add_watch (handle:CFFIPointer, path:Dynamic, recursive:Bool):Dynamic;
@:cffi private static function lime_directory_watcher_remove_watch (handle:CFFIPointer, watchID:Dynamic):Void;
@:cffi private static function lime_directory_watcher_update (handle:CFFIPointer):Void;
@:cffi private static function lime_drop_event_manager_register (callback:Dynamic, eventObject:Dynamic):Void;
@:cffi private static function lime_file_dialog_open_directory (title:String, filter:String, defaultPath:String):Dynamic;
@:cffi private static function lime_file_dialog_open_file (title:String, filter:String, defaultPath:String):Dynamic;
@:cffi private static function lime_file_dialog_open_files (title:String, filter:String, defaultPath:String):Dynamic;
@:cffi private static function lime_file_dialog_save_file (title:String, filter:String, defaultPath:String):Dynamic;
@:cffi private static function lime_file_watcher_create (callback:Dynamic):CFFIPointer;
@:cffi private static function lime_file_watcher_add_directory (handle:CFFIPointer, path:Dynamic, recursive:Bool):Dynamic;
@:cffi private static function lime_file_watcher_remove_directory (handle:CFFIPointer, watchID:Dynamic):Void;
@:cffi private static function lime_file_watcher_update (handle:CFFIPointer):Void;
@:cffi private static function lime_font_get_ascender (handle:Dynamic):Int;
@:cffi private static function lime_font_get_descender (handle:Dynamic):Int;
@:cffi private static function lime_font_get_family_name (handle:Dynamic):Dynamic;
Expand Down
30 changes: 13 additions & 17 deletions lime/system/DirectoryWatcher.hx → lime/system/FileWatcher.hx
Expand Up @@ -13,13 +13,12 @@ import lime.app.Event;
@:access(lime._backend.native.NativeCFFI)


class DirectoryWatcher {
class FileWatcher {


public var onChange = new Event<Void->Void> ();
public var onFileAdd = new Event<String->Void> ();
public var onFileModify = new Event<String->Void> ();
public var onFileRemove = new Event<String->Void> ();
public var onAdd = new Event<String->Void> ();
public var onModify = new Event<String->Void> ();
public var onRemove = new Event<String->Void> ();

private var handle:CFFIPointer;
private var hasUpdate:Bool;
Expand All @@ -29,14 +28,14 @@ class DirectoryWatcher {
public function new () {

#if (lime_cffi && !macro)
handle = NativeCFFI.lime_directory_watcher_create (this_onChange);
handle = NativeCFFI.lime_file_watcher_create (this_onChange);
ids = new Map ();
#end

}


public function addPath (path:String, recursive:Bool = true):Void {
public function addDirectory (path:String, recursive:Bool = true):Void {

#if (lime_cffi && !macro)
if (!hasUpdate) {
Expand All @@ -46,19 +45,19 @@ class DirectoryWatcher {

}

var id:Int = NativeCFFI.lime_directory_watcher_add_watch (handle, path, recursive);
var id:Int = NativeCFFI.lime_file_watcher_add_directory (handle, path, recursive);
ids[path] = id;
#end

}


public function removePath (path:String):Void {
public function removeDirectory (path:String):Void {

#if (lime_cffi && !macro)
if (ids.exists (path)) {

NativeCFFI.lime_directory_watcher_remove_watch (handle, ids[path]);
NativeCFFI.lime_file_watcher_remove_directory (handle, ids[path]);
ids.remove (path);

if (!ids.keys ().hasNext ()) {
Expand Down Expand Up @@ -99,18 +98,15 @@ class DirectoryWatcher {

case 1:

onFileAdd.dispatch (path);
onChange.dispatch ();
onAdd.dispatch (path);

case 2:

onFileRemove.dispatch (path);
onChange.dispatch ();
onRemove.dispatch (path);

case 4:

onFileModify.dispatch (path);
onChange.dispatch ();
onModify.dispatch (path);

}

Expand All @@ -120,7 +116,7 @@ class DirectoryWatcher {
private function this_onUpdate (_):Void {

#if (lime_cffi && !macro)
NativeCFFI.lime_directory_watcher_update (handle);
NativeCFFI.lime_file_watcher_update (handle);
#end

}
Expand Down
2 changes: 1 addition & 1 deletion project/Build.xml
Expand Up @@ -219,7 +219,7 @@
<compilerflag value="-I${NATIVE_TOOLKIT_PATH}/simplefilewatcher/include/" />
<compilerflag value="-DLIME_SIMPLEFILEWATCHER" />

<file name="src/system/DirectoryWatcher.cpp" />
<file name="src/system/FileWatcher.cpp" />

</section>

Expand Down
38 changes: 0 additions & 38 deletions project/include/system/DirectoryWatcher.h

This file was deleted.

42 changes: 42 additions & 0 deletions project/include/system/FileWatcher.h
@@ -0,0 +1,42 @@
#ifndef LIME_SYSTEM_FILE_WATCHER_H
#define LIME_SYSTEM_FILE_WATCHER_H

#ifdef RemoveDirectory
#undef RemoveDirectory
#endif

#include <hx/CFFI.h>
#include <map>
#include <string>


namespace lime {


class FileWatcher {


public:

FileWatcher (value callback);
~FileWatcher ();

unsigned long AddDirectory (const std::string directory, bool recursive);
void RemoveDirectory (unsigned long watchID);
void Update ();

AutoGCRoot* callback;

private:

void* fileWatcher = 0;
std::map<unsigned long, void*> watchListeners;


};


}


#endif
103 changes: 52 additions & 51 deletions project/src/ExternalInterface.cpp
Expand Up @@ -23,8 +23,8 @@
#include <system/CFFIPointer.h>
#include <system/Clipboard.h>
#include <system/ClipboardEvent.h>
#include <system/DirectoryWatcher.h>
#include <system/Endian.h>
#include <system/FileWatcher.h>
#include <system/JNI.h>
#include <system/Locale.h>
#include <system/SensorEvent.h>
Expand Down Expand Up @@ -65,10 +65,10 @@ namespace lime {
}


void gc_directory_watcher (value handle) {
void gc_file_watcher (value handle) {

#ifdef LIME_SIMPLEFILEWATCHER
DirectoryWatcher* watcher = (DirectoryWatcher*)val_data (handle);
FileWatcher* watcher = (FileWatcher*)val_data (handle);
delete watcher;
#endif

Expand Down Expand Up @@ -360,50 +360,6 @@ namespace lime {
}


value lime_directory_watcher_create (value callback) {

#ifdef LIME_SIMPLEFILEWATCHER
DirectoryWatcher* watcher = new DirectoryWatcher (callback);
return CFFIPointer (watcher, gc_directory_watcher);
#else
return alloc_null ();
#endif

}


value lime_directory_watcher_add_watch (value handle, value path, bool recursive) {

#ifdef LIME_SIMPLEFILEWATCHER
DirectoryWatcher* watcher = (DirectoryWatcher*)val_data (handle);
return alloc_int (watcher->AddWatch (val_string (path), recursive));
#else
return alloc_int (0);
#endif

}


void lime_directory_watcher_remove_watch (value handle, value watchID) {

#ifdef LIME_SIMPLEFILEWATCHER
DirectoryWatcher* watcher = (DirectoryWatcher*)val_data (handle);
watcher->RemoveWatch (val_int (watchID));
#endif

}


void lime_directory_watcher_update (value handle) {

#ifdef LIME_SIMPLEFILEWATCHER
DirectoryWatcher* watcher = (DirectoryWatcher*)val_data (handle);
watcher->Update ();
#endif

}


void lime_drop_event_manager_register (value callback, value eventObject) {

DropEvent::callback = new AutoGCRoot (callback);
Expand Down Expand Up @@ -546,6 +502,51 @@ namespace lime {
}


value lime_file_watcher_create (value callback) {

#ifdef LIME_SIMPLEFILEWATCHER
FileWatcher* watcher = new FileWatcher (callback);
return CFFIPointer (watcher, gc_file_watcher);
#else
return alloc_null ();
#endif

}


value lime_file_watcher_add_directory (value handle, value path, bool recursive) {

#ifdef LIME_SIMPLEFILEWATCHER
FileWatcher* watcher = (FileWatcher*)val_data (handle);
return alloc_int (watcher->AddDirectory (val_string (path), recursive));
#else
return alloc_int (0);
#endif


}


void lime_file_watcher_remove_directory (value handle, value watchID) {

#ifdef LIME_SIMPLEFILEWATCHER
FileWatcher* watcher = (FileWatcher*)val_data (handle);
watcher->RemoveDirectory (val_int (watchID));
#endif

}


void lime_file_watcher_update (value handle) {

#ifdef LIME_SIMPLEFILEWATCHER
FileWatcher* watcher = (FileWatcher*)val_data (handle);
watcher->Update ();
#endif

}


int lime_font_get_ascender (value fontHandle) {

#ifdef LIME_FREETYPE
Expand Down Expand Up @@ -1888,15 +1889,15 @@ namespace lime {
DEFINE_PRIME2 (lime_data_pointer_offset);
DEFINE_PRIME2 (lime_deflate_compress);
DEFINE_PRIME2 (lime_deflate_decompress);
DEFINE_PRIME1 (lime_directory_watcher_create);
DEFINE_PRIME3 (lime_directory_watcher_add_watch);
DEFINE_PRIME2v (lime_directory_watcher_remove_watch);
DEFINE_PRIME1v (lime_directory_watcher_update);
DEFINE_PRIME2v (lime_drop_event_manager_register);
DEFINE_PRIME3 (lime_file_dialog_open_directory);
DEFINE_PRIME3 (lime_file_dialog_open_file);
DEFINE_PRIME3 (lime_file_dialog_open_files);
DEFINE_PRIME3 (lime_file_dialog_save_file);
DEFINE_PRIME1 (lime_file_watcher_create);
DEFINE_PRIME3 (lime_file_watcher_add_directory);
DEFINE_PRIME2v (lime_file_watcher_remove_directory);
DEFINE_PRIME1v (lime_file_watcher_update);
DEFINE_PRIME1 (lime_font_get_ascender);
DEFINE_PRIME1 (lime_font_get_descender);
DEFINE_PRIME1 (lime_font_get_family_name);
Expand Down

0 comments on commit a70a948

Please sign in to comment.