github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/core/ir_warden.h (about) 1 // Copyright (C) 2017 go-nebulas authors 2 // 3 // This file is part of the go-nebulas library. 4 // 5 // the go-nebulas library is free software: you can redistribute it and/or 6 // modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation, either version 3 of the License, or 9 // (at your option) any later version. 10 // 11 // the go-nebulas library is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with the go-nebulas library. If not, see 18 // <http://www.gnu.org/licenses/>. 19 // 20 21 #pragma once 22 #include "common/common.h" 23 #include "core/net_ipc/nipc_pkg.h" 24 #include "fs/ir_manager/ir_manager.h" 25 #include "fs/proto/ir.pb.h" 26 #include "fs/storage.h" 27 #include "util/quitable_thread.h" 28 #include "util/singleton.h" 29 #include <boost/asio.hpp> 30 #include <boost/asio/deadline_timer.hpp> 31 #include <condition_variable> 32 #include <thread> 33 34 namespace neb { 35 namespace core { 36 class ir_warden : public util::singleton<ir_warden> { 37 public: 38 ir_warden(); 39 virtual ~ir_warden(); 40 41 std::unique_ptr<nbre::NBREIR> get_ir_by_name_version(const std::string &name, 42 uint64_t version); 43 std::unique_ptr<std::vector<nbre::NBREIR>> 44 get_ir_by_name_height(const std::string &name, uint64_t height, 45 bool depends = true); 46 47 bool is_sync_already() const; 48 void wait_until_sync(); 49 void on_timer(); 50 51 void on_receive_ir_transactions( 52 const std::shared_ptr<nbre_ir_transactions_req> &txs_ptr); 53 54 private: 55 std::unique_ptr<fs::ir_manager> m_ir_manager; 56 bool m_is_sync_already; 57 mutable std::mutex m_sync_mutex; 58 std::condition_variable m_sync_cond_var; 59 util::wakeable_queue<std::shared_ptr<nbre_ir_transactions_req>> m_queue; 60 }; 61 } 62 }