00001 // 00002 // cfg_yaml.h 00003 // 00004 // Created by Chris Ross on 12/25/07. 00005 // Copyright 2007. All rights reserved. 00006 // 00007 // 00008 // ***** BEGIN LICENSE BLOCK ***** 00009 // Version: MPL 1.1/GPL 2.0/LGPL 2.1 00010 // 00011 // The contents of this file are subject to the Mozilla Public License 00012 // Version 1.1 (the "License"); you may not use this file except in 00013 // compliance with the License. You may obtain a copy of the License at 00014 // http://www.mozilla.org/MPL/ 00015 // 00016 // Software distributed under the License is distributed on an "AS IS" 00017 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00018 // the License for the specific language governing rights and limitations 00019 // under the License. 00020 // 00021 // The Original Code is the consmgr network/serial-line monitoring package. 00022 // 00023 // The Initial Developer of the Original Code is Chris P. Ross. 00024 // Portions created by the Initial Developer are Copyright (C) 2000-2008 00025 // the Initial Developer. All Rights Reserved. 00026 // 00027 // Contributor(s): 00028 // 00029 // Alternatively, the contents of this file may be used under the terms of 00030 // either the GNU General Public License Version 2 or later (the "GPL"), or 00031 // the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 00032 // in which case the provisions of the GPL or the LGPL are applicable instead 00033 // of those above. If you wish to allow use of your version of this file only 00034 // under the terms of either the GPL or the LGPL, and not to allow others to 00035 // use your version of this file under the terms of the MPL, indicate your 00036 // decision by deleting the provisions above and replace them with the notice 00037 // and other provisions required by the GPL or the LGPL. If you do not delete 00038 // the provisions above, a recipient may use your version of this file under 00039 // the terms of any one of the MPL, the GPL or the LGPL. 00040 // 00041 // ***** END LICENSE BLOCK ***** 00042 00043 #include <string> 00044 00045 #include "cmconfig.h" 00046 #if YAML_USING_SYCK 00047 #include <syck.h> 00048 #else 00049 #error "No available implementation for reading YAML config files." 00050 #endif 00051 00052 extern "C" { 00053 #include <pthread.h> 00054 }; 00055 00065 class YAML : public Config { 00066 public: 00067 YAML(const string&); 00068 ~YAML(void); 00069 00071 void load_entry(const string&); 00072 00073 private: 00074 pthread_mutex_t mutex; 00075 #if YAML_USING_SYCK 00078 static YAML *instance; 00079 00082 std::string intended; 00083 00084 SyckParser *parser; 00085 FILE *filep; 00086 std::map<SYMID,string> scalars; 00087 std::map<SYMID,SyckNode*> maps; 00088 SYMID index; 00089 00092 static SYMID node_handler(SyckParser*, SyckNode*); 00093 static void error_handler(SyckParser*, char*); 00094 static SyckNode *bad_anchor_handler(SyckParser*, char*); 00095 00098 SYMID import_node(SyckNode*); 00099 void load_from_map(SYMID); 00100 #endif 00101 };