/* Size of the buffer used for reading from the socket */
#define BUF_SIZE 1024
-G_DEFINE_TYPE (GSSDPClient,
- gssdp_client,
- G_TYPE_OBJECT);
+static void
+gssdp_client_initable_iface_init (gpointer g_iface,
+ gpointer iface_data);
+
+G_DEFINE_TYPE_EXTENDED (GSSDPClient,
+ gssdp_client,
+ G_TYPE_OBJECT,
+ 0,
+ G_IMPLEMENT_INTERFACE
+ (G_TYPE_INITABLE,
+ gssdp_client_initable_iface_init));
struct _GSSDPClientPrivate {
GMainContext *main_context;
char *host_ip;
char *network;
- GError **error;
-
GSSDPSocketSource *request_socket;
GSSDPSocketSource *multicast_socket;
PROP_IFACE,
PROP_NETWORK,
PROP_HOST_IP,
- PROP_ACTIVE,
- PROP_ERROR
+ PROP_ACTIVE
};
enum {
GIOCondition condition,
gpointer user_data);
static gboolean
-init_network_info (GSSDPClient *client);
+init_network_info (GSSDPClient *client,
+ GError **error);
+
+static gboolean
+gssdp_client_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error);
static void
gssdp_client_init (GSSDPClient *client)
}
static void
-gssdp_client_constructed (GObject *object)
+gssdp_client_initable_iface_init (gpointer g_iface,
+ gpointer iface_data)
{
- GSSDPClient *client = GSSDP_CLIENT (object);
- GError *error = NULL;
+ GInitableIface *iface = (GInitableIface *)g_iface;
+ iface->init = gssdp_client_initable_init;
+}
+
+static gboolean
+gssdp_client_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GSSDPClient *client = GSSDP_CLIENT (initable);
+ GError *internal_error = NULL;
#ifdef G_OS_WIN32
WSADATA wsaData = {0};
if (WSAStartup (MAKEWORD (2,2), &wsaData) != 0) {
gchar *message;
message = g_win32_error_message (WSAGetLastError ());
- g_set_error_literal (client->priv->error,
+ g_set_error_literal (error,
GSSDP_ERROR,
GSSDP_ERROR_FAILED,
message);
g_free (message);
+
+ return FALSE;
}
#endif
/* Make sure all network info is available to us */
- if (!init_network_info (client))
- return;
+ if (!init_network_info (client, &internal_error))
+ goto errors;
/* Set up sockets (Will set errno if it failed) */
client->priv->request_socket =
gssdp_socket_source_new (GSSDP_SOCKET_SOURCE_TYPE_REQUEST,
gssdp_client_get_host_ip (client),
- &error);
+ &internal_error);
if (client->priv->request_socket != NULL) {
gssdp_socket_source_set_callback
(client->priv->request_socket,
client->priv->multicast_socket =
gssdp_socket_source_new (GSSDP_SOCKET_SOURCE_TYPE_MULTICAST,
gssdp_client_get_host_ip (client),
- &error);
+ &internal_error);
if (client->priv->multicast_socket != NULL) {
gssdp_socket_source_set_callback
(client->priv->multicast_socket,
errors:
if (!client->priv->request_socket || !client->priv->multicast_socket) {
- g_propagate_error (client->priv->error, error);
- return;
+ g_propagate_error (error, internal_error);
+
+ return FALSE;
}
gssdp_socket_source_attach (client->priv->request_socket,
gssdp_socket_source_attach (client->priv->multicast_socket,
client->priv->main_context);
+
+ return TRUE;
}
static void
gssdp_client_set_main_context (client,
g_value_get_pointer (value));
break;
- case PROP_ERROR:
- client->priv->error = g_value_get_pointer (value);
- break;
case PROP_IFACE:
client->priv->iface = g_value_dup_string (value);
break;
object_class = G_OBJECT_CLASS (klass);
- object_class->constructed = gssdp_client_constructed;
object_class->set_property = gssdp_client_set_property;
object_class->get_property = gssdp_client_get_property;
object_class->dispose = gssdp_client_dispose;
G_PARAM_STATIC_BLURB));
/**
- * GSSDPClient:error
- *
- * Internal property.
- *
- * Stability: Private
- **/
- g_object_class_install_property
- (object_class,
- PROP_ERROR,
- g_param_spec_pointer
- ("error",
- "Error",
- "Location where to store the constructor GError, "
- "if any.",
- G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
- G_PARAM_STATIC_BLURB));
-
- /**
* GSSDPClient:interface
*
* The name of the network interface this client is associated with.
const char *iface,
GError **error)
{
- return g_object_new (GSSDP_TYPE_CLIENT,
- "main-context", main_context,
- "interface", iface,
- "error", error,
- NULL);
+ return g_initable_new (GSSDP_TYPE_CLIENT,
+ NULL,
+ error,
+ "main-context", main_context,
+ "interface", iface,
+ NULL);
}
/**
}
static gboolean
-init_network_info (GSSDPClient *client)
+init_network_info (GSSDPClient *client, GError **error)
{
gboolean ret = TRUE;
&client->priv->network);
if (client->priv->iface == NULL) {
- g_set_error_literal (client->priv->error,
+ g_set_error_literal (error,
GSSDP_ERROR,
GSSDP_ERROR_FAILED,
"No default route?");
ret = FALSE;
} else if (client->priv->host_ip == NULL) {
- g_set_error (client->priv->error,
+ g_set_error (error,
GSSDP_ERROR,
GSSDP_ERROR_NO_IP_ADDRESS,
"Failed to find IP of interface %s",