Re: rep.ffi



On Sat, Aug 21, 2010 at 06:51:35PM +0200, Christopher Roy Bratusek wrote:
> does anyone of you have a clue on how to use rep.ffi?
You can look at attached "examples".  It was written by Sergey
Bolshakov, the person who wrote patch for rep.ffi.

-- 
Regards,    --
Sir Raorn.   --- http://thousandsofhate.blogspot.com/
#| util.jl -- FFI helpers

  Author: Sergey Bolshakov <sbolshakov altlinux ru>
  Version: $Id: util.jl,v 1.5 2006/07/16 19:40:32 me Exp $

  This file is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2, or (at your option)
  any later version.

  This file is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this file.  If not, write to the Free Software
  Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

|#

(define-structure rep.ffi.util

    (export ffi-bind
	    ffi-type-enum)

    (open rep
	  rep.ffi
	  rep.data.tables)

  (define (ffi-bind soname tab)
    (let ((handle (ffi-load-library soname))
	  (symtab (make-table symbol-hash eq-hash))
	  (ifacetab (make-table symbol-hash eq-hash)))
      (mapc
       (lambda (elt)
	 (apply
	  (lambda (key dlsym ret . args)
	    (table-set symtab key (ffi-lookup-symbol handle dlsym))
	    (table-set ifacetab key (ffi-interface ret args)))
	  elt))
       tab)
      (lambda (key . args)
	(and
	 (table-bound-p symtab key)
	 (ffi-apply (table-ref ifacetab key)
		    (table-ref symtab key) args)))))

  (define (enump sym enum-alist)
    (and (symbolp sym)
	 (assq sym enum-alist)))

  (define (enum->sym num enum-alist)
    (let ((p (rassq num enum-alist)))
      (if p (car p)
	(signal 'bad-arg `(,num)))))

  (define (sym->enum sym enum-alist)
    (let ((p (assq sym enum-alist)))
      (if p (cdr p)
	(signal 'bad-arg `(,sym)))))
  
  (define (ffi-type-enum enum-alist)
    (ffi-type
     ffi-type-sint32
     (lambda (x) (enump x enum-alist))
     (lambda (x) (sym->enum x enum-alist))
     (lambda (x) (enum->sym x enum-alist))))

  )
#| xosd.jl -- Bindings to libxosd using rep.ffi

  Author: Sergey Bolshakov <sbolshakov altlinux ru>
  Version: $Id: xosd.jl,v 1.3 2006/07/16 15:17:32 me Exp me $

  This file is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2, or (at your option)
  any later version.

  This file is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this file.  If not, write to the Free Software
  Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

|#

(define-structure rep.ffi.xosd

    (export xosd)

    (open rep
	  rep.ffi
	  rep.ffi.util
	  rep.data.objects)

  (defconst xosd-dl-soname "libxosd.so.2"
    "xosd library's soname.")
  
  (define handle
    (ffi-bind
     xosd-dl-soname
     `((create "xosd_create"					; xosd *xosd_create(int number_lines)
	       ,ffi-type-pointer ,ffi-type-sint32)
       (destroy "xosd_destroy"					; int xosd_destroy(xosd * osd)
		,ffi-type-sint32 ,ffi-type-pointer)			
       (set-bar-len! "xosd_set_bar_length"			; int xosd_set_bar_length(xosd * osd, int length)
		     ,ffi-type-sint32 ,ffi-type-pointer ,ffi-type-sint32)
       (display-string "xosd_display"				; int xosd_display(xosd * osd, int line, xosd_command command, ...)
		       ,ffi-type-sint32 ,ffi-type-pointer ,ffi-type-sint32
		       ,(ffi-type-enum '((string . 1) (printf . 2)))
		       ,ffi-type-pointer)
       (display-bar "xosd_display"				; int xosd_display(xosd * osd, int line, xosd_command command, ...)
		    ,ffi-type-sint32 ,ffi-type-pointer ,ffi-type-sint32
		    ,(ffi-type-enum '((percentage . 0) (slider . 3)))
		    ,ffi-type-sint32)
       (onscreenp "xosd_is_onscreen"				; int xosd_is_onscreen(xosd * osd)
		  ,ffi-type-sint32 ,ffi-type-pointer)
       (wait "xosd_wait_until_no_display"			; int xosd_wait_until_no_display(xosd * osd)
	     ,ffi-type-sint32 ,ffi-type-pointer)
       (hide "xosd_hide"					; int xosd_hide(xosd * osd)
	     ,ffi-type-sint32 ,ffi-type-pointer)
       (show "xosd_show"					; int xosd_show(xosd * osd)
	     ,ffi-type-sint32 ,ffi-type-pointer)
       (set-pos! "xosd_set_pos"					; int xosd_set_pos(xosd * osd, xosd_pos pos)
		 ,ffi-type-sint32 ,ffi-type-pointer
		 ,(ffi-type-enum '((top . 0) (bottom . 1) (middle . 2))))
       (set-align! "xosd_set_align"				; int xosd_set_align(xosd * osd, xosd_align align)
		   ,ffi-type-sint32 ,ffi-type-pointer 
		   ,(ffi-type-enum '((left . 0) (center . 1) (right . 2))))
       (set-shadow-offset! "xosd_set_shadow_offset"		; int xosd_set_shadow_offset(xosd * osd, int shadow_offset)
			   ,ffi-type-sint32 ,ffi-type-pointer ,ffi-type-sint32)
       (set-outline-offset! "xosd_set_outline"			; int xosd_set_outline_offset(xosd * osd, int outline_offset)
			    ,ffi-type-sint32 ,ffi-type-pointer ,ffi-type-sint32)
       (set-outline-colour! "xosd_set_outline_colour"		; int xosd_set_outline_colour(xosd * osd, const char *colour)
			    ,ffi-type-sint32 ,ffi-type-pointer ,ffi-type-sint32)
       (set-shadow-colour! "xosd_set_shadow_colour"		; int xosd_set_shadow_colour(xosd * osd, const char *colour)
			   ,ffi-type-sint32 ,ffi-type-pointer ,ffi-type-sint32)
       (set-horiz-offset! "xosd_set_horizontal_offset"		; int xosd_set_horizontal_offset(xosd * osd, int offset)
			  ,ffi-type-sint32 ,ffi-type-pointer ,ffi-type-sint32)
       (set-vert-offset! "xosd_set_vertical_offset"		; int xosd_set_vertical_offset(xosd * osd, int offset)
			 ,ffi-type-sint32 ,ffi-type-pointer ,ffi-type-sint32)
       (set-timeout! "xosd_set_timeout"				; int xosd_set_timeout(xosd * osd, int timeout)
		     ,ffi-type-sint32 ,ffi-type-pointer ,ffi-type-sint32)
       (set-colour! "xosd_set_colour"				; int xosd_set_colour(xosd * osd, const char *colour)
		    ,ffi-type-sint32 ,ffi-type-pointer ,ffi-type-pointer)
       (set-font! "xosd_set_font"				; int xosd_set_font(xosd * osd, const char *font)
		  ,ffi-type-sint32 ,ffi-type-pointer ,ffi-type-pointer)
       (colour "xosd_get_colour"				; int xosd_get_colour(xosd * osd, int *red, int *green, int *blue)
	       ,ffi-type-sint32 ,ffi-type-pointer ,ffi-type-pointer
	       ,ffi-type-pointer ,ffi-type-pointer)
       (scroll "xosd_scroll"					; int xosd_scroll(xosd * osd, int lines)
	       ,ffi-type-sint32 ,ffi-type-pointer ,ffi-type-sint32)
       (lines "xosd_get_number_lines"				; int xosd_get_number_lines(xosd * osd)
	      ,ffi-type-sint32 ,ffi-type-pointer))))
  
  (define (xosd #!key lines position align font colour timeout voffset hoffset
		shadow-colour shadow-offset outline-colour outline-offset)
    (let ((o (handle 'create (or lines 1))))
      (and align (handle 'set-align! o align))
      (and position (handle 'set-pos! o position))
      (and font (handle 'set-font! o font))
      (and colour (handle 'set-colour! o colour))
      (and timeout (handle 'set-timeout! o timeout))
      (and voffset (handle 'set-vert-offset! o voffset))
      (and hoffset (handle 'set-horiz-offset! o hoffset))
      (and shadow-colour (handle 'set-shadow-colour! o shadow-colour))
      (and shadow-offset (handle 'set-shadow-offset! o shadow-offset))
      (and outline-colour (handle 'set-outline-colour! o outline-colour))
      (and outline-offset (handle 'set-outline-offset! o outline-offset))
      (object 
       nil
       ((display type . args)
	(case type
	  ((string format) (apply handle 'display-string o 0 type args))
	  ((percentage slider) (apply handle 'display-bar o 0 type args))))
       ((destroy) (handle 'destroy o))
       ((hide) (handle 'hide o))
       ((show) (handle 'show o))
       ((scroll) (handle 'scroll o))
       ((wait) (handle 'wait o))
       ((onscreenp) (handle 'onscreenp o)))))
  )

;; local variables:
;; comment-column: 64
;; end:

Attachment: signature.asc
Description: Digital signature



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