2017-01-18 14:33:57 +00:00
|
|
|
//
|
|
|
|
// imag - the personal information management suite for the commandline
|
|
|
|
// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors
|
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; version
|
|
|
|
// 2.1 of the License.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
//
|
|
|
|
|
2017-01-21 17:16:24 +00:00
|
|
|
use libimagstore::store::Store;
|
|
|
|
use libimagerror::trace::trace_error;
|
|
|
|
use std::error::Error;
|
|
|
|
use std::ops::Deref;
|
|
|
|
use std::ops::DerefMut;
|
|
|
|
|
|
|
|
use ruru::{Class, Object, AnyObject, Boolean, RString, VM, Hash, NilClass, VerifiedObject};
|
|
|
|
|
|
|
|
use ruby_utils::IntoToml;
|
|
|
|
use toml_utils::IntoRuby;
|
|
|
|
use util::Wrap;
|
|
|
|
use util::Unwrap;
|
|
|
|
|
|
|
|
use storeid::RStoreId;
|
|
|
|
use entry::RFileLockEntry;
|
2017-01-21 18:24:08 +00:00
|
|
|
use cache::StoreHandle;
|
2017-01-21 17:16:24 +00:00
|
|
|
|
2017-01-21 18:24:08 +00:00
|
|
|
wrappable_struct!(StoreHandle, StoreWrapper, STORE_WRAPPER);
|
2017-01-21 17:16:24 +00:00
|
|
|
class!(RStore);
|
2017-01-21 18:24:08 +00:00
|
|
|
impl_wrap!(StoreHandle, STORE_WRAPPER);
|
|
|
|
impl_unwrap!(RStore, StoreHandle, STORE_WRAPPER);
|
2017-01-21 17:16:24 +00:00
|
|
|
impl_verified_object!(RStore);
|
|
|
|
|
2017-01-21 18:08:11 +00:00
|
|
|
macro_rules! call_on_store_by_handle {
|
|
|
|
($store_handle:ident -> $name:ident -> $operation:block) => {{
|
2017-01-21 18:24:08 +00:00
|
|
|
call_on_store_by_handle!($store_handle -> $name -> $operation on fail return NilClass::new().to_any_object())
|
|
|
|
}};
|
|
|
|
|
|
|
|
($store_handle:ident -> $name:ident -> $operation:block on fail return $ex:expr) => {{
|
2017-01-21 18:08:11 +00:00
|
|
|
use cache::RUBY_STORE_CACHE;
|
|
|
|
|
|
|
|
let arc = RUBY_STORE_CACHE.clone();
|
|
|
|
{
|
|
|
|
let lock = arc.lock();
|
|
|
|
match lock {
|
|
|
|
Ok(mut hm) => {
|
|
|
|
match hm.get($store_handle) {
|
|
|
|
Some($name) => { $operation },
|
|
|
|
None => {
|
|
|
|
VM::raise(Class::from_existing("RuntimeError"),
|
|
|
|
"Tried to operate on non-existing object");
|
2017-01-21 18:24:08 +00:00
|
|
|
$ex
|
2017-01-21 18:08:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Err(e) => {
|
|
|
|
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
2017-01-21 18:24:08 +00:00
|
|
|
$ex
|
2017-01-21 18:08:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-21 18:24:08 +00:00
|
|
|
}};
|
2017-01-21 18:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! call_on_store {
|
2017-01-21 18:24:08 +00:00
|
|
|
($itself:ident ($wrapper:ident) -> $name:ident -> $operation:block on fail return $ex:expr) => {{
|
|
|
|
let handle = $itself.get_data(&*$wrapper);
|
|
|
|
call_on_store_by_handle!(handle -> $name -> $operation on fail return $ex)
|
|
|
|
}};
|
2017-01-21 18:08:11 +00:00
|
|
|
($itself:ident ($wrapper:ident) -> $name:ident -> $operation:block) => {{
|
2017-01-21 18:24:08 +00:00
|
|
|
let handle = $itself.get_data(&*$wrapper);
|
2017-01-21 18:08:11 +00:00
|
|
|
call_on_store_by_handle!(handle -> $name -> $operation)
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2017-01-21 17:16:24 +00:00
|
|
|
methods!(
|
|
|
|
RStore,
|
|
|
|
itself,
|
|
|
|
|
|
|
|
// Create an FileLockEntry in the store
|
|
|
|
//
|
|
|
|
// # Returns:
|
|
|
|
//
|
|
|
|
// On success: A RFileLockEntry
|
|
|
|
// On failure: Nil
|
|
|
|
// On error: Nil + Exception
|
|
|
|
//
|
|
|
|
fn create(id: RStoreId) -> AnyObject {
|
|
|
|
unimplemented!()
|
2017-01-21 15:10:29 +00:00
|
|
|
}
|
|
|
|
|
2017-01-21 17:16:24 +00:00
|
|
|
// Retrieve an FileLockEntry from the store
|
|
|
|
//
|
|
|
|
// # Returns:
|
|
|
|
//
|
|
|
|
// On success: A RFileLockEntry
|
|
|
|
// On error: Nil + Exception
|
|
|
|
//
|
|
|
|
fn retrieve(id: RStoreId) -> AnyObject {
|
|
|
|
unimplemented!()
|
2017-01-21 15:07:24 +00:00
|
|
|
}
|
2017-01-18 14:33:57 +00:00
|
|
|
|
2017-01-21 17:16:24 +00:00
|
|
|
// Get an FileLockEntry from the store
|
|
|
|
//
|
|
|
|
// # Returns:
|
|
|
|
//
|
|
|
|
// On success, if there is some: A RFileLockEntry
|
|
|
|
// On success, if there is none: Nil
|
|
|
|
// On error: Nil + Exception
|
|
|
|
//
|
|
|
|
fn get(sid: RStoreId) -> AnyObject {
|
|
|
|
unimplemented!()
|
2017-01-18 14:33:57 +00:00
|
|
|
}
|
|
|
|
|
2017-01-21 17:16:24 +00:00
|
|
|
// Get all FileLockEntry of a module from the store
|
|
|
|
//
|
|
|
|
// # Returns:
|
|
|
|
//
|
|
|
|
// On success: A Array[RFileLockEntry]
|
|
|
|
// On error: Nil + Exception
|
|
|
|
//
|
|
|
|
fn retrieve_for_module(name: RString) -> AnyObject {
|
|
|
|
unimplemented!()
|
2017-01-20 10:12:06 +00:00
|
|
|
}
|
|
|
|
|
2017-01-21 17:16:24 +00:00
|
|
|
// Update a FileLockEntry in the store
|
|
|
|
//
|
|
|
|
// # Returns:
|
|
|
|
//
|
|
|
|
// On success: Nil
|
|
|
|
// On error: Nil + Exception
|
|
|
|
//
|
|
|
|
fn update(fle: RFileLockEntry) -> NilClass {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
2017-01-21 13:25:06 +00:00
|
|
|
|
2017-01-21 17:16:24 +00:00
|
|
|
// Delete a FileLockEntry from the store
|
|
|
|
//
|
|
|
|
// # Returns:
|
|
|
|
//
|
|
|
|
// On success: Nil
|
|
|
|
// On error: Nil + Exception
|
|
|
|
//
|
|
|
|
fn delete(sid: RStoreId) -> NilClass {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
2017-01-21 13:25:06 +00:00
|
|
|
|
2017-01-21 17:16:24 +00:00
|
|
|
// Save a FileLockEntry in a new path inside the store, keep the RFileLockEntry
|
|
|
|
//
|
|
|
|
// # Returns:
|
|
|
|
//
|
|
|
|
// On success: Nil
|
|
|
|
// On error: Nil + Exception
|
|
|
|
//
|
|
|
|
fn save_to(fle: RFileLockEntry, sid: RStoreId) -> NilClass {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
2017-01-21 13:25:06 +00:00
|
|
|
|
2017-01-21 17:16:24 +00:00
|
|
|
// Save a FileLockEntry in a new path inside the store, move the RFileLockEntry
|
|
|
|
//
|
|
|
|
// # Returns:
|
|
|
|
//
|
|
|
|
// On success: Nil
|
|
|
|
// On error: Nil + Exception
|
|
|
|
//
|
|
|
|
fn save_as(fle: RFileLockEntry, sid: RStoreId) -> NilClass {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
2017-01-21 13:25:06 +00:00
|
|
|
|
2017-01-21 17:16:24 +00:00
|
|
|
// Move one entry in the store to another place, by its ID
|
|
|
|
//
|
|
|
|
// # Returns:
|
|
|
|
//
|
|
|
|
// On success: Nil
|
|
|
|
// On error: Nil + Exception
|
|
|
|
//
|
|
|
|
fn move_by_id(old: RStoreId, nw: RStoreId) -> NilClass {
|
|
|
|
let old = typecheck!(old).unwrap().clone();
|
|
|
|
let nw = typecheck!(nw).unwrap().clone();
|
2017-01-21 13:25:06 +00:00
|
|
|
|
2017-01-21 18:24:08 +00:00
|
|
|
call_on_store!(itself (STORE_WRAPPER) -> store -> {
|
|
|
|
if let Err(e) = store.move_by_id(old, nw) {
|
|
|
|
trace_error(&e);
|
|
|
|
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
|
|
|
}
|
|
|
|
NilClass::new()
|
|
|
|
} on fail return NilClass::new())
|
2017-01-21 17:16:24 +00:00
|
|
|
}
|
2017-01-21 13:25:06 +00:00
|
|
|
|
2017-01-21 17:16:24 +00:00
|
|
|
// Get the path of the store object
|
|
|
|
//
|
|
|
|
// # Returns:
|
|
|
|
//
|
|
|
|
// A RString
|
|
|
|
//
|
|
|
|
fn path() -> RString {
|
2017-01-21 18:24:08 +00:00
|
|
|
call_on_store!(itself (STORE_WRAPPER) -> store -> {
|
|
|
|
store.path()
|
|
|
|
.clone()
|
|
|
|
.to_str()
|
|
|
|
.map(RString::new)
|
|
|
|
.unwrap_or(RString::new(""))
|
|
|
|
} on fail return RString::new(""))
|
2017-01-21 17:16:24 +00:00
|
|
|
}
|
2017-01-21 13:25:06 +00:00
|
|
|
|
2017-01-21 17:16:24 +00:00
|
|
|
);
|
2017-01-21 13:25:06 +00:00
|
|
|
|
2017-01-21 17:16:24 +00:00
|
|
|
pub fn setup() {
|
|
|
|
unimplemented!()
|
2017-01-20 10:12:06 +00:00
|
|
|
}
|