| 1 |
;;; |
| 2 |
;;; mqueue_lib.stub |
| 3 |
;;; |
| 4 |
|
| 5 |
(in-module example.mqueue-cpp) |
| 6 |
|
| 7 |
(inline-stub |
| 8 |
(.include "mqueue_glue.h") |
| 9 |
|
| 10 |
;; Let the stub generator know about <mqueue> type. |
| 11 |
;; The arguments of define-type are: |
| 12 |
;; |
| 13 |
;; (declare-stub-type |
| 14 |
;; scheme-name ;; Scheme class name |
| 15 |
;; c-type ;; C type name when unboxed |
| 16 |
;; description ;; used in error message |
| 17 |
;; c-predicate ;; bool c-predicate(ScmObj obj) - check whether |
| 18 |
;; ;; obj is the type. |
| 19 |
;; c-unbox ;; c-type c-unbox(ScmObj obj) - unbox obj. |
| 20 |
;; ;; You can assume obj is of the type. |
| 21 |
;; c-box ;; ScmObj c-box(c-type x) - box obj. |
| 22 |
;; ) |
| 23 |
;; |
| 24 |
;; Note: when you use a foreign pointer class, care should be taken |
| 25 |
;; if you want to save the unboxed value somewhere; since the ScmObj |
| 26 |
;; that points to the unboxed value may be unreferenced after subr |
| 27 |
;; call, you should be responsible to make sure the unboxed pointer |
| 28 |
;; is visible from GC. |
| 29 |
(declare-stub-type <mqueue> "MQueue*" "mqueue" |
| 30 |
"MQUEUE_P" "MQUEUE_UNBOX" "MQUEUE_BOX") |
| 31 |
|
| 32 |
(define-cproc make-mqueue (name::<const-cstring>) ::<mqueue> |
| 33 |
(return (new (MQueue name)))) |
| 34 |
|
| 35 |
(define-cproc mqueue-find (name::<const-cstring>) ::<mqueue> |
| 36 |
(return (MQueue::findByName name))) |
| 37 |
|
| 38 |
(define-cproc mqueue-name (mq::<mqueue>) ::<const-cstring> |
| 39 |
(return (ref (-> mq (getName)) (c_str)))) |
| 40 |
|
| 41 |
(define-cproc mqueue-empty? (mq::<mqueue>) ::<boolean> |
| 42 |
(return (-> mq (empty)))) |
| 43 |
|
| 44 |
(define-cproc mqueue-push! (mq::<mqueue> message::<const-cstring> |
| 45 |
:optional (urgency::<int> 0)) |
| 46 |
::<int> |
| 47 |
(return (-> mq (pushMessage message urgency)))) |
| 48 |
|
| 49 |
(define-cproc mqueue-pop! (mq::<mqueue>) |
| 50 |
(catch ("MQueueException& e" |
| 51 |
(Scm_Error "mqueue-pop!: %s" (ref e reason (c_str))))) |
| 52 |
(return (SCM_MAKE_STR_COPYING (ref (-> mq (popMessage)) (c_str))))) |
| 53 |
) |