Changeset 10327 in project


Ignore:
Timestamp:
04/03/08 09:35:25 (12 years ago)
Author:
ecloud
Message:

each bus must be polled separately

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/3/dbus/trunk/dbus.scm

    r10324 r10327  
    1616
    1717        ; By default, dbus:register-method starts a polling thread
    18         ; if there is not yet one.  Call (dbus:enable-polling-thread #f)
    19         ; to disable it.  If you later call (dbus:enable-polling-thread #f)
     18        ; if there is not yet one.  Call (dbus:enable-polling-thread enable: #f)
     19        ; to disable it.  If you later call (dbus:enable-polling-thread enable: #t)
    2020        ; it will start the polling thread immediately, whether there are
    2121        ; any registered methods or not.
     
    3232        dbus:system-bus
    3333        dbus:starter-bus
     34        ; dbus:known-bus-count
    3435))
    3536
     
    5859(define dbus:starter-bus (foreign-value DBUS_BUS_STARTER int))
    5960(define dbus:dbus-service (foreign-value DBUS_SERVICE_DBUS c-string))
     61(define dbus:known-bus-count (+ 1 (max dbus:session-bus dbus:system-bus dbus:starter-bus)))
    6062
    6163(define-foreign-type dbus:handler-result int) ; really "DBusHandlerResult"
     
    129131                [context-idx-interface 4]
    130132                [context-count 0]
    131                 [polling-enabled #t]
    132                 [polling-thread #f]
    133133                [default-polling-interval 0.01]
    134                 [polling-interval 0.01]
     134                [polling-interval (make-vector dbus:known-bus-count 0.01)]
     135                [polling-enabled (make-vector dbus:known-bus-count #t)]
     136                [polling-threads (make-vector dbus:known-bus-count #f)]
    135137                ;; will become an assoc tree:
    136138                ;; bus
     
    541543
    542544        (set! dbus:enable-polling-thread! (lambda (#!key (bus dbus:session-bus) (enable #t) (interval default-polling-interval))
    543                 (set! polling-enabled enable)
     545                (vector-set! polling-enabled bus enable)
    544546                (if enable
    545547                        (dbus:start-polling! bus interval)
    546                         (when polling-thread (thread-join! polling-thread)))))
     548                        (let ([th (vector-ref polling-threads bus)])
     549                                (when th (thread-join! th))))))
    547550
    548551
    549552        ;; TODO: one polling thread is necessary for each connection
    550553        (define (dbus:start-polling! bus interval)
    551                 (set! polling-interval interval)
     554                (vector-set! polling-interval bus interval)
    552555                ; (pretty-print callbacks-table)
    553                 (when polling-enabled
    554                         (unless polling-thread
    555                                 (set! polling-thread (thread-start! (lambda ()
     556                (when (vector-ref polling-enabled bus)
     557                        (unless (vector-ref polling-threads bus)
     558                                (vector-set! polling-threads bus (thread-start! (lambda ()
    556559                                        (let loop ()
    557560                                                ; (printf "polling~%")
    558561                                                (dbus:poll-for-message bus: bus timeout: 0)
    559                                                 (thread-sleep! polling-interval)
    560                                                 (when polling-enabled (loop)))))))))
     562                                                (thread-sleep! (vector-ref polling-interval bus))
     563                                                (when (vector-ref polling-enabled bus) (loop)))))))))
    561564
    562565        ;; Wraps a user-provided callback so as to pass it the
Note: See TracChangeset for help on using the changeset viewer.