GateKeeper.h
author Volker Birk <vb@pep-project.org>
Sun, 19 Jun 2016 08:31:51 +0200
changeset 94 59e25c32911a
parent 89 56b26b1c4f3b
child 96 7c1816ce1dbd
permissions -rw-r--r--
more robustness
vb@88
     1
class CpEpCOMServerAdapterModule;
vb@88
     2
vb@88
     3
class GateKeeper {
vb@88
     4
public:
vb@88
     5
    GateKeeper(CpEpCOMServerAdapterModule * const self) : _self(self), now(time(NULL)), next(now + time_diff())
vb@88
     6
    {
vb@88
     7
        LONG lResult = RegOpenCurrentUser(KEY_READ, &cu);
vb@88
     8
        assert(lResult == ERROR_SUCCESS);
vb@94
     9
        if (lResult == ERROR_SUCCESS)
vb@94
    10
            cu_open = true;
vb@94
    11
        else
vb@94
    12
            cu_open = false;
vb@88
    13
    }
vb@88
    14
vb@88
    15
    ~GateKeeper()
vb@88
    16
    {
vb@94
    17
        if (cu_open)
vb@94
    18
            RegCloseKey(cu);
vb@88
    19
    }
vb@88
    20
vb@89
    21
    CpEpCOMServerAdapterModule * const module() const
vb@89
    22
    {
vb@89
    23
        return _self;
vb@89
    24
    }
vb@89
    25
vb@88
    26
    void keep();
vb@88
    27
vb@88
    28
protected:
vb@88
    29
    static const LPCTSTR plugin_reg_path;
vb@88
    30
    static const LPCTSTR plugin_reg_value_name;
vb@88
    31
    static const time_t cycle;
vb@88
    32
    static const DWORD waiting;
vb@88
    33
vb@88
    34
    static time_t time_diff();
vb@88
    35
    void keep_plugin();
vb@88
    36
    void keep_updated();
vb@88
    37
vb@88
    38
private:
vb@88
    39
    time_t now;
vb@88
    40
    time_t next;
vb@94
    41
    bool cu_open;
vb@88
    42
    HKEY cu;
vb@88
    43
vb@88
    44
    CpEpCOMServerAdapterModule * const _self;
vb@88
    45
};