softwarecontainer  0.18.0-739e8d7 2017-05-04
fileconfigloader.cpp
1 
2 /*
3  * Copyright (C) 2016-2017 Pelagicore AB
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
12  * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
13  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
14  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
15  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
16  * SOFTWARE.
17  *
18  * For further information see LICENSE
19  */
20 
21 
22 #include "fileconfigloader.h"
23 
24 
25 namespace softwarecontainer {
26 
27 std::unique_ptr<Glib::KeyFile> FileConfigLoader::loadConfig()
28 {
29  std::unique_ptr<Glib::KeyFile> configData = std::unique_ptr<Glib::KeyFile>(new Glib::KeyFile);
30  try {
31  configData->load_from_file(Glib::ustring(this->m_source), Glib::KEY_FILE_NONE);
32  log_debug() << "Loaded config file: \"" << this->m_source << "\"";
33  } catch (Glib::FileError &error) {
34  log_error() << "Could not load SoftwareContainer config: \"" << error.what() << "\"";
35  log_debug() << "Config file that failed to load: \"" << this->m_source << "\"";
36  throw;
37  } catch (Glib::KeyFileError &error) {
38  log_error() << "Could not load SoftwareContainer config: \"" << error.what() << "\"";
39  log_debug() << "Config file that failed to load: \"" << this->m_source << "\"";
40  throw;
41  }
42 
43  return configData;
44 }
45 
46 } // namespace softwarecontainer
Developers guide to adding a config item: