1 /* Communication module for Android terminals. -*- c-file-style: "GNU" -*-
2
3 Copyright (C) 2023 Free Software Foundation, Inc.
4
5 This file is part of GNU Emacs.
6
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or (at
10 your option) any later version.
11
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
19
20 package org.gnu.emacs;
21
22 import java.lang.Thread;
23 import java.util.Arrays;
24
25 import android.util.Log;
26
27 public final class EmacsThread extends Thread
28 {
29 private static final String TAG = "EmacsThread";
30
31 /* Whether or not Emacs should be started with an additional
32 argument, and that additional argument if non-NULL. */
33 private String extraStartupArgument;
34
35 /* Runnable run to initialize Emacs. */
36 private Runnable paramsClosure;
37
38 /* Whether or not to open a file after starting Emacs. */
39 private String fileToOpen;
40
41 public
42 EmacsThread (EmacsService service, Runnable paramsClosure,
43 String extraStartupArgument, String fileToOpen)
44 {
45 super ("Emacs main thread");
46 this.extraStartupArgument = extraStartupArgument;
47 this.paramsClosure = paramsClosure;
48 this.fileToOpen = fileToOpen;
49 }
50
51 @Override
52 public void
53 run ()
54 {
55 String args[];
56
57 if (fileToOpen == null)
58 {
59 if (extraStartupArgument == null)
60 args = new String[] { "libandroid-emacs.so", };
61 else
62 args = new String[] { "libandroid-emacs.so",
63 extraStartupArgument, };
64 }
65 else
66 {
67 if (extraStartupArgument == null)
68 args = new String[] { "libandroid-emacs.so",
69 fileToOpen, };
70 else
71 args = new String[] { "libandroid-emacs.so",
72 extraStartupArgument,
73 fileToOpen, };
74 }
75
76 paramsClosure.run ();
77
78 /* Run the native code now. */
79 Log.d (TAG, "run: " + Arrays.toString (args));
80 EmacsNative.initEmacs (args, EmacsApplication.dumpFileName);
81 }
82 };