<commit_before>use dbus::arg::{Array};
use dbus::tree::MethodErr;
use dbus::MessageItem;

use ::ipc::utils::{parse_uuid, lock_tree_dbus};
use ::ipc::{DBusFactory, DBusObjPath};
use ::render::screen_scrape::{write_screen_scrape_lock, read_screen_scrape_lock,
                              scraped_pixels_lock, sync_scrape};

pub fn setup(f: &mut DBusFactory) -> DBusObjPath {
    f.object_path("/org/way_cooler/Screen", ()).introspectable().add(
        f.interface("org.way_cooler.Screen", ())
            .add_m(
                f.method("List", (), |m| {
                    let tree = lock_tree_dbus()?;
                    let outputs = tree.outputs().iter()
                        .map(|id|
                             MessageItem::Str(format!("{}", id.simple())))
                        .collect();
                    Ok(vec![m.msg.method_return()
                            .append((MessageItem::Array(outputs, "s".into())))
                    ])
                }).outarg::<Array<String, Vec<String>>, _>("success")
            )
            .add_m(
                // TODO Make this take in a:
                // * Output UUID
                // * Size (u32, u32) to scrape. For invalid ones, we throw error
                f.method("Scrape", (), |m| {
                    *write_screen_scrape_lock() = true;
                    // ensure that no other threads can try to grab the pixels.
                    let _lock = read_screen_scrape_lock();
                    sync_scrape();
                    drop(_lock);
                    *write_screen_scrape_lock() = false;
                    let scraped_pixels = scraped_pixels_lock()
                        .expect("scraped_pixels lock was poisoned!");<commit_msg>Added Screen.ActiveScreen endpoint<commit_after>use dbus::arg::{Array};
use dbus::tree::MethodErr;
use dbus::MessageItem;

use ::rustwlc::WlcOutput;
use ::layout::Handle;
use ::ipc::utils::{parse_uuid, lock_tree_dbus};
use ::ipc::{DBusFactory, DBusObjPath};
use ::render::screen_scrape::{write_screen_scrape_lock, read_screen_scrape_lock,
                              scraped_pixels_lock, sync_scrape};

pub fn setup(f: &mut DBusFactory) -> DBusObjPath {
    f.object_path("/org/way_cooler/Screen", ()).introspectable().add(
        f.interface("org.way_cooler.Screen", ())
            .add_m(
                f.method("List", (), |m| {
                    let tree = lock_tree_dbus()?;
                    let outputs = tree.outputs().iter()
                        .map(|id|
                             MessageItem::Str(format!("{}", id.simple())))
                        .collect();
                    Ok(vec![m.msg.method_return()
                            .append((MessageItem::Array(outputs, "s".into())))
                    ])
                }).outarg::<Array<String, Vec<String>>, _>("success")
            )
            .add_m(
                f.method("ActiveScreen", (), |m| {
                    let tree = lock_tree_dbus()?;
                    let id = tree.lookup_handle(Handle::Output(WlcOutput::focused()))
                        .map_err(|err| MethodErr::failed(&format!("{:?}", err)))?.to_string();
                    Ok(vec![m.msg.method_return().append((MessageItem::Str(id)))])
                }).outarg::<String, _>("success")
            )
            .add_m(
                // TODO Make this take in a:
                // * Output UUID
                // * Size (u32, u32) to scrape. For invalid ones, we throw error
                f.method("Scrape", (), |m| {
                    *write_screen_scrape_lock() = true;
                    // ensure that no other threads can try to grab the pixels.
                    let _lock = read_screen_scrape_lock();
                    sync_scrape();
                    drop(_lock);
                    *write_screen_scrape_lock() = false;
                    let scraped_pixels = scraped_pixels_lock()
                        .expect("scraped_pixels lock was poisoned!");
{'fraction_non_alphanumeric': 0.1408839779005525, 'fraction_numerical': 0.0020090406830738324, 'mean_word_length': 1.6118032786885246, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 12, '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': '4796299', 'n_tokens_mistral': 1171, 'n_tokens_neox': 1111, 'n_words': 208}