Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Event and
Signal Driven
Programming
The wheel already exists…
Feedback is precious
https://joind.in/7027
Computer Science 201
Event based programming …. ??? …. PROFIT!
Structured programming
 simple,hierarchical program flow
 structures
     sequence
     selection
     repetition
 pr...
Event Driven Programming
                  Wait for
                  Events




      Handlers               Accept
     ...
Transitioning to events
 code  flow is controlled by the user, not
  the program
 software can sit “idle” until an event...
Asyncronous vs. Synchronous
 event-driven  !== asynchronous
 structured !== synchronous


 concurrency    through
    ...
Interrupts
 asynchronous    signal/event indicating
  need for change in execution or need for
  attention
 “The ship is...
Design Patterns
The Evolution of Event based programming
Publish/Subscribe
 type   of event programming
 this is NOT observer
 publisher and subscriber are decoupled
 subscrib...
Subscriber


Publisher   Broker   Subscriber


                     Subscriber
(Main) (event/message) loop
 poll
 blocks until something arrives
 dispatches
 main is added if it is the highest leve...
Subject/Observer
 this is a subset of publish/subscribe NOT
  the other way around
 in this case, the subject maintains ...
Observer1
Subject
          Observer2
          Observer3
Event/Handler
 events are spawned by the system
 events are dispatched to handlers which
  are attached to them
 handle...
Object                         Handler1
                               (Event1)


          Send
         Event2
         ...
Dispatcher
 getsevent
 determines which handlers get called
     either attached
     determined by type
     stored ...
Signal/Slot
 signal – something you know is going to
  happen that is attached to a class
 slot – method in a class that...
Reactor
 Resources
 Synchronous   Event Demultiplexer
 Dispatcher
 Request   Handler
Reactor
  Service       Service     Service
  Request       Request     Request


            Demultiplexer

             ...
Copy the Giants
   Use examples of existing event driven code


https://github.com/auroraeosrose/event-and-signal-
exercis...
Windows API
Message Pump of Doom
On to the Code
 Concepts
    Main “Loop” for processing
    Message Queue holding messages
    Windows (objects) post ...
Gobject
Event Handler madness
On to the Code
 Concepts
    Dispatcher
    Register event by name
    Attach a handler
    Emit event
QT
For those who like a little ++
with their C
On to the Code
 event–   virtual function in a class you
  reimplement to handle the event
 signal – wired to a callback...
Best Practices
What to do in your own code
Name It properly
   Publish / Subscribe    Dispatcher
       Decoupled
                           (Main) Event Loop
 ...
Standard interfaces
 Observer?  Use SplSubject and
  SplObserver
 Pub/Sub?
 Event/Handler?
 Signal/Slot?
Borrow from other languages
 Any  C based language translates REALLY
  well to PHP
 If you can’t depend on an extension,...
The future?
 Best  new hope for clean, easy eventing
  implementations? Traits
 Some good wrappers around existing C
  l...
The Wild Wild West
Experiments are coming
Eventing Libraries
 https://github.com/christopherobin/Event
  Emitter
 https://github.com/Wordi/LooPHP/tree/m
  aster/L...
Framework’s New Thing
 ZF2 – Event Manager
 Symfony 2 – Event Manager
 Kohana Events
 Aura (Aura.signal)
 CodeIgnitor...
Extensions galore
 Php-gtk    (gobject)
     http://gtk.php.net
 libevent
        http://pecl.php.net/package/libevent
