nm-activation-request.c 5.31 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/* NetworkManager -- Network link manager
 *
 * Dan Williams <dcbw@redhat.com>
 *
 * 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.
 *
 * 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * (C) Copyright 2005 Red Hat, Inc.
 */


#include <glib.h>
#include <string.h>
25
#include <dbus/dbus.h>
26
#include "nm-activation-request.h"
27
#include "nm-device.h"
28
#include "NetworkManagerDbus.h"
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "nm-dhcp-manager.h"
#include "nm-utils.h"


struct NMActRequest
{
	int				refcount;
	NMData *			data;
	NMDevice *		dev;
	NMAccessPoint *	ap;
	NMIP4Config *		ip4_config;

	gboolean			user_requested;

	NMActStage		stage;
	DBusPendingCall *	user_key_pcall;

46
	guint32			dhcp_state;
47
48
49
50
51
52
53
54
55
56
57
	guint			dhcp_timeout;
};


NMActRequest * nm_act_request_new (NMData *data, NMDevice *dev, NMAccessPoint *ap, gboolean user_requested)
{
	NMActRequest *	req;

	g_return_val_if_fail (data != NULL, NULL);
	g_return_val_if_fail (dev != NULL, NULL);

58
	if (nm_device_is_802_11_wireless (dev))
59
60
61
62
63
64
		g_return_val_if_fail (ap != NULL, NULL);

	req = g_malloc0 (sizeof (NMActRequest));
	req->refcount = 1;
	req->data = data;

65
	g_object_ref (G_OBJECT (dev));
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
	req->dev = dev;

	if (ap)
		nm_ap_ref (ap);
	req->ap = ap;

	req->user_requested = user_requested;
	req->dhcp_state = nm_dhcp_manager_get_state_for_device (data->dhcp_manager, dev);

	return req;
}

void nm_act_request_ref (NMActRequest *req)
{
	g_return_if_fail (req != NULL);

	req->refcount++;
}


void nm_act_request_unref (NMActRequest *req)
{
	g_return_if_fail (req != NULL);

90
91
	req->refcount--;
	if (req->refcount <= 0)
92
	{
93
		g_object_unref (G_OBJECT (req->dev));
94
95
96
97
98
99
100
101
102
103
		if (req->ap)
			nm_ap_unref (req->ap);

		if (req->dhcp_timeout > 0)
		{
			GSource *	source = g_main_context_find_source_by_id (req->data->main_context, req->dhcp_timeout);
			g_source_destroy (source);
		}

		memset (req, 0, sizeof (NMActRequest));
104
		g_free (req);
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
	}
}

NMDevice * nm_act_request_get_dev (NMActRequest *req)
{
	g_return_val_if_fail (req != NULL, NULL);

	return req->dev;
}


NMData * nm_act_request_get_data (NMActRequest *req)
{
	g_return_val_if_fail (req != NULL, NULL);

	return req->data;
}


NMAccessPoint * nm_act_request_get_ap (NMActRequest *req)
{
	g_return_val_if_fail (req != NULL, NULL);

	return req->ap;
}


gboolean nm_act_request_get_user_requested (NMActRequest *req)
{
	g_return_val_if_fail (req != NULL, FALSE);

	return req->user_requested;
}


NMIP4Config * nm_act_request_get_ip4_config (NMActRequest *req)
{
	g_return_val_if_fail (req != NULL, NULL);

	return req->ip4_config;
}

void nm_act_request_set_ip4_config (NMActRequest *req, NMIP4Config *ip4_config)
{
	g_return_if_fail (req != NULL);

	if (req->ip4_config)
	{
		nm_ip4_config_unref (req->ip4_config);
		req->ip4_config = NULL;
	}
	if (ip4_config)
	{
		nm_ip4_config_ref (ip4_config);
		req->ip4_config = ip4_config;
	}
}

NMActStage nm_act_request_get_stage (NMActRequest *req)
{
165
	g_return_val_if_fail (req != NULL, NM_ACT_STAGE_UNKNOWN);
166
167
168
169
170
171

	return req->stage;
}

void nm_act_request_set_stage (NMActRequest *req, NMActStage stage)
{
172
173
174
	DBusMessage *		message;
	char *			dev_path;

175
176
177
	g_return_if_fail (req != NULL);

	req->stage = stage;
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198

	g_return_if_fail (req->data);
	g_return_if_fail (req->dev);

	if (!(dev_path = nm_dbus_get_object_path_for_device (req->dev)))
		return;

	if (!(message = dbus_message_new_signal (NM_DBUS_PATH, NM_DBUS_INTERFACE, "DeviceActivationStage")))
	{
		nm_warning ("nm_act_request_set_stage(): Not enough memory for new dbus message!");
		g_free (dev_path);
		return;
	}

	dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &dev_path, DBUS_TYPE_UINT32, &stage, DBUS_TYPE_INVALID);
	g_free (dev_path);

	if (!dbus_connection_send (req->data->dbus_connection, message, NULL))
		nm_warning ("nm_act_request_set_stage(): Could not raise the signal!");

	dbus_message_unref (message);
199
200
201
202
203
204
205
206
207
208
209
210
211
}

DBusPendingCall * nm_act_request_get_user_key_pending_call (NMActRequest *req)
{
	g_return_val_if_fail (req != NULL, NULL);

	return req->user_key_pcall;
}

void nm_act_request_set_user_key_pending_call (NMActRequest *req, DBusPendingCall *pcall)
{
	g_return_if_fail (req != NULL);

212
213
	if (req->user_key_pcall)
		dbus_pending_call_unref (req->user_key_pcall);
214
	req->user_key_pcall = pcall;
215
216
	if (req->user_key_pcall)
		dbus_pending_call_ref (req->user_key_pcall);
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
}

guint8 nm_act_request_get_dhcp_state (NMActRequest *req)
{
	g_return_val_if_fail (req != NULL, 0);

	return req->dhcp_state;
}

void nm_act_request_set_dhcp_state (NMActRequest *req, guint8 dhcp_state)
{
	g_return_if_fail (req != NULL);

	req->dhcp_state = dhcp_state;
}

guint nm_act_request_get_dhcp_timeout (NMActRequest *req)
{
	g_return_val_if_fail (req != NULL, 0);

	return req->dhcp_timeout;
}

void nm_act_request_set_dhcp_timeout (NMActRequest *req, guint dhcp_timeout)
{
	g_return_if_fail (req != NULL);

	req->dhcp_timeout = dhcp_timeout;
}