Data Driven Programming Change Nets Dr. Werner Van Belle e-mail:...
-
Upload
charity-barber -
Category
Documents
-
view
215 -
download
0
Transcript of Data Driven Programming Change Nets Dr. Werner Van Belle e-mail:...
![Page 1: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/1.jpg)
Data Driven ProgrammingChange Nets
Dr. Werner Van Bellee-mail: [email protected]: [email protected]: +47 776 29 40411 November 2005
![Page 2: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/2.jpg)
1. Connections
![Page 3: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/3.jpg)
Connections Multiple 'actors' that can be
separated in time
separated in space
Communicate through connections shared data
self contained (messages)
Different implementation flavors processes, threads, thunks, longjumps, callbacks,...
copy-on-write, fetch-on-access, serialization
![Page 4: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/4.jpg)
Connection Based Programming Provides
loose coupling: every actor can connect any two different actors
actors do not need to know to whom they will be connected
dissociation of control flow and code: send and forget
suitable for distributed systems
efficient local execution (10x slower than function calls)
increased flexibility: rerouting of connections, multiple receivers
![Page 5: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/5.jpg)
Program Layout Programming larger applications consists of
combining methods and functions to bring a program from one state to another
to be modular, often a mixture of action calls ('print out this file') state reactions ('queue contains file to print')
Focus here on state 'reactive' programming a natural use of connections
![Page 6: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/6.jpg)
2. Updates
![Page 7: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/7.jpg)
Updating strategy
1.Change the variable or data content
2.Send out a change notification
3.Listeners receive update and 'react' to the new state
Advantage Efficient for both message based and thread based
connection models.
Disadvantage update loops
![Page 8: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/8.jpg)
Scenario Queue
push(string)
pop()
PrintingQueue relies on a 'waiting' queue for data storage
pops, prints, stops, pops, prints, stops, ...
How to functionally connect these two objects ?How to functionally connect these two objects ?
![Page 9: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/9.jpg)
Scenario Connect a Queue state change to the
PrintingQueue void Queue::push(string s) { files.push_back(s); updated(); }
void PrintingQueue::state_changed(){ if (printing) return; string s = waiting->pop(); printing=true;}
Update Loop atwaiting->pop() !
Update Loop atwaiting->pop() !
direct connection (call / callback)
string Queue::pop() { string s = files.pop_front(); updated();
return s; }
![Page 10: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/10.jpg)
Scenario
void Queue::push(string s) { files.push_back(s); updated(); }
void PrintingQueue::state_changed(){ if (printing) return; string s = waiting->pop(); printing=true;}
indirect connection (Threaded Asgeir style)
All interested partners want to be notified at least once !
All interested partners want to be notified at least once !
Changedpush
poppop
![Page 11: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/11.jpg)
Scenario
void Queue::push(string s) { files.push_back(s); updated(); }
void PrintingQueue::state_changed(){ if (printing) return; string s = waiting->pop(); printing=true;}
indirect connection (message-queue / receiver)
Needless changed messages !Needless changed messages !
Changedpushpop
pop
Changed
pushChanged
![Page 12: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/12.jpg)
Scenario
void Queue::push(string s) { files.push_back(s); updated(); }
void PrintingQueue::state_changed(){ if (printing) return; string s = waiting->pop(); printing=true;}
indirect connection (eventObjects)
Queue state will be accessedconcurrently, popping of change shouldlock queue, deadlocks/livelocks in manyscenarios
Queue state will be accessedconcurrently, popping of change shouldlock queue, deadlocks/livelocks in manyscenarios
pushpop
pop
Changed
pushChanged
Changed
poppush
![Page 13: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/13.jpg)
Update Loops Direct loops avoided using distinct names
poppop_without_update
pop_updatepush_update
pop_from_printer_queuepop_from_other_actor
Leads to unclear naming convention & usage dependency
indirect conflicts with extra actors (log connected to queue)
multi hop loops tend to be difficult to avoid
![Page 14: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/14.jpg)
Update Loops Other solutions include
loop breaking using version numbers
loop breaking using locking
loop breaking points using comparison checks
All of these can work but they tend to be scattered throughout the code !
Control flow of the overall program is difficult to understand
![Page 15: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/15.jpg)
3. Formal State Transition
![Page 16: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/16.jpg)
Petri-Nets Tokens: a piece of data, a message
![Page 17: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/17.jpg)
Petri-Nets Places: contain zero, one or more tokens
![Page 18: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/18.jpg)
Petri-Nets Transitions: can move tokens between places
can fire when all inputs provide a suitable token (pre-condition / guarding)
when fired, removes all input tokens and creates new output tokens (post-condition)
fire atomically (no concurrent transitions)
![Page 19: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/19.jpg)
The Printing Queue Petri-Net
![Page 20: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/20.jpg)
Petri-Nets
![Page 21: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/21.jpg)
Petri-Nets
![Page 22: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/22.jpg)
Petri-Nets Advantages
Good program documentation
Possibility to simulate message flow, without working program
Formal proof of boundedness, reachability (homestate), deadlock-freedom
Efficient implementation through locality-principle
Can we use Petri-nets as a change notification mechanism ?Can we use Petri-nets as a change notification mechanism ?
![Page 23: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/23.jpg)
Tracking Change with Petri-Nets
![Page 24: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/24.jpg)
Petri-Nets Disadvantages
Formal guard requirements are too broad to implement efficiently (search for a matching binding problem).
Programming with Petri-nets difficult because tokens are consumed. All state is volatile.
Petri-nets are good for constraint checkingThey fail to provide natural change tracking capabilities
Petri-nets are good for constraint checkingThey fail to provide natural change tracking capabilities
![Page 25: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/25.jpg)
Change Nets Modification to Petri-nets
There is always exactly one token per place.
Transition are extended with 'might-be-enabled' flag.
'might-be-enabled' is updated whenever any of the input places changes state
Once 'might-be-enabled', the constraint associated with the transition can be checked
Then the transition can be fired
1. Change messages are separated in time -> no direct loop updates2. Change messages are only send if change occurs -> no indirect loops3. Multiple changes result in one change message per listener4. Change messages do no contain the data -> lightweight
1. Change messages are separated in time -> no direct loop updates2. Change messages are only send if change occurs -> no indirect loops3. Multiple changes result in one change message per listener4. Change messages do no contain the data -> lightweight
![Page 26: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/26.jpg)
No update Loops
var<int> a(0); var<int> b(0); var<int> c(0);
a.update_to(b); b.update_to(c); c.update_to(a);
a=10;
Content FireableA B C A-B B-C C-A0 0 0 0 0 0
a=10 10 0 0 1 0 0execute b = a 10 10 0 0 1 0execute c = a 10 10 10 0 0 1execute a = c 10 10 10 0 0 0
![Page 27: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/27.jpg)
Queue
class Queue: public Place{ list<string> files; void push(string s) { files.push_back(s); updated(); } string pop() { string s = files.front(); files.pop_front(); updated(); return s; }};
![Page 28: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/28.jpg)
PrintingQueue
class PrintingQueue{ Queue * waiting; var<bool> printing; PrintingQueue(Queue *q); void state_changed();};
PrintingQueue::PrintingQueue(Queue *q) : waiting(q){new MemberTransition<PrintingQueue>(*this, &PrintingQueue::state) ->react_on(waiting); ->react_on(printing);printing = false;}
![Page 29: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/29.jpg)
PrintingQueue
void PrintingQueue::state_changed(){ if (printing) return; string s = waiting->pop(); printing=true;}
Queue * q = new Queue(); PrintingQueue pq1(q); PrintingQueue pq2(q); q->push("File1"); q->push("File2");
![Page 30: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/30.jpg)
Multi-Threaded Change Nets
1.Transition waits for a changed state
2.Clear state
3.Sorted waiting acquisition of input locks & output locks
4.Checks constraints
5.Execute transition
6.Releases locks
![Page 31: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/31.jpg)
Intermediate Conclusion Petri-nets are a natural way to think about state
changes in programs
Change nets well defined based on Petri-nets (can be automatically generated in function of the constraint net)
Change net transitions provide a clear, transparent way to glue programs together
Change nets can be efficiently implemented in process, thread & thunk based execution models.
![Page 32: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/32.jpg)
4. Implementation
![Page 33: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/33.jpg)
Places
class Place{ // all the listeners to state changes on this place vector<Transition*> output_transitions; public: void update_to(Transition*t) {output_transitions.push_back(t);}; // will update all the output transitions 'changed' state void updated();};
void Place::updated(){ for(int i = 0 ; i < output_transitions.size() ; i++) output_transitions[i].input_place_changed=true;}
![Page 34: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/34.jpg)
Transitions
class Transition{ bool input_place_changed; // might_be_enabled // will create a transition and add it to the global net Transition(); // will mark this transition as 'possible' executable void set_input_place_changed() { input_place_changed=true; }; // will inform this transition to react on changes at place void react_on(Place*p) {p->update_to(this);}; // will check the might_be_enabled state and run if necessary void execute(); virtual void run() = 0;};
void Transition::execute(){ if (!input_place_changed) return; input_place_changed = false; run();}
![Page 35: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/35.jpg)
Convenience Classes - Variables
template <class T> class var: public Place{ T value; public: var<T>() : Place() {}; var<T>(T init) : Place(), value(init) {}; void update_to(var<T> & other); operator const T&(void) {return value;}; operator const T&(void) const {return value;}; var<T>& operator= (const var<T>& f); var<T>& operator= (const T& f);};
![Page 36: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/36.jpg)
Convenience Classes - Variables
template <class T> var<T>& var<T>::operator= (const var<T>& f){
if (value==f.value) return *this;value=f;updated();return * this;
}
![Page 37: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/37.jpg)
Convenience Classes – Member Transitions
template <class H> class MemberTransition: public Transition{ public: typedef void (H::*member)(); member F; H& o; MemberTransition(H &ob, member i) : o(ob) {F=i;}; virtual void run() {((o).*(F))();};};
![Page 38: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/38.jpg)
Conclusion Petri-nets are a natural way to think about state
changes in programs
Change nets well defined based on Petri-nets (can be automatically generated in function of the constraint net)
Change net transitions provide a clear, transparent way to glue programs together
Change nets can be efficiently implemented in process, thread & thunk based execution models.
![Page 39: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/39.jpg)
5. Extra: Trolltech Connections
![Page 40: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/40.jpg)
Connections - Trolltech Multi-threaded
Signals – emit function calls
Slots – accepts function calls
On an i586-500, you can emit around 2,000,000 signals per second connected to one receiver, or around 1,200,000 per second connected to two receivers. The simplicity and flexibility of the signals and slots mechanism is well worth the overhead, which your users won't even notice.
![Page 41: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/41.jpg)
Connections - Trolltech
![Page 42: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/42.jpg)
Connections - Trolltech
#include <QObject>
class Counter : public QObject { Q_OBJECT int m_value; public: Counter() { m_value = 0; } int value() const { return m_value; } public slots: void setValue(int value); signals: void valueChanged(int newValue); };
![Page 43: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/43.jpg)
Connections - Trolltech
void Counter::setValue(int value) { if (value != m_value) { m_value = value; emit valueChanged(value); } }
![Page 44: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/44.jpg)
Connections - Trolltech
class LcdNumber : public QFrame{ Q_OBJECT public: LcdNumber(QWidget *parent = 0); public slots: void display(int num); void display(double num); void display(const QString &str); void setHexMode(); void setDecMode(); void setOctMode(); void setBinMode(); void setSmallDecimalPoint(bool point);};
![Page 45: Data Driven Programming Change Nets Dr. Werner Van Belle e-mail: werner.van.belle@bio6.itek.norut.nowerner.van.belle@bio6.itek.norut.no e-mail: werner@onlinux.bewerner@onlinux.be.](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649efb5503460f94c0e4c7/html5/thumbnails/45.jpg)
Connections - Trolltech
Counter * a = new Counter();LcdNumber * l = new LcdNumber();
connect(a,SIGNAL(valueChanged(int)), l,SLOT(display(int)))