_a_p_i_cache_8h_source.html 15.3 KB
<!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
   &#160;<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>&#160;</div><div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="preprocessor">#ifndef INCLUDE_API_CACHE_H</span></div><div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="preprocessor">#define INCLUDE_API_CACHE_H</span></div><div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;</div><div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;<span class="preprocessor">#include &lt;chrono&gt;</span></div><div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;<span class="preprocessor">#include &lt;string&gt;</span></div><div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;</div><div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="_hue_command_a_p_i_8h.html">HueCommandAPI.h</a>&quot;</span></div><div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;</div><div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;<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>&#160;{</div><div class="line"><a name="l00034"></a><span class="lineno"><a class="line" href="namespacehueplusplus.html#add9e010e3277f7763db4006cc9f46b86">   34</a></span>&#160;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>&#160;</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>&#160;<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>&#160;{</div><div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;<span class="keyword">public</span>:</div><div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;    <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>&#160;        std::shared_ptr&lt;APICache&gt; baseCache, <span class="keyword">const</span> std::string&amp; 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>&#160;</div><div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;    <a class="code" href="classhueplusplus_1_1_a_p_i_cache.html#ab4657a168d72e1f2c344ef1f2f44647c">APICache</a>(<span class="keyword">const</span> std::string&amp; path, <span class="keyword">const</span> <a class="code" href="classhueplusplus_1_1_hue_command_a_p_i.html">HueCommandAPI</a>&amp; commands, std::chrono::steady_clock::duration refresh,</div><div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;        <span class="keyword">const</span> nlohmann::json&amp; initial);</div><div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;</div><div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;    <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>&#160;</div><div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;    nlohmann::json&amp; <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>&#160;    <span class="keyword">const</span> nlohmann::json&amp; <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>&#160;</div><div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;    <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>&#160;</div><div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;    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>&#160;</div><div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;    <a class="code" href="classhueplusplus_1_1_hue_command_a_p_i.html">HueCommandAPI</a>&amp; <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>&#160;    <span class="keyword">const</span> <a class="code" href="classhueplusplus_1_1_hue_command_a_p_i.html">HueCommandAPI</a>&amp; <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>&#160;</div><div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;    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>&#160;</div><div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;<span class="keyword">private</span>:</div><div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;    <span class="keywordtype">bool</span> needsRefresh();</div><div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;</div><div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;<span class="keyword">private</span>:</div><div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;    std::shared_ptr&lt;APICache&gt; base;</div><div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;    std::string path;</div><div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;    <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>&#160;    std::chrono::steady_clock::duration refreshDuration;</div><div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;    std::chrono::steady_clock::time_point lastRefresh;</div><div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;    nlohmann::json value;</div><div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;};</div><div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;} <span class="comment">// namespace hueplusplus</span></div><div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;</div><div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;<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 &amp; 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&lt; APICache &gt; baseCache, const std::string &amp;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 &amp; 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 &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>