[vala] Allow dynamic type registration of generated dbus proxy classes



commit b3d144251e7aaeb33ef5af1fa98b05bda4672a47
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Mon Nov 4 18:00:15 2013 +0100

    Allow dynamic type registration of generated dbus proxy classes
    
    https://bugzilla.gnome.org/show_bug.cgi?id=711423

 codegen/valaccodemethodmodule.vala |   12 ++++++++++
 codegen/valagdbusclientmodule.vala |   43 ++++++++++++++++++++++++++++++++++-
 2 files changed, 53 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index c7c7818..e6069f6 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -266,6 +266,18 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                var register_call = new CCodeFunctionCall (new CCodeIdentifier ("%s_register_type".printf 
(get_ccode_lower_case_name (type_symbol, null))));
                register_call.add_argument (new CCodeIdentifier (module_init_param_name));
                ccode.add_expression (register_call);
+
+               var iface = type_symbol as Interface;
+               if (iface != null) {
+                       string? dbus_name = GDBusModule.get_dbus_name(type_symbol);
+
+                       if (dbus_name != null) {
+                               string proxy_cname = get_ccode_lower_case_prefix (type_symbol) + "proxy";
+                               var register_proxy = new CCodeFunctionCall (new CCodeIdentifier 
("%s_register_dynamic_type".printf (proxy_cname)));
+                               register_proxy.add_argument (new CCodeIdentifier (module_init_param_name));
+                               ccode.add_expression (register_proxy);
+                       }
+               }
        }
 
        /**
diff --git a/codegen/valagdbusclientmodule.vala b/codegen/valagdbusclientmodule.vala
index 695ccbc..4d01c15 100644
--- a/codegen/valagdbusclientmodule.vala
+++ b/codegen/valagdbusclientmodule.vala
@@ -127,7 +127,16 @@ public class Vala.GDBusClientModule : GDBusModule {
                        }
                }
 
-               result += "G_IMPLEMENT_INTERFACE (%s, %sproxy_%sinterface_init) ".printf (
+               string interface_macro;
+
+               if (in_plugin) {
+                       interface_macro = "G_IMPLEMENT_INTERFACE_DYNAMIC";
+               } else {
+                       interface_macro = "G_IMPLEMENT_INTERFACE";
+               }
+
+               result += "%s (%s, %sproxy_%sinterface_init) ".printf (
+                       interface_macro,
                        get_ccode_upper_case_name (iface, "TYPE_"),
                        get_ccode_lower_case_prefix (main_iface),
                        get_ccode_lower_case_prefix (iface));
@@ -156,6 +165,12 @@ public class Vala.GDBusClientModule : GDBusModule {
                var proxy_get_type = new CCodeFunction (get_type_name, "GType");
                proxy_get_type.attributes = "G_GNUC_CONST";
                decl_space.add_function_declaration (proxy_get_type);
+
+               if (in_plugin) {
+                       var proxy_register_type = new CCodeFunction ("%sproxy_register_dynamic_type".printf 
(get_ccode_lower_case_prefix (iface)));
+                       proxy_register_type.add_parameter (new CCodeParameter ("module", "GTypeModule*"));
+                       decl_space.add_function_declaration (proxy_register_type);
+               }
        }
 
        public override void visit_interface (Interface iface) {
@@ -175,7 +190,15 @@ public class Vala.GDBusClientModule : GDBusModule {
                cfile.add_type_declaration (new CCodeTypeDefinition ("GDBusProxy", new 
CCodeVariableDeclarator (cname)));
                cfile.add_type_declaration (new CCodeTypeDefinition ("GDBusProxyClass", new 
CCodeVariableDeclarator (cname + "Class")));
 
-               var define_type = new CCodeFunctionCall (new CCodeIdentifier ("G_DEFINE_TYPE_EXTENDED"));
+               string type_macro;
+
+               if (in_plugin) {
+                       type_macro = "G_DEFINE_DYNAMIC_TYPE_EXTENDED";
+               } else {
+                       type_macro = "G_DEFINE_TYPE_EXTENDED";
+               }
+
+               var define_type = new CCodeFunctionCall (new CCodeIdentifier (type_macro));
                define_type.add_argument (new CCodeIdentifier (cname));
                define_type.add_argument (new CCodeIdentifier (lower_cname));
                define_type.add_argument (new CCodeIdentifier ("G_TYPE_DBUS_PROXY"));
@@ -196,6 +219,22 @@ public class Vala.GDBusClientModule : GDBusModule {
 
                generate_signal_handler_function (iface);
 
+               if (in_plugin) {
+                       var proxy_class_finalize = new CCodeFunction (lower_cname + "_class_finalize", 
"void");
+                       proxy_class_finalize.add_parameter (new CCodeParameter ("klass", cname + "Class*"));
+                       proxy_class_finalize.modifiers = CCodeModifiers.STATIC;
+                       cfile.add_function (proxy_class_finalize);
+
+                       var proxy_type_init = new CCodeFunction (lower_cname + "_register_dynamic_type", 
"void");
+                       proxy_type_init.add_parameter (new CCodeParameter ("module", "GTypeModule*"));
+                       push_function (proxy_type_init);
+                       var call_register_type = new CCodeFunctionCall (new CCodeIdentifier (lower_cname + 
"_register_type"));
+                       call_register_type.add_argument (new CCodeIdentifier ("module"));
+                       ccode.add_expression (call_register_type);
+                       pop_function ();
+                       cfile.add_function(proxy_type_init);
+               }
+
                var proxy_instance_init = new CCodeFunction (lower_cname + "_init", "void");
                proxy_instance_init.add_parameter (new CCodeParameter ("self", cname + "*"));
                proxy_instance_init.modifiers = CCodeModifiers.STATIC;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]