~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/catalog/instance.h

Merge catalog with current 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) 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/make_shared.hpp>
 
25
#include "drizzled/message/catalog.h"
 
26
#include "drizzled/session.h"
 
27
 
 
28
namespace drizzled {
 
29
namespace catalog {
 
30
 
 
31
class Instance
 
32
{
 
33
  Instance() :
 
34
    _locked(false),
 
35
    _lock_id(0)
 
36
  { };
 
37
 
 
38
  bool _locked;
 
39
  drizzled::session_id_t _lock_id;
 
40
  message::catalog::shared_ptr _message;
 
41
 
 
42
public:
 
43
  typedef boost::shared_ptr<Instance> shared_ptr;
 
44
  typedef std::vector<shared_ptr> vector;
 
45
 
 
46
  Instance(message::catalog::shared_ptr &message_arg)
 
47
  {
 
48
    _message= message_arg;
 
49
  };
 
50
 
 
51
  Instance(const message::catalog::shared_ptr &message_arg)
 
52
  {
 
53
    _message= message_arg;
 
54
  };
 
55
 
 
56
  static shared_ptr create(message::catalog::shared_ptr &message_arg)
 
57
  {
 
58
    return boost::make_shared<Instance>(message_arg);
 
59
  };
 
60
 
 
61
  static shared_ptr create(const identifier::Catalog &identifier)
 
62
  {
 
63
    drizzled::message::catalog::shared_ptr new_message= drizzled::message::catalog::make_shared(identifier);
 
64
    return boost::make_shared<Instance>(new_message);
 
65
  }
 
66
 
 
67
  const std::string &getName() const
 
68
  {
 
69
    assert(_message);
 
70
    return _message->name();
 
71
  }
 
72
 
 
73
  message::catalog::shared_ptr message() const
 
74
  {
 
75
    return _message;
 
76
  }
 
77
 
 
78
  bool locked() const
 
79
  {
 
80
    return _locked;
 
81
  }
 
82
 
 
83
  bool lock(drizzled::session_id_t id)
 
84
  {
 
85
    if (_locked and _lock_id == id)
 
86
    {
 
87
      assert(0); // We shouldn't support recursion
 
88
      return true;
 
89
    }
 
90
    else if (_locked)
 
91
    {
 
92
      return false;
 
93
    }
 
94
 
 
95
    _locked= true;
 
96
    _lock_id= id;
 
97
 
 
98
    return true;
 
99
  }
 
100
 
 
101
  bool unlock(drizzled::session_id_t id)
 
102
  {
 
103
    if (_locked and _lock_id == id)
 
104
    {
 
105
      _locked= false;
 
106
      _lock_id= 0;
 
107
 
 
108
      return true;
 
109
    }
 
110
 
 
111
    return false;
 
112
  }
 
113
};
 
114
 
 
115
} /* namespace catalog */
 
116
} /* namespace drizzled */
 
117
 
 
118
#endif /* DRIZZLED_CATALOG_INSTANCE_H */