[Scummvm-git-logs] scummvm master -> 8ce6a32ac23941e70b74ae8f7f0c2bdb2ec72504

antoniou79 noreply at scummvm.org
Sun Mar 26 09:05:22 UTC 2023


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
8ce6a32ac2 ANDROID: Clean up log code and use Backends::Log


Commit: 8ce6a32ac23941e70b74ae8f7f0c2bdb2ec72504
    https://github.com/scummvm/scummvm/commit/8ce6a32ac23941e70b74ae8f7f0c2bdb2ec72504
Author: Antoniou Athanasios (a.antoniou79 at gmail.com)
Date: 2023-03-26T12:05:12+03:00

Commit Message:
ANDROID: Clean up log code and use Backends::Log

Changed paths:
    backends/graphics/android/android-graphics.cpp
    backends/graphics3d/android/android-graphics3d.cpp
    backends/graphics3d/android/texture.cpp
    backends/platform/android/android.cpp
    backends/platform/android/android.h
    backends/platform/android/events.cpp
    backends/platform/android/jni-android.cpp
    backends/platform/android/options.cpp


diff --git a/backends/graphics/android/android-graphics.cpp b/backends/graphics/android/android-graphics.cpp
index 06e85eba9b2..ebdf4f3b858 100644
--- a/backends/graphics/android/android-graphics.cpp
+++ b/backends/graphics/android/android-graphics.cpp
@@ -36,13 +36,12 @@
 // for the Android port
 #define FORBIDDEN_SYMBOL_EXCEPTION_printf
 
-#include "graphics/blit.h"
-
-#include "backends/graphics/opengl/pipelines/pipeline.h"
-
-#include "backends/graphics/android/android-graphics.h"
 #include "backends/platform/android/android.h"
 #include "backends/platform/android/jni-android.h"
+#include "backends/graphics/android/android-graphics.h"
+#include "backends/graphics/opengl/pipelines/pipeline.h"
+
+#include "graphics/blit.h"
 
 static void loadBuiltinTexture(JNI::BitmapResources resource, OpenGL::Surface *surf) {
 	const Graphics::Surface *src = JNI::getBitmapResource(resource);
diff --git a/backends/graphics3d/android/android-graphics3d.cpp b/backends/graphics3d/android/android-graphics3d.cpp
index 3648fa9acc4..4e7f3e36e8c 100644
--- a/backends/graphics3d/android/android-graphics3d.cpp
+++ b/backends/graphics3d/android/android-graphics3d.cpp
@@ -36,14 +36,15 @@
 // for the Android port
 #define FORBIDDEN_SYMBOL_EXCEPTION_printf
 
+#include "backends/platform/android/android.h"
+#include "backends/platform/android/jni-android.h"
+
 #include "common/tokenizer.h"
 #include "graphics/blit.h"
 #include "graphics/opengl/shader.h"
 #include "graphics/opengl/context.h"
 
 #include "backends/graphics3d/android/android-graphics3d.h"
-#include "backends/platform/android/android.h"
-#include "backends/platform/android/jni-android.h"
 
 // These helper macros let us setup our context only when the game has different settings than us
 #define CONTEXT_SAVE_STATE(gl_param) GLboolean saved ## gl_param; GLCALL(saved ## gl_param = glIsEnabled(gl_param))
diff --git a/backends/graphics3d/android/texture.cpp b/backends/graphics3d/android/texture.cpp
index 36782d8e0b3..7ae71ac930e 100644
--- a/backends/graphics3d/android/texture.cpp
+++ b/backends/graphics3d/android/texture.cpp
@@ -36,6 +36,9 @@
 // for the Android port
 #define FORBIDDEN_SYMBOL_EXCEPTION_printf
 
+#include "backends/platform/android/android.h"
+#include "backends/platform/android/jni-android.h"
+
 #include "base/main.h"
 #include "graphics/surface.h"
 #include "graphics/opengl/shader.h"
@@ -45,8 +48,6 @@
 #include "common/array.h"
 #include "common/util.h"
 
-#include "backends/platform/android/android.h"
-#include "backends/platform/android/jni-android.h"
 #include "backends/graphics3d/android/texture.h"
 
 // Supported GL extensions
diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp
index c16543d4489..ffb4725322c 100644
--- a/backends/platform/android/android.cpp
+++ b/backends/platform/android/android.cpp
@@ -43,10 +43,10 @@
 #define FORBIDDEN_SYMBOL_EXCEPTION_FILE
 #define FORBIDDEN_SYMBOL_EXCEPTION_fopen
 #define FORBIDDEN_SYMBOL_EXCEPTION_fclose
-#define FORBIDDEN_SYMBOL_EXCEPTION_fputs
-#define FORBIDDEN_SYMBOL_EXCEPTION_fwrite
+//#define FORBIDDEN_SYMBOL_EXCEPTION_fputs
+//#define FORBIDDEN_SYMBOL_EXCEPTION_fwrite
 #define FORBIDDEN_SYMBOL_EXCEPTION_ftell
-#define FORBIDDEN_SYMBOL_EXCEPTION_fflush
+//#define FORBIDDEN_SYMBOL_EXCEPTION_fflush
 
 #include <EGL/egl.h>
 #include <sys/time.h>
@@ -56,14 +56,14 @@
 #include <unistd.h>
 #include <dlfcn.h>
 
-#include "common/util.h"
-#include "common/textconsole.h"
-#include "common/rect.h"
-#include "common/queue.h"
-#include "common/mutex.h"
-#include "common/events.h"
-#include "common/config-manager.h"
-#include "graphics/cursorman.h"
+#include "backends/platform/android/android.h"
+#include "backends/platform/android/jni-android.h"
+#include "backends/fs/android/android-fs.h"
+#include "backends/fs/android/android-fs-factory.h"
+#include "backends/fs/posix/posix-iostream.h"
+
+#include "backends/graphics/android/android-graphics.h"
+#include "backends/graphics3d/android/android-graphics3d.h"
 
 #include "backends/audiocd/default/default-audiocd.h"
 #include "backends/events/default/default-events.h"
@@ -75,12 +75,14 @@
 #include "backends/keymapper/keymapper-defaults.h"
 #include "backends/keymapper/standard-actions.h"
 
-#include "backends/graphics/android/android-graphics.h"
-#include "backends/graphics3d/android/android-graphics3d.h"
-#include "backends/platform/android/jni-android.h"
-#include "backends/platform/android/android.h"
-#include "backends/fs/android/android-fs.h"
-#include "backends/fs/android/android-fs-factory.h"
+#include "common/util.h"
+#include "common/textconsole.h"
+#include "common/rect.h"
+#include "common/queue.h"
+#include "common/mutex.h"
+#include "common/events.h"
+#include "common/config-manager.h"
+#include "graphics/cursorman.h"
 
 const char *android_log_tag = "ScummVM";
 
@@ -190,23 +192,29 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) :
 	_trackball_scale(2),
 	_joystick_scale(10),
 	_defaultConfigFileName(""),
