interface_implementation.h 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. (c) Copyright 2001-2009 The world wide DirectFB Open Source Community (directfb.org)
  3. (c) Copyright 2000-2004 Convergence (integrated media) GmbH
  4. All rights reserved.
  5. Written by Denis Oliver Kropp <dok@directfb.org>,
  6. Andreas Hundt <andi@fischlustig.de>,
  7. Sven Neumann <neo@directfb.org>,
  8. Ville Syrjälä <syrjala@sci.fi> and
  9. Claudio Ciccani <klan@users.sf.net>.
  10. This library is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU Lesser General Public
  12. License as published by the Free Software Foundation; either
  13. version 2 of the License, or (at your option) any later version.
  14. This library is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. Lesser General Public License for more details.
  18. You should have received a copy of the GNU Lesser General Public
  19. License along with this library; if not, write to the
  20. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21. Boston, MA 02111-1307, USA.
  22. */
  23. #ifndef __DIRECT__INTERFACE_IMPLEMENTATION_H__
  24. #define __DIRECT__INTERFACE_IMPLEMENTATION_H__
  25. #include <direct/interface.h>
  26. static const char *GetType( void );
  27. static const char *GetImplementation( void );
  28. static DirectResult Allocate( void **interface );
  29. static DirectInterfaceFuncs interface_funcs = {
  30. .GetType = GetType,
  31. .GetImplementation = GetImplementation,
  32. .Allocate = Allocate,
  33. .Probe = (DirectInterfaceGenericProbeFunc) Probe,
  34. .Construct = (DirectInterfaceGenericConstructFunc) Construct
  35. };
  36. #define DIRECT_INTERFACE_IMPLEMENTATION(type, impl) \
  37. \
  38. static const char * \
  39. GetType( void ) \
  40. { \
  41. return #type; \
  42. } \
  43. \
  44. static const char * \
  45. GetImplementation( void ) \
  46. { \
  47. return #impl; \
  48. } \
  49. \
  50. static DirectResult \
  51. Allocate( void **interface ) \
  52. { \
  53. DIRECT_ALLOCATE_INTERFACE( *interface, type ); \
  54. return DR_OK; \
  55. } \
  56. \
  57. __attribute__((constructor)) \
  58. void \
  59. type##_##impl##_ctor(void); \
  60. \
  61. __attribute__((constructor)) \
  62. void \
  63. type##_##impl##_ctor(void) \
  64. { \
  65. DirectRegisterInterface( &interface_funcs ); \
  66. } \
  67. \
  68. __attribute__((destructor)) \
  69. void \
  70. type##_##impl##_dtor(void); \
  71. \
  72. __attribute__((destructor)) \
  73. void \
  74. type##_##impl##_dtor(void) \
  75. { \
  76. DirectUnregisterInterface( &interface_funcs ); \
  77. }
  78. #endif