2 * Copyright (C) 2012 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 #include "network_manager.h"
17 #include "../android_jni.h"
20 typedef struct private_network_manager_t private_network_manager_t
;
22 struct private_network_manager_t
{
27 network_manager_t
public;
30 * Reference to NetworkManager object
35 * Java class for NetworkManager
40 METHOD(network_manager_t
, get_local_address
, host_t
*,
41 private_network_manager_t
*this, bool ipv4
)
49 androidjni_attach_thread(&env
);
50 method_id
= (*env
)->GetMethodID(env
, this->cls
, "getLocalAddress",
51 "(Z)Ljava/lang/String;");
56 jaddr
= (*env
)->CallObjectMethod(env
, this->obj
, method_id
, ipv4
);
61 addr
= androidjni_convert_jstring(env
, jaddr
);
62 androidjni_detach_thread();
63 host
= host_create_from_string(addr
, 0);
68 androidjni_exception_occurred(env
);
69 androidjni_detach_thread();
73 METHOD(network_manager_t
, destroy
, void,
74 private_network_manager_t
*this)
78 androidjni_attach_thread(&env
);
81 (*env
)->DeleteGlobalRef(env
, this->obj
);
85 (*env
)->DeleteGlobalRef(env
, this->cls
);
87 androidjni_detach_thread();
92 * Described in header.
94 network_manager_t
*network_manager_create()
96 private_network_manager_t
*this;
104 .get_local_address
= _get_local_address
,
109 androidjni_attach_thread(&env
);
110 cls
= (*env
)->FindClass(env
, JNI_PACKAGE_STRING
"/NetworkManager");
115 this->cls
= (*env
)->NewGlobalRef(env
, cls
);
116 method_id
= (*env
)->GetMethodID(env
, cls
, "<init>",
122 obj
= (*env
)->NewObject(env
, cls
, method_id
);
127 this->obj
= (*env
)->NewGlobalRef(env
, obj
);
128 androidjni_detach_thread();
129 return &this->public;
132 DBG1(DBG_KNL
, "failed to build NetworkManager object");
133 androidjni_exception_occurred(env
);
134 androidjni_detach_thread();