IODA Bundle
ThreadSharedDataHandle.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 1996-2018 ECMWF.
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 /// @author Simon Smart
12 /// @date Dec 2018
13 
14 #ifndef odc_core_ThreadSharedDataHandle_H
15 #define odc_core_ThreadSharedDataHandle_H
16 
17 #include <mutex>
18 #include <memory>
19 
20 #include "eckit/io/DataHandle.h"
21 
22 namespace eckit { class DataHandle; }
23 
24 namespace odc {
25 namespace core {
26 
27 //----------------------------------------------------------------------------------------------------------------------
28 
29 class ThreadSharedDataHandle : public eckit::DataHandle {
30 
31 public: // methods
32 
33  ThreadSharedDataHandle (eckit::DataHandle& dh);
34  ThreadSharedDataHandle (eckit::DataHandle* dh);
35  ~ThreadSharedDataHandle() override;
36 
39 
42 
43  bool operator!=(const ThreadSharedDataHandle& other);
44  bool operator==(const ThreadSharedDataHandle& other);
45 
46  void print(std::ostream& s) const override;
47 
48  eckit::Length openForRead() override;
49  void openForWrite(const eckit::Length&) override;
50  void openForAppend(const eckit::Length&) override;
51 
52  long read(void*,long) override;
53  long write(const void*,long) override;
54  void close() override;
55 
56  eckit::Length estimate() override;
57  eckit::Offset position() override;
58  eckit::Offset seek(const eckit::Offset&) override;
59 
60  std::string title() const override;
61 
62 private: // members
63 
64  struct Internal {
65 
66  Internal(eckit::DataHandle* dh, bool owned);
67  ~Internal();
68 
69  std::mutex m_;
70  eckit::DataHandle* dh_;
71  bool owned_;
72  };
73 
74  std::shared_ptr<Internal> internal_;
75 
76  eckit::Offset position_;
77 };
78 
79 //----------------------------------------------------------------------------------------------------------------------
80 
81 } // namespace core
82 } // namespace odc
83 
84 #endif
std::string title() const override
ThreadSharedDataHandle & operator=(const ThreadSharedDataHandle &)
void openForAppend(const eckit::Length &) override
std::shared_ptr< Internal > internal_
eckit::Offset seek(const eckit::Offset &) override
bool operator==(const ThreadSharedDataHandle &other)
void openForWrite(const eckit::Length &) override
long write(const void *, long) override
void print(std::ostream &s) const override
ThreadSharedDataHandle(eckit::DataHandle &dh)
bool operator!=(const ThreadSharedDataHandle &other)
Definition: ColumnInfo.h:23
Internal(eckit::DataHandle *dh, bool owned)