Skip to content

Commit

Permalink
remove Android/AndroidKernelService commands
Browse files Browse the repository at this point in the history
  • Loading branch information
irov committed Oct 16, 2024
1 parent 9def54e commit c9ca3f4
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 115 deletions.
58 changes: 0 additions & 58 deletions src/Environment/Android/AndroidKernelService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,6 @@ namespace Mengine
ANALYTICS_SERVICE()
->addEventProvider( m_androidAnalyticsEventProvider );

ThreadMutexInterfacePtr mutexCommands = Helper::createThreadMutex( MENGINE_DOCUMENT_FACTORABLE );

m_mutexCommands = mutexCommands;

ThreadMutexInterfacePtr mutexJStrings = Helper::createThreadMutex( MENGINE_DOCUMENT_FACTORABLE );

m_mutexJStrings = mutexJStrings;
Expand All @@ -293,8 +289,6 @@ namespace Mengine
NOTIFICATION_ADDOBSERVERMETHOD_THIS( NOTIFICATOR_PLATFORM_STOP, &AndroidKernelService::notifyPlatformStop_, MENGINE_DOCUMENT_FACTORABLE );
NOTIFICATION_ADDOBSERVERMETHOD_THIS( NOTIFICATOR_BOOTSTRAPPER_INITIALIZE_BASE_SERVICES, &AndroidKernelService::notifyBootstrapperInitializeBaseServices_, MENGINE_DOCUMENT_FACTORABLE );
NOTIFICATION_ADDOBSERVERMETHOD_THIS( NOTIFICATOR_BOOTSTRAPPER_CREATE_APPLICATION, &AndroidKernelService::notifyBootstrapperCreateApplication_, MENGINE_DOCUMENT_FACTORABLE );
NOTIFICATION_ADDOBSERVERMETHOD_THIS( NOTIFICATOR_APPLICATION_BEGIN_UPDATE, &AndroidKernelService::notifyApplicationBeginUpdate_, MENGINE_DOCUMENT_FACTORABLE );
NOTIFICATION_ADDOBSERVERMETHOD_THIS( NOTIFICATOR_APPLICATION_END_UPDATE, &AndroidKernelService::notifyApplicationEndUpdate_, MENGINE_DOCUMENT_FACTORABLE );

return true;
}
Expand All @@ -305,8 +299,6 @@ namespace Mengine
NOTIFICATION_REMOVEOBSERVER_THIS( NOTIFICATOR_PLATFORM_STOP );
NOTIFICATION_REMOVEOBSERVER_THIS( NOTIFICATOR_BOOTSTRAPPER_INITIALIZE_BASE_SERVICES );
NOTIFICATION_REMOVEOBSERVER_THIS( NOTIFICATOR_BOOTSTRAPPER_CREATE_APPLICATION );
NOTIFICATION_REMOVEOBSERVER_THIS( NOTIFICATOR_APPLICATION_BEGIN_UPDATE );
NOTIFICATION_REMOVEOBSERVER_THIS( NOTIFICATOR_APPLICATION_END_UPDATE );

m_mutexJStrings = nullptr;

Expand Down Expand Up @@ -400,28 +392,6 @@ namespace Mengine
m_holdersJString.push_back( holder );
}
//////////////////////////////////////////////////////////////////////////
void AndroidKernelService::addCommand( const LambdaCommand & _command )
{
m_mutexCommands->lock();
m_commandsAux.emplace_back( _command );
m_mutexCommands->unlock();
}
//////////////////////////////////////////////////////////////////////////
void AndroidKernelService::invokeCommands()
{
m_mutexCommands->lock();
std::swap( m_commands, m_commandsAux );
m_commandsAux.clear();
m_mutexCommands->unlock();

for( const LambdaCommand & command : m_commands )
{
command();
}

m_commands.clear();
}
//////////////////////////////////////////////////////////////////////////
bool AndroidKernelService::openUrlInDefaultBrowser( const Char * _url )
{
if( Mengine_JNI_ExistMengineActivity() == JNI_FALSE )
Expand Down Expand Up @@ -478,8 +448,6 @@ namespace Mengine
MENGINE_ASSERTION_MEMORY_PANIC( jenv, "invalid get jenv" );

Helper::AndroidCallVoidActivityMethod( jenv, "onMenginePlatformRun", "()V" );

this->invokeCommands();
}
//////////////////////////////////////////////////////////////////////////
void AndroidKernelService::notifyPlatformStop_()
Expand All @@ -494,28 +462,6 @@ namespace Mengine
MENGINE_ASSERTION_MEMORY_PANIC( jenv, "invalid get jenv" );

