feisty meow concerns codebase  2.140
heavy_file_ops.h
Go to the documentation of this file.
1 #ifndef HEAVY_FILE_OPERATIONS_CLASS
2 #define HEAVY_FILE_OPERATIONS_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : heavy file operations *
7 * Author : Chris Koeritz *
8 * *
9 *******************************************************************************
10 * Copyright (c) 2005-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
17 
18 #include "filename_list.h"
19 
20 #include <basis/astring.h>
21 #include <basis/contracts.h>
22 
23 namespace filesystem {
24 
26 
30 {
31 public:
33 //hmmm: consider adding full length here so we know it.
34  double _byte_start;
35  int _length;
37 
38  DEFINE_CLASS_NAME("file_transfer_header");
39 
40  file_transfer_header(const file_time &time_stamp);
42 
43  virtual void pack(basis::byte_array &packed_form) const;
44  virtual bool unpack(basis::byte_array &packed_form);
45 
46  virtual int packed_size() const;
47 
48  basis::astring text_form() const;
49 
50 //hmmm: this could live in lots of other places. file_info for one.
53 };
54 
56 
58 
59 class heavy_file_operations : public virtual basis::root_object
60 {
61 public:
62  virtual ~heavy_file_operations();
63 
64  enum outcomes {
65  OKAY = basis::common::OKAY,
66  BAD_INPUT = basis::common::BAD_INPUT,
67  FINISHED = basis::common::IS_EMPTY, // nothing left to pack.
68  DEFINE_OUTCOME(SOURCE_MISSING, -43, "The source file is not accessible"),
69  DEFINE_OUTCOME(TARGET_DIR_ERROR, -44, "The target's directory could not "
70  "be created"),
71  DEFINE_OUTCOME(TARGET_ACCESS_ERROR, -45, "The target file could not be "
72  "created")
73  };
74  static const char *outcome_name(const basis::outcome &to_name);
75 
76  DEFINE_CLASS_NAME("heavy_file_operations");
77 
78  static const size_t COPY_CHUNK_FACTOR;
80  static size_t copy_chunk_factor();
82 
83  static basis::outcome copy_file(const basis::astring &source, const basis::astring &destination,
86 
89  static basis::outcome write_file_chunk(const basis::astring &target, double byte_start,
90  const basis::byte_array &chunk, bool truncate = true,
93 
101  static basis::outcome buffer_files(const basis::astring &source_root,
102  const filename_list &to_transfer, file_transfer_header &last_action,
103  basis::byte_array &storage, int maximum_bytes);
105 
110 private:
111  static basis::outcome advance(const filename_list &to_transfer,
112  file_transfer_header &last_action);
114 };
115 
117 
118 } //namespace.
119 
120 #endif
121 
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
A very common template for a dynamic array of bytes.
Definition: byte_array.h:36
Outcomes describe the state of completion for an operation.
Definition: outcome.h:31
A base class for objects that can pack into an array of bytes.
Definition: byte_array.h:87
describes one portion of an ongoing file transfer.
double _byte_start
the starting location in the file being sent.
file_time _time
the timestamp on the file.
virtual int packed_size() const
Estimates the space needed for the packed structure.
int _length
the length of the transferred piece.
virtual bool unpack(basis::byte_array &packed_form)
Restores the packable from the "packed_form".
file_transfer_header(const file_time &time_stamp)
refactored to force addition of the time_stamp.
basis::astring text_form() const
basis::astring _filename
the name of the file being transferred.
DEFINE_CLASS_NAME("file_transfer_header")
basis::astring readable_text_form() const
a nicer formatting of the information.
virtual void pack(basis::byte_array &packed_form) const
Creates a packed form of the packable object in "packed_form".
Provides serious file operations, such as copy and partial writing.
static size_t copy_chunk_factor()
method can be exported for use by shared libs.
static const size_t COPY_CHUNK_FACTOR
the default copy chunk size for the file copy method.
static basis::outcome copy_file(const basis::astring &source, const basis::astring &destination, int copy_chunk_factor=heavy_file_operations::copy_chunk_factor())
copies a file from the "source" location to the "destination".
DEFINE_CLASS_NAME("heavy_file_operations")
static basis::outcome write_file_chunk(const basis::astring &target, double byte_start, const basis::byte_array &chunk, bool truncate=true, int copy_chunk_factor=heavy_file_operations::copy_chunk_factor())
stores a chunk of bytes into the "target" file.
static const char * outcome_name(const basis::outcome &to_name)
static basis::outcome buffer_files(const basis::astring &source_root, const filename_list &to_transfer, file_transfer_header &last_action, basis::byte_array &storage, int maximum_bytes)
reads files in "to_transfer" and packs them into a "storage" buffer.
A platform independent way to obtain the timestamp of a file.
Definition: byte_filer.cpp:37