1 #ifndef PUBLIC_COMMENT_CALLBACK__HPP 2 #define PUBLIC_COMMENT_CALLBACK__HPP 3 4 /* $Id: public_comment_callback.hpp 619307 2020-11-03 13:09:26Z satskyse $ 5 * =========================================================================== 6 * 7 * PUBLIC DOMAIN NOTICE 8 * National Center for Biotechnology Information 9 * 10 * This software/database is a "United States Government Work" under the 11 * terms of the United States Copyright Act. It was written as part of 12 * the author's official duties as a United States Government employee and 13 * thus cannot be copyrighted. This software/database is freely available 14 * to the public for use. The National Library of Medicine and the U.S. 15 * Government have not placed any restriction on its use or reproduction. 16 * 17 * Although all reasonable efforts have been taken to ensure the accuracy 18 * and reliability of the software and data, the NLM and the U.S. 19 * Government do not and cannot warrant the performance or results that 20 * may be obtained by using this software or data. The NLM and the U.S. 21 * Government disclaim all warranties, express or implied, including 22 * warranties of performance, merchantability or fitness for any particular 23 * purpose. 24 * 25 * Please cite the author in any work or product based on this material. 26 * 27 * =========================================================================== 28 * 29 * Authors: Sergey Satskiy 30 * 31 * File Description: 32 * 33 */ 34 35 #include "http_server_transport.hpp" 36 #include "cass_fetch.hpp" 37 38 #include <functional> 39 40 41 using TPublicCommentConsumeCB = 42 function<void(CCassPublicCommentFetch * fetch_details, 43 string comment, 44 bool is_found)>; 45 using TPublicCommentErrorCB = 46 function<void(CCassPublicCommentFetch * fetch_details, 47 CRequestStatus::ECode status, 48 int code, 49 EDiagSev severity, 50 const string & message)>; 51 52 53 class CPublicCommentConsumeCallback 54 { 55 public: CPublicCommentConsumeCallback(TPublicCommentConsumeCB consume_cb,CCassPublicCommentFetch * fetch_details)56 CPublicCommentConsumeCallback( 57 TPublicCommentConsumeCB consume_cb, 58 CCassPublicCommentFetch * fetch_details) : 59 m_ConsumeCB(consume_cb), 60 m_FetchDetails(fetch_details), 61 m_PublicCommentRetrieveTiming(chrono::high_resolution_clock::now()) 62 {} 63 operator ()(string comment,bool is_found)64 void operator()(string comment, bool is_found) 65 { 66 EPSGOperationStatus op_status = eOpStatusFound; 67 if (!is_found) 68 op_status = eOpStatusNotFound; 69 70 CPubseqGatewayApp::GetInstance()->GetTiming(). 71 Register(ePublicCommentRetrieve, op_status, 72 m_PublicCommentRetrieveTiming); 73 74 m_ConsumeCB(m_FetchDetails, comment, is_found); 75 } 76 77 private: 78 TPublicCommentConsumeCB m_ConsumeCB; 79 CCassPublicCommentFetch * m_FetchDetails; 80 chrono::high_resolution_clock::time_point m_PublicCommentRetrieveTiming; 81 }; 82 83 84 class CPublicCommentErrorCallback 85 { 86 public: CPublicCommentErrorCallback(TPublicCommentErrorCB error_cb,CCassPublicCommentFetch * fetch_details)87 CPublicCommentErrorCallback( 88 TPublicCommentErrorCB error_cb, 89 CCassPublicCommentFetch * fetch_details) : 90 m_ErrorCB(error_cb), 91 m_FetchDetails(fetch_details), 92 m_PublicCommentRetrieveTiming(chrono::high_resolution_clock::now()) 93 {} 94 operator ()(CRequestStatus::ECode status,int code,EDiagSev severity,const string & message)95 void operator()(CRequestStatus::ECode status, 96 int code, 97 EDiagSev severity, 98 const string & message) 99 { 100 if (status == CRequestStatus::e404_NotFound) 101 CPubseqGatewayApp::GetInstance()->GetTiming(). 102 Register(ePublicCommentRetrieve, eOpStatusNotFound, 103 m_PublicCommentRetrieveTiming); 104 m_ErrorCB(m_FetchDetails, status, code, severity, message); 105 } 106 107 private: 108 TPublicCommentErrorCB m_ErrorCB; 109 CCassPublicCommentFetch * m_FetchDetails; 110 chrono::high_resolution_clock::time_point m_PublicCommentRetrieveTiming; 111 }; 112 113 114 #endif 115 116