heavy_file_ops.h

Go to the documentation of this file.
00001 #ifndef HEAVY_FILE_OPERATIONS_CLASS
00002 #define HEAVY_FILE_OPERATIONS_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : heavy file operations                                             *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 2005-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include "filename_list.h"
00019 
00020 #include <basis/astring.h>
00021 #include <basis/contracts.h>
00022 
00023 namespace filesystem {
00024 
00026 
00029 class file_transfer_header : public basis::packable
00030 {
00031 public:
00032   basis::astring _filename;  
00033   double _byte_start;  
00034   int _length;  
00035   file_time _time;  
00036 
00037   DEFINE_CLASS_NAME("file_transfer_header");
00038 
00039   file_transfer_header(const file_time &time_stamp);
00041 
00042   virtual void pack(basis::byte_array &packed_form) const;
00043   virtual bool unpack(basis::byte_array &packed_form);
00044 
00045   virtual int packed_size() const;
00046 
00047   basis::astring text_form() const;
00048 
00049 //hmmm: this could live in lots of other places.  file_info for one.
00050   basis::astring readable_text_form() const;
00052 };
00053 
00055 
00057 
00058 class heavy_file_operations : public virtual basis::root_object
00059 {
00060 public:
00061   virtual ~heavy_file_operations();
00062 
00063   enum outcomes {
00064     OKAY = basis::common::OKAY,
00065     BAD_INPUT = basis::common::BAD_INPUT,
00066 //    GARBAGE = basis::common::GARBAGE,
00067 //    NOT_FOUND = basis::common::NOT_FOUND,
00068 //    NONE_READY = basis::common::NONE_READY,
00069 //    FAILURE = basis::common::FAILURE,
00070     DEFINE_OUTCOME(SOURCE_MISSING, -43, "The source file is not accessible"),
00071     DEFINE_OUTCOME(TARGET_DIR_ERROR, -44, "The target's directory could not "
00072         "be created"),
00073     DEFINE_OUTCOME(TARGET_ACCESS_ERROR, -45, "The target file could not be "
00074         "created")
00075   };
00076   static const char *outcome_name(const basis::outcome &to_name);
00077 
00078   DEFINE_CLASS_NAME("heavy_file_operations");
00079 
00080   static const size_t COPY_CHUNK_FACTOR;
00082   static size_t copy_chunk_factor();
00084 
00085   static basis::outcome copy_file(const basis::astring &source, const basis::astring &destination,
00086           int copy_chunk_factor = copy_chunk_factor());
00088 
00091   static basis::outcome write_file_chunk(const basis::astring &target, double byte_start,
00092           const basis::byte_array &chunk, bool truncate = true,
00093           int copy_chunk_factor = copy_chunk_factor());
00095 
00103   static basis::outcome buffer_files(const basis::astring &source_root,
00104           const filename_list &to_transfer, file_transfer_header &last_action,
00105           basis::byte_array &storage, int maximum_bytes);
00107 
00112 private:
00113   static bool advance(const filename_list &to_transfer, file_transfer_header &last_action);
00115 };
00116 
00118 
00119 } //namespace.
00120 
00121 #endif
00122 
Generated on Sat Jan 28 04:22:22 2012 for hoople2 project by  doxygen 1.6.3