[vala] D-Bus: Move D-Bus helpers to DBusModule
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] D-Bus: Move D-Bus helpers to DBusModule
- Date: Sat, 19 Jun 2010 23:45:55 +0000 (UTC)
commit 7cd45c840ba0c5428a6ed0b55ed1c0e59f53f79d
Author: Jürg Billeter <j bitron ch>
Date: Sun Jun 20 00:26:37 2010 +0200
D-Bus: Move D-Bus helpers to DBusModule
codegen/valaccodebasemodule.vala | 91 -------------------------------------
codegen/valadbusclientmodule.vala | 6 +--
codegen/valadbusmodule.vala | 90 ++++++++++++++++++++++++++++++++++++
codegen/valadbusservermodule.vala | 10 ++---
4 files changed, 95 insertions(+), 102 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 5b2c101..63f8795 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -208,8 +208,6 @@ public class Vala.CCodeBaseModule : CCodeModule {
public bool requires_array_move;
public bool requires_array_length;
public bool requires_strcmp0;
- public bool dbus_glib_h_needed;
- public bool dbus_glib_h_needed_in_header;
public Set<string> wrappers;
Set<Symbol> generated_external_symbols;
@@ -570,8 +568,6 @@ public class Vala.CCodeBaseModule : CCodeModule {
variable_name_map.clear ();
gvaluecollector_h_needed = false;
- dbus_glib_h_needed = false;
- dbus_glib_h_needed_in_header = false;
requires_array_free = false;
requires_array_move = false;
requires_array_length = false;
@@ -610,93 +606,6 @@ public class Vala.CCodeBaseModule : CCodeModule {
source_declarations.add_include ("gobject/gvaluecollector.h");
}
- if (dbus_glib_h_needed) {
- source_declarations.add_include ("dbus/dbus.h");
- source_declarations.add_include ("dbus/dbus-glib.h");
- source_declarations.add_include ("dbus/dbus-glib-lowlevel.h");
- }
- if (dbus_glib_h_needed_in_header || dbus_glib_h_needed) {
- var dbusvtable = new CCodeStruct ("_DBusObjectVTable");
- dbusvtable.add_field ("void", "(*register_object) (DBusConnection*, const char*, void*)");
- source_declarations.add_type_definition (dbusvtable);
-
- source_declarations.add_type_declaration (new CCodeTypeDefinition ("struct _DBusObjectVTable", new CCodeVariableDeclarator ("_DBusObjectVTable")));
-
- var cfunc = new CCodeFunction ("_vala_dbus_register_object", "void");
- cfunc.add_parameter (new CCodeFormalParameter ("connection", "DBusConnection*"));
- cfunc.add_parameter (new CCodeFormalParameter ("path", "const char*"));
- cfunc.add_parameter (new CCodeFormalParameter ("object", "void*"));
-
- cfunc.modifiers |= CCodeModifiers.STATIC;
- source_declarations.add_type_member_declaration (cfunc.copy ());
-
- var block = new CCodeBlock ();
- cfunc.block = block;
-
- var cdecl = new CCodeDeclaration ("const _DBusObjectVTable *");
- cdecl.add_declarator (new CCodeVariableDeclarator ("vtable"));
- block.add_statement (cdecl);
-
- var quark = new CCodeFunctionCall (new CCodeIdentifier ("g_quark_from_static_string"));
- quark.add_argument (new CCodeConstant ("\"DBusObjectVTable\""));
-
- var get_qdata = new CCodeFunctionCall (new CCodeIdentifier ("g_type_get_qdata"));
- get_qdata.add_argument (new CCodeIdentifier ("G_TYPE_FROM_INSTANCE (object)"));
- get_qdata.add_argument (quark);
-
- block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("vtable"), get_qdata)));
-
- var cregister = new CCodeFunctionCall (new CCodeMemberAccess.pointer (new CCodeIdentifier ("vtable"), "register_object"));
- cregister.add_argument (new CCodeIdentifier ("connection"));
- cregister.add_argument (new CCodeIdentifier ("path"));
- cregister.add_argument (new CCodeIdentifier ("object"));
-
- var ifblock = new CCodeBlock ();
- ifblock.add_statement (new CCodeExpressionStatement (cregister));
-
- var elseblock = new CCodeBlock ();
-
- var warn = new CCodeFunctionCall (new CCodeIdentifier ("g_warning"));
- warn.add_argument (new CCodeConstant ("\"Object does not implement any D-Bus interface\""));
-
- elseblock.add_statement (new CCodeExpressionStatement(warn));
-
- block.add_statement (new CCodeIfStatement (new CCodeIdentifier ("vtable"), ifblock, elseblock));
-
- source_type_member_definition.append (cfunc);
-
- // unregister function
- cfunc = new CCodeFunction ("_vala_dbus_unregister_object", "void");
- cfunc.add_parameter (new CCodeFormalParameter ("connection", "gpointer"));
- cfunc.add_parameter (new CCodeFormalParameter ("object", "GObject*"));
-
- cfunc.modifiers |= CCodeModifiers.STATIC;
- source_declarations.add_type_member_declaration (cfunc.copy ());
-
- block = new CCodeBlock ();
- cfunc.block = block;
-
- cdecl = new CCodeDeclaration ("char*");
- cdecl.add_declarator (new CCodeVariableDeclarator ("path"));
- block.add_statement (cdecl);
-
- var path = new CCodeFunctionCall (new CCodeIdentifier ("g_object_steal_data"));
- path.add_argument (new CCodeCastExpression (new CCodeIdentifier ("object"), "GObject*"));
- path.add_argument (new CCodeConstant ("\"dbus_object_path\""));
- block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("path"), path)));
-
- var unregister_call = new CCodeFunctionCall (new CCodeIdentifier ("dbus_connection_unregister_object_path"));
- unregister_call.add_argument (new CCodeIdentifier ("connection"));
- unregister_call.add_argument (new CCodeIdentifier ("path"));
- block.add_statement (new CCodeExpressionStatement (unregister_call));
-
- var path_free = new CCodeFunctionCall (new CCodeIdentifier ("g_free"));
- path_free.add_argument (new CCodeIdentifier ("path"));
- block.add_statement (new CCodeExpressionStatement (path_free));
-
- source_type_member_definition.append (cfunc);
- }
-
var writer = new CCodeWriter (source_file.get_csource_filename (), source_file.filename);
if (!writer.open (context.version_header)) {
Report.error (null, "unable to open `%s' for writing".printf (writer.filename));
diff --git a/codegen/valadbusclientmodule.vala b/codegen/valadbusclientmodule.vala
index 6993be0..77b90fc 100644
--- a/codegen/valadbusclientmodule.vala
+++ b/codegen/valadbusclientmodule.vala
@@ -1055,11 +1055,7 @@ public class Vala.DBusClientModule : DBusModule {
string cname = iface.get_cname () + "DBusProxy";
string lower_cname = iface.get_lower_case_cprefix () + "dbus_proxy";
- if (iface.access != SymbolAccessibility.PRIVATE) {
- dbus_glib_h_needed_in_header = true;
- } else {
- dbus_glib_h_needed = true;
- }
+ add_dbus_helpers ();
source_declarations.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (cname), new CCodeVariableDeclarator (cname)));
source_declarations.add_type_declaration (new CCodeTypeDefinition ("DBusGProxyClass", new CCodeVariableDeclarator (cname + "Class")));
diff --git a/codegen/valadbusmodule.vala b/codegen/valadbusmodule.vala
index 6fbf48c..1ee94d4 100644
--- a/codegen/valadbusmodule.vala
+++ b/codegen/valadbusmodule.vala
@@ -988,4 +988,94 @@ public class Vala.DBusModule : GAsyncModule {
Report.error (type.source_reference, "D-Bus serialization of type `%s' is not supported".printf (type.to_string ()));
}
}
+
+ public void add_dbus_helpers () {
+ if (source_declarations.add_declaration ("_vala_dbus_register_object")) {
+ return;
+ }
+
+ source_declarations.add_include ("dbus/dbus.h");
+ source_declarations.add_include ("dbus/dbus-glib.h");
+ source_declarations.add_include ("dbus/dbus-glib-lowlevel.h");
+
+ var dbusvtable = new CCodeStruct ("_DBusObjectVTable");
+ dbusvtable.add_field ("void", "(*register_object) (DBusConnection*, const char*, void*)");
+ source_declarations.add_type_definition (dbusvtable);
+
+ source_declarations.add_type_declaration (new CCodeTypeDefinition ("struct _DBusObjectVTable", new CCodeVariableDeclarator ("_DBusObjectVTable")));
+
+ var cfunc = new CCodeFunction ("_vala_dbus_register_object", "void");
+ cfunc.add_parameter (new CCodeFormalParameter ("connection", "DBusConnection*"));
+ cfunc.add_parameter (new CCodeFormalParameter ("path", "const char*"));
+ cfunc.add_parameter (new CCodeFormalParameter ("object", "void*"));
+
+ cfunc.modifiers |= CCodeModifiers.STATIC;
+ source_declarations.add_type_member_declaration (cfunc.copy ());
+
+ var block = new CCodeBlock ();
+ cfunc.block = block;
+
+ var cdecl = new CCodeDeclaration ("const _DBusObjectVTable *");
+ cdecl.add_declarator (new CCodeVariableDeclarator ("vtable"));
+ block.add_statement (cdecl);
+
+ var quark = new CCodeFunctionCall (new CCodeIdentifier ("g_quark_from_static_string"));
+ quark.add_argument (new CCodeConstant ("\"DBusObjectVTable\""));
+
+ var get_qdata = new CCodeFunctionCall (new CCodeIdentifier ("g_type_get_qdata"));
+ get_qdata.add_argument (new CCodeIdentifier ("G_TYPE_FROM_INSTANCE (object)"));
+ get_qdata.add_argument (quark);
+
+ block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("vtable"), get_qdata)));
+
+ var cregister = new CCodeFunctionCall (new CCodeMemberAccess.pointer (new CCodeIdentifier ("vtable"), "register_object"));
+ cregister.add_argument (new CCodeIdentifier ("connection"));
+ cregister.add_argument (new CCodeIdentifier ("path"));
+ cregister.add_argument (new CCodeIdentifier ("object"));
+
+ var ifblock = new CCodeBlock ();
+ ifblock.add_statement (new CCodeExpressionStatement (cregister));
+
+ var elseblock = new CCodeBlock ();
+
+ var warn = new CCodeFunctionCall (new CCodeIdentifier ("g_warning"));
+ warn.add_argument (new CCodeConstant ("\"Object does not implement any D-Bus interface\""));
+
+ elseblock.add_statement (new CCodeExpressionStatement(warn));
+
+ block.add_statement (new CCodeIfStatement (new CCodeIdentifier ("vtable"), ifblock, elseblock));
+
+ source_type_member_definition.append (cfunc);
+
+ // unregister function
+ cfunc = new CCodeFunction ("_vala_dbus_unregister_object", "void");
+ cfunc.add_parameter (new CCodeFormalParameter ("connection", "gpointer"));
+ cfunc.add_parameter (new CCodeFormalParameter ("object", "GObject*"));
+
+ cfunc.modifiers |= CCodeModifiers.STATIC;
+ source_declarations.add_type_member_declaration (cfunc.copy ());
+
+ block = new CCodeBlock ();
+ cfunc.block = block;
+
+ cdecl = new CCodeDeclaration ("char*");
+ cdecl.add_declarator (new CCodeVariableDeclarator ("path"));
+ block.add_statement (cdecl);
+
+ var path = new CCodeFunctionCall (new CCodeIdentifier ("g_object_steal_data"));
+ path.add_argument (new CCodeCastExpression (new CCodeIdentifier ("object"), "GObject*"));
+ path.add_argument (new CCodeConstant ("\"dbus_object_path\""));
+ block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("path"), path)));
+
+ var unregister_call = new CCodeFunctionCall (new CCodeIdentifier ("dbus_connection_unregister_object_path"));
+ unregister_call.add_argument (new CCodeIdentifier ("connection"));
+ unregister_call.add_argument (new CCodeIdentifier ("path"));
+ block.add_statement (new CCodeExpressionStatement (unregister_call));
+
+ var path_free = new CCodeFunctionCall (new CCodeIdentifier ("g_free"));
+ path_free.add_argument (new CCodeIdentifier ("path"));
+ block.add_statement (new CCodeExpressionStatement (path_free));
+
+ source_type_member_definition.append (cfunc);
+ }
}
diff --git a/codegen/valadbusservermodule.vala b/codegen/valadbusservermodule.vala
index 02abc79..399a1cc 100644
--- a/codegen/valadbusservermodule.vala
+++ b/codegen/valadbusservermodule.vala
@@ -574,11 +574,9 @@ public class Vala.DBusServerModule : DBusClientModule {
cfunc.add_parameter (new CCodeFormalParameter ("path", "const char*"));
cfunc.add_parameter (new CCodeFormalParameter ("object", "void*"));
- if (!sym.is_private_symbol ()) {
- dbus_glib_h_needed_in_header = true;
- } else {
- dbus_glib_h_needed = true;
+ add_dbus_helpers ();
+ if (sym.is_private_symbol ()) {
cfunc.modifiers |= CCodeModifiers.STATIC;
}
@@ -1504,7 +1502,7 @@ public class Vala.DBusServerModule : DBusClientModule {
void generate_message_function (ObjectType object_type) {
var sym = object_type.type_symbol;
- dbus_glib_h_needed = true;
+ add_dbus_helpers ();
var cfunc = new CCodeFunction (sym.get_lower_case_cprefix () + "dbus_message", "DBusHandlerResult");
cfunc.add_parameter (new CCodeFormalParameter ("connection", "DBusConnection*"));
@@ -1637,7 +1635,7 @@ public class Vala.DBusServerModule : DBusClientModule {
return;
}
- dbus_glib_h_needed = true;
+ add_dbus_helpers ();
expr.accept_children (codegen);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]