7c7d0544a35ff069b71ff8e1ffab10d655ae286d
[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 <memory>
26 #include <string>
27 #include <boost/progress.hpp>
28
29 #include "OCResource.h"
30 #include "logger.h"
31
32 #include "CacheTypes.h"
33
34 class DataCache
35 {
36 public:
37     DataCache(
38             PrimitiveResource & pResource,
39             CacheCB func,
40             REPORT_FREQUENCY rf,
41             long repeatTime);
42     ~DataCache();
43
44     CacheID addSubscriber(CacheCB func, REPORT_FREQUENCY rf, long repeatTime);
45     CacheID deleteSubscriber(CacheID id);
46
47     std::shared_ptr<CacheData> getCachedData();
48     PrimitiveResource * getPrimitiveResource();
49
50 private:
51     // origin resource info
52     std::string uri;
53     std::string address;
54
55     // resource instance
56     PrimitiveResource *sResource;
57     std::shared_ptr<BaseResource> baseHandler;
58
59     std::shared_ptr<ResourceAttributes> attributes;
60
61     // cached data info
62     std::shared_ptr<CacheData> data;
63     long updateTime;
64     CACHE_STATE state;
65
66     // subscriber info
67     SubscriberInfo *subscriberList;
68     SubscriberInfoPair findSubscriber(CacheID id);
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     //
79     OCStackResult updateCacheData();
80
81     // for timer
82     void setUpdateTime();
83     void onTimer();
84     bool isAvailable();
85
86 };
87
88 #endif /* DATACACHE_H_ */