-	_defaultLogFileName("") {
-//	_scvmLogFilePtr(nullptr) {
-
-	LOGI("Running on: [%s] [%s] [%s] [%s] [%s] SDK:%s ABI:%s",
-			getSystemProperty("ro.product.manufacturer").c_str(),
-			getSystemProperty("ro.product.model").c_str(),
-			getSystemProperty("ro.product.brand").c_str(),
-			getSystemProperty("ro.build.fingerprint").c_str(),
-			getSystemProperty("ro.build.display.id").c_str(),
-			getSystemProperty("ro.build.version.sdk").c_str(),
-			getSystemProperty("ro.product.cpu.abi").c_str());
+	_defaultLogFileName(""),
+	_systemPropertiesSummaryStr(""),
+	_systemSDKdetectedStr(""),
+	_logger(nullptr) {
+
+	_systemPropertiesSummaryStr = Common::String::format("Running on: [%s] [%s] [%s] [%s] [%s] SDK:%s ABI:%s\n",
+	                                                   getSystemProperty("ro.product.manufacturer").c_str(),
+	                                                   getSystemProperty("ro.product.model").c_str(),
+	                                                   getSystemProperty("ro.product.brand").c_str(),
+	                                                   getSystemProperty("ro.build.fingerprint").c_str(),
+	                                                   getSystemProperty("ro.build.display.id").c_str(),
+	                                                   getSystemProperty("ro.build.version.sdk").c_str(),
+	                                                   getSystemProperty("ro.product.cpu.abi").c_str()) ;
+
+	LOGI("%s", _systemPropertiesSummaryStr.c_str());
 	// JNI::getAndroidSDKVersionId() should be identical to the result from ("ro.build.version.sdk"),
 	// though getting it via JNI is maybe the most reliable option (?)
 	// Also __system_property_get which is used by getSystemProperty() is being deprecated in recent NDKs
 
 	int sdkVersion = JNI::getAndroidSDKVersionId();
-	LOGI("SDK Version: %d", sdkVersion);
+
+	_systemSDKdetectedStr = Common::String::format("SDK Version: %d\n", sdkVersion) ;
+	LOGI("%s", _systemSDKdetectedStr.c_str());
 
 	AndroidFilesystemFactory &fsFactory = AndroidFilesystemFactory::instance();
 	if (sdkVersion >= 24) {
@@ -244,11 +252,8 @@ OSystem_Android::~OSystem_Android() {
 	// Uninitialize surface now to avoid it to be done later when touch controls are destroyed
 	dynamic_cast<AndroidCommonGraphics *>(_graphicsManager)->deinitSurface();
 
-//	// close log file
-//	if (_scvmLogFilePtr != nullptr) {
-//		fflush(_scvmLogFilePtr);
-//		fclose(_scvmLogFilePtr);
-//	}
+	delete _logger;
+	_logger = nullptr;
 }
 
 void *OSystem_Android::timerThreadFunc(void *arg) {
@@ -422,18 +427,25 @@ void OSystem_Android::initBackend() {
 
 	_main_thread = pthread_self();
 
-//	// Open log file
-//	if (!getDefaultLogFileName().empty()) {
-//		_scvmLogFilePtr = fopen(getDefaultLogFileName().c_str(), "a");
-//		if (_scvmLogFilePtr != nullptr) {
-//			LOGD("Opened log file for writing upon initializing backend");
-//		} else {
-//			LOGE("Error when opening log file for writing upon initializing backend");
-//		}
-//	} else {
-//		LOGE("Error: log file path not known yet, upon initializing backend");
-//	}
+	if (!_logger)
+		_logger = new Backends::Log::Log(this);
+
+	if (_logger) {
+		Common::WriteStream *logFile = createLogFileForAppending();
+		if (logFile) {
+			_logger->open(logFile);
 
+			if (!_systemPropertiesSummaryStr.empty())
+				_logger->print(_systemPropertiesSummaryStr.c_str());
+
+			if (!_systemSDKdetectedStr.empty())
+				_logger->print(_systemSDKdetectedStr.c_str());
+		} else {
+			LOGE("Error when opening log file for writing upon initializing backend");
+			//_logger->close();
+			_logger = nullptr;
+		}
+	}
 
 	// Warning: ConfMan.registerDefault() can be used for a Session of ScummVM
 	//          but:
@@ -575,6 +587,37 @@ Common::String OSystem_Android::getDefaultLogFileName() {
 	return _defaultLogFileName;
 }
 
+Common::WriteStream *OSystem_Android::createLogFileForAppending() {
+	if (getDefaultLogFileName().empty()) {
+		__android_log_write(ANDROID_LOG_ERROR, android_log_tag, "Log file path is not known upon create attempt!");
+		return nullptr;
+	}
+
+	FILE *scvmLogFilePtr = fopen(getDefaultLogFileName().c_str(), "a");
+	if (scvmLogFilePtr != nullptr) {
+		long sz = ftell(scvmLogFilePtr);
+		if (sz > MAX_ANDROID_SCUMMVM_LOG_FILESIZE_IN_BYTES) {
+			fclose(scvmLogFilePtr);
+			__android_log_write(ANDROID_LOG_WARN, android_log_tag, "Default log file is bigger than 100KB. It will be overwritten!");
+			if (!getDefaultLogFileName().empty()) {
+				// Create the log file from scratch overwriting the previous one
+				scvmLogFilePtr = fopen(getDefaultLogFileName().c_str(), "w");
+				if (scvmLogFilePtr == nullptr) {
+					__android_log_write(ANDROID_LOG_ERROR, android_log_tag, "Could not open default log file for rewrite!");
+					return nullptr;
+				}
+			} else {
+				__android_log_write(ANDROID_LOG_ERROR, android_log_tag, "Log file path is not known upon rewrite attempt!");
+				return nullptr;
+			}
+		}
+	} else {
+		__android_log_write(ANDROID_LOG_ERROR, android_log_tag, "Could not open default log file for writing/appending.");
+		__android_log_write(ANDROID_LOG_ERROR, android_log_tag, getDefaultLogFileName().c_str());
+	}
+	return new PosixIoStream(scvmLogFilePtr);
+}
+
 bool OSystem_Android::hasFeature(Feature f) {
 	if (f == kFeatureFullscreenMode)
 		return false;
@@ -770,41 +813,10 @@ void OSystem_Android::logMessage(LogMessageType::Type type, const char *message)
 		break;
 	}
 
-	if (!getDefaultLogFileName().empty()) {
-		// open for append by default
-		FILE *_scvmLogFilePtr = fopen(getDefaultLogFileName().c_str(), "a");
-
-		// TODO Do we need to worry about threading/synchronization here?
-		if (_scvmLogFilePtr != nullptr) {
-			long sz = ftell(_scvmLogFilePtr);
-			if (sz > MAX_ANDROID_SCUMMVM_LOG_FILESIZE_IN_BYTES) {
-				fclose(_scvmLogFilePtr);
-				__android_log_write(ANDROID_LOG_WARN, android_log_tag, "Default log file is bigger than 100KB. It will be overwritten!");
-				if (!getDefaultLogFileName().empty()) {
-					// Create the log file from scratch overwriting the previous one
-					_scvmLogFilePtr = fopen(getDefaultLogFileName().c_str(), "w");
-					if (_scvmLogFilePtr == nullptr) {
-						__android_log_write(ANDROID_LOG_ERROR, android_log_tag, "Could not open default log file for rewrite!");
-						return;
-					}
-				} else {
-					__android_log_write(ANDROID_LOG_ERROR, android_log_tag, "Log file path is not known!");
-					return;
-				}
-			}
+	// Then log into file (via the logger)
+	if (_logger)
+		_logger->print(message);
 
-			fputs(message, _scvmLogFilePtr);
-			fwrite("\n", 1, 1, _scvmLogFilePtr);
-			// close log file
-			fflush(_scvmLogFilePtr);
-			fclose(_scvmLogFilePtr);
-		} else {
-			__android_log_write(ANDROID_LOG_ERROR, android_log_tag, "Could not open default log file for writing/appending.");
-			__android_log_write(ANDROID_LOG_ERROR, android_log_tag, getDefaultLogFileName().c_str());
-		}
-	}   else {
-		__android_log_write(ANDROID_LOG_ERROR, android_log_tag, "Error: log file path not known yet, upon initializing backend");
-	}
 }
 
 Common::String OSystem_Android::getSystemLanguage() const {
diff --git a/backends/platform/android/android.h b/backends/platform/android/android.h
index 517681d51d6..3e3ad59fb3c 100644
--- a/backends/platform/android/android.h
+++ b/backends/platform/android/android.h
@@ -18,13 +18,14 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  */
-//#define FORBIDDEN_SYMBOL_EXCEPTION_FILE
 
 #ifndef _ANDROID_H_
 #define _ANDROID_H_
 
 #if defined(__ANDROID__)
 
+#define FORBIDDEN_SYMBOL_EXCEPTION_FILE
+
 #include "backends/platform/android/portdefs.h"
 #include "common/fs.h"
 #include "common/archive.h"
@@ -34,7 +35,8 @@
 #include "backends/modular-backend.h"
 #include "backends/plugins/posix/posix-provider.h"
 #include "backends/fs/posix/posix-fs-factory.h"
-
+#include "backends/fs/posix/posix-fs-factory.h"
+#include "backends/log/log.h"
 #include "backends/platform/android/touchcontrols.h"
 
 #include <pthread.h>
@@ -110,46 +112,15 @@ private:
 
 	bool _timer_thread_exit;
 	pthread_t _timer_thread;
-	static void *timerThreadFunc(void *arg);
 
 	bool _audio_thread_exit;
 	pthread_t _audio_thread;
-	static void *audioThreadFunc(void *arg);
 
 	bool _virtkeybd_on;
 
 	Audio::MixerImpl *_mixer;
 	timeval _startTime;
 
-	Common::String getSystemProperty(const char *name) const;
-
-public:
-	enum {
-		TOUCH_MODE_TOUCHPAD = 0,
-		TOUCH_MODE_MOUSE = 1,
-		TOUCH_MODE_GAMEPAD = 2,
-		TOUCH_MODE_MAX = 3
-	};
-
-	OSystem_Android(int audio_sample_rate, int audio_buffer_size);
-	virtual ~OSystem_Android();
-
-	void initBackend() override;
-
-	bool hasFeature(OSystem::Feature f) override;
-	void setFeatureState(OSystem::Feature f, bool enable) override;
-	bool getFeatureState(OSystem::Feature f) override;
-
-public:
-	void pushEvent(int type, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6);
-	void pushEvent(const Common::Event &event);
-	void pushEvent(const Common::Event &event1, const Common::Event &event2);
-
-	TouchControls &getTouchControls() { return _touchControls; }
-	void applyTouchSettings(bool _3dMode, bool overlayShown);
-	void setupTouchMode(int oldValue, int newValue);
-
-private:
 	Common::Queue<Common::Event> _event_queue;
 	Common::Event _queuedEvent;
 	uint32 _queuedEventTime;
@@ -172,14 +143,47 @@ private:
 
 	Common::String _defaultConfigFileName;
 	Common::String _defaultLogFileName;
+	Common::String _systemPropertiesSummaryStr;
+	Common::String _systemSDKdetectedStr;
 
-//	FILE *_scvmLogFilePtr;
+	Backends::Log::Log *_logger;
 
 #if defined(USE_OPENGL) && defined(USE_GLAD)
 	// Cached dlopen object
 	mutable void *_gles2DL;
 #endif
+
+	static void *timerThreadFunc(void *arg);
+	static void *audioThreadFunc(void *arg);
+	Common::String getSystemProperty(const char *name) const;
+
+	Common::WriteStream *createLogFileForAppending();
+
 public:
+	enum {
+		TOUCH_MODE_TOUCHPAD = 0,
+		TOUCH_MODE_MOUSE = 1,
+		TOUCH_MODE_GAMEPAD = 2,
+		TOUCH_MODE_MAX = 3
+	};
+
+	OSystem_Android(int audio_sample_rate, int audio_buffer_size);
+	virtual ~OSystem_Android();
+
+	void initBackend() override;
+
+	bool hasFeature(OSystem::Feature f) override;
+	void setFeatureState(OSystem::Feature f, bool enable) override;
+	bool getFeatureState(OSystem::Feature f) override;
+
+	void pushEvent(int type, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6);
+	void pushEvent(const Common::Event &event);
+	void pushEvent(const Common::Event &event1, const Common::Event &event2);
+
+	TouchControls &getTouchControls() { return _touchControls; }
+	void applyTouchSettings(bool _3dMode, bool overlayShown);
+	void setupTouchMode(int oldValue, int newValue);
+
 	bool pollEvent(Common::Event &event) override;
 	Common::HardwareInputSet *getHardwareInputSet() override;
 	Common::KeymapArray getGlobalKeymaps() override;
@@ -224,6 +228,7 @@ public:
 #ifdef ANDROID_DEBUG_GL_CALLS
 	bool isRunningInMainThread() { return pthread_self() == _main_thread; }
 #endif
+
 };
 
 #endif
diff --git a/backends/platform/android/events.cpp b/backends/platform/android/events.cpp
index beab7fae4e9..9d3a64ead7d 100644
--- a/backends/platform/android/events.cpp
+++ b/backends/platform/android/events.cpp
@@ -40,8 +40,8 @@
 
 #include <android/input.h>
 
-#include "backends/graphics/android/android-graphics.h"
 #include "backends/platform/android/android.h"
+#include "backends/graphics/android/android-graphics.h"
 #include "backends/platform/android/jni-android.h"
 
 // floating point. use sparingly
diff --git a/backends/platform/android/jni-android.cpp b/backends/platform/android/jni-android.cpp
index 4d9567be215..b60da9ccde9 100644
--- a/backends/platform/android/jni-android.cpp
+++ b/backends/platform/android/jni-android.cpp
@@ -41,6 +41,10 @@
 
 #include <android/bitmap.h>
 
+#include "backends/platform/android/android.h"
+#include "backends/platform/android/jni-android.h"
+#include "backends/platform/android/asset-archive.h"
+
 #include "base/main.h"
 #include "base/version.h"
 #include "common/config-manager.h"
@@ -49,10 +53,6 @@
 #include "engines/engine.h"
 #include "graphics/surface.h"
 
-#include "backends/platform/android/android.h"
-#include "backends/platform/android/asset-archive.h"
-#include "backends/platform/android/jni-android.h"
-
 __attribute__ ((visibility("default")))
 jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
 	return JNI::onLoad(vm);
diff --git a/backends/platform/android/options.cpp b/backends/platform/android/options.cpp
index 75a03f77d4b..2258a84c0b4 100644
--- a/backends/platform/android/options.cpp
+++ b/backends/platform/android/options.cpp
@@ -36,10 +36,10 @@
 // for the Android port
 #define FORBIDDEN_SYMBOL_EXCEPTION_printf
 
-#include "backends/fs/android/android-fs-factory.h"
-#include "backends/fs/android/android-saf-fs.h"
 #include "backends/platform/android/android.h"
 #include "backends/platform/android/jni-android.h"
+#include "backends/fs/android/android-fs-factory.h"
+#include "backends/fs/android/android-saf-fs.h"
 
 #include "gui/gui-manager.h"
 #include "gui/ThemeEval.h"




More information about the Scummvm-git-logs mailing list