libflute
File.h
Go to the documentation of this file.
1 // libflute - FLUTE/ALC library
2 //
3 // Copyright (C) 2021 Klaus Kühnhammer (Österreichische Rundfunksender GmbH & Co KG)
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Affero General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Affero General Public License for more details.
14 //
15 // You should have received a copy of the GNU Affero General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18 #pragma once
19 #include <stddef.h>
20 #include <stdint.h>
21 #include <map>
22 #include <memory>
23 #include "AlcPacket.h"
24 #include "FileDeliveryTable.h"
25 #include "EncodingSymbol.h"
26 
27 namespace LibFlute {
31  class File {
32  public:
39 
52  File(uint32_t toi,
54  std::string content_location,
55  std::string content_type,
56  uint64_t expires,
57  char* data,
58  size_t length,
59  bool copy_data = false);
60 
64  virtual ~File();
65 
69  void put_symbol(const EncodingSymbol& symbol);
70 
74  bool complete() const { return _complete; };
75 
79  char* buffer() const { return _buffer; };
80 
84  size_t length() const { return _meta.fec_oti.transfer_length; };
85 
89  const FecOti& fec_oti() const { return _meta.fec_oti; };
90 
94  const LibFlute::FileDeliveryTable::FileEntry& meta() const { return _meta; };
95 
99  unsigned long received_at() const { return _received_at; };
100 
104  void log_access() { _access_count++; };
105 
109  unsigned access_count() const { return _access_count; };
110 
114  std::vector<EncodingSymbol> get_next_symbols(size_t max_size);
115 
119  void mark_completed(const std::vector<EncodingSymbol>& symbols, bool success);
120 
124  void set_fdt_instance_id( uint16_t id) { _fdt_instance_id = id; };
125 
129  uint16_t fdt_instance_id() { return _fdt_instance_id; };
130 
131  private:
132  void calculate_partitioning();
133  void create_blocks();
134 
135  struct SourceBlock {
136  bool complete = false;
137  struct Symbol {
138  char* data;
139  size_t length;
140  bool complete = false;
141  bool queued = false;
142  };
143  std::map<uint16_t, Symbol> symbols;
144  };
145 
146  void check_source_block_completion(SourceBlock& block);
147  void check_file_completion();
148 
149  std::map<uint16_t, SourceBlock> _source_blocks;
150 
151  bool _complete = false;;
152 
153  uint32_t _nof_source_symbols = 0;
154  uint32_t _nof_source_blocks = 0;
155  uint32_t _nof_large_source_blocks = 0;
156  uint32_t _large_source_block_length = 0;
157  uint32_t _small_source_block_length = 0;
158 
159  char* _buffer = nullptr;
160  bool _own_buffer = false;
161 
163  unsigned long _received_at;
164  unsigned _access_count = 0;
165 
166  uint16_t _fdt_instance_id = 0;
167  };
168 };
A class for handling FEC encoding symbols.
Represents a file being transmitted or received.
Definition: File.h:31
const FecOti & fec_oti() const
Get the FEC OTI values.
Definition: File.h:89
bool complete() const
Check if the file is complete.
Definition: File.h:74
void put_symbol(const EncodingSymbol &symbol)
Write the data from an encoding symbol into the appropriate place in the buffer.
Definition: File.cpp:98
unsigned access_count() const
Get the access counter value.
Definition: File.h:109
size_t length() const
Get the data buffer length.
Definition: File.h:84
virtual ~File()
Default destructor.
Definition: File.cpp:90
char * buffer() const
Get the data buffer.
Definition: File.h:79
uint16_t fdt_instance_id()
Get the FDT instance ID.
Definition: File.h:129
File(LibFlute::FileDeliveryTable::FileEntry entry)
Create a file from an FDT entry (used for reception)
Definition: File.cpp:31
void mark_completed(const std::vector< EncodingSymbol > &symbols, bool success)
Mark encoding symbols as completed.
Definition: File.cpp:215
void log_access()
Log access to the file by incrementing a counter.
Definition: File.h:104
void set_fdt_instance_id(uint16_t id)
Set the FDT instance ID.
Definition: File.h:124
std::vector< EncodingSymbol > get_next_symbols(size_t max_size)
Get the next encoding symbols that fit in max_size bytes.
Definition: File.cpp:189
unsigned long received_at() const
Timestamp of file reception.
Definition: File.h:99
const LibFlute::FileDeliveryTable::FileEntry & meta() const
Get the file metadata from its FDT entry.
Definition: File.h:94
OTI values struct.
Definition: flute_types.h:53
uint64_t transfer_length
Definition: flute_types.h:55
An entry for a file in the FDT.