Remove unused directories and files in video_in_hal
[staging/basesystem.git] / service / native / notification_persistent_service / server / src / ns_npp_registry_entry.cpp
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 ////////////////////////////////////////////////////////////////////////////////////////////////////
18 /// \ingroup  tag_NPPService
19 /// \brief    The file contains declaration of CRegistryEntry class.
20 ///
21 ///
22 ///
23 ////////////////////////////////////////////////////////////////////////////////////////////////////
24 #include <string>
25 #include "ns_npp_notificationpersistentservicelog.h"
26 #include "ns_npp_registry_entry.h"
27
28 ////////////////////////////////////////////////////////////////////////////////////////////
29 /// Constructor
30 ////////////////////////////////////////////////////////////////////////////////////////////
31 CRegistryEntry::CRegistryEntry(const std::string &f_ctag, const std::string &f_crequester,
32                                const std::string &f_cstoragepath,
33                                const BOOL f_bisuserpersistence):
34   m_eJobState(ENOTIFICATIONPERSISTENTSERVICEPERSISTJObSTATEIDLE),
35   m_cTag(f_ctag),
36   m_cRequestor(f_crequester),
37   m_bIsReleased(FALSE),
38   m_bIsPersisted(FALSE),
39   m_bIsUserPersistence(f_bisuserpersistence),
40   m_eCurrentAction(LOADTYPE_NONE),
41   m_ePersistType(ENOTIFICATIONPERSISTENTSERVICEPERSISTNONE),
42   m_ePersistCategory(eFrameworkunifiedUserData) {
43   m_cBasePath.clear();
44
45   // set base path.
46   m_cBasePath += f_cstoragepath;
47 }
48
49 ////////////////////////////////////////////////////////////////////////////////////////////
50 /// Copy Constructor
51 ////////////////////////////////////////////////////////////////////////////////////////////
52 CRegistryEntry::CRegistryEntry(const CRegistryEntry &in):
53   m_eJobState(ENOTIFICATIONPERSISTENTSERVICEPERSISTJObSTATEIDLE),
54   m_cTag(in.m_cTag),
55   m_cRequestor(in.m_cRequestor),
56   m_bIsReleased(in.m_bIsReleased),
57   m_bIsPersisted(in.m_bIsPersisted),
58   m_cPersistPath(in.m_cPersistPath),
59   m_cBasePath(in.m_cBasePath),
60   m_bIsUserPersistence(in.m_bIsUserPersistence),
61   m_eCurrentAction(in.m_eCurrentAction),
62   m_ePersistType(in.m_ePersistType),
63   m_ePersistCategory(in.m_ePersistCategory) {
64 }
65
66 ////////////////////////////////////////////////////////////////////////////////////////////
67 /// Operator overload
68 ///
69 ////////////////////////////////////////////////////////////////////////////////////////////
70 CRegistryEntry &CRegistryEntry::operator=(const CRegistryEntry &in) {   // LCOV_EXCL_START 8: never be used
71   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
72   if (this != &in) {
73     m_eJobState = in.m_eJobState;
74     m_cTag = in.m_cTag;
75     m_cRequestor = in.m_cRequestor;
76     m_bIsReleased = in.m_bIsReleased;
77     m_bIsPersisted = in.m_bIsPersisted;
78     m_cPersistPath = in.m_cPersistPath;
79     m_cBasePath = in.m_cBasePath;
80     m_bIsUserPersistence = in.m_bIsUserPersistence;
81     m_ePersistType = in.m_ePersistType;
82   }
83   return *this;
84 }
85 // LCOV_EXCL_STOP
86
87 ////////////////////////////////////////////////////////////////////////////////////////////
88 /// SetReleasePath
89 /// Set release path.
90 ////////////////////////////////////////////////////////////////////////////////////////////
91 VOID CRegistryEntry::SetReleasePath(const std::string &f_creleasepath) {
92   m_bIsReleased = TRUE;
93   m_cReleasePath = f_creleasepath;
94 }
95
96 ////////////////////////////////////////////////////////////////////////////////////////////
97 /// SetBeingPersisted
98 /// Set the file/folder is being persisted.
99 ////////////////////////////////////////////////////////////////////////////////////////////
100 VOID CRegistryEntry::SetBeingPersisted() {
101   if (LOADTYPE_RELEASE == m_eCurrentAction) {
102     m_bIsPersisted = TRUE;
103   }
104 }
105
106 ////////////////////////////////////////////////////////////////////////////////////////////
107 /// IsReleased
108 /// File/folder released or not.
109 ////////////////////////////////////////////////////////////////////////////////////////////
110 BOOL CRegistryEntry::IsReleased() const {
111   return m_bIsReleased;
112 }
113
114 ////////////////////////////////////////////////////////////////////////////////////////////
115 /// HasntBeenPersisted
116 /// File/Folder persisted or not
117 ////////////////////////////////////////////////////////////////////////////////////////////
118 BOOL CRegistryEntry::HasntBeenPersisted() const {
119   return !m_bIsPersisted;
120 }
121
122 ////////////////////////////////////////////////////////////////////////////////////////////
123 /// IsPersisted
124 /// File persisted or not
125 ////////////////////////////////////////////////////////////////////////////////////////////
126 BOOL CRegistryEntry::IsPersisted() const {
127   return m_bIsPersisted;
128 }
129
130 ////////////////////////////////////////////////////////////////////////////////////////////
131 /// GetPersistPath
132 /// Get the persist path.
133 ////////////////////////////////////////////////////////////////////////////////////////////
134 std::string CRegistryEntry::GetPersistPath() const {
135   return m_cPersistPath;
136 }
137
138 ////////////////////////////////////////////////////////////////////////////////////////////
139 /// GetReleasePath
140 /// Get the release path.
141 ////////////////////////////////////////////////////////////////////////////////////////////
142 std::string CRegistryEntry::GetReleasePath() const {
143   return m_cReleasePath;
144 }
145
146 ////////////////////////////////////////////////////////////////////////////////////////////
147 /// GetLoadPath
148 /// Get the load path.
149 ////////////////////////////////////////////////////////////////////////////////////////////
150 std::string CRegistryEntry::GetLoadPath(ENotificationpersistentservicePersistType f_epersisttype, std::string f_cusername) const {
151   std::string l_cLoadPath = "";
152
153   if (f_epersisttype > ENOTIFICATIONPERSISTENTSERVICEPERSISTFIRST && f_epersisttype < ENOTIFICATIONPERSISTENTSERVICEPERSISTLAST) {  // LCOV_EXCL_BR_LINE 6: f_epersisttype must be in range.  // NOLINT[whitespace/line_length]
154     l_cLoadPath = m_cBasePath;
155
156     switch (m_ePersistCategory) {
157       case eFrameworkunifiedUserData: {
158           l_cLoadPath += USERDATADIR;
159
160           // Check if to persist for user
161           if (m_bIsUserPersistence) {
162             //  if its a user file, user name can't be empty
163             if (!f_cusername.empty()) {   // LCOV_EXCL_BR_LINE 6: f_cusername can't be empty
164               FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Tag %s is registered for user %s", m_cTag.c_str(), f_cusername.c_str());
165               l_cLoadPath += f_cusername;
166               l_cLoadPath += "/";
167             }
168           } else {
169             l_cLoadPath += ALLUSERAPPDATADIR;
170           }
171
172           break;
173         }
174       case eFrameworkunifiedFactoryData: {
175           l_cLoadPath += FACTORYDATADIR;
176           break;
177         }
178       case eFrameworkunifiedFactoryCustomerData: {
179           l_cLoadPath += FACTORYCUSTOMERDATADIR;
180           break;
181         }
182       case eFrameworkunifiedDealerData: {
183           l_cLoadPath += DEALERDATADIR;
184           break;
185         }
186     }
187
188     l_cLoadPath += m_cRequestor;
189     l_cLoadPath += "/";
190
191     // file and folder persistency has different storage paths mapped
192     if (ENOTIFICATIONPERSISTENTSERVICEPERSISTFILE == f_epersisttype) {
193       l_cLoadPath += "NSFile/";
194     } else if (ENOTIFICATIONPERSISTENTSERVICEPERSISTFOLDER == f_epersisttype) {  // LCOV_EXCL_BR_LINE 6: f_epersisttype must be ENOTIFICATIONPERSISTENTSERVICEPERSISTFILE or ENOTIFICATIONPERSISTENTSERVICEPERSISTFOLDER.  // NOLINT[whitespace/line_length]
195       l_cLoadPath += "NSFolder/";
196     }
197
198     l_cLoadPath += m_cTag;
199   }
200
201   return l_cLoadPath;
202 }
203
204 ////////////////////////////////////////////////////////////////////////////////////////////
205 /// GetRequester
206 /// Get the name of requester.
207 ////////////////////////////////////////////////////////////////////////////////////////////
208 std::string CRegistryEntry::GetRequester() const {
209   return m_cRequestor;
210 }
211
212 ////////////////////////////////////////////////////////////////////////////////////////////
213 /// GetTag
214 /// Get the tag.
215 ////////////////////////////////////////////////////////////////////////////////////////////
216 std::string CRegistryEntry::GetTag() const {
217   return m_cTag;
218 }
219
220 ////////////////////////////////////////////////////////////////////////////////////////////
221 /// IsUserPersistence
222 ///
223 ////////////////////////////////////////////////////////////////////////////////////////////
224 BOOL CRegistryEntry::IsUserPersistence() {
225   return m_bIsUserPersistence;
226 }
227
228 ////////////////////////////////////////////////////////////////////////////////////////////
229 /// SetCurrentAction
230 ///
231 ////////////////////////////////////////////////////////////////////////////////////////////
232 VOID CRegistryEntry::SetCurrentAction(ENPS_Loadtype f_ecurrentaction) {
233   m_eCurrentAction = f_ecurrentaction;
234 }
235
236 ////////////////////////////////////////////////////////////////////////////////////////////
237 /// ResetPersistedFlag
238 ///
239 ////////////////////////////////////////////////////////////////////////////////////////////
240 VOID CRegistryEntry::ResetPersistedFlag() {
241   m_bIsPersisted = FALSE;
242 }
243
244 ////////////////////////////////////////////////////////////////////////////////////////////
245 /// SetPersistProperties
246 ///
247 ////////////////////////////////////////////////////////////////////////////////////////////
248 VOID CRegistryEntry::SetPersistProperties(ENotificationpersistentservicePersistType f_epersisttype, std::string f_cusername) {
249   if (f_epersisttype > ENOTIFICATIONPERSISTENTSERVICEPERSISTFIRST && f_epersisttype < ENOTIFICATIONPERSISTENTSERVICEPERSISTLAST) {  // LCOV_EXCL_BR_LINE 6: f_epersisttype must be in range.  // NOLINT[whitespace/line_length]
250     // set the persist type
251     m_ePersistType = f_epersisttype;
252
253     // set the persist file based on the persist type and username (if a user file)
254     m_cPersistPath = m_cBasePath;
255
256     switch (m_ePersistCategory) {
257       case eFrameworkunifiedUserData: {
258           m_cPersistPath += USERDATADIR;
259
260           // Check if to persist for user
261           if (m_bIsUserPersistence) {
262             //  if its a user file, user name can't be empty
263             if (!f_cusername.empty()) {  // LCOV_EXCL_BR_LINE 6: f_cusername can't be empty
264               FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Tag %s is registered for user %s", m_cTag.c_str(), f_cusername.c_str());
265               m_cPersistPath += f_cusername;
266               m_cPersistPath += "/";
267             }
268           } else {
269             m_cPersistPath += ALLUSERAPPDATADIR;
270           }
271
272           break;
273         }
274       case eFrameworkunifiedFactoryData: {
275           m_cPersistPath += FACTORYDATADIR;
276           break;
277         }
278       case eFrameworkunifiedFactoryCustomerData: {
279           m_cPersistPath += FACTORYCUSTOMERDATADIR;
280           break;
281         }
282       case eFrameworkunifiedDealerData: {
283           m_cPersistPath += DEALERDATADIR;
284           break;
285         }
286     }
287
288     m_cPersistPath += m_cRequestor;
289     m_cPersistPath += "/";
290
291     // file and folder persistency has different storage paths mapped
292     if (ENOTIFICATIONPERSISTENTSERVICEPERSISTFILE == f_epersisttype) {
293       m_cPersistPath += "NSFile/";
294     } else if (ENOTIFICATIONPERSISTENTSERVICEPERSISTFOLDER == f_epersisttype) {  // LCOV_EXCL_BR_LINE 6: f_epersisttype must be ENOTIFICATIONPERSISTENTSERVICEPERSISTFILE or ENOTIFICATIONPERSISTENTSERVICEPERSISTFOLDER.  // NOLINT[whitespace/line_length]
295       m_cPersistPath += "NSFolder/";
296     }
297
298     m_cPersistPath += m_cTag;
299   }
300 }
301
302 ////////////////////////////////////////////////////////////////////////////////////////////
303 /// GetPersistType
304 ///
305 ////////////////////////////////////////////////////////////////////////////////////////////
306 ENotificationpersistentservicePersistType CRegistryEntry::GetPersistType() const {
307   return m_ePersistType;
308 }
309
310 ////////////////////////////////////////////////////////////////////////////////////////////
311 /// SetPersistentCategory
312 /// Sets the persistent type related to tag
313 ////////////////////////////////////////////////////////////////////////////////////////////
314 EFrameworkunifiedStatus CRegistryEntry::SetPersistentCategory(EFrameworkunifiedPersistCategory f_epersistcategory) {
315   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
316   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
317
318   m_ePersistCategory = f_epersistcategory;
319
320   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
321   return l_estatus;
322 }
323
324 ////////////////////////////////////////////////////////////////////////////////////////////
325 /// GetPersistentCategory
326 /// Gets the persistent type of a tag
327 ////////////////////////////////////////////////////////////////////////////////////////////
328 EFrameworkunifiedPersistCategory CRegistryEntry::GetPersistentCategory() {
329   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
330
331   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
332   return m_ePersistCategory;
333 }