2 #include <msp/fs/path.h>
3 #include "application.h"
4 #include "errorlogger.h"
5 #include "mainthread.h"
12 MainThread::MainThread(ANativeActivity *a):
16 activity->callbacks->onNativeWindowCreated = &native_window_created;
17 activity->callbacks->onNativeWindowResized = &native_window_resized;
18 activity->callbacks->onNativeWindowDestroyed = &native_window_destroyed;
19 activity->callbacks->onInputQueueCreated = &input_queue_created;
20 activity->callbacks->onInputQueueDestroyed = &input_queue_destroyed;
21 activity->instance = this;
28 void MainThread::wait_for_app_created()
30 MutexLock lock(startup_mutex);
33 void MainThread::resume_startup()
38 startup_mutex.unlock();
42 void MainThread::main()
44 /* I have no idea how dependable this is, but it seems to be the only way
45 to get the package name aside from making a Java call through JNI */
46 char *appname = strdup(FS::Path(activity->internalDataPath)[-2].c_str());
47 char *argv[] = { appname, 0 };
48 Msp::Android::ErrorLogger err_logger;
49 Msp::Application::run(1, argv, this, &app_created);
51 ANativeActivity_finish(activity);
54 void MainThread::app_created(void *data)
56 reinterpret_cast<MainThread *>(data)->resume_startup();
59 void MainThread::native_window_created(ANativeActivity *activity, ANativeWindow *window)
61 reinterpret_cast<MainThread *>(activity->instance)->signal_native_window_created.emit(window);
64 void MainThread::native_window_resized(ANativeActivity *activity, ANativeWindow *window)
66 reinterpret_cast<MainThread *>(activity->instance)->signal_native_window_resized.emit(window);
69 void MainThread::native_window_destroyed(ANativeActivity *activity, ANativeWindow *window)
71 reinterpret_cast<MainThread *>(activity->instance)->signal_native_window_destroyed.emit(window);
74 void MainThread::input_queue_created(ANativeActivity *activity, AInputQueue *queue)
76 reinterpret_cast<MainThread *>(activity->instance)->signal_input_queue_created.emit(queue);
79 void MainThread::input_queue_destroyed(ANativeActivity *activity, AInputQueue *queue)
81 reinterpret_cast<MainThread *>(activity->instance)->signal_input_queue_destroyed.emit(queue);
84 } // namespace Android