<commit_before>#include <future>

#include "plugins/calibration/calibration.h"
#include "calibration/calibration.grpc.pb.h"

namespace dronecode_sdk {
namespace backend {

template<typename Calibration = Calibration>
class CalibrationServiceImpl final : public rpc::calibration::CalibrationService::Service {
public:
    CalibrationServiceImpl(Calibration &calibration) : _calibration(calibration) {}

    static std::unique_ptr<rpc::calibration::CalibrationResult>
    translateCalibrationResult(const dronecode_sdk::Calibration::Result &calibration_result)
    {
        auto rpc_calibration_result = std::unique_ptr<rpc::calibration::CalibrationResult>(
            new rpc::calibration::CalibrationResult());

        auto rpc_result =
            static_cast<rpc::calibration::CalibrationResult::Result>(calibration_result);
        rpc_calibration_result->set_result(rpc_result);
        rpc_calibration_result->set_result_str(
            dronecode_sdk::Calibration::result_str(calibration_result));

        return rpc_calibration_result;
    }

    static std::unique_ptr<rpc::calibration::ProgressData>
    translateProgressData(const dronecode_sdk::Calibration::ProgressData &progress_data)
    {
        auto rpc_progress_data =
            std::unique_ptr<rpc::calibration::ProgressData>(new rpc::calibration::ProgressData());

        rpc_progress_data->set_has_progress(progress_data.has_progress);
        rpc_progress_data->set_progress(progress_data.progress);
        rpc_progress_data->set_has_status_text(progress_data.has_status_text);
        rpc_progress_data->set_status_text(progress_data.status_text);

        return rpc_progress_data;
    }

    grpc::Status
    CalibrateGyro(grpc::ServerContext * /* context */,
                  const rpc::calibration::CalibrateGyroRequest request,
                  grpc::ServerWriter<rpc::calibration::CalibrateGyroResponse> *writer) override
    {
        std::promise<void> stream_closed_promise;
        auto stream_closed_future = stream_closed_promise.get_future();

        bool is_finished = false;

        _calibration.calibrate_gyro_async([this, &writer, &stream_closed_promise, &is_finished](
                                              const dronecode_sdk::Calibration::Result result,
                                              const float progress,
                                              const std::string &status_text) {
            rpc::calibration::CalibrateGyroResponse rpc_response;
            rpc_response.set_allocated_calibration_result(translateCalibrationResult(result).get());

            std::lock_guard<std::mutex> lock(_subscribe_mutex);
            if (!writer->Write(rpc_response) && !is_finished) {
                is_finished = true;
                stream_closed_promise.set_value();
            }
        });

        stream_closed_future.wait();
        return grpc::Status::OK;
    }

    grpc::Status CalibrateAccelerometer(
        grpc::ServerContext * /* context */,
        const rpc::calibration::CalibrateAccelerometerRequest request,
        grpc::ServerWriter<rpc::calibration::CalibrateAccelerometerResponse> *writer) override
    {
        std::promise<void> stream_closed_promise;
        auto stream_closed_future = stream_closed_promise.get_future();

        bool is_finished = false;

        _calibration.calibrate_accelerometer_async(
            [this, &writer, &stream_closed_promise, &is_finished](
                const dronecode_sdk::Calibration::Result result,
                const float progress,
                const std::string &status_text) {
                rpc::calibration::CalibrateAccelerometerResponse rpc_response;
                rpc_response.set_allocated_calibration_result(
                    translateCalibrationResult(result).get());

                std::lock_guard<std::mutex> lock(_subscribe_mutex);
                if (!writer->Write(rpc_response) && !is_finished) {
                    is_finished = true;
                    stream_closed_promise.set_value();
                }
            });

        stream_closed_future.wait();
        return grpc::Status::OK;
    }

    grpc::Status CalibrateMagnetometer(
        grpc::ServerContext * /* context */,
        const rpc::calibration::CalibrateMagnetometerRequest request,
        grpc::ServerWriter<rpc::calibration::CalibrateMagnetometerResponse> *writer) override
    {
        std::promise<void> stream_closed_promise;
        auto stream_closed_future = stream_closed_promise.get_future();

        bool is_finished = false;

        _calibration.calibrate_magnetometer_async(
            [this, &writer, &stream_closed_promise, &is_finished](
                const dronecode_sdk::Calibration::Result result,
                const float progress,
                const std::string &status_text) {
                rpc::calibration::CalibrateMagnetometerResponse rpc_response;
                rpc_response.set_allocated_calibration_result(
                    translateCalibrationResult(result).get());

                std::lock_guard<std::mutex> lock(_subscribe_mutex);
                if (!writer->Write(rpc_response) && !is_finished) {
                    is_finished = true;
                    stream_closed_promise.set_value();
                }
            });

        stream_closed_future.wait();
        return grpc::Status::OK;
    }

