1 //******************************************************************
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #ifndef RCM_OBSERVECACHE_H_
22 #define RCM_OBSERVECACHE_H_
30 #include "CacheTypes.h"
31 #include "PrimitiveResource.h"
32 #include "ExpiryTimer.h"
38 class ObserveCache : public std::enable_shared_from_this<ObserveCache>
41 typedef std::function<OCStackResult(std::shared_ptr<PrimitiveResource>,
42 const RCSResourceAttributes &, int)> DataCacheCB;
43 typedef std::shared_ptr<ObserveCache> Ptr;
46 ObserveCache(std::weak_ptr<PrimitiveResource> pResource);
47 ~ObserveCache() = default;
49 ObserveCache(const ObserveCache &) = delete;
50 ObserveCache(ObserveCache &&) = delete;
51 ObserveCache & operator = (const ObserveCache &) = delete;
52 ObserveCache & operator = (ObserveCache &&) = delete;
54 void startCache(DataCacheCB func);
57 CACHE_STATE getCacheState() const;
59 RCSResourceAttributes getCachedData() const;
61 bool isCachedData() const;
62 bool isStartCache() const;
65 typedef unsigned int TimerID;
66 typedef std::weak_ptr<PrimitiveResource> weakPrimitiveResource;
67 typedef std::weak_ptr<ObserveCache> weakDataCache;
70 weakPrimitiveResource m_wpResource;
73 RCSResourceAttributes m_attributes;
77 DataCacheCB m_reportCB;
79 std::atomic<bool> m_isStart;
84 static void verifyObserveCB(const HeaderOptions &_hos,
85 const ResponseStatement &_rep, int _result,
86 unsigned int _seq, weakDataCache ptr);
87 void onObserve(const HeaderOptions &_hos,
88 const ResponseStatement &_rep, int _result, unsigned int _seq);
89 bool convertOCResultToSuccess(OCStackResult ret);
91 } // namespace Service
94 #endif /* RCM_DATACACHE_H_ */