| 1 |
/* Callback management |
| 2 |
Copyright (C) 2014-2025 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is part of GCC. |
| 5 |
|
| 6 |
GCC is free software; you can redistribute it and/or modify it under |
| 7 |
the terms of the GNU General Public License as published by the Free |
| 8 |
Software Foundation; either version 3, or (at your option) any later |
| 9 |
version. |
| 10 |
|
| 11 |
GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 |
WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 |
for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with GCC; see the file COPYING3. If not see |
| 18 |
<http://www.gnu.org/licenses/>. */ |
| 19 |
|
| 20 |
#ifndef CC1_PLUGIN_CALLBACKS_HH |
| 21 |
#define CC1_PLUGIN_CALLBACKS_HH |
| 22 |
|
| 23 |
#include "status.hh" |
| 24 |
#include "hashtab.h" |
| 25 |
|
| 26 |
namespace cc1_plugin |
| 27 |
{ |
| 28 |
class connection; |
| 29 |
|
| 30 |
// The type of a callback method. |
| 31 |
typedef status callback_ftype (connection *); |
| 32 |
|
| 33 |
// This class manages callback functions. A callback has a name and |
| 34 |
// an underlying function. When a query packet arrives, the name is |
| 35 |
// inspected and the corresponding function is called. A callback |
| 36 |
// function has to know how to decode its own arguments, but |
| 37 |
// wrappers are provided elsewhere to automate this. |
| 38 |
class callbacks |
| 39 |
{ |
| 40 |
public: |
| 41 |
|
| 42 |
callbacks (); |
| 43 |
~callbacks (); |
| 44 |
|
| 45 |
callbacks (const callbacks &) = delete; |
| 46 |
callbacks &operator= (const callbacks &) = delete; |
| 47 |
|
| 48 |
// Add a callback named NAME. FUNC is the function to call when |
| 49 |
// this method is invoked. |
| 50 |
void add_callback (const char *name, callback_ftype *func); |
| 51 |
|
| 52 |
// Look up a callback by name. Returns NULL if the method is not |
| 53 |
// found. |
| 54 |
callback_ftype *find_callback (const char *name); |
| 55 |
|
| 56 |
private: |
| 57 |
|
| 58 |
// The mapping. |
| 59 |
htab_t m_registry; |
| 60 |
}; |
| 61 |
}; |
| 62 |
|
| 63 |
#endif // CC1_PLUGIN_CALLBACKS_HH |