[Spice-commits] 2 commits - common/Makefile.am common/client_marshallers.h python_modules/marshal.py spice_codegen.py

Frediano Ziglio fziglio at kemper.freedesktop.org
Fri Jun 24 09:03:44 UTC 2016


 common/Makefile.am          |    6 ++++-
 common/client_marshallers.h |   46 --------------------------------------------
 python_modules/marshal.py   |   41 ++++++++++++++++++++++++++++++++++++---
 spice_codegen.py            |    1 
 4 files changed, 45 insertions(+), 49 deletions(-)

New commits:
commit 073d064b86d5233d3cbe2136ddfb2a8313b6130e
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Thu Jun 23 12:57:21 2016 +0200

    codegen: Autogenerate client_marshallers.h
    
    This commit adds autogeneration of a generated_client_marshallers.h
    header, which is then included in client_marshallers.h
    
    This allows to remove the SpiceMessageMarshallers struct from this file,
    which has to match what the generated code expects.
    
    Acked-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/common/Makefile.am b/common/Makefile.am
index 2dd56f3..4b8f63a 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -5,6 +5,7 @@ CLIENT_MARSHALLERS =				\
 	generated_client_demarshallers.c	\
 	generated_client_demarshallers1.c	\
 	generated_client_marshallers.c		\
+	generated_client_marshallers.h		\
 	generated_client_marshallers1.c		\
 	$(NULL)
 
@@ -107,8 +108,11 @@ generated_client_demarshallers.c: $(top_srcdir)/spice.proto $(MARSHALLERS_DEPS)
 generated_client_demarshallers1.c: $(top_srcdir)/spice1.proto $(MARSHALLERS_DEPS)
 	$(AM_V_GEN)$(PYTHON) $(top_srcdir)/spice_codegen.py --generate-demarshallers --client --include common/messages.h --prefix 1 --ptrsize 8 $< $@ >/dev/null
 
+generated_client_marshallers.h: $(top_srcdir)/spice.proto $(MARSHALLERS_DEPS)
+	$(AM_V_GEN)$(PYTHON) $(top_srcdir)/spice_codegen.py --generate-marshallers -P --client --include common/messages.h -H $< $@ >/dev/null
+
 generated_client_marshallers.c: $(top_srcdir)/spice.proto $(MARSHALLERS_DEPS)
-	$(AM_V_GEN)$(PYTHON) $(top_srcdir)/spice_codegen.py --generate-marshallers -P --include common/messages.h --include client_marshallers.h --client $< $@ >/dev/null
+	$(AM_V_GEN)$(PYTHON) $(top_srcdir)/spice_codegen.py --generate-marshallers -P --include client_marshallers.h --client $< $@ >/dev/null
 
 generated_client_marshallers1.c: $(top_srcdir)/spice1.proto $(MARSHALLERS_DEPS)
 	$(AM_V_GEN)$(PYTHON) $(top_srcdir)/spice_codegen.py --generate-marshallers -P --include common/messages.h --include client_marshallers.h --client --prefix 1 --ptrsize 8 $< $@ >/dev/null
diff --git a/common/client_marshallers.h b/common/client_marshallers.h
index 2074323..d3e26b4 100644
--- a/common/client_marshallers.h
+++ b/common/client_marshallers.h
@@ -25,56 +25,12 @@
 
 #include <spice/protocol.h>
 
+#include "generated_client_marshallers.h"
 #include "marshaller.h"
 #include "messages.h"
 
 SPICE_BEGIN_DECLS
 
