c1a14a7e47f5b28e2a0ce77e172b789282e445aa
[platform/upstream/iotivity.git] / service / resource-encapsulation / src / resourceCache / include / ResourceCacheManager.h
1 //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #ifndef RCM_RESOURCECACHEMANAGER_H_
22 #define RCM_RESOURCECACHEMANAGER_H_
23
24 #include <list>
25 #include <string>
26 #include <mutex>
27 #include <map>
28
29 #include "CacheTypes.h"
30 #include "DataCache.h"
31
32 namespace OIC
33 {
34     namespace Service
35     {
36         class ResourceCacheManager
37         {
38             public:
39                 class InvalidParameterException: public RCSException
40                 {
41                     public:
42                         InvalidParameterException(std::string &&what)
43                             : RCSException { std::move(what) } {}
44                 };
45
46                 static ResourceCacheManager *getInstance();
47
48                 CacheID requestResourceCache(
49                     PrimitiveResourcePtr pResource, CacheCB func = NULL,
50                     REPORT_FREQUENCY rf = REPORT_FREQUENCY::NONE, long time = 0l);
51                 void cancelResourceCache(CacheID id);
52
53                 void updateResourceCache(PrimitiveResourcePtr pResource) const;
54                 void updateResourceCache(CacheID id) const;
55
56                 const ResourceAttributes getCachedData(PrimitiveResourcePtr pResource) const;
57                 const ResourceAttributes getCachedData(CacheID id) const;
58
59                 CACHE_STATE getResourceCacheState(PrimitiveResourcePtr pResource) const;
60                 CACHE_STATE getResourceCacheState(CacheID id) const;
61
62             private:
63                 static ResourceCacheManager *s_instance;
64                 static std::mutex s_mutexForCreation;
65                 static std::unique_ptr<std::list<DataCachePtr>> s_cacheDataList;
66                 std::map<CacheID, DataCachePtr> cacheIDmap;
67
68                 ResourceCacheManager() = default;
69                 ~ResourceCacheManager();
70                 ResourceCacheManager(const ResourceCacheManager &) = delete;
71                 ResourceCacheManager(ResourceCacheManager &&) = delete;
72
73                 ResourceCacheManager &operator=(const ResourceCacheManager &) const = delete;
74                 ResourceCacheManager &operator=(ResourceCacheManager && ) const = delete;
75
76                 static void initializeResourceCacheManager();
77                 DataCachePtr findDataCache(PrimitiveResourcePtr pResource) const;
78                 DataCachePtr findDataCache(CacheID id) const;
79         };
80     } // namespace Service
81 } // namespace OIC
82
83 #endif /* RCM_RESOURCECACHEMANAGER_H_ */