-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathmain.h
96 lines (80 loc) · 2.92 KB
/
main.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
// Copyright 2016 Google Inc. All rights reserved.
//
// 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_TESTAPP_MAIN_H_ // NOLINT
#define FIREBASE_TESTAPP_MAIN_H_ // NOLINT
#include <stdarg.h>
#include <string>
#if !defined(_WIN32)
#include <sys/time.h>
#endif
#if defined(__ANDROID__)
#include <android/native_activity.h>
#include <jni.h>
#elif defined(__APPLE__)
extern "C" {
#include <objc/objc.h>
} // extern "C"
#endif // __ANDROID__
// Defined using -DTESTAPP_NAME=some_app_name when compiling this
// file.
#ifndef TESTAPP_NAME
#define TESTAPP_NAME "android_main"
#endif // TESTAPP_NAME
namespace app_framework {
// Cross platform logging method.
// Implemented by android/android_main.cc or ios/ios_main.mm.
void LogMessage(const char* format, ...);
void LogMessageV(const char* format, va_list list);
// Platform-independent method to flush pending events for the main thread.
// Returns true when an event requesting program-exit is received.
bool ProcessEvents(int msec);
// Returns a path to a file suitable for the given platform.
std::string PathForResource();
#if defined(_WIN32)
// Windows requires its own version of time-handling code.
int64_t WinGetCurrentTimeInMicroseconds();
#endif
// Returns the number of microseconds since the epoch.
static int64_t GetCurrentTimeInMicroseconds() {
#if !defined(_WIN32)
struct timeval now;
gettimeofday(&now, nullptr);
return now.tv_sec * 1000000LL + now.tv_usec;
#else
return WinGetCurrentTimeInMicroseconds();
#endif
}
// WindowContext represents the handle to the parent window. It's type
// (and usage) vary based on the OS.
#if defined(__ANDROID__)
typedef jobject WindowContext; // A jobject to the Java Activity.
#elif defined(__APPLE__)
typedef id WindowContext; // A pointer to an iOS UIView.
#else
typedef void* WindowContext; // A void* for any other environments.
#endif
#if defined(__ANDROID__)
// Get the JNI environment.
JNIEnv* GetJniEnv();
// Get the activity.
jobject GetActivity();
#endif // defined(__ANDROID__)
// Returns a variable that describes the window context for the app. On Android
// this will be a jobject pointing to the Activity. On iOS, it's an id pointing
// to the root view of the view controller.
WindowContext GetWindowContext();
// Run the given function on a detached background thread.
void RunOnBackgroundThread(void* (*func)(void* data), void* data);
} // namespace app_framework
#endif // FIREBASE_TESTAPP_MAIN_H_ // NOLINT