File: main.c

package info (click to toggle)
mlterm 3.9.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,340 kB
  • sloc: ansic: 154,713; sh: 5,302; cpp: 2,953; objc: 2,776; java: 2,472; makefile: 2,445; perl: 1,674; xml: 44
file content (119 lines) | stat: -rw-r--r-- 2,749 bytes parent folder | download
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
111
112
113
114
115
116
117
118
119
/* -*- c-basic-offset:2; tab-width:2; indent-tabs-mode:nil -*- */

#include <pobl/bl_conf_io.h>
#include <pobl/bl_debug.h>
#include <pobl/bl_dlfcn.h>
#include <vt_term_manager.h>
#if 0
#include <sys/prctl.h>
#endif
#include "uitoolkit/fb/ui_display.h"
#include "uitoolkit/ui_event_source.h"
#include "main_loop.h"

#ifdef SYSCONFDIR
#define CONFIG_PATH SYSCONFDIR
#else
#define CONFIG_PATH "/etc"
#endif

#if 0
#define SAVE_DEFAULT_FONT
#endif

#ifdef SAVE_DEFAULT_FONT

/* --- global variables --- */

char *default_font_path;

/* --- static functions --- */

static inline void save_default_font(ANativeActivity *activity) {
  JNIEnv *env;
  jobject this;
  jstring jstr;
  const char *path;

  if (default_font_path || (*activity->vm)->GetEnv(activity->vm, &env, JNI_VERSION_1_6) != JNI_OK) {
    return;
  }

  this = activity->clazz;
  jstr = (*env)->CallObjectMethod(
      env, this, (*env)->GetMethodID(env, (*env)->GetObjectClass(env, this), "saveDefaultFont",
                                     "()Ljava/lang/String;"));

  path = (*env)->GetStringUTFChars(env, jstr, NULL);
  default_font_path = strdup(path);
  (*env)->ReleaseStringUTFChars(env, jstr, path);
}

#endif /* SAVE_DEFAULT_FONT */

static void attach_current_thread(JavaVM *vm) {
  JNIEnv *env;
  (*vm)->AttachCurrentThread(vm, &env, NULL);
}

static void detach_current_thread(JavaVM *vm) {
  (*vm)->DetachCurrentThread(vm);
}

static void finish(struct android_app *app) {
    int ident;
    int events;
    struct android_poll_source *source;

    ui_display_final(); /* Calls ANativeActivity_finish() */

    while ((ident = ALooper_pollOnce(-1, NULL, &events, (void **)&source)) >= 0 &&
           ui_display_process_event(source, ident));
}

/* --- global functions --- */

int ui_screen_manager_suspend(void); /* ui_screen_manager.c */

void android_main(struct android_app *app) {
  int argc = 1;
  char *argv[] = {"mlterm"};

#if 0
  prctl(PR_SET_DUMPABLE, 1, 0, 0, 0);
#endif

#ifdef DEBUG
  bl_debug_printf(BL_DEBUG_TAG " android_main started.\n");
#endif

  bl_set_sys_conf_dir(CONFIG_PATH);

  attach_current_thread(app->activity->vm);

#ifdef SAVE_DEFAULT_FONT
  save_default_font(app->activity);
#endif

  if (ui_display_init(app) &&      /* ui_display_init() returns 1 only once. */
      !main_loop_init(argc, argv)) /* main_loop_init() is called once. */
  {
#ifdef DEBUG
    bl_warn_printf(BL_DEBUG_TAG " main_loop_init() failed.\n");
#endif

    finish(app);
  } else if (!main_loop_start()) {
    /* Unable to open any screen. */
    finish(app);
  }

  /* Only screen objects are closed. */
  ui_screen_manager_suspend();

  detach_current_thread(app->activity->vm);

#ifdef DEBUG
  bl_debug_printf(BL_DEBUG_TAG " android_main finished.\n");
#endif
}