Recent

Author Topic: Cross platform DirectoryWatcher  (Read 4938 times)

Wosi

  • New Member
  • *
  • Posts: 21
Cross platform DirectoryWatcher
« on: July 02, 2017, 07:30:21 pm »
I hope here is the right place for this:

I've made a cross platform DirectoryWatcher library. It's working on Windows, Mac and Linux.
Feel free to use it.
Please tell me if you find a bug.

https://github.com/Wosi/DirectoryWatcher

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3861
  • I like bugs.
Re: Cross platform DirectoryWatcher
« Reply #1 on: July 02, 2017, 08:28:19 pm »
I think this should be placed in FPC's libraries.
I remember such a cross-platform class has been requested and discussed earlier but it did not exist then.
Now it does. Cool!
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux.

hnb

  • Sr. Member
  • ****
  • Posts: 270
Re: Cross platform DirectoryWatcher
« Reply #2 on: July 02, 2017, 08:36:09 pm »
I think this should be placed in FPC's libraries.

Fully agree :). Anyway I see that DirectoryWatcher is licensed under MIT so AFAIK can't be added to FPC libraries.
Checkout NewPascal initiative and donate beer - ready to use tuned FPC compiler + Lazarus for mORMot project

best regards,
Maciej Izak

Wosi

  • New Member
  • *
  • Posts: 21
Re: Cross platform DirectoryWatcher
« Reply #3 on: July 02, 2017, 08:38:55 pm »
I think this should be placed in FPC's libraries.

Fully agree :). Anyway I see that DirectoryWatcher is licensed under MIT so AFAIK can't be added to FPC libraries.

Glad, you like it ;-)
What is the license you want? LGPL?
I'm not a lawyer. Is it possible to license the library under both licenses?

hnb

  • Sr. Member
  • ****
  • Posts: 270
Re: Cross platform DirectoryWatcher
« Reply #4 on: July 02, 2017, 08:48:04 pm »
What is the license you want? LGPL?
I'm not a lawyer. Is it possible to license the library under both licenses?

:) I am not lawyer too, but IMO the most perfect licensing model for 3rd library has mORMot:

https://synopse.info/files/html/Synopse%20mORMot%20Framework%20SAD%201.18.html#TITL_34

Any part of mORMot can be integrated with Lazarus or FPC at any time. FPC RTL/FCL is licensed under modified LGPL with static linking exception, see: http://wiki.freepascal.org/modified_LGPL
Checkout NewPascal initiative and donate beer - ready to use tuned FPC compiler + Lazarus for mORMot project

best regards,
Maciej Izak

ASerge

  • Hero Member
  • *****
  • Posts: 1680
Re: Cross platform DirectoryWatcher
« Reply #5 on: July 02, 2017, 08:53:39 pm »
Please tell me if you find a bug.
OnGetData is called without synchronization with the main thread. When used in GUI applications, this can cause problems.

Wosi

  • New Member
  • *
  • Posts: 21
Re: Cross platform DirectoryWatcher
« Reply #6 on: July 02, 2017, 09:10:07 pm »
https://synopse.info/files/html/Synopse%20mORMot%20Framework%20SAD%201.18.html#TITL_34

Any part of mORMot can be integrated with Lazarus or FPC at any time. FPC RTL/FCL is licensed under modified LGPL with static linking exception, see: http://wiki.freepascal.org/modified_LGPL

Thanks, I copied the license text from mORMot.

Please tell me if you find a bug.
OnGetData is called without synchronization with the main thread. When used in GUI applications, this can cause problems.

Works as intended. If synchronization is important then the user of the library has to take care of it inside the callback.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3861
  • I like bugs.
Re: Cross platform DirectoryWatcher
« Reply #7 on: July 03, 2017, 01:07:18 pm »
The nested method calls when constructing TDirectoryWatcherBuilder is a nice idea.
However I think the user should have an option to use a more traditional way of setting properties.
For example there should be:
Code: Pascal  [Select][+][-]
  1. property Recursive: Boolean read FRecursively write FRecursively;
  2. property OnDirectoryChanged: TDirectoryEvent read FCallBack write FCallBack;
