~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/catalog/instance.h

  • Committer: lbieber
  • Date: 2010-10-06 16:34:16 UTC
  • mfrom: (1816.1.3 build)
  • Revision ID: lbieber@orisndriz08-20101006163416-ea0sl59qgpglk21y
Merge Monty - Change the requirement from either libinnodb to libhaildb. Also, tied it to version 2.2
Merge Andrew - fix bug 650935: remove --compress from all clients
Merge Andrew - fix bug 653471: Add -A to drizzle client
Merge Travis - 621861 = To change C structs to C++ classes in Drizzle

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) 2010 Brian Aker
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 DRIZZLED_CATALOG_INSTANCE_H
22
 
#define DRIZZLED_CATALOG_INSTANCE_H
23
 
 
24
 
#include <boost/thread/mutex.hpp>
25
 
#include <boost/make_shared.hpp>
26
 
 
27
 
#include <drizzled/message/catalog.h>
28
 
#include <drizzled/identifier/session.h>
29
 
 
30
 
namespace drizzled {
31
 
namespace catalog {
32
 
 
33
 
class Instance
34
 
{
35
 
  Instance() :
36
 
    _locked(false),
37
 
    _lock_id(0)
38
 
  { };
39
 
 
40
 
  bool _locked;
41
 
  drizzled::session_id_t _lock_id;
42
 
  message::catalog::shared_ptr _message;
43
 
  mutable boost::mutex _schema_lock;
44
 
  mutable boost::mutex _system_variable_lock;
45
 
 
46
 
 
47
 
public:
48
 
  typedef boost::shared_ptr<Instance> shared_ptr;
49
 
  typedef std::vector<shared_ptr> vector;
50
 
  typedef const Instance* const_pointer;
51
 
  typedef const Instance& const_reference;
52
 
  typedef Instance& reference;
53
 
 
54
 
  Instance(message::catalog::shared_ptr &message_arg)
55
 
  {
56
 
    _message= message_arg;
57
 
  };
58
 
 
59
 
  Instance(const message::catalog::shared_ptr &message_arg)
60
 
  {
61
 
    _message= message_arg;
62
 
  };
63
 
 
64
 
  static shared_ptr make_shared(message::catalog::shared_ptr &message_arg)
65
 
  {
66
 
    assert(not message_arg->name().empty());
67
 
    return boost::make_shared<Instance>(message_arg);
68
 
  };
69
 
 
70
 
  static shared_ptr make_shared(const identifier::Catalog &identifier)
71
 
  {
72
 
    drizzled::message::catalog::shared_ptr new_message= drizzled::message::catalog::make_shared(identifier);
73
 
    assert(not new_message->name().empty());
74
 
    return boost::make_shared<Instance>(new_message);
75
 
  }
76
 
 
77
 
  const std::string &getName() const
78
 
  {
79
 
    assert(_message);
80
 
    return _message->name();
81
 
  }
82
 
 
83
 
  const std::string &name() const
84
 
  {
85
 
    assert(_message);
86
 
    return _message->name();
87
 
  }
88
 
 
89
 
  message::catalog::shared_ptr message() const
90
 
  {
91
 
    return _message;
92
 
  }
93
 
 
94
 
  bool locked() const
95
 
  {
96
 
    return _locked;
97
 
  }
98
 
 
99
 
  bool lock(drizzled::session_id_t id)
100
 
  {
101
 
    if (_locked and _lock_id == id)
102
 
    {
103
 
      assert(0); // We shouldn't support recursion
104
 
      return true;
105
 
    }
106
 
    else if (_locked)
107
 
    {
108
 
      return false;
109
 
    }
110
 
 
111
 
    _locked= true;
112
 
    _lock_id= id;
113
 
 
114
 
    return true;
115
 
  }
116
 
 
117
 
  bool unlock(drizzled::session_id_t id)
118
 
  {
119
 
    if (_locked and _lock_id == id)
120
 
    {
121
 
      _locked= false;
122
 
      _lock_id= 0;
123
 
 
124
 
      return true;
125
 
    }
126
 
 
127
 
    return false;
128
 
  }
129
 
 
130
 
  boost::mutex &schemaLock()
131
 
  {
132
 
    return _schema_lock;
133
 
  }
134
 
 
135
 
  boost::mutex &systemVariableLock()
136
 
  {
137
 
    return _system_variable_lock;
138
 
  }
139
 
};
140
 
 
141
 
} /* namespace catalog */
142
 
} /* namespace drizzled */
143
 
 
144
 
#endif /* DRIZZLED_CATALOG_INSTANCE_H */