From d98d8c3d245192abe6ec5a531c9d0d678b07d061 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 21 Sep 2007 11:54:40 +0100 Subject: Add stubs to JsonParser for actually parsing a JSON stream Initial commit for getting JsonParser to work. Because GScanner API is old and mostly sucks, we need to do some magic with signals. If json_parser_load_from_data() fails, the passed GError will be set with a JSON_PARSER_ERROR code and message; unfortunately, we can't get the nice error message out of GScanner. We can, however, override the default message handler and make it emit a signal on the JsonParser object. So, to make a long story short: the GError passed to the load_from_data() method is filled with a short error message; the *real* error message is passed to the ::error signal handlers so they can actually use it. GScanner should really get a way to retrieve the last error message. --- json-glib/json-parser.h | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'json-glib/json-parser.h') diff --git a/json-glib/json-parser.h b/json-glib/json-parser.h index 50d5aa5..071b881 100644 --- a/json-glib/json-parser.h +++ b/json-glib/json-parser.h @@ -19,13 +19,19 @@ typedef struct _JsonParserPrivate JsonParserPrivate; typedef struct _JsonParserClass JsonParserClass; typedef enum { - JSON_PARSER_ERROR_INVALID_OBJECT, - JSON_PARSER_ERROR_INVALID_ARRAY, - JSON_PARSER_ERROR_INVALID_PAIR, + JSON_PARSER_ERROR_PARSE, JSON_PARSER_ERROR_UNKNOWN } JsonParserError; +typedef enum { + JSON_TOKEN_INVALID = G_TOKEN_LAST, + JSON_TOKEN_TRUE, + JSON_TOKEN_FALSE, + JSON_TOKEN_NULL, + JSON_TOKEN_LAST +} JsonTokenType; + struct _JsonParser { /*< private >*/ @@ -36,7 +42,23 @@ struct _JsonParser struct _JsonParserClass { + /*< private >*/ GObjectClass parent_class; + + /*< public >*/ + void (* error) (JsonParser *parser, + const GError *error); + + /*< private >*/ + /* padding for future expansion */ + void (* _json_reserved1) (void); + void (* _json_reserved2) (void); + void (* _json_reserved3) (void); + void (* _json_reserved4) (void); + void (* _json_reserved5) (void); + void (* _json_reserved6) (void); + void (* _json_reserved7) (void); + void (* _json_reserved8) (void); }; GQuark json_parser_error_quark (void); -- cgit v1.2.1