DwarfMiddlewareTutorialLesson8

Chair for Computer Aided Medical Procedures & Augmented Reality
Lehrstuhl für Informatikanwendungen in der Medizin & Augmented Reality

THIS WEBPAGE IS DEPRECATED - please visit our new website

Up to DwarfMiddlewareTutorial, forward to DwarfMiddlewareTutorialLesson9?, back to DwarfMiddlewareTutorialLesson7

Lesson 8: Changing Attributes

In this lesson, you will learn how a service can be configured with attributes.

Build time receiver and sender

First, run make install in (top build directory)/src/tutorials/middleware/lesson7.

Now, run make install in (top build directory)/src/tutorials/middleware/lesson8. This will install a new binary, for the TimeSender. We will reuse the TimeReceiver of lesson 7. It will also install a new service description:

TimeSender
<service name="TimeSender" isTemplate="true">
   <attribute name="tickInterval" value="3">
   <ability name="senddate" type="TimeOfDay">
      <connector protocol="PushSupplier"/>
   </ability>
</service>

Note the attribute tickInterval. The TimeSender evaluates this attribute to decide how often to send an event.

Try it out

In one terminal, run the TimeSender. In another, run the TimeReceiver. The two services will start communicating, as in DwarfMiddlewareTutorialLesson7.

Note how the TimeSender reads its configuration:

15:20:02.540 00003 10 TimeSender.cpp       135 TimeSender_impl : tickInterval attribute found: 3
15:20:02.540 00003 10 TimeSender.cpp       137 TimeSender_impl : tickInterval set to 3

And the TimeReceiver will receive events every three seconds:

got event with time of day: 15:20:42
15:20:45.262 00003 10 TimeReceiver.cpp     064 TimeClient_impl : getStatus
got event with time of day: 15:20:45
got event with time of day: 15:20:48
15:20:49.467 00003 10 TimeReceiver.cpp     064 TimeClient_impl : getStatus
got event with time of day: 15:20:51

Changing the attribute

In DIVE, click on the sendDate ability of the TimeSender. Then click on "Edit Attributes". A new window will appear, allowing you to adit the attributes of the TimeSender.

Editing attribtues in DIVE

Change the attribute tickInterval to 5. See what happens. Change it to 1. See what happens.

Changing the attribute quickly

In DIVE, select the sendDate ability and click on "Python Shell". Enter the following command (don't forget to hit return twice):

for i in range(1,100) : ad.setAttribute("tickInterval", "%d" % i)

This is what happens...

15:54:17.689 00003 10 TimeSender.cpp       135 TimeSender_impl : tickInterval attribute found: 1
15:54:17.689 00003 10 TimeSender.cpp       137 TimeSender_impl : tickInterval set to 1
15:54:17.789 00003 10 TimeSender.cpp       135 TimeSender_impl : tickInterval attribute found: 63
15:54:17.790 00003 10 TimeSender.cpp       137 TimeSender_impl : tickInterval set to 63
15:54:17.890 00003 10 TimeSender.cpp       135 TimeSender_impl : tickInterval attribute found: 99
15:54:17.891 00003 10 TimeSender.cpp       137 TimeSender_impl : tickInterval set to 99

How it works

Whenever a service implements the AttributesChanged interface, it will be notified when the attributes of its service description change.

Thus, the TimeSender service reads it attributes in two places:

  • the startService method
  • the attribtuesHaveChanged method

Excercise 8.1 Run the TimeSender with the command line parameters -DtickInterval=5. What happens? Why?


Up to DwarfMiddlewareTutorial, forward to DwarfMiddlewareTutorialLesson9?, back to DwarfMiddlewareTutorialLesson7

-- AsaMacWilliams - 18 Feb 2004


Edit | Attach | Refresh | Diffs | More | Revision r1.4 - 17 Mar 2005 - 21:10 - NikolasDoerfler

Lehrstuhl für Computer Aided Medical Procedures & Augmented Reality    rss.gif