If we get an EOF trying to read a uint or a time value, throw an exception.
[beagle.git] / libbeagle / beagle / beagle-indexing-status-response.c
blob1d64cb235c38523f845fc8cab9828f6d4144fa77
1 /*
2 * beagle-indexing-status-response.c
4 * Copyright (C) 2006 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-indexing-status-response.h"
34 #include "beagle-private.h"
36 typedef struct {
37 gboolean is_indexing;
38 } BeagleIndexingStatusResponsePrivate;
40 #define BEAGLE_INDEXING_STATUS_RESPONSE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BEAGLE_TYPE_INDEXING_STATUS_RESPONSE, BeagleIndexingStatusResponsePrivate))
42 static BeagleResponseClass *parent_class = NULL;
44 G_DEFINE_TYPE (BeagleIndexingStatusResponse, beagle_indexing_status_response, BEAGLE_TYPE_RESPONSE)
46 static void
47 end_status (BeagleParserContext *ctx)
49 BeagleIndexingStatusResponse *response = BEAGLE_INDEXING_STATUS_RESPONSE (_beagle_parser_context_get_response (ctx));
50 BeagleIndexingStatusResponsePrivate *priv = BEAGLE_INDEXING_STATUS_RESPONSE_GET_PRIVATE (response);
52 char *buf;
53 buf = _beagle_parser_context_get_text_buffer (ctx);
55 if (strcmp (buf, "Running") == 0)
56 priv->is_indexing = TRUE;
57 else if (strcmp (buf, "NotRunning") == 0)
58 priv->is_indexing = FALSE;
59 else {
60 g_warning ("Unknown value for indexing status: %s", buf);
61 priv->is_indexing = FALSE;
64 g_free (buf);
67 enum {
68 PARSER_STATE_STATUS,
71 static BeagleParserHandler parser_handlers[] = {
72 { "Status",
73 -1,
74 PARSER_STATE_STATUS,
75 NULL,
76 end_status},
78 { 0 }
81 static void
82 beagle_indexing_status_response_class_init (BeagleIndexingStatusResponseClass *klass)
84 parent_class = g_type_class_peek_parent (klass);
86 _beagle_response_class_set_parser_handlers (BEAGLE_RESPONSE_CLASS (klass),
87 parser_handlers);
89 g_type_class_add_private (klass, sizeof (BeagleIndexingStatusResponsePrivate));
92 static void
93 beagle_indexing_status_response_init (BeagleIndexingStatusResponse *response)
97 /**
98 * beagle_indexing_status_response_is_indexing
99 * @response: a #BeagleIndexingStatusResponse
101 * Returns whether or not the daemon is running a large indexing process. This
102 * will be TRUE if a long crawling process is running, but will return FALSE if
103 * it's just indexing one or two documents.
105 * Return value: TRUE if indexing, FALSE if not.
108 beagle_indexing_status_response_is_indexing (BeagleIndexingStatusResponse *response)
110 BeagleIndexingStatusResponsePrivate *priv;
112 g_return_val_if_fail (BEAGLE_IS_INDEXING_STATUS_RESPONSE (response), -1);
113 priv = BEAGLE_INDEXING_STATUS_RESPONSE_GET_PRIVATE (response);
114 g_return_val_if_fail (priv != NULL, -1);
116 return priv->is_indexing;