LogCabin
Storage/LogFactory.cc
Go to the documentation of this file.
00001 /* Copyright (c) 2014 Stanford University
00002  * Copyright (c) 2015 Diego Ongaro
00003  *
00004  * Permission to use, copy, modify, and distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
00009  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00010  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
00011  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00012  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00013  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00014  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00015  */
00016 
00017 #include "Core/Config.h"
00018 #include "Core/Debug.h"
00019 #include "Storage/Layout.h"
00020 #include "Storage/LogFactory.h"
00021 #include "Storage/MemoryLog.h"
00022 #include "Storage/SegmentedLog.h"
00023 #include "Storage/SimpleFileLog.h"
00024 
00025 namespace LogCabin {
00026 namespace Storage {
00027 namespace LogFactory {
00028 
00029 std::unique_ptr<Log>
00030 makeLog(const Core::Config& config,
00031         const Storage::Layout& storageLayout)
00032 {
00033     const FilesystemUtil::File& parentDir = storageLayout.logDir;
00034     std::string module =
00035         config.read<std::string>("storageModule", "Segmented");
00036     std::unique_ptr<Log> log;
00037     if (module == "Memory") {
00038         log.reset(new MemoryLog());
00039     } else if (module == "SimpleFile") {
00040         log.reset(new SimpleFileLog(parentDir));
00041     } else if (module == "Segmented" ||
00042                module == "Segmented-Binary") {
00043         log.reset(new SegmentedLog(parentDir,
00044                                    SegmentedLog::Encoding::BINARY,
00045                                    config));
00046     } else if (module == "Segmented-Text") {
00047         log.reset(new SegmentedLog(parentDir,
00048                                    SegmentedLog::Encoding::TEXT,
00049                                    config));
00050     } else {
00051         EXIT("Unknown storage module from config file: %s", module.c_str());
00052     }
00053     return log;
00054 }
00055 
00056 } // namespace LogCabin::Storage::LogFactory
00057 } // namespace LogCabin::Storage
00058 } // namespace LogCabin
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines