1 #ifndef PSGS_TSECHUNKPROCESSOR__HPP
2 #define PSGS_TSECHUNKPROCESSOR__HPP
3 
4 /*  $Id: tse_chunk_processor.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: Sergey Satskiy
30  *
31  * File Description: get TSE chunk processor
32  *
33  */
34 
35 #include "cass_blob_base.hpp"
36 #include "id2info.hpp"
37 
38 USING_NCBI_SCOPE;
39 USING_IDBLOB_SCOPE;
40 
41 // Forward declaration
42 class CCassFetch;
43 
44 
45 class CPSGS_TSEChunkProcessor : public CPSGS_CassBlobBase
46 {
47 public:
48     virtual IPSGS_Processor* CreateProcessor(shared_ptr<CPSGS_Request> request,
49                                              shared_ptr<CPSGS_Reply> reply,
50                                              TProcessorPriority  priority) const;
51     virtual void Process(void);
52     virtual void Cancel(void);
53     virtual EPSGS_Status GetStatus(void);
54     virtual string GetName(void) const;
55     virtual void ProcessEvent(void);
56 
57 public:
58     CPSGS_TSEChunkProcessor();
59     CPSGS_TSEChunkProcessor(
60             shared_ptr<CPSGS_Request> request,
61             shared_ptr<CPSGS_Reply> reply,
62             TProcessorPriority  priority,
63             shared_ptr<CPSGS_SatInfoChunksVerFlavorId2Info> sat_info_chunk_ver_id2info,
64             shared_ptr<CPSGS_IdModifiedVerFlavorId2Info>    id_mod_ver_id2info);
65     virtual ~CPSGS_TSEChunkProcessor();
66 
67 private:
68     void OnGetBlobProp(CCassBlobFetch *  fetch_details,
69                        CBlobRecord const &  blob, bool is_found);
70     void OnGetBlobError(CCassBlobFetch *  fetch_details,
71                         CRequestStatus::ECode  status, int  code,
72                         EDiagSev  severity, const string &  message);
73     void OnGetBlobChunk(CCassBlobFetch *  fetch_details,
74                         CBlobRecord const &  blob,
75                         const unsigned char *  chunk_data,
76                         unsigned int  data_size, int  chunk_no);
77     void OnGetSplitHistoryError(CCassSplitHistoryFetch *  fetch_details,
78                                 CRequestStatus::ECode  status,
79                                 int  code,
80                                 EDiagSev  severity,
81                                 const string &  message);
82     void OnGetSplitHistory(CCassSplitHistoryFetch *  fetch_details,
83                            vector<SSplitHistoryRecord> && result);
84 
85 private:
86     void x_ProcessSatInfoChunkVerId2Info(void);
87     void x_ProcessIdModVerId2Info(void);
88 
89     void x_SendProcessorError(const string &  msg,
90                               CRequestStatus::ECode  status,
91                               int  code);
92     bool x_ValidateTSEChunkNumber(
93                     int64_t  requested_chunk,
94                     CPSGS_SatInfoChunksVerFlavorId2Info::TChunks  total_chunks,
95                     bool  need_finish);
96     bool x_TSEChunkSatToKeyspace(SCass_BlobId &  blob_id);
97     EPSGSId2InfoFlavor x_DetectId2InfoFlavor(
98             const string &                                    id2_info,
99             shared_ptr<CPSGS_SatInfoChunksVerFlavorId2Info> & sat_info_chunk_ver_id2info,
100             shared_ptr<CPSGS_IdModifiedVerFlavorId2Info> &    id_mod_ver_id2info) const;
101     bool x_ParseTSEChunkId2Info(
102             const string &                                     info,
103             unique_ptr<CPSGS_SatInfoChunksVerFlavorId2Info> &  id2_info,
104             const SCass_BlobId &                               blob_id,
105             bool                                               need_finish);
106     bool x_TSEChunkSatToKeyspace(SCass_BlobId &  blob_id,
107                                  bool  need_finish);
108     void x_RequestTSEChunk(const SSplitHistoryRecord &  split_record,
109                            CCassSplitHistoryFetch *  fetch_details);
110 
111 private:
112     void x_Peek(bool  need_wait);
113     bool x_Peek(unique_ptr<CCassFetch> &  fetch_details,
114                 bool  need_wait);
115 
116 private:
117     SPSGS_TSEChunkRequest *                             m_TSEChunkRequest;
118 
119     // NB: Only one will be populated
120     shared_ptr<CPSGS_SatInfoChunksVerFlavorId2Info>     m_SatInfoChunkVerId2Info;
121     shared_ptr<CPSGS_IdModifiedVerFlavorId2Info>        m_IdModVerId2Info;
122 };
123 
124 #endif  // PSGS_TSECHUNKPROCESSOR__HPP
125 
126