Helper::AndroidCallVoidActivityMethod( jenv, "onMenginePlatformStop", "()V" );

this->invokeCommands();
}
//////////////////////////////////////////////////////////////////////////
void AndroidKernelService::notifyApplicationBeginUpdate_()
{
if( Mengine_JNI_ExistMengineActivity() == JNI_FALSE )
{
return;
}

this->invokeCommands();
}
//////////////////////////////////////////////////////////////////////////
void AndroidKernelService::notifyApplicationEndUpdate_()
{
if( Mengine_JNI_ExistMengineActivity() == JNI_FALSE )
{
return;
}

this->invokeCommands();
}
//////////////////////////////////////////////////////////////////////////
void AndroidKernelService::notifyBootstrapperInitializeBaseServices_()
Expand All @@ -530,8 +476,6 @@ namespace Mengine
MENGINE_ASSERTION_MEMORY_PANIC( jenv, "invalid get jenv" );

Helper::AndroidCallVoidActivityMethod( jenv, "onMengineInitializeBaseServices", "()V" );

this->invokeCommands();
}
//////////////////////////////////////////////////////////////////////////
void AndroidKernelService::notifyBootstrapperCreateApplication_()
Expand All @@ -546,8 +490,6 @@ namespace Mengine
MENGINE_ASSERTION_MEMORY_PANIC( jenv, "invalid get jenv" );

Helper::AndroidCallVoidActivityMethod( jenv, "onMengineCreateApplication", "()V" );

this->invokeCommands();
}
//////////////////////////////////////////////////////////////////////////
}
12 changes: 0 additions & 12 deletions src/Environment/Android/AndroidKernelService.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,19 @@ namespace Mengine
public:
void stringize( JNIEnv * _jenv, jstring _value, ConstString * const _cstr ) override;

protected:
void addCommand( const LambdaCommand & _lambda ) override;
void invokeCommands() override;

protected:
bool openUrlInDefaultBrowser( const Char * _url ) override;
bool openMail( const Char * _email, const Char * _subject, const Char * _body ) override;

protected:
void notifyPlatformRun_();
void notifyPlatformStop_();
void notifyApplicationBeginUpdate_();
void notifyApplicationEndUpdate_();
void notifyBootstrapperInitializeBaseServices_();
void notifyBootstrapperCreateApplication_();

protected:
AndroidAnalyticsEventProviderPtr m_androidAnalyticsEventProvider;

ThreadMutexInterfacePtr m_mutexCommands;

typedef Vector<LambdaCommand> VectorCommand;
VectorCommand m_commands;
VectorCommand m_commandsAux;

ThreadMutexInterfacePtr m_mutexJStrings;

typedef Pool<ConstStringHolderJString, 256> PoolConstStringHolderJString;
Expand Down
5 changes: 0 additions & 5 deletions src/Interface/AndroidKernelServiceInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ namespace Mengine
public:
virtual void stringize( JNIEnv * _jenv, jstring _value, ConstString * const _cstr ) = 0;

public:
typedef Lambda<void()> LambdaCommand;
virtual void addCommand( const LambdaCommand & _lambda ) = 0;
virtual void invokeCommands() = 0;

public:
virtual bool openUrlInDefaultBrowser( const Char * _url ) = 0;
virtual bool openMail( const Char * _email, const Char * _subject, const Char * _body ) = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "Kernel/AssertionFactory.h"
#include "Kernel/FactoryPool.h"
#include "Kernel/ThreadMutexScope.h"
#include "Kernel/ThreadHelper.h"

#include "Environment/Android/AndroidIncluder.h"
#include "Environment/Android/AndroidEnv.h"
Expand Down Expand Up @@ -58,8 +59,7 @@ extern "C"

jobjectArray new_args = (jobjectArray)env->NewGlobalRef( _args );

