From d023bb993c34521833606d05bfbcdfb8bce04374 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Thu, 11 Feb 2016 16:30:05 -0500 Subject: [PATCH] Improved swig entry API --- .../com/frostwire/jlibtorrent/swig/entry.java | 12 + .../jlibtorrent/swig/libtorrent_jni.java | 3 + swig/libtorrent.i | 12 + swig/libtorrent_jni.cpp | 116 +++++++++- swig/libtorrent_node.cpp | 207 +++++++++++++++++- 5 files changed, 348 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/frostwire/jlibtorrent/swig/entry.java b/src/main/java/com/frostwire/jlibtorrent/swig/entry.java index 5e6c4e54b..5564d96a7 100644 --- a/src/main/java/com/frostwire/jlibtorrent/swig/entry.java +++ b/src/main/java/com/frostwire/jlibtorrent/swig/entry.java @@ -112,6 +112,18 @@ public short getM_type_queried() { return libtorrent_jni.entry_m_type_queried_get(swigCPtr, this); } + public entry get(String key) { + return new entry(libtorrent_jni.entry_get(swigCPtr, this, key), false); + } + + public void set(String key, String value) { + libtorrent_jni.entry_set__SWIG_0(swigCPtr, this, key, value); + } + + public void set(String key, int value) { + libtorrent_jni.entry_set__SWIG_1(swigCPtr, this, key, value); + } + public byte_vector bencode() { return new byte_vector(libtorrent_jni.entry_bencode(swigCPtr, this), true); } diff --git a/src/main/java/com/frostwire/jlibtorrent/swig/libtorrent_jni.java b/src/main/java/com/frostwire/jlibtorrent/swig/libtorrent_jni.java index 934cecad9..80fa98419 100644 --- a/src/main/java/com/frostwire/jlibtorrent/swig/libtorrent_jni.java +++ b/src/main/java/com/frostwire/jlibtorrent/swig/libtorrent_jni.java @@ -603,6 +603,9 @@ public class libtorrent_jni { public final static native String entry_to_string(long jarg1, entry jarg1_); public final static native void entry_m_type_queried_set(long jarg1, entry jarg1_, short jarg2); public final static native short entry_m_type_queried_get(long jarg1, entry jarg1_); + public final static native long entry_get(long jarg1, entry jarg1_, String jarg2); + public final static native void entry_set__SWIG_0(long jarg1, entry jarg1_, String jarg2, String jarg3); + public final static native void entry_set__SWIG_1(long jarg1, entry jarg1_, String jarg2, int jarg3); public final static native long entry_bencode(long jarg1, entry jarg1_); public final static native long entry_bdecode(long jarg1, byte_vector jarg1_); public final static native int sha1_hash_size_get(); diff --git a/swig/libtorrent.i b/swig/libtorrent.i index bacc66d53..331a1ac45 100644 --- a/swig/libtorrent.i +++ b/swig/libtorrent.i @@ -884,6 +884,18 @@ namespace libtorrent { }; %extend entry { + entry& get(std::string const& key) { + return $self->operator[](key); + } + + void set(std::string const& key, std::string const& value) { + $self->operator[](key) = value; + } + + void set(std::string const& key, long const& value) { + $self->operator[](key) = value; + } + std::vector bencode() { std::vector buffer; libtorrent::bencode(std::back_inserter(buffer), *$self); diff --git a/swig/libtorrent_jni.cpp b/swig/libtorrent_jni.cpp index fa8fe5630..82f308bb1 100644 --- a/swig/libtorrent_jni.cpp +++ b/swig/libtorrent_jni.cpp @@ -1226,6 +1226,15 @@ SWIGINTERN void std_vector_Sl_std_pair_Sl_std_string_Sc_dht_extension_handler_li else throw std::out_of_range("vector index out of range"); } +SWIGINTERN libtorrent::entry &libtorrent_entry_get(libtorrent::entry *self,std::string const &key){ + return self->operator[](key); + } +SWIGINTERN void libtorrent_entry_set__SWIG_0(libtorrent::entry *self,std::string const &key,std::string const &value){ + self->operator[](key) = value; + } +SWIGINTERN void libtorrent_entry_set__SWIG_1(libtorrent::entry *self,std::string const &key,long const &value){ + self->operator[](key) = value; + } SWIGINTERN std::vector< int8_t > libtorrent_entry_bencode(libtorrent::entry *self){ std::vector buffer; libtorrent::bencode(std::back_inserter(buffer), *self); @@ -17419,6 +17428,111 @@ SWIGEXPORT jshort JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_en } +SWIGEXPORT jlong JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_entry_1get(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2) { + jlong jresult = 0 ; + libtorrent::entry *arg1 = (libtorrent::entry *) 0 ; + std::string *arg2 = 0 ; + libtorrent::entry *result = 0 ; + + (void)jenv; + (void)jcls; + (void)jarg1_; + arg1 = *(libtorrent::entry **)&jarg1; + if(!jarg2) { + SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string"); + return 0; + } + const char *arg2_pstr = (const char *)jenv->GetStringUTFChars(jarg2, 0); + if (!arg2_pstr) return 0; + std::string arg2_str(arg2_pstr); + arg2 = &arg2_str; + jenv->ReleaseStringUTFChars(jarg2, arg2_pstr); + { + try { + result = (libtorrent::entry *) &libtorrent_entry_get(arg1,(std::string const &)*arg2); + } catch (std::exception& e) { + SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, e.what()); + } catch (...) { + SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "Unknown exception type"); + } + } + *(libtorrent::entry **)&jresult = result; + return jresult; +} + + +SWIGEXPORT void JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_entry_1set_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2, jstring jarg3) { + libtorrent::entry *arg1 = (libtorrent::entry *) 0 ; + std::string *arg2 = 0 ; + std::string *arg3 = 0 ; + + (void)jenv; + (void)jcls; + (void)jarg1_; + arg1 = *(libtorrent::entry **)&jarg1; + if(!jarg2) { + SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string"); + return ; + } + const char *arg2_pstr = (const char *)jenv->GetStringUTFChars(jarg2, 0); + if (!arg2_pstr) return ; + std::string arg2_str(arg2_pstr); + arg2 = &arg2_str; + jenv->ReleaseStringUTFChars(jarg2, arg2_pstr); + if(!jarg3) { + SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string"); + return ; + } + const char *arg3_pstr = (const char *)jenv->GetStringUTFChars(jarg3, 0); + if (!arg3_pstr) return ; + std::string arg3_str(arg3_pstr); + arg3 = &arg3_str; + jenv->ReleaseStringUTFChars(jarg3, arg3_pstr); + { + try { + libtorrent_entry_set__SWIG_0(arg1,(std::string const &)*arg2,(std::string const &)*arg3); + } catch (std::exception& e) { + SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, e.what()); + } catch (...) { + SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "Unknown exception type"); + } + } +} + + +SWIGEXPORT void JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_entry_1set_1_1SWIG_11(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2, jint jarg3) { + libtorrent::entry *arg1 = (libtorrent::entry *) 0 ; + std::string *arg2 = 0 ; + long *arg3 = 0 ; + long temp3 ; + + (void)jenv; + (void)jcls; + (void)jarg1_; + arg1 = *(libtorrent::entry **)&jarg1; + if(!jarg2) { + SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string"); + return ; + } + const char *arg2_pstr = (const char *)jenv->GetStringUTFChars(jarg2, 0); + if (!arg2_pstr) return ; + std::string arg2_str(arg2_pstr); + arg2 = &arg2_str; + jenv->ReleaseStringUTFChars(jarg2, arg2_pstr); + temp3 = (long)jarg3; + arg3 = &temp3; + { + try { + libtorrent_entry_set__SWIG_1(arg1,(std::string const &)*arg2,(long const &)*arg3); + } catch (std::exception& e) { + SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, e.what()); + } catch (...) { + SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "Unknown exception type"); + } + } +} + + SWIGEXPORT jlong JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_entry_1bencode(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) { jlong jresult = 0 ; libtorrent::entry *arg1 = (libtorrent::entry *) 0 ; @@ -61009,7 +61123,7 @@ SWIGEXPORT jstring JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_J (void)jenv; (void)jcls; - result = (char *)("9765a1d65921c6a18b30812c3f25e79f98d90e0d"); + result = (char *)("56f397e662d7a82306507668837a5fdf3af77395"); if (result) jresult = jenv->NewStringUTF((const char *)result); return jresult; } diff --git a/swig/libtorrent_node.cpp b/swig/libtorrent_node.cpp index a15de4af6..d02b7aeaa 100644 --- a/swig/libtorrent_node.cpp +++ b/swig/libtorrent_node.cpp @@ -2633,6 +2633,15 @@ SWIG_From_unsigned_SS_char (unsigned char value) return SWIG_From_unsigned_SS_long (value); } +SWIGINTERN libtorrent::entry &libtorrent_entry_get(libtorrent::entry *self,std::string const &key){ + return self->operator[](key); + } +SWIGINTERN void libtorrent_entry_set__SWIG_0(libtorrent::entry *self,std::string const &key,std::string const &value){ + self->operator[](key) = value; + } +SWIGINTERN void libtorrent_entry_set__SWIG_1(libtorrent::entry *self,std::string const &key,long const &value){ + self->operator[](key) = value; + } SWIGINTERN std::vector< int8_t > libtorrent_entry_bencode(libtorrent::entry *self){ std::vector buffer; libtorrent::bencode(std::back_inserter(buffer), *self); @@ -23596,6 +23605,200 @@ static SwigV8ReturnValue _wrap_entry_m_type_queried_get(v8::Local pr } +static SwigV8ReturnValue _wrap_entry_get(const SwigV8Arguments &args) { + SWIGV8_HANDLESCOPE(); + + v8::Handle jsresult; + libtorrent::entry *arg1 = (libtorrent::entry *) 0 ; + std::string *arg2 = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 = SWIG_OLDOBJ ; + libtorrent::entry *result = 0 ; + + if(args.Length() != 1) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for _wrap_entry_get."); + + res1 = SWIG_ConvertPtr(args.Holder(), &argp1,SWIGTYPE_p_libtorrent__entry, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "entry_get" "', argument " "1"" of type '" "libtorrent::entry *""'"); + } + arg1 = (libtorrent::entry *)(argp1); + { + std::string *ptr = (std::string *)0; + res2 = SWIG_AsPtr_std_string(args[0], &ptr); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "entry_get" "', argument " "2"" of type '" "std::string const &""'"); + } + if (!ptr) { + SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "entry_get" "', argument " "2"" of type '" "std::string const &""'"); + } + arg2 = ptr; + } + result = (libtorrent::entry *) &libtorrent_entry_get(arg1,(std::string const &)*arg2); + jsresult = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_libtorrent__entry, 0 | 0 ); + + if (SWIG_IsNewObj(res2)) delete arg2; + + SWIGV8_RETURN(jsresult); + + goto fail; +fail: + SWIGV8_RETURN(SWIGV8_UNDEFINED()); +} + + +static SwigV8ReturnValue _wrap_entry_set__SWIG_0(const SwigV8Arguments &args, V8ErrorHandler &SWIGV8_ErrorHandler) +{ + SWIGV8_HANDLESCOPE(); + + v8::Handle jsresult; + libtorrent::entry *arg1 = (libtorrent::entry *) 0 ; + std::string *arg2 = 0 ; + std::string *arg3 = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 = SWIG_OLDOBJ ; + int res3 = SWIG_OLDOBJ ; + + res1 = SWIG_ConvertPtr(args.Holder(), &argp1,SWIGTYPE_p_libtorrent__entry, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "entry_set" "', argument " "1"" of type '" "libtorrent::entry *""'"); + } + arg1 = (libtorrent::entry *)(argp1); + { + std::string *ptr = (std::string *)0; + res2 = SWIG_AsPtr_std_string(args[0], &ptr); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "entry_set" "', argument " "2"" of type '" "std::string const &""'"); + } + if (!ptr) { + SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "entry_set" "', argument " "2"" of type '" "std::string const &""'"); + } + arg2 = ptr; + } + { + std::string *ptr = (std::string *)0; + res3 = SWIG_AsPtr_std_string(args[1], &ptr); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "entry_set" "', argument " "3"" of type '" "std::string const &""'"); + } + if (!ptr) { + SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "entry_set" "', argument " "3"" of type '" "std::string const &""'"); + } + arg3 = ptr; + } + libtorrent_entry_set__SWIG_0(arg1,(std::string const &)*arg2,(std::string const &)*arg3); + jsresult = SWIGV8_UNDEFINED(); + + if (SWIG_IsNewObj(res2)) delete arg2; + if (SWIG_IsNewObj(res3)) delete arg3; + + SWIGV8_RETURN(jsresult); + + goto fail; +fail: + SWIGV8_RETURN(SWIGV8_UNDEFINED()); +} + + +static SwigV8ReturnValue _wrap_entry_set__SWIG_1(const SwigV8Arguments &args, V8ErrorHandler &SWIGV8_ErrorHandler) +{ + SWIGV8_HANDLESCOPE(); + + v8::Handle jsresult; + libtorrent::entry *arg1 = (libtorrent::entry *) 0 ; + std::string *arg2 = 0 ; + long *arg3 = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 = SWIG_OLDOBJ ; + long temp3 ; + long val3 ; + int ecode3 = 0 ; + + res1 = SWIG_ConvertPtr(args.Holder(), &argp1,SWIGTYPE_p_libtorrent__entry, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "entry_set" "', argument " "1"" of type '" "libtorrent::entry *""'"); + } + arg1 = (libtorrent::entry *)(argp1); + { + std::string *ptr = (std::string *)0; + res2 = SWIG_AsPtr_std_string(args[0], &ptr); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "entry_set" "', argument " "2"" of type '" "std::string const &""'"); + } + if (!ptr) { + SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "entry_set" "', argument " "2"" of type '" "std::string const &""'"); + } + arg2 = ptr; + } + ecode3 = SWIG_AsVal_long(args[1], &val3); + if (!SWIG_IsOK(ecode3)) { + SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "entry_set" "', argument " "3"" of type '" "long""'"); + } + temp3 = (long)(val3); + arg3 = &temp3; + libtorrent_entry_set__SWIG_1(arg1,(std::string const &)*arg2,(long const &)*arg3); + jsresult = SWIGV8_UNDEFINED(); + + if (SWIG_IsNewObj(res2)) delete arg2; + + + SWIGV8_RETURN(jsresult); + + goto fail; +fail: + SWIGV8_RETURN(SWIGV8_UNDEFINED()); +} + + +static SwigV8ReturnValue _wrap_entry__wrap_entry_set(const SwigV8Arguments &args) { + SWIGV8_HANDLESCOPE(); + + v8::Handle jsresult; + OverloadErrorHandler errorHandler; + + + if(args.Length() == 2) { + errorHandler.err.Clear(); +#if (SWIG_V8_VERSION < 0x031903) + jsresult = _wrap_entry_set__SWIG_0(args, errorHandler); + if(errorHandler.err.IsEmpty()) { + SWIGV8_ESCAPE(jsresult); + } +#else + _wrap_entry_set__SWIG_0(args, errorHandler); + if(errorHandler.err.IsEmpty()) { + return; + } +#endif + } + + + if(args.Length() == 2) { + errorHandler.err.Clear(); +#if (SWIG_V8_VERSION < 0x031903) + jsresult = _wrap_entry_set__SWIG_1(args, errorHandler); + if(errorHandler.err.IsEmpty()) { + SWIGV8_ESCAPE(jsresult); + } +#else + _wrap_entry_set__SWIG_1(args, errorHandler); + if(errorHandler.err.IsEmpty()) { + return; + } +#endif + } + + + SWIG_exception_fail(SWIG_ERROR, "Illegal arguments for function set."); + + goto fail; +fail: + SWIGV8_RETURN(SWIGV8_UNDEFINED()); +} + + static SwigV8ReturnValue _wrap_entry_bencode(const SwigV8Arguments &args) { SWIGV8_HANDLESCOPE(); @@ -102820,7 +103023,7 @@ static SwigV8ReturnValue _wrap_JLIBTORRENT_REVISION_SHA1(v8::Local p v8::Handle jsresult; - jsresult = SWIG_FromCharPtr((const char *)"9765a1d65921c6a18b30812c3f25e79f98d90e0d"); + jsresult = SWIG_FromCharPtr((const char *)"56f397e662d7a82306507668837a5fdf3af77395"); SWIGV8_RETURN_INFO(jsresult, info); @@ -112140,6 +112343,8 @@ SWIGV8_AddMemberFunction(_exports_entry_class, "swap", _wrap_entry_swap); SWIGV8_AddMemberFunction(_exports_entry_class, "find_key", _wrap_entry_find_key); SWIGV8_AddMemberFunction(_exports_entry_class, "to_string", _wrap_entry_to_string); SWIGV8_AddMemberVariable(_exports_entry_class, "m_type_queried", _wrap_entry_m_type_queried_get, _wrap_entry_m_type_queried_set); +SWIGV8_AddMemberFunction(_exports_entry_class, "get", _wrap_entry_get); +SWIGV8_AddMemberFunction(_exports_entry_class, "set", _wrap_entry__wrap_entry_set); SWIGV8_AddMemberFunction(_exports_entry_class, "bencode", _wrap_entry_bencode); SWIGV8_AddMemberFunction(_exports_sha1_hash_class, "clear", _wrap_sha1_hash_clear); SWIGV8_AddMemberFunction(_exports_sha1_hash_class, "is_all_zeros", _wrap_sha1_hash_is_all_zeros);