123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- /*##############################################################################
- HPCC SYSTEMS software Copyright (C) 2017 HPCC Systems®.
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- ############################################################################## */
- #ifndef _CONFIG2_ENVIRONMENTMGR_HPP_
- #define _CONFIG2_ENVIRONMENTMGR_HPP_
- #include <string>
- #include <fstream>
- #include <vector>
- #include <atomic>
- #include "SchemaItem.hpp"
- #include "SchemaParser.hpp"
- #include "EnvironmentNode.hpp"
- #include "Status.hpp"
- #include "NameValue.hpp"
- #include "platform.h"
- #include "EnvSupportLib.hpp"
- #include "Cfgmgrlib.hpp"
- class EnvironmentMgr;
- enum EnvironmentType
- {
- UNDEFINED,
- XML
- };
- CFGMGRLIB_API EnvironmentMgr *getEnvironmentMgrInstance(const EnvironmentType envType);
- class CFGMGRLIB_API EnvironmentMgr
- {
- public:
- EnvironmentMgr();
- virtual ~EnvironmentMgr() {}
- bool loadSchema(const std::string &configPath, const std::string &masterConfigFile, const std::map<std::string, std::string> &cfgParms = std::map<std::string, std::string>());
- std::string getLastSchemaMessage() const;
- std::string getLastEnvironmentMessage() const { return m_message; }
- bool loadEnvironment(const std::string &qualifiedFilename);
- std::shared_ptr<EnvironmentNode> findEnvironmentNodeById(const std::string &nodeId) const;
- std::shared_ptr<EnvironmentNode> getNewEnvironmentNode(const std::string &parentNodeId, const std::string &inputItem, Status &status) const;
- std::shared_ptr<EnvironmentNode> addNewEnvironmentNode(const std::string &parentNodeId, const std::string &configType,
- std::vector<NameValue> &initAttributes, Status &status, bool allowInvalid=false, bool forceCreate=false);
- std::shared_ptr<EnvironmentNode> addNewEnvironmentNode(const std::shared_ptr<EnvironmentNode> &pParentNode, const std::string &nodeData,
- Status &status, const std::string &itemType);
- std::shared_ptr<EnvironmentNode> addNewEnvironmentNode(const std::shared_ptr<EnvironmentNode> &pParentNode, const std::shared_ptr<SchemaItem> &pNewCfgItem,
- std::vector<NameValue> &initAttributes, Status &status, bool allowInvalid=false, bool forceCreate=false);
- bool removeEnvironmentNode(const std::string &nodeId);
- virtual bool serialize(std::ostream &out, const std::shared_ptr<EnvironmentNode> &pStartNode);
- bool saveEnvironment(const std::string &qualifiedFilename);
- void discardEnvironment() { m_pRootNode = nullptr; m_nodeIds.clear();}
- void validate(Status &status, bool includeHiddenNodes=false) const;
- std::string getRootNodeId() const;
- static std::string getUniqueKey();
- void fetchNodes(const std::string path, std::vector<std::shared_ptr<EnvironmentNode>> &nodes, const std::shared_ptr<EnvironmentNode> &pStartNode = nullptr) const;
- bool isSchemaLoaded() const { return static_cast<bool>(m_pSchema); }
- bool isEnvironmentLoaded() const { return static_cast<bool>(m_pRootNode); }
- protected:
- void addPath(const std::shared_ptr<EnvironmentNode> pNode);
- virtual bool createParser() = 0;
- virtual std::vector<std::shared_ptr<EnvironmentNode>> doLoadEnvironment(std::istream &in, const std::shared_ptr<SchemaItem> &pSchemaItem, const std::string itemType = std::string("")) = 0;
- virtual bool save(std::ostream &out) = 0;
- void assignNodeIds(const std::shared_ptr<EnvironmentNode> &pNode);
- void insertExtraEnvironmentData(std::shared_ptr<EnvironmentNode> pNode);
- std::shared_ptr<SchemaItem> findInsertableItem(const std::shared_ptr<EnvironmentNode> &pNode, const std::string &itemType) const;
- void getPredefinedAttributeValues(const std::string &inputItemType, std::string &itemType,
- std::vector<NameValue> &initAttributes) const;
- protected:
- std::shared_ptr<SchemaItem> m_pSchema;
- std::shared_ptr<SchemaParser> m_pSchemaParser;
- std::shared_ptr<EnvironmentNode> m_pRootNode;
- std::map<std::string, std::shared_ptr<EnvironmentNode>> m_nodeIds;
- std::string m_message;
- std::vector<std::shared_ptr<EnvSupportLib>> m_supportLibs;
- private:
- static std::atomic_int m_key;
- };
- #endif
|