Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
446 andreas 1
/*
2
 * Copyright (C) 2021 by Andreas Theofilu <andreas@theosys.at>
3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software Foundation,
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 */
18
 
19
#ifndef __TIMAGEREFRESH_H__
20
#define __TIMAGEREFRESH_H__
21
 
22
#include <string>
23
#include <thread>
24
#include <chrono>
25
#include <functional>
26
#include <atomic>
27
 
28
extern bool prg_stopped;
29
 
30
class TImageRefresh
31
{
32
    public:
33
        TImageRefresh();
34
        ~TImageRefresh();
35
 
36
        void run(const std::string& url);
37
        void stop() { mStopped = true; }
38
        void stopWait();
39
        bool isRunning() { return mRunning; }
40
        void setInterval(std::chrono::seconds s) { mSec = s; }
41
        void setRunOnce() { mRunOnce = true; }
42
        void setUsername(const std::string& user) { mUser = user; }
43
        void setPassword(const std::string& pw) { mPassword = pw; }
44
        void registerCallback(std::function<void(const std::string& url)> callback) { _callback = callback; }
45
 
46
    protected:
47
        void _run(const std::string& url);
48
        std::function<void(const std::string& url)> _callback{nullptr};
49
 
50
    private:
51
        std::thread mThread;
52
        std::chrono::seconds mSec{0};
53
        std::atomic<bool> mStopped{false};
54
        std::atomic<bool> mRunning{false};
55
        std::atomic<bool> mRunOnce{false};
56
        std::string mUser;
57
        std::string mPassword;
58
};
59
 
60
#endif