@Septag
DMON 은 디렉토리의 변경 사항을 모니터링하는 작은 C 라이브러리입니다. 각 OS에 존재하는 다중 시스템 API에 대한 통합 솔루션을 제공합니다. 또한 디렉토리를 재귀 적으로 모니터링 할 수 있습니다.
ReadDirectoryChangesW Backend. Windows10 SDK + Visual Studio 2019로 테스트inotify 백엔드. GCC-7.4/Clang-6, Ubuntu 18.04 LTS로 테스트FSEvents 백엔드. MACOS-10.14 Clang 10으로 테스트파일을 포함시키고 기능을 사용하면됩니다. 또한 C ++ 코드와 호환됩니다. Windows 경로의 백 슬래시는 휴대 성을 위해 '/'로 변환됩니다.
#define DMON_IMPL
#include "dmon.h"
static void watch_callback ( dmon_watch_id watch_id , dmon_action action , const char * rootdir ,
const char * filepath , const char * oldfilepath , void * user )
{
// receive change events. type of event is stored in 'action' variable
}
int main ()
{
dmon_init ();
dmon_watch ( "/path/to/directory" , watch_callback , DMON_WATCHFLAGS_RECURSIVE , NULL );
// wait ...
dmon_deinit ();
return 0 ;
}자세한 내용과 기능을 사용자 정의하는 방법은 DMON.H를 참조하십시오.
Linux를 구축하려면 pthread : gcc test.c -lpthread -o test 와 링크
MACOS를 구축하려면 CoreServices 및 CoreFoundation 과 링크 : clang test.c -framework CoreFoundation -framework CoreServices -lpthread -o test
Linux 백엔드 용 dmon.h 다음에 선택적으로 포함 할 수있는이 다른 파일 dmon_extra.h 가 있습니다. 해당 헤더에 dmon_watch_add 및 dmon_watch_rm 에 소개되는 두 가지 API가있어 현재 시청 된 디렉토리에 하위 디렉토리를 추가/제거 할 수 있습니다. 이는 Linux 백엔드에서 큰 변화가 발생하는 경우 유용 할 수 있으며 inotify 백엔드의 일부 단점으로 인해 모든 이벤트를 얻지 못할 경우 유용 할 수 있습니다. 따라서 DMON_WATCHFLAGS_RECURSIVE 비활성화하고 이러한 기능을 사용하여 디렉토리 재귀를 수동으로 처리하면 해당 문제를 해결할 수 있습니다.
Copyright 2019 Sepehr Taghdisian. All rights reserved.
https://github.com/septag/dmon
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.