    grpc::Status CalibrateGimbalAccelerometer(
        grpc::ServerContext * /* context */,
        const rpc::calibration::CalibrateGimbalAccelerometerRequest request,
        grpc::ServerWriter<rpc::calibration::CalibrateGimbalAccelerometerResponse> *writer) override
    {
        std::promise<void> stream_closed_promise;
        auto stream_closed_future = stream_closed_promise.get_future();

        bool is_finished = false;<commit_msg>backend: fix calibration build on macos<commit_after>#include <future>

#include "plugins/calibration/calibration.h"
#include "calibration/calibration.grpc.pb.h"

namespace dronecode_sdk {
namespace backend {

template<typename Calibration = Calibration>
class CalibrationServiceImpl final : public rpc::calibration::CalibrationService::Service {
public:
    CalibrationServiceImpl(Calibration &calibration) : _calibration(calibration) {}

    static std::unique_ptr<rpc::calibration::CalibrationResult>
    translateCalibrationResult(const dronecode_sdk::Calibration::Result &calibration_result)
    {
        auto rpc_calibration_result = std::unique_ptr<rpc::calibration::CalibrationResult>(
            new rpc::calibration::CalibrationResult());

        auto rpc_result =
            static_cast<rpc::calibration::CalibrationResult::Result>(calibration_result);
        rpc_calibration_result->set_result(rpc_result);
        rpc_calibration_result->set_result_str(
            dronecode_sdk::Calibration::result_str(calibration_result));

        return rpc_calibration_result;
    }

    static std::unique_ptr<rpc::calibration::ProgressData>
    translateProgressData(const dronecode_sdk::Calibration::ProgressData &progress_data)
    {
        auto rpc_progress_data =
            std::unique_ptr<rpc::calibration::ProgressData>(new rpc::calibration::ProgressData());

        rpc_progress_data->set_has_progress(progress_data.has_progress);
        rpc_progress_data->set_progress(progress_data.progress);
        rpc_progress_data->set_has_status_text(progress_data.has_status_text);
        rpc_progress_data->set_status_text(progress_data.status_text);

        return rpc_progress_data;
    }

    grpc::Status
    CalibrateGyro(grpc::ServerContext * /* context */,
                  const rpc::calibration::CalibrateGyroRequest *request,
                  grpc::ServerWriter<rpc::calibration::CalibrateGyroResponse> *writer) override
    {
        std::promise<void> stream_closed_promise;
        auto stream_closed_future = stream_closed_promise.get_future();

        bool is_finished = false;

        _calibration.calibrate_gyro_async([this, &writer, &stream_closed_promise, &is_finished](
                                              const dronecode_sdk::Calibration::Result result,
                                              const float progress,
                                              const std::string &status_text) {
            rpc::calibration::CalibrateGyroResponse rpc_response;
            rpc_response.set_allocated_calibration_result(translateCalibrationResult(result).get());

            std::lock_guard<std::mutex> lock(_subscribe_mutex);
            if (!writer->Write(rpc_response) && !is_finished) {
                is_finished = true;
                stream_closed_promise.set_value();
            }
        });

        stream_closed_future.wait();
        return grpc::Status::OK;
    }

    grpc::Status CalibrateAccelerometer(
        grpc::ServerContext * /* context */,
        const rpc::calibration::CalibrateAccelerometerRequest *request,
        grpc::ServerWriter<rpc::calibration::CalibrateAccelerometerResponse> *writer) override
    {
        std::promise<void> stream_closed_promise;
        auto stream_closed_future = stream_closed_promise.get_future();

        bool is_finished = false;

        _calibration.calibrate_accelerometer_async(
            [this, &writer, &stream_closed_promise, &is_finished](
                const dronecode_sdk::Calibration::Result result,
                const float progress,
                const std::string &status_text) {
                rpc::calibration::CalibrateAccelerometerResponse rpc_response;
                rpc_response.set_allocated_calibration_result(
                    translateCalibrationResult(result).get());

                std::lock_guard<std::mutex> lock(_subscribe_mutex);
                if (!writer->Write(rpc_response) && !is_finished) {
                    is_finished = true;
                    stream_closed_promise.set_value();
                }
            });

        stream_closed_future.wait();
        return grpc::Status::OK;
    }

    grpc::Status CalibrateMagnetometer(
        grpc::ServerContext * /* context */,
        const rpc::calibration::CalibrateMagnetometerRequest *request,
        grpc::ServerWriter<rpc::calibration::CalibrateMagnetometerResponse> *writer) override
    {
        std::promise<void> stream_closed_promise;
        auto stream_closed_future = stream_closed_promise.get_future();

        bool is_finished = false;

        _calibration.calibrate_magnetometer_async(
            [this, &writer, &stream_closed_promise, &is_finished](
                const dronecode_sdk::Calibration::Result result,
                const float progress,
                const std::string &status_text) {
                rpc::calibration::CalibrateMagnetometerResponse rpc_response;
                rpc_response.set_allocated_calibration_result(
                    translateCalibrationResult(result).get());

                std::lock_guard<std::mutex> lock(_subscribe_mutex);
                if (!writer->Write(rpc_response) && !is_finished) {
                    is_finished = true;
                    stream_closed_promise.set_value();
                }
            });

        stream_closed_future.wait();
        return grpc::Status::OK;
    }

    grpc::Status CalibrateGimbalAccelerometer(
        grpc::ServerContext * /* context */,
        const rpc::calibration::CalibrateGimbalAccelerometerRequest *request,
        grpc::ServerWriter<rpc::calibration::CalibrateGimbalAccelerometerResponse> *writer) override
    {
        std::promise<void> stream_closed_promise;
        auto stream_closed_future = stream_closed_promise.get_future();

        bool is_finished = false;
{'fraction_non_alphanumeric': 0.09459691252144083, 'fraction_numerical': 0.0, 'mean_word_length': 2.8792415169660677, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5322825', 'n_tokens_mistral': 3221, 'n_tokens_neox': 3078, 'n_words': 426}