ANDROID_KERNEL_SERVICE()
->addCommand([plugin, method, new_args]()
Mengine::Helper::dispatchMainThreadEvent( [plugin, method, new_args]()
{
s_androidNativePythonService->callPythonMethod( plugin, method, new_args );
} );
Expand All @@ -80,8 +80,7 @@ extern "C"

jobject new_plugin = env->NewGlobalRef( _plugin );

ANDROID_KERNEL_SERVICE()
->addCommand([name, new_plugin]()
Mengine::Helper::dispatchMainThreadEvent([name, new_plugin]()
{
s_androidNativePythonService->addPlugin( name, new_plugin );
} );
Expand Down Expand Up @@ -142,9 +141,6 @@ namespace Mengine
MENGINE_ASSERTION_MEMORY_PANIC( jenv, "invalid get jenv" );

Helper::AndroidCallVoidActivityMethod( jenv, "onPythonEmbeddedInitialize", "()V" );

ANDROID_KERNEL_SERVICE()
->invokeCommands();
}

return true;
Expand All @@ -164,9 +160,6 @@ namespace Mengine
if( Mengine_JNI_ExistMengineActivity() == JNI_TRUE )
{
Helper::AndroidCallVoidActivityMethod( jenv, "onPythonEmbeddedFinalize", "()V" );

ANDROID_KERNEL_SERVICE()
->invokeCommands();
}

s_androidNativePythonService = nullptr;
Expand Down Expand Up @@ -377,9 +370,6 @@ namespace Mengine

jenv->DeleteLocalRef( j );
}

ANDROID_KERNEL_SERVICE()
->invokeCommands();
}
//////////////////////////////////////////////////////////////////////////
bool AndroidNativePythonService::androidBooleanMethod( const ConstString & _plugin, const ConstString & _method, const pybind::args & _args ) const
Expand Down Expand Up @@ -416,9 +406,6 @@ namespace Mengine
jenv->DeleteLocalRef( j );
}

ANDROID_KERNEL_SERVICE()
->invokeCommands();

return (bool)jresult;
}
//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -456,9 +443,6 @@ namespace Mengine
jenv->DeleteLocalRef( j );
}

ANDROID_KERNEL_SERVICE()
->invokeCommands();

return (int32_t)jresult;
}
//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -496,9 +480,6 @@ namespace Mengine
jenv->DeleteLocalRef( j );
}

ANDROID_KERNEL_SERVICE()
->invokeCommands();

return (int64_t)jresult;
}
//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -536,9 +517,6 @@ namespace Mengine
jenv->DeleteLocalRef( j );
}

ANDROID_KERNEL_SERVICE()
->invokeCommands();

return (float)jresult;
}
//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -576,9 +554,6 @@ namespace Mengine
jenv->DeleteLocalRef( j );
}

ANDROID_KERNEL_SERVICE()
->invokeCommands();

return (double)jresult;
}
//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -625,9 +600,6 @@ namespace Mengine

jenv->DeleteLocalRef( jresult );

ANDROID_KERNEL_SERVICE()
->invokeCommands();

return py_value;
}
//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -667,9 +639,6 @@ namespace Mengine

PyObject * py_result = Helper::androidNativePythonMakePyObject( m_kernel, jenv, jresult, MENGINE_DOCUMENT_FACTORABLE );

ANDROID_KERNEL_SERVICE()
->invokeCommands();

return py_result;
}
//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -903,9 +872,6 @@ namespace Mengine
Helper::AndroidCallVoidActivityMethod( jenv, "onMengineCurrentSceneChange", "(Ljava/lang/String;)V", sceneName_jvalue );

jenv->DeleteLocalRef( sceneName_jvalue );

ANDROID_KERNEL_SERVICE()
->invokeCommands();
}
//////////////////////////////////////////////////////////////////////////
void AndroidNativePythonService::notifyRemoveSceneComplete_()
Expand All @@ -924,9 +890,6 @@ namespace Mengine
Helper::AndroidCallVoidActivityMethod( jenv, "onMengineCurrentSceneChange", "(Ljava/lang/String;)V", sceneName_jvalue );

jenv->DeleteLocalRef( sceneName_jvalue );

ANDROID_KERNEL_SERVICE()
->invokeCommands();
}
//////////////////////////////////////////////////////////////////////////
}

0 comments on commit c9ca3f4

Please sign in to comment.