~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/mysql_protocol/mysql_protocol.cc

  • Committer: Lee Bieber
  • Date: 2011-02-02 17:06:06 UTC
  • mfrom: (2136.1.3 build)
  • Revision ID: kalebral@gmail.com-20110202170606-gdueaj1a3utc5wkp
Merge Andrew - 710947: Valgrind warning in hello_events.table test      
Merge Vijay - 709653: invalid command line option in dbqp.py does not display the entire usage menu
Merge Andrew - 686135: data_dictionary table for protocol counters need to be added
Merge Andrew - 710572: Slight change needed in Ubuntu install docs^

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include "mysql_protocol.h"
33
33
#include "mysql_password.h"
34
34
#include "options.h"
35
 
#include "table_function.h"
36
35
 
37
36
#include "drizzled/identifier.h"
38
37
 
66
65
ListenMySQLProtocol::~ListenMySQLProtocol()
67
66
{ }
68
67
 
 
68
void ListenMySQLProtocol::addCountersToTable()
 
69
{
 
70
  counters.push_back(new drizzled::plugin::ListenCounter(new std::string("connection_count"), &getCounters()->connectionCount));
 
71
  counters.push_back(new drizzled::plugin::ListenCounter(new std::string("connected"), &getCounters()->connected));
 
72
  counters.push_back(new drizzled::plugin::ListenCounter(new std::string("failed_connections"), &getCounters()->failedConnections));
 
73
}
 
74
 
69
75
const std::string ListenMySQLProtocol::getHost(void) const
70
76
{
71
77
  return _hostname;
979
985
 
980
986
static int init(drizzled::module::Context &context)
981
987
{  
982
 
  context.add(new MysqlProtocolStatus);
983
 
 
984
988
  /* Initialize random seeds for the MySQL algorithm with minimal changes. */
985
989
  time_t seed_time= time(NULL);
986
990
  random_seed1= seed_time % random_max;
992
996
  context.add(mysql_password);
993
997
 
994
998
  listen_obj= new ListenMySQLProtocol("mysql_protocol", vm["bind-address"].as<std::string>(), true);
 
999
  listen_obj->addCountersToTable();
995
1000
  context.add(listen_obj); 
996
1001
  context.registerVariable(new sys_var_constrained_value_readonly<in_port_t>("port", port));
997
1002
  context.registerVariable(new sys_var_constrained_value<uint32_t>("connect_timeout", connect_timeout));
1039
1044
          _("A restrictive IP address list for incoming admin connections."));
1040
1045
}
1041
1046
 
1042
 
static int mysql_protocol_connection_count_func(drizzle_show_var *var, char *buff)
1043
 
{
1044
 
  var->type= SHOW_LONGLONG;
1045
 
  var->value= buff;
1046
 
  *((uint64_t *)buff)= ListenMySQLProtocol::mysql_counters->connectionCount;
1047
 
  return 0;
1048
 
}
1049
 
 
1050
 
static int mysql_protocol_connected_count_func(drizzle_show_var *var, char *buff)
1051
 
{
1052
 
  var->type= SHOW_LONGLONG;
1053
 
  var->value= buff;
1054
 
  *((uint64_t *)buff)= ListenMySQLProtocol::mysql_counters->connected;
1055
 
  return 0;
1056
 
}
1057
 
 
1058
 
static int mysql_protocol_failed_count_func(drizzle_show_var *var, char *buff)
1059
 
{
1060
 
  var->type= SHOW_LONGLONG;
1061
 
  var->value= buff;
1062
 
  *((uint64_t *)buff)= ListenMySQLProtocol::mysql_counters->failedConnections;
1063
 
  return 0;
1064
 
}
1065
 
 
1066
 
static st_show_var_func_container mysql_protocol_connection_count=
1067
 
  { &mysql_protocol_connection_count_func };
1068
 
 
1069
 
static st_show_var_func_container mysql_protocol_connected_count=
1070
 
  { &mysql_protocol_connected_count_func };
1071
 
 
1072
 
static st_show_var_func_container mysql_protocol_failed_count=
1073
 
  { &mysql_protocol_failed_count_func };
1074
 
 
1075
 
static drizzle_show_var mysql_protocol_status_variables[]= {
1076
 
  {"Connections",
1077
 
  (char*) &mysql_protocol_connection_count, SHOW_FUNC},
1078
 
  {"Connected",
1079
 
  (char*) &mysql_protocol_connected_count, SHOW_FUNC},
1080
 
  {"Failed_connections",
1081
 
  (char*) &mysql_protocol_failed_count, SHOW_FUNC},
1082
 
  {NULL, NULL, SHOW_LONGLONG}
1083
 
};
1084
 
 
1085
 
MysqlProtocolStatus::Generator::Generator(drizzled::Field **fields) :
1086
 
  plugin::TableFunction::Generator(fields)
1087
 
{
1088
 
  status_var_ptr= mysql_protocol_status_variables;
1089
 
}
1090
 
 
1091
 
bool MysqlProtocolStatus::Generator::populate()
1092
 
{
1093
 
  MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
1094
 
  char * const buff= (char *) &buff_data;
1095
 
  drizzle_show_var tmp;
1096
 
 
1097
 
  if (status_var_ptr->name)
1098
 
  {
1099
 
    std::ostringstream oss;
1100
 
    string return_value;
1101
 
    const char *value;
1102
 
    int type;
1103
 
 
1104
 
    push(status_var_ptr->name);
1105
 
 
1106
 
    if (status_var_ptr->type == SHOW_FUNC)
1107
 
    {
1108
 
      ((drizzle_show_var_func)((st_show_var_func_container *)status_var_ptr->value)->func)(&tmp, buff);
1109
 
      value= buff;
1110
 
      type= tmp.type;
1111
 
    }
1112
 
    else
1113
 
    {
1114
 
      value= status_var_ptr->value;
1115
 
      type= status_var_ptr->type;
1116
 
    }
1117
 
 
1118
 
    switch(type)
1119
 
    {
1120
 
    case SHOW_LONGLONG:
1121
 
      oss << *(uint64_t*) value;
1122
 
      return_value= oss.str();
1123
 
      break;
1124
 
    default:
1125
 
      assert(0);
1126
 
    }
1127
 
    if (return_value.length())
1128
 
      push(return_value);
1129
 
    else
1130
 
      push(" ");
1131
 
 
1132
 
    status_var_ptr++;
1133
 
 
1134
 
    return true;
1135
 
  }
1136
 
  return false;
1137
 
}
1138
 
 
1139
1047
} /* namespace drizzle_plugin */
1140
1048
 
1141
1049
DRIZZLE_DECLARE_PLUGIN