Main Page   Class Hierarchy   Compound List   File List   Compound Members  

awsslot.h

00001 #ifndef __AWS_SLOT_H__
00002 #define __AWS_SLOT_H__
00003 
00004 /**************************************************************************
00005     Copyright (C) 2000-2001 by Christopher Nelson 
00006     
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Library General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011   
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Library General Public License for more details.
00016   
00017     You should have received a copy of the GNU Library General Public
00018     License along with this library; if not, write to the Free
00019     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020 *****************************************************************************/
00021 
00022 #include "aws/iaws.h"
00023 #include "iutil/comp.h"
00024 #include "csutil/csvector.h"
00025 
00026 /*********************************************************************************************************************
00027 *                                                                                                                    *
00028 *      This implements the signal source architecture.  A signal source is an object which knows how to register and *
00029 *    unregister slots.  A signal source always defines and emits signals.  A signal source does not care if someone  *
00030 *    is listening or not.                                                                                            *
00031 *                                                                                                                    *
00032 *********************************************************************************************************************/
00033 
00034 class awsSinkManager : public iAwsSinkManager
00035 {
00036   struct SinkMap
00037   {
00038     unsigned long name;
00039     iAwsSink     *sink;
00040 
00041     SinkMap(unsigned long n, iAwsSink *s):name(n), sink(s) {};
00042   };
00043 
00044   csBasicVector sinks;
00045 
00046 public:
00047   SCF_DECLARE_IBASE;
00048 
00049   awsSinkManager(iBase *p);
00050   virtual ~awsSinkManager();
00051     
00052   bool Initialize(iObjectRegistry *sys);
00053   
00054 public:
00056   virtual void RegisterSink(char *name, iAwsSink *sink);
00057 
00059   virtual iAwsSink* FindSink(char *name);
00060 
00062   virtual iAwsSink *CreateSink(void *parm);
00063 
00064 
00065 public:
00066   // Implement iComponent interface.
00067   struct eiComponent : public iComponent
00068   {
00069     SCF_DECLARE_EMBEDDED_IBASE(awsSinkManager);
00070     virtual bool Initialize(iObjectRegistry* p)
00071     { return scfParent->Initialize(p); }
00072   } scfiComponent;
00073 };
00074 
00075 class awsSink : public iAwsSink
00076 {
00077   struct TriggerMap
00078   {
00079     unsigned long name;
00080     void (*trigger)(void *, iAwsSource *);
00081 
00082     TriggerMap(unsigned long n, void (*t)(void *, iAwsSource *)):name(n), trigger(t) {};
00083   };
00084     
00086   csBasicVector triggers;
00087 
00089   void *parm;
00090 
00091 public:
00092   SCF_DECLARE_IBASE;
00093 
00094   awsSink(void *p);
00095   virtual ~awsSink();
00096 
00098   virtual unsigned long GetTriggerID(char *name);
00099 
00101   virtual void HandleTrigger(int trigger, iAwsSource *source);
00102 
00104   virtual void RegisterTrigger(char *name, void (*Trigger)(void *, iAwsSource *));
00105   
00106 };
00107 
00108 class awsSource : public iAwsSource
00109 {
00111    iAwsComponent *owner;
00112 
00114    csBasicVector slots;
00115 
00116    struct SlotSignalMap
00117    {
00119       iAwsSlot *slot;
00120 
00122       unsigned long signal;
00123    };
00124 
00125 public:  
00126     SCF_DECLARE_IBASE;
00127 
00129     awsSource(iAwsComponent *_owner);
00130 
00132     virtual ~awsSource();
00133 
00135     virtual iAwsComponent *GetComponent();
00136 
00138     virtual bool RegisterSlot(iAwsSlot *slot, unsigned long signal);
00139 
00141     virtual bool UnregisterSlot(iAwsSlot *slot, unsigned long signal);
00142 
00144     virtual void Broadcast(unsigned long signal);
00145 };
00146 
00147 /**********************************************************************************************************************
00148 *                                                                                                                     *
00149 *   This implements the slot architecture.  Slots are conduits for signals.  Signals always have a source.  Slots may *
00150 *  be a conduit for multiple signals from multiple sources.  It is up to the user to determine how to use his slots.  *
00151 *  Slots do not care, other than they always activate a particular trigger of a particular sink.                      *
00152 *                                                                                                                     *
00153 **********************************************************************************************************************/
00154 class awsSlot : public iAwsSlot
00155 {
00157    
00158    
00162    struct SignalTriggerMap
00163    {
00164      unsigned long signal;
00165      unsigned long trigger;
00166      iAwsSink     *sink;
00167      unsigned long refs;
00168 
00169      SignalTriggerMap(unsigned long s, iAwsSink *sk, unsigned long t, unsigned long r):signal(s), trigger(t), sink(sk), refs(r) {};
00170    };
00171 
00172    csBasicVector stmap;
00173   
00174 public:
00175   SCF_DECLARE_IBASE;
00176 
00178   awsSlot();
00179 
00181   virtual ~awsSlot();
00182     
00184   virtual void Connect(iAwsSource *source, unsigned long signal, iAwsSink *sink, unsigned long trigger);
00185                                           
00187   virtual void Disconnect(iAwsSource *source, unsigned long signal, iAwsSink *sink, unsigned long trigger);
00188 
00190   virtual void Emit(iAwsSource &source, unsigned long signal);
00191 };
00192 
00193 
00194 #endif 
00195 

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000