Skip to content

Commit

Permalink
More robust framework for posix file functions override.
Browse files Browse the repository at this point in the history
  • Loading branch information
aldenml committed Dec 17, 2015
1 parent 30f5476 commit ddd64d0
Show file tree
Hide file tree
Showing 12 changed files with 353 additions and 642 deletions.
10 changes: 5 additions & 5 deletions src/main/java/com/frostwire/jlibtorrent/LibTorrent.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import com.frostwire.jlibtorrent.swig.libtorrent;
import com.frostwire.jlibtorrent.swig.stats_metric_vector;
import com.frostwire.jlibtorrent.swig.swig_posix_wrapper;
import com.frostwire.jlibtorrent.swig.swig_posix_file_functions;

/**
* @author gubatron
* @author aldenml
*/
public final class LibTorrent {

private static swig_posix_wrapper posix_wrapper;
private static swig_posix_file_functions posix_file_functions;

private LibTorrent() {
}
Expand Down Expand Up @@ -82,8 +82,8 @@ public static int findMetricIdx(String name) {
return libtorrent.find_metric_idx(name);
}

public static void setPosixWrapper(swig_posix_wrapper ctx) {
LibTorrent.posix_wrapper = ctx;
libtorrent.set_global_posix_wrapper(ctx);
public static void setPosixFileFunctions(swig_posix_file_functions fns) {
LibTorrent.posix_file_functions = fns;
libtorrent.set_global_posix_file_functions(fns);
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/frostwire/jlibtorrent/swig/libtorrent.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ public static String boost_lib_version() {
return libtorrent_jni.boost_lib_version();
}

public static void set_global_posix_wrapper(swig_posix_wrapper ctx) {
libtorrent_jni.set_global_posix_wrapper(swig_posix_wrapper.getCPtr(ctx), ctx);
public static void set_global_posix_file_functions(swig_posix_file_functions fns) {
libtorrent_jni.set_global_posix_file_functions(swig_posix_file_functions.getCPtr(fns), fns);
}

}
51 changes: 23 additions & 28 deletions src/main/java/com/frostwire/jlibtorrent/swig/libtorrent_jni.java
Original file line number Diff line number Diff line change
Expand Up @@ -3350,25 +3350,23 @@ public class libtorrent_jni {
public final static native int swig_posix_stat_ctime_get(long jarg1, swig_posix_stat jarg1_);
public final static native long new_swig_posix_stat();
public final static native void delete_swig_posix_stat(long jarg1);
public final static native void delete_swig_posix_wrapper(long jarg1);
public final static native int swig_posix_wrapper_open(long jarg1, swig_posix_wrapper jarg1_, String jarg2, int jarg3, int jarg4);
public final static native int swig_posix_wrapper_openSwigExplicitswig_posix_wrapper(long jarg1, swig_posix_wrapper jarg1_, String jarg2, int jarg3, int jarg4);
public final static native int swig_posix_wrapper_open64(long jarg1, swig_posix_wrapper jarg1_, String jarg2, int jarg3, int jarg4);
public final static native int swig_posix_wrapper_open64SwigExplicitswig_posix_wrapper(long jarg1, swig_posix_wrapper jarg1_, String jarg2, int jarg3, int jarg4);
public final static native int swig_posix_wrapper_mkdir(long jarg1, swig_posix_wrapper jarg1_, String jarg2, int jarg3);
public final static native int swig_posix_wrapper_mkdirSwigExplicitswig_posix_wrapper(long jarg1, swig_posix_wrapper jarg1_, String jarg2, int jarg3);
public final static native int swig_posix_wrapper_rename(long jarg1, swig_posix_wrapper jarg1_, String jarg2, String jarg3);
public final static native int swig_posix_wrapper_renameSwigExplicitswig_posix_wrapper(long jarg1, swig_posix_wrapper jarg1_, String jarg2, String jarg3);
public final static native int swig_posix_wrapper_remove(long jarg1, swig_posix_wrapper jarg1_, String jarg2);
public final static native int swig_posix_wrapper_removeSwigExplicitswig_posix_wrapper(long jarg1, swig_posix_wrapper jarg1_, String jarg2);
public final static native int swig_posix_wrapper_lstat(long jarg1, swig_posix_wrapper jarg1_, String jarg2, long jarg3, swig_posix_stat jarg3_);
public final static native int swig_posix_wrapper_lstatSwigExplicitswig_posix_wrapper(long jarg1, swig_posix_wrapper jarg1_, String jarg2, long jarg3, swig_posix_stat jarg3_);
public final static native int swig_posix_wrapper_stat(long jarg1, swig_posix_wrapper jarg1_, String jarg2, long jarg3, swig_posix_stat jarg3_);
public final static native int swig_posix_wrapper_statSwigExplicitswig_posix_wrapper(long jarg1, swig_posix_wrapper jarg1_, String jarg2, long jarg3, swig_posix_stat jarg3_);
public final static native long new_swig_posix_wrapper();
public final static native void swig_posix_wrapper_director_connect(swig_posix_wrapper obj, long cptr, boolean mem_own, boolean weak_global);
public final static native void swig_posix_wrapper_change_ownership(swig_posix_wrapper obj, long cptr, boolean take_or_release);
public final static native void set_global_posix_wrapper(long jarg1, swig_posix_wrapper jarg1_);
public final static native void delete_swig_posix_file_functions(long jarg1);
public final static native int swig_posix_file_functions_open(long jarg1, swig_posix_file_functions jarg1_, String jarg2, int jarg3, int jarg4);
public final static native int swig_posix_file_functions_openSwigExplicitswig_posix_file_functions(long jarg1, swig_posix_file_functions jarg1_, String jarg2, int jarg3, int jarg4);
public final static native int swig_posix_file_functions_mkdir(long jarg1, swig_posix_file_functions jarg1_, String jarg2, int jarg3);
public final static native int swig_posix_file_functions_mkdirSwigExplicitswig_posix_file_functions(long jarg1, swig_posix_file_functions jarg1_, String jarg2, int jarg3);
public final static native int swig_posix_file_functions_rename(long jarg1, swig_posix_file_functions jarg1_, String jarg2, String jarg3);
public final static native int swig_posix_file_functions_renameSwigExplicitswig_posix_file_functions(long jarg1, swig_posix_file_functions jarg1_, String jarg2, String jarg3);
public final static native int swig_posix_file_functions_remove(long jarg1, swig_posix_file_functions jarg1_, String jarg2);
public final static native int swig_posix_file_functions_removeSwigExplicitswig_posix_file_functions(long jarg1, swig_posix_file_functions jarg1_, String jarg2);
public final static native int swig_posix_file_functions_lstat(long jarg1, swig_posix_file_functions jarg1_, String jarg2, long jarg3, swig_posix_stat jarg3_);
public final static native int swig_posix_file_functions_lstatSwigExplicitswig_posix_file_functions(long jarg1, swig_posix_file_functions jarg1_, String jarg2, long jarg3, swig_posix_stat jarg3_);
public final static native int swig_posix_file_functions_stat(long jarg1, swig_posix_file_functions jarg1_, String jarg2, long jarg3, swig_posix_stat jarg3_);
public final static native int swig_posix_file_functions_statSwigExplicitswig_posix_file_functions(long jarg1, swig_posix_file_functions jarg1_, String jarg2, long jarg3, swig_posix_stat jarg3_);
public final static native long new_swig_posix_file_functions();
public final static native void swig_posix_file_functions_director_connect(swig_posix_file_functions obj, long cptr, boolean mem_own, boolean weak_global);
public final static native void swig_posix_file_functions_change_ownership(swig_posix_file_functions obj, long cptr, boolean take_or_release);
public final static native void set_global_posix_file_functions(long jarg1, swig_posix_file_functions jarg1_);
public final static native long torrent_alert_SWIGUpcast(long jarg1);
public final static native long peer_alert_SWIGUpcast(long jarg1);
public final static native long tracker_alert_SWIGUpcast(long jarg1);
Expand Down Expand Up @@ -3652,25 +3650,22 @@ public static void SwigDirector_swig_peer_plugin_tick(swig_peer_plugin jself) {
public static boolean SwigDirector_swig_peer_plugin_write_request(swig_peer_plugin jself, long r) {
return jself.write_request(new peer_request(r, false));
}
public static int SwigDirector_swig_posix_wrapper_open(swig_posix_wrapper jself, String pathname, int flags, int mode) {
public static int SwigDirector_swig_posix_file_functions_open(swig_posix_file_functions jself, String pathname, int flags, int mode) {
return jself.open(pathname, flags, mode);
}
public static int SwigDirector_swig_posix_wrapper_open64(swig_posix_wrapper jself, String pathname, int flags, int mode) {
return jself.open64(pathname, flags, mode);
}
public static int SwigDirector_swig_posix_wrapper_mkdir(swig_posix_wrapper jself, String pathname, int mode) {
public static int SwigDirector_swig_posix_file_functions_mkdir(swig_posix_file_functions jself, String pathname, int mode) {
return jself.mkdir(pathname, mode);
}
public static int SwigDirector_swig_posix_wrapper_rename(swig_posix_wrapper jself, String oldpath, String newpath) {
public static int SwigDirector_swig_posix_file_functions_rename(swig_posix_file_functions jself, String oldpath, String newpath) {
return jself.rename(oldpath, newpath);
}
public static int SwigDirector_swig_posix_wrapper_remove(swig_posix_wrapper jself, String pathname) {
public static int SwigDirector_swig_posix_file_functions_remove(swig_posix_file_functions jself, String pathname) {
return jself.remove(pathname);
}
public static int SwigDirector_swig_posix_wrapper_lstat(swig_posix_wrapper jself, String path, long buf) {
public static int SwigDirector_swig_posix_file_functions_lstat(swig_posix_file_functions jself, String path, long buf) {
return jself.lstat(path, (buf == 0) ? null : new swig_posix_stat(buf, false));
}
public static int SwigDirector_swig_posix_wrapper_stat(swig_posix_wrapper jself, String path, long buf) {
public static int SwigDirector_swig_posix_file_functions_stat(swig_posix_file_functions jself, String path, long buf) {
return jself.stat(path, (buf == 0) ? null : new swig_posix_stat(buf, false));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 3.0.7
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */

package com.frostwire.jlibtorrent.swig;

public class swig_posix_file_functions {
private transient long swigCPtr;
protected transient boolean swigCMemOwn;

protected swig_posix_file_functions(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}

protected static long getCPtr(swig_posix_file_functions obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}

protected void finalize() {
delete();
}

public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
libtorrent_jni.delete_swig_posix_file_functions(swigCPtr);
}
swigCPtr = 0;
}
}

protected void swigDirectorDisconnect() {
swigCMemOwn = false;
delete();
}

public void swigReleaseOwnership() {
swigCMemOwn = false;
libtorrent_jni.swig_posix_file_functions_change_ownership(this, swigCPtr, false);
}

public void swigTakeOwnership() {
swigCMemOwn = true;
libtorrent_jni.swig_posix_file_functions_change_ownership(this, swigCPtr, true);
}

public int open(String pathname, int flags, int mode) {
return (getClass() == swig_posix_file_functions.class) ? libtorrent_jni.swig_posix_file_functions_open(swigCPtr, this, pathname, flags, mode) : libtorrent_jni.swig_posix_file_functions_openSwigExplicitswig_posix_file_functions(swigCPtr, this, pathname, flags, mode);
}

public int mkdir(String pathname, int mode) {
return (getClass() == swig_posix_file_functions.class) ? libtorrent_jni.swig_posix_file_functions_mkdir(swigCPtr, this, pathname, mode) : libtorrent_jni.swig_posix_file_functions_mkdirSwigExplicitswig_posix_file_functions(swigCPtr, this, pathname, mode);
}

public int rename(String oldpath, String newpath) {
return (getClass() == swig_posix_file_functions.class) ? libtorrent_jni.swig_posix_file_functions_rename(swigCPtr, this, oldpath, newpath) : libtorrent_jni.swig_posix_file_functions_renameSwigExplicitswig_posix_file_functions(swigCPtr, this, oldpath, newpath);
}

public int remove(String pathname) {
return (getClass() == swig_posix_file_functions.class) ? libtorrent_jni.swig_posix_file_functions_remove(swigCPtr, this, pathname) : libtorrent_jni.swig_posix_file_functions_removeSwigExplicitswig_posix_file_functions(swigCPtr, this, pathname);
}

public int lstat(String path, swig_posix_stat buf) {
return (getClass() == swig_posix_file_functions.class) ? libtorrent_jni.swig_posix_file_functions_lstat(swigCPtr, this, path, swig_posix_stat.getCPtr(buf), buf) : libtorrent_jni.swig_posix_file_functions_lstatSwigExplicitswig_posix_file_functions(swigCPtr, this, path, swig_posix_stat.getCPtr(buf), buf);
}

public int stat(String path, swig_posix_stat buf) {
return (getClass() == swig_posix_file_functions.class) ? libtorrent_jni.swig_posix_file_functions_stat(swigCPtr, this, path, swig_posix_stat.getCPtr(buf), buf) : libtorrent_jni.swig_posix_file_functions_statSwigExplicitswig_posix_file_functions(swigCPtr, this, path, swig_posix_stat.getCPtr(buf), buf);
}

public swig_posix_file_functions() {
this(libtorrent_jni.new_swig_posix_file_functions(), true);
libtorrent_jni.swig_posix_file_functions_director_connect(this, swigCPtr, swigCMemOwn, true);
}

}

This file was deleted.

10 changes: 2 additions & 8 deletions src/test/java/com/frostwire/jlibtorrent/demo/FsContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.frostwire.jlibtorrent.alerts.BlockFinishedAlert;
import com.frostwire.jlibtorrent.alerts.TorrentFinishedAlert;
import com.frostwire.jlibtorrent.swig.swig_posix_stat;
import com.frostwire.jlibtorrent.swig.swig_posix_wrapper;
import com.frostwire.jlibtorrent.swig.swig_posix_file_functions;

import java.io.File;
import java.util.concurrent.CountDownLatch;
Expand All @@ -25,19 +25,13 @@ public static void main(String[] args) throws Throwable {

File torrentFile = new File(args[0]);

LibTorrent.setPosixWrapper(new swig_posix_wrapper() {
LibTorrent.setPosixFileFunctions(new swig_posix_file_functions() {
@Override
public int open(String pathname, int flags, int mode) {
System.out.println("OPEN: " + pathname);
return super.open(pathname, flags, mode);
}

@Override
public int open64(String pathname, int flags, int mode) {
System.out.println("OPEN64: " + pathname);
return super.open64(pathname, flags, mode);
}

@Override
public int mkdir(String pathname, int mode) {
System.out.println("MKDIR: " + pathname);
Expand Down
1 change: 1 addition & 0 deletions swig/config/macosx-native-x86_64-config.jam
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ using darwin : x86_64 : clang++ :
<cflags>-std=c11
<cxxflags>-std=c++11
<cxxflags>-stdlib=libc++
<cxxflags>-DREPLACE_POSIX_FILE_FUNCTIONS
<cxxflags>-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator/sdk/MacOSX.sdk/usr/include
<cxxflags>-Wno-deprecated-declarations
<cxxflags>-Wno-reserved-id-macro
Expand Down

0 comments on commit ddd64d0

Please sign in to comment.