source: globalnotifiergen.pl @ 9bd51b8

release-1.10release-1.7release-1.8release-1.9
Last change on this file since 9bd51b8 was f06baef, checked in by David Benjamin <davidben@mit.edu>, 14 years ago
Add a message received signal as well
  • Property mode set to 100755
File size: 7.8 KB
Line 
1print qq(/* THIS FILE WAS AUTOGENERATED BY GLOBALNOTIFIERGEN.PL --- DO NOT EDIT BY HAND!!! */\n\n);
2
3my @vars = ();
4foreach $file (@ARGV) {
5    open(FILE, $file);
6
7    while (<FILE>) {
8      if (m|^\s*OWLVAR_([A-Z_0-9]+)\s*\(\s*"([^"]+)"\s*/\*\s*%OwlVarStub:?([a-z0-9_]+)?\s*\*/|) {   # "
9        my $vartype = $1;
10        my $varname = $2;
11        my $altvarname = $2;
12        $altvarname = $3 if ($3);
13
14        my $propname = $altvarname;
15        $propname =~ tr/a-z/A-Z/;
16        $propname = "PROP_$propname";
17
18        my $detailname = $altvarname;
19        $detailname =~ s/[^a-zA-Z0-9]/-/g;
20        $detailname =~ s/^[^a-zA-Z]+//;
21
22        push @vars, {type => $vartype,
23                     name => $varname,
24                     altname => $altvarname,
25                     propname => $propname,
26                     detailname => $detailname};
27      }
28    }
29    close(FILE);
30}
31
32print <<EOT;
33#include "globalnotifier.h"
34#include "owl.h"
35
36/* properties */
37enum {
38  PROP_NONE,
39  /* normal properties */
40  PROP_RIGHTSHIFT,
41  PROP_CURMSG_VERT_OFFSET,
42  /* generated from variable listings */
43EOT
44
45for my $var (@vars) {
46  print "  " . $var->{propname} . ",\n";
47}
48
49print <<EOT;
50};
51
52/* signals */
53enum {
54  VIEW_CHANGED,
55  MESSAGE_RECEIVED,
56  LAST_SIGNAL
57};
58
59static guint notifier_signals[LAST_SIGNAL] = { 0 };
60
61G_DEFINE_TYPE(OwlGlobalNotifier, owl_global_notifier, G_TYPE_OBJECT)
62
63static void owl_global_notifier_set_property(GObject *object,
64                                             guint property_id,
65                                             const GValue *value,
66                                             GParamSpec *pspec)
67{
68  OwlGlobalNotifier *notifier = OWL_GLOBAL_NOTIFIER(object);
69
70  switch (property_id) {
71    /* normal properties */
72    case PROP_RIGHTSHIFT:
73      owl_global_set_rightshift(notifier->g, g_value_get_int(value));
74      break;
75    case PROP_CURMSG_VERT_OFFSET:
76      owl_global_set_curmsg_vert_offset(notifier->g, g_value_get_int(value));
77      break;
78    /* generated from variable listings */
79EOT
80
81for my $var (@vars) {
82    my $varname = $var->{name};
83    my $propname = $var->{propname};
84    print "    case $propname:\n";
85
86    if ($var->{type} =~ /^BOOL/) {
87      print <<EOT;
88      if (g_value_get_boolean(value)) {
89        owl_variable_set_bool_on(&notifier->g->vars, "$varname");
90      } else {
91        owl_variable_set_bool_off(&notifier->g->vars, "$varname");
92      }
93EOT
94    } elsif ($var->{type} =~ /^PATH/ or $var->{type} =~ /^STRING/) {
95      print "      owl_variable_set_string(&notifier->g->vars, \"$varname\", g_value_get_string(value));\n";
96    } elsif ($var->{type} =~ /^INT/ or $var->{type} =~ /^ENUM/) {
97      print "      owl_variable_set_int(&notifier->g->vars, \"$varname\", g_value_get_int(value));\n";
98    } 
99    print "      break;\n";
100}
101
102print <<EOT;
103    default:
104      G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
105  }
106}
107
108static void owl_global_notifier_get_property(GObject *object,
109                                             guint property_id,
110                                             GValue *value,
111                                             GParamSpec *pspec)
112{
113  OwlGlobalNotifier *notifier = OWL_GLOBAL_NOTIFIER(object);
114
115  switch (property_id) {
116    /* normal properties */
117    case PROP_RIGHTSHIFT:
118      g_value_set_int(value, owl_global_get_rightshift(notifier->g));
119      break;
120    case PROP_CURMSG_VERT_OFFSET:
121      g_value_set_int(value, owl_global_get_curmsg_vert_offset(notifier->g));
122      break;
123    /* generated from variable listings */
124EOT
125for my $var (@vars) {
126    my $varname = $var->{name};
127    my $propname = $var->{propname};
128    print "    case $propname:\n";
129
130    if ($var->{type} =~ /^BOOL/) {
131      print "      g_value_set_boolean(value, owl_variable_get_bool(&notifier->g->vars, \"$varname\"));\n";
132    } elsif ($var->{type} =~ /^PATH/ or $var->{type} =~ /^STRING/) {
133      print "      g_value_set_string(value, owl_variable_get_string(&notifier->g->vars, \"$varname\"));\n";
134    } elsif ($var->{type} =~ /^INT/ or $var->{type} =~ /^ENUM/) {
135      print "      g_value_set_int(value, owl_variable_get_int(&notifier->g->vars, \"$varname\"));\n";
136    } 
137    print "      break;\n";
138}
139print <<EOT;
140    default:
141      G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
142  }
143}
144
145static void owl_global_notifier_class_init(OwlGlobalNotifierClass *klass)
146{
147  GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
148  GParamSpec *pspec;
149
150  gobject_class->get_property = owl_global_notifier_get_property;
151  gobject_class->set_property = owl_global_notifier_set_property;
152
153  /* Create signals */
154
155  notifier_signals[VIEW_CHANGED] =
156    g_signal_new("view-changed",
157                 G_TYPE_FROM_CLASS(gobject_class),
158                 G_SIGNAL_RUN_FIRST,
159                 0,
160                 NULL, NULL,
161                 g_cclosure_marshal_VOID__VOID,
162                 G_TYPE_NONE,
163                 0,
164                 NULL);
165
166  notifier_signals[MESSAGE_RECEIVED] =
167    g_signal_new("message-received",
168                 G_TYPE_FROM_CLASS(gobject_class),
169                 G_SIGNAL_RUN_FIRST,
170                 0,
171                 NULL, NULL,
172                 g_cclosure_marshal_VOID__POINTER,
173                 G_TYPE_NONE,
174                 1,
175                 G_TYPE_POINTER, NULL);
176
177  /* Register properties */
178 
179  pspec = g_param_spec_int("rightshift",
180                           "rightshift",
181                           "How much we shift to the right",
182                           0,
183                           INT_MAX,
184                           0,
185                           G_PARAM_READABLE|G_PARAM_WRITABLE
186                          |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB);
187  g_object_class_install_property(gobject_class, PROP_RIGHTSHIFT, pspec);
188
189EOT
190for my $var (@vars) {
191    my $varname = $var->{name};
192    my $propname = $var->{propname};
193    my $detailname = $var->{detailname};
194    if ($var->{type} =~ /^BOOL/) {
195      print <<EOT
196  pspec = g_param_spec_boolean("$detailname",
197                               "$varname",
198                               "$varname", /* TODO: parse out the summary too */
199                               FALSE,
200                               G_PARAM_READABLE|G_PARAM_WRITABLE
201                              |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB);
202EOT
203    } elsif ($var->{type} =~ /^PATH/ or $var->{type} =~ /^STRING/) {
204      print <<EOT
205  pspec = g_param_spec_string("$detailname",
206                              "$varname",
207                              "$varname", /* TODO: parse out the summary too */
208                              "",
209                              G_PARAM_READABLE|G_PARAM_WRITABLE
210                             |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB);
211EOT
212    } elsif ($var->{type} =~ /^INT/ or $var->{type} =~ /^ENUM/) {
213      print <<EOT
214  pspec = g_param_spec_int("$detailname",
215                           "$varname",
216                           "$varname", /* TODO: parse out the summary too */
217                           INT_MIN,
218                           INT_MAX,
219                           0,
220                           G_PARAM_READABLE|G_PARAM_WRITABLE
221                          |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB);
222EOT
223    } 
224    print "  g_object_class_install_property(gobject_class, $propname, pspec);\n\n";
225}
226print <<EOT;
227}
228
229static void owl_global_notifier_init(OwlGlobalNotifier *self)
230{
231}
232
233OwlGlobalNotifier *owl_global_notifier_new(owl_global *g)
234{
235  OwlGlobalNotifier *gn;
236 
237  gn = g_object_new(OWL_TYPE_GLOBAL_NOTIFIER, NULL);
238  gn->g = g;
239  return gn;
240}
241
242void owl_global_notifier_emit_view_changed(OwlGlobalNotifier *gn)
243{
244  g_signal_emit(gn, notifier_signals[VIEW_CHANGED], 0);
245}
246
247void owl_global_notifier_emit_message_received(OwlGlobalNotifier *gn, owl_message *msg)
248{
249  g_signal_emit(gn, notifier_signals[MESSAGE_RECEIVED], 0, msg);
250}
251EOT
Note: See TracBrowser for help on using the repository browser.