GDBus: Support Ugly_Case and use org.gtk.GDBus.C.Name since it's C-only

Signed-off-by: David Zeuthen <davidz@redhat.com>
This commit is contained in:
David Zeuthen 2011-04-15 08:24:40 -04:00
parent 8826ad046d
commit febfc45fbe
5 changed files with 125 additions and 56 deletions

View File

@ -154,7 +154,7 @@
gdbus-codegen --c-namespace MyApp \ gdbus-codegen --c-namespace MyApp \
--generate-c-code myapp-generated \ --generate-c-code myapp-generated \
--annotate "org.project.InterfaceName" \ --annotate "org.project.InterfaceName" \
--key org.gtk.GDBus.Name --value MyFrobnicator \ --key org.gtk.GDBus.C.Name --value MyFrobnicator \
--annotate "org.project.InterfaceName:Property" \ --annotate "org.project.InterfaceName:Property" \
--key bar --value bat \ --key bar --value bat \
--annotate "org.project.InterfaceName.Method()" \ --annotate "org.project.InterfaceName.Method()" \
@ -182,35 +182,57 @@ gdbus-codegen --c-namespace MyApp \
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term><literal>org.gtk.GDBus.Name</literal></term> <term><literal>org.gtk.GDBus.C.Name</literal></term>
<listitem> <listitem>
<para> <para>
Can be used on any <literal>&lt;interface&gt;</literal>, Can be used on any <literal>&lt;interface&gt;</literal>,
<literal>&lt;method&gt;</literal>, <literal>&lt;method&gt;</literal>,
<literal>&lt;signal&gt;</literal> and <literal>&lt;signal&gt;</literal> and
<literal>&lt;property&gt;</literal> element to specify the <literal>&lt;property&gt;</literal> element to specify the
name to use. name to use when generating C code. The value is always
expected to be in <ulink
url="http://en.wikipedia.org/wiki/CamelCase">CamelCase</ulink>
or <emphasis>Ugly_Case</emphasis> (see below).
</para> </para>
<para> <para>
For interfaces where this annotation is not specified, the For interfaces, if not specified, the name defaults to the
name used is the D-Bus interface name stripped with the D-Bus interface name stripped with the prefix given with
prefix given with <option>--interface-prefix</option> and with <option>--interface-prefix</option> and with the dots
the dots removed and initial characters capitalized. For removed and initial characters capitalized. For example, for
example the D-Bus interface the D-Bus interface <literal>com.acme.Coyote</literal> the
<literal>com.acme.Coyote</literal> the name used is name used is <literal>ComAcmeCoyote</literal>. For the D-Bus
<type>ComAcmeCoyote</type>. For the D-Bus interface interface <literal>org.project.Bar.Frobnicator</literal>
<literal>org.project.Bar.Frobnicator</literal> with with <option>--interface-prefix</option>
<option>--interface-prefix</option>
<literal>org.project.</literal>, the name used is <literal>org.project.</literal>, the name used is
<type>BarFrobnicator</type>. <literal>BarFrobnicator</literal>.
</para> </para>
<para> <para>
For methods, signals and properties the name used is For methods, signals and properties, if not specified, the
calculated by transforming name defaults to the name of the method, signal or property.
<literal>NameGivenThisWay</literal> into </para>
<literal>name_given_this_way</literal>, e.g. roughly <para>
converting from camel-case to lower-case with underscores Two forms of the name are used - the CamelCase form and
using certain heuristics. the lower-case form. The CamelCase form is used for the #GType
and struct name, while lower-case form is used in function
names. The lower-case form is calculated by converting from
CamelCase to lower-case and inserting underscores at word
boundaries (using certain heuristics).
</para>
<para>
If the value given by the annotation contains an underscore
(sometimes called <emphasis>Ugly_Case</emphasis>), then the
camel-case name is derived by removing all underscores, and
the lower-case name is derived by lower-casing the
string. This is useful in some situations where
abbreviations are used. For example, if the annotation is
used on the interface
<literal>net.MyCorp.MyApp.iSCSITarget</literal> with the
value <literal>iSCSI_Target</literal> the CamelCase form is
<literal>iSCSITarget</literal> while the lower-case form is
<literal>iscsi_target</literal>. If the annotation is used
on the method <literal>EjectTheiPod</literal> with the value
<literal>Eject_The_iPod</literal>, the lower-case form is
<literal>eject_the_ipod</literal>.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>

