~posulliv/drizzle/optimizer-style-cleanup

« back to all changes in this revision

Viewing changes to plugin/information_engine/information_engine.h

  • Committer: Padraig O'Sullivan
  • Date: 2010-03-15 14:05:26 UTC
  • mfrom: (1237.9.99 staging)
  • Revision ID: osullivan.padraig@gmail.com-20100315140526-opbgwdwn6tfecdkq
MergeĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2009 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; either version 2 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
11
 
 *  This program is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 */
20
 
 
21
 
#ifndef PLUGIN_INFORMATION_ENGINE_INFORMATION_ENGINE_H
22
 
#define PLUGIN_INFORMATION_ENGINE_INFORMATION_ENGINE_H
23
 
 
24
 
#include <drizzled/thr_lock.h>
25
 
#include <drizzled/plugin/info_schema_table.h>
26
 
#include <drizzled/plugin/storage_engine.h>
27
 
 
28
 
static const char *information_exts[] = {
29
 
  NULL
30
 
};
31
 
 
32
 
 
33
 
class InformationEngine : public drizzled::plugin::StorageEngine
34
 
{
35
 
public:
36
 
  InformationEngine(const std::string &name_arg)
37
 
    : drizzled::plugin::StorageEngine(name_arg,
38
 
                                      drizzled::HTON_ALTER_NOT_SUPPORTED |
39
 
                                      drizzled::HTON_SKIP_STORE_LOCK |
40
 
                                      drizzled::HTON_HIDDEN |
41
 
                                      drizzled::HTON_TEMPORARY_NOT_SUPPORTED)
42
 
  {
43
 
    pthread_mutex_init(&mutex, NULL);
44
 
  }
45
 
 
46
 
  ~InformationEngine()
47
 
  {
48
 
    pthread_mutex_destroy(&mutex);
49
 
  }
50
 
 
51
 
  class Share
52
 
  {
53
 
  private:
54
 
    uint32_t count;
55
 
    drizzled::plugin::InfoSchemaTable *table;
56
 
 
57
 
  public:
58
 
    drizzled::THR_LOCK lock;
59
 
 
60
 
    Share(const std::string &in_name) :
61
 
      count(1)
62
 
    {
63
 
      table= drizzled::plugin::InfoSchemaTable::getTable(in_name.c_str());
64
 
    }
65
 
 
66
 
    ~Share()  {}
67
 
 
68
 
    void initThreadLock()
69
 
    {
70
 
      thr_lock_init(&lock);
71
 
    }
72
 
 
73
 
    void deinitThreadLock()
74
 
    {
75
 
      thr_lock_delete(&lock);
76
 
    }
77
 
 
78
 
    /**
79
 
     * Increment the counter which tracks how many instances of this share are
80
 
     * currently open.
81
 
     * @return the new counter value
82
 
   */
83
 
    uint32_t incUseCount(void) 
84
 
    { 
85
 
      return ++count; 
86
 
    }
87
 
 
88
 
    /**
89
 
     * Decrement the count which tracks how many instances of this share are
90
 
     * currently open.
91
 
     * @return the new counter value
92
 
   */
93
 
    uint32_t decUseCount(void) 
94
 
    { 
95
 
      return --count; 
96
 
    }
97
 
 
98
 
    /**
99
 
     * @ return the value of the use counter for this share
100
 
   */
101
 
    uint32_t getUseCount() const
102
 
    {
103
 
      return count;
104
 
    }
105
 
 
106
 
    /**
107
 
     * @return the table name associated with this share.
108
 
   */
109
 
    const std::string &getName() const
110
 
    {
111
 
      return table->getTableName();
112
 
    }
113
 
 
114
 
    /**
115
 
     * Set the I_S table associated with this share.
116
 
     * @param[in] name the name of the I_S table
117
 
     */
118
 
    void setInfoSchemaTable(const std::string &name)
119
 
    {
120
 
      table= drizzled::plugin::InfoSchemaTable::getTable(name.c_str());
121
 
    }
122
 
 
123
 
    /**
124
 
     * @return the I_S table associated with this share.
125
 
     */
126
 
    drizzled::plugin::InfoSchemaTable *getInfoSchemaTable()
127
 
    {
128
 
      return table;
129
 
    }
130
 
  };
131
 
 
132
 
private:
133
 
  typedef std::map<const std::string, Share> OpenTables;
134
 
  typedef std::pair<const std::string, Share> Record;
135
 
 
136
 
  OpenTables open_tables;
137
 
  pthread_mutex_t mutex; // Mutext used in getShare() calls
138
 
 
139
 
public:
140
 
 
141
 
  // Follow Two Methods are for "share"
142
 
  Share *getShare(const std::string &name_arg);
143
 
  void freeShare(Share *share);
144
 
 
145
 
 
146
 
  int doCreateTable(drizzled::Session *,
147
 
                    const char *,
148
 
                    drizzled::Table&,
149
 
                    drizzled::message::Table&)
150
 
  {
151
 
    return EPERM;
152
 
  }
153
 
 
154
 
  int doDropTable(drizzled::Session&, const std::string) 
155
 
  { 
156
 
    return EPERM; 
157
 
  }
158
 
 
159
 
  virtual drizzled::Cursor *create(drizzled::TableShare &table,
160
 
                                   drizzled::memory::Root *mem_root);
161
 
 
162
 
  const char **bas_ext() const 
163
 
  {
164
 
    return information_exts;
165
 
  }
166
 
 
167
 
  void doGetTableNames(drizzled::CachedDirectory&, 
168
 
                       std::string &db, 
169
 
                       std::set<std::string> &set_of_names);
170
 
 
171
 
  int doGetTableDefinition(drizzled::Session &session,
172
 
                           const char *path,
173
 
                           const char *db,
174
 
                           const char *table_name,
175
 
                           const bool is_tmp,
176
 
                           drizzled::message::Table *table_proto);
177
 
 
178
 
};
179
 
 
180
 
#endif /* PLUGIN_INFORMATION_ENGINE_INFORMATION_ENGINE_H */