diff options
author | Rob Taylor <rob.taylor@codethink.co.uk> | 2009-02-03 22:53:39 +0000 |
---|---|---|
committer | Rob Taylor <rob.taylor@codethink.co.uk> | 2009-02-03 22:53:39 +0000 |
commit | 3b6a845e0cc8c8b5cd18cdb40aa5cdfa3f1e42e6 (patch) | |
tree | 1cf90965d219b49047e90067410f642e76eb268e /python | |
parent | d1b4ef3452abe1d59e2bf3247238f285faf13c64 (diff) |
Bind StringSet, test calbacks in python binding
Diffstat (limited to 'python')
-rw-r--r-- | python/ContextProvider.py | 77 |
1 files changed, 69 insertions, 8 deletions
diff --git a/python/ContextProvider.py b/python/ContextProvider.py index d897592b..f0a2ffdd 100644 --- a/python/ContextProvider.py +++ b/python/ContextProvider.py @@ -2,6 +2,8 @@ from ctypes import * from CTypesHelpers import * +_dll = CDLL("libcontextprovider.so") + class STRING_SET(c_void_p): pass @@ -9,19 +11,17 @@ class CHANGE_SET(c_void_p): pass class ContextProvider: - _dll = CDLL("libcontextprovider.so") - STRING_ARRAY = POINTER(c_char_p) - GET_CALLBACK = POINTER(CFUNCTYPE(STRING_SET, CHANGE_SET, c_void_p)) - SUBSCRIBE_CALLBACK = POINTER(CFUNCTYPE(STRING_SET, c_void_p)) + GET_CALLBACK = CFUNCTYPE(STRING_SET, CHANGE_SET, c_void_p) + SUBSCRIBE_CALLBACK = CFUNCTYPE(STRING_SET, c_void_p) init = cfunc('context_provider_init', _dll, None, ('provided_keys', ListPOINTER (c_char_p), 1), ('useSessionBus', c_int, 1), - ('get_cb', GET_CALLBACK, 1), + ('get_cb', POINTER(GET_CALLBACK), 1), ('get_cb_target', c_void_p, 1), - ('first_cb', SUBSCRIBE_CALLBACK, 1), + ('first_cb', POINTER(SUBSCRIBE_CALLBACK), 1), ('first_cb_target', c_void_p, 1), - ('last_cb', SUBSCRIBE_CALLBACK, 1), + ('last_cb', POINTER(SUBSCRIBE_CALLBACK), 1), ('last_cb_target', c_void_p, 1)) no_of_subscribers = cfunc('context_provider_no_of_subscribers', _dll, c_int, ('key', c_char_p, 1)) @@ -44,6 +44,55 @@ class ContextProvider: ('change_set', CHANGE_SET, 1), ('key', c_char_p, 1)) +class StringSet: + + new = cfunc('context_provider_string_set_new', _dll, STRING_SET) + new_sized = cfunc('context_provider_string_set_new_sized', _dll, STRING_SET, + ('size', c_int, 1)) + new_from_array = cfunc('context_provider_string_set_new_from_array', _dll, STRING_SET, + ('array', ListPOINTER(c_char_p), 1), + ('length', c_int, 1)) + new_intersection = cfunc('context_provider_string_set_new_intersection', _dll, STRING_SET, + ('left', STRING_SET, 1), + ('right', STRING_SET, 1)) + new_symmetric_difference = cfunc('context_provider_string_set_new_symmetric_difference', _dll, STRING_SET, + ('left', STRING_SET, 1), + ('right', STRING_SET, 1)) + new_difference = cfunc('context_provider_string_set_new_difference', _dll, STRING_SET, + ('left', STRING_SET, 1), + ('right', STRING_SET, 1)) + new_union = cfunc('context_provider_string_set_new_union', _dll, STRING_SET, + ('left', STRING_SET, 1), + ('right', STRING_SET, 1)) + add = cfunc('context_provider_string_set_add', _dll, None, + ('self', STRING_SET, 1), + ('element', c_char_p, 1)) + remove = cfunc('context_provider_string_set_remove', _dll, c_int, + ('self', STRING_SET, 1), + ('element', c_char_p, 1)) + clear = cfunc('context_provider_string_set_clear', _dll, None, + ('self', STRING_SET, 1)) + is_member = cfunc('context_provider_string_set_is_member', _dll, c_int, + ('self', STRING_SET, 1), + ('element', c_char_p, 1)) + is_equal = cfunc('context_provider_string_set_is_equal', _dll, c_int, + ('left', STRING_SET, 1), + ('right', STRING_SET, 1)) + is_subset = cfunc('context_provider_string_set_is_subset', _dll, c_int, + ('left', STRING_SET, 1), + ('right', STRING_SET, 1)) + is_disjoint = cfunc('context_provider_string_set_is_disjoint', _dll, c_int, + ('left', STRING_SET, 1), + ('right', STRING_SET, 1)) + size = cfunc('context_provider_string_set_size', _dll, None, + ('self', STRING_SET, 1)) + debug = cfunc('context_provider_string_set_size', _dll, c_char_p, + ('self', STRING_SET, 1)) + ref = cfunc('context_provider_string_set_ref', _dll, c_char_p, + ('self', STRING_SET, 1)) + unref = cfunc('context_provider_string_set_unref', _dll, c_char_p, + ('self', STRING_SET, 1)) + if __name__ == "__main__": import gobject import dbus @@ -55,7 +104,18 @@ if __name__ == "__main__": busname = dbus.service.BusName("org.freedesktop.ContextKit.Testing.Provider", dbus.SessionBus()) - ContextProvider.init(["foo.bar", "foo.baz"], 1, None, None, None, None, None, None) + def get_cb (ss, cs, d): + print StringSet.debug(ss) + def first_cb (ss, d): + print StringSet.debug(ss) + def last_cb (ss, d): + print StringSet.debug(ss) + + + ContextProvider.init(["foo.bar", "foo.baz"], 1, + ContextProvider.GET_CALLBACK(get_cb), None, + ContextProvider.SUBSCRIBE_CALLBACK(first_cb), None, + ContextProvider.SUBSCRIBE_CALLBACK(last_cb), None) print ContextProvider.no_of_subscribers("foo.bar") cs = ContextProvider.change_set_create() ContextProvider.change_set_cancel(cs) @@ -63,4 +123,5 @@ if __name__ == "__main__": ContextProvider.change_set_add_int(cs2, "foo.bar", 1) ContextProvider.change_set_add_undetermined_key(cs2, "foo.baz") ContextProvider.change_set_commit(cs2) + loop.run() |