~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/src/common/debugger/DebuggerNames.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#include <ndb_global.h>
 
17
#include <BaseString.hpp>
 
18
 
 
19
#include "DebuggerNames.hpp"
 
20
 
 
21
#include <BlockNumbers.h>
 
22
#include <GlobalSignalNumbers.h>
 
23
#include <signaldata/SignalDataPrint.hpp>
 
24
 
 
25
static const char *            localSignalNames[MAX_GSN+1];
 
26
static SignalDataPrintFunction localPrintFunctions[MAX_GSN+1];
 
27
static const char *            localBlockNames[NO_OF_BLOCKS]; 
 
28
 
 
29
static
 
30
int
 
31
initSignalNames(const char * dst[], const GsnName src[], unsigned short len){
 
32
  unsigned i;
 
33
  for(i = 0; i<=MAX_GSN; i++)
 
34
    dst[i] = 0;
 
35
  
 
36
  for(i = 0; i<len; i++){
 
37
    unsigned short gsn = src[i].gsn;
 
38
    const char * name  = src[i].name;
 
39
    
 
40
    if(dst[gsn] != 0 && name != 0){
 
41
      if(strcmp(dst[gsn], name) != 0){
 
42
        fprintf(stderr, 
 
43
                "Multiple definition of signal name for gsn: %d (%s, %s)\n", 
 
44
                gsn, dst[gsn], name);
 
45
        exit(0);
 
46
      }
 
47
    }
 
48
    dst[gsn] = name;
 
49
  }
 
50
  return 0;
 
51
}
 
52
 
 
53
static
 
54
int
 
55
initSignalPrinters(SignalDataPrintFunction dst[], 
 
56
                   const NameFunctionPair src[]){
 
57
  unsigned i;
 
58
  for(i = 0; i<=MAX_GSN; i++)
 
59
    dst[i] = 0;
 
60
  
 
61
  unsigned short gsn;
 
62
  for(i = 0; (gsn = src[i].gsn) > 0; i++){
 
63
    SignalDataPrintFunction fun = src[i].function;
 
64
    
 
65
    if(dst[gsn] != 0 && fun != 0){
 
66
      if(dst[gsn] != fun){
 
67
        fprintf(stderr, 
 
68
                "Multiple definition of signal print function for gsn: %d\n", 
 
69
                gsn);
 
70
        exit(0);
 
71
      }
 
72
    }
 
73
    dst[gsn] = fun;
 
74
  }
 
75
  return 0;
 
76
}
 
77
 
 
78
static
 
79
int
 
80
initBlockNames(const char * dst[],
 
81
               const BlockName src[],
 
82
               unsigned len){
 
83
  unsigned i;
 
84
  for(i = 0; i<NO_OF_BLOCKS; i++)
 
85
    dst[i] = 0;
 
86
 
 
87
  for(i = 0; i<len; i++){
 
88
    const int index = src[i].number - MIN_BLOCK_NO;
 
89
    if(index < 0 && index >= NO_OF_BLOCKS || dst[index] != 0){
 
90
      fprintf(stderr, 
 
91
              "Invalid block name definition: %d %s\n",
 
92
              src[i].number, src[i].name);
 
93
      exit(0);
 
94
    }
 
95
    dst[index] = src[i].name;
 
96
  }
 
97
  return 0;
 
98
}
 
99
 
 
100
/**
 
101
 * Run static initializer
 
102
 */
 
103
static const int 
 
104
xxx_DUMMY_SIGNAL_NAMES_xxx = initSignalNames(localSignalNames, 
 
105
                                             SignalNames, 
 
106
                                             NO_OF_SIGNAL_NAMES);
 
107
static const int 
 
108
xxx_DUMMY_PRINT_FUNCTIONS_xxx  = initSignalPrinters(localPrintFunctions, 
 
109
                                                    SignalDataPrintFunctions);
 
110
 
 
111
static const int
 
112
xxx_DUMMY_BLOCK_NAMES_xxx = initBlockNames(localBlockNames,
 
113
                                           BlockNames,
 
114
                                           NO_OF_BLOCK_NAMES);
 
115
 
 
116
const char * 
 
117
getSignalName(unsigned short gsn, const char * defVal){
 
118
  if(gsn > 0 && gsn <= MAX_GSN)
 
119
    return (localSignalNames[gsn] ? localSignalNames[gsn] : defVal);
 
120
  return defVal;
 
121
}
 
122
 
 
123
unsigned short
 
124
getGsn(const char * signalName){
 
125
  return 0;
 
126
}
 
127
 
 
128
const char * 
 
129
getBlockName(unsigned short blockNo, const char * ret){
 
130
  if(blockNo >= MIN_BLOCK_NO && blockNo <= MAX_BLOCK_NO)
 
131
    return localBlockNames[blockNo-MIN_BLOCK_NO];
 
132
  if (ret == 0) {
 
133
    static char buf[20];
 
134
    BaseString::snprintf(buf, sizeof(buf), "BLOCK#%d", (int)blockNo);
 
135
    return buf;
 
136
  }
 
137
  return ret;
 
138
}  
 
139
 
 
140
unsigned short
 
141
getBlockNo(const char * blockName){
 
142
  for(int i = 0; i<NO_OF_BLOCKS; i++)
 
143
    if(localBlockNames[i] != 0 && strcmp(localBlockNames[i], blockName) == 0)
 
144
      return i + MIN_BLOCK_NO;
 
145
  return 0;
 
146
}
 
147
 
 
148
SignalDataPrintFunction
 
149
findPrintFunction(unsigned short gsn){
 
150
  if(gsn > 0 && gsn <= MAX_GSN)
 
151
    return localPrintFunctions[gsn];
 
152
  return 0;
 
153
}