source: globalnotifiergen.pl @ f3a9d4d

release-1.10release-1.7release-1.8release-1.9
Last change on this file since f3a9d4d was f3a9d4d, checked in by David Benjamin <davidben@mit.edu>, 14 years ago
Add an OwlGlobalNotifer generated from variables It exists purely as a little GObject to fire off property signals.
  • Property mode set to 100755
File size: 6.4 KB
RevLine 
[f3a9d4d]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
21        push @vars, {type => $vartype,
22                     name => $varname,
23                     altname => $altvarname,
24                     propname => $propname,
25                     detailname => $detailname};
26      }
27    }
28    close(FILE);
29}
30
31print <<EOT;
32#include "globalnotifier.h"
33#include "owl.h"
34
35/* properties */
36enum {
37  PROP_NONE,
38  /* normal properties */
39  PROP_RIGHTSHIFT,
40  /* generated from variable listings */
41EOT
42
43for my $var (@vars) {
44  print "  " . $var->{propname} . ",\n";
45}
46
47print <<EOT;
48};
49
50G_DEFINE_TYPE(OwlGlobalNotifier, owl_global_notifier, G_TYPE_OBJECT)
51
52static void owl_global_notifier_set_property(GObject *object,
53                                             guint property_id,
54                                             const GValue *value,
55                                             GParamSpec *pspec)
56{
57  OwlGlobalNotifier *notifier = OWL_GLOBAL_NOTIFIER(object);
58
59  switch (property_id) {
60    /* normal properties */
61    case PROP_RIGHTSHIFT:
62      owl_global_set_rightshift(notifier->g, g_value_get_int(value));
63      break;
64    /* generated from variable listings */
65EOT
66
67for my $var (@vars) {
68    my $varname = $var->{name};
69    my $propname = $var->{propname};
70    print "    case $propname:\n";
71
72    if ($var->{type} =~ /^BOOL/) {
73      print <<EOT;
74      if (g_value_get_boolean(value)) {
75        owl_variable_set_bool_on(&notifier->g->vars, "$varname");
76      } else {
77        owl_variable_set_bool_off(&notifier->g->vars, "$varname");
78      }
79EOT
80    } elsif ($var->{type} =~ /^PATH/ or $var->{type} =~ /^STRING/) {
81      print "      owl_variable_set_string(&notifier->g->vars, \"$varname\", g_value_get_string(value));\n";
82    } elsif ($var->{type} =~ /^INT/ or $var->{type} =~ /^ENUM/) {
83      print "      owl_variable_set_int(&notifier->g->vars, \"$varname\", g_value_get_int(value));\n";
84    } 
85    print "      break;\n";
86}
87
88print <<EOT;
89    default:
90      G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
91  }
92}
93
94static void owl_global_notifier_get_property(GObject *object,
95                                             guint property_id,
96                                             GValue *value,
97                                             GParamSpec *pspec)
98{
99  OwlGlobalNotifier *notifier = OWL_GLOBAL_NOTIFIER(object);
100
101  switch (property_id) {
102    /* normal properties */
103    case PROP_RIGHTSHIFT:
104      g_value_set_int(value, owl_global_get_rightshift(notifier->g));
105      break;
106    /* generated from variable listings */
107EOT
108for my $var (@vars) {
109    my $varname = $var->{name};
110    my $propname = $var->{propname};
111    print "    case $propname:\n";
112
113    if ($var->{type} =~ /^BOOL/) {
114      print "      g_value_set_boolean(value, owl_variable_get_bool(&notifier->g->vars, \"$varname\"));\n";
115    } elsif ($var->{type} =~ /^PATH/ or $var->{type} =~ /^STRING/) {
116      print "      g_value_set_string(value, owl_variable_get_string(&notifier->g->vars, \"$varname\"));\n";
117    } elsif ($var->{type} =~ /^INT/ or $var->{type} =~ /^ENUM/) {
118      print "      g_value_set_int(value, owl_variable_get_int(&notifier->g->vars, \"$varname\"));\n";
119    } 
120    print "      break;\n";
121}
122print <<EOT;
123    default:
124      G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
125  }
126}
127
128static void owl_global_notifier_class_init(OwlGlobalNotifierClass *klass)
129{
130  GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
131  GParamSpec *pspec;
132
133  gobject_class->get_property = owl_global_notifier_get_property;
134  gobject_class->set_property = owl_global_notifier_set_property;
135
136  /* Register properties */
137 
138  pspec = g_param_spec_int("rightshift",
139                           "rightshift",
140                           "How much we shift to the right",
141                           0,
142                           INT_MAX,
143                           0,
144                           G_PARAM_READABLE|G_PARAM_WRITABLE
145                          |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB);
146  g_object_class_install_property(gobject_class, PROP_RIGHTSHIFT, pspec);
147
148EOT
149for my $var (@vars) {
150    my $varname = $var->{name};
151    my $propname = $var->{propname};
152    my $detailname = $var->{detailname};
153    if ($var->{type} =~ /^BOOL/) {
154      print <<EOT
155  pspec = g_param_spec_boolean("$detailname",
156                               "$varname",
157                               "$varname", /* TODO: parse out the summary too */
158                               FALSE,
159                               G_PARAM_READABLE|G_PARAM_WRITABLE
160                              |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB);
161EOT
162    } elsif ($var->{type} =~ /^PATH/ or $var->{type} =~ /^STRING/) {
163      print <<EOT
164  pspec = g_param_spec_string("$detailname",
165                              "$varname",
166                              "$varname", /* TODO: parse out the summary too */
167                              "",
168                              G_PARAM_READABLE|G_PARAM_WRITABLE
169                             |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB);
170EOT
171    } elsif ($var->{type} =~ /^INT/ or $var->{type} =~ /^ENUM/) {
172      print <<EOT
173  pspec = g_param_spec_int("$detailname",
174                           "$varname",
175                           "$varname", /* TODO: parse out the summary too */
176                           INT_MIN,
177                           INT_MAX,
178                           0,
179                           G_PARAM_READABLE|G_PARAM_WRITABLE
180                          |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB);
181EOT
182    } 
183    print "  g_object_class_install_property(gobject_class, $propname, pspec);\n\n";
184}
185print <<EOT;
186}
187
188static void owl_global_notifier_init(OwlGlobalNotifier *self)
189{
190}
191
192OwlGlobalNotifier *owl_global_notifier_new(owl_global *g)
193{
194  OwlGlobalNotifier *gn;
195 
196  gn = g_object_new(OWL_TYPE_GLOBAL_NOTIFIER, NULL);
197  gn->g = g;
198  return gn;
199}
200EOT
Note: See TracBrowser for help on using the repository browser.