_a_p_i_cache_8h_source.html
15.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>hueplusplus: include/hueplusplus/APICache.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">hueplusplus
 <span id="projectnumber">1.0.0</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_e05b4b7707bd5f9fd045e8be02b17d0a.html">hueplusplus</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">APICache.h</div> </div>
</div><!--header-->
<div class="contents">
<a href="_a_p_i_cache_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> </div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span> <span class="preprocessor">#ifndef INCLUDE_API_CACHE_H</span></div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span> <span class="preprocessor">#define INCLUDE_API_CACHE_H</span></div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span> </div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span> <span class="preprocessor">#include <chrono></span></div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span> <span class="preprocessor">#include <string></span></div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span> </div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span> <span class="preprocessor">#include "<a class="code" href="_hue_command_a_p_i_8h.html">HueCommandAPI.h</a>"</span></div><div class="line"><a name="l00030"></a><span class="lineno"> 30</span> </div><div class="line"><a name="l00031"></a><span class="lineno"> 31</span> <span class="keyword">namespace </span><a class="code" href="namespacehueplusplus.html">hueplusplus</a></div><div class="line"><a name="l00032"></a><span class="lineno"> 32</span> {</div><div class="line"><a name="l00034"></a><span class="lineno"><a class="line" href="namespacehueplusplus.html#add9e010e3277f7763db4006cc9f46b86"> 34</a></span> constexpr std::chrono::steady_clock::duration <a class="code" href="namespacehueplusplus.html#add9e010e3277f7763db4006cc9f46b86">c_refreshNever</a> = std::chrono::steady_clock::duration::max();</div><div class="line"><a name="l00035"></a><span class="lineno"> 35</span> </div><div class="line"><a name="l00037"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_a_p_i_cache.html"> 37</a></span> <span class="keyword">class </span><a class="code" href="classhueplusplus_1_1_a_p_i_cache.html">APICache</a></div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span> {</div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span> <span class="keyword">public</span>:</div><div class="line"><a name="l00047"></a><span class="lineno"> 47</span>  <a class="code" href="classhueplusplus_1_1_a_p_i_cache.html#ab4657a168d72e1f2c344ef1f2f44647c">APICache</a>(</div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span>  std::shared_ptr<APICache> baseCache, <span class="keyword">const</span> std::string& subEntry, std::chrono::steady_clock::duration <a class="code" href="classhueplusplus_1_1_a_p_i_cache.html#a712df81284602eb43afae322f8d43e7b">refresh</a>);</div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span> </div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span>  <a class="code" href="classhueplusplus_1_1_a_p_i_cache.html#ab4657a168d72e1f2c344ef1f2f44647c">APICache</a>(<span class="keyword">const</span> std::string& path, <span class="keyword">const</span> <a class="code" href="classhueplusplus_1_1_hue_command_a_p_i.html">HueCommandAPI</a>& commands, std::chrono::steady_clock::duration refresh,</div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span>  <span class="keyword">const</span> nlohmann::json& initial);</div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span> </div><div class="line"><a name="l00065"></a><span class="lineno"> 65</span>  <span class="keywordtype">void</span> <a class="code" href="classhueplusplus_1_1_a_p_i_cache.html#a712df81284602eb43afae322f8d43e7b">refresh</a>();</div><div class="line"><a name="l00066"></a><span class="lineno"> 66</span> </div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span>  nlohmann::json& <a class="code" href="classhueplusplus_1_1_a_p_i_cache.html#afeededdbb81e3c668b2b983c3d29ee0d">getValue</a>();</div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span>  <span class="keyword">const</span> nlohmann::json& <a class="code" href="classhueplusplus_1_1_a_p_i_cache.html#afeededdbb81e3c668b2b983c3d29ee0d">getValue</a>() <span class="keyword">const</span>;</div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span> </div><div class="line"><a name="l00084"></a><span class="lineno"> 84</span>  <span class="keywordtype">void</span> <a class="code" href="classhueplusplus_1_1_a_p_i_cache.html#a25233da7881b9046555164bcf44b0f85">setRefreshDuration</a>(std::chrono::steady_clock::duration refreshDuration);</div><div class="line"><a name="l00085"></a><span class="lineno"> 85</span> </div><div class="line"><a name="l00087"></a><span class="lineno"> 87</span>  std::chrono::steady_clock::duration <a class="code" href="classhueplusplus_1_1_a_p_i_cache.html#a0f924bf1a6341b11f68f020472041548">getRefreshDuration</a>() <span class="keyword">const</span>;</div><div class="line"><a name="l00088"></a><span class="lineno"> 88</span> </div><div class="line"><a name="l00090"></a><span class="lineno"> 90</span>  <a class="code" href="classhueplusplus_1_1_hue_command_a_p_i.html">HueCommandAPI</a>& <a class="code" href="classhueplusplus_1_1_a_p_i_cache.html#afbbe9068d0b6e8e3b600091c51123464">getCommandAPI</a>();</div><div class="line"><a name="l00092"></a><span class="lineno"> 92</span>  <span class="keyword">const</span> <a class="code" href="classhueplusplus_1_1_hue_command_a_p_i.html">HueCommandAPI</a>& <a class="code" href="classhueplusplus_1_1_a_p_i_cache.html#afbbe9068d0b6e8e3b600091c51123464">getCommandAPI</a>() <span class="keyword">const</span>;</div><div class="line"><a name="l00093"></a><span class="lineno"> 93</span> </div><div class="line"><a name="l00096"></a><span class="lineno"> 96</span>  std::string <a class="code" href="classhueplusplus_1_1_a_p_i_cache.html#ab7bfbec1c32e236c2878a3368f8767cb">getRequestPath</a>() <span class="keyword">const</span>;</div><div class="line"><a name="l00097"></a><span class="lineno"> 97</span> </div><div class="line"><a name="l00098"></a><span class="lineno"> 98</span> <span class="keyword">private</span>:</div><div class="line"><a name="l00099"></a><span class="lineno"> 99</span>  <span class="keywordtype">bool</span> needsRefresh();</div><div class="line"><a name="l00100"></a><span class="lineno"> 100</span> </div><div class="line"><a name="l00101"></a><span class="lineno"> 101</span> <span class="keyword">private</span>:</div><div class="line"><a name="l00102"></a><span class="lineno"> 102</span>  std::shared_ptr<APICache> base;</div><div class="line"><a name="l00103"></a><span class="lineno"> 103</span>  std::string path;</div><div class="line"><a name="l00104"></a><span class="lineno"> 104</span>  <a class="code" href="classhueplusplus_1_1_hue_command_a_p_i.html">HueCommandAPI</a> commands;</div><div class="line"><a name="l00105"></a><span class="lineno"> 105</span>  std::chrono::steady_clock::duration refreshDuration;</div><div class="line"><a name="l00106"></a><span class="lineno"> 106</span>  std::chrono::steady_clock::time_point lastRefresh;</div><div class="line"><a name="l00107"></a><span class="lineno"> 107</span>  nlohmann::json value;</div><div class="line"><a name="l00108"></a><span class="lineno"> 108</span> };</div><div class="line"><a name="l00109"></a><span class="lineno"> 109</span> } <span class="comment">// namespace hueplusplus</span></div><div class="line"><a name="l00110"></a><span class="lineno"> 110</span> </div><div class="line"><a name="l00111"></a><span class="lineno"> 111</span> <span class="preprocessor">#endif</span></div><div class="ttc" id="classhueplusplus_1_1_hue_command_a_p_i_html"><div class="ttname"><a href="classhueplusplus_1_1_hue_command_a_p_i.html">hueplusplus::HueCommandAPI</a></div><div class="ttdef"><b>Definition:</b> HueCommandAPI.h:37</div></div>
<div class="ttc" id="classhueplusplus_1_1_a_p_i_cache_html_afbbe9068d0b6e8e3b600091c51123464"><div class="ttname"><a href="classhueplusplus_1_1_a_p_i_cache.html#afbbe9068d0b6e8e3b600091c51123464">hueplusplus::APICache::getCommandAPI</a></div><div class="ttdeci">HueCommandAPI & getCommandAPI()</div><div class="ttdoc">Get HueCommandAPI used for requests. </div><div class="ttdef"><b>Definition:</b> APICache.cpp:127</div></div>
<div class="ttc" id="namespacehueplusplus_html"><div class="ttname"><a href="namespacehueplusplus.html">hueplusplus</a></div><div class="ttdoc">Namespace for the hueplusplus library. </div><div class="ttdef"><b>Definition:</b> Action.h:27</div></div>
<div class="ttc" id="classhueplusplus_1_1_a_p_i_cache_html"><div class="ttname"><a href="classhueplusplus_1_1_a_p_i_cache.html">hueplusplus::APICache</a></div><div class="ttdoc">Caches API GET requests and refreshes regularly. </div><div class="ttdef"><b>Definition:</b> APICache.h:37</div></div>
<div class="ttc" id="classhueplusplus_1_1_a_p_i_cache_html_a712df81284602eb43afae322f8d43e7b"><div class="ttname"><a href="classhueplusplus_1_1_a_p_i_cache.html#a712df81284602eb43afae322f8d43e7b">hueplusplus::APICache::refresh</a></div><div class="ttdeci">void refresh()</div><div class="ttdoc">Refresh cache now. </div><div class="ttdef"><b>Definition:</b> APICache.cpp:47</div></div>
<div class="ttc" id="_hue_command_a_p_i_8h_html"><div class="ttname"><a href="_hue_command_a_p_i_8h.html">HueCommandAPI.h</a></div></div>
<div class="ttc" id="classhueplusplus_1_1_a_p_i_cache_html_ab4657a168d72e1f2c344ef1f2f44647c"><div class="ttname"><a href="classhueplusplus_1_1_a_p_i_cache.html#ab4657a168d72e1f2c344ef1f2f44647c">hueplusplus::APICache::APICache</a></div><div class="ttdeci">APICache(std::shared_ptr< APICache > baseCache, const std::string &subEntry, std::chrono::steady_clock::duration refresh)</div><div class="ttdoc">Constructs APICache which forwards to a base cache. </div><div class="ttdef"><b>Definition:</b> APICache.cpp:29</div></div>
<div class="ttc" id="classhueplusplus_1_1_a_p_i_cache_html_a25233da7881b9046555164bcf44b0f85"><div class="ttname"><a href="classhueplusplus_1_1_a_p_i_cache.html#a25233da7881b9046555164bcf44b0f85">hueplusplus::APICache::setRefreshDuration</a></div><div class="ttdeci">void setRefreshDuration(std::chrono::steady_clock::duration refreshDuration)</div><div class="ttdoc">Set duration after which the cache is refreshed. </div><div class="ttdef"><b>Definition:</b> APICache.cpp:117</div></div>
<div class="ttc" id="namespacehueplusplus_html_add9e010e3277f7763db4006cc9f46b86"><div class="ttname"><a href="namespacehueplusplus.html#add9e010e3277f7763db4006cc9f46b86">hueplusplus::c_refreshNever</a></div><div class="ttdeci">constexpr std::chrono::steady_clock::duration c_refreshNever</div><div class="ttdoc">Maximum duration, used to indicate that the cache should never be refreshed automatically. </div><div class="ttdef"><b>Definition:</b> APICache.h:34</div></div>
<div class="ttc" id="classhueplusplus_1_1_a_p_i_cache_html_afeededdbb81e3c668b2b983c3d29ee0d"><div class="ttname"><a href="classhueplusplus_1_1_a_p_i_cache.html#afeededdbb81e3c668b2b983c3d29ee0d">hueplusplus::APICache::getValue</a></div><div class="ttdeci">nlohmann::json & getValue()</div><div class="ttdoc">Get cached value, refresh if necessary. </div><div class="ttdef"><b>Definition:</b> APICache.cpp:69</div></div>
<div class="ttc" id="classhueplusplus_1_1_a_p_i_cache_html_ab7bfbec1c32e236c2878a3368f8767cb"><div class="ttname"><a href="classhueplusplus_1_1_a_p_i_cache.html#ab7bfbec1c32e236c2878a3368f8767cb">hueplusplus::APICache::getRequestPath</a></div><div class="ttdeci">std::string getRequestPath() const</div><div class="ttdoc">Get path the cache is refreshed from. </div><div class="ttdef"><b>Definition:</b> APICache.cpp:166</div></div>
<div class="ttc" id="classhueplusplus_1_1_a_p_i_cache_html_a0f924bf1a6341b11f68f020472041548"><div class="ttname"><a href="classhueplusplus_1_1_a_p_i_cache.html#a0f924bf1a6341b11f68f020472041548">hueplusplus::APICache::getRefreshDuration</a></div><div class="ttdeci">std::chrono::steady_clock::duration getRefreshDuration() const</div><div class="ttdoc">Get duration between refreshes. </div><div class="ttdef"><b>Definition:</b> APICache.cpp:122</div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by  <a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>