summaryrefslogtreecommitdiff
path: root/jni
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2013-02-19 17:29:18 -0800
committerJeff Sharkey <jsharkey@android.com>2013-02-19 18:08:35 -0800
commitef946f3ae80556ab221265c0bf1c560683ea27f6 (patch)
tree1075b9a5a6f58c8a1333aac666124f40ba40fa1f /jni
parent1a4f172df720edcc97ca86838910d3be557a5225 (diff)
downloadTerminal-ef946f3ae80556ab221265c0bf1c560683ea27f6.tar.gz
Initial code for Terminal app, with JNI glue.
Change-Id: I4b2ecb2eef9bef7a8236391d19a3708751a7c71d
Diffstat (limited to 'jni')
-rw-r--r--jni/Android.mk22
-rw-r--r--jni/com_android_terminal_Terminal.cpp162
-rw-r--r--jni/jni_init.cpp38
3 files changed, 222 insertions, 0 deletions
diff --git a/jni/Android.mk b/jni/Android.mk
new file mode 100644
index 0000000..0563efc
--- /dev/null
+++ b/jni/Android.mk
@@ -0,0 +1,22 @@
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+ jni_init.cpp \
+ com_android_terminal_Terminal.cpp
+
+LOCAL_C_INCLUDES += \
+ external/libvterm/include
+
+LOCAL_SHARED_LIBRARIES := \
+ libutils \
+ libnativehelper
+
+LOCAL_STATIC_LIBRARIES := \
+ libvterm
+
+LOCAL_MODULE := libjni_terminal
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/jni/com_android_terminal_Terminal.cpp b/jni/com_android_terminal_Terminal.cpp
new file mode 100644
index 0000000..ed84619
--- /dev/null
+++ b/jni/com_android_terminal_Terminal.cpp
@@ -0,0 +1,162 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * 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.
+ */
+
+#define LOG_TAG "Terminal"
+
+#include <utils/Log.h>
+#include "jni.h"
+#include "JNIHelp.h"
+
+#include <vterm.h>
+
+#include <string.h>
+
+namespace android {
+
+class Terminal;
+
+/*
+ * VTerm event handlers
+ */
+
+static int term_damage(VTermRect rect, void *user) {
+ Terminal* term = reinterpret_cast<Terminal*>(user);
+ ALOGW("term_damage");
+ return 1;
+}
+
+static int term_prescroll(VTermRect rect, void *user) {
+ Terminal* term = reinterpret_cast<Terminal*>(user);
+ ALOGW("term_prescroll");
+ return 1;
+}
+
+static int term_moverect(VTermRect dest, VTermRect src, void *user) {
+ Terminal* term = reinterpret_cast<Terminal*>(user);
+ ALOGW("term_moverect");
+ return 1;
+}
+
+static int term_movecursor(VTermPos pos, VTermPos oldpos, int visible, void *user) {
+ Terminal* term = reinterpret_cast<Terminal*>(user);
+ ALOGW("term_movecursor");
+ return 1;
+}
+
+static int term_settermprop(VTermProp prop, VTermValue *val, void *user) {
+ Terminal* term = reinterpret_cast<Terminal*>(user);
+ ALOGW("term_settermprop");
+ return 1;
+}
+
+static int term_setmousefunc(VTermMouseFunc func, void *data, void *user) {
+ Terminal* term = reinterpret_cast<Terminal*>(user);
+ ALOGW("term_setmousefunc");
+ return 1;
+}
+
+static int term_bell(void *user) {
+ Terminal* term = reinterpret_cast<Terminal*>(user);
+ ALOGW("term_bell");
+ return 1;
+}
+
+static int term_resize(int rows, int cols, void *user) {
+ Terminal* term = reinterpret_cast<Terminal*>(user);
+ ALOGW("term_resize");
+ return 1;
+}
+
+static VTermScreenCallbacks cb = {
+ .damage = term_damage,
+ .prescroll = term_prescroll,
+ .moverect = term_moverect,
+ .movecursor = term_movecursor,
+ .settermprop = term_settermprop,
+ .setmousefunc = term_setmousefunc,
+ .bell = term_bell,
+ .resize = term_resize,
+};
+
+/*
+ * Terminal session
+ */
+
+class Terminal {
+public:
+ Terminal(int rows, int cols);
+ ~Terminal();
+
+ int getRows();
+
+private:
+ VTerm *mVt;
+ VTermScreen *mVts;
+
+ int mRows;
+ int mCols;
+};
+
+Terminal::Terminal(int rows, int cols) : mRows(rows), mCols(cols) {
+// pt->writefn = NULL;
+// pt->resizedfn = NULL;
+
+ /* Create VTerm */
+ mVt = vterm_new(rows, cols);
+ vterm_parser_set_utf8(mVt, 1);
+
+ /* Set up screen */
+ mVts = vterm_obtain_screen(mVt);
+ vterm_screen_enable_altscreen(mVts, 1);
+ vterm_screen_set_callbacks(mVts, &cb, this);
+ vterm_screen_set_damage_merge(mVts, VTERM_DAMAGE_SCROLL);
+
+ // TODO: finish setup and forkpty() here
+}
+
+Terminal::~Terminal() {
+ vterm_free(mVt);
+}
+
+int Terminal::getRows() {
+ return mRows;
+}
+
+/*
+ * JNI glue
+ */
+
+static jint com_android_terminal_Terminal_nativeInit(JNIEnv* env, jclass clazz,
+ jint rows, jint cols) {
+ return reinterpret_cast<jint>(new Terminal(rows, cols));
+}
+
+static jint com_android_terminal_Terminal_nativeGetRows(JNIEnv* env, jclass clazz, jint ptr) {
+ Terminal* term = reinterpret_cast<Terminal*>(ptr);
+ return term->getRows();
+}
+
+static JNINativeMethod gMethods[] = {
+ { "nativeInit", "(II)I", (void*)com_android_terminal_Terminal_nativeInit },
+ { "nativeGetRows", "(I)I", (void*)com_android_terminal_Terminal_nativeGetRows },
+};
+
+int register_com_android_terminal_Terminal(JNIEnv* env) {
+ return jniRegisterNativeMethods(env, "com/android/terminal/Terminal",
+ gMethods, NELEM(gMethods));
+}
+
+} /* namespace android */
diff --git a/jni/jni_init.cpp b/jni/jni_init.cpp
new file mode 100644
index 0000000..c4a262e
--- /dev/null
+++ b/jni/jni_init.cpp
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * 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.
+ */
+
+#define LOG_TAG "Terminal"
+
+#include <utils/Log.h>
+#include "jni.h"
+
+namespace android {
+extern int register_com_android_terminal_Terminal(JNIEnv *env);
+}
+
+using namespace android;
+
+extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved) {
+ JNIEnv *env;
+ if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
+ ALOGE("ERROR: GetEnv failed");
+ return -1;
+ }
+
+ register_com_android_terminal_Terminal(env);
+
+ return JNI_VERSION_1_6;
+}