better configure-time checking for inotify & kqueue.
This commit is contained in:
parent
b5327c36ee
commit
09161120eb
35
configure.ac
35
configure.ac
|
@ -101,6 +101,41 @@ AC_PATH_ZLIB
|
|||
AC_SYS_LARGEFILE
|
||||
|
||||
|
||||
dnl ----------------------------------------------------------------------------
|
||||
dnl
|
||||
dnl third_party/FilewWatcher tests: look for inotify and kqueue
|
||||
|
||||
AC_CHECK_HEADER([sys/inotify.h],
|
||||
[AC_CHECK_FUNC([inotify_init],[have_inotify="yes"],[have_inotify="no"])],
|
||||
[have_inotify="no"])
|
||||
AC_ARG_WITH([inotify],
|
||||
[AS_HELP_STRING([--with-inotify],[Enable inotify support (default=auto)])],
|
||||
[want_inotify=${enableval}],
|
||||
[want_inotify=${have_inotify}])
|
||||
if test "x$want_inotify" = "xyes" ; then
|
||||
if test "x$have_inotify" = "xyes"; then
|
||||
AC_DEFINE([WITH_INOTIFY],[1])
|
||||
else
|
||||
AC_MSG_ERROR("inotify not found!")
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_CHECK_HEADER([sys/event.h],
|
||||
[AC_CHECK_FUNC([kqueue],[have_kqueue="yes"],[have_kqueue="no"])],
|
||||
[have_kqueue="no"])
|
||||
AC_ARG_WITH([kqueue],
|
||||
[AS_HELP_STRING([--with-kqueue],[Enable kqueue support (default=auto)])],
|
||||
[want_kqueue=${enableval}],
|
||||
[want_kqueue=${have_kqueue}])
|
||||
if test "x$want_kqueue" = "xyes" ; then
|
||||
if test "x$have_kqueue" = "xyes"; then
|
||||
AC_DEFINE([WITH_KQUEUE],[1])
|
||||
else
|
||||
AC_MSG_ERROR("kqueue not found!")
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
dnl ----------------------------------------------------------------------------
|
||||
dnl
|
||||
dnl posix_fadvise
|
||||
|
|
|
@ -181,16 +181,23 @@ getConfigDir( int argc, const char ** argv )
|
|||
}
|
||||
|
||||
static void
|
||||
dirChangedCB( CFW_Watch * watch UNUSED, const char * directory, const char * filename, CFW_Action action, void * userData )
|
||||
dirChangedCB( CFW_Watch * watch UNUSED,
|
||||
const char * directory,
|
||||
const char * filename,
|
||||
CFW_Action action,
|
||||
void * userData )
|
||||
{
|
||||
if( action & ( CFW_ACTION_ADD | CFW_ACTION_DELETE ) )
|
||||
if( ( action & CFW_ACTION_ADD ) && ( strstr( filename, ".torrent" ) != NULL ) )
|
||||
{
|
||||
int err;
|
||||
char * path = tr_buildPath( directory, filename, NULL );
|
||||
tr_session * session = userData;
|
||||
tr_ctor * ctor = tr_ctorNew( session );
|
||||
tr_ctorSetMetainfoFromFile( ctor, path );
|
||||
|
||||
err = tr_ctorSetMetainfoFromFile( ctor, path );
|
||||
if( !err )
|
||||
tr_torrentNew( session, ctor, &err );
|
||||
|
||||
tr_free( path );
|
||||
}
|
||||
}
|
||||
|
@ -325,9 +332,11 @@ main( int argc, char ** argv )
|
|||
tr_ctorFree( ctor );
|
||||
}
|
||||
|
||||
while( !closing ) {
|
||||
while( !closing )
|
||||
{
|
||||
tr_wait( 1000 ); /* sleep one second */
|
||||
if( watch )
|
||||
|
||||
if( watch != NULL ) /* maybe look for new .torrent files */
|
||||
cfw_update( watch );
|
||||
}
|
||||
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
|
||||
#if defined(_WIN32)
|
||||
# include "FileWatcherWin32.h"
|
||||
#elif defined(__APPLE_CC__)
|
||||
#elif defined(WITH_KQUEUE) || defined(__APPLE_CC__)
|
||||
# include "FileWatcherOSX.h"
|
||||
#elif defined(__linux__)
|
||||
#elif defined(WITH_INOTIFY) || defined(__linux__)
|
||||
# include "FileWatcherLinux.h"
|
||||
#else
|
||||
# error FIXME
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
@date 4/15/2009
|
||||
*/
|
||||
|
||||
#ifdef __linux__
|
||||
#if defined(WITH_INOTIFY)
|
||||
|
||||
#include "FileWatcherLinux.h"
|
||||
|
||||
|
@ -163,4 +163,4 @@ namespace FW
|
|||
};//namespace FW
|
||||
|
||||
|
||||
#endif//__linux__
|
||||
#endif // WITH_INOTIFY || __linux__
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
@date 4/15/2009
|
||||
*/
|
||||
|
||||
#ifdef __APPLE_CC__
|
||||
#if defined(WITH_KQUEUE) || defined(__APPLE_CC__)
|
||||
|
||||
#include "FileWatcherOSX.h"
|
||||
|
||||
|
@ -129,4 +129,4 @@ namespace FW
|
|||
|
||||
};//namespace FW
|
||||
|
||||
#endif//__APPLE_CC__
|
||||
#endif // WITH_KQUEUE || __APPLE_CC__
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
#define _FW_FILEWATCHEROSX_H_
|
||||
#pragma once
|
||||
|
||||
#ifdef __APPLE_CC__
|
||||
|
||||
#include "FileWatcher.h"
|
||||
#include <map>
|
||||
#include <sys/types.h>
|
||||
|
@ -71,6 +69,4 @@ namespace FW
|
|||
|
||||
};//namespace FW
|
||||
|
||||
#endif//__APPLE_CC__
|
||||
|
||||
#endif//_FW_FILEWATCHEROSX_H_
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
#define _FW_FILEWATCHERWIN32_H_
|
||||
#pragma once
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include "FileWatcher.h"
|
||||
#include <map>
|
||||
|
||||
|
@ -68,6 +66,4 @@ namespace FW
|
|||
|
||||
};//namespace FW
|
||||
|
||||
#endif//_WIN32
|
||||
|
||||
#endif//_FW_FILEWATCHERWIN32_H_
|
||||
|
|
|
@ -21,7 +21,9 @@ struct CFW_Impl: public FileWatchListener
|
|||
void * myCallbackData;
|
||||
|
||||
public:
|
||||
CFW_Impl( const char * dir, CFW_ActionCallback * callback, void * callbackData ):
|
||||
CFW_Impl( const char * dir,
|
||||
CFW_ActionCallback * callback,
|
||||
void * callbackData ):
|
||||
myID( myWatcher.addWatch( dir, this ) ),
|
||||
myCallback( callback ),
|
||||
myCallbackData( callbackData )
|
||||
|
@ -31,10 +33,18 @@ struct CFW_Impl: public FileWatchListener
|
|||
{
|
||||
myWatcher.removeWatch( myID );
|
||||
}
|
||||
virtual void handleFileAction( WatchID watchid, const String& dir, const String& filename, FileWatcher::Action action )
|
||||
|
||||
public:
|
||||
virtual void handleFileAction( WatchID watchid,
|
||||
const String & dir,
|
||||
const String & filename,
|
||||
FileWatcher::Action action )
|
||||
{
|
||||
std::cerr << __FILE__ << ':' << __LINE__ << " dir is " << dir << " filename is " << filename << std::endl;
|
||||
(*myCallback)( this, dir.c_str(), filename.c_str(), (CFW_Action)action, myCallbackData );
|
||||
(*myCallback)( this,
|
||||
dir.c_str(),
|
||||
filename.c_str(),
|
||||
(CFW_Action)action,
|
||||
myCallbackData );
|
||||
}
|
||||
void update( )
|
||||
{
|
||||
|
@ -42,20 +52,25 @@ std::cerr << __FILE__ << ':' << __LINE__ << " dir is " << dir << " filename is "
|
|||
}
|
||||
};
|
||||
|
||||
extern "C" CFW_Watch*
|
||||
cfw_addWatch( const char * directory, CFW_ActionCallback * callback, void * callbackData )
|
||||
extern "C"
|
||||
{
|
||||
CFW_Watch*
|
||||
cfw_addWatch( const char * directory, CFW_ActionCallback * callback, void * callbackData )
|
||||
{
|
||||
return new CFW_Impl( directory, callback, callbackData );
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
cfw_removeWatch( CFW_Watch * watch )
|
||||
{
|
||||
void
|
||||
cfw_removeWatch( CFW_Watch * watch )
|
||||
{
|
||||
if( watch != 0 )
|
||||
delete watch;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
cfw_update( CFW_Watch * watch )
|
||||
{
|
||||
void
|
||||
cfw_update( CFW_Watch * watch )
|
||||
{
|
||||
if( watch != 0 )
|
||||
watch->update( );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,13 +28,19 @@ CFW_Action;
|
|||
|
||||
typedef struct CFW_Impl CFW_Watch;
|
||||
|
||||
typedef void ( CFW_ActionCallback )( CFW_Watch*, const char * dir, const char * filename, CFW_Action, void * callbackData );
|
||||
typedef void ( CFW_ActionCallback )( CFW_Watch * watch,
|
||||
const char * dir,
|
||||
const char * filename,
|
||||
CFW_Action action,
|
||||
void * callbackData );
|
||||
|
||||
CFW_Watch* cfw_addWatch ( const char * directory, CFW_ActionCallback * callback, void * callbackData );
|
||||
CFW_Watch* cfw_addWatch ( const char * directory,
|
||||
CFW_ActionCallback * callback,
|
||||
void * callbackData );
|
||||
|
||||
void cfw_removeWatch ( CFW_Watch * );
|
||||
void cfw_removeWatch ( CFW_Watch * watch );
|
||||
|
||||
void cfw_update ( CFW_Watch * );
|
||||
void cfw_update ( CFW_Watch * watch );
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
Loading…
Reference in New Issue