libtest_b.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. struct iface_list iface_list = {
  60. .iface1_func1 = iface1_func1,
  61. .iface1_func2 = iface1_func2,
  62. .iface1_func3 = iface1_func3,
  63. };
  64. 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. struct lcr_iface iface1[2]= {
  70. /*
  71. * Version 0
  72. */
  73. {
  74. .name = "B_iface1",
  75. .version = 0,
  76. .versions_replace = 0,
  77. .versions_replace_count = 0,
  78. .dependencies = 0,
  79. .dependency_count = 0,
  80. .constructor = iface1_constructor,
  81. .destructor = iface1_destructor,
  82. .interfaces = NULL
  83. },
  84. /*
  85. * Version 1
  86. */
  87. {
  88. .name = "B_iface1",
  89. .version = 1,
  90. .versions_replace = 0,
  91. .versions_replace_count = 0,
  92. .dependencies = 0,
  93. .dependency_count = 0,
  94. .constructor = iface1_ver1_constructor,
  95. .destructor = iface1_ver1_destructor,
  96. .interfaces = NULL
  97. }
  98. };
  99. struct lcr_comp test_comp = {
  100. .iface_count = 2,
  101. .ifaces = iface1
  102. };
  103. static int iface1_constructor (void *context)
  104. {
  105. printf ("B - version 0 constructor context %p\n", context);
  106. return (0);
  107. }
  108. static void iface1_destructor (void *context)
  109. {
  110. printf ("B - version 0 destructor context %p\n", context);
  111. }
  112. static void iface1_func1 (void) {
  113. printf ("B - version 0 func1\n");
  114. }
  115. static void iface1_func2 (void) {
  116. printf ("B - version 0 func2\n");
  117. }
  118. static void iface1_func3 (void) {
  119. printf ("B - version 0 func3\n");
  120. }
  121. static int iface1_ver1_constructor (void *context)
  122. {
  123. printf ("B - version 1 constructor context %p\n", context);
  124. return (0);
  125. }
  126. static void iface1_ver1_destructor (void *context)
  127. {
  128. printf ("B - version 1 destructor context %p\n", context);
  129. }
  130. static void iface1_ver1_func1 (void) {
  131. printf ("B - version 1 func1\n");
  132. }
  133. static void iface1_ver1_func2 (void) {
  134. printf ("B - version 1 func2\n");
  135. }
  136. static void iface1_ver1_func3 (void) {
  137. printf ("B - version 1 func3\n");
  138. }
  139. __attribute__ ((constructor)) static void register_this_component (void)
  140. {
  141. lcr_interfaces_set (&iface1[0], &iface_list);
  142. lcr_interfaces_set (&iface1[1], &iface_ver1_list);
  143. lcr_component_register (&test_comp);
  144. }