1 #ifndef PSGS_OSGFETCH__HPP 2 #define PSGS_OSGFETCH__HPP 3 4 /* $Id: osg_fetch.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: class to keep single ID2 request/replies 32 * 33 */ 34 35 #include <corelib/ncbiobj.hpp> 36 #include <vector> 37 38 BEGIN_NCBI_NAMESPACE; 39 40 class CRequestContext; 41 42 BEGIN_NAMESPACE(objects); 43 44 class CID2_Request; 45 class CID2_Reply; 46 47 END_NAMESPACE(objects); 48 49 BEGIN_NAMESPACE(psg); 50 BEGIN_NAMESPACE(osg); 51 52 USING_SCOPE(objects); 53 54 55 class COSGFetch : public CObject 56 { 57 public: 58 enum EStatus { 59 eIdle, 60 eSent, 61 eReceived, 62 eFailed 63 }; 64 65 explicit COSGFetch(CRef<CID2_Request> request, 66 const CRef<CRequestContext>& context); 67 virtual ~COSGFetch(); 68 GetRequest() const69 const CRef<CID2_Request>& GetRequest() const 70 { 71 return m_Request; 72 } 73 GetContext() const74 const CRef<CRequestContext>& GetContext() const 75 { 76 return m_Context; 77 } 78 79 typedef vector<CRef<CID2_Reply>> TReplies; GetReplies() const80 const TReplies& GetReplies() const 81 { 82 return m_Replies; 83 } 84 bool EndOfReplies() const; 85 void AddReply(CRef<CID2_Reply>&& reply); 86 void ResetReplies(); 87 GetStatus() const88 EStatus GetStatus() const 89 { 90 return m_Status; 91 } IsStarted() const92 bool IsStarted() const 93 { 94 return m_Status != eIdle; 95 } IsFinished() const96 bool IsFinished() const 97 { 98 return m_Status == eReceived || m_Status == eFailed; 99 } 100 SetSent()101 void SetSent() 102 { 103 _ASSERT(m_Status == eIdle); 104 m_Status = eSent; 105 } SetReplies(const TReplies & replies)106 void SetReplies(const TReplies& replies) 107 { 108 _ASSERT(m_Status == eSent); 109 m_Replies = replies; 110 m_Status = eReceived; 111 } SetFailed()112 void SetFailed() 113 { 114 m_Status = eFailed; 115 } 116 117 private: 118 CRef<CID2_Request> m_Request; 119 CRef<CRequestContext> m_Context; 120 TReplies m_Replies; 121 EStatus m_Status; 122 }; 123 124 125 END_NAMESPACE(osg); 126 END_NAMESPACE(psg); 127 END_NCBI_NAMESPACE; 128 129 #endif // PSGS_OSGPFETCH__HPP 130