Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
21 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
 
27
extern bool prg_stopped;
28
 
29
class TImageRefresh
30
{
31
    public:
32
        TImageRefresh();
33
        ~TImageRefresh();
34
 
35
        void run(const std::string& url);
36
        void stop() { mStopped = true; }
37
        bool isRunning() { return mRunning; }
38
        void setInterval(std::chrono::seconds s) { mSec = s; }
39
        void setRunOnce() { mRunOnce = true; }
40
        void setUsername(const std::string& user) { mUser = user; }
41
        void setPassword(const std::string& pw) { mPassword = pw; }
42
        void registerCallback(std::function<void(const std::string& url)> callback) { _callback = callback; }
43
 
44
    protected:
45
        void _run(const std::string& url);
46
        std::function<void(const std::string& url)> _callback{nullptr};
47
 
48
    private:
49
        std::thread mThread;
50
        std::chrono::seconds mSec{0};
51
        bool mStopped{false};
52
        bool mRunning{false};
53
        bool mRunOnce{false};
54
        std::string mUser;
55
        std::string mPassword;
56
};
57
 
58
#endif