Initial commit
This commit is contained in:
173
backends/networking/basic/android/jni.cpp
Normal file
173
backends/networking/basic/android/jni.cpp
Normal file
@@ -0,0 +1,173 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Allow use of stuff in <time.h> and abort()
|
||||
#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
|
||||
#define FORBIDDEN_SYMBOL_EXCEPTION_abort
|
||||
|
||||
// Disable printf override in common/forbidden.h to avoid
|
||||
// clashes with log.h from the Android SDK.
|
||||
// That header file uses
|
||||
// __attribute__ ((format(printf, 3, 4)))
|
||||
// which gets messed up by our override mechanism; this could
|
||||
// be avoided by either changing the Android SDK to use the equally
|
||||
// legal and valid
|
||||
// __attribute__ ((format(__printf__, 3, 4)))
|
||||
// or by refining our printf override to use a varadic macro
|
||||
// (which then wouldn't be portable, though).
|
||||
// Anyway, for now we just disable the printf override globally
|
||||
// for the Android port
|
||||
#define FORBIDDEN_SYMBOL_EXCEPTION_printf
|
||||
|
||||
#include "backends/platform/android/android.h"
|
||||
|
||||
#include "backends/networking/basic/android/jni.h"
|
||||
#ifdef USE_HTTP
|
||||
#include "backends/networking/http/android/networkreadstream-android.h"
|
||||
#endif
|
||||
|
||||
namespace Networking {
|
||||
|
||||
jclass NetJNI::_CLS_URL = nullptr;
|
||||
|
||||
jmethodID NetJNI::_MID_url_init = 0;
|
||||
jmethodID NetJNI::_MID_url_getProtocol = 0;
|
||||
jmethodID NetJNI::_MID_url_getHost = 0;
|
||||
jmethodID NetJNI::_MID_url_getPort = 0;
|
||||
jmethodID NetJNI::_MID_url_getDefaultPort = 0;
|
||||
|
||||
jclass NetJNI::_CLS_Socket = nullptr;
|
||||
|
||||
jmethodID NetJNI::_MID_socket_init = 0;
|
||||
jmethodID NetJNI::_MID_socket_ready = 0;
|
||||
jmethodID NetJNI::_MID_socket_send = 0;
|
||||
jmethodID NetJNI::_MID_socket_recv = 0;
|
||||
jmethodID NetJNI::_MID_socket_close = 0;
|
||||
|
||||
#ifdef USE_HTTP
|
||||
jmethodID NetJNI::_MID_manager_init = 0;
|
||||
jmethodID NetJNI::_MID_manager_startRequest = 0;
|
||||
jmethodID NetJNI::_MID_manager_poll = 0;
|
||||
jfieldID NetJNI::_FID_manager__empty = 0;
|
||||
|
||||
jclass NetJNI::_CLS_HTTPRequest = nullptr;
|
||||
|
||||
jmethodID NetJNI::_MID_request_bufinit = 0;
|
||||
jmethodID NetJNI::_MID_request_forminit = 0;
|
||||
jmethodID NetJNI::_MID_request_cancel = 0;
|
||||
jmethodID NetJNI::_MID_request_getURL = 0;
|
||||
|
||||
const JNINativeMethod NetJNI::_natives_request[] = {
|
||||
{ "gotHeaders", "(J[Ljava/lang/String;)V",
|
||||
(void *)NetworkReadStreamAndroid::gotHeaders },
|
||||
{ "gotData", "(J[BII)V",
|
||||
(void *)NetworkReadStreamAndroid::gotData },
|
||||
{ "finished", "(JILjava/lang/String;)V",
|
||||
(void *)NetworkReadStreamAndroid::finished_ },
|
||||
};
|
||||
#endif
|
||||
|
||||
bool NetJNI::_init = false;
|
||||
|
||||
void NetJNI::init(JNIEnv *env) {
|
||||
if (_init) {
|
||||
return;
|
||||
}
|
||||
|
||||
// We can't call error here as the backend is not built yet
|
||||
#define FIND_CONSTRUCTOR(prefix, signature) do { \
|
||||
_MID_ ## prefix ## init = env->GetMethodID(cls, "<init>", signature "V");\
|
||||
if (_MID_ ## prefix ## init == 0) { \
|
||||
LOGE("Can't find method ID <init>"); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
#define FIND_METHOD(prefix, name, signature) do { \
|
||||
_MID_ ## prefix ## name = env->GetMethodID(cls, #name, signature); \
|
||||
if (_MID_ ## prefix ## name == 0) { \
|
||||
LOGE("Can't find method ID " #name); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
#define FIND_FIELD(prefix, name, signature) do { \
|
||||
_FID_ ## prefix ## name = env->GetFieldID(cls, #name, signature); \
|
||||
if (_FID_ ## prefix ## name == 0) { \
|
||||
LOGE("Can't find field ID " #name); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
jclass cls = env->FindClass("java/net/URL");
|
||||
_CLS_URL = (jclass)env->NewGlobalRef(cls);
|
||||
|
||||
FIND_CONSTRUCTOR(url_, "(Ljava/lang/String;)");
|
||||
FIND_METHOD(url_, getProtocol, "()Ljava/lang/String;");
|
||||
FIND_METHOD(url_, getHost, "()Ljava/lang/String;");
|
||||
FIND_METHOD(url_, getPort, "()I");
|
||||
FIND_METHOD(url_, getDefaultPort, "()I");
|
||||
|
||||
env->DeleteLocalRef(cls);
|
||||
|
||||
cls = env->FindClass("org/scummvm/scummvm/net/SSocket");
|
||||
_CLS_Socket = (jclass)env->NewGlobalRef(cls);
|
||||
|
||||
FIND_CONSTRUCTOR(socket_, "(Ljava/lang/String;)");
|
||||
FIND_METHOD(socket_, ready, "()I");
|
||||
FIND_METHOD(socket_, send, "([B)I");
|
||||
FIND_METHOD(socket_, recv, "([B)I");
|
||||
FIND_METHOD(socket_, close, "()V");
|
||||
|
||||
env->DeleteLocalRef(cls);
|
||||
|
||||
#ifdef USE_HTTP
|
||||
cls = env->FindClass("org/scummvm/scummvm/net/HTTPManager");
|
||||
|
||||
FIND_CONSTRUCTOR(manager_, "()");
|
||||
FIND_METHOD(manager_, startRequest, "(Lorg/scummvm/scummvm/net/HTTPRequest;)V");
|
||||
FIND_METHOD(manager_, poll, "()V");
|
||||
FIND_FIELD(manager_, _empty, "Z");
|
||||
|
||||
env->DeleteLocalRef(cls);
|
||||
|
||||
cls = env->FindClass("org/scummvm/scummvm/net/HTTPRequest");
|
||||
_CLS_HTTPRequest = (jclass)env->NewGlobalRef(cls);
|
||||
|
||||
if (env->RegisterNatives(cls, _natives_request, ARRAYSIZE(_natives_request)) < 0) {
|
||||
LOGE("Can't register natives for org/scummvm/scummvm/net/HTTPRequest");
|
||||
abort();
|
||||
}
|
||||
|
||||
FIND_CONSTRUCTOR(request_buf, "(JLjava/lang/String;[Ljava/lang/String;[BZZZ)");
|
||||
FIND_CONSTRUCTOR(request_form, "(JLjava/lang/String;[Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;)");
|
||||
FIND_METHOD(request_, cancel, "()V");
|
||||
FIND_METHOD(request_, getURL, "()Ljava/lang/String;");
|
||||
|
||||
env->DeleteLocalRef(cls);
|
||||
#endif
|
||||
|
||||
#undef FIND_FIELD
|
||||
#undef FIND_METHOD
|
||||
#undef FIND_CONSTRUCTOR
|
||||
|
||||
_init = true;
|
||||
}
|
||||
|
||||
} // End of namespace Networking
|
||||
79
backends/networking/basic/android/jni.h
Normal file
79
backends/networking/basic/android/jni.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BACKENDS_NETWORKING_BASIC_ANDROID_JNI_H
|
||||
#define BACKENDS_NETWORKING_BASIC_ANDROID_JNI_H
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
namespace Networking {
|
||||
|
||||
class NetJNI {
|
||||
#ifdef USE_HTTP
|
||||
friend class ConnectionManagerAndroid;
|
||||
friend class NetworkReadStreamAndroid;
|
||||
#endif
|
||||
friend class AndroidSocket;
|
||||
friend class AndroidURL;
|
||||
|
||||
public:
|
||||
static void init(JNIEnv *env);
|
||||
|
||||
private:
|
||||
static jclass _CLS_URL;
|
||||
|
||||
static jmethodID _MID_url_init;
|
||||
static jmethodID _MID_url_getProtocol;
|
||||
static jmethodID _MID_url_getHost;
|
||||
static jmethodID _MID_url_getPort;
|
||||
static jmethodID _MID_url_getDefaultPort;
|
||||
|
||||
static jclass _CLS_Socket;
|
||||
|
||||
static jmethodID _MID_socket_init;
|
||||
static jmethodID _MID_socket_ready;
|
||||
static jmethodID _MID_socket_send;
|
||||
static jmethodID _MID_socket_recv;
|
||||
static jmethodID _MID_socket_close;
|
||||
|
||||
#ifdef USE_HTTP
|
||||
static jmethodID _MID_manager_init;
|
||||
static jmethodID _MID_manager_startRequest;
|
||||
static jmethodID _MID_manager_poll;
|
||||
static jfieldID _FID_manager__empty;
|
||||
|
||||
static const JNINativeMethod _natives_request[];
|
||||
|
||||
static jclass _CLS_HTTPRequest;
|
||||
|
||||
static jmethodID _MID_request_bufinit;
|
||||
static jmethodID _MID_request_forminit;
|
||||
static jmethodID _MID_request_cancel;
|
||||
static jmethodID _MID_request_getURL;
|
||||
#endif
|
||||
|
||||
static bool _init;
|
||||
};
|
||||
|
||||
} // End of namespace Networking
|
||||
|
||||
#endif
|
||||
|
||||
156
backends/networking/basic/android/socket.cpp
Normal file
156
backends/networking/basic/android/socket.cpp
Normal file
@@ -0,0 +1,156 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Allow use of stuff in <time.h> and abort()
|
||||
#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
|
||||
#define FORBIDDEN_SYMBOL_EXCEPTION_abort
|
||||
|
||||
// Disable printf override in common/forbidden.h to avoid
|
||||
// clashes with log.h from the Android SDK.
|
||||
// That header file uses
|
||||
// __attribute__ ((format(printf, 3, 4)))
|
||||
// which gets messed up by our override mechanism; this could
|
||||
// be avoided by either changing the Android SDK to use the equally
|
||||
// legal and valid
|
||||
// __attribute__ ((format(__printf__, 3, 4)))
|
||||
// or by refining our printf override to use a varadic macro
|
||||
// (which then wouldn't be portable, though).
|
||||
// Anyway, for now we just disable the printf override globally
|
||||
// for the Android port
|
||||
#define FORBIDDEN_SYMBOL_EXCEPTION_printf
|
||||
|
||||
#include "backends/platform/android/android.h"
|
||||
#include "backends/platform/android/jni-android.h"
|
||||
|
||||
#include "backends/networking/basic/android/jni.h"
|
||||
|
||||
#include "backends/networking/basic/android/socket.h"
|
||||
|
||||
#include "common/debug.h"
|
||||
#include "common/textconsole.h"
|
||||
|
||||
namespace Networking {
|
||||
|
||||
Socket *Socket::connect(const Common::String &url) {
|
||||
return AndroidSocket::connect(url);
|
||||
}
|
||||
|
||||
Socket *AndroidSocket::connect(const Common::String &url) {
|
||||
JNIEnv *env = JNI::getEnv();
|
||||
NetJNI::init(env);
|
||||
|
||||
jstring url_obj = env->NewStringUTF(url.c_str());
|
||||
jobject socket_obj = env->NewObject(NetJNI::_CLS_Socket, NetJNI::_MID_socket_init, url_obj);
|
||||
|
||||
env->DeleteLocalRef(url_obj);
|
||||
|
||||
if (env->ExceptionCheck()) {
|
||||
LOGE("Socket::<init> failed");
|
||||
env->ExceptionDescribe();
|
||||
env->ExceptionClear();
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Socket *socket = new AndroidSocket(env, socket_obj);
|
||||
env->DeleteLocalRef(socket_obj);
|
||||
|
||||
return socket;
|
||||
}
|
||||
|
||||
AndroidSocket::AndroidSocket(JNIEnv *env, jobject socket) {
|
||||
_socket = env->NewGlobalRef(socket);
|
||||
}
|
||||
|
||||
AndroidSocket::~AndroidSocket() {
|
||||
JNIEnv *env = JNI::getEnv();
|
||||
|
||||
env->CallVoidMethod(_socket, NetJNI::_MID_socket_close);
|
||||
if (env->ExceptionCheck()) {
|
||||
LOGE("Socket::close failed");
|
||||
env->ExceptionDescribe();
|
||||
env->ExceptionClear();
|
||||
}
|
||||
|
||||
env->DeleteGlobalRef(_socket);
|
||||
}
|
||||
|
||||
int AndroidSocket::ready() {
|
||||
JNIEnv *env = JNI::getEnv();
|
||||
|
||||
jint ret = env->CallIntMethod(_socket, NetJNI::_MID_socket_ready);
|
||||
if (env->ExceptionCheck()) {
|
||||
LOGE("Socket::ready failed");
|
||||
env->ExceptionDescribe();
|
||||
env->ExceptionClear();
|
||||
|
||||
// In doubt make it ready
|
||||
return 1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t AndroidSocket::send(const char *data, int len) {
|
||||
JNIEnv *env = JNI::getEnv();
|
||||
|
||||
jbyteArray buffer_obj = env->NewByteArray(len);
|
||||
env->SetByteArrayRegion(buffer_obj, 0, len, (const jbyte *)data);
|
||||
|
||||
jint sent = env->CallIntMethod(_socket, NetJNI::_MID_socket_send, buffer_obj);
|
||||
|
||||
env->DeleteLocalRef(buffer_obj);
|
||||
|
||||
if (env->ExceptionCheck()) {
|
||||
LOGE("Socket::send failed");
|
||||
env->ExceptionDescribe();
|
||||
env->ExceptionClear();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return sent;
|
||||
}
|
||||
|
||||
size_t AndroidSocket::recv(void *data, int maxLen) {
|
||||
JNIEnv *env = JNI::getEnv();
|
||||
|
||||
jbyteArray buffer_obj = env->NewByteArray(maxLen);
|
||||
|
||||
jint recvd = env->CallIntMethod(_socket, NetJNI::_MID_socket_recv, buffer_obj);
|
||||
assert(recvd <= maxLen);
|
||||
|
||||
if (env->ExceptionCheck()) {
|
||||
LOGE("Socket::send failed");
|
||||
env->ExceptionDescribe();
|
||||
env->ExceptionClear();
|
||||
|
||||
env->DeleteLocalRef(buffer_obj);
|
||||
return 0;
|
||||
}
|
||||
|
||||
env->GetByteArrayRegion(buffer_obj, 0, recvd, (jbyte *)data);
|
||||
|
||||
return recvd;
|
||||
}
|
||||
|
||||
} // End of namespace Networking
|
||||
|
||||
47
backends/networking/basic/android/socket.h
Normal file
47
backends/networking/basic/android/socket.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#ifndef BACKENDS_NETWORKING_BASIC_CURL_SOCKET_H
|
||||
#define BACKENDS_NETWORKING_BASIC_CURL_SOCKET_H
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include "backends/networking/basic/socket.h"
|
||||
|
||||
namespace Networking {
|
||||
|
||||
class AndroidSocket : public Socket {
|
||||
public:
|
||||
static Socket *connect(const Common::String &url);
|
||||
|
||||
AndroidSocket(JNIEnv *env, jobject socket);
|
||||
~AndroidSocket() override;
|
||||
|
||||
int ready() override;
|
||||
|
||||
size_t send(const char *data, int len) override;
|
||||
size_t recv(void *data, int maxLen) override;
|
||||
private:
|
||||
jobject _socket;
|
||||
};
|
||||
|
||||
} // End of namespace Networking
|
||||
|
||||
#endif
|
||||
180
backends/networking/basic/android/url.cpp
Normal file
180
backends/networking/basic/android/url.cpp
Normal file
@@ -0,0 +1,180 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Allow use of stuff in <time.h> and abort()
|
||||
#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
|
||||
#define FORBIDDEN_SYMBOL_EXCEPTION_abort
|
||||
|
||||
// Disable printf override in common/forbidden.h to avoid
|
||||
// clashes with log.h from the Android SDK.
|
||||
// That header file uses
|
||||
// __attribute__ ((format(printf, 3, 4)))
|
||||
// which gets messed up by our override mechanism; this could
|
||||
// be avoided by either changing the Android SDK to use the equally
|
||||
// legal and valid
|
||||
// __attribute__ ((format(__printf__, 3, 4)))
|
||||
// or by refining our printf override to use a varadic macro
|
||||
// (which then wouldn't be portable, though).
|
||||
// Anyway, for now we just disable the printf override globally
|
||||
// for the Android port
|
||||
#define FORBIDDEN_SYMBOL_EXCEPTION_printf
|
||||
|
||||
#include "backends/platform/android/android.h"
|
||||
#include "backends/platform/android/jni-android.h"
|
||||
|
||||
#include "backends/networking/basic/android/jni.h"
|
||||
|
||||
#include "backends/networking/basic/android/url.h"
|
||||
|
||||
#include "common/debug.h"
|
||||
#include "common/textconsole.h"
|
||||
|
||||
namespace Networking {
|
||||
|
||||
URL *URL::parseURL(const Common::String &url) {
|
||||
return AndroidURL::parseURL(url);
|
||||
}
|
||||
|
||||
URL *AndroidURL::parseURL(const Common::String &url) {
|
||||
JNIEnv *env = JNI::getEnv();
|
||||
NetJNI::init(env);
|
||||
|
||||
jstring url_sobj = env->NewStringUTF(url.c_str());
|
||||
jobject url_obj = env->NewObject(NetJNI::_CLS_URL, NetJNI::_MID_url_init, url_sobj);
|
||||
|
||||
env->DeleteLocalRef(url_sobj);
|
||||
|
||||
if (env->ExceptionCheck()) {
|
||||
LOGE("URL::<init> failed");
|
||||
env->ExceptionDescribe();
|
||||
env->ExceptionClear();
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
URL *url_ = new AndroidURL(env, url_obj);
|
||||
env->DeleteLocalRef(url_obj);
|
||||
|
||||
return url_;
|
||||
}
|
||||
|
||||
AndroidURL::AndroidURL(JNIEnv *env, jobject url) {
|
||||
_url = env->NewGlobalRef(url);
|
||||
}
|
||||
|
||||
AndroidURL::~AndroidURL() {
|
||||
JNIEnv *env = JNI::getEnv();
|
||||
env->DeleteGlobalRef(_url);
|
||||
}
|
||||
|
||||
Common::String AndroidURL::getScheme() const {
|
||||
JNIEnv *env = JNI::getEnv();
|
||||
|
||||
jstring protocol_obj = (jstring)env->CallObjectMethod(_url, NetJNI::_MID_url_getProtocol);
|
||||
if (env->ExceptionCheck()) {
|
||||
LOGE("URL::getProtocol failed");
|
||||
env->ExceptionDescribe();
|
||||
env->ExceptionClear();
|
||||
|
||||
return Common::String();
|
||||
}
|
||||
|
||||
uint length = env->GetStringLength(protocol_obj);
|
||||
if (!length) {
|
||||
env->DeleteLocalRef(protocol_obj);
|
||||
return Common::String();
|
||||
}
|
||||
|
||||
const char *protocol_ptr = env->GetStringUTFChars(protocol_obj, 0);
|
||||
if (!protocol_ptr) {
|
||||
env->DeleteLocalRef(protocol_obj);
|
||||
return Common::String();
|
||||
}
|
||||
|
||||
Common::String result(protocol_ptr, length);
|
||||
|
||||
env->ReleaseStringUTFChars(protocol_obj, protocol_ptr);
|
||||
env->DeleteLocalRef(protocol_obj);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Common::String AndroidURL::getHost() const {
|
||||
JNIEnv *env = JNI::getEnv();
|
||||
|
||||
jstring protocol_obj = (jstring)env->CallObjectMethod(_url, NetJNI::_MID_url_getHost);
|
||||
if (env->ExceptionCheck()) {
|
||||
LOGE("URL::getHost failed");
|
||||
env->ExceptionDescribe();
|
||||
env->ExceptionClear();
|
||||
|
||||
return Common::String();
|
||||
}
|
||||
|
||||
uint length = env->GetStringLength(protocol_obj);
|
||||
if (!length) {
|
||||
env->DeleteLocalRef(protocol_obj);
|
||||
return Common::String();
|
||||
}
|
||||
|
||||
const char *protocol_ptr = env->GetStringUTFChars(protocol_obj, 0);
|
||||
if (!protocol_ptr) {
|
||||
env->DeleteLocalRef(protocol_obj);
|
||||
return Common::String();
|
||||
}
|
||||
|
||||
Common::String result(protocol_ptr, length);
|
||||
|
||||
env->ReleaseStringUTFChars(protocol_obj, protocol_ptr);
|
||||
env->DeleteLocalRef(protocol_obj);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int AndroidURL::getPort(bool defaultPort) const {
|
||||
JNIEnv *env = JNI::getEnv();
|
||||
|
||||
jint port = env->CallIntMethod(_url, NetJNI::_MID_url_getPort);
|
||||
if (env->ExceptionCheck()) {
|
||||
LOGE("URL::getPort failed");
|
||||
env->ExceptionDescribe();
|
||||
env->ExceptionClear();
|
||||
|
||||
return -1;
|
||||
}
|
||||
if (port == -1 && defaultPort) {
|
||||
port = env->CallIntMethod(_url, NetJNI::_MID_url_getDefaultPort);
|
||||
if (env->ExceptionCheck()) {
|
||||
LOGE("URL::getDefaultPort failed");
|
||||
env->ExceptionDescribe();
|
||||
env->ExceptionClear();
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (port == -1) {
|
||||
port = 0;
|
||||
}
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
} // End of namespace Networking
|
||||
47
backends/networking/basic/android/url.h
Normal file
47
backends/networking/basic/android/url.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#ifndef BACKENDS_NETWORKING_BASIC_ANDROID_URL_H
|
||||
#define BACKENDS_NETWORKING_BASIC_ANDROID_URL_H
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include "backends/networking/basic/url.h"
|
||||
|
||||
namespace Networking {
|
||||
|
||||
class AndroidURL : public URL {
|
||||
public:
|
||||
static URL *parseURL(const Common::String &url);
|
||||
|
||||
AndroidURL(JNIEnv *env, jobject url);
|
||||
|
||||
~AndroidURL() override;
|
||||
|
||||
Common::String getScheme() const override;
|
||||
Common::String getHost() const override;
|
||||
int getPort(bool returnDefault = false) const override;
|
||||
private:
|
||||
jobject _url;
|
||||
};
|
||||
|
||||
} // End of Namespace Networking
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user