1 #ifndef PSGS_OSGPROCESSORBASE__HPP 2 #define PSGS_OSGPROCESSORBASE__HPP 3 4 /* $Id: osg_processor_base.hpp 629837 2021-04-22 12:47:49Z ivanov $ 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: Eugene Vasilchenko 30 * 31 * File Description: base class for processors which may generate os_gateway 32 * fetches 33 * 34 */ 35 36 #include <corelib/request_status.hpp> 37 #include "psgs_request.hpp" 38 #include "psgs_reply.hpp" 39 #include "ipsgs_processor.hpp" 40 41 BEGIN_NCBI_NAMESPACE; 42 43 class CRequestContext; 44 45 BEGIN_NAMESPACE(objects); 46 47 class CID2_Request; 48 class CID2_Reply; 49 50 END_NAMESPACE(objects); 51 52 BEGIN_NAMESPACE(psg); 53 BEGIN_NAMESPACE(osg); 54 55 class COSGFetch; 56 class COSGConnectionPool; 57 class COSGConnection; 58 59 60 enum EDebugLevel { 61 eDebug_none = 0, 62 eDebug_error = 1, 63 eDebug_open = 2, 64 eDebug_exchange = 4, 65 eDebug_asn = 5, 66 eDebug_blob = 8, 67 eDebug_raw = 9, 68 eDebugLevel_default = eDebug_error 69 }; 70 71 int GetDebugLevel(); 72 void SetDebugLevel(int debug_level); 73 74 Severity GetDiagSeverity(); 75 void SetDiagSeverity(EDiagSev severity); 76 77 USING_SCOPE(objects); 78 79 80 // actual OSG processor base class for communication with OSG 81 class CPSGS_OSGProcessorBase : public IPSGS_Processor 82 { 83 public: 84 CPSGS_OSGProcessorBase(const CRef<COSGConnectionPool>& pool, 85 const shared_ptr<CPSGS_Request>& request, 86 const shared_ptr<CPSGS_Reply>& reply, 87 TProcessorPriority priority); 88 virtual ~CPSGS_OSGProcessorBase(); 89 90 virtual IPSGS_Processor* CreateProcessor(shared_ptr<CPSGS_Request> request, 91 shared_ptr<CPSGS_Reply> reply, 92 TProcessorPriority priority) const override; 93 virtual void Process(void) override; 94 virtual void Cancel(void) override; 95 virtual EPSGS_Status GetStatus(void) override; 96 IsCanceled() const97 bool IsCanceled() const 98 { 99 return m_Canceled; 100 } 101 102 // notify processor about communication events 103 virtual void NotifyOSGCallStart(); 104 virtual void NotifyOSGCallReply(const CID2_Reply& reply); 105 virtual void NotifyOSGCallEnd(); 106 107 typedef vector<CRef<COSGFetch>> TFetches; GetFetches() const108 const TFetches& GetFetches() const 109 { 110 return m_Fetches; 111 } 112 113 protected: GetConnectionPool() const114 COSGConnectionPool& GetConnectionPool() const { 115 return m_ConnectionPool.GetNCObject(); 116 } 117 118 void SetFinalStatus(EPSGS_Status status); 119 void FinalizeResult(EPSGS_Status status); 120 void FinalizeResult(); 121 122 void AddRequest(const CRef<CID2_Request>& req); 123 124 // create ID2 requests for the PSG request 125 virtual void CreateRequests() = 0; 126 // process ID2 replies and issue PSG reply 127 virtual void ProcessReplies() = 0; 128 // reset processing state in case of ID2 communication failure before next attempt 129 virtual void ResetReplies(); 130 131 private: 132 CRef<CRequestContext> m_Context; 133 CRef<COSGConnectionPool> m_ConnectionPool; 134 CRef<COSGConnection> m_Connection; 135 TFetches m_Fetches; 136 EPSGS_Status m_Status; 137 volatile bool m_Canceled; 138 }; 139 140 141 END_NAMESPACE(osg); 142 END_NAMESPACE(psg); 143 END_NCBI_NAMESPACE; 144 145 #endif // PSGS_OSGPROCESSORBASE__HPP 146