tracker-0.16.2/src/libtracker-miner/tracker-network-provider.c

No issues found

  1 /*
  2  * Copyright (C) 2010, Adrien Bustany <abustany@gnome.org>
  3  *
  4  * This library is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU Lesser General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2.1 of the License, or (at your option) any later version.
  8  *
  9  * This library is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  * Lesser General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU Lesser General Public
 15  * License along with this library; if not, write to the
 16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 17  * Boston, MA  02110-1301, USA.
 18  */
 19 
 20 #include "config.h"
 21 
 22 #include "tracker-network-provider.h"
 23 
 24 /**
 25  * SECTION:tracker-network-provider
 26  * @short_description: Network status interface for cross platform backends
 27  * @include: libtracker-miner/tracker-miner.h
 28  *
 29  * The #TrackerNetworkProvider allows different backends to be written for
 30  * retrieving network connectivity status information. This can be used to
 31  * avoid heavy transfers when on a slow connection, or on a connection where
 32  * costs may apply. Currently, there are two implementations. The
 33  * NetworkManager one uses NetworkManager, and the Dummy one will always expose
 34  * the network as connected, no matter what the connectivity status actually
 35  * is.
 36  *
 37  * Since: 0.10
 38  **/
 39 
 40 static void
 41 tracker_network_provider_init (gpointer object_class)
 42 {
 43 	static gboolean is_initialized = FALSE;
 44 
 45 	if (!is_initialized) {
 46 		g_object_interface_install_property (object_class,
 47 		                                     g_param_spec_string ("name",
 48 		                                                          "Network provider name",
 49 		                                                          "Network provider name",
 50 		                                                          NULL,
 51 		                                                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 52 		/**
 53 		 * TrackerNetworkProvider::status-changed:
 54 		 * @provider: the TrackerNetworkProvider
 55 		 * @status: a TrackerNetworkProviderStatus describing the new network
 56 		 * status
 57 		 *
 58 		 * the ::status-changed signal is emitted whenever the backend informs
 59 		 * that the network status changed.
 60 		 *
 61 		 * Since: 0.10
 62 		 **/
 63 		g_signal_new ("status-changed",
 64 		              TRACKER_TYPE_NETWORK_PROVIDER,
 65 		              G_SIGNAL_RUN_LAST,
 66 		              0,
 67 		              NULL, NULL,
 68 		              g_cclosure_marshal_VOID__UINT,
 69 		              G_TYPE_NONE, 1,
 70 		              G_TYPE_UINT);
 71 		is_initialized = TRUE;
 72 	}
 73 }
 74 
 75 /**
 76  * tracker_network_provider_get_type:
 77  *
 78  * Returns: a #GType representing a %TrackerNetworkProvider.
 79  **/
 80 GType
 81 tracker_network_provider_get_type (void)
 82 {
 83 	static GType iface_type = 0;
 84 
 85 	if (iface_type == 0) {
 86 		static const GTypeInfo info = {
 87 			sizeof (TrackerNetworkProviderIface),
 88 			tracker_network_provider_init,
 89 			NULL
 90 		};
 91 
 92 		iface_type = g_type_register_static (G_TYPE_INTERFACE,
 93 		                                     "TrackerNetworkProvider",
 94 		                                     &info,
 95 		                                     0);
 96 	}
 97 
 98 	return iface_type;
 99 }
100 
101 /**
102  * tracker_network_provider_get_name:
103  * @provider: a TrackerNetworkProvider
104  *
105  * At the moment there are only two providers, "Dummy" and
106  * "NetworkManager". Either of these is what will be returned unless new
107  * providers are written.
108  *
109  * Returns: (transfer full): a newly allocated string representing the name
110  * which must be freed with g_free().
111  *
112  * Since: 0.10
113  **/
114 gchar *
115 tracker_network_provider_get_name (TrackerNetworkProvider *provider)
116 {
117 	gchar *name;
118 
119 	g_return_val_if_fail (TRACKER_IS_NETWORK_PROVIDER (provider), NULL);
120 
121 	g_object_get (provider, "name", &name, NULL);
122 
123 	return name;
124 }
125 
126 /**
127  * tracker_network_provider_get_status:
128  * @provider: a TrackerNetworkProvider
129  *
130  * This function calls the network provider's "get_status" implementation.
131  *
132  * Returns: a TrackerNetworkProviderStatus decribing the current network
133  * status.
134  *
135  * Since: 0.10
136  **/
137 TrackerNetworkProviderStatus
138 tracker_network_provider_get_status (TrackerNetworkProvider *provider)
139 {
140 	TrackerNetworkProviderIface *iface;
141 
142 	g_return_val_if_fail (TRACKER_IS_NETWORK_PROVIDER (provider), TRACKER_NETWORK_PROVIDER_UNKNOWN);
143 
144 	iface = TRACKER_NETWORK_PROVIDER_GET_INTERFACE (provider);
145 
146 	if (!iface->get_status) {
147 		return TRACKER_NETWORK_PROVIDER_UNKNOWN;
148 	}
149 
150 	return iface->get_status (provider);
151 }