Commit 3c33df38 authored by petr@mysql.com's avatar petr@mysql.com

more review fixes

parent 73aeeaf4
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
#include "command.h" #include "command.h"
Command::Command(Instance_map *imap_arg) Command::Command(Instance_map *instance_map_arg)
:instance_map(imap_arg) :instance_map(instance_map_arg)
{} {}
Command::~Command() Command::~Command()
......
...@@ -60,7 +60,7 @@ int Show_instances::do_command(struct st_net *net) ...@@ -60,7 +60,7 @@ int Show_instances::do_command(struct st_net *net)
{ {
Instance *instance; Instance *instance;
Imap_iterator iterator(instance_map); Instance_map::Iterator iterator(instance_map);
instance_map->lock(); instance_map->lock();
while (instance= iterator.next()) while (instance= iterator.next())
...@@ -110,9 +110,9 @@ int Flush_instances::execute(struct st_net *net, ulong connection_id) ...@@ -110,9 +110,9 @@ int Flush_instances::execute(struct st_net *net, ulong connection_id)
/* implementation for Show_instance_status: */ /* implementation for Show_instance_status: */
Show_instance_status::Show_instance_status(Instance_map *imap_arg, Show_instance_status::Show_instance_status(Instance_map *instance_map_arg,
const char *name, uint len) const char *name, uint len)
:Command(imap_arg) :Command(instance_map_arg)
{ {
Instance *instance; Instance *instance;
...@@ -212,9 +212,9 @@ int Show_instance_status::execute(struct st_net *net, ulong connection_id) ...@@ -212,9 +212,9 @@ int Show_instance_status::execute(struct st_net *net, ulong connection_id)
/* Implementation for Show_instance_options */ /* Implementation for Show_instance_options */
Show_instance_options::Show_instance_options(Instance_map *imap_arg, Show_instance_options::Show_instance_options(Instance_map *instance_map_arg,
const char *name, uint len): const char *name, uint len):
Command(imap_arg) Command(instance_map_arg)
{ {
Instance *instance; Instance *instance;
...@@ -333,9 +333,9 @@ int Show_instance_options::execute(struct st_net *net, ulong connection_id) ...@@ -333,9 +333,9 @@ int Show_instance_options::execute(struct st_net *net, ulong connection_id)
/* Implementation for Start_instance */ /* Implementation for Start_instance */
Start_instance::Start_instance(Instance_map *imap_arg, Start_instance::Start_instance(Instance_map *instance_map_arg,
const char *name, uint len) const char *name, uint len)
:Command(imap_arg) :Command(instance_map_arg)
{ {
/* we make a search here, since we don't want t store the name */ /* we make a search here, since we don't want t store the name */
if (instance= instance_map->find(name, len)) if (instance= instance_map->find(name, len))
...@@ -366,9 +366,9 @@ int Start_instance::execute(struct st_net *net, ulong connection_id) ...@@ -366,9 +366,9 @@ int Start_instance::execute(struct st_net *net, ulong connection_id)
/* Implementation for Stop_instance: */ /* Implementation for Stop_instance: */
Stop_instance::Stop_instance(Instance_map *imap_arg, Stop_instance::Stop_instance(Instance_map *instance_map_arg,
const char *name, uint len) const char *name, uint len)
:Command(imap_arg) :Command(instance_map_arg)
{ {
/* we make a search here, since we don't want t store the name */ /* we make a search here, since we don't want t store the name */
if (instance= instance_map->find(name, len)) if (instance= instance_map->find(name, len))
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
class Show_instances : public Command class Show_instances : public Command
{ {
public: public:
Show_instances(Instance_map *imap_arg): Command(imap_arg) Show_instances(Instance_map *instance_map_arg): Command(instance_map_arg)
{} {}
int do_command(struct st_net *net); int do_command(struct st_net *net);
...@@ -43,7 +43,7 @@ public: ...@@ -43,7 +43,7 @@ public:
class Flush_instances : public Command class Flush_instances : public Command
{ {
public: public:
Flush_instances(Instance_map *imap_arg): Command(imap_arg) Flush_instances(Instance_map *instance_map_arg): Command(instance_map_arg)
{} {}
int execute(struct st_net *net, ulong connection_id); int execute(struct st_net *net, ulong connection_id);
...@@ -59,7 +59,7 @@ class Show_instance_status : public Command ...@@ -59,7 +59,7 @@ class Show_instance_status : public Command
{ {
public: public:
Show_instance_status(Instance_map *imap_arg, const char *name, uint len); Show_instance_status(Instance_map *instance_map_arg, const char *name, uint len);
int do_command(struct st_net *net, const char *instance_name); int do_command(struct st_net *net, const char *instance_name);
int execute(struct st_net *net, ulong connection_id); int execute(struct st_net *net, ulong connection_id);
const char *instance_name; const char *instance_name;
...@@ -75,7 +75,7 @@ class Show_instance_options : public Command ...@@ -75,7 +75,7 @@ class Show_instance_options : public Command
{ {
public: public:
Show_instance_options(Instance_map *imap_arg, const char *name, uint len); Show_instance_options(Instance_map *instance_map_arg, const char *name, uint len);
int execute(struct st_net *net, ulong connection_id); int execute(struct st_net *net, ulong connection_id);
int do_command(struct st_net *net, const char *instance_name); int do_command(struct st_net *net, const char *instance_name);
...@@ -91,7 +91,7 @@ public: ...@@ -91,7 +91,7 @@ public:
class Start_instance : public Command class Start_instance : public Command
{ {
public: public:
Start_instance(Instance_map *imap_arg, const char *name, uint len); Start_instance(Instance_map *instance_map_arg, const char *name, uint len);
int execute(struct st_net *net, ulong connection_id); int execute(struct st_net *net, ulong connection_id);
const char *instance_name; const char *instance_name;
...@@ -107,7 +107,7 @@ public: ...@@ -107,7 +107,7 @@ public:
class Stop_instance : public Command class Stop_instance : public Command
{ {
public: public:
Stop_instance(Instance_map *imap_arg, const char *name, uint len); Stop_instance(Instance_map *instance_map_arg, const char *name, uint len);
Instance *instance; Instance *instance;
int execute(struct st_net *net, ulong connection_id); int execute(struct st_net *net, ulong connection_id);
......
...@@ -107,7 +107,7 @@ void Guardian_thread::run() ...@@ -107,7 +107,7 @@ void Guardian_thread::run()
int Guardian_thread::start() int Guardian_thread::start()
{ {
Instance *instance; Instance *instance;
Imap_iterator iterator(instance_map); Instance_map::Iterator iterator(instance_map);
instance_map->lock(); instance_map->lock();
while (instance= iterator.next()) while (instance= iterator.next())
......
...@@ -226,26 +226,20 @@ int Instance_map::load() ...@@ -226,26 +226,20 @@ int Instance_map::load()
} }
Instance *Instance_map::get_instance(uint instance_number) /*--- Implementaton of the Instance map iterator class ---*/
{
if (instance_number < hash.records)
return (Instance *) hash_element(&hash, instance_number);
else
return NULL;
}
/*--- Implementaton of the Instance map iterator class (Imap_iterator) ---*/ void Instance_map::Iterator::go_to_first()
void Imap_iterator::go_to_first()
{ {
current_instance=0; current_instance=0;
} }
Instance *Imap_iterator::next() Instance *Instance_map::Iterator::next()
{ {
return instance_map->get_instance(current_instance++); if (current_instance < instance_map->hash.records)
return (Instance *) hash_element(&instance_map->hash, current_instance++);
else
return NULL;
} }
...@@ -38,6 +38,22 @@ extern void free_groups(char **groups); ...@@ -38,6 +38,22 @@ extern void free_groups(char **groups);
class Instance_map class Instance_map
{ {
friend class Iterator;
public:
/* Instance_map iterator */
class Iterator
{
private:
uint current_instance;
Instance_map *instance_map;
public:
Iterator(Instance_map *instance_map_arg) :
instance_map(instance_map_arg), current_instance(0)
{}
void go_to_first();
Instance *next();
};
public: public:
/* returns a pointer to the instance or NULL, if there is no such instance */ /* returns a pointer to the instance or NULL, if there is no such instance */
Instance *find(const char *name, uint name_len); Instance *find(const char *name, uint name_len);
...@@ -47,7 +63,6 @@ public: ...@@ -47,7 +63,6 @@ public:
int cleanup(); int cleanup();
int lock(); int lock();
int unlock(); int unlock();
Instance *get_instance(uint instance_number);
Instance_map(); Instance_map();
~Instance_map(); ~Instance_map();
...@@ -72,22 +87,4 @@ private: ...@@ -72,22 +87,4 @@ private:
HASH hash; HASH hash;
}; };
/* Instance_map iterator */
class Imap_iterator
{
private:
uint current_instance;
Instance_map *instance_map;
public:
Imap_iterator(Instance_map *instance_map_arg) :
instance_map(instance_map_arg), current_instance(0)
{}
void go_to_first();
Instance *next();
};
#endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_INSTANCE_MAP_H */ #endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_INSTANCE_MAP_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment