Rev 1627 | Go to most recent revision | Details | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1619 | runge | 1 | /* |
| 2 | * |
||
| 3 | * Copyright (C) 2010 Mattias Runge |
||
| 4 | * |
||
| 5 | * This program is free software; you can redistribute it and/or modify |
||
| 6 | * it under the terms of the GNU General Public License as published by |
||
| 7 | * the Free Software Foundation; either version 2 of the License, or |
||
| 8 | * (at your option) any later version. |
||
| 9 | * |
||
| 10 | * This program is distributed in the hope that it will be useful, |
||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 13 | * GNU General Public License for more details. |
||
| 14 | * |
||
| 15 | * You should have received a copy of the GNU General Public License along |
||
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
||
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
||
| 18 | * |
||
| 19 | */ |
||
| 20 | |||
| 21 | #include "Manager.h" |
||
| 22 | |||
| 23 | namespace atom { |
||
| 24 | namespace storage { |
||
| 25 | |||
| 26 | Manager::Pointer Manager::instance_; |
||
| 27 | |||
| 28 | Manager::Manager() : LOG("storage::Manager") |
||
| 29 | { |
||
| 30 | } |
||
| 31 | |||
| 32 | Manager::~Manager() |
||
| 33 | { |
||
| 34 | for (StoreList::iterator it = this->stores_.begin(); it != this->stores_.end(); it++) |
||
| 35 | { |
||
| 36 | try |
||
| 37 | { |
||
| 38 | it->second->Flush(); |
||
| 39 | } |
||
| 40 | catch (std::runtime_error& e) |
||
| 41 | { |
||
| 42 | LOG.Error("Error while flusing store, " + std::string(e.what())); |
||
| 43 | } |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | Manager::Pointer Manager::Instance() |
||
| 48 | { |
||
| 49 | return Manager::instance_; |
||
| 50 | } |
||
| 51 | |||
| 52 | void Manager::Create() |
||
| 53 | { |
||
| 54 | Manager::instance_ = Manager::Pointer(new Manager()); |
||
| 55 | } |
||
| 56 | |||
| 57 | void Manager::Delete() |
||
| 58 | { |
||
| 59 | Manager::instance_.reset(); |
||
| 60 | } |
||
| 61 | |||
| 62 | void Manager::SetRootPath(std::string root_path) |
||
| 63 | { |
||
| 64 | this->root_path_ = root_path; |
||
| 65 | } |
||
| 66 | |||
| 67 | Store::ParameterList& Manager::GetParameters(std::string store_name) |
||
| 68 | { |
||
| 69 | StoreList::iterator it = this->stores_.find(store_name); |
||
| 70 | |||
| 71 | if (it == this->stores_.end()) |
||
| 72 | { |
||
| 73 | LOG.Info("Loading storage " + store_name + "..."); |
||
| 74 | this->stores_[store_name] = Store::Pointer(new Store(this->root_path_ + store_name)); |
||
| 75 | } |
||
| 76 | |||
| 77 | return this->stores_[store_name]->GetParameters(); |
||
| 78 | } |
||
| 79 | |||
| 80 | std::string Manager::GetParameter(std::string store_name, std::string parameter_name) |
||
| 81 | { |
||
| 82 | StoreList::iterator it = this->stores_.find(store_name); |
||
| 83 | |||
| 84 | if (it == this->stores_.end()) |
||
| 85 | { |
||
| 86 | LOG.Info("Loading storage " + store_name + "..."); |
||
| 87 | this->stores_[store_name] = Store::Pointer(new Store(this->root_path_ + store_name)); |
||
| 88 | } |
||
| 89 | |||
| 90 | return this->stores_[store_name]->GetParameter(parameter_name); |
||
| 91 | } |
||
| 92 | |||
| 93 | void Manager::SetParameter(std::string store_name, std::string parameter_name, std::string parameter_value) |
||
| 94 | { |
||
| 95 | StoreList::iterator it = this->stores_.find(store_name); |
||
| 96 | |||
| 97 | if (it == this->stores_.end()) |
||
| 98 | { |
||
| 99 | LOG.Info("Loading storage " + store_name + "..."); |
||
| 100 | this->stores_[store_name] = Store::Pointer(new Store(this->root_path_ + store_name)); |
||
| 101 | } |
||
| 102 | |||
| 103 | return this->stores_[store_name]->SetParameter(parameter_name, parameter_value); |
||
| 104 | } |
||
| 105 | |||
| 106 | }; // namespace timer |
||
| 107 | }; // namespace atom |