FilterHtml.cs: Add ExtractText(string) command to extract text out of large html...
[beagle.git] / libbeagle / beagle / beagle-client.c
blobd667e2529a243db817abea021a13919a33669332
1 /*
2 * beagle-client.c
4 * Copyright (C) 2005 Novell, Inc.
6 */
8 /*
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
28 #include <stdlib.h>
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 #include <sys/socket.h>
32 #include <sys/un.h>
34 #include "beagle-private.h"
35 #include "beagle-client.h"
36 #include "beagle-util.h"
38 typedef struct {
39 gchar *socket_path;
40 } BeagleClientPrivate;
42 #define BEAGLE_CLIENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BEAGLE_TYPE_CLIENT, BeagleClientPrivate))
44 static GObjectClass *parent_class = NULL;
46 G_DEFINE_TYPE (BeagleClient, beagle_client, G_TYPE_OBJECT)
48 static void
49 beagle_client_finalize (GObject *obj)
51 BeagleClientPrivate *priv = BEAGLE_CLIENT_GET_PRIVATE (obj);
53 g_free (priv->socket_path);
55 if (G_OBJECT_CLASS (parent_class)->finalize)
56 G_OBJECT_CLASS (parent_class)->finalize (obj);
59 static void
60 beagle_client_class_init (BeagleClientClass *klass)
62 GObjectClass *obj_class = G_OBJECT_CLASS (klass);
64 parent_class = g_type_class_peek_parent (klass);
66 obj_class->finalize = beagle_client_finalize;
68 g_type_class_add_private (klass, sizeof (BeagleClientPrivate));
71 static void
72 beagle_client_init (BeagleClient *client)
76 /**
77 * beagle_client_new:
78 * @client_name: a string
80 * Creates a new #BeagleClient. If @client_name is %NULL it will default to "socket".
82 * Return value: a newly created #BeagleClient, or NULL if the client cannot be created.
83 **/
84 BeagleClient *
85 beagle_client_new (const char *client_name)
87 BeagleClient *client;
88 BeagleClientPrivate *priv;
89 gchar *socket_path;
91 socket_path = beagle_util_get_socket_path (client_name);
93 if (socket_path == NULL)
94 return NULL;
96 client = g_object_new (BEAGLE_TYPE_CLIENT, 0);
97 priv = BEAGLE_CLIENT_GET_PRIVATE (client);
98 priv->socket_path = socket_path;
100 return client;
104 * beagle_client_new_from_socket_path:
105 * @socket_path: a string of the path to the daemon socket
107 * Creates a new #BeagleClient, connecting to the path with @socket_path. NULL
108 * is not allowed.
110 * Return value: a newly created #BeagleClient, or NULL if the client cannot be created.
112 BeagleClient *
113 beagle_client_new_from_socket_path (const char *socket_path)
115 BeagleClient *client;
116 BeagleClientPrivate *priv;
117 struct stat buf;
119 if (stat (socket_path, &buf) == -1 || !S_ISSOCK (buf.st_mode))
120 return NULL;
122 client = g_object_new (BEAGLE_TYPE_CLIENT, 0);
123 priv = BEAGLE_CLIENT_GET_PRIVATE (client);
124 priv->socket_path = g_strdup (socket_path);
126 return client;
130 * beagle_client_send_request:
131 * @client: a #BeagleClient
132 * @request: a #BeagleRequest
133 * @err: a location to return an error #GError of type #GIOChannelError.
135 * Synchronously send a #BeagleRequest using the given #BeagleClient.
137 * Return value: a #BeagleResponse.
139 BeagleResponse *
140 beagle_client_send_request (BeagleClient *client,
141 BeagleRequest *request,
142 GError **err)
144 BeagleClientPrivate *priv;
146 g_return_val_if_fail (BEAGLE_IS_CLIENT (client), NULL);
147 g_return_val_if_fail (BEAGLE_IS_REQUEST (request), NULL);
149 priv = BEAGLE_CLIENT_GET_PRIVATE (client);
151 return _beagle_request_send (request, priv->socket_path, err);
155 * beagle_client_send_request_async:
156 * @client: a #BeagleClient
157 * @request: a #BeagleRequest
158 * @err: a location to store a #GError of type #GIOChannelError
160 * Asynchronously send a #BeagleRequest using the given #BeagleClient.
162 * Return value: %TRUE on success and otherwise %FALSE.
164 gboolean
165 beagle_client_send_request_async (BeagleClient *client,
166 BeagleRequest *request,
167 GError **err)
169 BeagleClientPrivate *priv;
171 g_return_val_if_fail (BEAGLE_IS_CLIENT (client), FALSE);
172 g_return_val_if_fail (BEAGLE_IS_REQUEST (request), FALSE);
174 priv = BEAGLE_CLIENT_GET_PRIVATE (client);
176 return _beagle_request_send_async (request, priv->socket_path, err);