Merge "Fix memory leaks in Locales" into tizen_2.1
[platform/framework/native/appfw.git] / src / io / inc / FIo_RegistryImpl.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        FIo_RegistryImpl.h
20  * @brief       This is the header file for the %_RegistryImpl class.
21  *
22  * This header file contains the declarations of the %_RegistryImpl class.
23  */
24
25 #ifndef _FIO_INTERNAL_REGISTRY_IMPL_H_
26 #define _FIO_INTERNAL_REGISTRY_IMPL_H_
27
28 #include <FOspConfig.h>
29 #include <FBaseObject.h>
30 #include <FIoFileLock.h>
31 #include <locale.h>
32
33 namespace Tizen {namespace Base
34 {
35 class String;
36 class ByteBuffer;
37 namespace Collection
38 {
39 class HashMap;
40 class IList;
41 class IMap;
42 }
43 }}
44
45 namespace Tizen { namespace Io
46 {
47
48 class Registry;
49 class _RegistryCore;
50
51 // @enum %Registry value Type
52 enum _RegValueType
53 {
54         REG_VALUE_TYPE_INT = 1,     // Integer type
55         REG_VALUE_TYPE_REAL,        // Real type
56         REG_VALUE_TYPE_STRING,      // String type
57         REG_VALUE_TYPE_BINARY,      // Binary type
58         REG_VALUE_TYPE_UUID,        // UUID type
59         REG_VALUE_TYPE_UUIDSET,     // UUIDSET type
60         REG_VALUE_TYPE_MAX
61 };
62
63 class _OSP_EXPORT_ _RegistryImpl
64         : public Tizen::Base::Object
65 {
66
67 public:
68         _RegistryImpl(void);
69
70         virtual ~_RegistryImpl(void);
71
72         result Construct(const Tizen::Base::String& regPath, long openMode, const Tizen::Base::ByteBuffer* pKey = null);
73
74         result Construct(const Tizen::Base::String& regPath, const char* pOpenMode, const Tizen::Base::ByteBuffer* pSecretKey);
75
76         static result Remove(const Tizen::Base::String& regPath);
77
78         result AddSection(const Tizen::Base::String& SectionName);
79
80         result RemoveSection(const Tizen::Base::String& SectionName);
81
82         result GetSectionListN(Tizen::Base::Collection::IList** pRetList);
83
84         result GetEntryListN(const Tizen::Base::String& sectionName, Tizen::Base::Collection::HashMap** pRetList);
85
86         /**
87         * Gets all entries in the specified section of the registry.
88         *
89         * @since 2.1
90         * @return               A map of entries @n
91         *                               If this method fails, @c null value is returned. @n
92         *                               When there are no entries at all, the method returns an empty map instance.
93         *                               Use the GetCount() method to check the number of element in the map.
94         * @param                sectionName                             The section name
95         * @exception    E_SUCCESS                               The method was successful.
96         * @exception    E_INVALID_STATE                 This instance has not been constructed yet.
97         * @exception    E_SECTION_NOT_FOUND             The specified @c sectionName was not found within the registry.
98         * @exception    E_OUT_OF_MEMORY                 The memory was insufficient.
99         * @exception    E_IO                                    The system error has occurred.
100         * @remarks              Do not forget to delete not only the returned IMap instance, but also its
101         *                               contents by invoking IMap::RemoveAll(). @n
102         *                               The specific error code can be accessed using the GetLastResult() method.
103         */
104         Tizen::Base::Collection::IMap* GetAllEntriesN(const Tizen::Base::String& sectionName) const;
105
106         Tizen::Base::Collection::IList* GetAllEntryNamesN(const Tizen::Base::String& sectionName) const;
107
108         result GetEntryList(const Tizen::Base::String& sectionName, Tizen::Base::Collection::HashMap& retMap);
109
110         result GetValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, float& entryValue);
111
112         result GetValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, double& entryValue);
113
114         result GetValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, Tizen::Base::String& entryValue);
115
116         result AddValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, float entryValue);
117
118         result AddValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, double entryValue);
119
120         result AddValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, const Tizen::Base::String& entryValue);
121
122         result SetValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, float entryValue);
123
124         result SetValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, double entryValue);
125
126         result SetValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, const Tizen::Base::String& entryValue);
127
128         result RemoveValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName);
129
130         result Flush(void);
131
132         int GetSectionIndex(const Tizen::Base::String& sectionName);
133
134         Tizen::Base::String GetSectionName(int sectionIndex);
135
136         int GetEntryIndex(int sectionIndex, const Tizen::Base::String& entryName);
137
138         Tizen::Base::String GetEntryName(int sectionIndex, int entryIndex);
139
140         void Removekey(const Tizen::Base::String& sectionName, const Tizen::Base::String& keyName);
141
142         int GetAllSectionCount(void);
143
144         int GetAllEntryCount(int sectionIndex);
145
146         void RemoveEntry(int sectionIndex, int entryIndex);
147
148         void GetEntryValue(int sectionIndex, int entryIndex, _RegValueType type, void* pValue, int* pSize);
149
150         void ModifyEntryValue(int sectionIndex, int entryIndex, _RegValueType type, const void* pValue, int size);
151
152         FileLock* LockN(FileLockType lockType);
153
154         FileLock* TryToLockN(FileLockType lockType);
155
156         static result ConvertToSecureRegistry(const Tizen::Base::String& plainRegPath, const Tizen::Base::String& secureRegPath, const Tizen::Base::ByteBuffer* key = null);
157
158         static _RegistryImpl* GetInstance(Registry& registry);
159
160         static const _RegistryImpl* GetInstance(const Registry& registry);
161
162 private:
163         _RegistryImpl(const _RegistryImpl& source);
164
165         _RegistryImpl& operator =(const _RegistryImpl& source);
166
167         void* GetSectionByIndex(int sectionIndex);
168
169         static bool ConvertRegistryOpenMode(long legacyMode, char* pOpenMode);
170
171         static result CheckOpenMode(const Tizen::Base::String& openMode);
172
173         _RegistryCore* __pRegistryCore;
174
175         locale_t __loc;
176
177 }; // _RegistryImpl
178
179 }} // Tizen::Io
180
181 #endif // _FIO_INTERNAL_REGISTRY_IMPL_H_
182