Re: [Vala] Writing bindings as legacy
- From: Andre Masella <andre masella name>
- To: Gonzalo Aguilar Delgado <gaguilar aguilardelgado com>
- Cc: Vala List <vala-list gnome org>
- Subject: Re: [Vala] Writing bindings as legacy
- Date: Sun, 23 Nov 2014 07:35:50 -0500
Why not something like this:
[CCode (cheader_filename = "rados/librados.h", cname = "rados_create2")]
public static int from_config (out ClusterClient? client, string?
cluster_name, string? user_name, Flags flags);
Vala will ensure `client` is null before calling this function, if the
result is a failure, `client` will be null. It's owned, so the
`rados_shutdown` will be called. If you want it to look like a return:
[CCode (cname="g_io_error_from_errno")]
private int _g_io_error_from_errno(int errno);
[CCode (cheader_filename = "rados/librados.h", cname = "rados_create2")]
private static int _from_config (out ClusterClient? client, string?
cluster_name, string? user_name, Flags flags);
public static ClusterClient? from_config(string? cluster_name, string?
user_name, Flags flags) throw GLib.IOError {
ClusterClient? result;
int code;
if ((code = _from_config(out result, cluster_name, user_name, flags)) <
0) {
throw new Error(IOError.quark(), _g_io_error_from_errno(-code), "%s",
GLib.strerror(-code));
}
return (owned) result;
}
This requires depending on gio-2.0.
Also, Flags should probably be an enum.
On 22 November 2014 at 18:01, Gonzalo Aguilar Delgado <
gaguilar aguilardelgado com> wrote:
Hi,
I my case (rados lib) I found non standard anyway and trying hard to
figure out how to do the binding. Maybe someone can help.
I managed to create some kind of working stuff but I think is not really
good with lot's of variable copying in generated code.
[ The problem ]
Rados want's a (void *) (formally rados_t) to be initialized on startup.
This is done with rados_create2 function:
int rados_create2(rados_t *pcluster, const char *const clustername,
const char * const name, uint64_t flags);
What I did is:
Map flags: (ok)
[SimpleType]
[IntegerType (rank = 11)]
[CCode (cname = "uint64_t", has_type_id = false)]
publicstruct Flags {
}
Create a cluster client:
[CCode (cheader_filename = "rados/librados.h", cname = "void",
free_function = "rados_shutdown", has_type_id = false)]
[Compact]
publicclass ClusterClient {
[CCode (cheader_filename = "rados/librados.h", cname =
"rados_create2")]
protectedstaticint create (ref unowned ClusterClient client, string?
cluster_name, string? user_name, Flags flags);
publicstatic unowned ClusterClient? from_config(string? cluster_name,
string? user_name, Flags flags) {
unowned ClusterClient result = null;
if(create(ref result, cluster_name, user_name, flags)<0){
result = null;
}
return result;
}
}
I code I do:
Rados.Flags flags=0;
unowned Rados.ClusterClient cluster = Rados.ClusterClient.from_config("ceph",
"client.admin", flags);
But this makes a lot of problems in code. And of course, not calling
rados_shutdown because unowned.
What I want is to do it in a way it's everything handled in the
constructor with no static method, but don't find how to do it.
What I really want to do is:
Rados.Flags flags=0;
Rados.ClusterClient cluster = Rados.ClusterClient("ceph", "client.admin",
flags);
And the result of the rados_create2 (first argument) being copied to
cluster var as instance object.
How should I do it?
Any help will be appreciated.
_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list
--
--Andre Masella<andre masella name>
http://www.masella.name/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]