[cogl/wip/cogl-sharp: 51/51] cogl-sharp: Support generation of functions with a CoglError
- From: Damien Lespiau <dlespiau src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cogl/wip/cogl-sharp: 51/51] cogl-sharp: Support generation of functions with a CoglError
- Date: Sat, 5 Jan 2013 16:52:34 +0000 (UTC)
commit 1b6450f8460c970b244112fb1846201278747582
Author: Damien Lespiau <damien lespiau intel com>
Date: Sat Jan 5 16:37:24 2013 +0000
cogl-sharp: Support generation of functions with a CoglError
These functions throw a Cogl.Exception in the C# sharp versions and the
mechanisms in C (boolean return value and CoglError** argument) are
dropped.
cogl-sharp/_FrameBuffer.cs | 12 +++++++++
cogl-sharp/_Pipeline.cs | 12 +++++++++
cogl-sharp/parse-gir.py | 55 ++++++++++++++++++++++++++++++++++++-------
3 files changed, 70 insertions(+), 9 deletions(-)
---
diff --git a/cogl-sharp/_FrameBuffer.cs b/cogl-sharp/_FrameBuffer.cs
index 247d839..0c1b559 100644
--- a/cogl-sharp/_FrameBuffer.cs
+++ b/cogl-sharp/_FrameBuffer.cs
@@ -7,6 +7,18 @@ namespace Cogl
public partial class FrameBuffer
{
[DllImport("cogl2.dll")]
+ public static extern bool cogl_framebuffer_allocate(IntPtr o, out IntPtr error);
+
+ public void Allocate()
+ {
+ IntPtr error;
+
+ cogl_framebuffer_allocate(handle, out error);
+ if (error != IntPtr.Zero)
+ throw new Cogl.Exception(error);
+ }
+
+ [DllImport("cogl2.dll")]
public static extern void cogl_framebuffer_clear(IntPtr o, BufferBit buffers, ref Color color);
public void Clear(BufferBit buffers, ref Color color)
diff --git a/cogl-sharp/_Pipeline.cs b/cogl-sharp/_Pipeline.cs
index ef6e957..b0c82f4 100644
--- a/cogl-sharp/_Pipeline.cs
+++ b/cogl-sharp/_Pipeline.cs
@@ -217,6 +217,18 @@ namespace Cogl
}
[DllImport("cogl2.dll")]
+ public static extern bool cogl_pipeline_set_layer_point_sprite_coords_enabled(IntPtr o, int layer_index, bool enable, out IntPtr error);
+
+ public void SetLayerPointSpriteCoordsEnabled(int layer_index, bool enable)
+ {
+ IntPtr error;
+
+ cogl_pipeline_set_layer_point_sprite_coords_enabled(handle, layer_index, enable, out error);
+ if (error != IntPtr.Zero)
+ throw new Cogl.Exception(error);
+ }
+
+ [DllImport("cogl2.dll")]
public static extern void cogl_pipeline_set_layer_texture(IntPtr o, int layer_index, IntPtr texture);
public void SetLayerTexture(int layer_index, Texture texture)
diff --git a/cogl-sharp/parse-gir.py b/cogl-sharp/parse-gir.py
index abc0d30..86a8af8 100755
--- a/cogl-sharp/parse-gir.py
+++ b/cogl-sharp/parse-gir.py
@@ -249,8 +249,9 @@ def is_handwritten(gir_name, overrides):
return gir_name in overrides['handwritten']
def generate_method(node, overrides, fo):
- gir_name = node.getAttribute("name")
+ throw_exception = False
+ gir_name = node.getAttribute("name")
gir_name = apply_name_override(gir_name, overrides)
native_method_name = node.getAttributeNS(C_NS, "identifier")
@@ -301,7 +302,8 @@ def generate_method(node, overrides, fo):
params = params_list.getElementsByTagName("parameter")
for param in params:
direction = param.getAttribute("direction")
- if direction == 'out':
+ out = direction == 'out'
+ if out:
print(" Skipping %s, out parameters not supported yet" %
(cs_method_name))
generatable = False
@@ -311,7 +313,11 @@ def generate_method(node, overrides, fo):
assert len(param_type) == 1
c_type = param_type.item(0).getAttributeNS(C_NS, "type")
gir_type = param_type.item(0).getAttribute("name")
- if not known_type(gir_type):
+ # mark methods throwing exceptions
+ if c_type == 'CoglError**':
+ throw_exception = True
+ out = True
+ elif not known_type(gir_type):
print(" Skipping %s, unknown parameter type '%s' (%s)" %
(cs_method_name, gir_type, c_type))
generatable = False
@@ -320,18 +326,32 @@ def generate_method(node, overrides, fo):
# time to update {native,cs}_params and call_params
param_name = param.getAttribute("name")
ref = 'ref ' if gir_type in struct_types else ''
+ out = 'out ' if out else ''
t = derive_native_type(gir_type, c_type)
- native_params.append(ref + t + ' ' + param_name)
+ native_params.append(ref + out + t + ' ' + param_name)
+
+ handle = '.Handle' if gir_type in object_types else ''
+ call_params.append(ref + out + param_name + handle)
+
+ # if we are throwing an exception then:
+ # 1. we don't want to mirror the exception argument in the C#
+ # wrapper so we skip the cs_param update
+ # 2. we can safely break the loop as exception are always the
+ # last parameter
+ if throw_exception:
+ break
t = derive_cs_type(gir_type, c_type)
cs_params.append(ref + t + ' ' + param_name)
- handle = '.Handle' if gir_type in object_types else ''
- call_params.append(ref + param_name + handle)
-
if not generatable:
return
+ # We hide the returned boolean from functions that can return a CoglError
+ # to have a exception-only error handling
+ if throw_exception:
+ cs_return_value = 'void'
+
return_str = 'return ' if (cs_return_value != 'void') else ''
# native symbol declaration
@@ -341,7 +361,7 @@ def generate_method(node, overrides, fo):
# C# wrapper
#
- # We support 2 types of functions:
+ # We support 3 types of functions:
#
# 1. simple wrappers (can return values as well)
#
@@ -357,10 +377,27 @@ def generate_method(node, overrides, fo):
# IntPtr p = cogl_pipeline_get_layer_texture(handle, layer_index);
# return new Texture(p);
# }
+ #
+ # 3. functions returning a CoglError throw exceptions
+ #
+ # public void Allocate()
+ # {
+ # IntPtr error;
+ #
+ # cogl_framebuffer_allocate(handle, out error);
+ # if (error != IntPtr.Zero)
+ # throw new Cogl.Exception(error);
+ # }
fo.write(" public %s %s(%s)\n" %
(cs_return_value, cs_method_name, ", ".join(cs_params)))
fo.write(" {\n")
- if not return_object:
+ if throw_exception:
+ fo.write(" IntPtr error;\n\n")
+ fo.write(" %s(%s);\n" %
+ (native_method_name, ", ".join(call_params)))
+ fo.write(" if (error != IntPtr.Zero)\n")
+ fo.write(" throw new Cogl.Exception(error);\n")
+ elif not return_object:
fo.write(" %s%s(%s);\n" %
(return_str, native_method_name, ", ".join(call_params)))
else:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]