mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-26 22:16:16 +01:00
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:
parent
8826ad046d
commit
febfc45fbe
@ -154,7 +154,7 @@
|
||||
gdbus-codegen --c-namespace MyApp \
|
||||
--generate-c-code myapp-generated \
|
||||
--annotate "org.project.InterfaceName" \
|
||||
--key org.gtk.GDBus.Name --value MyFrobnicator \
|
||||
--key org.gtk.GDBus.C.Name --value MyFrobnicator \
|
||||
--annotate "org.project.InterfaceName:Property" \
|
||||
--key bar --value bat \
|
||||
--annotate "org.project.InterfaceName.Method()" \
|
||||
@ -182,35 +182,57 @@ gdbus-codegen --c-namespace MyApp \
|
||||
<variablelist>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>org.gtk.GDBus.Name</literal></term>
|
||||
<term><literal>org.gtk.GDBus.C.Name</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Can be used on any <literal><interface></literal>,
|
||||
<literal><method></literal>,
|
||||
<literal><signal></literal> and
|
||||
<literal><property></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>
|
||||
For interfaces where this annotation is not specified, the
|
||||
name used is the D-Bus interface name stripped with the
|
||||
prefix given with <option>--interface-prefix</option> and with
|
||||
the dots removed and initial characters capitalized. For
|
||||
example the D-Bus interface
|
||||
<literal>com.acme.Coyote</literal> the name used is
|
||||
<type>ComAcmeCoyote</type>. For the D-Bus interface
|
||||
<literal>org.project.Bar.Frobnicator</literal> with
|
||||
<option>--interface-prefix</option>
|
||||
For interfaces, if not specified, the name defaults to the
|
||||
D-Bus interface name stripped with the prefix given with
|
||||
<option>--interface-prefix</option> and with the dots
|
||||
removed and initial characters capitalized. For example, for
|
||||
the D-Bus interface <literal>com.acme.Coyote</literal> the
|
||||
name used is <literal>ComAcmeCoyote</literal>. For the D-Bus
|
||||
interface <literal>org.project.Bar.Frobnicator</literal>
|
||||
with <option>--interface-prefix</option>
|
||||
<literal>org.project.</literal>, the name used is
|
||||
<type>BarFrobnicator</type>.
|
||||
<literal>BarFrobnicator</literal>.
|
||||
</para>
|
||||
<para>
|
||||
For methods, signals and properties the name used is
|
||||
calculated by transforming
|
||||
<literal>NameGivenThisWay</literal> into
|
||||
<literal>name_given_this_way</literal>, e.g. roughly
|
||||
converting from camel-case to lower-case with underscores
|
||||
using certain heuristics.
|
||||
For methods, signals and properties, if not specified, the
|
||||
name defaults to the name of the method, signal or property.
|
||||
</para>
|
||||
<para>
|
||||
Two forms of the name are used - the CamelCase form and
|
||||
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>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
@ -170,11 +170,13 @@ class Method:
|
||||
self.since = utils.lookup_since(self.annotations)
|
||||
|
||||
name = self.name
|
||||
overridden_name = utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.Name')
|
||||
if overridden_name:
|
||||
name = overridden_name
|
||||
|
||||
self.name_lower = utils.camel_case_to_uscore(name).lower().replace('-', '_')
|
||||
overridden_name = utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.C.Name')
|
||||
if utils.is_ugly_case(overridden_name):
|
||||
self.name_lower = overridden_name.lower()
|
||||
else:
|
||||
if overridden_name:
|
||||
name = overridden_name
|
||||
self.name_lower = utils.camel_case_to_uscore(name).lower().replace('-', '_')
|
||||
self.name_hyphen = self.name_lower.replace('_', '-')
|
||||
|
||||
arg_count = 0
|
||||
@ -201,11 +203,13 @@ class Signal:
|
||||
self.since = utils.lookup_since(self.annotations)
|
||||
|
||||
name = self.name
|
||||
overridden_name = utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.Name')
|
||||
if overridden_name:
|
||||
name = overridden_name
|
||||
|
||||
self.name_lower = utils.camel_case_to_uscore(name).lower().replace('-', '_')
|
||||
overridden_name = utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.C.Name')
|
||||
if utils.is_ugly_case(overridden_name):
|
||||
self.name_lower = overridden_name.lower()
|
||||
else:
|
||||
if overridden_name:
|
||||
name = overridden_name
|
||||
self.name_lower = utils.camel_case_to_uscore(name).lower().replace('-', '_')
|
||||
self.name_hyphen = self.name_lower.replace('_', '-')
|
||||
|
||||
arg_count = 0
|
||||
@ -242,11 +246,13 @@ class Property:
|
||||
self.since = utils.lookup_since(self.annotations)
|
||||
|
||||
name = self.name
|
||||
overridden_name = utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.Name')
|
||||
if overridden_name:
|
||||
name = overridden_name
|
||||
|
||||
self.name_lower = utils.camel_case_to_uscore(name).lower().replace('-', '_')
|
||||
overridden_name = utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.C.Name')
|
||||
if utils.is_ugly_case(overridden_name):
|
||||
self.name_lower = overridden_name.lower()
|
||||
else:
|
||||
if overridden_name:
|
||||
name = overridden_name
|
||||
self.name_lower = utils.camel_case_to_uscore(name).lower().replace('-', '_')
|
||||
self.name_hyphen = self.name_lower.replace('_', '-')
|
||||
|
||||
# recalculate arg
|
||||
@ -272,26 +278,40 @@ class Interface:
|
||||
if len(self.since) == 0:
|
||||
self.since = utils.lookup_since(self.annotations)
|
||||
|
||||
overridden_name = utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.Name')
|
||||
if overridden_name:
|
||||
name = overridden_name
|
||||
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)
|
||||
overridden_name = utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.C.Name')
|
||||
if utils.is_ugly_case(overridden_name):
|
||||
name = overridden_name.replace('_', '')
|
||||
name_with_ns = c_namespace + name
|
||||
self.name_without_prefix = 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) + '_' + overridden_name.lower()
|
||||
else:
|
||||
self.ns_upper = ''
|
||||
self.name_lower = overridden_name.lower()
|
||||
self.name_upper = overridden_name.upper()
|
||||
|
||||
|
||||
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)
|
||||
#raise RuntimeError('handle Ugly_Case ', overridden_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()
|
||||
if overridden_name:
|
||||
name = overridden_name
|
||||
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:
|
||||
m.post_process(interface_prefix, c_namespace)
|
||||
|
@ -34,6 +34,11 @@ def camel_case_to_uscore(s):
|
||||
insert_uscore = False
|
||||
return ret
|
||||
|
||||
def is_ugly_case(s):
|
||||
if s and s.find('_') > 0:
|
||||
return True
|
||||
return False
|
||||
|
||||
def lookup_annotation(annotations, key):
|
||||
if annotations:
|
||||
for a in annotations:
|
||||
|
@ -2137,10 +2137,16 @@ extern gpointer name_forcing_1;
|
||||
extern gpointer name_forcing_2;
|
||||
extern gpointer name_forcing_3;
|
||||
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_2 = foo_rocket123_call_ignite_xyz;
|
||||
gpointer name_forcing_3 = foo_rocket123_emit_exploded_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;
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------- */
|
||||
|
||||
|
@ -135,21 +135,21 @@
|
||||
<!-- force various names -->
|
||||
<interface name="com.acme.Rocket">
|
||||
<!-- 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 -->
|
||||
<method name="Ignite">
|
||||
<annotation name="org.gtk.GDBus.Name" value="ignite_xyz"/>
|
||||
<annotation name="org.gtk.GDBus.C.Name" value="ignite_xyz"/>
|
||||
</method>
|
||||
|
||||
<!-- ditto signal -->
|
||||
<signal name="Exploded">
|
||||
<annotation name="org.gtk.GDBus.Name" value="exploded-xyz"/>
|
||||
<annotation name="org.gtk.GDBus.C.Name" value="exploded-xyz"/>
|
||||
</signal>
|
||||
|
||||
<!-- ditto property -->
|
||||
<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 name="Direction" type="(ddd)" access="read"/>
|
||||
@ -398,4 +398,20 @@
|
||||
<method name="FooMethod"/>
|
||||
</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>
|
||||
|
Loading…
Reference in New Issue
Block a user