2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #ifndef _CONFIGURATIONMANAGER_H_
17 #define _CONFIGURATIONMANAGER_H_
22 #include <libxml/xmlreader.h>
23 #include "Constants.h"
26 #include <dpl/log/log.h>
28 #define ATTR_ACTIVE_POLICY BAD_CAST("active")
30 #define PARSER_ERROR 1
31 #define PARSER_SUCCESS 0
33 class ConfigurationManager
36 enum ConfigurationManagerResult
38 CM_OPERATION_SUCCESS = 0,
39 CM_GENERAL_ERROR = -1,
42 CM_REMOVE_CURRENT = -4,
43 CM_REMOVE_NOT_EXISTING = -5
47 * Current policy file getter
48 * @return Name of the current ACE policy file
50 std::string getCurrentPolicyFile(void) const;
53 * ACE policy file path getter
54 * @return Full path to ACE current policy file
56 std::string getFullPathToCurrentPolicyFile(void) const;
59 * ACE policy dtd file path getter
60 * @return Full path to ACE current policy file
62 std::string getFullPathToCurrentPolicyXMLSchema(void) const;
65 * ACE policy storage path getter
66 * @return Full path to ACE policy file storage
68 std::string getStoragePath(void) const;
71 * Adds file to ACE policy storage
72 * @param filePath full path to policy to be added
73 * @return CM_OPERATION_SUCCESS on success,
74 * CM_FILE_EXISTS if file with the same name already exists in the storage (the new file is not added),
75 * other error code on other error
78 int addPolicyFile(const std::string & filePath);
81 * Removes file with a given filename from ACE policy storage
82 * @param fileName name of the policy to be removed
83 * @return CM_OPERATION_SUCCESS on success,
84 * CM_REMOVE_CURRENT if file to be removed is a current file (it cannot be removed)
85 * CM_REMOVE_NOT_EXISTING if file already doesn't exists
86 * other error code on other error
89 int removePolicyFile(const std::string& fileName);
91 //change current PolicyFile
93 * @param filePath Name of the policy file in the policy storage that should be made
94 * a current policy file
95 * @param CM_OPERATION_SUCCESS on success or error code on error
97 int changeCurrentPolicyFile(const std::string& filePath);
99 //TODO this getInstance() method is a little bit to complicated
101 * Method to obtain instance of configuration manager
102 * @return retuns pointer to configuration manager or NULL in case of error
104 static ConfigurationManager * getInstance()
107 instance = new ConfigurationManager();
108 if (instance->parse(std::string(ACE_CONFIGURATION_PATH)) !=
112 "Couldn't parse configuration file " ACE_CONFIGURATION_PATH);
120 * Extracts filename from full path
121 * @param path Full path from which filename should be extracted
122 * @return returns extracted filename
124 std::string extractFilename(const std::string& path) const;
129 * Parse given ACE configuration file
130 * @param configFileName full path to configuration file to be parsed
131 * @return PARSER_SUCCESS on succes, PARSER_ERROR on error
133 int parse(const std::string &configFileName);
135 * @param path full path to the file which size should be obtained
136 * @return size of a given file in bytes
138 int getFileSize(const std::string & path) const;
139 bool copyFile(FILE * source,
141 int lenght = 1024) const;
142 bool checkIfFileExistst(const std::string & newFilePath) const;
144 const std::list<std::string> & getPolicyFiles() const
149 const std::string & getConfigFile() const
154 ConfigurationManager() : xmlActive(false)
157 virtual ~ConfigurationManager()
164 * Internal parser methods
166 void extractFileAttributes(void);
167 void startNodeHandler(void);
168 void endNodeHandler(void);
169 void textNodeHandler(void);
170 void processNode(void);
171 //Save configuration file
174 //Private fields for parser state representation
175 xmlTextReaderPtr reader;
176 std::string currentText;
179 static ConfigurationManager * instance;
182 * Full path to ACE configuration file
184 std::string configFile;
186 * ACE policy file storage path
188 std::string storagePath;
190 * Name of the current ACE policy
192 std::string currentPolicyFile;
194 * List of available ACE policy files
196 std::list<std::string> policyFiles;