Rev 1647 | Rev 1741 | Go to most recent revision | Details | Compare with Previous | 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 "Storage.h" |
||
| 22 | |||
| 23 | #include <boost/lexical_cast.hpp> |
||
| 24 | |||
| 25 | #include "storage/Manager.h" |
||
| 26 | #include "storage/Store.h" |
||
| 27 | #include "vm/Manager.h" |
||
| 28 | |||
| 29 | namespace atom { |
||
| 30 | namespace vm { |
||
| 31 | namespace plugin { |
||
| 32 | |||
| 33 | logging::Logger Storage::LOG("vm::plugin::storage"); |
||
| 34 | |||
| 1625 | runge | 35 | Storage::Storage(boost::asio::io_service& io_service) : Plugin(io_service) |
| 1619 | runge | 36 | { |
| 37 | this->name_ = "storage"; |
||
| 38 | |||
| 1644 | runge | 39 | this->ExportFunction("StorageExport_GetParameters", Storage::Export_GetParameters); |
| 40 | this->ExportFunction("StorageExport_GetParameter", Storage::Export_GetParameter); |
||
| 41 | this->ExportFunction("StorageExport_SetParameter", Storage::Export_SetParameter); |
||
| 1619 | runge | 42 | } |
| 43 | |||
| 44 | Storage::~Storage() |
||
| 45 | { |
||
| 46 | } |
||
| 47 | |||
| 48 | void Storage::InitializeDone() |
||
| 49 | { |
||
| 50 | Plugin::InitializeDone(); |
||
| 51 | } |
||
| 52 | |||
| 1647 | runge | 53 | void Storage::CallOutput(unsigned int request_id, std::string output) |
| 54 | { |
||
| 55 | LOG.Info(output); |
||
| 56 | } |
||
| 57 | |||
| 1619 | runge | 58 | Value Storage::Export_GetParameters(const v8::Arguments& args) |
| 59 | { |
||
| 1740 | runge | 60 | v8::Locker lock; |
| 1619 | runge | 61 | v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext()); |
| 62 | |||
| 1647 | runge | 63 | //LOG.Debug(std::string(__FUNCTION__) + " called!"); |
| 1619 | runge | 64 | |
| 65 | if (args.Length() < 1) |
||
| 66 | { |
||
| 1644 | runge | 67 | LOG.Error(std::string(__FUNCTION__) + ": To few arguments."); |
| 1647 | runge | 68 | return v8::Boolean::New(false); |
| 1619 | runge | 69 | } |
| 70 | |||
| 71 | v8::String::AsciiValue store_name(args[0]); |
||
| 72 | |||
| 73 | storage::Store::ParameterList parameters = storage::Manager::Instance()->GetParameters(*store_name); |
||
| 74 | |||
| 75 | v8::Local<v8::Array> params = v8::Array::New(parameters.size()); |
||
| 76 | |||
| 77 | for (storage::Store::ParameterList::iterator it = parameters.begin(); it != parameters.end(); it++) |
||
| 78 | { |
||
| 79 | params->Set(v8::String::New(it->first.data()), v8::String::New(it->second.data())); |
||
| 80 | } |
||
| 81 | |||
| 82 | return params; |
||
| 83 | } |
||
| 84 | |||
| 85 | Value Storage::Export_GetParameter(const v8::Arguments& args) |
||
| 86 | { |
||
| 1740 | runge | 87 | v8::Locker lock; |
| 1625 | runge | 88 | v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext()); |
| 89 | |||
| 1647 | runge | 90 | //LOG.Debug(std::string(__FUNCTION__) + " called!"); |
| 1619 | runge | 91 | |
| 92 | if (args.Length() < 2) |
||
| 93 | { |
||
| 1644 | runge | 94 | LOG.Error(std::string(__FUNCTION__) + ": To few arguments."); |
| 1647 | runge | 95 | return v8::Boolean::New(false); |
| 1619 | runge | 96 | } |
| 97 | |||
| 98 | v8::String::AsciiValue store_name(args[0]); |
||
| 99 | v8::String::AsciiValue parameter_name(args[1]); |
||
| 100 | |||
| 101 | Value result; |
||
| 102 | |||
| 103 | try |
||
| 104 | { |
||
| 105 | result = v8::String::New(storage::Manager::Instance()->GetParameter(*store_name, *parameter_name).data()); |
||
| 106 | } |
||
| 107 | catch (std::runtime_error& e) |
||
| 108 | { |
||
| 109 | result = v8::Undefined(); |
||
| 110 | } |
||
| 111 | |||
| 112 | return result; |
||
| 113 | } |
||
| 114 | |||
| 115 | Value Storage::Export_SetParameter(const v8::Arguments& args) |
||
| 116 | { |
||
| 1740 | runge | 117 | v8::Locker lock; |
| 1625 | runge | 118 | v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext()); |
| 119 | |||
| 1647 | runge | 120 | //LOG.Debug(std::string(__FUNCTION__) + " called!"); |
| 1619 | runge | 121 | |
| 122 | if (args.Length() < 3) |
||
| 123 | { |
||
| 1644 | runge | 124 | LOG.Error(std::string(__FUNCTION__) + ": To few arguments."); |
| 1647 | runge | 125 | return v8::Boolean::New(false); |
| 1619 | runge | 126 | } |
| 127 | |||
| 128 | v8::String::AsciiValue store_name(args[0]); |
||
| 129 | v8::String::AsciiValue parameter_name(args[1]); |
||
| 130 | v8::String::AsciiValue parameter_value(args[2]); |
||
| 131 | |||
| 132 | storage::Manager::Instance()->SetParameter(*store_name, *parameter_name, *parameter_value); |
||
| 133 | |||
| 134 | return v8::String::New("OK"); |
||
| 135 | } |
||
| 136 | |||
| 137 | }; // namespace plugin |
||
| 138 | }; // namespace vm |
||
| 139 | }; // namespace atom |