NCBI C++ ToolKit
state.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef MISC_NETSTORAGE___NETSTORAGEIMPL__HPP
2 #define MISC_NETSTORAGE___NETSTORAGEIMPL__HPP
3 
4 /* $Id: state.hpp 100704 2023-08-31 20:09:55Z lavr $
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  * Author: Rafael Sadyrov
30  *
31  */
32 
36 #include "filetrack.hpp"
37 
38 
40 
41 
43 {
44  enum EMode {
47  };
48 
51 
53  void ParseArg(const string&, const string&);
54 
55  static SCombinedNetStorageConfig Build(const string& init_string)
56  {
57  return BuildImpl<SCombinedNetStorageConfig>(init_string);
58  }
59 
60 private:
61  static EMode GetMode(const string&);
62 };
63 
64 template <class TBase>
66 {
67  template <class... TArgs>
69  TBase(std::forward<TArgs>(args)...),
70  m_Locator(locator)
71  {
72  }
73 
74  string GetLoc() const override { return m_Locator.GetLocator(); }
75  CNetStorageObjectLoc& Locator() override { return m_Locator; }
76 
77 private:
79 };
80 
81 
82 namespace NDirectNetStorageImpl
83 {
84 
85 class ILocation
86 {
87 public:
88  virtual ~ILocation() {}
89 
90  virtual INetStorageObjectState* StartRead(void*, size_t, size_t*, ERW_Result*) = 0;
91  virtual INetStorageObjectState* StartWrite(const void*, size_t, size_t*, ERW_Result*) = 0;
92  virtual Uint8 GetSize() = 0;
94  virtual bool Exists() = 0;
96  virtual void SetExpiration(const CTimeout&) = 0;
97  virtual string FileTrack_Path() = 0;
98  virtual pair<string, string> GetUserInfo() = 0;
99  virtual string GetLoc() const = 0;
101  virtual void SetLocator() = 0;
102 };
103 
105 
106 template <class TBase>
108 
110 {
115  string app_domain;
118 
120  SContext(const string&, const string&,
122 
124  {
126  }
127 
129  {
131  }
132 
133 private:
134  void Init();
135 };
136 
138 {
139 public:
140  CROState(bool* cancel_relocate) : m_CancelRelocate(cancel_relocate) {}
142 
143 private:
145 };
146 
148 {
149 public:
150  ERW_Result Read(void* buf, size_t count, size_t* read) override;
151  ERW_Result PendingCount(size_t* count) override;
152  bool Eof() override;
153  ERW_Result Write(const void* buf, size_t count, size_t* written) override;
154  ERW_Result Flush() override { return eRW_Success; }
155 
156  void Close() override { ExitState(); }
157  void Abort() override { ExitState(); }
158 };
159 
160 class CRONetCache : public CROState
161 {
162 public:
163  typedef unique_ptr<IReader> TReaderPtr;
164 
165  CRONetCache(bool* cancel_relocate) : CROState(cancel_relocate) {}
166 
167  void Set(TReaderPtr reader, size_t blob_size)
168  {
169  m_Reader = std::move(reader);
170  m_BlobSize = blob_size;
171  m_BytesRead = 0;
172  }
173 
174  ERW_Result Read(void* buf, size_t count, size_t* read) override;
175  ERW_Result PendingCount(size_t* count) override;
176  bool Eof() override;
177 
178  void Close() override;
179  void Abort() override;
180 
181 private:
183  size_t m_BlobSize;
184  size_t m_BytesRead;
185 };
186 
188 {
189 public:
190  typedef unique_ptr<IEmbeddedStreamWriter> TWriterPtr;
191 
192  void Set(TWriterPtr writer)
193  {
194  m_Writer = std::move(writer);
195  }
196 
197  ERW_Result Write(const void* buf, size_t count, size_t* written) override;
198  ERW_Result Flush() override;
199 
200  void Close() override;
201  void Abort() override;
202 
203 private:
205 };
206 
207 class CROFileTrack : public CROState
208 {
209 public:
211 
212  CROFileTrack(bool* cancel_relocate) : CROState(cancel_relocate) {}
213 
214  void Set(TRequest request)
215  {
216  m_Request = request;
217  }
218 
219  ERW_Result Read(void* buf, size_t count, size_t* read) override;
220  ERW_Result PendingCount(size_t* count) override;
221  bool Eof() override;
222 
223  void Close() override;
224  void Abort() override;
225 
226 private:
228 };
229 
231 {
232 public:
234 
235  void Set(TRequest request)
236  {
237  m_Request = request;
238  }
239 
240  ERW_Result Write(const void* buf, size_t count, size_t* written) override;
241  ERW_Result Flush() override;
242 
243  void Close() override;
244  void Abort() override;
245 
246 private:
248 };
249 
250 class CNotFound : public CLocation
251 {
252 public:
254  : CLocation(object_loc),
255  m_RW(fsm, object_loc)
256  {}
257 
258  void SetLocator() override;
259 
260  INetStorageObjectState* StartRead(void*, size_t, size_t*, ERW_Result*) override;
261  INetStorageObjectState* StartWrite(const void*, size_t, size_t*, ERW_Result*) override;
262  Uint8 GetSize() override;
263  CNetStorageObjectInfo GetInfo() override;
264  bool Exists() override;
265  ENetStorageRemoveResult Remove() override;
266  void SetExpiration(const CTimeout&) override;
267  string FileTrack_Path() override;
268  pair<string, string> GetUserInfo() override;
269 
270 private:
272 };
273 
274 class CNetCache : public CLocation
275 {
276 public:
277  CNetCache(CNetStorageObjectLoc& object_loc, SNetStorageObjectImpl& fsm, SContext* context, bool* cancel_relocate)
278  : CLocation(object_loc),
279  m_Context(context),
280  m_Read(fsm, object_loc, cancel_relocate),
281  m_Write(fsm, object_loc)
282  {}
283 
284  bool Init();
285  void SetLocator() override;
286 
287  INetStorageObjectState* StartRead(void*, size_t, size_t*, ERW_Result*) override;
288  INetStorageObjectState* StartWrite(const void*, size_t, size_t*, ERW_Result*) override;
289  Uint8 GetSize() override;
290  CNetStorageObjectInfo GetInfo() override;
291  bool Exists() override;
292  ENetStorageRemoveResult Remove() override;
293  void SetExpiration(const CTimeout&) override;
294  string FileTrack_Path() override;
295  pair<string, string> GetUserInfo() override;
296 
297 private:
302 };
303 
304 class CFileTrack : public CLocation
305 {
306 public:
307  CFileTrack(CNetStorageObjectLoc& object_loc, SNetStorageObjectImpl& fsm, SContext* context, bool* cancel_relocate)
308  : CLocation(object_loc),
309  m_Context(context),
310  m_Read(fsm, object_loc, cancel_relocate),
311  m_Write(fsm, object_loc)
312  {}
313 
314  bool Init() { return m_Context->filetrack_api; }
315  void SetLocator() override;
316 
317  INetStorageObjectState* StartRead(void*, size_t, size_t*, ERW_Result*) override;
318  INetStorageObjectState* StartWrite(const void*, size_t, size_t*, ERW_Result*) override;
319  Uint8 GetSize() override;
320  CNetStorageObjectInfo GetInfo() override;
321  bool Exists() override;
322  ENetStorageRemoveResult Remove() override;
323  void SetExpiration(const CTimeout&) override;
324  string FileTrack_Path() override;
325  pair<string, string> GetUserInfo() override;
326 
327 private:
331 };
332 
333 }
334 
336 
337 #endif
Pool of recycled CCompoundID objects.
Detailed information about a CNetStorage object.
Definition: netstorage.hpp:96
string GetLocator() const
CObject –.
Definition: ncbiobj.hpp:180
CRandom::
Definition: random_gen.hpp:66
CTimeout – Timeout interval.
Definition: ncbitime.hpp:1693
IRegistry –.
Definition: ncbireg.hpp:73
CFileTrack(CNetStorageObjectLoc &object_loc, SNetStorageObjectImpl &fsm, SContext *context, bool *cancel_relocate)
Definition: state.hpp:307
CRef< SContext > m_Context
Definition: state.hpp:328
TState< CROFileTrack > m_Read
Definition: state.hpp:329
ENetStorageRemoveResult Remove() override
Definition: state.cpp:614
INetStorageObjectState * StartWrite(const void *, size_t, size_t *, ERW_Result *) override
Definition: state.cpp:557
CNetStorageObjectInfo GetInfo() override
Definition: state.cpp:577
TState< CWOFileTrack > m_Write
Definition: state.hpp:330
void SetExpiration(const CTimeout &) override
Definition: state.cpp:622
string FileTrack_Path() override
Definition: state.cpp:633
pair< string, string > GetUserInfo() override
Definition: state.cpp:639
INetStorageObjectState * StartRead(void *, size_t, size_t *, ERW_Result *) override
Definition: state.cpp:533
TState< CRONetCache > m_Read
Definition: state.hpp:300
pair< string, string > GetUserInfo() override
Definition: state.cpp:513
void SetLocator() override
Definition: state.cpp:318
void SetExpiration(const CTimeout &) override
Definition: state.cpp:483
ENetStorageRemoveResult Remove() override
Definition: state.cpp:466
CNetICacheClientExt m_Client
Definition: state.hpp:299
TState< CWONetCache > m_Write
Definition: state.hpp:301
string FileTrack_Path() override
Definition: state.cpp:504
CNetCache(CNetStorageObjectLoc &object_loc, SNetStorageObjectImpl &fsm, SContext *context, bool *cancel_relocate)
Definition: state.hpp:277
INetStorageObjectState * StartWrite(const void *, size_t, size_t *, ERW_Result *) override
Definition: state.cpp:378
Uint8 GetSize() override
Definition: state.cpp:401
CRef< SContext > m_Context
Definition: state.hpp:298
CNetStorageObjectInfo GetInfo() override
Definition: state.cpp:414
INetStorageObjectState * StartRead(void *, size_t, size_t *, ERW_Result *) override
Definition: state.cpp:327
Uint8 GetSize() override
Definition: state.cpp:247
void SetExpiration(const CTimeout &) override
Definition: state.cpp:276
TState< CRWNotFound > m_RW
Definition: state.hpp:271
string FileTrack_Path() override
Definition: state.cpp:284
CNotFound(CNetStorageObjectLoc &object_loc, SNetStorageObjectImpl &fsm)
Definition: state.hpp:253
void SetLocator() override
Definition: state.cpp:223
pair< string, string > GetUserInfo() override
Definition: state.cpp:293
CNetStorageObjectInfo GetInfo() override
Definition: state.cpp:256
ENetStorageRemoveResult Remove() override
Definition: state.cpp:270
INetStorageObjectState * StartRead(void *, size_t, size_t *, ERW_Result *) override
Definition: state.cpp:230
INetStorageObjectState * StartWrite(const void *, size_t, size_t *, ERW_Result *) override
Definition: state.cpp:239
CROFileTrack(bool *cancel_relocate)
Definition: state.hpp:212
CRef< SFileTrackDownload > TRequest
Definition: state.hpp:210
void Set(TRequest request)
Definition: state.hpp:214
ERW_Result PendingCount(size_t *count) override
Via parameter "count" (which is guaranteed to be supplied non-NULL) return the number of bytes that a...
Definition: state.cpp:167
ERW_Result Read(void *buf, size_t count, size_t *read) override
Read as many as "count" bytes into a buffer pointed to by the "buf" argument.
Definition: state.cpp:161
ERW_Result Read(void *buf, size_t count, size_t *read) override
Read as many as "count" bytes into a buffer pointed to by the "buf" argument.
Definition: state.cpp:75
void Set(TReaderPtr reader, size_t blob_size)
Definition: state.hpp:167
unique_ptr< IReader > TReaderPtr
Definition: state.hpp:163
CRONetCache(bool *cancel_relocate)
Definition: state.hpp:165
ERW_Result PendingCount(size_t *count) override
Via parameter "count" (which is guaranteed to be supplied non-NULL) return the number of bytes that a...
Definition: state.cpp:90
void CancelRelocate() override
Definition: state.hpp:141
CROState(bool *cancel_relocate)
Definition: state.hpp:140
ERW_Result Read(void *buf, size_t count, size_t *read) override
Read as many as "count" bytes into a buffer pointed to by the "buf" argument.
Definition: state.cpp:47
ERW_Result Flush() override
Flush pending data (if any) down to the output device.
Definition: state.hpp:154
ERW_Result Write(const void *buf, size_t count, size_t *written) override
Write up to "count" bytes from the buffer pointed to by the "buf" argument onto the output device.
Definition: state.cpp:68
ERW_Result PendingCount(size_t *count) override
Via parameter "count" (which is guaranteed to be supplied non-NULL) return the number of bytes that a...
Definition: state.cpp:54
void Set(TRequest request)
Definition: state.hpp:235
ERW_Result Flush() override
Flush pending data (if any) down to the output device.
Definition: state.cpp:202
CRef< SFileTrackUpload > TRequest
Definition: state.hpp:233
ERW_Result Write(const void *buf, size_t count, size_t *written) override
Write up to "count" bytes from the buffer pointed to by the "buf" argument onto the output device.
Definition: state.cpp:195
unique_ptr< IEmbeddedStreamWriter > TWriterPtr
Definition: state.hpp:190
void Set(TWriterPtr writer)
Definition: state.hpp:192
ERW_Result Write(const void *buf, size_t count, size_t *written) override
Write up to "count" bytes from the buffer pointed to by the "buf" argument onto the output device.
Definition: state.cpp:122
ERW_Result Flush() override
Flush pending data (if any) down to the output device.
Definition: state.cpp:132
virtual void SetExpiration(const CTimeout &)=0
virtual pair< string, string > GetUserInfo()=0
virtual string GetLoc() const =0
virtual CNetStorageObjectInfo GetInfo()=0
virtual INetStorageObjectState * StartRead(void *, size_t, size_t *, ERW_Result *)=0
virtual string FileTrack_Path()=0
virtual ENetStorageRemoveResult Remove()=0
virtual INetStorageObjectState * StartWrite(const void *, size_t, size_t *, ERW_Result *)=0
virtual CNetStorageObjectLoc & Locator()=0
Declarations of CCompoundIDPool, CCompoundID, and CCompoundIDField.
static uch flags
unsigned TNetStorageFlags
Bitwise OR of ENetStorageFlags.
Definition: netstorage.hpp:147
ENetStorageRemoveResult
Result returned by Remove() methods.
Definition: netstorage.hpp:356
uint64_t Uint8
8-byte (64-bit) unsigned integer
Definition: ncbitype.h:105
Uint8 GetRandUint8(void)
Get random Uint8 number.
Definition: random_gen.hpp:244
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
ERW_Result
Result codes for I/O operations.
@ eRW_Success
Everything is okay, I/O completed.
char * buf
const struct ncbi::grid::netcache::search::fields::KEY key
NetCache ICache client specs.
SContext(const SCombinedNetStorageConfig &, TNetStorageFlags)
Definition: state.cpp:724
TNetStorageFlags default_flags
Definition: state.hpp:114
CNetICacheClientExt icache_client
Definition: state.hpp:111
CNetStorageObjectLoc Create(const string &key, TNetStorageFlags flags)
Definition: state.hpp:128
CNetStorageObjectLoc Create(TNetStorageFlags flags)
Definition: state.hpp:123
CCompoundIDPool compound_id_pool
Definition: state.hpp:113
void ParseArg(const string &, const string &)
Definition: state.cpp:786
static SCombinedNetStorageConfig Build(const string &init_string)
Definition: state.hpp:55
SFileTrackConfig ft
Definition: state.hpp:50
static EMode GetMode(const string &)
Definition: state.cpp:777
const SFileTrackConfig config
Definition: filetrack.hpp:136
static SSite site
Definition: filetrack.hpp:75
SNetStorageObjectDirectState(CNetStorageObjectLoc &locator, TArgs &&... args)
Definition: state.hpp:68
CNetStorageObjectLoc & Locator() override
Definition: state.hpp:75
CNetStorageObjectLoc & m_Locator
Definition: state.hpp:78
string GetLoc() const override
Definition: state.hpp:74
#define _ASSERT
Modified on Sat Dec 02 09:19:21 2023 by modify_doxy.py rev. 669887