[vala-extra-vapis] Completes bindings for libmemcached.vapi.



commit e4377e4300c5722243cca709dfec2c60ede966e9
Author: Guillaume Poirier-Morency <guillaumepoiriermorency gmail com>
Date:   Sun Jul 5 03:00:49 2015 -0400

    Completes bindings for libmemcached.vapi.
    
    Fixes fetch that return NULL if an error occured.
    
    Posix is required as the 'memcached_stat_st' struct has a 'pid_t'
    attribute.
    
    Finishes the bindings for 'result.h' and cleans the wrapper code.
    
    Defines ulonglong IntegerType to produce 'unsigned long long' for the
    stats struct.
    
    dump, fetch_execute, mget_execute and mget_execute_by_key take a
    sequence of callback and expect a void* context to be passed. As this is
    not supported by Vala (multiple delegates sharing the same context), it
    is bound by:
    
     - using a ref on a single function (generates a pointer on a function)
     - use a wrapper with a owned function that set the number of callbacks
       to '1'

 libmemcached.deps |    1 +
 libmemcached.vapi |  334 +++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 315 insertions(+), 20 deletions(-)
---
diff --git a/libmemcached.deps b/libmemcached.deps
new file mode 100644
index 0000000..b3188f7
--- /dev/null
+++ b/libmemcached.deps
@@ -0,0 +1 @@
+posix
diff --git a/libmemcached.vapi b/libmemcached.vapi
index 7231918..0dcf406 100644
--- a/libmemcached.vapi
+++ b/libmemcached.vapi
@@ -25,12 +25,69 @@
 [CCode (cheader_filename = "libmemcached/memcached.h")]
 namespace Memcached {
 
+  // defaults.h
   public const in_port_t DEFAULT_PORT;
+  public const string    DEFAULT_PORT_STRING;
+  public const uint      POINTS_PER_SERVER;
+  public const uint      POINTS_PER_SERVER_KETAMA;
+  public const uint      CONTINUUM_SIZE;
+  public const uint      STRIDE;
+  public const uint      DEFAULT_TIMEOUT;
+  public const uint      DEFAULT_CONNECT_TIMEOUT;
+  public const uint      CONTINUUM_ADDITION;
+  public const uint      EXPIRATION_NOT_ADD;
+  public const uint      SERVER_FAILURE_LIMIT;
+  public const uint      SERVER_FAILURE_RETRY_TIMEOUT;
+  public const uint      SERVER_FAILURE_DEAD_TIMEOUT;
+  public const uint      SERVER_TIMEOUT_LIMIT;
+
+  // limits.h
+  public const uint   MAXIMUM_INTEGER_DISPLAY_LENGTH;
+  public const uint   MAX_BUFFER;
+  public const uint   MAX_HOST_SORT_LENGTH;
+  public const uint   MAX_KEY;
+  public const uint   PREFIX_KEY_MAX_SIZE;
+  public const size_t VERSION_STRING_LENGTH;
+
+  public const string CALLBACK_PREFIX_KEY;
+
+  // alloc.h
+  public delegate void FreeFunc (Memcached.Context ptr, void* mem);
+  public delegate void* MallocFunc (Memcached.Context ptr, size_t size);
+  public delegate void* ReallocFunc (Memcached.Context ptr, void* mem, size_t size);
+  public delegate void* CallocFunc (Memcached.Context ptr, size_t nelem, size_t elsize);
+
+  // callbacks.h
+  [CCode (cname = "memcached_execute_fn")]
+  public delegate Memcached.ReturnCode ExecuteCallback (Memcached.Context ptr, Memcached.Result result);
+  [CCode (cname = "memcached_server_fn")]
+  public delegate Memcached.ReturnCode ServerCallback (Memcached.Context ptr, Memcached.Instance server);
+  [CCode (cname = "memcached_stat_fn")]
+  public delegate Memcached.ReturnCode StatCallback (Memcached.Instance server, [CCode (array_length_type = 
"size_t")] uint8[] key, [CCode (array_length_type = "size_t")] uint8[] value);
+
+  // triggers.h
+  [CCode (cname = "memcached_clone_fn", has_target = false)]
+  public delegate Memcached.ReturnCode CloneFunc (Memcached.Context destination, Memcached.Context source);
+  [CCode (cname = "memcached_cleanup_fn", has_target = false)]
+  public delegate Memcached.ReturnCode CleanupFunc (Memcached.Context ptr);
+  [CCode (cname = "memcached_trigger_key_fn", has_target = false)]
+  public delegate Memcached.ReturnCode KeyTrigger (Memcached.Context ptr, [CCode (array_length_type = 
"size_t")] uint8[] key, Memcached.Result result);
+  [CCode (cname = "memcached_trigger_delete_key_fn", has_target = false)]
+  public delegate Memcached.ReturnCode DeleteKeyTrigger (Memcached.Context ptr, [CCode (array_length_type = 
"size_t")] uint8[] key);
+  [CCode (cname = "memcached_dump_fn", has_target = false)]
+  public delegate Memcached.ReturnCode DumpCallback (Memcached.Context ptr, [CCode (array_length_type = 
"size_t")] uint8[] key);
 
   [SimpleType]
   [IntegerType (rank = 6), CCode (cname = "in_port_t")]
   public struct in_port_t {}
 
+  [SimpleType]
+  [IntegerType (rank = 11), CCode (cname = "unsigned long long")]
+  public struct ulonglong {}
+
+  // version.h
+  public string lib_version ();
+
   [Compact, CCode (cname = "memcached_st", has_type_id = false, lower_case_cprefix = "memcached_")]
   public class Context {
     // memcached.h
@@ -52,20 +109,53 @@ namespace Memcached {
     public uint32 server_count ();
     public uint64 query_id ();
 
+    // allocators.h
+    public Memcached.ReturnCode set_memory_allocator (MallocFunc mem_malloc, FreeFunc mem_free, ReallocFunc 
mem_realloc, CallocFunc mem_calloc);
+    public void get_memory_allocator (out MallocFunc mem_malloc, out FreeFunc mem_free, out ReallocFunc 
mem_realloc, out CallocFunc mem_calloc);
+    public void* get_memory_allocator_context ();
+
+    // analyze.h
+    public Memcached.Analysis analyze (Memcached.Stat memc_stat, out Memcached.ReturnCode error);
+
     // auto.h
     public Memcached.ReturnCode increment ([CCode (array_length_type = "size_t")] uint8[] key, uint32 
offset, out uint64 value);
-    public Memcached.ReturnCode increment_by_key ([CCode (array_length_type = "size_t")] uint8[] group_key, 
[CCode (array_length_type = "size_t")] uint8[] key, uint64 offset, out uint64 value);
-    public Memcached.ReturnCode increment_with_initial ([CCode (array_length_type = "size_t")] uint8[] key, 
uint64 offset, uint64 initial, time_t expiration, out uint64 value);
-    public Memcached.ReturnCode increment_with_initial_by_key ([CCode (array_length_type = "size_t")] 
uint8[] group_key, [CCode (array_length_type = "size_t")] uint8[] key, uint64 offset, uint64 initial, time_t 
expiration, out uint64 value);
     public Memcached.ReturnCode decrement ([CCode (array_length_type = "size_t")] uint8[] key, uint32 
offset, out uint64 value);
+    public Memcached.ReturnCode increment_by_key ([CCode (array_length_type = "size_t")] uint8[] group_key, 
[CCode (array_length_type = "size_t")] uint8[] key, uint64 offset, out uint64 value);
     public Memcached.ReturnCode decrement_by_key ([CCode (array_length_type = "size_t")] uint8[] group_key, 
[CCode (array_length_type = "size_t")] uint8[] key, uint64 offset, out uint64 value);
+    public Memcached.ReturnCode increment_with_initial ([CCode (array_length_type = "size_t")] uint8[] key, 
uint64 offset, uint64 initial, time_t expiration, out uint64 value);
     public Memcached.ReturnCode decrement_with_initial ([CCode (array_length_type = "size_t")] uint8[] key, 
uint64 offset, uint64 initial, time_t expiration, out uint64 value);
+    public Memcached.ReturnCode increment_with_initial_by_key ([CCode (array_length_type = "size_t")] 
uint8[] group_key, [CCode (array_length_type = "size_t")] uint8[] key, uint64 offset, uint64 initial, time_t 
expiration, out uint64 value);
     public Memcached.ReturnCode decrement_with_initial_by_key ([CCode (array_length_type = "size_t")] 
uint8[] group_key, [CCode (array_length_type = "size_t")] uint8[] key, uint64 offset, uint64 initial, time_t 
expiration, out uint64 value);
 
+    // behavior.h
+    public Memcached.ReturnCode behavior_set (Memcached.Behavior flag, uint64 data);
+    public uint64 behavior_get (Memcached.Behavior flag);
+    public Memcached.ReturnCode behavior_set_distribution (Memcached.ServerDistribution type);
+    public Memcached.ServerDistribution behavior_get_distribution ();
+    public Memcached.ReturnCode set_key_hash (Memcached.Hash type);
+    public Memcached.Hash get_key_hash ();
+    public Memcached.ReturnCode set_distribution_hash (Memcached.Hash type);
+    public Memcached.Hash get_distribution_hash ();
+    public Memcached.ReturnCode bucket_set (uint32[] host_map, uint32[] forward_map, uint32 buckets, uint32 
replicas);
+
+    // callback.h
+    public Memcached.ReturnCode callback_set<T> (Memcached.Callback flag, T data);
+    public T callback_get<T> (Memcached.Callback flag, out Memcached.ReturnCode error);
+
     // delete.h
     public Memcached.ReturnCode @delete ([CCode (array_length_type = "size_t")] uint8[] key, time_t 
expiration);
     public Memcached.ReturnCode delete_by_key ([CCode (array_length_type = "size_t")] uint8[] group_key, 
[CCode (array_length_type = "size_t")] uint8[] key, time_t expiration);
 
+    // dump.h
+    [CCode (cname = "memcached_dump")]
+    private Memcached.ReturnCode _dump (ref Memcached.DumpCallback function, uint32 number_of_callbacks);
+    public Memcached.ReturnCode dump (owned Memcached.DumpCallback function) {
+      return this._dump (ref function, 1);
+    }
+
+    // encoding_key.h
+    public Memcached.ReturnCode set_encoding_key ([CCode (array_length_type = "size_t")] uint8[] str);
+
     // error.h
     public unowned string error ();
     public unowned string last_error_message ();
@@ -77,6 +167,13 @@ namespace Memcached {
     public Memcached.ReturnCode exist ([CCode (array_length_type = "size_t")] uint8[] key);
     public Memcached.ReturnCode exist_by_key ([CCode (array_length_type = "size_t")] uint8[] group_key, 
[CCode (array_length_type = "size_t")] uint8[] key);
 
+    // fetch.h
+    [CCode (cname = "memcached_fetch_execute")]
+    private Memcached.ReturnCode _fetch_execute (ref Memcached.ExecuteCallback callback, uint32 
number_of_callbacks);
+    public Memcached.ReturnCode fetch_execute (owned Memcached.ExecuteCallback callback) {
+      return this._fetch_execute (ref callback, 1);
+    }
+
     // flush_buffers.h
     public Memcached.ReturnCode flush_buffers ();
 
@@ -89,8 +186,42 @@ namespace Memcached {
     public Memcached.ReturnCode mget ([CCode (array_length_type = "size_t", array_length_pos = 2.5)] 
uint8*[] keys, [CCode (array_length = false)] size_t[] keys_length);
     [CCode (array_length_pos = 2.5, array_length_type = "size_t")]
     public uint8[]? get_by_key ([CCode (array_length_type = "size_t")] uint8[] group_key, [CCode 
(array_length_type = "size_t")] uint8[] key, out uint32 flags, out Memcached.ReturnCode error);
+    public Memcached.ReturnCode mget_by_key ([CCode (array_length_type = "size_t")] uint8[] group_key, 
[CCode (array_length_type = "size_t", array_length_pos = 3.5)] uint8*[] keys, [CCode (array_length = false)] 
size_t[] keys_length);
+    [Deprecated (since = "0.50", replacement = "fetch_result"), CCode (array_length_pos = 1.5, 
array_length_type = "size_t")]
+    public uint8[]? fetch ([CCode (array_length_type = "size_t")] uint8[] key, out uint32 flags, out 
Memcached.ReturnCode error);
+    public Memcached.Result? fetch_result (Memcached.Result? result, out Memcached.ReturnCode error);
+    [CCode (cname = "memcached_mget_execute")]
+    private Memcached.ReturnCode _mget_execute ([CCode (array_length_type = "size_t", array_length_pos = 
2.5)] uint8*[] keys, [CCode (array_length = false)] size_t[] keys_length, ref Memcached.ExecuteCallback 
function, uint32 number_of_callbacks = 1);
+    public Memcached.ReturnCode mget_execute (uint8*[] keys, size_t[] keys_length, owned 
Memcached.ExecuteCallback function) {
+      return this._mget_execute (keys, keys_length, ref function, 1);
+    }
+    public Memcached.ReturnCode _mget_execute_by_key ([CCode (array_length_type = "size_t")] uint8[] 
group_key, [CCode (array_length_type = "size_t", array_length_pos = 3.5)] uint8*[] keys, [CCode (array_length 
= false)] size_t[] keys_length, ref Memcached.ExecuteCallback function, uint32 number_of_callbacks = 1);
+    public Memcached.ReturnCode mget_execute_by_key (uint8[] group_key, uint8*[] keys, size_t[] keys_length, 
owned Memcached.ExecuteCallback function) {
+      return this._mget_execute_by_key (group_key, keys, keys_length, ref function, 1);
+    }
+
+    // hash.h
+    public uint32 generate_hash_value ([CCode (array_length_type = "size_t")] uint8[] key, Memcached.Hash 
hash_algorithm);
+    public uint32 generate_hash ([CCode (array_length_type = "size_t")] uint8[] key);
+    public void autoeject ();
+
+    // options.h
+    [CCode (cname = "libmemcached_check_configuration")]
+    public Memcached.ReturnCode check_configuration ([CCode (array_length_type = "size_t")] uint8[] 
option_string, [CCode (array_length_type = "size_t")] uint8[] error_buffer);
+
+    // result.h
+    public Memcached.Result result_create (Memcached.Result? result = null);
+
+    // sasl.h
+    public Memcached.ReturnCode set_sasl_auth_data (string username, string password);
+    public Memcached.ReturnCode destroy_sasl_auth_data ();
 
     // server.h
+    [CCode (cname = "memcached_server_cursor")]
+    private Memcached.ReturnCode _server_cursor (ref Memcached.ServerCallback function, uint32 
number_of_callbacks);
+    public Memcached.ReturnCode server_cursor (owned Memcached.ServerCallback function) {
+      return this._server_cursor (ref function, 1);
+    }
     public Memcached.Instance server_by_key ([CCode (array_length_type = "size_t")] uint8[] key, out 
Memcached.ReturnCode error);
     public Memcached.Instance server_get_last_disconnected ();
     public Memcached.ReturnCode server_add_udp (string hostname, in_port_t port = Memcached.DEFAULT_PORT);
@@ -103,6 +234,13 @@ namespace Memcached {
     // server_list.h
     public Memcached.ReturnCode server_push (Memcached.ServerList list);
 
+    // stat.h
+    public void stat_free (Memcached.Stat memc_stat);
+    public Memcached.Stat stat (string args, out Memcached.ReturnCode error);
+    public string stat_get_value (Memcached.Stat memc_stat, out Memcached.ReturnCode error);
+    public string[] stat_get_keys (Memcached.Stat memc_stat, out Memcached.ReturnCode error);
+    public Memcached.ReturnCode stat_execute (string args, Memcached.StatCallback func);
+
     // storage.h
     public Memcached.ReturnCode @set ([CCode (array_length_type = "size_t")] uint8[] key, [CCode 
(array_length_type = "size_t")] uint8[] value, time_t expiration, uint32 flags);
     public Memcached.ReturnCode add ([CCode (array_length_type = "size_t")] uint8[] key, [CCode 
(array_length_type = "size_t")] uint8[] value, time_t expiration, uint32 flags);
@@ -125,34 +263,142 @@ namespace Memcached {
 
     // quit.h
     public void quit ();
+
+    // verbosity.h
+    public Memcached.ReturnCode verbosity (uint32 verbosity);
+
+    // version.h
+    public Memcached.ReturnCode version ();
+  }
+
+  // type/analysis.h
+  [SimpleType, CCode (cname = "memcached_analysis_st", free_function = "memcached_analyze_free")]
+  public struct Analysis {
+    public Memcached.Context root;
+    public uint32 average_item_size;
+    public uint32 longest_uptime;
+    public uint32 least_free_server;
+    public uint32 most_consumed_server;
+    public uint32 oldest_server;
+    public double pool_hit_ratio;
+    public uint64 most_used_bytes;
+    public uint64 least_remaining_bytes;
   }
 
   // result.h
-  [Compact]
+  [Compact, CCode (cname = "memcached_result_st")]
   public class Result {
-    [CCode (array_length = false)]
-    private unowned uint8[] key_value ();
+    public void reset ();
+    [CCode (cname = "memcached_result_key_value", array_length = false)]
+    private unowned uint8[] _key_value ();
     private size_t key_length ();
-    [CCode (cname = "_vala_memcached_result_key")]
-    public unowned uint8[] key () {
-      unowned uint8[] k = this.key_value ();
-      k.length = (int) this.key_length ();
-      return k;
+    [CCode (cname = "memcached_result_key_value_wrapper")]
+    public unowned uint8[] key_value () {
+        unowned uint8[] key    = this._key_value ();
+        key.length = (int) this.key_length ();
+        return key;
     }
-
     [CCode (cname = "memcached_result_value", array_length = false)]
-    private unowned uint8[] value_value ();
-    [CCode (cname = "memcached_result_length")]
-    private size_t value_length ();
-    [CCode (cname = "_vala_memcached_result_value")]
+    private unowned uint8[] _value ();
+    [CCode (cname = "memcached_result_take_value", array_length = false)]
+    private uint8[] _take_value ();
+    private size_t length ();
+    [CCode (cname = "memcached_result_value_wrapper")]
     public unowned uint8[] value () {
-      unowned uint8[] v = this.value_value ();
-      v.length = (int) this.value_length ();
-      return v;
+        unowned uint8[] val = this._value ();
+        val.length          = (int) this.length ();
+        return val;
+    }
+    [CCode (cname = "memcached_result_take_value_wrapper")]
+    public uint8[] take_value () {
+        var val    = this._take_value ();
+        val.length = (int) this.length ();
+        return val;
     }
-
     public uint32 flags ();
     public uint64 cas ();
+    public Memcached.ReturnCode set_value (uint8[] value);
+    public void set_flags (uint32 flags);
+    public void set_expiration (time_t expiration);
+  }
+
+  // types/behavior.h
+  [CCode (cname = "memcached_behavior_t")]
+  public enum Behavior {
+    NO_BLOCK,
+    TCP_NODELAY,
+    HASH,
+    KETAMA,
+    SOCKET_SEND_SIZE,
+    SOCKET_RECV_SIZE,
+    CACHE_LOOKUPS,
+    SUPPORT_CAS,
+    POLL_TIMEOUT,
+    DISTRIBUTION,
+    BUFFER_REQUESTS,
+    USER_DATA,
+    SORT_HOSTS,
+    VERIFY_KEY,
+    CONNECT_TIMEOUT,
+    RETRY_TIMEOUT,
+    KETAMA_WEIGHTED,
+    KETAMA_HASH,
+    BINARY_PROTOCOL,
+    SND_TIMEOUT,
+    RCV_TIMEOUT,
+    SERVER_FAILURE_LIMIT,
+    IO_MSG_WATERMARK,
+    IO_BYTES_WATERMARK,
+    IO_KEY_PREFETCH,
+    HASH_WITH_PREFIX_KEY,
+    NOREPLY,
+    USE_UDP,
+    AUTO_EJECT_HOSTS,
+    NUMBER_OF_REPLICAS,
+    RANDOMIZE_REPLICA_READ,
+    CORK,
+    TCP_KEEPALIVE,
+    TCP_KEEPIDLE,
+    LOAD_FROM_FILE,
+    REMOVE_FAILED_SERVERS,
+    DEAD_TIMEOUT,
+    SERVER_TIMEOUT_LIMIT,
+    MAX;
+
+    // behavior.h
+    [CCode (cname = "libmemcached_string_behavior")]
+    public string to_string ();
+  }
+
+  // types/callback.h
+  [CCode (cname = "memcached_callback_t")]
+  public enum Callback {
+    PREFIX_KEY       = 0,
+    USER_DATA        = 1,
+    CLEANUP_FUNCTION = 2,
+    CLONE_FUNCTION   = 3,
+    GET_FAILURE      = 7,
+    DELETE_TRIGGER   = 8,
+    MAX,
+    NAMESPACE        = Memcached.CALLBACK_PREFIX_KEY
+  }
+
+  // types/hash.h
+  [CCode (cname = "memcached_hash_t")]
+  public enum Hash {
+    DEFAULT,
+    MD5,
+    CRC,
+    FNV1_64,
+    FNV1A_64,
+    FNV1_32,
+    FNV1A_32,
+    HSIES,
+    MURMUR,
+    JENKINS,
+    MURMUR3,
+    CUSTOM,
+    MAX
   }
 
   // return.h
@@ -210,6 +456,23 @@ namespace Memcached {
     public bool fatal ();
   }
 
+  // types/server_distribution.h
+  [CCode (cname = "memcached_server_distribution_t", cprefix = "MEMCACHED_DISTRIBUTION_")]
+  public enum ServerDistribution {
+    MODULA,
+    CONSISTENT,
+    CONSISTENT_KETAMA,
+    RANDOM,
+    CONSISTENT_KETAMA_SPY,
+    CONSISTENT_WEIGHTED,
+    VIRTUAL_BUCKET,
+    CONSISTENT_MAX;
+
+    // behavior.h
+    [CCode (cname = "libmemcached_string_distribution")]
+    public string to_string ();
+  }
+
   // parse.h
   public Memcached.ServerList servers_parse (string server_strings);
 
@@ -238,4 +501,35 @@ namespace Memcached {
     public Memcached.ServerList append_with_weight (string hostname, in_port_t port, uint32 weight, out 
Memcached.ReturnCode error);
     public uint32 count ();
   }
+
+  // stat.h
+  [CCode (cname = "memcached_stat_st")]
+  public struct Stat {
+    ulong connection_structures;
+    ulong curr_connections;
+    ulong curr_items;
+    Posix.pid_t pid;
+    ulong pointer_size;
+    ulong rusage_system_microseconds;
+    ulong rusage_system_seconds;
+    ulong rusage_user_microseconds;
+    ulong rusage_user_seconds;
+    ulong threads;
+    ulong time;
+    ulong total_connections;
+    ulong total_items;
+    ulong uptime;
+    ulonglong bytes;
+    ulonglong bytes_read;
+    ulonglong bytes_written;
+    ulonglong cmd_get;
+    ulonglong cmd_set;
+    ulonglong evictions;
+    ulonglong get_hits;
+    ulonglong get_misses;
+    ulonglong limit_maxbytes;
+    uint8 version[Memcached.VERSION_STRING_LENGTH];
+    void* __future;
+    Memcached.Context root;
+  }
 }


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