callbacks.hh 1.8 KB

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