github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/common/ipc/shm_service_recv_handler.cpp (about) 1 // Copyright (C) 2018 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 #include "common/ipc/shm_service_recv_handler.h" 21 22 namespace neb { 23 namespace ipc { 24 namespace internal { 25 26 shm_service_recv_handler::shm_service_recv_handler( 27 boost::interprocess::managed_shared_memory *shmem, shm_service_op_queue *q) 28 : m_shmem(shmem), m_op_queue(q) {} 29 30 void shm_service_recv_handler::handle_recv_op( 31 const std::shared_ptr<shm_service_op_base> &op) { 32 assert(op->op_id() == shm_service_op_base::op_recv_obj); 33 34 shm_service_op_recv *recv_op = static_cast<shm_service_op_recv *>(op.get()); 35 36 void *data_pointer = recv_op->m_pointer; 37 shm_type_id_t type_id = recv_op->m_type_id; 38 if (data_pointer) { 39 typename decltype(m_all_handlers)::const_iterator fr = 40 m_all_handlers.find(type_id); 41 if (fr != m_all_handlers.end()) { 42 auto func = fr->second; 43 m_handler_thread.schedule([func, data_pointer]() { 44 try { 45 func(data_pointer); 46 } catch (const std::exception &e) { 47 LOG(WARNING) << "got exception when call handler " 48 << std::string(typeid(e).name()) << " : " << e.what(); 49 // throw shm_handle_recv_failure( 50 // std::string("shm_service_recv_handler, ") + 51 // std::string(typeid(e).name()) + " : " + e.what()); 52 } 53 }); 54 } else { 55 LOG(WARNING) << "cannot find data handler"; 56 } 57 } 58 } 59 } // namespace internal 60 } // namespace ipc 61 } // namespace neb