[Vala] Writing bindings as legacy



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.




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