-typedef struct {
-    void (*msg_SpiceMsgEmpty)(SpiceMarshaller *m, SpiceMsgEmpty *msg);
-    void (*msg_SpiceMsgData)(SpiceMarshaller *m, SpiceMsgData *msg);
-    void (*msg_SpiceMsgCompressedData)(SpiceMarshaller *m, SpiceMsgCompressedData *msg);
-    void (*msgc_ack_sync)(SpiceMarshaller *m, SpiceMsgcAckSync *msg);
-    void (*msgc_pong)(SpiceMarshaller *m, SpiceMsgPing *msg);
-    void (*msgc_disconnecting)(SpiceMarshaller *m, SpiceMsgDisconnect *msg);
-    void (*msgc_main_client_info)(SpiceMarshaller *m, SpiceMsgcClientInfo *msg);
-    void (*msgc_main_mouse_mode_request)(SpiceMarshaller *m, SpiceMsgcMainMouseModeRequest *msg);
-    void (*msgc_main_agent_start)(SpiceMarshaller *m, SpiceMsgcMainAgentStart *msg);
-    void (*msgc_main_agent_token)(SpiceMarshaller *m, SpiceMsgcMainAgentTokens *msg);
-    void (*msgc_main_migrate_dst_do_seamless)(SpiceMarshaller *m, SpiceMsgcMainMigrateDstDoSeamless *msg);
-    void (*msgc_display_init)(SpiceMarshaller *m, SpiceMsgcDisplayInit *msg);
-    void (*msgc_display_stream_report)(SpiceMarshaller *m, SpiceMsgcDisplayStreamReport *msg);
-    void (*msgc_display_gl_draw_done)(SpiceMarshaller *m, SpiceMsgcDisplayGlDrawDone *msg);
-    void (*msgc_inputs_key_down)(SpiceMarshaller *m, SpiceMsgcKeyDown *msg);
-    void (*msgc_inputs_key_up)(SpiceMarshaller *m, SpiceMsgcKeyUp *msg);
-    void (*msgc_inputs_key_modifiers)(SpiceMarshaller *m, SpiceMsgcKeyModifiers *msg);
-    void (*msgc_inputs_mouse_motion)(SpiceMarshaller *m, SpiceMsgcMouseMotion *msg);
-    void (*msgc_inputs_mouse_position)(SpiceMarshaller *m, SpiceMsgcMousePosition *msg);
-    void (*msgc_inputs_mouse_press)(SpiceMarshaller *m, SpiceMsgcMousePress *msg);
-    void (*msgc_inputs_mouse_release)(SpiceMarshaller *m, SpiceMsgcMouseRelease *msg);
-    void (*msgc_record_data)(SpiceMarshaller *m, SpiceMsgcRecordPacket *msg);
-    void (*msgc_record_mode)(SpiceMarshaller *m, SpiceMsgcRecordMode *msg);
-    void (*msgc_record_start_mark)(SpiceMarshaller *m, SpiceMsgcRecordStartMark *msg);
-    void (*msgc_tunnel_service_add)(SpiceMarshaller *m, SpiceMsgcTunnelAddGenericService *msg, SpiceMarshaller **name_out, SpiceMarshaller **description_out);
-    void (*msgc_tunnel_service_remove)(SpiceMarshaller *m, SpiceMsgcTunnelRemoveService *msg);
-    void (*msgc_tunnel_socket_open_ack)(SpiceMarshaller *m, SpiceMsgcTunnelSocketOpenAck *msg);
-    void (*msgc_tunnel_socket_open_nack)(SpiceMarshaller *m, SpiceMsgcTunnelSocketOpenNack *msg);
-    void (*msgc_tunnel_socket_fin)(SpiceMarshaller *m, SpiceMsgcTunnelSocketFin *msg);
-    void (*msgc_tunnel_socket_closed)(SpiceMarshaller *m, SpiceMsgcTunnelSocketClosed *msg);
-    void (*msgc_tunnel_socket_closed_ack)(SpiceMarshaller *m, SpiceMsgcTunnelSocketClosedAck *msg);
-    void (*msgc_tunnel_socket_data)(SpiceMarshaller *m, SpiceMsgcTunnelSocketData *msg);
-    void (*msgc_tunnel_socket_token)(SpiceMarshaller *m, SpiceMsgcTunnelSocketTokens *msg);
-#ifdef USE_SMARTCARD
-    void (*msgc_smartcard_atr)(SpiceMarshaller *m, VSCMsgATR *msg);
-    void (*msgc_smartcard_error)(SpiceMarshaller *m, VSCMsgError *msg);
-    void (*msgc_smartcard_header)(SpiceMarshaller *m, VSCMsgHeader *msg);
-    void (*msgc_smartcard_data)(SpiceMarshaller *m, SpiceMsgcSmartcard *msg, SpiceMarshaller **reader_name_out);
-    void (*msgc_smartcard_reader_add)(SpiceMarshaller *m, VSCMsgReaderAdd *msg);
-#endif
-    void (*msgc_port_event)(SpiceMarshaller *m, SpiceMsgcPortEvent *msg);
-    void (*msgc_display_preferred_compression)(SpiceMarshaller *m, SpiceMsgcDisplayPreferredCompression *msg);
-} SpiceMessageMarshallers;
-
 SpiceMessageMarshallers *spice_message_marshallers_get(void);
 SpiceMessageMarshallers *spice_message_marshallers_get1(void);
 
diff --git a/python_modules/marshal.py b/python_modules/marshal.py
index dc36e18..0483d3a 100644
--- a/python_modules/marshal.py
+++ b/python_modules/marshal.py
@@ -17,6 +17,9 @@ def write_includes(writer):
         src = "_H_"+src[:-2]
     writer.header.writeln("#ifndef %s" % src)
     writer.header.writeln("#define %s" % src)
+    writer.header.newline()
+    writer.header.writeln("SPICE_BEGIN_DECLS")
+    writer.header.newline()
 
     writer.writeln("#include <string.h>")
     writer.writeln("#include <assert.h>")
