summaryrefslogtreecommitdiff
path: root/packages/packagekit/files/repository-ping.patch
blob: 75597e42c0a1f798d5e86d2e93b8398c20567192 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
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
diff --git a/backends/dummy/pk-backend-dummy.c b/backends/dummy/pk-backend-dummy.c
index 5714e9f..162e6ce 100644
--- a/backends/dummy/pk-backend-dummy.c
+++ b/backends/dummy/pk-backend-dummy.c
@@ -777,6 +777,16 @@ backend_what_provides (PkBackend *backend, PkFilterEnum filters, PkProvidesEnum
 }
 
 /**
+ * backend_repos_ping:
+ */ 
+static PkNetworkEnum
+backend_repos_ping (PkBackend *backend)
+{
+	pk_backend_finished (backend);
+	return PK_NETWORK_ENUM_UNKNOWN;
+}
+
+/**
  * backend_get_packages:
  */
 static void
@@ -821,6 +831,7 @@ PK_BACKEND_OPTIONS (
 	backend_service_pack,			/* service_pack */
 	backend_update_packages,		/* update_packages */
 	backend_update_system,			/* update_system */
-	backend_what_provides			/* what_provides */
+	backend_what_provides, 			/* what_provides */
+	backend_repos_ping			/* repos_ping */
 );
 
diff --git a/backends/opkg/pk-backend-opkg.c b/backends/opkg/pk-backend-opkg.c
index 02966c9..a20769f 100644
--- a/backends/opkg/pk-backend-opkg.c
+++ b/backends/opkg/pk-backend-opkg.c
@@ -705,6 +705,16 @@ backend_get_details (PkBackend *backend, const gchar *package_id)
 	pk_backend_thread_create (backend, backend_get_details_thread);
 }
 
+static PkNetworkEnum 
+backend_repos_ping (PkBackend *backend)
+{
+	int opkg_ret = opkg_repository_accessibility_check(opkg);
+	pk_backend_set_percentage (backend, PK_BACKEND_PERCENTAGE_INVALID);
+	pk_backend_finished (backend);
+	pk_debug("opkg repos_ping ret = %d\n", opkg_ret);
+	return opkg_ret ? PK_NETWORK_ENUM_OFFLINE : PK_NETWORK_ENUM_ONLINE;
+}
+
 PK_BACKEND_OPTIONS (
 	"opkg",					/* description */
 	"Thomas Wood <thomas@openedhand.com>",	/* author */
@@ -737,6 +747,7 @@ PK_BACKEND_OPTIONS (
 	NULL,					/* service_pack */
 	backend_update_packages,		/* update_packages */
 	backend_update_system,			/* update_system */
-	NULL					/* what_provides */
+	NULL, 					/* what_provides */
+	backend_repos_ping			/* repos_ping */
 );
 
diff --git a/backends/test/pk-backend-test-dbus.c b/backends/test/pk-backend-test-dbus.c
index 76686dc..9ef733d 100644
--- a/backends/test/pk-backend-test-dbus.c
+++ b/backends/test/pk-backend-test-dbus.c
@@ -105,6 +105,7 @@ PK_BACKEND_OPTIONS (
 	NULL,					/* service_pack */
 	NULL,					/* update_packages */
 	NULL,					/* update_system */
-	NULL					/* what_provides */
+	NULL,					/* what_provides */
+	NULL					/* repos_ping */
 );
 
diff --git a/backends/test/pk-backend-test-fail.c b/backends/test/pk-backend-test-fail.c
index b429c1b..a70564a 100644
--- a/backends/test/pk-backend-test-fail.c
+++ b/backends/test/pk-backend-test-fail.c
@@ -275,6 +275,7 @@ PK_BACKEND_OPTIONS (
 	NULL,					/* service_pack */
 	backend_update_packages,		/* update_packages */
 	backend_update_system,			/* update_system */
-	NULL					/* what_provides */
+	NULL, 					/* what_provides */
+	NULL					/* repos_ping */
 );
 
diff --git a/backends/test/pk-backend-test-nop.c b/backends/test/pk-backend-test-nop.c
index 3526fa5..a715b9b 100644
--- a/backends/test/pk-backend-test-nop.c
+++ b/backends/test/pk-backend-test-nop.c
@@ -55,6 +55,7 @@ PK_BACKEND_OPTIONS (
 	NULL,					/* service_pack */
 	NULL,					/* update_package */
 	NULL,					/* update_system */
-	NULL					/* what_provides */
+	NULL, 					/* what_provides */
+	NULL					/* repos_ping */
 );
 
diff --git a/backends/test/pk-backend-test-spawn.c b/backends/test/pk-backend-test-spawn.c
index 584f44c..424c7d4 100644
--- a/backends/test/pk-backend-test-spawn.c
+++ b/backends/test/pk-backend-test-spawn.c
@@ -96,6 +96,7 @@ PK_BACKEND_OPTIONS (
 	NULL,					/* service_pack */
 	NULL,					/* update_package */
 	NULL,					/* update_system */
-	NULL					/* what_provides */
+	NULL,					/* what_provides */
+	NULL					/* repos_ping */
 );
 
diff --git a/backends/test/pk-backend-test-succeed.c b/backends/test/pk-backend-test-succeed.c
index c046c1d..116d4fe 100644
--- a/backends/test/pk-backend-test-succeed.c
+++ b/backends/test/pk-backend-test-succeed.c
@@ -304,6 +304,16 @@ backend_what_provides (PkBackend *backend, PkFilterEnum filters, PkProvidesEnum
 }
 
 /**
+ * backend_repos_ping
+ */ 
+static PkNetworkEnum
+backend_repos_ping (PkBackend *backend)
+{
+	pk_backend_finished(backend);
+	return PK_NETWORK_ENUM_UNKNOWN;
+}
+
+/**
  * backend_get_packages:
  */
 static void
@@ -344,6 +354,7 @@ PK_BACKEND_OPTIONS (
 	backend_service_pack,			/* service_pack */
 	backend_update_packages,		/* update_packages */
 	backend_update_system,			/* update_system */
-	backend_what_provides			/* what_provides */
+	backend_what_provides, 			/* what_provides */
+	backend_repos_ping			/* repos_ping */
 );
 
diff --git a/backends/test/pk-backend-test-thread.c b/backends/test/pk-backend-test-thread.c
index 46ee862..a00cd26 100644
--- a/backends/test/pk-backend-test-thread.c
+++ b/backends/test/pk-backend-test-thread.c
@@ -168,6 +168,7 @@ PK_BACKEND_OPTIONS (
 	NULL,					/* service_pack */
 	NULL,					/* update_package */
 	NULL,					/* update_system */
-	NULL					/* what_provides */
+	NULL, 					/* what_provides */
+	NULL					/* repos_ping */
 );
 
diff --git a/src/pk-backend-internal.h b/src/pk-backend-internal.h
index 2bffaff..f46159c 100644
--- a/src/pk-backend-internal.h
+++ b/src/pk-backend-internal.h
@@ -71,6 +71,8 @@ PkGroupEnum	 pk_backend_get_groups			(PkBackend	*backend);
 PkFilterEnum	 pk_backend_get_filters			(PkBackend	*backend);
 PkRoleEnum	 pk_backend_get_actions			(PkBackend	*backend);
 
+PkNetworkEnum    pk_backend_repos_ping			(PkBackend      *backend);
+
 G_END_DECLS
 
 #endif /* __PK_BACKEND_INTERNAL_H */
diff --git a/src/pk-backend.c b/src/pk-backend.c
index 6efa55e..32ff276 100644
--- a/src/pk-backend.c
+++ b/src/pk-backend.c
@@ -165,6 +165,23 @@ pk_backend_get_filters (PkBackend *backend)
 }
 
 /**
+ */
+PkNetworkEnum    
+pk_backend_repos_ping (PkBackend      *backend) 
+{
+	g_return_val_if_fail (PK_IS_BACKEND (backend), PK_NETWORK_ENUM_UNKNOWN);
+	g_return_val_if_fail (backend->priv->locked != FALSE, PK_NETWORK_ENUM_UNKNOWN);
+
+	/* not compulsory */
+	if (backend->desc->repos_ping == NULL) {
+		return PK_NETWORK_ENUM_UNKNOWN;
+	}
+
+	pk_debug("Runing backend's repos_ping\n");
+	return backend->desc->repos_ping (backend);
+}
+
+/**
  * pk_backend_get_actions:
  **/
 PkRoleEnum
