<commit_before>// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

use std::cell::RefCell;
use std::path::Path;
use std::rc::Rc;
use std::vec::Vec;

use dbus;
use dbus::{BusType, Connection, Message, NameFlag};
use dbus::arg::{Array, IterAppend};
use dbus::tree::{Access, ConnectionItem, EmitsChangedSignal, Factory, MTFn, MethodErr, MethodInfo,
                 MethodResult, PropInfo, Tree};
use uuid::Uuid;

use engine::{Engine, Pool};
use stratis::VERSION;

use super::blockdev::create_dbus_blockdev;
use super::filesystem::create_dbus_filesystem;
use super::pool::create_dbus_pool;
use super::types::{ActionQueue, DbusContext, DbusErrorEnum, DeferredAction, TData};
use super::util::{STRATIS_BASE_PATH, STRATIS_BASE_SERVICE, engine_to_dbus_err_tuple, get_next_arg,
                  msg_code_ok, msg_string_ok, tuple_to_option};

fn create_pool(m: &MethodInfo<MTFn<TData>, TData>) -> MethodResult {
    let message: &Message = m.msg;
    let mut iter = message.iter_init();

    let name: &str = get_next_arg(&mut iter, 0)?;
    let redundancy: (bool, u16) = get_next_arg(&mut iter, 1)?;
    let force: bool = get_next_arg(&mut iter, 2)?;
    let devs: Array<&str, _> = get_next_arg(&mut iter, 3)?;

    let blockdevs = devs.map(|x| Path::new(x)).collect::<Vec<&Path>>();

    let object_path = m.path.get_name();
    let dbus_context = m.tree.get_data();
    let mut engine = dbus_context.engine.borrow_mut();
    let result = engine.create_pool(name, &blockdevs, tuple_to_option(redundancy), force);

    let return_message = message.method_return();

    let default_return: (dbus::Path, Vec<dbus::Path>) = (dbus::Path::default(), Vec::new());<commit_msg>api.rs: Correct use for ConnectionItem<commit_after>// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

use std::cell::RefCell;
use std::path::Path;
use std::rc::Rc;
use std::vec::Vec;

use dbus;
use dbus::{BusType, Connection, ConnectionItem, Message, NameFlag};
use dbus::arg::{Array, IterAppend};
use dbus::tree::{Access, EmitsChangedSignal, Factory, MTFn, MethodErr, MethodInfo, MethodResult,
                 PropInfo, Tree};
use uuid::Uuid;

use engine::{Engine, Pool};
use stratis::VERSION;

use super::blockdev::create_dbus_blockdev;
use super::filesystem::create_dbus_filesystem;
use super::pool::create_dbus_pool;
use super::types::{ActionQueue, DbusContext, DbusErrorEnum, DeferredAction, TData};
use super::util::{STRATIS_BASE_PATH, STRATIS_BASE_SERVICE, engine_to_dbus_err_tuple, get_next_arg,
                  msg_code_ok, msg_string_ok, tuple_to_option};

fn create_pool(m: &MethodInfo<MTFn<TData>, TData>) -> MethodResult {
    let message: &Message = m.msg;
    let mut iter = message.iter_init();

    let name: &str = get_next_arg(&mut iter, 0)?;
    let redundancy: (bool, u16) = get_next_arg(&mut iter, 1)?;
    let force: bool = get_next_arg(&mut iter, 2)?;
    let devs: Array<&str, _> = get_next_arg(&mut iter, 3)?;

    let blockdevs = devs.map(|x| Path::new(x)).collect::<Vec<&Path>>();

    let object_path = m.path.get_name();
    let dbus_context = m.tree.get_data();
    let mut engine = dbus_context.engine.borrow_mut();
    let result = engine.create_pool(name, &blockdevs, tuple_to_option(redundancy), force);

    let return_message = message.method_return();

    let default_return: (dbus::Path, Vec<dbus::Path>) = (dbus::Path::default(), Vec::new());
{'fraction_non_alphanumeric': 0.14782370654256774, 'fraction_numerical': 0.005474952094169176, 'mean_word_length': 4.99016393442623, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6136937', 'n_tokens_mistral': 1266, 'n_tokens_neox': 1256, 'n_words': 319}