callbacks.hh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Callback management
  2. Copyright (C) 2014 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. // Add a callback named NAME. FUNC is the function to call when
  35. // this method is invoked.
  36. void add_callback (const char *name, callback_ftype *func);
  37. // Look up a callback by name. Returns NULL if the method is not
  38. // found.
  39. callback_ftype *find_callback (const char *name);
  40. private:
  41. // Declared but not defined to avoid use.
  42. callbacks (const callbacks &);
  43. callbacks &operator= (const callbacks &);
  44. // The mapping.
  45. htab_t m_registry;
  46. };
  47. };
  48. #endif // CC1_PLUGIN_CALLBACKS_HH