Changeset 10326 in project


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

Changes applied for ecloud (72.208.150.200) through svnwiki:

clarify that each bus must be polled separately

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/dbus

    r10325 r10326  
    101101dbus:register-method : provide a handler to be called when the given method-name is received and matches the given context.
    102102
    103 dbus:enable-polling-thread! : enable or disable the polling thread, and set the polling interval in seconds
     103dbus:enable-polling-thread! : enable or disable the polling thread for a particular bus, and set the polling interval in seconds
    104104
    105 dbus:poll-for-message : check once whether any incoming DBus message is waiting, and if so, dispatch it to the appropriate callback (which you have previously registered using dbus:register-method).  Returns #t if it received a message, #f if not.
     105dbus:poll-for-message : check once whether any incoming DBus message is waiting on a particular bus, and if so, dispatch it to the appropriate callback (which you have previously registered using dbus:register-method).  Returns #t if it received a message, #f if not.
    106106
    107107=== Examples
     
    147147</enscript>
    148148
    149 dbus:register-method starts a polling loop the first time that it is called.  So you can then run the program above which does dbus:send, and you will see the appropriate printf statement execute asynchronously when the message is received.  However the polling thread is subject to the usual limitations of Chicken threads: if there is any blocking I/O, which is waiting for something, then all threads are blocked.  That means you should not use the readline egg for example, because the polling thread will be blocked between each time that you type something and hit Enter.
     149dbus:register-method starts a polling loop the first time that it is called with a context specifying a particular bus.  (And if you register methods on multiple buses, there must be a polling thread for each.)  So you can then run the program above which does dbus:send, and you will see the appropriate printf statement execute asynchronously when the message is received.  However the polling thread is subject to the usual limitations of Chicken threads: if there is any blocking I/O, which is waiting for something, then all threads are blocked.  That means you should not use the readline egg for example, because the polling thread will be blocked between each time that you type something and hit Enter.
    150150
    151151If the polling thread doesn't work, and you would prefer to poll manually, you can call (dbus:enable-polling-thread! enable: #f) to stop the thread (or to prevent it from being started when you register a new method), and then call dbus:poll-for-message periodically.  Both of those functions can take an optional bus: parameter (which defaults to dbus:session-bus, naturally).  dbus:poll-for-message can also take an optional timeout: parameter (which is 0 by default, so that it is a non-blocking call).
     
    184184</enscript>
    185185
    186 What do you get if you combine a remote-controlled mobile thingy with a supercomputer capable of deep thought?  A paranoid android of course!  This example in the test directory handles both kinds of methods from the two examples above (the query and the turnLeft/turnRight commands) and proves that one polling thread is enough to handle multiple, completely different contexts.  So registering more than one method is low-cost compared to registering the first one.
     186What do you get if you combine a remote-controlled mobile thingy with a supercomputer capable of deep thought?  A paranoid android of course!  This example in the test directory handles both kinds of methods from the two examples above (the query and the turnLeft/turnRight commands) and proves that one polling thread is enough to handle multiple, completely different contexts, on a single bus.  So registering more than one method is low-cost compared to registering the first one.
Note: See TracChangeset for help on using the changeset viewer.