libtest_a.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright (C) 2006 Steven Dake (sdake@mvista.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 <stdio.h>
  31. #include "lcr_comp.h"
  32. /*
  33. * Version 0 of the interface
  34. */
  35. static int iface1_constructor (void *context);
  36. static void iface1_destructor (void *context);
  37. static void iface1_func1 (void);
  38. static void iface1_func2 (void);
  39. static void iface1_func3 (void);
  40. /*
  41. * Version 1 of the interface
  42. */
  43. static int iface1_ver1_constructor (void *context);
  44. static void iface1_ver1_destructor (void *context);
  45. static void iface1_ver1_func1 (void);
  46. static void iface1_ver1_func2 (void);
  47. static void iface1_ver1_func3 (void);
  48. struct iface_list {
  49. void (*iface1_func1)(void);
  50. void (*iface1_func2)(void);
  51. void (*iface1_func3)(void);
  52. };
  53. struct iface_ver1_list {
  54. void (*iface1_ver1_func1)(void);
  55. void (*iface1_ver1_func2)(void);
  56. void (*iface1_ver1_func3)(void);
  57. };
  58. static struct iface_list iface_list = {
  59. .iface1_func1 = iface1_func1,
  60. .iface1_func2 = iface1_func2,
  61. .iface1_func3 = iface1_func3,
  62. };
  63. static struct iface_list iface_ver1_list = {
  64. .iface1_func1 = iface1_ver1_func1,
  65. .iface1_func2 = iface1_ver1_func2,
  66. .iface1_func3 = iface1_ver1_func3,
  67. };
  68. static struct lcr_iface iface1[2] = {
  69. /* version 0 */
  70. {
  71. .name = "A_iface1",
  72. .version = 0,
  73. .versions_replace = 0,
  74. .versions_replace_count = 0,
  75. .dependencies = 0,
  76. .dependency_count = 0,
  77. .constructor = iface1_constructor,
  78. .destructor = iface1_destructor,
  79. .interfaces = NULL
  80. },
  81. /* version 1 */
  82. {
  83. .name = "A_iface1",
  84. .version = 1,
  85. .versions_replace = 0,
  86. .versions_replace_count = 0,
  87. .dependencies = 0,
  88. .dependency_count = 0,
  89. .constructor = iface1_ver1_constructor,
  90. .destructor = iface1_ver1_destructor,
  91. .interfaces = NULL
  92. }
  93. };
  94. static struct lcr_comp test_comp = {
  95. .iface_count = 2,
  96. .ifaces = iface1
  97. };
  98. static int iface1_constructor (void *context)
  99. {
  100. printf ("A - version 0 constructor context %p\n", context);
  101. return (0);
  102. }
  103. static void iface1_destructor (void *context)
  104. {
  105. printf ("A - version 0 destructor context %p\n", context);
  106. }
  107. static void iface1_func1 (void) {
  108. printf ("A - version 0 func1\n");
  109. }
  110. static void iface1_func2 (void) {
  111. printf ("A - version 0 func2\n");
  112. }
  113. static void iface1_func3 (void) {
  114. printf ("A - version 0 func3\n");
  115. }
  116. static int iface1_ver1_constructor (void *context)
  117. {
  118. printf ("A - version 1 constructor context %p\n", context);
  119. return (0);
  120. }
  121. static void iface1_ver1_destructor (void *context)
  122. {
  123. printf ("A - version 1 destructor context %p\n", context);
  124. }
  125. static void iface1_ver1_func1 (void) {
  126. printf ("A - version 1 func1\n");
  127. }
  128. static void iface1_ver1_func2 (void) {
  129. printf ("A - version 1 func2\n");
  130. }
  131. static void iface1_ver1_func3 (void) {
  132. printf ("A - version 1 func3\n");
  133. }
  134. __attribute__ ((constructor)) static void register_this_component (void) {
  135. lcr_interfaces_set (&iface1[0], &iface_list);
  136. lcr_interfaces_set (&iface1[1], &iface_ver1_list);
  137. lcr_component_register (&test_comp);
  138. }