Global charonservice_t object added to libandroidbridge
authorTobias Brunner <tobias@strongswan.org>
Sat, 14 Jul 2012 14:14:34 +0000 (16:14 +0200)
committerTobias Brunner <tobias@strongswan.org>
Wed, 8 Aug 2012 13:41:04 +0000 (15:41 +0200)
This is later used to call Java methods on CharonVpnService via JNI.

src/frontends/android/jni/libandroidbridge/Android.mk
src/frontends/android/jni/libandroidbridge/charonservice.c
src/frontends/android/jni/libandroidbridge/charonservice.h [new file with mode: 0644]

index d84004a..fe6cd6c 100644 (file)
@@ -4,7 +4,7 @@ include $(CLEAR_VARS)
 # copy-n-paste from Makefile.am
 LOCAL_SRC_FILES := \
 android_jni.c android_jni.h \
-charonservice.c
+charonservice.c charonservice.h
 
 # build libandroidbridge -------------------------------------------------------
 
index 758f154..c865549 100644 (file)
@@ -18,6 +18,7 @@
 #include <string.h>
 #include <android/log.h>
 
+#include "charonservice.h"
 #include "android_jni.h"
 
 #include <daemon.h>
 #include <ipsec.h>
 #include <library.h>
 
+typedef struct private_charonservice_t private_charonservice_t;
+
+/**
+ * private data of charonservice
+ */
+struct private_charonservice_t {
+
+       /**
+        * public interface
+        */
+       charonservice_t public;
+};
+
+/**
+ * Single instance of charonservice_t.
+ */
+charonservice_t *charonservice;
 
 /**
  * hook in library for debugging messages
@@ -61,6 +79,31 @@ static void dbg_android(debug_t group, level_t level, char *fmt, ...)
 }
 
 /**
+ * Initialize the charonservice object
+ */
+static void charonservice_init()
+{
+       private_charonservice_t *this;
+
+       INIT(this,
+               .public = {
+               },
+       );
+       charonservice = &this->public;
+}
+
+/**
+ * Deinitialize the charonservice object
+ */
+static void charonservice_deinit()
+{
+       private_charonservice_t *this = (private_charonservice_t*)charonservice;
+
+       free(this);
+       charonservice = NULL;
+}
+
+/**
  * Initialize charon and the libraries via JNI
  */
 JNI_METHOD(CharonVpnService, initializeCharon, void)
@@ -90,10 +133,13 @@ JNI_METHOD(CharonVpnService, initializeCharon, void)
                return;
        }
 
+       charonservice_init();
+
        if (!libcharon_init("charon") ||
                !charon->initialize(charon, PLUGINS))
        {
                libcharon_deinit();
+               charonservice_deinit();
                libipsec_deinit();
                libhydra_deinit();
                library_deinit();
@@ -105,11 +151,12 @@ JNI_METHOD(CharonVpnService, initializeCharon, void)
 }
 
 /**
- * Initialize charon and the libraries via JNI
+ * Deinitialize charon and all libraries
  */
 JNI_METHOD(CharonVpnService, deinitializeCharon, void)
 {
        libcharon_deinit();
+       charonservice_deinit();
        libipsec_deinit();
        libhydra_deinit();
        library_deinit();
diff --git a/src/frontends/android/jni/libandroidbridge/charonservice.h b/src/frontends/android/jni/libandroidbridge/charonservice.h
new file mode 100644 (file)
index 0000000..0788ced
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2012 Tobias Brunner
+ * Copyright (C) 2012 Giuliano Grassi
+ * Copyright (C) 2012 Ralf Sager
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+/**
+ * @defgroup libandroidbridge libandroidbridge
+ *
+ * @defgroup charonservice charonservice
+ * @{ @ingroup libandroidbridge
+ */
+
+#ifndef CHARONSERVICE_H_
+#define CHARONSERVICE_H_
+
+typedef struct charonservice_t charonservice_t;
+
+/**
+ * Public interface of charonservice.
+ *
+ * Used to communicate with CharonVpnService via JNI
+ */
+struct charonservice_t {
+
+};
+
+/**
+ * The single instance of charonservice_t.
+ *
+ * Set between JNI calls to initializeCharon() and deinitializeCharon().
+ */
+extern charonservice_t *charonservice;
+
+#endif /** CHARONSERVICE_H_ @}*/