From b593b4e08a138f3a8d56b05009711b2ada534fa3 Mon Sep 17 00:00:00 2001 From: Aaron Sarazan Date: Sat, 2 Jul 2016 18:10:56 -0700 Subject: [PATCH 1/3] goOffline/goOnline --- .../Plugins/Android/FirebaseAndroidImpl.cs | 10 ++++++++++ .../Plugins/Editor/FirebaseEditorImpl.cs | 15 +++++++++++++++ .../Assets/Plugins/Firebase/IFirebase.cs | 3 +++ empty-project/Assets/Plugins/iOS/Firebase.mm | 8 ++++++++ .../Assets/Plugins/iOS/FirebaseiOSImpl.cs | 16 ++++++++++++++++ source/XCodePlugin/JniFirebase.cpp | 18 ++++++++++++++++++ source/XCodePlugin/JniFirebase.h | 7 ++++++- source/XCodePlugin/JniHelper.h | 16 ++++++++++++++++ source/XCodePlugin/Plugin.cpp | 12 ++++++++++++ 9 files changed, 104 insertions(+), 1 deletion(-) diff --git a/empty-project/Assets/Plugins/Android/FirebaseAndroidImpl.cs b/empty-project/Assets/Plugins/Android/FirebaseAndroidImpl.cs index bacd20b..72576e6 100644 --- a/empty-project/Assets/Plugins/Android/FirebaseAndroidImpl.cs +++ b/empty-project/Assets/Plugins/Android/FirebaseAndroidImpl.cs @@ -172,6 +172,16 @@ public AuthData Auth { return new AuthData(token, uid, expiration); } } + + public void GoOffline () + { + GetJavaObject ().CallStatic ("goOffline"); + } + + public void GoOnline () + { + GetJavaObject ().CallStatic ("goOnline"); + } #endregion class CompletionListener : AndroidJavaProxy { diff --git a/empty-project/Assets/Plugins/Editor/FirebaseEditorImpl.cs b/empty-project/Assets/Plugins/Editor/FirebaseEditorImpl.cs index 1ca0bc4..48b45cf 100644 --- a/empty-project/Assets/Plugins/Editor/FirebaseEditorImpl.cs +++ b/empty-project/Assets/Plugins/Editor/FirebaseEditorImpl.cs @@ -105,6 +105,11 @@ private static extern void _FirebaseAuthWithOAuthToken (IntPtr firebase, string private static extern long _FirebaseGetAuthExpiration(IntPtr firebase); [DllImport ("FirebaseProxy")] private static extern void _FirebaseUnAuth(IntPtr firebase); + + [DllImport ("FirebaseProxy")] + private static extern void _FirebaseGoOffline(); + [DllImport ("FirebaseProxy")] + private static extern void _FirebaseGoOnline(); #endregion @@ -220,6 +225,16 @@ public AuthData Auth { _FirebaseGetAuthExpiration(GetEditorObject())); } } + + public void GoOffline () + { + _FirebaseGoOffline (); + } + + public void GoOnline () + { + _FirebaseGoOnline (); + } #endregion diff --git a/empty-project/Assets/Plugins/Firebase/IFirebase.cs b/empty-project/Assets/Plugins/Firebase/IFirebase.cs index b0a9354..3290627 100644 --- a/empty-project/Assets/Plugins/Firebase/IFirebase.cs +++ b/empty-project/Assets/Plugins/Firebase/IFirebase.cs @@ -41,4 +41,7 @@ public interface IFirebase : IQuery void UnAuth(); AuthData Auth { get; } + + void GoOffline (); + void GoOnline (); } diff --git a/empty-project/Assets/Plugins/iOS/Firebase.mm b/empty-project/Assets/Plugins/iOS/Firebase.mm index f97800f..bdaf850 100644 --- a/empty-project/Assets/Plugins/iOS/Firebase.mm +++ b/empty-project/Assets/Plugins/iOS/Firebase.mm @@ -269,6 +269,14 @@ void _FirebaseUnAuth( void* firebase) { [myFirebaseRef unauth]; } + void _FirebaseGoOffline() { + [Firebase goOffline]; + } + + void _FirebaseGoOnline() { + [Firebase goOnline]; + } + float _DataSnapshotGetFloatValue (void* datasnapshot) { FDataSnapshot *snapshotRef = (__bridge FDataSnapshot*) (datasnapshot); return [[snapshotRef value] floatValue]; diff --git a/empty-project/Assets/Plugins/iOS/FirebaseiOSImpl.cs b/empty-project/Assets/Plugins/iOS/FirebaseiOSImpl.cs index 85be4c4..e15f5f9 100644 --- a/empty-project/Assets/Plugins/iOS/FirebaseiOSImpl.cs +++ b/empty-project/Assets/Plugins/iOS/FirebaseiOSImpl.cs @@ -124,6 +124,12 @@ private static extern void _FirebaseAuthWithOAuthToken (IntPtr firebase, string [DllImport ("__Internal")] private static extern void _FirebaseUnAuth( IntPtr firebase); + [DllImport ("__Internal")] + private static extern void _FirebaseGoOffline(); + + [DllImport ("__Internal")] + private static extern void _FirebaseGoOnline(); + #endregion #region IFirebase implementation @@ -236,6 +242,16 @@ public AuthData Auth { } } + public void GoOffline () + { + _FirebaseGoOffline (); + } + + public void GoOnline () + { + _FirebaseGoOnline (); + } + #endregion [MonoPInvokeCallbackAttribute(typeof(OnAuthSuccessHandler))] diff --git a/source/XCodePlugin/JniFirebase.cpp b/source/XCodePlugin/JniFirebase.cpp index cdde91d..cb9df38 100644 --- a/source/XCodePlugin/JniFirebase.cpp +++ b/source/XCodePlugin/JniFirebase.cpp @@ -376,4 +376,22 @@ void JniFirebase::UnAuth() { env->CallVoidMethod(m_firebase, s_unAuth); } +jmethodID JniFirebase::s_goOffline = NULL; +void JniFirebase::GoOffline() { + auto env = getEnv(); + if (!GetStaticMethod(env, s_firebaseClass, "goOffline", "()V", + &s_goOffline)) { + return; + } + env->CallStaticVoidMethod(m_firebase, s_goOffline); +} +jmethodID JniFirebase::s_goOnline = NULL; +void JniFirebase::GoOnline() { + auto env = getEnv(); + if (!GetMethod(env, s_firebaseClass, "goOnline", "()V", + &s_goOnline)) { + return; + } + env->CallStaticVoidMethod(m_firebase, s_goOnline); +} diff --git a/source/XCodePlugin/JniFirebase.h b/source/XCodePlugin/JniFirebase.h index f7f8d6c..bd20812 100644 --- a/source/XCodePlugin/JniFirebase.h +++ b/source/XCodePlugin/JniFirebase.h @@ -55,6 +55,9 @@ class JniFirebase { uint64_t GetAuthExpiration(); void UnAuth(); + + static void GoOffline(); + static void GoOnline(); jobject getJniObject() { return m_firebase; @@ -123,7 +126,9 @@ class JniFirebase { static jmethodID s_firebaseGetAuth; - static jmethodID s_unAuth; + + static jmethodID s_goOffline; + static jmethodID s_goOnline; }; #endif /* defined(__XCodePlugin__JniFirebase__) */ diff --git a/source/XCodePlugin/JniHelper.h b/source/XCodePlugin/JniHelper.h index 5114997..bba15f1 100644 --- a/source/XCodePlugin/JniHelper.h +++ b/source/XCodePlugin/JniHelper.h @@ -156,6 +156,22 @@ bool GetMethod(JNIEnv* env, jclass clazz, const char* methodName, const char* me return (*pMethod) != NULL; } +inline +bool GetStaticMethod(JNIEnv* env, jclass clazz, const char* methodName, const char* methodSig, jmethodID* pMethod) { + if (!env) { + return false; + } + if (*pMethod) { + return true; + } + lock lock(g_lock); + if (*pMethod) { + return true; + } + *pMethod = env->GetStaticMethodID(clazz, methodName, methodSig); + return (*pMethod) != NULL; +} + const char* CallToString(JNIEnv* env, jobject localRef) ; const char* GetJNIExceptionDescription(JNIEnv* env, jthrowable exception ); diff --git a/source/XCodePlugin/Plugin.cpp b/source/XCodePlugin/Plugin.cpp index 8ce0781..19ca773 100644 --- a/source/XCodePlugin/Plugin.cpp +++ b/source/XCodePlugin/Plugin.cpp @@ -246,6 +246,18 @@ void _FirebaseUnAuth(void* firebase) { jniFirebase->UnAuth(); } +void _FirebaseGoOffline(void* firebase) { + if (!firebase) return; + JniFirebase* jniFirebase = (JniFirebase*) firebase; + jniFirebase->GoOffline(); +} + +void _FirebaseGoOnline(void* firebase) { + if (!firebase) return; + JniFirebase* jniFirebase = (JniFirebase*) firebase; + jniFirebase->GoOnline(); +} + float _DataSnapshotGetFloatValue (void* datasnapshot) { if (!datasnapshot) return 0; JniDataSnapshot* jniDataSnapshot = (JniDataSnapshot*)datasnapshot; From 11d47bb7f122702da4041d3a3e06f53168ebd44a Mon Sep 17 00:00:00 2001 From: Aaron Sarazan Date: Sun, 3 Jul 2016 10:23:15 -0700 Subject: [PATCH 2/3] Update gitignore to exclude xcuserdata and fix ds_store --- .gitignore | 5 +++-- source/XCodePlugin/.DS_Store | Bin 6148 -> 0 bytes 2 files changed, 3 insertions(+), 2 deletions(-) delete mode 100644 source/XCodePlugin/.DS_Store diff --git a/.gitignore b/.gitignore index 090a1f0..4318e6b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -.idea -.DS_Store +**/.idea +**/.DS_Store +**/xcuserdata diff --git a/source/XCodePlugin/.DS_Store b/source/XCodePlugin/.DS_Store deleted file mode 100644 index e2d6cbcf62fcd86038b31bf9bb74de10475c4fbc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%Sr<=6g|-{N<}D&(B=38h5o@%r)qaXH?Bncu&qp;p|(&L!hC{X<KYnc`ui(@Q4q3^k`GT+;^ZNfJf< z`K$-L)ZU)S-H_e?0XrS#SNJPi3aA3Az^4NCdHPqq9G-!-=8C%%P*hI691vZ2SwwNObZ7 z84eRVRIduC0!0P3-DlO_|E=%e|3#91sRF9Nzf!=IqE6IgO8#zLNzUH20m~(eH9IbI lC=@z>9ZSVt#WfZ&_64>=3_WHJ*+SDF0g*wSD)6fcd;s2&o(%v1 From 99da17e43f6153c6fc841468e3f8f24dc44309f3 Mon Sep 17 00:00:00 2001 From: Aaron Sarazan Date: Sun, 3 Jul 2016 10:44:29 -0700 Subject: [PATCH 3/3] Fix invalid reference to m_firebase --- source/.DS_Store | Bin 8196 -> 0 bytes source/XCodePlugin/JniFirebase.cpp | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) delete mode 100644 source/.DS_Store diff --git a/source/.DS_Store b/source/.DS_Store deleted file mode 100644 index 414b79f33b03a027aa645ca7078961adda9c095c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8196 zcmeHLU2IfE6h3EL;Ql~6Ed{oKu%xCbq2NNpPf=j|2l6M4+jd)8S?=z=v{!HMt$Xk8 zf}}|`CMq#X&?k*AfM5*j6Y;?ZH3s#;#Gf=#B>@J!c0pb9lQ09{9RNN-AClJ&*8>83_}liV1fnx;L!DcoDAJu*`LZeUXCpO z&P_SCA0(4kF;-JMZ~g*B)pY)24cZgw39pY#Eo54huE$J^20IbH{1iGj|%hG~rKp1&ZKDs$1FlaW7l}53fAb@?2%Tj$i7R)-kU_iXY~X zVqtG%pO$5fe1i^61-9qESLB>f|mo3*V<1GcNfd2e!(R_;sncKs2BeW@Jbb00AL;Lw!i()4vZ zccr@Gx?b(kM!0>KX-~_x3ufVHt8s3ES z@Bv(gkKqgW3ciMK;9K|+uE9_6GyDdBz@P9J#!$zFScmo4gb&~%7u+xwSEzd<_};c^CallStaticVoidMethod(m_firebase, s_goOffline); + env->CallStaticVoidMethod(NULL, s_goOffline); } jmethodID JniFirebase::s_goOnline = NULL; @@ -393,5 +393,5 @@ void JniFirebase::GoOnline() { &s_goOnline)) { return; } - env->CallStaticVoidMethod(m_firebase, s_goOnline); + env->CallStaticVoidMethod(NULL, s_goOnline); }