diff --git a/src/pk-backend.h b/src/pk-backend.h
index a7ba754..1f41c6c 100644
--- a/src/pk-backend.h
+++ b/src/pk-backend.h
@@ -258,6 +258,7 @@ typedef struct {
 							 PkFilterEnum	 filters,
 							 PkProvidesEnum	 provides,
 							 const gchar	*search);
+	PkNetworkEnum	(*repos_ping) 			(PkBackend 	*backend);
 	gpointer	padding[10];
 } PkBackendDesc;
 
@@ -266,7 +267,7 @@ typedef struct {
 			   get_update_detail, get_updates, install_files, install_packages,		\
 			   install_signature, refresh_cache, remove_packages, repo_enable,		\
 			   repo_set_data, resolve, rollback, search_details, search_file, search_group,	\
-			   search_name, service_pack, update_packages, update_system, what_provides)	\
+			   search_name, service_pack, update_packages, update_system, what_provides, repos_ping)	\
 	G_MODULE_EXPORT const PkBackendDesc pk_backend_desc = { 					\
 		description,		\
 		author,			\
@@ -300,6 +301,7 @@ typedef struct {
 		update_packages,	\
 		update_system,		\
 		what_provides,		\
+		repos_ping, 		\
 		{0} 			\
 	}
 
diff --git a/src/pk-engine.c b/src/pk-engine.c
index 14ecf41..f9359f2 100644
--- a/src/pk-engine.c
+++ b/src/pk-engine.c
@@ -279,8 +279,11 @@ pk_engine_get_network_state (PkEngine *engine, gchar **state, GError **error)
 {
 	PkNetworkEnum network;
 	g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
-	/* get the network state */
-	network = pk_network_get_network_state (engine->priv->network);
+	network = pk_backend_repos_ping(engine->priv->backend);
+	if (network == PK_NETWORK_ENUM_UNKNOWN)  {
+		/* get the network state */
+		network = pk_network_get_network_state (engine->priv->network);
+	}
 	*state = g_strdup (pk_network_enum_to_text (network));
 	return TRUE;
 }