NCCLOUD  0.1
coding.h
Go to the documentation of this file.
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_CODING_H
00043 #define NCCLOUD_CODING_H
00044 
00045 #include <string>
00046 #include <vector>
00047 
00048 
00050 class Coding
00051 {
00052 protected:
00056   virtual void read_metadata(std::string &path, size_t &chunksize);
00057 
00058 
00062   virtual void write_metadata(std::string &path, size_t chunksize);
00063 
00064 
00071   virtual void read_chunks(std::string &path, size_t chunksize,
00072                            std::vector<int> &chunk_indices, char *chunks);
00073 
00074 
00081   virtual void write_chunks(std::string &path, size_t chunksize,
00082                             std::vector<int> &chunk_indices, char *chunks);
00083 
00084 
00085 public:
00092   static Coding *use_coding(int type, int k, int n, int w);
00093 
00094 
00100   virtual int encode_file(std::string &dstdir, std::string &srcdir, std::string &filename) = 0;
00101 
00102 
00109   virtual int decode_file(std::string &dst, std::string &srcdir, std::string &filename,
00110                           std::vector<int> &chunk_indices) = 0;
00111 
00112 
00119   virtual int repair_file_preprocess(std::string &srcdir, std::string &filename,
00120                                      std::vector<int> &erasures,
00121                                      std::vector<int> &chunks_to_retrieve) = 0;
00122 
00123 
00129   virtual int repair_file(std::string &dstdir, std::string &srcdir, std::string &filename) = 0;
00130 
00131 
00134   virtual int getn(void) = 0;
00135 
00136 
00139   virtual int getk(void) = 0;
00140 
00141 
00145   virtual int nodeid(int index) = 0;
00146 
00147 
00150   virtual int chunks_per_node(void) = 0;
00151 
00152 
00157   virtual int chunks_on_node(int node, std::vector<int> &chunk_indices) = 0;
00158 
00159 
00161   virtual void reset(void) = 0;
00162 };
00163 
00164 #endif  /* NCCLOUD_CODING_H */
00165 
 All Data Structures Files Functions Variables Enumerations Enumerator Defines