1 /*
2  *  KCemu -- The emulator for the KC85 homecomputer series and much more.
3  *  Copyright (C) 1997-2010 Torsten Paul
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License along
16  *  with this program; if not, write to the Free Software Foundation, Inc.,
17  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef __kc_cb_list_h
21 #define __kc_cb_list_h
22 
23 #include "kc/cb.h"
24 
25 class CallbackListEntry
26 {
27  private:
28   enum {
29     CALLBACK_LIST_ALLOC_SIZE = 1000
30   };
31 
32  protected:
33   /**
34    *  time value of the callback entry
35    */
36   unsigned long long _value;
37 
38   /**
39    *  the Callback that will be run
40    */
41   Callback *_cb;
42 
43   /**
44    *  arbitrary data that can be set by the
45    *  routine registering a callback
46    */
47   void *_data;
48 
49   /**
50    *  single linked list
51    */
52   CallbackListEntry *_next;
53 
54   static CallbackListEntry *_free_list;
55 
56   static void alloc_entries(void);
57   static void free_entries(void);
58 
59  public:
60   CallbackListEntry(unsigned long long value,
61 		    Callback *cb,
62 		    void *data,
63 		    CallbackListEntry *next);
64   virtual ~CallbackListEntry(void);
65 
66   void * operator new(size_t size);
67   void operator delete(void *p);
68 
69   friend class CallbackList;
70 };
71 
72 class CallbackList
73 {
74  private:
75   CallbackListEntry *_list;
76 
77  public:
78   CallbackList(void);
79   virtual ~CallbackList(void);
80 
81   void clear();
82   void add_callback(unsigned long long offset, Callback *cb, void *data);
83   void run_callbacks(unsigned long long value);
84   void remove_callback_listener(Callback *cb);
85 };
86 
87 #endif /* __kc_cb_list_h */
88