00001 /* 00002 * NullBlockManager.h : part of the Mace toolkit for building distributed systems 00003 * 00004 * Copyright (c) 2007, Charles Killian, Dejan Kostic, Ryan Braud, James W. Anderson, John Fisher-Ogden, Calvin Hubble, Duy Nguyen, Justin Burke, David Oppenheimer, Amin Vahdat, Adolfo Rodriguez, Sooraj Bhat 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions are met: 00009 * 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in 00014 * the documentation and/or other materials provided with the 00015 * distribution. 00016 * * Neither the names of Duke University nor The University of 00017 * California, San Diego, nor the names of the authors or contributors 00018 * may be used to endorse or promote products derived from 00019 * this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00022 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00023 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00024 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 00025 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00026 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00027 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00028 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00029 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00030 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 * 00032 * ----END-OF-LEGAL-STUFF---- */ 00033 #ifndef NULL_BLOCK_MANAGER_H 00034 #define NULL_BLOCK_MANAGER_H 00035 00036 #include "FileBlockManager.h" 00037 00048 00049 class NullBlockManager : public FileBlockManager { 00050 public: 00051 // NullBlockManager(size_t blockCount, size_t blockSize = DEFAULT_BLOCK_SIZE) : 00052 // blockSize(blockSize), blockCount(blockCount), size(blockSize * blockCount) { } 00053 NullBlockManager(uint64_t blockCount, size_t blockSize = DEFAULT_BLOCK_SIZE) { 00054 this->blockSize = blockSize; 00055 this->blockCount = blockCount; 00056 this->size = blockSize * blockCount; 00057 } 00058 virtual ~NullBlockManager() { } 00059 std::string getBlock(uint64_t index) { 00060 static std::string r(blockSize, 0); 00061 static bool init = false; 00062 if (!init) { 00063 init = true; 00064 for (size_t i = 0; i < blockSize; i++) { 00065 r[i] = (i&0x7F); 00066 } 00067 } 00068 00069 return r; 00070 } 00071 // const std::string& getBlockRef(uint index) { 00072 // static std::string r(blockSize, 0); 00073 // return r; 00074 // } 00075 size_t setBlock(uint64_t index, const std::string& buffer) { return buffer.size(); } 00076 int open(const std::string& path, const char* mode) { return 0; } 00077 bool isOpen() { return true; } 00078 int close() { return 0; } 00079 }; // NullBlockManager 00080 00083 #endif // NULL_BLOCK_MANAGER_H