-
Notifications
You must be signed in to change notification settings - Fork 122
/
Copy pathfunctions_android.h
110 lines (84 loc) · 3.44 KB
/
functions_android.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2017 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef FIREBASE_FUNCTIONS_SRC_ANDROID_FUNCTIONS_ANDROID_H_
#define FIREBASE_FUNCTIONS_SRC_ANDROID_FUNCTIONS_ANDROID_H_
#include <jni.h>
#include <map>
#include <set>
#include <string>
#include "app/src/cleanup_notifier.h"
#include "app/src/future_manager.h"
#include "app/src/include/firebase/app.h"
#include "app/src/include/firebase/internal/common.h"
#include "app/src/include/firebase/internal/mutex.h"
#include "app/src/util_android.h"
#include "functions/src/android/functions_android.h"
#include "functions/src/include/firebase/functions/callable_reference.h"
#include "functions/src/include/firebase/functions/common.h"
namespace firebase {
namespace functions {
namespace internal {
class FunctionsInternal {
public:
// Build a Functions.
FunctionsInternal(App* app, const char* region);
~FunctionsInternal();
// Return the App we were created with.
App* app() const;
// Return the region we were created with.
const char* region() const;
HttpsCallableReferenceInternal* GetHttpsCallable(const char* name) const;
// Get a FunctionsReference for the specified URL.
HttpsCallableReferenceInternal* GetHttpsCallableFromURL(
const char* url) const;
void UseFunctionsEmulator(const char* origin);
// Convert an error code obtained from a Java FunctionsException into a C++
// Error enum.
Error ErrorFromJavaErrorCode(jint java_error_code) const;
// Convert a Java FunctionsExcetion instance into a C++ Error enum.
// If error_message is not null, it will be set to the error message string
// from the exception.
Error ErrorFromJavaFunctionsException(jobject java_error,
std::string* error_message) const;
FutureManager& future_manager() { return future_manager_; }
// Whether this object was successfully initialized by the constructor.
bool initialized() const { return app_ != nullptr; }
// When this is deleted, it will clean up all FunctionsReferences and other
// objects.
CleanupNotifier& cleanup() { return cleanup_; }
// Used for registering global callbacks. See
// firebase::util::RegisterCallbackOnTask for context.
const char* jni_task_id() { return jni_task_id_.c_str(); }
private:
// Initialize JNI for all classes.
static bool Initialize(App* app);
static void Terminate(App* app);
// Initialize classes loaded from embedded files.
static bool InitializeEmbeddedClasses(App* app);
static Mutex init_mutex_;
static int initialize_count_;
static std::map<jint, Error> java_error_to_cpp_;
App* app_;
std::string region_;
// Java FirebaseFunctions global ref.
jobject obj_;
FutureManager future_manager_;
CleanupNotifier cleanup_;
// String to be used when registering for JNI task callbacks.
std::string jni_task_id_;
};
} // namespace internal
} // namespace functions
} // namespace firebase
#endif // FIREBASE_FUNCTIONS_SRC_ANDROID_FUNCTIONS_ANDROID_H_