NCCLOUD
0.1
|
00001 00007 /* =================================================================== 00008 Copyright (c) 2013, Henry C. H. Chen 00009 All rights reserved. 00010 00011 Redistribution and use in source and binary forms, with or without 00012 modification, are permitted provided that the following conditions are 00013 met: 00014 00015 - Redistributions of source code must retain the above copyright 00016 notice, this list of conditions and the following disclaimer. 00017 00018 - Redistributions in binary form must reproduce the above copyright 00019 notice, this list of conditions and the following disclaimer in 00020 the documentation and/or other materials provided with the 00021 distribution. 00022 00023 - Neither the name of the Chinese University of Hong Kong nor the 00024 names of its contributors may be used to endorse or promote 00025 products derived from this software without specific prior written 00026 permission. 00027 00028 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00029 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00030 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00031 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00032 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00033 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00034 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00035 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00036 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00037 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00038 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00039 =================================================================== */ 00040 00041 00042 #ifndef NCCLOUD_FILEOP_H 00043 #define NCCLOUD_FILEOP_H 00044 00045 #include <string> 00046 #include <thread> 00047 #include <vector> 00048 00049 #include "coding.h" 00050 #include "common.h" 00051 #include "storage.h" 00052 00053 00056 class Job 00057 { 00058 /* Storage job routines. */ 00059 void upload_metadata_and_chunks(void); 00060 void upload_metadata(void); 00061 void download_chunks(void); 00062 void download_metadata(void); 00063 00064 /* Coding job routines. */ 00065 void decode_file(void); 00066 void repair_file(void); 00067 00068 public: 00070 enum ACTIONS { ULMETACHUNKS, ULMETA, DLCHUNKS, DLMETA, 00071 DIVIDER, DECODE, REPAIR }; 00072 00073 int action; 00074 Coding *coding; 00075 std::vector<Storage *> *storages; 00076 std::string tmpdir; 00077 std::string filename; 00078 std::vector<int> chunk_indices; 00079 std::vector<int> node_indices; 00080 Job *next_job; 00083 Job(int action, Coding *coding, std::vector<Storage *> *storages, 00084 std::string &tmpdir, std::string &filename); 00085 00086 00088 void follow_job(void); 00089 00090 00092 void run_job(void); 00093 }; 00094 00095 00097 class FileOp 00098 { 00100 std::vector<std::thread> workers; 00101 00102 FileOp(); 00103 00104 public: 00106 static FileOp *instance(void); 00107 00108 00110 void wait(void); 00111 00112 00118 void encode_file(std::string &path, Coding *coding, 00119 std::vector<Storage *> &storages, std::string &tmpdir); 00120 00121 00127 void decode_file(std::string &filename, Coding *coding, 00128 std::vector<Storage *> &storages, std::string &tmpdir); 00129 00130 00138 void repair_file(std::string &filename, Coding *coding, 00139 std::vector<Storage *> &storages, 00140 std::vector<int> &chunks_to_retrieve, 00141 int faulty_node, std::string &tmpdir); 00142 00143 00148 void delete_file(std::string &filename, Coding *coding, 00149 std::vector<Storage *> &storages); 00150 }; 00151 00152 #endif /* NCCLOUD_FILEOP_H */ 00153