cache_action.h
1 /*
2  * <one line to give the program's name and a brief idea of what it does.>
3  * Copyright (C) 2023 Jose F Rivas C <email>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef NAF_FUNCTIONS_CACHEACTION
20 #define NAF_FUNCTIONS_CACHEACTION
21 
22 
23 #include <string>
24 #include <memory>
25 #include <mutex>
26 #include <thread>
27 #include <chrono>
28 
29 #include "functions/action.h"
30 #include "query/results.h"
31 
32 #include "Poco/Exception.h"
33 #include "functions/action.h"
34 
35 
36 namespace NAF
37 {
38  namespace Functions
39  {
40  class CacheAction;
41  }
42 }
43 
44 using namespace std::chrono_literals;
45 
46 
48 {
49  public:
50  using Ptr = std::shared_ptr<CacheAction>;
51 
52  CacheAction(std::string identifier, std::chrono::seconds update_time);
53 
54  std::shared_ptr<std::thread> get_updates_thread() const { return updates_thread_; }
55  bool get_state() const { return state_; }
56  std::chrono::seconds get_update_time() const { return update_time_; }
57 
58  void set_state(bool state) { state_ = state; }
59  void set_update_time(std::chrono::seconds update_time) { update_time_ = update_time; }
60 
61  virtual bool Work_() override;
62 
63  protected:
64  void WorkInBackground_();
65 
66  private:
67  std::shared_ptr<std::thread> updates_thread_;
68  bool state_;
69  std::chrono::seconds update_time_;
70  std::mutex mutex_;
71 };
72 
73 #endif // NAF_FUNCTIONS_CACHEACTION
Definition: action.h:61
Definition: cache_action.h:48