WithSession helper function
Handles the repeated boiler plate of using a weak reference to NetplaySession from NetplayUICallbacks
This commit is contained in:
1 parent
06cc09cf09
commit
4d1e749977
2 files changed
+129
-204
No files matched your search
@@ -13,6 +13,7 @@
|
||||
#include "Common/HookableEvent.h"
|
||||
#include "Core/NetPlayClient.h"
|
||||
#include "UICommon/GameFile.h"
|
||||
#include "jni/AndroidCommon/IDCache.h"
|
||||
|
||||
namespace NetPlay {
|
||||
|
||||
@@ -67,6 +68,17 @@ public:
|
||||
private:
|
||||
jobject GetNetplaySessionLocalRef(JNIEnv* env) const;
|
||||
|
||||
template <typename F>
|
||||
void WithSession(F&& callback) const
|
||||
{
|
||||
JNIEnv* env = IDCache::GetEnvForThread();
|
||||
jobject netplay_session = GetNetplaySessionLocalRef(env);
|
||||
if (!netplay_session)
|
||||
return;
|
||||
callback(env, netplay_session);
|
||||
env->DeleteLocalRef(netplay_session);
|
||||
}
|
||||
|
||||
jweak m_netplay_session;
|
||||
std::vector<std::shared_ptr<const UICommon::GameFile>> m_games;
|
||||
NetPlay::SyncIdentifier m_current_game_identifier;
|
||||
|
||||
Reference in new issue
Block a user