int PluginLoop(void*){ WatchHandle watch = CreateWatch("*", "*", "*"); while(running){ Notification notif; if(GetNotification(¬if, 0)){ PLUGIN_INFO("notification received: %d.\n", notif.type); int res = 0; switch (notif.type) { case kShutdown: running = false; break; case kWatch: PluginInfo info; res = GetPluginInfo(notif.content.watch.plugin, &info); PLUGIN_INFO("plugin %s(%s) available\n", info.name, info.version); if(watch == notif.content.watch.handle && notif.content.watch.plugin_state == kPluginAvailable) { Connect(notif.content.watch.plugin); } break; default: break; } // process notification } } return 0; }
WatchID FileWatcherWin32::addWatch(const mxChar* directory) { WatchID watchid = ++mLastWatchID; WatchStruct* watch = CreateWatch( directory, FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_FILE_NAME); if( !watch ) { mxErrf( "CreateWatch() failed, directory: %s", mxTO_ANSI(directory) ); return 0; } watch->mWatchid = watchid; watch->mWatcher = this; const size_t strLen = (mxStrLen(directory)) *sizeof(directory[0]); Assert( strLen < sizeof(watch->mDirName)); watch->mDirName.SetNum(strLen + 1); MemCopy(watch->mDirName.ToChars(), directory, strLen ); watch->mDirName[strLen] = 0; mWatches.Set(watchid, watch); return watchid; }
//-------- WatchID FileWatcherWin32::addWatch(const String& directory, FileWatchListener* watcher, bool recursive) { WatchID watchid = ++mLastWatchID; WatchStruct* watch = CreateWatch( directory.c_str(), FILE_NOTIFY_CHANGE_CREATION | FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_FILE_NAME, recursive); if(!watch) { std::ostringstream message; message << "In " << __FILE__ << " at line " << __LINE__ << ": "; throw FileNotFoundException(directory, message.str()); } watch->mWatchid = watchid; watch->mFileWatcher = this; watch->mFileWatchListener = watcher; watch->mRecursive = recursive; watch->mDirName = new char[directory.length()+1]; strcpy(watch->mDirName, directory.c_str()); mWatches.insert(std::make_pair(watchid, watch)); return watchid; }
WatchID FileWatcherWin32::addWatch(const std::string& directory, FileWatchListener* watcher, bool recursive) { std::string dir( directory ); FileInfo fi( dir ); if ( !fi.isDirectory() ) { return Errors::Log::createLastError( Errors::FileNotFound, dir ); } else if ( !fi.isReadable() ) { return Errors::Log::createLastError( Errors::FileNotReadable, dir ); } FileSystem::dirAddSlashAtEnd( dir ); WatchID watchid = ++mLastWatchID; mWatchesLock.lock(); WatcherStructWin32 * watch = CreateWatch( String::fromUtf8( dir ).toWideString().c_str(), recursive, FILE_NOTIFY_CHANGE_CREATION | FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME ); if( NULL == watch ) { return Errors::Log::createLastError( Errors::FileNotFound, dir ); } if ( pathInWatches( dir ) ) { return Errors::Log::createLastError( Errors::FileRepeated, dir ); } // Add the handle to the handles vector watch->Watch->ID = watchid; watch->Watch->Watch = this; watch->Watch->Listener = watcher; watch->Watch->DirName = new char[dir.length()+1]; strcpy(watch->Watch->DirName, dir.c_str()); mHandles.push_back( watch->Watch->DirHandle ); mWatches.push_back( watch ); mWatchesLock.unlock(); return watchid; }
//-------- WatchID FileWatcherWin32::addWatch(const String& directory, FileWatchListener* watcher, bool recursive) { WatchID watchid = ++mLastWatchID; WatchStruct* watch = CreateWatch(directory.c_str(), recursive, FILE_NOTIFY_CHANGE_CREATION | FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_FILE_NAME); if(!watch) throw FileNotFoundException(directory); watch->mWatchid = watchid; watch->mFileWatcher = this; watch->mFileWatchListener = watcher; watch->mDirName = new char[directory.length()+1]; strcpy(watch->mDirName, directory.c_str()); mWatches.insert(std::make_pair(watchid, watch)); return watchid; }
//-------- WatchID FileWatcherWin32::addWatch(const String& directory, std::function<void(WatchID watchid, const String& dir, const String& filename, Action action)> watcher, bool recursive) { WatchID watchid = ++mLastWatchID; // LPCTSTR is a long (regular) const pointer to TCHAR string // TCHAR is a wide char if UNICODE has been defined (in which case std::wstring can be used as fs::String) WatchStruct* watch = CreateWatch((LPCTSTR)directory.c_str(), recursive, FILE_NOTIFY_CHANGE_CREATION | FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_FILE_NAME); if(!watch) throw FileNotFoundException(directory); watch->mWatchid = watchid; watch->mFileWatcher = this; watch->mFileWatchListener = watcher; watch->mDirName = new char[directory.length()+1]; strcpy(watch->mDirName, directory.c_str()); mWatches.insert(std::make_pair(watchid, watch)); return watchid; }