rasdaman complete source
callbackmgr.hh
Go to the documentation of this file.
1 /*
2 * This file is part of rasdaman community.
3 *
4 * Rasdaman community is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Rasdaman community is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
18 rasdaman GmbH.
19 *
20 * For more information please see <http://www.rasdaman.org>
21 * or contact Peter Baumann via <baumann@rasdaman.com>.
22 /
34 #ifndef _CALLBACK_MANAGER_
35 #define _CALLBACK_MANAGER_
36 
37 
38 //@ManMemo: Module: {\bf servercomm}
39 
40 /*@Doc:
41  The class CallBackManager stores function- and context pointers
42  that are executed in the order they were registered in when
43  calling executePending(). This system replaces the alarm handler
44  approach formerly used which suffered from a restrictive
45  environment where mallocs and printfs were not legal. Since
46  neither call must happen when a callback function is registered
47  the maximum number of callbacks must be fixed in the constructor.
48 */
49 
50 class CallBackManager
51 {
52 public:
54  CallBackManager(unsigned int size=1024);
60  ~CallBackManager(void);
62 
64  void setMaximumSize(unsigned int size);
65 
67  typedef void (*callback_f)(void*);
74  int registerCallback(callback_f function, void *context);
83  int registerUniqueCallback(callback_f function, void *context);
90  int removeCallback(callback_f function, void *context);
97  unsigned int getNumCallbacks(void) const;
99 
101  int executePending(void);
108 private:
109 
111  int findCallback(callback_f function, void *context) const;
117 
118  typedef struct callback_desc_s
119  {
120  callback_f function;
121  void *context;
122  } callback_desc_t;
124 
125  callback_desc_t *callbacks;
126 
128  unsigned int maxCallbacks;
129 
131  unsigned int numPending;
132 
134  int overflowDetected;
135 };
136 
137 #endif