Add ResourceCache Sconscript
[platform/upstream/iotivity.git] / service / basis / resourceCache / include / DataCache.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 DATACACHE_H_
22 #define DATACACHE_H_
23
24 #include <list>
25 #include <string>
26 #include <boost/progress.hpp>
27
28 #include "OCResource.h"
29 #include "logger.h"
30
31 #include "CacheTypes.h"
32
33 class DataCache
34 {
35 public:
36     DataCache(
37             PrimitiveResourcePtr pResource,
38             CacheCB func,
39             REPORT_FREQUENCY rf,
40             long repeatTime);
41     ~DataCache();
42
43     CacheID addSubscriber(CacheCB func, REPORT_FREQUENCY rf, long repeatTime);
44     CacheID deleteSubscriber(CacheID id);
45
46     CachedDataPtr getCachedData();
47     CACHE_STATE getCacheState();
48     PrimitiveResourcePtr getPrimitiveResource();
49
50     SubscriberInfoPair findSubscriber(CacheID id);
51
52 private:
53     // origin resource info
54     std::string uri;
55     std::string address;
56
57     // resource instance
58     PrimitiveResourcePtr sResource;
59     std::shared_ptr<BaseResource> baseHandler;
60
61     // cached data info
62     CachedDataPtr data;
63     std::shared_ptr<ResourceAttributes> attributes;
64     long updateTime;
65     CACHE_STATE state;
66
67     // subscriber info
68     std::unique_ptr<SubscriberInfo> subscriberList;
69
70     // for requestCB from base
71     void onObserve(const HeaderOptions& _hos,
72             const ResponseStatement& _rep, int _result, int _seq);
73     void onGet(const HeaderOptions& _hos, const ResponseStatement& _rep, int _result);
74
75     ObserveCB pObserveCB;
76     GetCB pGetCB;
77
78     OCStackResult updateCacheData();
79
80     // for timer
81     void setUpdateTime();
82     void onTimer();
83     bool isAvailable();
84
85 };
86
87 #endif /* DATACACHE_H_ */