1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
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  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef DISTRIBUTEDDATAMGR_HIVIEW_MGR_H
17 #define DISTRIBUTEDDATAMGR_HIVIEW_MGR_H
18 
19 #include <any>
20 #include <map>
21 #include <string>
22 #include <unistd.h>
23 
24 class FakeHivew {
25 public:
GetString(const std::string & key)26     static std::string GetString(const std::string &key)
27     {
28         usleep(INTERNAL);
29         if (fakeCache_.count(key)) {
30             return std::any_cast<std::string>(fakeCache_[key]);
31         }
32         return "";
33     }
34 
GetInt(const std::string & key)35     static int GetInt(const std::string &key)
36     {
37         usleep(INTERNAL);
38         if (fakeCache_.count(key)) {
39             return std::any_cast<int>(fakeCache_[key]);
40         }
41         return 0;
42     }
43 
Put(const std::string & key,const std::any & an)44     static void Put(const std::string &key, const std::any &an)
45     {
46         fakeCache_.insert({key, an});
47     }
48 
Clear()49     static void Clear()
50     {
51         fakeCache_.clear();
52     }
53 
54 private:
55     static std::map<std::string, std::any> fakeCache_;
56     static const inline int INTERNAL = 1000;
57 };
58 
59 #endif // DISTRIBUTEDDATAMGR_HIVIEW_MGR_H
60