...
node.php
 https://github.com/JosephMoniz/node.ph
  p
 PHP extension using libuv (joyent based
  platform abstraction eve...
react-php
 http://nodephp.org/
 Originally called nodephp (to great
  screams), now is called react-php
 Is actually pa...
Bring it on
 Good   Libraries
 Blog posts
 Articles
 Extensions
Contact Me
 http://emsmith.net
 http://joind.in/7027
 auroraeosrose@gmail.com
 IRC– freenode – auroraeosrose
 #coapp ...
Event and Signal Driven Programming Zendcon 2012
Event and Signal Driven Programming Zendcon 2012
Event and Signal Driven Programming Zendcon 2012
Upcoming SlideShare
Loading in …5
×

of

Event and Signal Driven Programming Zendcon 2012 Slide 1 Event and Signal Driven Programming Zendcon 2012 Slide 2 Event and Signal Driven Programming Zendcon 2012 Slide 3 Event and Signal Driven Programming Zendcon 2012 Slide 4 Event and Signal Driven Programming Zendcon 2012 Slide 5 Event and Signal Driven Programming Zendcon 2012 Slide 6 Event and Signal Driven Programming Zendcon 2012 Slide 7 Event and Signal Driven Programming Zendcon 2012 Slide 8 Event and Signal Driven Programming Zendcon 2012 Slide 9 Event and Signal Driven Programming Zendcon 2012 Slide 10 Event and Signal Driven Programming Zendcon 2012 Slide 11 Event and Signal Driven Programming Zendcon 2012 Slide 12 Event and Signal Driven Programming Zendcon 2012 Slide 13 Event and Signal Driven Programming Zendcon 2012 Slide 14 Event and Signal Driven Programming Zendcon 2012 Slide 15 Event and Signal Driven Programming Zendcon 2012 Slide 16 Event and Signal Driven Programming Zendcon 2012 Slide 17 Event and Signal Driven Programming Zendcon 2012 Slide 18 Event and Signal Driven Programming Zendcon 2012 Slide 19 Event and Signal Driven Programming Zendcon 2012 Slide 20 Event and Signal Driven Programming Zendcon 2012 Slide 21 Event and Signal Driven Programming Zendcon 2012 Slide 22 Event and Signal Driven Programming Zendcon 2012 Slide 23 Event and Signal Driven Programming Zendcon 2012 Slide 24 Event and Signal Driven Programming Zendcon 2012 Slide 25 Event and Signal Driven Programming Zendcon 2012 Slide 26 Event and Signal Driven Programming Zendcon 2012 Slide 27 Event and Signal Driven Programming Zendcon 2012 Slide 28 Event and Signal Driven Programming Zendcon 2012 Slide 29 Event and Signal Driven Programming Zendcon 2012 Slide 30 Event and Signal Driven Programming Zendcon 2012 Slide 31 Event and Signal Driven Programming Zendcon 2012 Slide 32 Event and Signal Driven Programming Zendcon 2012 Slide 33 Event and Signal Driven Programming Zendcon 2012 Slide 34 Event and Signal Driven Programming Zendcon 2012 Slide 35 Event and Signal Driven Programming Zendcon 2012 Slide 36 Event and Signal Driven Programming Zendcon 2012 Slide 37 Event and Signal Driven Programming Zendcon 2012 Slide 38 Event and Signal Driven Programming Zendcon 2012 Slide 39 Event and Signal Driven Programming Zendcon 2012 Slide 40 Event and Signal Driven Programming Zendcon 2012 Slide 41 Event and Signal Driven Programming Zendcon 2012 Slide 42 Event and Signal Driven Programming Zendcon 2012 Slide 43
Upcoming SlideShare
Event and signal driven programming
Next
Download to read offline and view in fullscreen.

6 Likes

Share

Download to read offline

Event and Signal Driven Programming Zendcon 2012

Download to read offline

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Event and Signal Driven Programming Zendcon 2012

  1. 1. Event and Signal Driven Programming The wheel already exists…
  2. 2. Feedback is precious https://joind.in/7027
  3. 3. Computer Science 201 Event based programming …. ??? …. PROFIT!
  4. 4. Structured programming  simple,hierarchical program flow structures  sequence  selection  repetition  procedural  adds sub-routines or functions  object oriented  modularizes components of code
  5. 5. Event Driven Programming Wait for Events Handlers Accept are Called Event Dispatch Event
  6. 6. Transitioning to events  code flow is controlled by the user, not the program  software can sit “idle” until an event occurs  allows software to react  why?
  7. 7. Asyncronous vs. Synchronous  event-driven !== asynchronous  structured !== synchronous  concurrency through  Async I/O (epoll, IOCP, kqueue, et al)  threads  forking (multi-process)
  8. 8. Interrupts  asynchronous signal/event indicating need for change in execution or need for attention  “The ship is going to explode”  A signal is a software interrupt delivered to a process
  9. 9. Design Patterns The Evolution of Event based programming
  10. 10. Publish/Subscribe  type of event programming  this is NOT observer  publisher and subscriber are decoupled  subscribers express interest in a state change/event/message/signal  each subscriber receives a copy
  11. 11. Subscriber Publisher Broker Subscriber Subscriber
  12. 12. (Main) (event/message) loop  poll  blocks until something arrives  dispatches  main is added if it is the highest level of control in a program
  13. 13. Subject/Observer  this is a subset of publish/subscribe NOT the other way around  in this case, the subject maintains the observers and notifies them of state change/event/message/signal  more tightly coupled then publish/subscribe
  14. 14. Observer1 Subject Observer2 Observer3
  15. 15. Event/Handler  events are spawned by the system  events are dispatched to handlers which are attached to them  handler can go by many names – callback, closure, function  events might have priority, might interrupt depending on the dispatch method used
  16. 16. Object Handler1 (Event1) Send Event2 Handler2 (Event1) Dispatcher Handler3 (Event1) Handler4 Send Event (Event 2)
  17. 17. Dispatcher  getsevent  determines which handlers get called  either attached  determined by type  stored in some manner  calls the handlers
  18. 18. Signal/Slot  signal – something you know is going to happen that is attached to a class  slot – method in a class that can be connected to a signal  connect a signal to a slot (wire it up)  emit the signal  requires oo
  19. 19. Reactor  Resources  Synchronous Event Demultiplexer  Dispatcher  Request Handler
  20. 20. Reactor Service Service Service Request Request Request Demultiplexer Dispatcher Various Handlers
  21. 21. Copy the Giants Use examples of existing event driven code https://github.com/auroraeosrose/event-and-signal- exercises
  22. 22. Windows API Message Pump of Doom
  23. 23. On to the Code  Concepts  Main “Loop” for processing  Message Queue holding messages  Windows (objects) post to queue  Queue passes messages around  Each window has a winproc to handle messages sent to it (switch of doom)
  24. 24. Gobject Event Handler madness
  25. 25. On to the Code  Concepts  Dispatcher  Register event by name  Attach a handler  Emit event
  26. 26. QT For those who like a little ++ with their C
  27. 27. On to the Code  event– virtual function in a class you reimplement to handle the event  signal – wired to a callback (slot) by a metaobject class, no loop necessarily required  slot – the actual implemented function for an event or a callback attached to a signal
  28. 28. Best Practices What to do in your own code
  29. 29. Name It properly  Publish / Subscribe  Dispatcher  Decoupled  (Main) Event Loop  Subject / Observer  stateless  State Machine  Event / Handler  Message Pump  event loop  Reactor  Signal / Slot  Tightly coupled objects  Traits
  30. 30. Standard interfaces  Observer? Use SplSubject and SplObserver  Pub/Sub?  Event/Handler?  Signal/Slot?
  31. 31. Borrow from other languages  Any C based language translates REALLY well to PHP  If you can’t depend on an extension, but want to “drop it in” – do the same API in a different namespace and class_alias as appropriate  Upgrading from stone wheels to vulcanized rubber is great, but don’t reinvent
  32. 32. The future?  Best new hope for clean, easy eventing implementations? Traits  Some good wrappers around existing C libraries (libevent, dbus, glib/gobject, qt, winapi, . NET)  Pulling in good ideas from other languages, PHP evolves
  33. 33. The Wild Wild West Experiments are coming
  34. 34. Eventing Libraries  https://github.com/christopherobin/Event Emitter  https://github.com/Wordi/LooPHP/tree/m aster/LooPHP  https://github.com/igorw/evenement  https://github.com/kirbysayshi/SignalSlot
  35. 35. Framework’s New Thing  ZF2 – Event Manager  Symfony 2 – Event Manager  Kohana Events  Aura (Aura.signal)  CodeIgnitor events  I could go on….
  36. 36. Extensions galore  Php-gtk (gobject)  http://gtk.php.net  libevent http://pecl.php.net/package/libevent  eio  http://pecl.php.net/package/eio  libev  https://github.com/m4rw3r/php-libev
  37. 37. node.php  https://github.com/JosephMoniz/node.ph p  PHP extension using libuv (joyent based platform abstraction eventing layer ) and http parser used for node  So essentially it IS node in a php extension
  38. 38. react-php  http://nodephp.org/  Originally called nodephp (to great screams), now is called react-php  Is actually passing off to another server  Written in php
  39. 39. Bring it on  Good Libraries  Blog posts  Articles  Extensions
  40. 40. Contact Me  http://emsmith.net  http://joind.in/7027  auroraeosrose@gmail.com  IRC– freenode – auroraeosrose  #coapp #phpmentoring and others
  • CeesJanKiewiet

    Apr. 26, 2018
  • hanochaloni

    Aug. 25, 2015
  • inetfuture

    May. 16, 2013
  • benyan

    Nov. 12, 2012
  • rgaidot

    Oct. 31, 2012
  • raphaelstolt

    Oct. 29, 2012

Views

Total views

1,941

On Slideshare

0

From embeds

0

Number of embeds

9

Actions

Downloads

42

Shares

0

Comments

0

Likes

6

×