Note the naming convention for the event property, they typically start with On...
The event type itself could be TDirectoryChangedEvent, and the event variable could be FOnDirectoryChanged instead of FCallBack.
The event handler in the example is poorly named. It should be DirectoryChanged or maybe FileChanged instead of OnFileEvent.

Is there a need to separate events for directories and files?

@hnb, you are an FPC developer, or at least a semi-developer due to your generics collection work.
Can you influence this DirectoryWatcher going into FPC libs?
We can also ask about it in fpc-dev list.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux.

hnb

  • Sr. Member
  • ****
  • Posts: 270
Re: Cross platform DirectoryWatcher
« Reply #8 on: July 03, 2017, 02:49:13 pm »
@hnb, you are an FPC developer, or at least a semi-developer due to your generics collection work.
I have no idea x)
Can you influence this DirectoryWatcher going into FPC libs?
We can also ask about it in fpc-dev list.
No need to ask on fpc-dev list. The library will be added to FCL (rather synchronized with not committed yet similar library).
Checkout NewPascal initiative and donate beer - ready to use tuned FPC compiler + Lazarus for mORMot project

best regards,
Maciej Izak

hnb

  • Sr. Member
  • ****
  • Posts: 270
Re: Cross platform DirectoryWatcher
« Reply #9 on: July 03, 2017, 02:49:51 pm »
@Wosi please check PM from me.
Checkout NewPascal initiative and donate beer - ready to use tuned FPC compiler + Lazarus for mORMot project

best regards,
Maciej Izak

edwinyzh

  • New Member
  • *
  • Posts: 39
Re: Cross platform DirectoryWatcher
« Reply #10 on: July 04, 2017, 05:53:43 am »
checked, worked as expected, and I like the fluent sytle API :)

promisetom

  • Newbie
  • Posts: 1
Re: Cross platform DirectoryWatcher
« Reply #11 on: September 14, 2020, 04:30:52 am »
Has anyone created an app using DirectoryWatcher using Forms.
I would like to use it in a graphics based app, not a console.
I tested an issue version using formas and received a "SIGSEGV exception"
Tom

zamronypj

  • Full Member
  • ***
  • Posts: 101
    • Fano Framework, Free Pascal web application framework
Re: Cross platform DirectoryWatcher
« Reply #12 on: September 15, 2020, 05:00:30 am »
I think this should be placed in FPC's libraries.

Fully agree :). Anyway I see that DirectoryWatcher is licensed under MIT so AFAIK can't be added to FPC libraries.

According to  https://softwareengineering.stackexchange.com/questions/189633/what-sublicense-actually-means I believe you can sublicense MIT as LGPL but not vice versa as long as you give copyright license and license notice. https://tldrlegal.com/license/mit-license
Fano Framework, Free Pascal web application framework https://fanoframework.github.io
Personal Projects https://v3.juhara.com
Github https://github.com/zamronypj

af0815

  • Hero Member
  • *****
  • Posts: 584
Re: Cross platform DirectoryWatcher
« Reply #13 on: September 15, 2020, 05:50:25 am »
Has anyone created an app using DirectoryWatcher using Forms.
I would like to use it in a graphics based app, not a console.
I tested an issue version using formas and received a "SIGSEGV exception"
Tom
Have you used synchronize to make a correct thread change as described in post #6 from wosi. You have to use this in the callback. See also
https://wiki.freepascal.org/Multithreaded_Application_Tutorial
https://www.freepascal.org/~michael/articles/lazthread/lazthread.pdf

The reason is, the forms and other grafic stuff is not thread safe. So you have to use synchronize to bring the operation to the main thread, which can deal with the forms and the other graphical elements.

But it is a good idea to show the program or parts, so other people can see your problem. Because you see your code and the community sees nothing and can only stick in fog.
 
regards
Andreas

 

TinyPortal © 2005-2018