00001 #ifndef GLUE_DEV_H 00002 #define GLUE_DEV_H 00003 00004 #include "std/strings.H" 00005 #include "std/list.H" 00006 #include "std/typedobj.H" 00007 #include "event/event.H" 00008 00009 00010 // 00011 // DEVice - base class for chainable, observable device sources 00012 // 00013 // DEVice's are event sources that generate callbacks to observers 00014 // when events are generated. 00015 // 00016 class DllImpExp DEVice: public EVENTsource, public TYPEDOBJ { 00017 protected: 00018 ARRAY<EVENThandler *> _hdlrs; // Pointer to event handler for this device 00019 static ARRAY<DEVice *> *_devices; 00020 str_ptr _dev_name; 00021 00022 public: 00023 DEVice(Cstr_ptr &dev_name, Cstr_ptr &evt_name); 00024 virtual ~DEVice() { } 00025 00026 void add_handler(EVENThandler *h) { _hdlrs += h; } 00027 void rem_handler(EVENThandler *h) { _hdlrs -= h; } 00028 void distrib (cEVENTptr &e) const { EVENTmgr::distrib(e); 00029 for (int i=0;i<_hdlrs.num();i++) 00030 _hdlrs[i]->handle_event(e); } 00031 00032 str_ptr dev_name() const { return _dev_name; } 00033 void debug(ostream &os) const { os << "dev = "<< _dev_name << " "; 00034 EVENTsource::debug(os); } 00035 00036 static void print_available_events(Cstr_ptr &evtype); 00037 static DEVice *lookup(EVENTsource s); 00038 static const ARRAY<DEVice *> &devices() { return *_devices; } 00039 00040 00041 /* ----------- TYPEDOBJ methods --------------- */ 00042 DEFINE_BASE_TYPE(DEVice, const DEVice *); 00043 }; 00044 00045 #endif