Merge branch 'debian-testing'
[strongswan.git] / src / frontends / android / jni / libandroidbridge / kernel / network_manager.h
1 /*
2 * Copyright (C) 2012-2013 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
4 *
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 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup network_manager network_manager
18 * @{ @ingroup kernel_android
19 */
20
21 #ifndef NETWORK_MANAGER_H_
22 #define NETWORK_MANAGER_H_
23
24 #include <jni.h>
25
26 #include <library.h>
27 #include <networking/host.h>
28
29 typedef struct network_manager_t network_manager_t;
30
31 /**
32 * Callback called if connectivity changes somehow.
33 *
34 * Implementation should be quick as the call is made by the Java apps main
35 * thread.
36 *
37 * @param data data supplied during registration
38 * @param disconnected TRUE if currently disconnected
39 */
40 typedef void (*connectivity_cb_t)(void *data, bool disconnected);
41
42 /**
43 * NetworkManager, used to listen for network changes and retrieve local IP
44 * addresses.
45 *
46 * Communicates with NetworkManager via JNI
47 */
48 struct network_manager_t {
49
50 /**
51 * Get a local address
52 *
53 * @param ipv4 TRUE to get an IPv4 address
54 * @return the address or NULL if none available
55 */
56 host_t *(*get_local_address)(network_manager_t *this, bool ipv4);
57
58 /**
59 * Get the name of the interface on which the given IP address is installed
60 *
61 * @param ip the IP address to look for
62 * @param name returns the name of the interface (optional)
63 * @return TRUE if found
64 */
65 bool (*get_interface)(network_manager_t *this, host_t *ip, char **name);
66
67 /**
68 * Register a callback that is called if connectivity changes
69 *
70 * @note Only the first registered callback is currently used
71 *
72 * @param cb callback to register
73 * @param data data provided to callback
74 */
75 void (*add_connectivity_cb)(network_manager_t *this, connectivity_cb_t cb,
76 void *data);
77
78 /**
79 * Unregister a previously registered callback for connectivity changes
80 *
81 * @param cb previously registered callback
82 */
83 void (*remove_connectivity_cb)(network_manager_t *this,
84 connectivity_cb_t cb);
85
86 /**
87 * Destroy a network_manager_t instance
88 */
89 void (*destroy)(network_manager_t *this);
90 };
91
92 /**
93 * Create a network_manager_t instance
94 *
95 * @param context Context object
96 * @return network_manager_t instance
97 */
98 network_manager_t *network_manager_create(jobject context);
99
100 #endif /** NETWORK_MANAGER_H_ @}*/