From: Vitaly Mayatskikh Date: Mon, 7 Sep 2009 10:17:28 +0000 (+0200) Subject: Cleanups. X-Git-Url: https://repo.or.cz/w/cl-v4l2.git/commitdiff_plain/e4708b3e5e98e9a0eb5c65369fa28eb2ecbf4519 Cleanups. Documentation strings, comment for the wrappers generator, global variables rename. --- diff --git a/videodev2.lisp b/videodev2.lisp index 4b39510..01f6360 100644 --- a/videodev2.lisp +++ b/videodev2.lisp @@ -1,5 +1,12 @@ (in-package :cl-v4l2) +;; Generate wrapper classes for all structures. +;; Slot access is overtaken via MOP. This allows to utilize usual `with-slots' +;; macro. This is slow, 'cause it uses hash lookup tables. +;; +;; Better access speed can be achieved using generated accessors +;; named like -, e.g. `capability-driver'. + (defclass v4l2 (standard-class) ()) (defmethod validate-superclass ((obj v4l2) (obj1 standard-class)) t) @@ -9,20 +16,21 @@ (when (equal slot (slot-definition-name s)) (return s)))) -(defvar v4l2-slot-readers (make-hash-table :test 'equal)) -(defvar v4l2-slot-writers (make-hash-table :test 'equal)) +(defvar *v4l2-slot-readers* (make-hash-table :test 'equal)) +(defvar *v4l2-slot-writers* (make-hash-table :test 'equal)) (defmethod slot-value-using-class ((class v4l2) inst slot) (if (string= (string-upcase (slot-definition-name slot)) "RAW") (call-next-method class inst) (funcall (gethash (cons (class-name class) (slot-definition-name slot)) - v4l2-slot-readers) + *v4l2-slot-readers*) inst))) (defmethod (setf slot-value-using-class) (new (class v4l2) inst slot) (if (string= (string-upcase (slot-definition-name slot)) "RAW") (call-next-method new class inst) - (funcall (gethash (cons (class-name class) (slot-definition-name slot)) v4l2-slot-writers) + (funcall (gethash (cons (class-name class) (slot-definition-name slot)) + *v4l2-slot-writers*) new inst))) (defmacro define-wrapper (class-and-type supers &optional slots) @@ -50,7 +58,7 @@ :pointer (cffi:foreign-slot-value (,raw-accessor inst) ',class-name ',slot)) `(cffi:foreign-slot-value (,raw-accessor inst) ',class-name ',slot)))) collect - `(setf (gethash (cons ',class-name ',slot) v4l2-slot-readers) + `(setf (gethash (cons ',class-name ',slot) *v4l2-slot-readers*) (fdefinition ',slot-name)) collect @@ -58,7 +66,7 @@ (setf (cffi:foreign-slot-value (,raw-accessor inst) ',class-name ',slot) (cffi:convert-to-foreign new ',slot-type))) collect - `(setf (gethash (cons ',class-name ',slot) v4l2-slot-writers) + `(setf (gethash (cons ',class-name ',slot) *v4l2-slot-writers*) (fdefinition '(setf ,slot-name)))) (defmethod initialize-instance :after ((inst ,class-name) &key pointer) @@ -71,12 +79,14 @@ ',class-name)))) (defmacro def-c-struct (name &rest args) + "Define cffi struct and generate wrapper" `(progn (defcstruct ,name ,@args) (define-wrapper ,name ()))) (defmacro def-c-union (name &rest args) + "Define cffi union and generate wrapper" `(progn (defcunion ,name ,@args)