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

Go to the SVN repository for this file.

1 #ifndef _GRID_RW_IMPL_HPP_
2 #define _GRID_RW_IMPL_HPP_
3 
4 
5 /* $Id: grid_rw_impl.hpp 84663 2018-11-27 18:22:00Z ucko $
6  * ===========================================================================
7  *
8  * PUBLIC DOMAIN NOTICE
9  * National Center for Biotechnology Information
10  *
11  * This software/database is a "United States Government Work" under the
12  * terms of the United States Copyright Act. It was written as part of
13  * the author's official duties as a United States Government employee and
14  * thus cannot be copyrighted. This software/database is freely available
15  * to the public for use. The National Library of Medicine and the U.S.
16  * Government have not placed any restriction on its use or reproduction.
17  *
18  * Although all reasonable efforts have been taken to ensure the accuracy
19  * and reliability of the software and data, the NLM and the U.S.
20  * Government do not and cannot warrant the performance or results that
21  * may be obtained by using this software or data. The NLM and the U.S.
22  * Government disclaim all warranties, express or implied, including
23  * warranties of performance, merchantability or fitness for any particular
24  * purpose.
25  *
26  * Please cite the author in any work or product based on this material.
27  *
28  * ===========================================================================
29  *
30  * Authors: Maxim Didenko, Dmitry Kazimirov
31  *
32  */
33 
35 
36 #include <connect/connect_export.h>
37 
39 
40 #include <functional>
41 #include <memory>
42 
44 
46 {
47 public:
48  using TWriterCreate = function<IEmbeddedStreamWriter*(string&)>;
49 
50  CStringOrWriter(size_t max_data_size, string& data_ref, TWriterCreate writer_create);
51 
52  ERW_Result Write(const void* buf, size_t count, size_t* bytes_written = 0) override;
53  ERW_Result Flush() override;
54 
55  void Close() override;
56  void Abort() override;
57 
58 private:
59  size_t m_MaxDataSize;
60  string& m_Data;
62  unique_ptr<IEmbeddedStreamWriter> m_Writer;
63 };
64 
65 /// String or Blob Storage Writer
66 ///
67 /// An implementation of the IWriter interface with a dual behavior.
68 /// It writes data into the "data_or_key" parameter until
69 /// the total number of written bytes reaches "max_string_size" parameter.
70 /// After that all data from "data_or_key" is stored into the Blob Storage
71 /// and all next calls to Write method will write data to the Blob Storage.
72 /// In this case "data_or_key" parameter holds a blob key for the written data.
73 ///
75  public CStringOrWriter
76 {
77 public:
78  CStringOrBlobStorageWriter(size_t max_string_size,
79  SNetCacheAPIImpl* storage,
80  string& job_output_ref);
81 };
82 
83 struct SGridWrite
84 {
85  unique_ptr<IEmbeddedStreamWriter> writer;
86  unique_ptr<CNcbiOstream> stream;
87 
88  CNcbiOstream& operator()(CNetCacheAPI nc_api, size_t embedded_max_size, string& data);
89  void Reset(bool flush = false);
90 };
91 
92 /// String or Blob Storage Reader
93 ///
94 /// An implementation of the IReader interface with a dual behavior.
95 /// If "data_or_key" parameter can be interpreted as Blob Storage key and
96 /// a blob with given key is found in the storage, then the storage is
97 /// used as data source. Otherwise "data_or_key" is a data source.
98 ///
100 {
101 public:
102  CStringOrBlobStorageReader(const string& data_or_key,
103  SNetCacheAPIImpl* storage,
104  size_t* data_size = NULL);
105 
106  virtual ERW_Result Read(void* buf,
107  size_t count,
108  size_t* bytes_read = 0);
109 
110  virtual ERW_Result PendingCount(size_t* count);
111 
112 protected:
113  enum EType { eNetCache, eEmbedded, eEmpty, eRaw };
114  static EType x_GetDataType(string& data);
115 
116 private:
118  unique_ptr<IReader> m_NetCacheReader;
119  string m_Data;
121 };
122 
123 struct SGridRead
124 {
125  unique_ptr<CNcbiIstream> stream;
126 
127  CNcbiIstream& operator()(CNetCacheAPI nc_api, const string& data, size_t* data_size);
128  void Reset();
129 };
130 
132 {
133 public:
134  enum EErrCode {
136  };
137 
138  virtual const char* GetErrCodeString(void) const override
139  {
140  switch (GetErrCode())
141  {
142  case eInvalidFlag: return "eInvalidFlag";
143  default: return CException::GetErrCodeString();
144  }
145  }
146 
148 };
149 
151 
152 #endif // __GRID_RW_IMPL_HPP_
@ eEmpty
no filtering at all.
Client API for NetCache server.
virtual const char * GetErrCodeString(void) const override
Get error code interpreted as text.
NCBI_EXCEPTION_DEFAULT(CStringOrBlobStorageRWException, CException)
String or Blob Storage Reader.
unique_ptr< IReader > m_NetCacheReader
String or Blob Storage Writer.
function< IEmbeddedStreamWriter *(string &)> TWriterCreate
TWriterCreate m_WriterCreate
unique_ptr< IEmbeddedStreamWriter > m_Writer
virtual void Close()=0
virtual void Abort()=0
A very basic data-read interface.
Abstract reader-writer interface classes.
char data[12]
Definition: iconv.c:80
@ eNetCache
Definition: grid_cli.hpp:171
#define NULL
Definition: ncbistd.hpp:225
TErrCode GetErrCode(void) const
Get error code.
Definition: ncbiexpt.cpp:453
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
Definition: ncbiexpt.cpp:444
void Read(CObjectIStream &in, TObjectPtr object, const CTypeRef &type)
Definition: serial.cpp:60
#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.
virtual ERW_Result Flush(void)=0
Flush pending data (if any) down to the output device.
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
virtual ERW_Result Write(const void *buf, size_t count, size_t *bytes_written=0)=0
Write up to "count" bytes from the buffer pointed to by the "buf" argument onto the output device.
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
Definition: ncbistre.hpp:146
#define NCBI_XCONNECT_EXPORT
@ eRaw
Definition: types.hpp:81
char * buf
NetCache client specs.
CNcbiIstream & operator()(CNetCacheAPI nc_api, const string &data, size_t *data_size)
void Reset()
unique_ptr< CNcbiIstream > stream
unique_ptr< IEmbeddedStreamWriter > writer
CNcbiOstream & operator()(CNetCacheAPI nc_api, size_t embedded_max_size, string &data)
unique_ptr< CNcbiOstream > stream
void Reset(bool flush=false)
Modified on Wed Jul 17 13:19:18 2024 by modify_doxy.py rev. 669887