utils_wrap.cxx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. /* ----------------------------------------------------------------------------
  2. * This file was automatically generated by SWIG (http://www.swig.org).
  3. * Version 2.0.4
  4. *
  5. * This file is not intended to be easily readable and contains a number of
  6. * coding conventions designed to improve portability and efficiency. Do not make
  7. * changes to this file unless you know what you are doing--modify the SWIG
  8. * interface file instead.
  9. * ----------------------------------------------------------------------------- */
  10. #define SWIGJAVA
  11. #define SWIG_DIRECTORS
  12. #ifdef __cplusplus
  13. /* SwigValueWrapper is described in swig.swg */
  14. template<typename T> class SwigValueWrapper
  15. {
  16. struct SwigMovePointer {
  17. T *ptr;
  18. SwigMovePointer(T *p) : ptr(p) { }
  19. ~SwigMovePointer() {
  20. delete ptr;
  21. }
  22. SwigMovePointer& operator=(SwigMovePointer& rhs) {
  23. T* oldptr = ptr;
  24. ptr = 0;
  25. delete oldptr;
  26. ptr = rhs.ptr;
  27. rhs.ptr = 0;
  28. return *this;
  29. }
  30. } pointer;
  31. SwigValueWrapper& operator=(const SwigValueWrapper<T>& rhs);
  32. SwigValueWrapper(const SwigValueWrapper<T>& rhs);
  33. public:
  34. SwigValueWrapper() : pointer(0) { }
  35. SwigValueWrapper& operator=(const T& t) {
  36. SwigMovePointer tmp(new T(t));
  37. pointer = tmp;
  38. return *this;
  39. }
  40. operator T&() const {
  41. return *pointer.ptr;
  42. }
  43. T *operator&() {
  44. return pointer.ptr;
  45. }
  46. };
  47. template <typename T> T SwigValueInit()
  48. {
  49. return T();
  50. }
  51. #endif
  52. /* -----------------------------------------------------------------------------
  53. * This section contains generic SWIG labels for method/variable
  54. * declarations/attributes, and other compiler dependent labels.
  55. * ----------------------------------------------------------------------------- */
  56. /* template workaround for compilers that cannot correctly implement the C++ standard */
  57. #ifndef SWIGTEMPLATEDISAMBIGUATOR
  58. # if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560)
  59. # define SWIGTEMPLATEDISAMBIGUATOR template
  60. # elif defined(__HP_aCC)
  61. /* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */
  62. /* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */
  63. # define SWIGTEMPLATEDISAMBIGUATOR template
  64. # else
  65. # define SWIGTEMPLATEDISAMBIGUATOR
  66. # endif
  67. #endif
  68. /* inline attribute */
  69. #ifndef SWIGINLINE
  70. # if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
  71. # define SWIGINLINE inline
  72. # else
  73. # define SWIGINLINE
  74. # endif
  75. #endif
  76. /* attribute recognised by some compilers to avoid 'unused' warnings */
  77. #ifndef SWIGUNUSED
  78. # if defined(__GNUC__)
  79. # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
  80. # define SWIGUNUSED __attribute__ ((__unused__))
  81. # else
  82. # define SWIGUNUSED
  83. # endif
  84. # elif defined(__ICC)
  85. # define SWIGUNUSED __attribute__ ((__unused__))
  86. # else
  87. # define SWIGUNUSED
  88. # endif
  89. #endif
  90. #ifndef SWIG_MSC_UNSUPPRESS_4505
  91. # if defined(_MSC_VER)
  92. # pragma warning(disable : 4505) /* unreferenced local function has been removed */
  93. # endif
  94. #endif
  95. #ifndef SWIGUNUSEDPARM
  96. # ifdef __cplusplus
  97. # define SWIGUNUSEDPARM(p)
  98. # else
  99. # define SWIGUNUSEDPARM(p) p SWIGUNUSED
  100. # endif
  101. #endif
  102. /* internal SWIG method */
  103. #ifndef SWIGINTERN
  104. # define SWIGINTERN static SWIGUNUSED
  105. #endif
  106. /* internal inline SWIG method */
  107. #ifndef SWIGINTERNINLINE
  108. # define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
  109. #endif
  110. /* exporting methods */
  111. #if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
  112. # ifndef GCC_HASCLASSVISIBILITY
  113. # define GCC_HASCLASSVISIBILITY
  114. # endif
  115. #endif
  116. #ifndef SWIGEXPORT
  117. # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
  118. # if defined(STATIC_LINKED)
  119. # define SWIGEXPORT
  120. # else
  121. # define SWIGEXPORT __declspec(dllexport)
  122. # endif
  123. # else
  124. # if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
  125. # define SWIGEXPORT __attribute__ ((visibility("default")))
  126. # else
  127. # define SWIGEXPORT
  128. # endif
  129. # endif
  130. #endif
  131. /* calling conventions for Windows */
  132. #ifndef SWIGSTDCALL
  133. # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
  134. # define SWIGSTDCALL __stdcall
  135. # else
  136. # define SWIGSTDCALL
  137. # endif
  138. #endif
  139. /* Deal with Microsoft's attempt at deprecating C standard runtime functions */
  140. #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
  141. # define _CRT_SECURE_NO_DEPRECATE
  142. #endif
  143. /* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */
  144. #if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE)
  145. # define _SCL_SECURE_NO_DEPRECATE
  146. #endif
  147. /* Fix for jlong on some versions of gcc on Windows */
  148. #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
  149. typedef long long __int64;
  150. #endif
  151. /* Fix for jlong on 64-bit x86 Solaris */
  152. #if defined(__x86_64)
  153. # ifdef _LP64
  154. # undef _LP64
  155. # endif
  156. #endif
  157. #include <jni.h>
  158. #include <stdlib.h>
  159. #include <string.h>
  160. /* Support for throwing Java exceptions */
  161. typedef enum {
  162. SWIG_JavaOutOfMemoryError = 1,
  163. SWIG_JavaIOException,
  164. SWIG_JavaRuntimeException,
  165. SWIG_JavaIndexOutOfBoundsException,
  166. SWIG_JavaArithmeticException,
  167. SWIG_JavaIllegalArgumentException,
  168. SWIG_JavaNullPointerException,
  169. SWIG_JavaDirectorPureVirtual,
  170. SWIG_JavaUnknownError
  171. } SWIG_JavaExceptionCodes;
  172. typedef struct {
  173. SWIG_JavaExceptionCodes code;
  174. const char *java_exception;
  175. } SWIG_JavaExceptions_t;
  176. static void SWIGUNUSED SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionCodes code, const char *msg)
  177. {
  178. jclass excep;
  179. static const SWIG_JavaExceptions_t java_exceptions[] = {
  180. { SWIG_JavaOutOfMemoryError, "java/lang/OutOfMemoryError" },
  181. { SWIG_JavaIOException, "java/io/IOException" },
  182. { SWIG_JavaRuntimeException, "java/lang/RuntimeException" },
  183. { SWIG_JavaIndexOutOfBoundsException, "java/lang/IndexOutOfBoundsException" },
  184. { SWIG_JavaArithmeticException, "java/lang/ArithmeticException" },
  185. { SWIG_JavaIllegalArgumentException, "java/lang/IllegalArgumentException" },
  186. { SWIG_JavaNullPointerException, "java/lang/NullPointerException" },
  187. { SWIG_JavaDirectorPureVirtual, "java/lang/RuntimeException" },
  188. { SWIG_JavaUnknownError, "java/lang/UnknownError" },
  189. { (SWIG_JavaExceptionCodes)0, "java/lang/UnknownError" }
  190. };
  191. const SWIG_JavaExceptions_t *except_ptr = java_exceptions;
  192. while (except_ptr->code != code && except_ptr->code) {
  193. except_ptr++;
  194. }
  195. jenv->ExceptionClear();
  196. excep = jenv->FindClass(except_ptr->java_exception);
  197. if (excep) {
  198. jenv->ThrowNew(excep, msg);
  199. }
  200. }
  201. /* Contract support */
  202. #define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, msg); return nullreturn; } else
  203. /* -----------------------------------------------------------------------------
  204. * director.swg
  205. *
  206. * This file contains support for director classes that proxy
  207. * method calls from C++ to Java extensions.
  208. * ----------------------------------------------------------------------------- */
  209. #ifdef __cplusplus
  210. #if defined(DEBUG_DIRECTOR_OWNED)
  211. #include <iostream>
  212. #endif
  213. namespace Swig
  214. {
  215. /* Java object wrapper */
  216. class JObjectWrapper
  217. {
  218. public:
  219. JObjectWrapper() : jthis_(NULL), weak_global_(true) {
  220. }
  221. ~JObjectWrapper() {
  222. jthis_ = NULL;
  223. weak_global_ = true;
  224. }
  225. bool set(JNIEnv *jenv, jobject jobj, bool mem_own, bool weak_global) {
  226. if (!jthis_) {
  227. weak_global_ = weak_global;
  228. if (jobj) {
  229. jthis_ = ((weak_global_ || !mem_own) ? jenv->NewWeakGlobalRef(jobj) : jenv->NewGlobalRef(jobj));
  230. }
  231. #if defined(DEBUG_DIRECTOR_OWNED)
  232. std::cout << "JObjectWrapper::set(" << jobj << ", " << (weak_global ? "weak_global" : "global_ref") << ") -> " << jthis_ << std::endl;
  233. #endif
  234. return true;
  235. }
  236. else {
  237. #if defined(DEBUG_DIRECTOR_OWNED)
  238. std::cout << "JObjectWrapper::set(" << jobj << ", " << (weak_global ? "weak_global" : "global_ref") << ") -> already set" << std::endl;
  239. #endif
  240. return false;
  241. }
  242. }
  243. jobject get(JNIEnv *jenv) const {
  244. #if defined(DEBUG_DIRECTOR_OWNED)
  245. std::cout << "JObjectWrapper::get(";
  246. if (jthis_) {
  247. std::cout << jthis_;
  248. }
  249. else {
  250. std::cout << "null";
  251. }
  252. std::cout << ") -> return new local ref" << std::endl;
  253. #endif
  254. return (jthis_ ? jenv->NewLocalRef(jthis_) : jthis_);
  255. }
  256. void release(JNIEnv *jenv) {
  257. #if defined(DEBUG_DIRECTOR_OWNED)
  258. std::cout << "JObjectWrapper::release(" << jthis_ << "): " << (weak_global_ ? "weak global ref" : "global ref") << std::endl;
  259. #endif
  260. if (jthis_) {
  261. if (weak_global_) {
  262. if (jenv->IsSameObject(jthis_, NULL) == JNI_FALSE) {
  263. jenv->DeleteWeakGlobalRef((jweak)jthis_);
  264. }
  265. }
  266. else {
  267. jenv->DeleteGlobalRef(jthis_);
  268. }
  269. }
  270. jthis_ = NULL;
  271. weak_global_ = true;
  272. }
  273. jobject peek() {
  274. return jthis_;
  275. }
  276. /* Java proxy releases ownership of C++ object, C++ object is now
  277. responsible for destruction (creates NewGlobalRef to pin Java
  278. proxy) */
  279. void java_change_ownership(JNIEnv *jenv, jobject jself, bool take_or_release) {
  280. if (take_or_release) { /* Java takes ownership of C++ object's lifetime. */
  281. if (!weak_global_) {
  282. jenv->DeleteGlobalRef(jthis_);
  283. jthis_ = jenv->NewWeakGlobalRef(jself);
  284. weak_global_ = true;
  285. }
  286. }
  287. else { /* Java releases ownership of C++ object's lifetime */
  288. if (weak_global_) {
  289. jenv->DeleteWeakGlobalRef((jweak)jthis_);
  290. jthis_ = jenv->NewGlobalRef(jself);
  291. weak_global_ = false;
  292. }
  293. }
  294. }
  295. private:
  296. /* pointer to Java object */
  297. jobject jthis_;
  298. /* Local or global reference flag */
  299. bool weak_global_;
  300. };
  301. /* director base class */
  302. class Director
  303. {
  304. /* pointer to Java virtual machine */
  305. JavaVM *swig_jvm_;
  306. protected:
  307. #if defined (_MSC_VER) && (_MSC_VER<1300)
  308. class JNIEnvWrapper;
  309. friend class JNIEnvWrapper;
  310. #endif
  311. /* Utility class for managing the JNI environment */
  312. class JNIEnvWrapper
  313. {
  314. const Director *director_;
  315. JNIEnv *jenv_;
  316. public:
  317. JNIEnvWrapper(const Director *director) : director_(director), jenv_(0) {
  318. #if defined(SWIG_JAVA_ATTACH_CURRENT_THREAD_AS_DAEMON)
  319. // Attach a daemon thread to the JVM. Useful when the JVM should not wait for
  320. // the thread to exit upon shutdown. Only for jdk-1.4 and later.
  321. director_->swig_jvm_->AttachCurrentThreadAsDaemon((JNIEnv **) &jenv_, NULL);
  322. #else
  323. director_->swig_jvm_->AttachCurrentThread((JNIEnv **) &jenv_, NULL);
  324. #endif
  325. }
  326. ~JNIEnvWrapper() {
  327. #if !defined(SWIG_JAVA_NO_DETACH_CURRENT_THREAD)
  328. // Some JVMs, eg jdk-1.4.2 and lower on Solaris have a bug and crash with the DetachCurrentThread call.
  329. // However, without this call, the JVM hangs on exit when the thread was not created by the JVM and creates a memory leak.
  330. director_->swig_jvm_->DetachCurrentThread();
  331. #endif
  332. }
  333. JNIEnv *getJNIEnv() const {
  334. return jenv_;
  335. }
  336. };
  337. /* Java object wrapper */
  338. JObjectWrapper swig_self_;
  339. /* Disconnect director from Java object */
  340. void swig_disconnect_director_self(const char *disconn_method) {
  341. JNIEnvWrapper jnienv(this) ;
  342. JNIEnv *jenv = jnienv.getJNIEnv() ;
  343. jobject jobj = swig_self_.peek();
  344. #if defined(DEBUG_DIRECTOR_OWNED)
  345. std::cout << "Swig::Director::disconnect_director_self(" << jobj << ")" << std::endl;
  346. #endif
  347. if (jobj && jenv->IsSameObject(jobj, NULL) == JNI_FALSE) {
  348. jmethodID disconn_meth = jenv->GetMethodID(jenv->GetObjectClass(jobj), disconn_method, "()V");
  349. if (disconn_meth) {
  350. #if defined(DEBUG_DIRECTOR_OWNED)
  351. std::cout << "Swig::Director::disconnect_director_self upcall to " << disconn_method << std::endl;
  352. #endif
  353. jenv->CallVoidMethod(jobj, disconn_meth);
  354. }
  355. }
  356. }
  357. public:
  358. Director(JNIEnv *jenv) : swig_jvm_((JavaVM *) NULL), swig_self_() {
  359. /* Acquire the Java VM pointer */
  360. jenv->GetJavaVM(&swig_jvm_);
  361. }
  362. virtual ~Director() {
  363. JNIEnvWrapper jnienv(this) ;
  364. JNIEnv *jenv = jnienv.getJNIEnv() ;
  365. swig_self_.release(jenv);
  366. }
  367. bool swig_set_self(JNIEnv *jenv, jobject jself, bool mem_own, bool weak_global) {
  368. return swig_self_.set(jenv, jself, mem_own, weak_global);
  369. }
  370. jobject swig_get_self(JNIEnv *jenv) const {
  371. return swig_self_.get(jenv);
  372. }
  373. // Change C++ object's ownership, relative to Java
  374. void swig_java_change_ownership(JNIEnv *jenv, jobject jself, bool take_or_release) {
  375. swig_self_.java_change_ownership(jenv, jself, take_or_release);
  376. }
  377. };
  378. }
  379. #endif /* __cplusplus */
  380. #include <stdint.h> // Use the C99 official header
  381. #include "api.h"
  382. /* ---------------------------------------------------
  383. * C++ director class methods
  384. * --------------------------------------------------- */
  385. #include "utils_wrap.h"
  386. #ifdef __cplusplus
  387. extern "C" {
  388. #endif
  389. SWIGEXPORT jlong JNICALL Java_org_doubango_utils_utilsJNI_new_1AndroidUtils(JNIEnv *jenv, jclass jcls)
  390. {
  391. jlong jresult = 0 ;
  392. AndroidUtils *result = 0 ;
  393. (void)jenv;
  394. (void)jcls;
  395. result = (AndroidUtils *)new AndroidUtils();
  396. *(AndroidUtils **)&jresult = result;
  397. return jresult;
  398. }
  399. SWIGEXPORT void JNICALL Java_org_doubango_utils_utilsJNI_delete_1AndroidUtils(JNIEnv *jenv, jclass jcls, jlong jarg1)
  400. {
  401. AndroidUtils *arg1 = (AndroidUtils *) 0 ;
  402. (void)jenv;
  403. (void)jcls;
  404. arg1 = *(AndroidUtils **)&jarg1;
  405. delete arg1;
  406. }
  407. SWIGEXPORT jobject JNICALL Java_org_doubango_utils_utilsJNI_AndroidUtils_1getCpuFamily(JNIEnv *jenv, jclass jcls)
  408. {
  409. jobject jresult = 0 ;
  410. uint64_t result;
  411. (void)jenv;
  412. (void)jcls;
  413. result = (uint64_t)AndroidUtils::getCpuFamily();
  414. {
  415. jbyteArray ba = jenv->NewByteArray(9);
  416. jbyte* bae = jenv->GetByteArrayElements(ba, 0);
  417. jclass clazz = jenv->FindClass("java/math/BigInteger");
  418. jmethodID mid = jenv->GetMethodID(clazz, "<init>", "([B)V");
  419. jobject bigint;
  420. int i;
  421. bae[0] = 0;
  422. for(i=1; i<9; i++ ) {
  423. bae[i] = (jbyte)(result>>8*(8-i));
  424. }
  425. jenv->ReleaseByteArrayElements(ba, bae, 0);
  426. bigint = jenv->NewObject(clazz, mid, ba);
  427. jresult = bigint;
  428. }
  429. return jresult;
  430. }
  431. SWIGEXPORT jobject JNICALL Java_org_doubango_utils_utilsJNI_AndroidUtils_1getCpuFeatures(JNIEnv *jenv, jclass jcls)
  432. {
  433. jobject jresult = 0 ;
  434. uint64_t result;
  435. (void)jenv;
  436. (void)jcls;
  437. result = (uint64_t)AndroidUtils::getCpuFeatures();
  438. {
  439. jbyteArray ba = jenv->NewByteArray(9);
  440. jbyte* bae = jenv->GetByteArrayElements(ba, 0);
  441. jclass clazz = jenv->FindClass("java/math/BigInteger");
  442. jmethodID mid = jenv->GetMethodID(clazz, "<init>", "([B)V");
  443. jobject bigint;
  444. int i;
  445. bae[0] = 0;
  446. for(i=1; i<9; i++ ) {
  447. bae[i] = (jbyte)(result>>8*(8-i));
  448. }
  449. jenv->ReleaseByteArrayElements(ba, bae, 0);
  450. bigint = jenv->NewObject(clazz, mid, ba);
  451. jresult = bigint;
  452. }
  453. return jresult;
  454. }
  455. #ifdef __cplusplus
  456. }
  457. #endif