SpartanJ / efsw

efsw is a C++ cross-platform file system watcher and notifier.
Other
666 stars 103 forks source link

I can not deal with same callback but param is different in C API #187

Closed ritalin closed 1 day ago

ritalin commented 2 days ago

What's happens?

In current implementation, it seems that efsw_addwatch_withoptions function is selecting the same callback, even if param is different.

https://github.com/SpartanJ/efsw/blob/master/src/efsw/FileWatcherCWrapper.cpp#L31

Solution proposal

Watcher_CAPI::mParam has also compared with param in find_callback function

Watcher_CAPI* find_callback( efsw_watcher watcher, efsw_pfn_fileaction_callback fn, void *param ) {
    for ( std::vector<Watcher_CAPI*>::iterator i = g_callbacks.begin(); i != g_callbacks.end();
          ++i ) {
        Watcher_CAPI* callback = *i;

        if ( callback->mFn == fn && callback->mWatcher == watcher && callback->mParam == param )
            return *i;
    }

    return NULL;
}
SpartanJ commented 1 day ago

Thanks for reporting it! I just pushed the fix you proposed.