2 * beagle-error-response.c
4 * Copyright (C) 2005 Novell, Inc.
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.
29 #include <sys/types.h>
30 #include <sys/socket.h>
33 #include "beagle-error-response.h"
34 #include "beagle-private.h"
35 #include "beagle-util.h"
40 } BeagleErrorResponsePrivate
;
42 #define BEAGLE_ERROR_RESPONSE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BEAGLE_TYPE_ERROR_RESPONSE, BeagleErrorResponsePrivate))
44 static BeagleResponseClass
*parent_class
= NULL
;
46 G_DEFINE_TYPE (BeagleErrorResponse
, beagle_error_response
, BEAGLE_TYPE_RESPONSE
)
49 beagle_error_response_finalize (GObject
*obj
)
51 BeagleErrorResponsePrivate
*priv
= BEAGLE_ERROR_RESPONSE_GET_PRIVATE (obj
);
53 g_free (priv
->message
);
55 if (G_OBJECT_CLASS (parent_class
)->finalize
)
56 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
60 end_error_message (BeagleParserContext
*ctx
)
62 BeagleErrorResponse
*response
= BEAGLE_ERROR_RESPONSE (_beagle_parser_context_get_response (ctx
));
63 BeagleErrorResponsePrivate
*priv
= BEAGLE_ERROR_RESPONSE_GET_PRIVATE (response
);
65 priv
->message
= _beagle_parser_context_get_text_buffer (ctx
);
69 end_error_details (BeagleParserContext
*ctx
)
71 BeagleErrorResponse
*response
= BEAGLE_ERROR_RESPONSE (_beagle_parser_context_get_response (ctx
));
72 BeagleErrorResponsePrivate
*priv
= BEAGLE_ERROR_RESPONSE_GET_PRIVATE (response
);
74 priv
->details
= _beagle_parser_context_get_text_buffer (ctx
);
82 static BeagleParserHandler parser_handlers
[] = {
99 beagle_error_response_class_init (BeagleErrorResponseClass
*klass
)
101 GObjectClass
*obj_class
= G_OBJECT_CLASS (klass
);
103 parent_class
= g_type_class_peek_parent (klass
);
105 obj_class
->finalize
= beagle_error_response_finalize
;
107 _beagle_response_class_set_parser_handlers (BEAGLE_RESPONSE_CLASS (klass
),
110 g_type_class_add_private (klass
, sizeof (BeagleErrorResponsePrivate
));
114 beagle_error_response_init (BeagleErrorResponse
*response
)
119 * beagle_error_response_get_message:
120 * @response: a #BeagleErrorResponse
122 * Get the message from given #BeagleErrorResponse.
124 * Return value: the error message from the #BeagleErrorResponse.
127 beagle_error_response_get_message (BeagleErrorResponse
*response
)
129 BeagleErrorResponsePrivate
*priv
;
131 g_return_val_if_fail (BEAGLE_IS_ERROR_RESPONSE (response
), NULL
);
133 priv
= BEAGLE_ERROR_RESPONSE_GET_PRIVATE (response
);
135 return priv
->message
;
139 * beagle_error_response_get_details:
140 * @response: a #BeagleErrorResponse
142 * Gets the error's details from given #BeagleErrorResponse.
144 * Return value: the error details from the #BeagleErrorResponse.
147 beagle_error_response_get_details (BeagleErrorResponse
*response
)
149 BeagleErrorResponsePrivate
*priv
;
151 g_return_val_if_fail (BEAGLE_IS_ERROR_RESPONSE (response
), NULL
);
153 priv
= BEAGLE_ERROR_RESPONSE_GET_PRIVATE (response
);
155 return priv
->details
;
160 _beagle_error_response_to_g_error (BeagleErrorResponse
*response
,
163 BeagleErrorResponsePrivate
*priv
;
165 priv
= BEAGLE_ERROR_RESPONSE_GET_PRIVATE (response
);
167 g_set_error (error
, BEAGLE_ERROR
, BEAGLE_ERROR_DAEMON_ERROR
,
168 "%s", priv
->message
);