LCOV - code coverage report
Current view: top level - wjrpc/method/mem_fun - mem_fun_handler.hpp (source / functions) Hit Total Coverage
Test: wjrpc-coverage.info Lines: 8 12 66.7 %
Date: 2019-09-13 Functions: 7 12 58.3 %

          Line data    Source code
       1             : //
       2             : // Author: Vladimir Migashko <migashko@gmail.com>, (C) 2011-2016
       3             : //
       4             : // Copyright: See COPYING file that comes with this distribution
       5             : //
       6             : 
       7             : #pragma once
       8             : 
       9             : #include <wjrpc/method/mem_fun/mem_fun_helper.hpp>
      10             : 
      11             : namespace wjrpc{
      12             : 
      13             : template<
      14             :   typename Params, 
      15             :   typename Result, 
      16             :   typename I, 
      17             :   void (I::*mem_ptr)( 
      18             :     std::unique_ptr<Params>, 
      19             :     std::function< void(std::unique_ptr<Result>) > 
      20             :   ) 
      21             : >
      22           8 : struct mem_fun_handler
      23             : {
      24             :   typedef std::unique_ptr<Params> request_ptr;
      25             :   typedef std::unique_ptr<Result> responce_ptr;
      26             :   typedef std::unique_ptr<error> error_ptr;
      27             :   typedef std::function< void(responce_ptr, error_ptr) > jsonrpc_callback;
      28             : 
      29             :   template<typename T>
      30           0 :   void operator()(T& t, request_ptr req) const
      31             :   {
      32           0 :     if ( auto i = t.target() )
      33             :     {
      34           0 :       (i.get()->*mem_ptr)(std::move(req), nullptr );
      35             :     }
      36           0 :   }
      37             : 
      38             :   template<typename T>
      39           5 :   void operator()(T& t, request_ptr req, jsonrpc_callback cb) const
      40             :   {
      41          10 :     if ( auto i = t.target() )
      42             :     {
      43          12 :       (i.get()->*mem_ptr)( 
      44           4 :         std::move(req), 
      45           4 :         mem_fun_make_callback( std::move(cb)) 
      46             :       );
      47             :     }
      48             :     else 
      49             :     {
      50           1 :       mem_fun_service_unavailable( std::move(cb) );
      51             :     }
      52           5 :   }
      53             : };
      54             : 
      55             : } // wjrpc
      56             : 
      57             : 

Generated by: LCOV version 1.10