Oops, fix a broken part of the patch
[beagle.git] / libbeagle / beagle / beagle-daemon-information-response.c
blobbe77ea29efcf91dfab0630f7b8afc92c2c72db76
1 /*
2 * beagle-daemon-information-response.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/socket.h>
31 #include <sys/un.h>
33 #include "beagle-daemon-information-response.h"
34 #include "beagle-private.h"
36 typedef struct {
37 char *version;
38 char *index_information;
39 char *status;
40 gboolean is_indexing;
41 } BeagleDaemonInformationResponsePrivate;
43 #define BEAGLE_DAEMON_INFORMATION_RESPONSE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BEAGLE_TYPE_DAEMON_INFORMATION_RESPONSE, BeagleDaemonInformationResponsePrivate))
45 static GObjectClass *parent_class = NULL;
47 G_DEFINE_TYPE (BeagleDaemonInformationResponse, beagle_daemon_information_response, BEAGLE_TYPE_RESPONSE)
49 static void
50 beagle_daemon_information_response_finalize (GObject *obj)
52 BeagleDaemonInformationResponsePrivate *priv = BEAGLE_DAEMON_INFORMATION_RESPONSE_GET_PRIVATE (obj);
54 g_free (priv->version);
55 g_free (priv->index_information);
56 g_free (priv->status);
58 if (G_OBJECT_CLASS (parent_class)->finalize)
59 G_OBJECT_CLASS (parent_class)->finalize (obj);
63 static void
64 end_version (BeagleParserContext *ctx)
66 BeagleDaemonInformationResponse *response = BEAGLE_DAEMON_INFORMATION_RESPONSE (_beagle_parser_context_get_response (ctx));
67 BeagleDaemonInformationResponsePrivate *priv = BEAGLE_DAEMON_INFORMATION_RESPONSE_GET_PRIVATE (response);
69 priv->version = _beagle_parser_context_get_text_buffer (ctx);
73 static void
74 end_human_readable_status (BeagleParserContext *ctx)
76 BeagleDaemonInformationResponse *response = BEAGLE_DAEMON_INFORMATION_RESPONSE (_beagle_parser_context_get_response (ctx));
77 BeagleDaemonInformationResponsePrivate *priv = BEAGLE_DAEMON_INFORMATION_RESPONSE_GET_PRIVATE (response);
79 priv->status = _beagle_parser_context_get_text_buffer (ctx);
83 static void
84 end_index_information (BeagleParserContext *ctx)
86 BeagleDaemonInformationResponse *response = BEAGLE_DAEMON_INFORMATION_RESPONSE (_beagle_parser_context_get_response (ctx));
87 BeagleDaemonInformationResponsePrivate *priv = BEAGLE_DAEMON_INFORMATION_RESPONSE_GET_PRIVATE (response);
89 priv->index_information = _beagle_parser_context_get_text_buffer (ctx);
92 static void
93 end_is_indexing (BeagleParserContext *ctx)
95 BeagleDaemonInformationResponse *response = BEAGLE_DAEMON_INFORMATION_RESPONSE (_beagle_parser_context_get_response (ctx));
96 BeagleDaemonInformationResponsePrivate *priv = BEAGLE_DAEMON_INFORMATION_RESPONSE_GET_PRIVATE (response);
97 char *buf;
99 buf = _beagle_parser_context_get_text_buffer (ctx);
101 priv->is_indexing = (strcmp (buf, "true") == 0);
103 g_free (buf);
106 enum {
107 PARSER_STATE_DAEMON_INFORMATION_VERSION,
108 PARSER_STATE_DAEMON_INFORMATION_HUMAN_READABLE_STATUS,
109 PARSER_STATE_DAEMON_INFORMATION_INDEX_INFORMATION,
110 PARSER_STATE_DAEMON_INFORMATION_IS_INDEXING,
113 static BeagleParserHandler parser_handlers[] = {
114 { "Version",
116 PARSER_STATE_DAEMON_INFORMATION_VERSION,
117 NULL,
118 end_version },
120 { "HumanReadableStatus",
122 PARSER_STATE_DAEMON_INFORMATION_HUMAN_READABLE_STATUS,
123 NULL,
124 end_human_readable_status },
126 { "IndexInformation",
128 PARSER_STATE_DAEMON_INFORMATION_INDEX_INFORMATION,
129 NULL,
130 end_index_information },
132 { "IsIndexing",
134 PARSER_STATE_DAEMON_INFORMATION_IS_INDEXING,
135 NULL,
136 end_is_indexing },
138 { 0 }
141 static void
142 beagle_daemon_information_response_class_init (BeagleDaemonInformationResponseClass *klass)
144 GObjectClass *obj_class = G_OBJECT_CLASS (klass);
145 BeagleResponseClass *response_class = BEAGLE_RESPONSE_CLASS (klass);
147 parent_class = g_type_class_peek_parent (klass);
149 obj_class->finalize = beagle_daemon_information_response_finalize;
151 _beagle_response_class_set_parser_handlers (response_class,
152 parser_handlers);
154 g_type_class_add_private (klass, sizeof (BeagleDaemonInformationResponsePrivate));
157 static void
158 beagle_daemon_information_response_init (BeagleDaemonInformationResponse *info)
163 * beagle_daemon_information_response_get_version:
164 * @response: a #BeagleDaemonInformationResponse
166 * Fetches the version string of the given #BeagleDaemonInformationResponse.
168 * Return value: the version string of the #BeagleDaemonInformationResponse.
170 G_CONST_RETURN char *
171 beagle_daemon_information_response_get_version (BeagleDaemonInformationResponse *response)
173 BeagleDaemonInformationResponsePrivate *priv;
175 g_return_val_if_fail (BEAGLE_IS_DAEMON_INFORMATION_RESPONSE (response), NULL);
177 priv = BEAGLE_DAEMON_INFORMATION_RESPONSE_GET_PRIVATE (response);
179 return priv->version;
183 * beagle_daemon_information_response_get_human_readable_status:
184 * @response: a #BeagleDaemonInformationResponse
186 * Fetches the status string of the given #BeagleDaemonInformationResponse.
188 * Return value: the status of the #BeagleDaemonInformationResponse.
190 G_CONST_RETURN char *
191 beagle_daemon_information_response_get_human_readable_status (BeagleDaemonInformationResponse *response)
193 BeagleDaemonInformationResponsePrivate *priv;
195 g_return_val_if_fail (BEAGLE_IS_DAEMON_INFORMATION_RESPONSE (response), NULL);
197 priv = BEAGLE_DAEMON_INFORMATION_RESPONSE_GET_PRIVATE (response);
199 return priv->status;
203 * beagle_daemon_information_response_get_index_information:
204 * @response: a #BeagleDaemonInformationResponse
206 * Fetches the index information of the given #BeagleDaemonInformationResponse.
208 * Return value: the index information of the #BeagleDaemonInformationResponse.
210 G_CONST_RETURN char *
211 beagle_daemon_information_response_get_index_information (BeagleDaemonInformationResponse *response)
213 BeagleDaemonInformationResponsePrivate *priv;
215 g_return_val_if_fail (BEAGLE_IS_DAEMON_INFORMATION_RESPONSE (response), NULL);
217 priv = BEAGLE_DAEMON_INFORMATION_RESPONSE_GET_PRIVATE (response);
219 return priv->index_information;
223 * beagle_daemon_information_response_is_indexing:
224 * @response: a #BeagleDaemonInformationResponse
226 * Returns whether the daemon is in the process of indexing data.
228 * Return value: a boolean indicating whether the daemon is indexing.
230 gboolean
231 beagle_daemon_information_response_is_indexing (BeagleDaemonInformationResponse *response)
233 BeagleDaemonInformationResponsePrivate *priv;
235 g_return_val_if_fail (BEAGLE_IS_DAEMON_INFORMATION_RESPONSE (response), FALSE);
237 priv = BEAGLE_DAEMON_INFORMATION_RESPONSE_GET_PRIVATE (response);
239 return priv->is_indexing;