Changeset 25883 in project

02/09/12 23:55:44 (9 years ago)

Added "boxed" variant type and unsupported type to distinguish from #f.

You can choose whether to have variants automatically unboxed when reading, or not.
But the enclosing record will be necessary to indicate to e.g. dbus:send that
you wish to send an item in a variant.

3 edited


  • release/4/dbus/trunk/dbus.scm

    r25880 r25883  
    1212              dbus:discover-api-xml
    1313              dbus:dbus-service
    14               dbus:type-uint32
    1514              dbus:session-bus
    1615              dbus:system-bus
    1716              dbus:starter-bus
    1817              dbus:known-bus-count
    19               dbus:register-path)
    20         (import scheme chicken
     18              dbus:register-path
     19                  unsupported-type?
     20                  unsupported-type-signature
     21                  variant?
     22                  variant-data
     23                  make-variant
     24                  auto-unbox-variants)
     25        (import scheme chicken extras
    2126                (except foreign foreign-declare)
    2227                foreigners
    3540        static DBusError err;
     43;; A disjoint type to represent any kind of dbus data type
     44;; which this egg so far does not support.  The signature
     45;; is the ASCII string to represent that type on-the-wire.
     46(define-record-type unsupported-type
     47        (make-unsupported-type signature)
     48        unsupported-type?
     49        (signature unsupported-type-signature))
     50(define-record-printer (unsupported-type d out)
     51        (fprintf out "#<unsupported-type ~a>" (unsupported-type-signature d)))
     53;; Scheme is a dynamically typed language, so fundamentally we don't
     54;; have a use for the "variant" concept; but since dbus has a variant type,
     55;; we need a way of representing one when preparing a message for marshalling.
     56;; So, it might as well be symmetric, putting any variant returned from
     57;; a dbus call into this type as well.
     58(define-record-type variant
     59        (make-variant data)
     60        variant?
     61        (data variant-data))
     62(define-record-printer (variant v out)
     63        (fprintf out "#,(variant ~S)" (variant-data v)))
     64;; If unboxing is turned on, when a "call"ed dbus service method
     65;; returns a variant, it will look as if it was not packaged in a variant at all.
     66;; By default this feature is turned off, in the interest of having a
     67;; representation that is the same as you will need to build when
     68;; you want to send (marshall) a dbus message.
     69(define auto-unbox-variants (make-parameter #f))
    3871; Would want to do this:
    392425                                        (iter->pair (make-sub-iter iter))]
    393426                                [(eq? type dbus:type-variant)
    394                                         ((make-sub-iter iter))]
     427                                        (if (auto-unbox-variants)
     428                                                ((make-sub-iter iter))
     429                                                (make-variant ((make-sub-iter iter))))]
    395430                                ;; unsupported so far (not understood well enough):
    396431                                ;;      dbus:type-object-path and dbus:type-signature
    397432                                ;; dbus:type-invalid is returned as #f (could be (void) but that
    398433                                ;; would be the termination condition for the iterator)
    399                                 ;[else (format "unsupported-~c" (integer->char type))] )))
    400                                 [else #f] )))
     434                                [else (make-unsupported-type (integer->char type))] )))
    402436        (define (make-sub-iter iter)
  • release/4/dbus/trunk/dbus.setup

    r25881 r25883  
    1414(install-extension 'dbus
    1515        `("" "")
    16         `((version 0.89)))
     16        `((version 0.90)))
  • release/4/dbus/trunk/examples/introspect-connman.scm

    r25881 r25883  
    2828(printf "~%==== Manager Properties:~%")
     29(auto-unbox-variants #t)
    2930(let ([mgr-props (dbus:call mgr-ctxt "GetProperties")])
    3031        (pretty-print mgr-props)
Note: See TracChangeset for help on using the changeset viewer.