Merge "Fix Jira issue (db lock issue)" into tizen_2.1
[platform/framework/native/appfw.git] / src / io / inc / FIo_RegistryCore.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_RegistryCore.h
20  * @brief       This is the header file for the %_RegistryCore class.
21  */
22
23 #ifndef _FIO_INTERNAL_REGISTRYCORE_H_
24 #define _FIO_INTERNAL_REGISTRYCORE_H_
25
26 #include <FBaseUuId.h>
27 #include <FBaseString.h>
28 #include <FBaseByteBuffer.h>
29 #include <FBaseColArrayList.h>
30 #include <FBaseColLinkedList.h>
31 #include <FBaseColHashMap.h>
32 #include <FBaseColIMap.h>
33 #include <FBaseResult.h>
34 #include <FIoFileLock.h>
35
36
37 namespace Tizen { namespace Io
38 {
39
40 class _FileImpl;
41
42 class _RegistryCore
43         : public Tizen::Base::Object
44 {
45 public:
46         _RegistryCore(void);
47
48         virtual ~_RegistryCore(void);
49
50         virtual result Flush(void);
51
52         bool VerifyRegistryOpenMode(const char* pOpenMode);
53
54         result Parse(void);
55
56         result Load(const Tizen::Base::String& regPath, const char* pOpenMode);
57
58         result AddSection(const Tizen::Base::String& SectionName);
59
60         result RemoveSection(const Tizen::Base::String& SectionName);
61
62         result GetSectionListN(Tizen::Base::Collection::IList** pRetList);
63
64         result GetEntryListN(const Tizen::Base::String& sectionName, Tizen::Base::Collection::HashMap** pRetList);
65
66         Tizen::Base::Collection::IMap* GetAllEntriesN(const Tizen::Base::String& sectionName);
67
68         Tizen::Base::Collection::IList* GetAllEntryNamesN(const Tizen::Base::String& sectionName);
69
70         result GetEntryList(const Tizen::Base::String& sectionName, Tizen::Base::Collection::HashMap& retMap);
71
72         result GetValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, Tizen::Base::String& valStr);
73
74         result AddValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, const Tizen::Base::String& valStr);
75
76         result SetValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, const Tizen::Base::String& valStr);
77
78         result RemoveValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName);
79
80         result PrepareToWrite(void);
81
82         result Write(void);
83
84         int GetSectionIndex(const Tizen::Base::String& sectionName);
85
86         Tizen::Base::String GetSectionName(int sectionIndex);
87
88         int GetEntryIndex(int sectionIndex, const Tizen::Base::String& entryName);
89
90         Tizen::Base::String GetEntryName(int sectionIndex, int entryIndex);
91
92         void Removekey(const Tizen::Base::String& sectionName, const Tizen::Base::String& keyName);
93
94         int GetAllSectionCount(void);
95
96         int GetAllEntryCount(int sectionIndex);
97
98         void RemoveEntry(int sectionIndex, int entryIndex);
99
100         void GetEntryValue(int sectionIndex, int entryIndex, _RegValueType type, void* pValue, int* pSize);
101
102         void ModifyEntryValue(int sectionIndex, int entryIndex, _RegValueType type, const void* pValue, int size);
103
104         void* GetSectionByIndex(int sectionIndex);
105
106         static result ConvertToSecureRegistry(const Tizen::Base::String& plainRegPath, const Tizen::Base::String& secureRegPath, const Tizen::Base::ByteBuffer* key = null);
107
108         FileLock* LockN(FileLockType lockType);
109
110         FileLock* TryToLockN(FileLockType lockType);
111
112 protected:
113         static result AddSection(Tizen::Base::Collection::LinkedList& sectionList, const Tizen::Base::String& sectionName);
114
115         static result AddValue(Tizen::Base::Collection::LinkedList& sectionList, const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, const Tizen::Base::String& valStr);
116
117         static bool CheckSectionName(char* pSectionName);
118
119         static bool CheckEntryName(char* pEntryName);
120
121         static bool CheckEntryValue(char* pEntryVal);
122
123 private:
124         _RegistryCore(const _RegistryCore& rhs);
125
126         _RegistryCore& operator =(const _RegistryCore& rhs);
127
128         void DecodeData(const Tizen::Base::String& strValueEncoded, _RegValueType type, void* pValue, int* pSize);
129
130 protected:
131         bool _constructed;
132         Tizen::Base::String _regPath;
133     bool _read;
134     bool _write;
135     bool _truncate;
136     bool _append;
137     bool _update;
138         Tizen::Base::Collection::LinkedList _sectionList; // <section_name, list<section_val_name, val>>
139         byte* _pBuffer;
140         int _length;
141
142 private:
143         _FileImpl* __pFileImpl;
144
145 }; // _RegistryCore
146
147 }} // Tizen::Io
148
149 #endif //_FIO_INTERNAL_REGISTRYCORE_H_
150