fa54b1fba429546a411f5d049b9f940654ecf8a9
[platform/upstream/iotivity.git] / service / resource-manipulation / modules / 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 RESOURCECACHEMANAGER_H_
22 #define RESOURCECACHEMANAGER_H_
23
24 #include <list>
25 #include <string>
26 #include <mutex>
27
28 #include "OCPlatform.h"
29 #include "CacheTypes.h"
30 #include "DataCache.h"
31
32 #define CACHE_TAG PCF("CACHE")
33
34 class ResourceCacheManager
35 {
36 public:
37     static ResourceCacheManager * getInstance();
38
39     CacheID requestResourceCache(
40             PrimitiveResourcePtr pResource,
41                 CacheCB func = NULL, REPORT_FREQUENCY rf = REPORT_FREQUENCY::NONE, long time = 0l);
42     OCStackResult cancelResourceCache(PrimitiveResourcePtr pResource, CacheID id);
43     OCStackResult updateResourceCache(PrimitiveResourcePtr pResource);
44
45     const ResourceAttributes getCachedData(PrimitiveResourcePtr pResource) const;
46     const ResourceAttributes getCachedData(CacheID id) const;
47
48     CACHE_STATE getResourceCacheState(PrimitiveResourcePtr pResource) const;
49     CACHE_STATE getResourceCacheState(CacheID id) const;
50
51     ~ResourceCacheManager();
52 private:
53     ResourceCacheManager();
54
55     static ResourceCacheManager * s_instance;
56     static std::mutex s_mutexForCreation;
57     static std::unique_ptr<std::list<DataCachePtr>> s_cacheDataList;
58
59     DataCachePtr findDataCache(PrimitiveResourcePtr pResource) const;
60     DataCachePtr findDataCache(CacheID id) const;
61 };
62
63 #endif /* RESOURCECACHEMANAGER_H_ */