<commit_before>/// @file
/// @author uentity
/// @date 14.09.2016
/// @brief Implementation os link
/// @copyright
/// 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 https://mozilla.org/MPL/2.0/

#include <bs/log.h>
#include <bs/kernel/config.h>
#include "link_actor.h"

#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>

OMIT_OBJ_SERIALIZATION

NAMESPACE_BEGIN(blue_sky::tree)

link::link(caf::actor impl_a) : aimpl_(std::move(impl_a)) {
	pimpl_ = caf::actor_cast<link_actor*>(aimpl_);
	if(!pimpl_) throw error{ "Trying to construct tree::link with invalid actor" };
	fimpl_ = caf::make_function_view(aimpl_, caf::duration{pimpl_->timeout_});
	//pimpl_->master_ = this;
}

link::~link() {
	pimpl_->goodbye();
}

auto link::pimpl() const -> link_actor* {
	return pimpl_;
}

/// access link's unique ID
auto link::id() const -> const id_type& {
	return pimpl_->id_;
}

/// obtain link's symbolic name
auto link::name() const -> std::string {
	return pimpl_->name_;
}

/// get link's container
auto link::owner() const -> sp_node {
	return pimpl_->owner_.lock();
}

void link::reset_owner(const sp_node& new_owner) {
	pimpl_->reset_owner(new_owner);
}

auto link::info() const -> result_or_err<inode> {
	return pimpl_->get_inode().and_then([](const inodeptr& i) {
		return i ?
			result_or_err<inode>(*i) :
			tl::make_unexpected(error::quiet(Error::EmptyInode));
	});
}

link::Flags link::flags() const {
	return pimpl_->flags_;
}

void link::set_flags(Flags new_flags) {
	std::lock_guard<std::mutex> g(pimpl_->solo_);
	pimpl_->flags_ = new_flags;
}

auto link::rename(std::string new_name) -> void {
	pimpl_->send(pimpl_, a_lnk_rename(), std::move(new_name), false);
}

auto link::rename_silent(std::string new_name) -> void {
	pimpl_->send(pimpl_, a_lnk_rename(), std::move(new_name), true);
}

auto link::req_status(Req request) const -> ReqStatus {
	return pimpl_->req_status(request);
}

auto link::rs_reset(Req request, ReqStatus new_rs) const -> ReqStatus {
	return pimpl_->rs_reset(request, new_rs);
}

auto link::rs_reset_if_eq(Req request, ReqStatus self, ReqStatus new_rs) const -> ReqStatus {
	return pimpl_->rs_reset_if_eq(request, self, new_rs);
}

auto link::rs_reset_if_neq(Req request, ReqStatus self, ReqStatus new_rs) const -> ReqStatus {
	return pimpl_->rs_reset_if_neq(request, self, new_rs);
}

auto link::rs_data_changed() const -> void {
	// unconditionally sends Data = OK, ack
	pimpl_->send(pimpl_, a_lnk_status(), a_ack(), Req::Data, ReqStatus::OK, req_status(Req::Data));
}


/*-----------------------------------------------------------------------------
 *  sync API
 *-----------------------------------------------------------------------------*/
// get link's object ID
std::string link::oid() const {
	//pimpl_->pdbg() << "link: oid()" << std::endl;
	return actorf<std::string>(fimpl_, a_lnk_oid())
		.value_or( to_string(boost::uuids::nil_uuid()) );
}

std::string link::obj_type_id() const {
	//pimpl_->pdbg() << "link: obj_type_id()" << std::endl;
	return actorf<std::string>(fimpl_, a_lnk_otid())<commit_msg>tree/link: fix data_changed signal broadcasting<commit_after>/// @file
/// @author uentity
/// @date 14.09.2016
/// @brief Implementation os link
/// @copyright
/// 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 https://mozilla.org/MPL/2.0/

#include <bs/log.h>
#include <bs/kernel/config.h>
#include "link_actor.h"

#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>

OMIT_OBJ_SERIALIZATION

NAMESPACE_BEGIN(blue_sky::tree)

link::link(caf::actor impl_a) : aimpl_(std::move(impl_a)) {
	pimpl_ = caf::actor_cast<link_actor*>(aimpl_);
	if(!pimpl_) throw error{ "Trying to construct tree::link with invalid actor" };
	fimpl_ = caf::make_function_view(aimpl_, caf::duration{pimpl_->timeout_});
	//pimpl_->master_ = this;
}

link::~link() {
	pimpl_->goodbye();
}

auto link::pimpl() const -> link_actor* {
	return pimpl_;
}

/// access link's unique ID
auto link::id() const -> const id_type& {
	return pimpl_->id_;
}

/// obtain link's symbolic name
auto link::name() const -> std::string {
	return pimpl_->name_;
}

/// get link's container
auto link::owner() const -> sp_node {
	return pimpl_->owner_.lock();
}

void link::reset_owner(const sp_node& new_owner) {
	pimpl_->reset_owner(new_owner);
}

auto link::info() const -> result_or_err<inode> {
	return pimpl_->get_inode().and_then([](const inodeptr& i) {
		return i ?
			result_or_err<inode>(*i) :
			tl::make_unexpected(error::quiet(Error::EmptyInode));
	});
}

link::Flags link::flags() const {
	return pimpl_->flags_;
}

void link::set_flags(Flags new_flags) {
	std::lock_guard<std::mutex> g(pimpl_->solo_);
	pimpl_->flags_ = new_flags;
}

auto link::rename(std::string new_name) -> void {
	pimpl_->send(pimpl_, a_lnk_rename(), std::move(new_name), false);
}

auto link::rename_silent(std::string new_name) -> void {
	pimpl_->send(pimpl_, a_lnk_rename(), std::move(new_name), true);
}

auto link::req_status(Req request) const -> ReqStatus {
	return pimpl_->req_status(request);
}

auto link::rs_reset(Req request, ReqStatus new_rs) const -> ReqStatus {
	return pimpl_->rs_reset(request, new_rs);
}

auto link::rs_reset_if_eq(Req request, ReqStatus self, ReqStatus new_rs) const -> ReqStatus {
	return pimpl_->rs_reset_if_eq(request, self, new_rs);
}

auto link::rs_reset_if_neq(Req request, ReqStatus self, ReqStatus new_rs) const -> ReqStatus {
	return pimpl_->rs_reset_if_neq(request, self, new_rs);
}

auto link::rs_data_changed() const -> void {
	// unconditionally sends Data = OK, ack
	pimpl_->send(pimpl_->self_grp, a_lnk_status(), a_ack(), Req::Data, ReqStatus::OK, req_status(Req::Data));
}


/*-----------------------------------------------------------------------------
 *  sync API
 *-----------------------------------------------------------------------------*/
// get link's object ID
std::string link::oid() const {
	//pimpl_->pdbg() << "link: oid()" << std::endl;
	return actorf<std::string>(fimpl_, a_lnk_oid())
		.value_or( to_string(boost::uuids::nil_uuid()) );
}

std::string link::obj_type_id() const {
	//pimpl_->pdbg() << "link: obj_type_id()" << std::endl;
	return actorf<std::string>(fimpl_, a_lnk_otid())
{'fraction_non_alphanumeric': 0.21162212554381604, 'fraction_numerical': 0.0037290242386575512, 'mean_word_length': 3.9477325134511916, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 88, 'https://': 2, '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': '3066737', 'n_tokens_mistral': 2313, 'n_tokens_neox': 2268, 'n_words': 495}