[80] | 1 | /********************************************************************** <BR>
|
---|
| 2 | This file is part of Crack dot Com's free source code release of
|
---|
| 3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
| 4 | information about compiling & licensing issues visit this URL</a>
|
---|
| 5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
| 6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
| 7 | ***********************************************************************/
|
---|
| 8 |
|
---|
| 9 | #include "device/device.hh"
|
---|
| 10 | #include "device/event.hh"
|
---|
| 11 | #include "error/error.hh"
|
---|
| 12 | #include "device/kernel.hh"
|
---|
| 13 | #include "init/init.hh"
|
---|
| 14 |
|
---|
| 15 | #include <stdlib.h>
|
---|
| 16 |
|
---|
| 17 | i4_device_class::i4_device_class()
|
---|
| 18 | {
|
---|
| 19 | next=NULL;
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | void i4_device_class::send_event_to_agents(i4_event *ev, device_flags receive_types)
|
---|
| 23 | {
|
---|
| 24 | i4_kernel.broadcast_event_type(ev, receive_types);
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | i4_event_handler_class::~i4_event_handler_class()
|
---|
| 28 | {
|
---|
| 29 | I4_ASSERT(!thinking(), "i4_event_handler::thinking on destructor");
|
---|
| 30 |
|
---|
| 31 | #ifndef I4_RETAIL
|
---|
| 32 | if (!i4_is_initialized() && first)
|
---|
| 33 | {
|
---|
| 34 | i4_error("event_handler has references at end of program");
|
---|
| 35 | }
|
---|
| 36 | #endif
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 | // clear out all the references to ourself
|
---|
| 40 | while (first)
|
---|
| 41 | {
|
---|
| 42 | first->ref=0;
|
---|
| 43 | first=first->next;
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 |
|
---|
| 48 | i4_event_reaction_class *i4_event_reaction_class::copy()
|
---|
| 49 | {
|
---|
| 50 | i4_event *ev=event ? event->copy() : 0;
|
---|
| 51 |
|
---|
| 52 | return new i4_event_reaction_class(handler_reference.get(), ev);
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | i4_event_reaction_class::~i4_event_reaction_class()
|
---|
| 56 | {
|
---|
| 57 | I4_ASSERT(i4_is_initialized() || handler_reference.get()==0,
|
---|
| 58 | "event reaction is global and has a reference at end of program");
|
---|
| 59 |
|
---|
| 60 |
|
---|
| 61 | handler_reference.reference(0);
|
---|
| 62 |
|
---|
| 63 | I4_ASSERT(i4_is_initialized() || event==0,
|
---|
| 64 | "event reaction is global and has an event at end of program");
|
---|
| 65 |
|
---|
| 66 | if (event)
|
---|
| 67 | delete event;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | i4_event_reaction_class::i4_event_reaction_class(i4_event_handler_class *hand,
|
---|
| 71 | i4_event *event)
|
---|
| 72 | : event(event)
|
---|
| 73 | {
|
---|
| 74 |
|
---|
| 75 | handler_reference.reference(hand);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | i4_event_reaction_class::i4_event_reaction_class(i4_event_handler_class *hand,
|
---|
| 79 | w32 user_message_id)
|
---|
| 80 | {
|
---|
| 81 | event=new i4_user_message_event_class(user_message_id);
|
---|
| 82 | handler_reference.reference(hand);
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 |
|
---|
| 86 | void i4_event_handler_private_reference_class::destroy_ref()
|
---|
| 87 | {
|
---|
| 88 | // see if we need to remove our reference from the object we were referencing
|
---|
| 89 | if (ref)
|
---|
| 90 | {
|
---|
| 91 | i4_event_handler_private_reference_class *p, *last=0;
|
---|
| 92 | p=ref->first;
|
---|
| 93 | while (p && p!=this)
|
---|
| 94 | {
|
---|
| 95 | last=p;
|
---|
| 96 | p=p->next;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | I4_ASSERT(p, "destroy_ref : couldn't find reference");
|
---|
| 100 |
|
---|
| 101 | if (last)
|
---|
| 102 | last->next=next;
|
---|
| 103 | else
|
---|
| 104 | ref->first=next;
|
---|
| 105 |
|
---|
| 106 | ref=0;
|
---|
| 107 | }
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | // if who is 0, then reference is destroyed
|
---|
| 111 | void i4_event_handler_private_reference_class::reference(i4_event_handler_class *who)
|
---|
| 112 | {
|
---|
| 113 | destroy_ref();
|
---|
| 114 | if (who)
|
---|
| 115 | {
|
---|
| 116 | ref=who;
|
---|
| 117 | next=who->first;
|
---|
| 118 | who->first=this;
|
---|
| 119 | }
|
---|
| 120 | }
|
---|