//
// Created by zx on 2019/12/6.
//
#include <iostream>
#include <string>
#include <fstream>
#include <thread>
#include <unistd.h>

#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/text_format.h>
using google::protobuf::io::FileInputStream;
using google::protobuf::io::FileOutputStream;
using google::protobuf::io::ZeroCopyInputStream;
using google::protobuf::io::CodedInputStream;
using google::protobuf::io::ZeroCopyOutputStream;
using google::protobuf::io::CodedOutputStream;
using google::protobuf::Message;

#include <ros/ros.h>

#include "EleFence.pb.h"
#include "LogFiles.h"
#include "Lidar.h"
#include "region_worker.h"
#include "unistd.h"
#include "s7_plc.h"
#include "PlcData.h"

#ifndef FENCECONTROLLER_H
#define FENCECONTROLLER_H


class FenceController{
public:
    FenceController(std::string path);
    ~FenceController();
    static void cloudMergeUpdate(FenceController* fc);
    void GetCloud(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_out);

private:
    bool ReadProtoParam(std::string path);

public:
    bool                                    m_initialized;
    ros::NodeHandle                         m_handle;
    std::mutex                              m_cloud_mutex;
private:
    EleFence::globalParam                   m_global_param;

    std::vector<Lidar*>                     p_lidars;
    std::vector<Region_worker*>             p_region_workers;

    PlcData*                                p_plc_data;

    StdCondition                            m_cond_exit;
    std::thread*                            m_update_thread;

    pcl::PointCloud<pcl::PointXYZ>::Ptr     p_merged_cloud;
};

#endif //FENCECONTROLLER_H
