Merge "kill HAVE_INOTIFY"
This commit is contained in:
@@ -29,7 +29,7 @@
|
|||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#ifdef HAVE_INOTIFY
|
#if defined(__linux__)
|
||||||
#include <sys/inotify.h>
|
#include <sys/inotify.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -39,29 +39,25 @@ static jmethodID method_onEvent;
|
|||||||
|
|
||||||
static jint android_os_fileobserver_init(JNIEnv* env, jobject object)
|
static jint android_os_fileobserver_init(JNIEnv* env, jobject object)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_INOTIFY
|
#if defined(__linux__)
|
||||||
|
return (jint)inotify_init();
|
||||||
return (jint)inotify_init();
|
#else
|
||||||
|
|
||||||
#else // HAVE_INOTIFY
|
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
#endif
|
||||||
#endif // HAVE_INOTIFY
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void android_os_fileobserver_observe(JNIEnv* env, jobject object, jint fd)
|
static void android_os_fileobserver_observe(JNIEnv* env, jobject object, jint fd)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_INOTIFY
|
#if defined(__linux__)
|
||||||
|
|
||||||
char event_buf[512];
|
char event_buf[512];
|
||||||
struct inotify_event* event;
|
struct inotify_event* event;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
int event_pos = 0;
|
int event_pos = 0;
|
||||||
int num_bytes = read(fd, event_buf, sizeof(event_buf));
|
int num_bytes = read(fd, event_buf, sizeof(event_buf));
|
||||||
|
|
||||||
if (num_bytes < (int)sizeof(*event))
|
if (num_bytes < (int)sizeof(*event))
|
||||||
{
|
{
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
@@ -70,14 +66,14 @@ static void android_os_fileobserver_observe(JNIEnv* env, jobject object, jint fd
|
|||||||
ALOGE("***** ERROR! android_os_fileobserver_observe() got a short event!");
|
ALOGE("***** ERROR! android_os_fileobserver_observe() got a short event!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (num_bytes >= (int)sizeof(*event))
|
while (num_bytes >= (int)sizeof(*event))
|
||||||
{
|
{
|
||||||
int event_size;
|
int event_size;
|
||||||
event = (struct inotify_event *)(event_buf + event_pos);
|
event = (struct inotify_event *)(event_buf + event_pos);
|
||||||
|
|
||||||
jstring path = NULL;
|
jstring path = NULL;
|
||||||
|
|
||||||
if (event->len > 0)
|
if (event->len > 0)
|
||||||
{
|
{
|
||||||
path = env->NewStringUTF(event->name);
|
path = env->NewStringUTF(event->name);
|
||||||
@@ -98,37 +94,37 @@ static void android_os_fileobserver_observe(JNIEnv* env, jobject object, jint fd
|
|||||||
event_pos += event_size;
|
event_pos += event_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // HAVE_INOTIFY
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static jint android_os_fileobserver_startWatching(JNIEnv* env, jobject object, jint fd, jstring pathString, jint mask)
|
static jint android_os_fileobserver_startWatching(JNIEnv* env, jobject object, jint fd, jstring pathString, jint mask)
|
||||||
{
|
{
|
||||||
int res = -1;
|
int res = -1;
|
||||||
|
|
||||||
#ifdef HAVE_INOTIFY
|
#if defined(__linux__)
|
||||||
|
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
{
|
{
|
||||||
const char* path = env->GetStringUTFChars(pathString, NULL);
|
const char* path = env->GetStringUTFChars(pathString, NULL);
|
||||||
|
|
||||||
res = inotify_add_watch(fd, path, mask);
|
res = inotify_add_watch(fd, path, mask);
|
||||||
|
|
||||||
env->ReleaseStringUTFChars(pathString, path);
|
env->ReleaseStringUTFChars(pathString, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // HAVE_INOTIFY
|
#endif
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void android_os_fileobserver_stopWatching(JNIEnv* env, jobject object, jint fd, jint wfd)
|
static void android_os_fileobserver_stopWatching(JNIEnv* env, jobject object, jint fd, jint wfd)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_INOTIFY
|
#if defined(__linux__)
|
||||||
|
|
||||||
inotify_rm_watch((int)fd, (uint32_t)wfd);
|
inotify_rm_watch((int)fd, (uint32_t)wfd);
|
||||||
|
|
||||||
#endif // HAVE_INOTIFY
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static JNINativeMethod sMethods[] = {
|
static JNINativeMethod sMethods[] = {
|
||||||
@@ -137,7 +133,7 @@ static JNINativeMethod sMethods[] = {
|
|||||||
{ "observe", "(I)V", (void*)android_os_fileobserver_observe },
|
{ "observe", "(I)V", (void*)android_os_fileobserver_observe },
|
||||||
{ "startWatching", "(ILjava/lang/String;I)I", (void*)android_os_fileobserver_startWatching },
|
{ "startWatching", "(ILjava/lang/String;I)I", (void*)android_os_fileobserver_startWatching },
|
||||||
{ "stopWatching", "(II)V", (void*)android_os_fileobserver_stopWatching }
|
{ "stopWatching", "(II)V", (void*)android_os_fileobserver_stopWatching }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int register_android_os_FileObserver(JNIEnv* env)
|
int register_android_os_FileObserver(JNIEnv* env)
|
||||||
|
|||||||
Reference in New Issue
Block a user