View File

@ -170,11 +170,13 @@ class Method:
self.since = utils.lookup_since(self.annotations) self.since = utils.lookup_since(self.annotations)
name = self.name name = self.name
overridden_name = utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.Name') overridden_name = utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.C.Name')
if overridden_name: if utils.is_ugly_case(overridden_name):
name = overridden_name self.name_lower = overridden_name.lower()
else:
self.name_lower = utils.camel_case_to_uscore(name).lower().replace('-', '_') if overridden_name:
name = overridden_name
self.name_lower = utils.camel_case_to_uscore(name).lower().replace('-', '_')
self.name_hyphen = self.name_lower.replace('_', '-') self.name_hyphen = self.name_lower.replace('_', '-')
arg_count = 0 arg_count = 0
@ -201,11 +203,13 @@ class Signal:
self.since = utils.lookup_since(self.annotations) self.since = utils.lookup_since(self.annotations)
name = self.name name = self.name
overridden_name = utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.Name') overridden_name = utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.C.Name')
if overridden_name: if utils.is_ugly_case(overridden_name):
name = overridden_name self.name_lower = overridden_name.lower()
else:
self.name_lower = utils.camel_case_to_uscore(name).lower().replace('-', '_') if overridden_name:
name = overridden_name
self.name_lower = utils.camel_case_to_uscore(name).lower().replace('-', '_')
self.name_hyphen = self.name_lower.replace('_', '-') self.name_hyphen = self.name_lower.replace('_', '-')
arg_count = 0 arg_count = 0
@ -242,11 +246,13 @@ class Property:
self.since = utils.lookup_since(self.annotations) self.since = utils.lookup_since(self.annotations)
name = self.name name = self.name
overridden_name = utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.Name') overridden_name = utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.C.Name')
if overridden_name: if utils.is_ugly_case(overridden_name):
name = overridden_name self.name_lower = overridden_name.lower()
else:
self.name_lower = utils.camel_case_to_uscore(name).lower().replace('-', '_') if overridden_name:
name = overridden_name
self.name_lower = utils.camel_case_to_uscore(name).lower().replace('-', '_')
self.name_hyphen = self.name_lower.replace('_', '-') self.name_hyphen = self.name_lower.replace('_', '-')
# recalculate arg # recalculate arg
@ -272,26 +278,40 @@ class Interface:
if len(self.since) == 0: if len(self.since) == 0:
self.since = utils.lookup_since(self.annotations) self.since = utils.lookup_since(self.annotations)
overridden_name = utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.Name') overridden_name = utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.C.Name')
if overridden_name: if utils.is_ugly_case(overridden_name):
name = overridden_name name = overridden_name.replace('_', '')
else: name_with_ns = c_namespace + name
name = self.name self.name_without_prefix = name
if name.startswith(interface_prefix): self.camel_name = name_with_ns
name = name[len(interface_prefix):] if len(c_namespace) > 0:
self.name_without_prefix = name self.ns_upper = utils.camel_case_to_uscore(c_namespace).upper() + '_'
name = utils.strip_dots(name) self.name_lower = utils.camel_case_to_uscore(c_namespace) + '_' + overridden_name.lower()
name_with_ns = utils.strip_dots(c_namespace + '.' + name) else:
self.ns_upper = ''
self.name_lower = overridden_name.lower()
self.name_upper = overridden_name.upper()
#raise RuntimeError('handle Ugly_Case ', overridden_name)
self.camel_name = name_with_ns
if len(c_namespace) > 0:
self.ns_upper = utils.camel_case_to_uscore(c_namespace).upper() + '_'
self.name_lower = utils.camel_case_to_uscore(c_namespace) + '_' + utils.camel_case_to_uscore(name)
else: else:
self.ns_upper = '' if overridden_name:
self.name_lower = utils.camel_case_to_uscore(name_with_ns) name = overridden_name
self.name_upper = utils.camel_case_to_uscore(name).upper() else:
name = self.name
if name.startswith(interface_prefix):
name = name[len(interface_prefix):]
self.name_without_prefix = name
name = utils.strip_dots(name)
name_with_ns = utils.strip_dots(c_namespace + '.' + name)
self.camel_name = name_with_ns
if len(c_namespace) > 0:
self.ns_upper = utils.camel_case_to_uscore(c_namespace).upper() + '_'
self.name_lower = utils.camel_case_to_uscore(c_namespace) + '_' + utils.camel_case_to_uscore(name)
else:
self.ns_upper = ''
self.name_lower = utils.camel_case_to_uscore(name_with_ns)
self.name_upper = utils.camel_case_to_uscore(name).upper()
for m in self.methods: for m in self.methods:
m.post_process(interface_prefix, c_namespace) m.post_process(interface_prefix, c_namespace)

