ConfigFileUtils.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2015 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef _CONFIG_FILE_HPP_
  14. #define _CONFIG_FILE_HPP_
  15. #include "jiface.hpp"
  16. #include "jmutex.hpp"
  17. #include "jutil.hpp"
  18. #include "ConfigFileUtilsObservable.hpp"
  19. namespace CONFIGURATOR
  20. {
  21. static const char* DEFAULT_CONFIGURATION_PATH("/etc/HPCCSystems/source/");
  22. static const char* DEFAULT_CONFIGURATION_MASK("*.xml");
  23. class CConfigFileUtils : public CConfigFileUtilsObservable
  24. {
  25. public:
  26. enum CF_ERROR_CODES { CF_NO_ERROR = 0,
  27. CF_FILE_EXISTS,
  28. CF_FILE_PERMISSIONS,
  29. CF_FILE_NOT_OPEN,
  30. CF_FILE_ALREADY_OPEN,
  31. CF_FILE_DOES_NOT_EXIST,
  32. CF_WRITE_BUFFER_EMPTY,
  33. CF_DIRECTORY_ACCESS_ERROR,
  34. CF_OTHER = 99 };
  35. static CConfigFileUtils* getInstance();
  36. virtual ~CConfigFileUtils();
  37. const StringArray& getAvailableConfigurationFiles() const;
  38. enum CF_ERROR_CODES writeConfigurationToFile(const char *pFilePath, const char* pBuffer, unsigned int length);
  39. enum CF_ERROR_CODES createNewConfigurationFile(const char* pConfigFileName);
  40. enum CF_ERROR_CODES openConfigurationFile(const char* pConfigFileName);
  41. enum CF_ERROR_CODES closeConfigurationFile();
  42. enum CF_ERROR_CODES writeToOpenConfigurationFile(const char* pBuffer, unsigned int length);
  43. protected:
  44. enum CF_ERROR_CODES populateConfigFileArray();
  45. private:
  46. CConfigFileUtils(const char* pDir = DEFAULT_CONFIGURATION_PATH, const char* pMask = DEFAULT_CONFIGURATION_MASK);
  47. StringArray m_configFileArray;
  48. const char* m_pDirPath;
  49. const char* m_pMask;
  50. Owned<IFile> m_pDir;
  51. Owned<IFile> m_pFile;
  52. Owned<IFileIO> m_pFileIO;
  53. };
  54. }
  55. #endif // _CONFIG_FILE_HPP_