Commits

Sepehr Taghdisian  committed 95e5c36

C api fixed, small fatal fix in FileWatcherWin32

  • Participants
  • Parent commits cbdc266

Comments (0)

Files changed (3)

File include/efsw/efsw.h

 		const char* dir,
 		const char* filename,
 		enum efsw_action action,
-		const char* old_filename
+		const char* old_filename,
+        void* param
 );
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /**
  * Creates a new file-watcher
  * @param generic_mode Force the use of the Generic file watcher
 EFSW_API efsw_watcher efsw_create(int generic_mode);
 
 /// Release the file-watcher and unwatch any directories
-EFSW_API void efsw_release(efsw_watcher watcher);
+EFSW_API void efsw_destroy(efsw_watcher watcher);
 
 /// Retreive last error occured by file-watcher
 EFSW_API const char* efsw_getlasterror();
 /// For backwards compatibility.
 /// On error returns WatchID with Error type.
 EFSW_API efsw_watchid efsw_addwatch(efsw_watcher watcher, const char* directory, 
-	efsw_pfn_fileaction_callback callback_fn, int recursive);
+	efsw_pfn_fileaction_callback callback_fn, int recursive, void* param);
 
 /// Remove a directory watch. This is a brute force search O(nlogn).
 EFSW_API void efsw_removewatch(efsw_watcher watcher, const char* directory);
 /// @return Returns if out of scope links are allowed
 EFSW_API int efsw_outofscopelinks_isallowed(efsw_watcher watcher);
 
+#ifdef __cplusplus
+}
 #endif
+
+
+#endif

File src/efsw/FileWatcherCWrapper.cpp

 public:
 	efsw_watcher mWatcher;
 	efsw_pfn_fileaction_callback mFn;
+    void* mParam;
 
 public:
-	Watcher_CAPI(efsw_watcher watcher, efsw_pfn_fileaction_callback fn)
+	Watcher_CAPI(efsw_watcher watcher, efsw_pfn_fileaction_callback fn, void* param)
 	{
 		mWatcher = watcher;
 		mFn = fn;
+        mParam = param;
 	}
 
 	void handleFileAction(efsw::WatchID watchid, const std::string& dir, const std::string& filename,
 		efsw::Action action, std::string oldFilename = "")
 	{
 		mFn(mWatcher, watchid, dir.c_str(), filename.c_str(), (enum efsw_action)action,
-			oldFilename.c_str());
+			oldFilename.c_str(), mParam);
 	}
 };
 
 	return (efsw_watcher)new efsw::FileWatcher(TOBOOL(generic_mode));
 }
 
-void efsw_release(efsw_watcher watcher)
+void efsw_destroy(efsw_watcher watcher)
 {
 	remove_callback(watcher);
 	delete (efsw::FileWatcher*)watcher;
 }
 
 efsw_watchid efsw_addwatch(efsw_watcher watcher, const char* directory, 
-	efsw_pfn_fileaction_callback callback_fn, int recursive)
+	efsw_pfn_fileaction_callback callback_fn, int recursive, void* param)
 {
 	Watcher_CAPI* callback = find_callback(watcher, callback_fn);
 
 	if (callback == NULL)   {
-		callback = new Watcher_CAPI(watcher, callback_fn);
+		callback = new Watcher_CAPI(watcher, callback_fn, param);
 		g_callbacks.push_back(callback);
 	}
 

File src/efsw/FileWatcherWin32.cpp

 
 	do
 	{
+        /* due to a bug when mHandles is empty and program tries to call WaitForMultipleObjectsEx */
+        if (mHandles.empty())
+            return;
+
 		DWORD wait_result = WaitForMultipleObjectsEx( mHandles.size(), &mHandles[0], FALSE, 1000, FALSE );
 
 		switch ( wait_result )