@@ -345,6 +348,7 @@ def write_container_marshaller(writer, container, src):
 def write_message_marshaller(writer, message, private):
     if message.has_attr("ifdef"):
         writer.ifdef(message.attributes["ifdef"][0])
+        writer.header.ifdef(message.attributes["ifdef"][0])
     writer.out_prefix = ""
     function_name = "spice_marshall_" + message.c_name()
     if writer.is_generated("marshaller", function_name):
@@ -357,7 +361,15 @@ def write_message_marshaller(writer, message, private):
         n = [", SpiceMarshaller **%s_out" % name for name in names]
         names_args = "".join(n)
 
-    if not private:
+    if private:
+        message_name = message.c_name()
+        if (not message_name.startswith("msgc_")):
+            #small bug above, checks for startswith("msg") which
+            #matches "msgc" and appends "msg_" if this fails causing
+            #inconsistencies
+            message_name = "msg_" + message_name
+        writer.header.writeln("void (*" + message_name + ")(SpiceMarshaller *m, %s *msg" % message.c_type() + names_args + ");")
+    else:
         writer.header.writeln("void " + function_name + "(SpiceMarshaller *m, %s *msg" % message.c_type() + names_args + ");")
 
     scope = writer.function(function_name,
@@ -378,11 +390,15 @@ def write_message_marshaller(writer, message, private):
     writer.end_block()
     if message.has_attr("ifdef"):
         writer.endif(message.attributes["ifdef"][0])
+        writer.header.endif(message.attributes["ifdef"][0])
+
     writer.newline()
     return function_name
 
 def write_protocol_marshaller(writer, proto, is_server, private_marshallers):
     functions = {}
+    if private_marshallers:
+        writer.header.begin_block("typedef struct")
     for c in proto.channels:
         channel = c.channel_type
         if channel.has_attr("ifdef"):
@@ -406,6 +422,12 @@ def write_protocol_marshaller(writer, proto, is_server, private_marshallers):
             writer.header.endif(channel.attributes["ifdef"][0])
 
     if private_marshallers:
+        writer.header.end_block(newline=False)
+        writer.header.writeln(" SpiceMessageMarshallers;")
+        writer.header.newline()
+        writer.header.statement("SpiceMessageMarshallers *spice_message_marshallers_get" + writer.public_prefix+"(void)")
+        writer.header.newline()
+
         scope = writer.function("spice_message_marshallers_get" +  writer.public_prefix,
                                 "SpiceMessageMarshallers *",
                                 "void")
@@ -426,4 +448,8 @@ def write_protocol_marshaller(writer, proto, is_server, private_marshallers):
         writer.newline()
 
 def write_trailer(writer):
+    writer.header.newline()
+    writer.header.writeln("SPICE_END_DECLS")
+    writer.header.newline()
+
     writer.header.writeln("#endif")
commit 0eb567e6fb41ce4bf6d6b6bfdd113091cb2c72f0
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Thu Jun 23 12:57:17 2016 +0200

    codegen: Improve header guard generation
    
    Until now, the same header guard was used for all generated .h files.
    Now the header guard name is based on the name of the file being
    generated so that it's different for each .h file.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
    Acked-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/python_modules/marshal.py b/python_modules/marshal.py
index cc6cbdf..dc36e18 100644
--- a/python_modules/marshal.py
+++ b/python_modules/marshal.py
@@ -1,13 +1,22 @@
 
 from . import ptypes
 from . import codegen
+import re
 
 def write_includes(writer):
     writer.header.writeln("#include <spice/protocol.h>")
     writer.header.writeln('#include "common/marshaller.h"')
     writer.header.newline()
-    writer.header.writeln("#ifndef _GENERATED_HEADERS_H")
-    writer.header.writeln("#define _GENERATED_HEADERS_H")
+    if writer.header.has_option("dest_file"):
+        src = writer.header.options["dest_file"]
+    else:
+        src = "generated_headers.h"
+    src = re.sub(r'[^a-z0-9]+', '_', src, flags=re.IGNORECASE)
+    src = src.upper()
+    if src.endswith("_H"):
+        src = "_H_"+src[:-2]
+    writer.header.writeln("#ifndef %s" % src)
+    writer.header.writeln("#define %s" % src)
 
     writer.writeln("#include <string.h>")
     writer.writeln("#include <assert.h>")
diff --git a/spice_codegen.py b/spice_codegen.py
index c019ad8..410acbd 100755
--- a/spice_codegen.py
+++ b/spice_codegen.py
@@ -170,6 +170,7 @@ if proto == None:
 codegen.set_prefix(proto.name)
 writer = codegen.CodeWriter()
 writer.header = codegen.CodeWriter()
+writer.header.set_option("dest_file", dest_file)
 writer.set_option("source", os.path.basename(proto_file))
 
 license = """/*


More information about the Spice-commits mailing list