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

« back to all changes in this revision

Viewing changes to storage/ndb/src/mgmapi/mgmapi_configuration.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) 2004-2005 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
15
 
 
16
#include <ndb_types.h>
 
17
#include <mgmapi.h>
 
18
#include "mgmapi_configuration.hpp"
 
19
#include "../mgmsrv/ConfigInfo.hpp"
 
20
 
 
21
ndb_mgm_configuration_iterator::ndb_mgm_configuration_iterator
 
22
(const ndb_mgm_configuration & conf, unsigned type_of_section)
 
23
  : m_config(conf.m_config)
 
24
{
 
25
  m_sectionNo = ~0;
 
26
  m_typeOfSection = type_of_section;
 
27
  first();
 
28
}
 
29
 
 
30
ndb_mgm_configuration_iterator::~ndb_mgm_configuration_iterator(){
 
31
  reset();
 
32
}
 
33
 
 
34
void 
 
35
ndb_mgm_configuration_iterator::reset(){
 
36
  if(m_sectionNo != (Uint32)~0){
 
37
    m_config.closeSection();
 
38
  }
 
39
}
 
40
 
 
41
 
 
42
int
 
43
ndb_mgm_configuration_iterator::enter(){
 
44
  bool ok = m_config.openSection(m_typeOfSection, m_sectionNo);
 
45
  if(ok){
 
46
    return 0;
 
47
  }
 
48
 
 
49
  reset();
 
50
  m_sectionNo = ~0;
 
51
  return -1;
 
52
}
 
53
 
 
54
int
 
55
ndb_mgm_configuration_iterator::first(){
 
56
  reset();
 
57
  m_sectionNo = 0;
 
58
  return enter();
 
59
}
 
60
 
 
61
int
 
62
ndb_mgm_configuration_iterator::next(){
 
63
  reset();
 
64
  m_sectionNo++;
 
65
  return enter();
 
66
}
 
67
 
 
68
int
 
69
ndb_mgm_configuration_iterator::valid() const {
 
70
  return m_sectionNo != (Uint32)~0;
 
71
}
 
72
 
 
73
int
 
74
ndb_mgm_configuration_iterator::find(int param, unsigned search){
 
75
  unsigned val = search + 1;
 
76
 
 
77
  while(get(param, &val) == 0 && val != search){
 
78
    if(next() != 0)
 
79
      break;
 
80
  }
 
81
  
 
82
  if(val == search)
 
83
    return 0;
 
84
  
 
85
  return -1;
 
86
}
 
87
 
 
88
int
 
89
ndb_mgm_configuration_iterator::get(int param, unsigned * value) const {
 
90
  return m_config.get(param, value) != true;
 
91
 
 
92
}
 
93
 
 
94
int 
 
95
ndb_mgm_configuration_iterator::get(int param, 
 
96
                                    unsigned long long * value) const{
 
97
  return m_config.get(param, value) != true;
 
98
}
 
99
 
 
100
int 
 
101
ndb_mgm_configuration_iterator::get(int param, const char ** value) const {
 
102
  return m_config.get(param, value) != true;
 
103
}
 
104
 
 
105
/**
 
106
 * Published C interface
 
107
 */
 
108
extern "C"
 
109
ndb_mgm_configuration_iterator* 
 
110
ndb_mgm_create_configuration_iterator(ndb_mgm_configuration * conf, 
 
111
                                      unsigned type_of_section){
 
112
  ndb_mgm_configuration_iterator* iter = (ndb_mgm_configuration_iterator*)
 
113
    malloc(sizeof(ndb_mgm_configuration_iterator));
 
114
  if(iter == 0)
 
115
    return 0;
 
116
 
 
117
  return new(iter) ndb_mgm_configuration_iterator(* conf, type_of_section);
 
118
}
 
119
 
 
120
 
 
121
extern "C"
 
122
void ndb_mgm_destroy_iterator(ndb_mgm_configuration_iterator* iter){
 
123
  if(iter != 0){
 
124
    iter->~ndb_mgm_configuration_iterator();
 
125
    free(iter);
 
126
  }
 
127
}
 
128
 
 
129
extern "C"
 
130
int 
 
131
ndb_mgm_first(ndb_mgm_configuration_iterator* iter){
 
132
  return iter->first();
 
133
}
 
134
 
 
135
extern "C"
 
136
int 
 
137
ndb_mgm_next(ndb_mgm_configuration_iterator* iter){
 
138
  return iter->next();
 
139
}
 
140
 
 
141
extern "C"
 
142
int 
 
143
ndb_mgm_valid(const ndb_mgm_configuration_iterator* iter){
 
144
  return iter->valid();
 
145
}
 
146
 
 
147
extern "C"
 
148
int 
 
149
ndb_mgm_get_int_parameter(const ndb_mgm_configuration_iterator* iter, 
 
150
                          int param, unsigned * value){
 
151
  return iter->get(param, value);
 
152
}
 
153
 
 
154
extern "C"
 
155
int 
 
156
ndb_mgm_get_int64_parameter(const ndb_mgm_configuration_iterator* iter, 
 
157
                            int param, Uint64 * value){
 
158
  return iter->get(param, value);
 
159
}
 
160
 
 
161
extern "C"
 
162
int 
 
163
ndb_mgm_get_string_parameter(const ndb_mgm_configuration_iterator* iter, 
 
164
                             int param, const char  ** value){
 
165
  return iter->get(param, value);
 
166
}
 
167
 
 
168
extern "C"
 
169
int 
 
170
ndb_mgm_find(ndb_mgm_configuration_iterator* iter,
 
171
             int param, unsigned search){
 
172
  return iter->find(param, search);
 
173
}
 
174
 
 
175
/**
 
176
 * Retrieve information about parameter
 
177
 * @param info : in - pointer to structure allocated by caller
 
178
 * @param size : in/out : pointer to int initialized to sizeof(ndb_mgm_param_info)...will be set to bytes set by function on return
 
179
*/
 
180
extern "C"
 
181
int 
 
182
ndb_mgm_get_db_parameter_info(Uint32 paramId, struct ndb_mgm_param_info * info, size_t * size) {
 
183
  if ( paramId == 0 ) {
 
184
      return -1;
 
185
  }
 
186
 
 
187
  ConfigInfo data;
 
188
  for (int i = 0; i < data.m_NoOfParams; i++) {
 
189
    if (paramId == data.m_ParamInfo[i]._paramId && strcmp("DB", data.m_ParamInfo[i]._section) == 0) {
 
190
        size_t tmp = 0;
 
191
        if (tmp + sizeof(info->m_id) <= *size)
 
192
        {
 
193
          info->m_id = data.m_ParamInfo[i]._paramId;
 
194
          tmp += sizeof(info->m_id);
 
195
        }
 
196
 
 
197
        if (tmp + sizeof(info->m_name) <= *size)
 
198
        {
 
199
          info->m_name = data.m_ParamInfo[i]._fname;
 
200
          tmp += sizeof(info->m_name);
 
201
        }
 
202
 
 
203
        *size = tmp;
 
204
        return 0;
 
205
    }
 
206
  }
 
207
  return -1;
 
208
}