|
| 1 | +// GRPC Proxy Class implementation generated with xpcf_grpc_gen |
| 2 | +#include "IPanopticSegmentation_grpcProxy.h" |
| 3 | +#include <cstddef> |
| 4 | +#include <boost/date_time.hpp> |
| 5 | +#include <xpcf/core/Exception.h> |
| 6 | +#include <xpcf/remoting/ISerializable.h> |
| 7 | +#include <grpcpp/client_context.h> |
| 8 | +#include <grpcpp/create_channel.h> |
| 9 | +#include <grpcpp/security/credentials.h> |
| 10 | +#include <boost/algorithm/string.hpp> |
| 11 | +namespace xpcf = org::bcom::xpcf; |
| 12 | + |
| 13 | +template<> org::bcom::xpcf::grpc::proxyIPanopticSegmentation::IPanopticSegmentation_grpcProxy* xpcf::ComponentFactory::createInstance<org::bcom::xpcf::grpc::proxyIPanopticSegmentation::IPanopticSegmentation_grpcProxy>(); |
| 14 | + |
| 15 | +namespace org::bcom::xpcf::grpc::proxyIPanopticSegmentation { |
| 16 | + |
| 17 | +IPanopticSegmentation_grpcProxy::IPanopticSegmentation_grpcProxy():xpcf::ConfigurableBase(xpcf::toMap<IPanopticSegmentation_grpcProxy>()) |
| 18 | +{ |
| 19 | + declareInterface<SolAR::api::segm::IPanopticSegmentation>(this); |
| 20 | + declareProperty("channelUrl",m_channelUrl); |
| 21 | + declareProperty("channelCredentials",m_channelCredentials); |
| 22 | + m_grpcProxyCompressionConfig.resize(2); |
| 23 | + declarePropertySequence("grpc_compress_proxy", m_grpcProxyCompressionConfig); |
| 24 | +} |
| 25 | + |
| 26 | + |
| 27 | +void IPanopticSegmentation_grpcProxy::unloadComponent () |
| 28 | +{ |
| 29 | + delete this; |
| 30 | + return; |
| 31 | +} |
| 32 | + |
| 33 | + |
| 34 | +XPCFErrorCode IPanopticSegmentation_grpcProxy::onConfigured() |
| 35 | +{ |
| 36 | + m_channel = ::grpc::CreateChannel(m_channelUrl, xpcf::GrpcHelper::getCredentials(static_cast<xpcf::grpcCredentials>(m_channelCredentials))); |
| 37 | + m_grpcStub = ::grpcIPanopticSegmentation::grpcIPanopticSegmentationService::NewStub(m_channel); |
| 38 | + for (auto & compressionLine : m_grpcProxyCompressionConfig) { |
| 39 | + translateClientConfiguration(compressionLine, m_serviceCompressionInfos, m_methodCompressionInfosMap); |
| 40 | + } |
| 41 | + return xpcf::XPCFErrorCode::_SUCCESS; |
| 42 | +} |
| 43 | + |
| 44 | + |
| 45 | +SolAR::FrameworkReturnCode IPanopticSegmentation_grpcProxy::segment(SRef<SolAR::datastructure::Image> const image, SRef<SolAR::datastructure::Image>& labelMap, std::vector<SolAR::datastructure::Rectanglei>& boxes, std::vector<std::pair<uint32_t,uint32_t>>& classObjectIds, std::vector<float>& scores) |
| 46 | +{ |
| 47 | + ::grpc::ClientContext context; |
| 48 | + ::grpcIPanopticSegmentation::segmentRequest reqIn; |
| 49 | + ::grpcIPanopticSegmentation::segmentResponse respOut; |
| 50 | + #ifndef DISABLE_GRPC_COMPRESSION |
| 51 | + xpcf::grpcCompressionInfos proxyCompressionInfo = xpcf::deduceClientCompressionInfo(m_serviceCompressionInfos, "segment", m_methodCompressionInfosMap); |
| 52 | + xpcf::grpcCompressType serverCompressionType = xpcf::prepareClientCompressionContext(context, proxyCompressionInfo); |
| 53 | + reqIn.set_grpcservercompressionformat (static_cast<int32_t>(serverCompressionType)); |
| 54 | + #endif |
| 55 | + reqIn.set_image(xpcf::serialize<SRef<SolAR::datastructure::Image>>(image)); |
| 56 | + reqIn.set_labelmap(xpcf::serialize<SRef<SolAR::datastructure::Image>>(labelMap)); |
| 57 | + reqIn.set_boxes(xpcf::serialize<std::vector<SolAR::datastructure::Rectanglei>>(boxes)); |
| 58 | + reqIn.set_classobjectids(xpcf::serialize<std::vector<std::pair<uint32_t,uint32_t>>>(classObjectIds)); |
| 59 | + reqIn.set_scores(xpcf::serialize<std::vector<float>>(scores)); |
| 60 | + #ifdef ENABLE_PROXY_TIMERS |
| 61 | + boost::posix_time::ptime start = boost::posix_time::microsec_clock::universal_time(); |
| 62 | + std::cout << "====> IPanopticSegmentation_grpcProxy::segment request sent at " << to_simple_string(start) << std::endl; |
| 63 | + #endif |
| 64 | + ::grpc::Status grpcRemoteStatus = m_grpcStub->segment(&context, reqIn, &respOut); |
| 65 | + #ifdef ENABLE_PROXY_TIMERS |
| 66 | + boost::posix_time::ptime end = boost::posix_time::microsec_clock::universal_time(); |
| 67 | + std::cout << "====> IPanopticSegmentation_grpcProxy::segment response received at " << to_simple_string(end) << std::endl; |
| 68 | + std::cout << " => elapsed time = " << ((end - start).total_microseconds() / 1000.00) << " ms" << std::endl; |
| 69 | + #endif |
| 70 | + if (!grpcRemoteStatus.ok()) { |
| 71 | + std::cout << "segment rpc failed." << std::endl; |
| 72 | + throw xpcf::RemotingException("grpcIPanopticSegmentationService","segment",static_cast<uint32_t>(grpcRemoteStatus.error_code())); |
| 73 | + } |
| 74 | + |
| 75 | + labelMap = xpcf::deserialize<SRef<SolAR::datastructure::Image>>(respOut.labelmap()); |
| 76 | + boxes = xpcf::deserialize<std::vector<SolAR::datastructure::Rectanglei>>(respOut.boxes()); |
| 77 | + classObjectIds = xpcf::deserialize<std::vector<std::pair<uint32_t,uint32_t>>>(respOut.classobjectids()); |
| 78 | + scores = xpcf::deserialize<std::vector<float>>(respOut.scores()); |
| 79 | + return static_cast<SolAR::FrameworkReturnCode>(respOut.xpcfgrpcreturnvalue()); |
| 80 | +} |
| 81 | + |
| 82 | + |
| 83 | +} |
| 84 | + |
0 commit comments