libtest_a.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * Copyright (C) 2006 Steven Dake (sdake@redhat.com)
  3. *
  4. * This software licensed under BSD license, the text of which follows:
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * - Redistributions of source code must retain the above copyright notice,
  10. * this list of conditions and the following disclaimer.
  11. * - Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  15. * contributors may be used to endorse or promote products derived from this
  16. * software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  22. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  28. * THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #include <config.h>
  31. #include <stdio.h>
  32. #include <corosync/lcr/lcr_comp.h>
  33. /*
  34. * Version 0 of the interface
  35. */
  36. static int iface1_constructor (void *context);
  37. static void iface1_destructor (void *context);
  38. static void iface1_func1 (void);
  39. static void iface1_func2 (void);
  40. static void iface1_func3 (void);
  41. /*
  42. * Version 1 of the interface
  43. */
  44. static int iface1_ver1_constructor (void *context);
  45. static void iface1_ver1_destructor (void *context);
  46. static void iface1_ver1_func1 (void);
  47. static void iface1_ver1_func2 (void);
  48. static void iface1_ver1_func3 (void);
  49. struct iface_list {
  50. void (*iface1_func1)(void);
  51. void (*iface1_func2)(void);
  52. void (*iface1_func3)(void);
  53. };
  54. struct iface_ver1_list {
  55. void (*iface1_ver1_func1)(void);
  56. void (*iface1_ver1_func2)(void);
  57. void (*iface1_ver1_func3)(void);
  58. };
  59. static struct iface_list iface_list = {
  60. .iface1_func1 = iface1_func1,
  61. .iface1_func2 = iface1_func2,
  62. .iface1_func3 = iface1_func3,
  63. };
  64. static struct iface_list iface_ver1_list = {
  65. .iface1_func1 = iface1_ver1_func1,
  66. .iface1_func2 = iface1_ver1_func2,
  67. .iface1_func3 = iface1_ver1_func3,
  68. };
  69. static struct lcr_iface iface1[2] = {
  70. /* version 0 */
  71. {
  72. .name = "A_iface1",
  73. .version = 0,
  74. .versions_replace = 0,
  75. .versions_replace_count = 0,
  76. .dependencies = 0,
  77. .dependency_count = 0,
  78. .constructor = iface1_constructor,
  79. .destructor = iface1_destructor,
  80. .interfaces = NULL
  81. },
  82. /* version 1 */
  83. {
  84. .name = "A_iface1",
  85. .version = 1,
  86. .versions_replace = 0,
  87. .versions_replace_count = 0,
  88. .dependencies = 0,
  89. .dependency_count = 0,
  90. .constructor = iface1_ver1_constructor,
  91. .destructor = iface1_ver1_destructor,
  92. .interfaces = NULL
  93. }
  94. };
  95. static struct lcr_comp test_comp = {
  96. .iface_count = 2,
  97. .ifaces = iface1
  98. };
  99. static int iface1_constructor (void *context)
  100. {
  101. printf ("A - version 0 constructor context %p\n", context);
  102. return (0);
  103. }
  104. static void iface1_destructor (void *context)
  105. {
  106. printf ("A - version 0 destructor context %p\n", context);
  107. }
  108. static void iface1_func1 (void) {
  109. printf ("A - version 0 func1\n");
  110. }
  111. static void iface1_func2 (void) {
  112. printf ("A - version 0 func2\n");
  113. }
  114. static void iface1_func3 (void) {
  115. printf ("A - version 0 func3\n");
  116. }
  117. static int iface1_ver1_constructor (void *context)
  118. {
  119. printf ("A - version 1 constructor context %p\n", context);
  120. return (0);
  121. }
  122. static void iface1_ver1_destructor (void *context)
  123. {
  124. printf ("A - version 1 destructor context %p\n", context);
  125. }
  126. static void iface1_ver1_func1 (void) {
  127. printf ("A - version 1 func1\n");
  128. }
  129. static void iface1_ver1_func2 (void) {
  130. printf ("A - version 1 func2\n");
  131. }
  132. static void iface1_ver1_func3 (void) {
  133. printf ("A - version 1 func3\n");
  134. }
  135. __attribute__ ((constructor)) static void register_this_component (void) {
  136. lcr_interfaces_set (&iface1[0], &iface_list);
  137. lcr_interfaces_set (&iface1[1], &iface_ver1_list);
  138. lcr_component_register (&test_comp);
  139. }