View File

@ -34,6 +34,11 @@ def camel_case_to_uscore(s):
insert_uscore = False insert_uscore = False
return ret return ret
def is_ugly_case(s):
if s and s.find('_') > 0:
return True
return False
def lookup_annotation(annotations, key): def lookup_annotation(annotations, key):
if annotations: if annotations:
for a in annotations: for a in annotations:

View File

@ -2137,10 +2137,16 @@ extern gpointer name_forcing_1;
extern gpointer name_forcing_2; extern gpointer name_forcing_2;
extern gpointer name_forcing_3; extern gpointer name_forcing_3;
extern gpointer name_forcing_4; extern gpointer name_forcing_4;
extern gpointer name_forcing_5;
extern gpointer name_forcing_6;
extern gpointer name_forcing_7;
gpointer name_forcing_1 = foo_rocket123_get_gtype; gpointer name_forcing_1 = foo_rocket123_get_gtype;
gpointer name_forcing_2 = foo_rocket123_call_ignite_xyz; gpointer name_forcing_2 = foo_rocket123_call_ignite_xyz;
gpointer name_forcing_3 = foo_rocket123_emit_exploded_xyz; gpointer name_forcing_3 = foo_rocket123_emit_exploded_xyz;
gpointer name_forcing_4 = foo_rocket123_get_speed_xyz; gpointer name_forcing_4 = foo_rocket123_get_speed_xyz;
gpointer name_forcing_5 = foo_test_ugly_case_interface_call_get_iscsi_servers;
gpointer name_forcing_6 = foo_test_ugly_case_interface_emit_servers_updated_now;
gpointer name_forcing_7 = foo_test_ugly_case_interface_get_ugly_name;
/* ---------------------------------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------------------------------- */

View File

@ -135,21 +135,21 @@
<!-- force various names --> <!-- force various names -->
<interface name="com.acme.Rocket"> <interface name="com.acme.Rocket">
<!-- Forcing the typename via an annotation --> <!-- Forcing the typename via an annotation -->
<annotation name="org.gtk.GDBus.Name" value="Rocket123"/> <annotation name="org.gtk.GDBus.C.Name" value="Rocket123"/>
<!-- ditto method --> <!-- ditto method -->
<method name="Ignite"> <method name="Ignite">
<annotation name="org.gtk.GDBus.Name" value="ignite_xyz"/> <annotation name="org.gtk.GDBus.C.Name" value="ignite_xyz"/>
</method> </method>
<!-- ditto signal --> <!-- ditto signal -->
<signal name="Exploded"> <signal name="Exploded">
<annotation name="org.gtk.GDBus.Name" value="exploded-xyz"/> <annotation name="org.gtk.GDBus.C.Name" value="exploded-xyz"/>
</signal> </signal>
<!-- ditto property --> <!-- ditto property -->
<property name="Speed" type="d" access="read"> <property name="Speed" type="d" access="read">
<annotation name="org.gtk.GDBus.Name" value="speed-xyz"/> <annotation name="org.gtk.GDBus.C.Name" value="speed-xyz"/>
</property> </property>
<property name="Direction" type="(ddd)" access="read"/> <property name="Direction" type="(ddd)" access="read"/>
@ -398,4 +398,20 @@
<method name="FooMethod"/> <method name="FooMethod"/>
</interface> </interface>
<interface name="TestUglyCaseInterface">
<annotation name="org.gtk.GDBus.C.Name" value="TesT_ugly_CASE_Interface"/>
<method name="GetiSCSIServers">
<annotation name="org.gtk.GDBus.C.Name" value="Get_iSCSI_Servers"/>
</method>
<signal name="serversUPDATEDNOW">
<annotation name="org.gtk.GDBus.C.Name" value="Servers_UPDATED_NOW"/>
</signal>
<property name="UGLYNAME" type="i" access="readwrite">
<annotation name="org.gtk.GDBus.C.Name" value="UGLY_NAME"/>
</property>
</interface>
</node> </node>