fplutil
An open source project by FPL.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
main.h
Go to the documentation of this file.
1 // Copyright 2014 Google Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef FPLUTIL_MAIN_H
16 #define FPLUTIL_MAIN_H
17 
18 /// @file
19 /// Header for libfplutil_main.
20 ///
21 /// libfplutil_main makes it easy to build traditional C/C++
22 /// applications for Android that use an `int main()` entry point.
23 ///
24 /// Linking this library adds functionality to call a standard C main() from
25 /// Android's NativeActivity NDK entry point, android_main(). This helps
26 /// you by by making it very easy to resuse existing programs with a C main()
27 /// entry point.
28 ///
29 /// For example, this code:
30 ///
31 /// @code{.c}
32 /// #include "fplutil/main.h"
33 ///
34 /// int main(int argc, char **argv) {
35 /// ... do stuff ...
36 /// return 0;
37 /// }
38 /// @endcode
39 ///
40 /// will launch, "do stuff", and exit the NativeActivity on return from main().
41 /// The android_main() is implemented inside this library for you.
42 ///
43 /// If "do stuff" requires nontrivial amounts of time, such as entering a main
44 /// loop and looping forever, then it is advisable to add a call the
45 /// ProcessAndroidEvents() function below periodically, which will minimally
46 /// service events on the native activity looper.
47 ///
48 /// For more information see `ndk/sources/android/native_app_glue`.
49 
50 #if defined(ANDROID) || defined(__ANDROID__)
51 
52 #if defined(__cplusplus)
53 extern "C" {
54 #endif // defined(__cplusplus)
55 
56 /// This should be implemented by the application including this header.
57 extern int main(int argc, char** argv);
58 
59 /// Process android events on the main NativeActivity thread ALooper.
60 ///
61 /// This waits for and processes any pending events from the Android SDK being
62 /// passed into the NDK. The call will block up to maxWait milliseconds for
63 /// pending Android events.
64 ///
65 /// @param maxWait 0 returns immediately, -1 blocks indefinitely until an
66 /// event arrives.
67 void ProcessAndroidEvents(int maxWait);
68 
69 #if defined(__cplusplus)
70 }
71 #endif // defined(__cplusplus)
72 
73 #endif // defined(ANDROID) || defined(__ANDROID__)
74 #endif // FPLUTIL_MAIN_H
void ProcessAndroidEvents(int maxWait)
Definition: main.c:39
int main(int argc, char **argv)
This should be implemented by the application including this header.
Definition: test_index_allocator.cc:616