1 #ifndef PSGS_OSGGETBLOBBASE__HPP
2 #define PSGS_OSGGETBLOBBASE__HPP
3 
4 /*  $Id: osg_getblob_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: processor to get blob/chunk from OSG
32  *
33  */
34 
35 #include "osg_processor_base.hpp"
36 
37 
38 BEGIN_NCBI_NAMESPACE;
39 
40 BEGIN_NAMESPACE(objects);
41 
42 class CID2_Blob_Id;
43 class CID2_Reply_Data;
44 class CID2_Reply_Get_Blob;
45 class CID2S_Reply_Get_Split_Info;
46 class CID2S_Reply_Get_Chunk;
47 
48 END_NAMESPACE(objects);
49 
50 BEGIN_NAMESPACE(psg);
51 BEGIN_NAMESPACE(osg);
52 
53 
54 class CPSGS_OSGGetBlobBase : virtual public CPSGS_OSGProcessorBase
55 {
56 public:
57     typedef int TID2BlobState;
58     typedef int TID2BlobVersion;
59     typedef int TID2SplitVersion;
60     typedef int TID2ChunkId;
61 
62     CPSGS_OSGGetBlobBase();
63     virtual ~CPSGS_OSGGetBlobBase();
64 
65     static CRef<CID2_Blob_Id> ParsePSGBlobId(const SPSGS_BlobId& blob_id);
66     static string GetPSGBlobId(const CID2_Blob_Id& blob_id);
67 
68     struct SParsedId2Info
69     {
70         DECLARE_OPERATOR_BOOL_REF(tse_id);
71 
72         CRef<CID2_Blob_Id> tse_id;
73         TID2SplitVersion split_version;
74     };
75 
76     static bool IsOSGBlob(const CID2_Blob_Id& blob_id);
77     static bool IsCDDBlob(const CID2_Blob_Id& blob_id);
78     static SParsedId2Info ParsePSGId2Info(const string& idsss2_info);
79     static string GetPSGId2Info(const CID2_Blob_Id& tse_id,
80                                 TID2SplitVersion split_version);
81 protected:
82     void ProcessBlobReply(const CID2_Reply& reply);
83     bool HasBlob() const;
84     void SendExcludedBlob(const string& psg_blob_id);
85     void SendBlob();
86 
87     static string x_GetSplitInfoPSGBlobId(const string& main_blob_id);
88     static string x_GetChunkPSGBlobId(const string& main_blob_id,
89                                       TID2ChunkId chunk_id);
90 
91     template<class C>
x_GetBlobState(const C & obj)92     static TID2BlobState x_GetBlobState(const C& obj)
93         {
94             return obj.IsSetBlob_state()? obj.GetBlob_state(): 0;
95         }
96     string x_GetPSGDataBlobId(const CID2_Blob_Id& blob_id,
97                               const CID2_Reply_Data& data);
98     void x_SetBlobState(CBlobRecord& blob_props,
99                         TID2BlobState blob_state);
100     void x_SetBlobVersion(CBlobRecord& blob_props,
101                           const CID2_Blob_Id& blob_id);
102 
103     void x_SetBlobDataProps(CBlobRecord& blob_props,
104                             const CID2_Reply_Data& data);
105 
106     void x_SendBlobProps(const string& psg_blob_id,
107                          CBlobRecord& blob_props);
108     void x_SendBlobData(const string& psg_blob_id,
109                         const CID2_Reply_Data& data);
110     void x_SendChunkBlobProps(const string& id2_info,
111                               TID2ChunkId chunk_id,
112                               CBlobRecord& blob_props);
113     void x_SendChunkBlobData(const string& id2_info,
114                              TID2ChunkId chunk_id,
115                              const CID2_Reply_Data& data);
116 
117     void x_SendMainEntry(const CID2_Blob_Id& osg_blob_id,
118                          TID2BlobState blob_state,
119                          const CID2_Reply_Data& data);
120     void x_SendSplitInfo(const CID2_Blob_Id& osg_blob_id,
121                          TID2BlobState blob_state,
122                          TID2SplitVersion split_version,
123                          const CID2_Reply_Data& data);
124     void x_SendChunk(const CID2_Blob_Id& osg_blob_id,
125                      TID2ChunkId chunk_id,
126                      const CID2_Reply_Data& data);
127 
128     void x_SetSplitVersion(const CID2_Blob_Id& osg_blob_id,
129                            TID2SplitVersion split_version);
130     TID2SplitVersion x_GetSplitVersion(const CID2_Blob_Id& osg_blob_id);
131 
132     map<string, TID2SplitVersion> m_PSGBlobId2SplitVersion;
133     CConstRef<CID2_Reply_Get_Blob> m_Blob;
134     CConstRef<CID2S_Reply_Get_Split_Info> m_SplitInfo;
135     CConstRef<CID2S_Reply_Get_Chunk> m_Chunk;
136 };
137 
138 
139 END_NAMESPACE(osg);
140 END_NAMESPACE(psg);
141 END_NCBI_NAMESPACE;
142 
143 #endif  // PSGS_OSGGETBLOBBASE__HPP
144