8029b245333b30c5309ea497849190ebd5bbadd3
[platform/upstream/iotivity.git] / service / resource-manipulation / modules / 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 <memory>
27
28 #include "OCResource.h"
29 #include "logger.h"
30
31 #include "CacheTypes.h"
32 #include "PrimitiveTimer.h"
33
34 class DataCache
35 {
36 public:
37     DataCache(
38             PrimitiveResourcePtr 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     CACHE_STATE getCacheState() const;
48     const ResourceAttributes getCachedData() const;
49     const PrimitiveResourcePtr getPrimitiveResource() const;
50
51     SubscriberInfoPair findSubscriber(CacheID id);
52
53 private:
54     // origin resource info
55     std::string uri;
56     std::string address;
57
58     // resource instance
59     PrimitiveResourcePtr sResource;
60     std::shared_ptr<BaseResource> baseHandler;
61
62     // cached data info
63     ResourceAttributes attributes;
64     long updateTime;
65     CACHE_STATE state;
66
67     // subscriber info
68     std::unique_ptr<SubscriberInfo> subscriberList;
69
70     PrimitiveTimer *timerInstance;
71
72     // for requestCB from base
73     void onObserve(const HeaderOptions& _hos,
74             const ResponseStatement& _rep, int _result, int _seq);
75     void onGet(const HeaderOptions& _hos, const ResponseStatement& _rep, int _result);
76     void *onTimer(const unsigned int timerID);
77     ObserveCB pObserveCB;
78     GetCB pGetCB;
79     TimerCB pTimerCB;
80
81     OCStackResult updateCacheData();
82
83 };
84
85 #endif /* DATACACHE_H_ */