MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mgmapi_configuration.cpp
1 /*
2  Copyright (C) 2004-2007 MySQL AB, 2008 Sun Microsystems, Inc.
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include <ndb_types.h>
20 #include <mgmapi.h>
21 #include "mgmapi_configuration.hpp"
22 #include "../mgmsrv/ConfigInfo.hpp"
23 
25 (const ndb_mgm_configuration & conf, unsigned type_of_section)
26  : m_config(conf.m_config)
27 {
28  m_sectionNo = ~0;
29  m_typeOfSection = type_of_section;
30  first();
31 }
32 
33 ndb_mgm_configuration_iterator::~ndb_mgm_configuration_iterator(){
34  reset();
35 }
36 
37 void
38 ndb_mgm_configuration_iterator::reset(){
39  if(m_sectionNo != (Uint32)~0){
40  m_config.closeSection();
41  }
42 }
43 
44 
45 int
46 ndb_mgm_configuration_iterator::enter(){
47  bool ok = m_config.openSection(m_typeOfSection, m_sectionNo);
48  if(ok){
49  return 0;
50  }
51 
52  reset();
53  m_sectionNo = ~0;
54  return -1;
55 }
56 
57 int
58 ndb_mgm_configuration_iterator::first(){
59  reset();
60  m_sectionNo = 0;
61  return enter();
62 }
63 
64 int
65 ndb_mgm_configuration_iterator::next(){
66  reset();
67  m_sectionNo++;
68  return enter();
69 }
70 
71 int
72 ndb_mgm_configuration_iterator::valid() const {
73  return m_sectionNo != (Uint32)~0;
74 }
75 
76 int
77 ndb_mgm_configuration_iterator::find(int param, unsigned search){
78  unsigned val = search + 1;
79 
80  while(get(param, &val) == 0 && val != search){
81  if(next() != 0)
82  break;
83  }
84 
85  if(val == search)
86  return 0;
87 
88  return -1;
89 }
90 
91 int
92 ndb_mgm_configuration_iterator::get(int param, unsigned * value) const {
93  return m_config.get(param, value) != true;
94 
95 }
96 
97 int
98 ndb_mgm_configuration_iterator::get(int param,
99  unsigned long long * value) const{
100  return m_config.get(param, value) != true;
101 }
102 
103 int
104 ndb_mgm_configuration_iterator::get(int param, const char ** value) const {
105  return m_config.get(param, value) != true;
106 }
107 
111 extern "C"
114  unsigned type_of_section){
116  malloc(sizeof(ndb_mgm_configuration_iterator));
117  if(iter == 0)
118  return 0;
119 
120  return new(iter) ndb_mgm_configuration_iterator(* conf, type_of_section);
121 }
122 
123 
124 extern "C"
125 void ndb_mgm_destroy_iterator(ndb_mgm_configuration_iterator* iter){
126  if(iter != 0){
127  iter->~ndb_mgm_configuration_iterator();
128  free(iter);
129  }
130 }
131 
132 extern "C"
133 int
134 ndb_mgm_first(ndb_mgm_configuration_iterator* iter){
135  return iter->first();
136 }
137 
138 extern "C"
139 int
140 ndb_mgm_next(ndb_mgm_configuration_iterator* iter){
141  return iter->next();
142 }
143 
144 extern "C"
145 int
146 ndb_mgm_valid(const ndb_mgm_configuration_iterator* iter){
147  return iter->valid();
148 }
149 
150 extern "C"
151 int
152 ndb_mgm_get_int_parameter(const ndb_mgm_configuration_iterator* iter,
153  int param, unsigned * value){
154  return iter->get(param, value);
155 }
156 
157 extern "C"
158 int
159 ndb_mgm_get_int64_parameter(const ndb_mgm_configuration_iterator* iter,
160  int param, Uint64 * value){
161  return iter->get(param, value);
162 }
163 
164 extern "C"
165 int
166 ndb_mgm_get_string_parameter(const ndb_mgm_configuration_iterator* iter,
167  int param, const char ** value){
168  return iter->get(param, value);
169 }
170 
171 extern "C"
172 int
173 ndb_mgm_find(ndb_mgm_configuration_iterator* iter,
174  int param, unsigned search){
175  return iter->find(param, search);
176 }
177 
183 extern "C"
184 int
185 ndb_mgm_get_db_parameter_info(Uint32 paramId, struct ndb_mgm_param_info * info, size_t * size) {
186  if ( paramId == 0 ) {
187  return -1;
188  }
189 
190  ConfigInfo data;
191  (void)data;
192  for (int i = 0; i < data.m_NoOfParams; i++) {
193  if (paramId == data.m_ParamInfo[i]._paramId && strcmp("DB", data.m_ParamInfo[i]._section) == 0) {
194  size_t tmp = 0;
195  if (tmp + sizeof(info->m_id) <= *size)
196  {
197  info->m_id = data.m_ParamInfo[i]._paramId;
198  tmp += sizeof(info->m_id);
199  }
200 
201  if (tmp + sizeof(info->m_name) <= *size)
202  {
203  info->m_name = data.m_ParamInfo[i]._fname;
204  tmp += sizeof(info->m_name);
205  }
206 
207  *size = tmp;
208  return 0;
209  }
210  }
211  return -1;
212 }