# Path: pyczmq/_cffi.py
# C = ffi.dlopen('czmq')
# Z = ffi.dlopen('zmq')
# def ptop(typ, val):
# def cdef(decl, returns_string=False, nullable=False):
#     def wrap(f):
#         def inner_f(*args):


from pyczmq._cffi import ffi, C, ptop, cdef


def poll_callback(f):
    @ffi.callback('zloop_fn')
    def handler(loop, item, arg):
        return f(loop, item, ffi.from_handle(arg))
    return handler


def timer_callback(f):
    @ffi.callback('zloop_timer_fn')
    def handler(loop, timer_id, arg):
        return f(loop, timer_id, ffi.from_handle(arg))
    return handler


def callback(f):
    @ffi.callback('zloop_fn')
    def handler(loop, item, arg):
        return f(loop, item, ffi.from_handle(arg))
    return handler


@cdef('void zloop_destroy (zloop_t **self_p);')
def destroy(loop):
    """
    Destroy a reactor, this is not necessary if you create it with
    new.
    """
    if loop is not ffi.NULL:

# Path: pyczmq/_cffi.py
# C = ffi.dlopen('czmq')
# Z = ffi.dlopen('zmq')
# def ptop(typ, val):
# def cdef(decl, returns_string=False, nullable=False):
#     def wrap(f):
#         def inner_f(*args):


# Path: pyczmq/zloop.py
from pyczmq._cffi import ffi, C, ptop, cdef



def poll_callback(f):
    @ffi.callback('zloop_fn')
    def handler(loop, item, arg):
        return f(loop, item, ffi.from_handle(arg))
    return handler


def timer_callback(f):
    @ffi.callback('zloop_timer_fn')
    def handler(loop, timer_id, arg):
        return f(loop, timer_id, ffi.from_handle(arg))
    return handler


def callback(f):
    @ffi.callback('zloop_fn')
    def handler(loop, item, arg):
        return f(loop, item, ffi.from_handle(arg))
    return handler


@cdef('void zloop_destroy (zloop_t **self_p);')
def destroy(loop):
    """
    Destroy a reactor, this is not necessary if you create it with
    new.
    """
    if loop is not ffi.NULL:

        C.zloop_destroy(ptop('zloop_t', loop))