diff options
-rw-r--r-- | dnn/Event.cc | 163 | ||||
-rw-r--r-- | dnn/Event.h | 97 | ||||
-rw-r--r-- | dnn/Imakefile | 59 | ||||
-rw-r--r-- | dnn/Reaction.cc | 94 | ||||
-rw-r--r-- | dnn/Reaction.h | 71 | ||||
-rw-r--r-- | dnn/Trigger.cc | 67 | ||||
-rw-r--r-- | dnn/Trigger.h | 44 | ||||
-rw-r--r-- | dnn/doc.main | 76 | ||||
-rw-r--r-- | dnn/test.cc | 12 | ||||
-rw-r--r-- | dnn/version.h | 71 |
10 files changed, 754 insertions, 0 deletions
diff --git a/dnn/Event.cc b/dnn/Event.cc new file mode 100644 index 0000000..3dbf5fb --- /dev/null +++ b/dnn/Event.cc @@ -0,0 +1,163 @@ +/* + * DNN - Data News Network + * + * by Stephane Chatty + * + * Copyright 1993-1994 + * Centre d'Etudes de la Navigation Aerienne (CENA) + * + * Events. + * + * $Id$ + * $CurLog$ + */ + +#include "Event.h" +#include <memory.h> + +DnnEventFeatureList :: DnnEventFeatureList (const DnnEventFeatureList& base, int nbf, DnnEventFeature* f) +: CcuListOf <DnnEventFeature> (base) +{ + Load (nbf, f); +} + +DnnEventFeatureList :: DnnEventFeatureList (int nbf, DnnEventFeature* f) +: CcuListOf <DnnEventFeature> () +{ + Load (nbf, f); +} + +void +DnnEventFeatureList :: Load (int nbf, DnnEventFeature* f) +{ + while (nbf-- > 0) + Append (f++); +} + +DnnEventFeatureList :: ~DnnEventFeatureList () +{ +} + + +/*?class DnnEventType +A \typ{DnnEventType} contains the description of a -- dynamic -- class of events. +It holds a name and an array of offsets, each describing where to find the corresponding +feature in an event of that class. +?*/ + +CcuListOf <DnnEventType>* DnnEventType::AllTypes = 0; + +/*?hidden?*/ +void +DnnEventType :: ClassInit () +{ + AllTypes = new CcuListOf <DnnEventType>; +} + +/*? +Build an event type named \var{name} from an array of features. This is mostly +useful for statically defined event classes. \var{f} is the array of features, and +\var{nbf} is the number of features in that array. +?*/ +DnnEventType :: DnnEventType (const char* name, int nbf, DnnEventFeature f []) +: Name (name), +#if 0 + Features (), +#endif + NbFeatures (nbf), + FeaturesOffsets (new int [nbf]) +{ + if (!AllTypes) + ClassInit (); + AllTypes->Append (this); + int offset = 0; + for (int i = 0; i < nbf; ++i) { + offset += f[i].Size; + FeaturesOffsets [i] = offset; + } +} + +/*? +Build an event type from a list of features. +?*/ +DnnEventType :: DnnEventType (const char* name, const DnnEventFeatureList& fl) +: Name (name), +#if 0 + Features (), +#endif + NbFeatures (fl.Length ()), + FeaturesOffsets (new int [NbFeatures]) +{ + if (!AllTypes) + ClassInit (); + AllTypes->Append (this); + int offset = 0; + int i = 0; + CcuListIterOf <DnnEventFeature> f = fl; + while (++f) { + offset += (*f)->Size; + FeaturesOffsets [i] = offset; + ++i; + } +} + +/*?nodoc?*/ +DnnEventType :: ~DnnEventType () +{ + AllTypes->Remove (this); + delete [] FeaturesOffsets; +} + +/*? +Build an even of type \var{t}. +?*/ +DnnEvent :: DnnEvent (const DnnEventType* t) +: Type (*t) +{ + int sz = t->GetTotalSize (); + if (sz > 0) + Data = new char [sz]; + else + Data = 0; +} + +/*?nodoc?*/ +DnnEvent :: ~DnnEvent () +{ + if (Data) + delete [] Data; +} + +void +DnnEvent :: SetFeature (int i, const void* data) +{ + int offset = Type.GetOffset (i); + int size = Type.GetSize (i); + memcpy (Data+offset, data, size); +} + +void +DnnEvent :: GetFeature (int i, void* data) +{ + int offset = Type.GetOffset (i); + int size = Type.GetSize (i); + memcpy (data, Data+offset, size); +} + +#if 0 +void +DnnEvent :: WriteTo (DnnIOS& s) +{ + // what about byte swapping? + s.WriteBuf ((const byte*) Data, Type.GetTotalSize ()); +} + +void +DnnEvent :: ReadFrom (DnnIOS& s, lword) +{ + // what about byte swapping? + s.ReadBuf ((byte*) Data, Type.GetTotalSize ()); +} + + +#endif diff --git a/dnn/Event.h b/dnn/Event.h new file mode 100644 index 0000000..cacb2e8 --- /dev/null +++ b/dnn/Event.h @@ -0,0 +1,97 @@ +/* + * DNN - Data News Network + * + * by Stephane Chatty + * + * Copyright 1993-1994 + * Centre d'Etudes de la Navigation Aerienne (CENA) + * + * Events. + * + * $Id$ + * $CurLog$ + */ + +#ifndef DnnEvent_H_ +#define DnnEvent_H_ + +#include "cplus_bugs.h" +#include "ccu/String.h" +#include "ccu/List.h" + +class UchIOS; + +#if 0 + +class DnnEventFeature { +protected: + CcuString Name; + DnnEventFeatureType& Type; + +public: +inline DnnEventFeature (const char* n, DnnEventFeatureType& t) : Name (n), Type (t) {} +inline ~DnnEventFeature () {} +}; + +#else + +struct DnnEventFeature { + const char* Name; + int Size; +}; + +#endif + + +class DnnEventFeatureList : public CcuListOf <DnnEventFeature> { +private: + void Load (int, DnnEventFeature*); + +public: + DnnEventFeatureList (int, DnnEventFeature*); + DnnEventFeatureList (const DnnEventFeatureList&, int, DnnEventFeature*); + ~DnnEventFeatureList (); +}; + + +class DnnEventType { +private: +static void ClassInit (); + +protected: +static CcuListOf <DnnEventType>* AllTypes; + CcuString Name; +#if 0 + CcuListOf <DnnEventFeature> Features; +#endif + int NbFeatures; + int* FeaturesOffsets; + +public: + DnnEventType (const char*, int, DnnEventFeature []); + DnnEventType (const char*, const DnnEventFeatureList&); + ~DnnEventType (); +inline int operator == (const DnnEventType& evt) const { return (this == &evt); } +inline int GetTotalSize () const { return FeaturesOffsets [NbFeatures - 1]; } +inline int GetOffset (int i) const { return i ? FeaturesOffsets [i-1] : 0; } +inline int GetSize (int i) const { return FeaturesOffsets [i] - (i ? FeaturesOffsets [i-1] : 0); } +#if 0 +inline void AddFeature (const char* fn, DnnEventFeatureType& t) { Features->Append (new DnnEventFeature (fn, t); } +inline void RemoveFeature () { } +#endif +}; + +class DnnEvent { +protected: + const DnnEventType& Type; + char* Data; + +public: + DnnEvent (const DnnEventType*); + ~DnnEvent (); + void SetFeature (int, const void*); + void GetFeature (int, void*); +inline const DnnEventType* GetType () const { return &Type; } +}; + +#endif /* DnnEvent_H_ */ diff --git a/dnn/Imakefile b/dnn/Imakefile new file mode 100644 index 0000000..838440a --- /dev/null +++ b/dnn/Imakefile @@ -0,0 +1,59 @@ +# +# DNN - Data News Network +# +# by Stephane Chatty +# +# Copyright 1994 +# Centre d'Etudes de la Navigation Aerienne (CENA) +# +# Imakefile +# +# $Id$ +# $CurLog$ +# + + CXXFLAGS = $(CXXOPTIONS) -I$(LOCINCL) + + OBJ = Event.o Trigger.o Reaction.o + + + cc = $(CXXSUFFIX) + SRC = Event.$(cc) Trigger.$(cc) Reaction.$(cc) + + HDR = Event.h Trigger.h Reaction.h + + + LLIB = + DOC = ../../DOC/DNN + +CxxRule () + +all : $(LOCLIB)/libDnn.a $(LOCINCL)/dnn.h headers + +headers: incldir \ + $(LOCINCL)/dnn/Event.h \ + $(LOCINCL)/dnn/Trigger.h \ + $(LOCINCL)/dnn/Reaction.h + +incldir: + -mkdir $(LOCINCL)/dnn + + CCUHDR = $(LOCINCL)/ccu/List.h \ + $(LOCINCL)/ccu/String.h + + LLIB = $(LOCLIB)/libCcu.a + + +CopyLibsTarget ($(LOCLIB),Dnn) +CopyTarget ($(LOCINCL)/dnn.h, dnn.h) +CopyTarget ($(LOCINCL)/dnn/Event.h, Event.h) +CopyTarget ($(LOCINCL)/dnn/Trigger.h, Trigger.h) +CopyTarget ($(LOCINCL)/dnn/Reaction.h, Reaction.h) + +GenHeaderTarget (dnn.h, version.h $(CCUHDR) $(HDR)) +LibraryTarget (Dnn,$(OBJ)) + +ProgramTarget(test, test.o $(OBJ),) +DocRule("Data News Network") +TeXRule() +DistrDocRule(DNN) diff --git a/dnn/Reaction.cc b/dnn/Reaction.cc new file mode 100644 index 0000000..62a6849 --- /dev/null +++ b/dnn/Reaction.cc @@ -0,0 +1,94 @@ +/* + * DNN - Data News Network + * + * by Stephane Chatty + * + * Copyright 1993-1994 + * Centre d'Etudes de la Navigation Aerienne (CENA) + * + * Reactions. + * + * $Id$ + * $CurLog$ + */ + +#include "Reaction.h" +#include "Trigger.h" + +/*?class DnnBaseReaction +The class \typ{DnnBaseReaction} is the base class for event handling. +A reaction implements a behaviour (through the virtual function \fun{Manage}), +and can be associated to one or more triggers, generally located in a sensor. +?*/ + +/*? +Create a reaction. +?*/ +DnnBaseReaction :: DnnBaseReaction () +{ +} + +/*?nodoc?*/ +DnnBaseReaction :: ~DnnBaseReaction () +{ + CcuListIterOf <DnnTrigger> ti (Triggers); + while (++ti) + (*ti)->Unsubscribe (*this); +} + +/*?nextdoc?*/ +void +DnnBaseReaction :: SubscribeTo (DnnTrigger& t) +{ + Triggers.Append (&t); + t.Subscribe (*this); +} + +/*? +Tell that a reaction should (resp. should no more) be activated when the trigger \var{t} +causes the emission of an event. +?*/ +void +DnnBaseReaction :: UnsubscribeTo (DnnTrigger& t) +{ + Triggers.Remove (&t); + t.Unsubscribe (*this); +} + +/*? +This virtual function is called when an event is emitted because of a trigger to which +this reaction was attached. It should be redefined in derived classes to implement +behaviours. +?*/ +void +DnnBaseReaction :: Manage (DnnEvent&) +{ +} + +/*?class DnnReaction +The class \typ{DnnReaction} is a ready-to-use derived class of \typ{DnnBaseReaction}. +In this class, the function \fun{Manage} is redefined to call a function passed when creating +the reaction. +?*/ + +/*? +Build a reaction that will call \var{f} to handle events. +\fun{f} has to take a \typ{DnnEvent\&} parameter and return \typ{void}. +?*/ +DnnReaction :: DnnReaction (DnnHandlingFunction f) +: DnnBaseReaction (), + Handler (f) +{ +} + +/*?nodoc?*/ +DnnReaction :: ~DnnReaction () +{ +} + +/*?nodoc?*/ +void +DnnReaction :: Manage (DnnEvent& ev) +{ + (*Handler) (ev); +} diff --git a/dnn/Reaction.h b/dnn/Reaction.h new file mode 100644 index 0000000..91cc180 --- /dev/null +++ b/dnn/Reaction.h @@ -0,0 +1,71 @@ +/* + * DNN - Data News Network + * + * by Stephane Chatty + * + * Copyright 1993-1994 + * Centre d'Etudes de la Navigation Aerienne (CENA) + * + * Reactions. + * + * $Id$ + * $CurLog$ + */ + +#ifndef DnnReaction_H_ +#define DnnReaction_H_ + +#include "ccu/List.h" + +class DnnTrigger; +class DnnEvent; + +class DnnBaseReaction { +protected: + DnnBaseReaction (); + CcuListOf <DnnTrigger> Triggers; + +public: +virtual ~DnnBaseReaction (); + void SubscribeTo (DnnTrigger&); + void UnsubscribeTo (DnnTrigger&); +virtual void Manage (DnnEvent&); +}; + + +typedef void (*DnnHandlingFunction) (DnnEvent&); + +class DnnReaction : public DnnBaseReaction { +protected: + DnnHandlingFunction Handler; + +public: + DnnReaction (DnnHandlingFunction); + ~DnnReaction (); + void Manage (DnnEvent&); +}; + + +#define SpecializedReaction(R,S) \ +class R : public DnnBaseReaction { \ +protected: \ + S& Body; \ + void (S::*React) (DnnEvent&); \ +public: \ + R (S& s, void (S::*sc) (DnnEvent&)) : DnnBaseReaction (), Body (s), React (sc) {} \ + ~R () {} \ + void Manage (DnnEvent& ev) { (Body.*React) (ev); } \ +}; + +template <class T> class DnnReactionOf : public DnnBaseReaction { +protected: + T& Object; + void (T::*Reaction) (DnnEvent&); + +public: + DnnReactionOf (T& o, void (T::*r) (DnnEvent&)) : DnnBaseReaction (), Object (o), Reaction (r) {} + ~DnnReactionOf () {} + void Manage (DnnEvent& ev) { (Object.*Reaction) (ev); } +}; + +#endif /* DnnReaction_H_ */ diff --git a/dnn/Trigger.cc b/dnn/Trigger.cc new file mode 100644 index 0000000..59a3b33 --- /dev/null +++ b/dnn/Trigger.cc @@ -0,0 +1,67 @@ +/* + * DNN - Data News Network + * + * by Stephane Chatty + * + * Copyright 1993-1994 + * Centre d'Etudes de la Navigation Aerienne (CENA) + * + * Event triggers. + * + * $Id$ + * $CurLog$ + */ + +#include "Trigger.h" +#include "Reaction.h" + +/*?class DnnTrigger +\typ{DnnTrigger}s are the core of event detection and emission. The presence of a trigger +(generally in a sensor) determines whether a certain situation, or the reception +of an event from the underlying window system, should provoke the emission of an event. +Each trigger holds a list of reactions (of type \typ{DnnBaseReaction}). These reactions will +receive all the events whose creation and emission was caused by the presence of +the trigger. +?*/ + +/*? +Create a trigger with an empty list of associated reaction. +?*/ +DnnTrigger :: DnnTrigger () +: Subscribers () +{ +} + +/*?nodoc?*/ +DnnTrigger :: ~DnnTrigger () +{ +} + +/*?nextdoc?*/ +void +DnnTrigger :: Subscribe (DnnBaseReaction& a) +{ + Subscribers.Append (&a); +} + +/*? +Add (resp. Remove) a reaction to (resp. from) the list of reactions that should receive +events caused by this trigger. +?*/ +void +DnnTrigger :: Unsubscribe (DnnBaseReaction& a) +{ + Subscribers.Remove (&a); +} + +/*? +Have a trigger dispatch the event \var{ev} to its associated reactions. +?*/ +void +DnnTrigger :: Dispatch (DnnEvent& ev) +{ + CcuListOf <DnnBaseReaction> subscribers = Subscribers; + CcuListIterOf <DnnBaseReaction> ai (subscribers); + while (++ai) + (*ai)->Manage (ev); +} diff --git a/dnn/Trigger.h b/dnn/Trigger.h new file mode 100644 index 0000000..31dd7f9 --- /dev/null +++ b/dnn/Trigger.h @@ -0,0 +1,44 @@ +/* + * DNN - Data News Network + * + * by Stephane Chatty + * + * Copyright 1993-1994 + * Centre d'Etudes de la Navigation Aerienne (CENA) + * + * Event triggers. + * + * $Id$ + * $CurLog$ + */ + +#ifndef DnnTrigger_H_ +#define DnnTrigger_H_ + +#include "cplus_bugs.h" +#include "ccu/List.h" + +class DnnReaction; +class DnnWindow; +class DnnEvent; + +class DnnTrigger { +friend class DnnBaseReaction; + +private: + DnnTrigger (const DnnTrigger&); + DnnTrigger& operator = (const DnnTrigger&); + +protected: + CcuListOf <DnnBaseReaction> Subscribers; + void Subscribe (DnnBaseReaction&); + void Unsubscribe (DnnBaseReaction&); + +public: + DnnTrigger (); + ~DnnTrigger (); +inline const CcuListOf <DnnBaseReaction>& GetSubscribers () const { return Subscribers; } + void Dispatch (DnnEvent&); +}; + +#endif /* DnnTrigger_H_ */ diff --git a/dnn/doc.main b/dnn/doc.main new file mode 100644 index 0000000..be3601f --- /dev/null +++ b/dnn/doc.main @@ -0,0 +1,76 @@ +/* + * DNN - Data News Network + * + * by Stephane Chatty + * + * Copyright 1994 + * Centre d'Etudes de la Navigation Aerienne (CENA) + * + * documentation skeleton + * + * $Id$ + * $CurLog$ + */ + +\documentstyle[11pt,mydoc,twoside]{doc} + +\pagestyle{ENTETE} +\makeindex + +\def\dnn{DNN} +\namedoc{DNN - Data News Network} + +\begin{document} +\maketitle +\cleardoublepage +\tableofcontents + +\input{psfig} +\chapter{Introduction} +\chapter{Events} +#class DnnEvent +#class DnnEventType + +\chapter{Generating events} +#class DnnTrigger + +\chapter{Handling events} +#class DnnReaction + +\newpage + +\appendix + +\chapter{Class List} + +This chapter contains the list of the classes defined in \dnn. +The first section contains the inheritance tree of \dnn\ classes. +The second section contains for each class the ordered list of its base classes. +The section number indicated after each class refers to the +documentation of that class. +Classes defined in \dnn\ but +which are not documented do not appear in the lists. + +\section{Inheritance Tree} +This section contains the set of classes defined in \dnn. +Each base class is followed by the indented list of its subclasses. + +\input{inhtree.tex} + +\newpage +\section{Inheritance List} +This section contains the set of classes defined in \dnn. +Each class is followed by its base class, recursively. +Thus, from a given class, one can follow the inheritance link +and thus refer to the documentation for the inherited methods. + +\begin{inhlist}{XXXXXXXXXXXXXXXX} +\input{inhlist.tex} +\end{inhlist} + +\begin{theindex} +\indexinc +\end{theindex} + +\end{document} + diff --git a/dnn/test.cc b/dnn/test.cc new file mode 100644 index 0000000..e4c1b25 --- /dev/null +++ b/dnn/test.cc @@ -0,0 +1,12 @@ +#include "dnn.h" + +class A { +public: + void foo (DnnEvent&); +}; + +main () +{ + A a; + DnnReactionOf <A> r (a, &A::foo); +} diff --git a/dnn/version.h b/dnn/version.h new file mode 100644 index 0000000..20cb01a --- /dev/null +++ b/dnn/version.h @@ -0,0 +1,71 @@ +/* + * Data News Network + * + * by Stephane Chatty + * + * Copyright 1994 + * Centre d'Etudes de la Navigation Aerienne (CENA) + * + * Version and copyright header + * + * $Id$ + * $CurLog$ + */ + + +/*** + * Copyright 1994 Centre d'Etudes de la Navigation Aerienne (CENA) + * + * Permission to use, copy, and modify this software and its documentation + * for your own purposes is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and use acknowledge that the software was developed + * by Centre d'Etudes de la Navigation Aerienne, Toulouse, + * France. CENA makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + * + * This software or modified versions of this software cannot be + * distributed in source or binary form, nor included into products + * without prior written permission of the author. + * + * CENA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL LRI OR + * CENA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY + * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + *** + * + * Maintainer: + * + * Stephane Chatty e-mail: chatty@dgac.fr + * CENA + * 7 avenue Edouard Belin phone: +33 62 25 95 42 + * 31055 TOULOUSE - FRANCE fax: +33 62 25 95 99 + * +**/ + +/** +title DNN - Data News Network +subtitle ~ +version 0.1 +date February 1994 +copyright (c) 1994 CENA +authors St\'ephane Chatty +address Centre d'\'Etudes de la Navigation A\'erienne +| 7 avenue \'Edouard Belin +| 31055 Toulouse Cedex, France +e-mail chatty@dgac.fr +phone 33+ 62 25 95 42 +fax 33+ 62 25 95 99 +**/ + +#ifndef DnnVersion + +#define DnnVersion 0 +#define DnnRelease 1 +#define DnnPatchLevel 0 + +#endif |