print.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * Copyright (c) 2002-2004 MontaVista Software, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake (sdake@mvista.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <stdio.h>
  35. #include <string.h>
  36. #include <stdarg.h>
  37. #include "print.h"
  38. #include "parse.h"
  39. #include "../include/ais_types.h"
  40. /*
  41. * logging printf
  42. */
  43. void
  44. internal_log_printf (int level, char *string, ...)
  45. {
  46. va_list ap;
  47. char newstring[1024];
  48. va_start(ap, string);
  49. sprintf (newstring, "L(%x): %s", level, string);
  50. vfprintf(stderr, newstring, ap);
  51. va_end(ap);
  52. }
  53. void
  54. internal_log_printf_checkdebug (int level, char *string, ...)
  55. {
  56. va_list ap;
  57. char newstring[1024];
  58. va_start(ap, string);
  59. #ifdef DEBUG
  60. sprintf (newstring, "L(%x): %s", level, string);
  61. vfprintf(stderr, newstring, ap);
  62. #else
  63. if (level != LOG_LEVEL_DEBUG) {
  64. sprintf (newstring, "L(%x): %s", level, string);
  65. vfprintf(stderr, newstring, ap);
  66. }
  67. #endif
  68. va_end(ap);
  69. }
  70. char *getSaNameT (SaNameT *name)
  71. {
  72. static char ret_name[300];
  73. memset (ret_name, 0, sizeof (ret_name));
  74. if (name->length > 299) {
  75. memcpy (ret_name, name->value, 299);
  76. } else {
  77. memcpy (ret_name, name->value, name->length);
  78. }
  79. return (ret_name);
  80. }
  81. #ifdef DEBUG
  82. extern char *getSaClmNodeAddressT (SaClmNodeAddressT *nodeAddress) {
  83. int i;
  84. static char node_address[300];
  85. int pos;
  86. for (i = 0, pos = 0; i < nodeAddress->length; i++) {
  87. pos += sprintf (&node_address[pos], "%d.", nodeAddress->value[i]);
  88. }
  89. return (node_address);
  90. }
  91. void printSaClmClusterNodeT (char *description, SaClmClusterNodeT *clusterNode) {
  92. log_printf (LOG_LEVEL_NOTICE, "Node Information for %s:\n", description);
  93. log_printf (LOG_LEVEL_NOTICE, "\tnode id is %x\n", (int)clusterNode->nodeId);
  94. log_printf (LOG_LEVEL_NOTICE, "\tnode address is %s\n", getSaClmNodeAddressT (&clusterNode->nodeAddress));
  95. log_printf (LOG_LEVEL_NOTICE, "\tnode name is %s.\n", getSaNameT (&clusterNode->nodeName));
  96. log_printf (LOG_LEVEL_NOTICE, "\tcluster name is %s.\n", getSaNameT (&clusterNode->clusterName));
  97. log_printf (LOG_LEVEL_NOTICE, "\tMember is %d\n", clusterNode->member);
  98. log_printf (LOG_LEVEL_NOTICE, "\tTimestamp is %llx nanoseconds\n", clusterNode->bootTimestamp);
  99. }
  100. #endif /* DEBUG */
  101. #ifdef CODE_COVERAGE_COMPILE_OUT
  102. void saAmfPrintGroups (void)
  103. {
  104. struct list_head *AmfGroupList;
  105. struct list_head *AmfUnitList;
  106. struct list_head *AmfComponentList;
  107. struct list_head *AmfProtectionGroupList;
  108. struct saAmfGroup *saAmfGroup;
  109. struct saAmfUnit *AmfUnit;
  110. struct saAmfComponent *AmfComponent;
  111. struct saAmfProtectionGroup *AmfProtectionGroup;
  112. for (AmfGroupList = saAmfGroupHead.next;
  113. AmfGroupList != &saAmfGroupHead;
  114. AmfGroupList = AmfGroupList->next) {
  115. saAmfGroup = list_entry (AmfGroupList,
  116. struct saAmfGroup, saAmfGroupList);
  117. log_printf (LOG_LEVEL_DEBUG, "group {\n");
  118. log_printf (LOG_LEVEL_DEBUG, "\tname = ", getSaNameT (&saAmfGroup->name));
  119. log_printf (LOG_LEVEL_DEBUG, "\tmodel = %d\n", saAmfGroup->model);
  120. log_printf (LOG_LEVEL_DEBUG, "\tactive-units = %d\n", (int)saAmfGroup->saAmfActiveUnitsDesired);
  121. log_printf (LOG_LEVEL_DEBUG, "\tbackup-units = %d\n", (int)saAmfGroup->saAmfStandbyUnitsDesired);
  122. for (AmfUnitList = saAmfGroup->saAmfUnitHead.next;
  123. AmfUnitList != &saAmfGroup->saAmfUnitHead;
  124. AmfUnitList = AmfUnitList->next) {
  125. AmfUnit = list_entry (AmfUnitList,
  126. struct saAmfUnit, saAmfUnitList);
  127. log_printf (LOG_LEVEL_DEBUG, "\tunit {\n");
  128. log_printf (LOG_LEVEL_DEBUG, "\t\tname = ", getSaNameT (&AmfUnit->name));
  129. for (AmfComponentList = AmfUnit->saAmfComponentHead.next;
  130. AmfComponentList != &AmfUnit->saAmfComponentHead;
  131. AmfComponentList = AmfComponentList->next) {
  132. AmfComponent = list_entry (AmfComponentList,
  133. struct saAmfComponent, saAmfComponentList);
  134. log_printf (LOG_LEVEL_DEBUG, "\t\tcomponent {\n");
  135. log_printf (LOG_LEVEL_DEBUG, "\t\t\tname = ", getSaNameT (&AmfComponent->name));
  136. log_printf (LOG_LEVEL_DEBUG, "\t\t\tmodel = %d\n", AmfComponent->componentCapabilityModel);
  137. log_printf (LOG_LEVEL_DEBUG, "\t\t}\n");
  138. }
  139. log_printf (LOG_LEVEL_DEBUG, "\t}\n");
  140. }
  141. for (AmfProtectionGroupList = saAmfGroup->saAmfProtectionGroupHead.next;
  142. AmfProtectionGroupList != &saAmfGroup->saAmfProtectionGroupHead;
  143. AmfProtectionGroupList = AmfProtectionGroupList->next) {
  144. AmfProtectionGroup = list_entry (AmfProtectionGroupList,
  145. struct saAmfProtectionGroup, saAmfProtectionGroupList);
  146. log_printf (LOG_LEVEL_DEBUG, "\tprotection {\n");
  147. log_printf (LOG_LEVEL_DEBUG, "\t\tname = ", getSaNameT (&AmfProtectionGroup->name));
  148. for (AmfComponentList = AmfProtectionGroup->saAmfMembersHead.next;
  149. AmfComponentList != &AmfProtectionGroup->saAmfMembersHead;
  150. AmfComponentList = AmfComponentList->next) {
  151. AmfComponent = list_entry (AmfComponentList,
  152. struct saAmfComponent, saAmfProtectionGroupList);
  153. log_printf (LOG_LEVEL_DEBUG, "\t\tmember = ", getSaNameT (&AmfComponent->name));
  154. }
  155. log_printf (LOG_LEVEL_DEBUG, "\t}\n");
  156. }
  157. log_printf (LOG_LEVEL_DEBUG, "}\n");
  158. }
  159. }
  160. #endif /* CODE_COVERAGE_COMPILE_OUT */