1 /* GSequencer - Advanced GTK Sequencer
2  * Copyright (C) 2005-2019 Joël Krähemann
3  *
4  * This file is part of GSequencer.
5  *
6  * GSequencer is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * GSequencer is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with GSequencer.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef __AGS_OSC_PARSER_H__
21 #define __AGS_OSC_PARSER_H__
22 
23 #include <glib.h>
24 #include <glib-object.h>
25 
26 #include <libxml/tree.h>
27 
28 #include <ags/libags.h>
29 
30 G_BEGIN_DECLS
31 
32 #define AGS_TYPE_OSC_PARSER                (ags_osc_parser_get_type ())
33 #define AGS_OSC_PARSER(obj)                (G_TYPE_CHECK_INSTANCE_CAST((obj), AGS_TYPE_OSC_PARSER, AgsOscParser))
34 #define AGS_OSC_PARSER_CLASS(class)        (G_TYPE_CHECK_CLASS_CAST((class), AGS_TYPE_OSC_PARSER, AgsOscParserClass))
35 #define AGS_IS_OSC_PARSER(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AGS_TYPE_OSC_PARSER))
36 #define AGS_IS_OSC_PARSER_CLASS(class)     (G_TYPE_CHECK_CLASS_TYPE ((class), AGS_TYPE_OSC_PARSER))
37 #define AGS_OSC_PARSER_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS ((obj), AGS_TYPE_OSC_PARSER, AgsOscParserClass))
38 
39 #define AGS_OSC_PARSER_GET_OBJ_MUTEX(obj) (&(((AgsOscParser *) obj)->obj_mutex))
40 
41 #define AGS_OSC_PARSER_MAX_TEXT_LENGTH (4096)
42 
43 typedef struct _AgsOscParser AgsOscParser;
44 typedef struct _AgsOscParserClass AgsOscParserClass;
45 
46 typedef enum{
47   AGS_OSC_PARSER_EOF        = 1,
48 }AgsOscParserFlags;
49 
50 struct _AgsOscParser
51 {
52   GObject gobject;
53 
54   guint flags;
55 
56   GRecMutex obj_mutex;
57 
58   unsigned char *buffer;
59 
60   size_t file_length;
61   size_t offset;
62 
63   gsize start_offset;
64   gint32 packet_size;
65 
66   xmlDoc *doc;
67 };
68 
69 struct _AgsOscParserClass
70 {
71   GObjectClass gobject;
72 
73   int (*osc_getc)(AgsOscParser *osc_parser);
74   void (*on_error)(AgsOscParser *osc_parser,
75 		   GError **error);
76 
77   xmlDoc* (*parse_full)(AgsOscParser *osc_parser);
78   xmlNode* (*parse_bytes)(AgsOscParser *osc_parser,
79 			  unsigned char *osc_buffer,
80 			  guint buffer_length);
81 
82   xmlNode* (*packet)(AgsOscParser *osc_parser);
83 
84   xmlNode* (*bundle)(AgsOscParser *osc_parser);
85 
86   xmlNode* (*message)(AgsOscParser *osc_parser);
87 
88   xmlNode* (*value)(AgsOscParser *osc_parser,
89 		    guint v_type);
90 };
91 
92 GType ags_osc_parser_get_type(void);
93 
94 gint32 ags_osc_parser_read_gint32(AgsOscParser *osc_parser);
95 gint64 ags_osc_parser_read_gint64(AgsOscParser *osc_parser);
96 
97 gfloat ags_osc_parser_read_gfloat(AgsOscParser *osc_parser);
98 gdouble ags_osc_parser_read_gdouble(AgsOscParser *osc_parser);
99 
100 gchar* ags_osc_parser_read_text(AgsOscParser *osc_parser,
101 				gint length);
102 
103 int ags_osc_parser_osc_getc(AgsOscParser *osc_parser);
104 void ags_osc_parser_on_error(AgsOscParser *osc_parser,
105 			     GError **error);
106 
107 xmlDoc* ags_osc_parser_parse_full(AgsOscParser *osc_parser);
108 xmlNode* ags_osc_parser_parse_bytes(AgsOscParser *osc_parser,
109 				    unsigned char *osc_buffer,
110 				    guint buffer_length);
111 
112 xmlNode* ags_osc_parser_packet(AgsOscParser *osc_parser);
113 
114 xmlNode* ags_osc_parser_bundle(AgsOscParser *osc_parser);
115 
116 xmlNode* ags_osc_parser_message(AgsOscParser *osc_parser);
117 
118 xmlNode* ags_osc_parser_value(AgsOscParser *osc_parser,
119 			      guint v_type);
120 
121 AgsOscParser* ags_osc_parser_new();
122 
123 G_END_DECLS
124 
125 #endif /*__AGS_OSC_PARSER_H__*/
126