nicer
authorVolker Birk <vb@pep-project.org>
Sun, 19 Jun 2016 07:59:43 +0200
changeset 88659d0fc5bc30
parent 87 f0ce6a1a7118
child 89 56b26b1c4f3b
nicer
GateKeeper.cpp
GateKeeper.h
pEpCOMServerAdapter.cpp
pEpCOMServerAdapter.vcxproj
pEpCOMServerAdapter.vcxproj.filters
stdafx.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/GateKeeper.cpp	Sun Jun 19 07:59:43 2016 +0200
     1.3 @@ -0,0 +1,64 @@
     1.4 +#include "stdafx.h"
     1.5 +
     1.6 +#include "GateKeeper.h"
     1.7 +
     1.8 +using namespace std;
     1.9 +
    1.10 +const LPCTSTR GateKeeper::plugin_reg_path = _T("Software\\Microsoft\\Office\\Outlook\\Addins\\pEp");
    1.11 +const LPCTSTR GateKeeper::plugin_reg_value_name = _T("LoadBehavior");
    1.12 +
    1.13 +const time_t GateKeeper::cycle = 7200;   // 7200 sec is 2 h
    1.14 +const DWORD GateKeeper::waiting = 10000; // 10000 ms is 10 sec
    1.15 +
    1.16 +time_t GateKeeper::time_diff()
    1.17 +{
    1.18 +    try {
    1.19 +        static random_device rd;
    1.20 +        static mt19937 gen(rd());
    1.21 +
    1.22 +        uniform_int_distribution<time_t> dist(0, cycle);
    1.23 +
    1.24 +        return dist(gen);
    1.25 +    }
    1.26 +    catch (exception&) {
    1.27 +        assert(0);
    1.28 +        return 0;
    1.29 +    }
    1.30 +}
    1.31 +
    1.32 +void GateKeeper::keep()
    1.33 +{
    1.34 +    while (1) {
    1.35 +        keep_plugin();
    1.36 +
    1.37 +        now = time(NULL);
    1.38 +        assert(now != -1);
    1.39 +
    1.40 +        if (now > next) {
    1.41 +            next = now + GateKeeper::cycle;
    1.42 +            keep_updated();
    1.43 +        }
    1.44 +
    1.45 +        Sleep(waiting);
    1.46 +    }
    1.47 +}
    1.48 +
    1.49 +void GateKeeper::keep_plugin()
    1.50 +{
    1.51 +    DWORD value;
    1.52 +    DWORD size;
    1.53 +
    1.54 +    LONG lResult = RegGetValue(cu, plugin_reg_path, plugin_reg_value_name, RRF_RT_REG_DWORD, NULL, &value, &size);
    1.55 +    if (lResult != ERROR_SUCCESS)
    1.56 +        return;
    1.57 +
    1.58 +    if (value != 3) {
    1.59 +        lResult = RegSetValue(cu, plugin_reg_path, RRF_RT_REG_DWORD, plugin_reg_value_name, 3);
    1.60 +        assert(lResult == ERROR_SUCCESS);
    1.61 +    }
    1.62 +}
    1.63 +
    1.64 +void GateKeeper::keep_updated()
    1.65 +{
    1.66 +
    1.67 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/GateKeeper.h	Sun Jun 19 07:59:43 2016 +0200
     2.3 @@ -0,0 +1,34 @@
     2.4 +class CpEpCOMServerAdapterModule;
     2.5 +
     2.6 +class GateKeeper {
     2.7 +public:
     2.8 +    GateKeeper(CpEpCOMServerAdapterModule * const self) : _self(self), now(time(NULL)), next(now + time_diff())
     2.9 +    {
    2.10 +        LONG lResult = RegOpenCurrentUser(KEY_READ, &cu);
    2.11 +        assert(lResult == ERROR_SUCCESS);
    2.12 +    }
    2.13 +
    2.14 +    ~GateKeeper()
    2.15 +    {
    2.16 +        RegCloseKey(cu);
    2.17 +    }
    2.18 +
    2.19 +    void keep();
    2.20 +
    2.21 +protected:
    2.22 +    static const LPCTSTR plugin_reg_path;
    2.23 +    static const LPCTSTR plugin_reg_value_name;
    2.24 +    static const time_t cycle;
    2.25 +    static const DWORD waiting;
    2.26 +
    2.27 +    static time_t time_diff();
    2.28 +    void keep_plugin();
    2.29 +    void keep_updated();
    2.30 +
    2.31 +private:
    2.32 +    time_t now;
    2.33 +    time_t next;
    2.34 +    HKEY cu;
    2.35 +
    2.36 +    CpEpCOMServerAdapterModule * const _self;
    2.37 +};
     3.1 --- a/pEpCOMServerAdapter.cpp	Sun Jun 19 01:04:41 2016 +0200
     3.2 +++ b/pEpCOMServerAdapter.cpp	Sun Jun 19 07:59:43 2016 +0200
     3.3 @@ -6,102 +6,11 @@
     3.4  #include "pEpCOMServerAdapter_i.h"
     3.5  #include "xdlldata.h"
     3.6  
     3.7 +#include "GateKeeper.h"
     3.8  
     3.9  using namespace ATL;
    3.10  using namespace std;
    3.11  
    3.12 -class CpEpCOMServerAdapterModule;
    3.13 -
    3.14 -static class GateKeeper {
    3.15 -public:
    3.16 -    static const time_t cycle = 7200;   // 7200 sec is 2 h
    3.17 -    static const DWORD waiting = 10000; // 10000 ms is 10 sec
    3.18 -
    3.19 -    static time_t time_diff()
    3.20 -    {
    3.21 -        try {
    3.22 -            static random_device rd;
    3.23 -            static mt19937 gen(rd());
    3.24 -
    3.25 -            uniform_int_distribution<time_t> dist(0, cycle);
    3.26 -
    3.27 -            return dist(gen);
    3.28 -        }
    3.29 -        catch (exception& e) {
    3.30 -            assert(0);
    3.31 -            return 0;
    3.32 -        }
    3.33 -    }
    3.34 -
    3.35 -    GateKeeper(CpEpCOMServerAdapterModule * const self) : _self(self), now(time(NULL)), next(now + time_diff())
    3.36 -    {
    3.37 -        LONG lResult = RegOpenCurrentUser(KEY_READ, &cu);
    3.38 -        assert(lResult == ERROR_SUCCESS);
    3.39 -    }
    3.40 -
    3.41 -    ~GateKeeper()
    3.42 -    {
    3.43 -        RegCloseKey(cu);
    3.44 -    }
    3.45 -
    3.46 -    void keep();
    3.47 -
    3.48 -    void keep_plugin();
    3.49 -    void keep_updated();
    3.50 -
    3.51 -protected:
    3.52 -    static const LPCTSTR plugin_reg_path;
    3.53 -    static const LPCTSTR plugin_reg_value_name;
    3.54 -
    3.55 -private:
    3.56 -    time_t now;
    3.57 -    time_t next;
    3.58 -    HKEY cu;
    3.59 -
    3.60 -    CpEpCOMServerAdapterModule * const _self;
    3.61 -};
    3.62 -
    3.63 -const LPCTSTR GateKeeper::plugin_reg_path = _T("Software\\Microsoft\\Office\\Outlook\\Addins\\pEp");
    3.64 -const LPCTSTR GateKeeper::plugin_reg_value_name = _T("LoadBehavior");
    3.65 -
    3.66 -void GateKeeper::keep()
    3.67 -{
    3.68 -    while (1) {
    3.69 -        keep_plugin();
    3.70 -
    3.71 -        now = time(NULL);
    3.72 -        assert(now != -1);
    3.73 -        
    3.74 -        if (now > next) {
    3.75 -            next = now + GateKeeper::cycle;
    3.76 -            keep_updated();
    3.77 -        }
    3.78 -
    3.79 -        Sleep(10000);
    3.80 -    }
    3.81 -}
    3.82 -
    3.83 -void GateKeeper::keep_plugin()
    3.84 -{
    3.85 -    DWORD value;
    3.86 -    DWORD size;
    3.87 -    LONG lResult = RegGetValue(cu, plugin_reg_path, plugin_reg_value_name, RRF_RT_REG_DWORD, NULL, &value, &size);
    3.88 -
    3.89 -    assert(lResult == ERROR_SUCCESS);
    3.90 -    if (lResult != ERROR_SUCCESS)
    3.91 -        return;
    3.92 -
    3.93 -    if (value != 3) {
    3.94 -        lResult = RegSetValue(cu, plugin_reg_path, RRF_RT_REG_DWORD, plugin_reg_value_name, 3);
    3.95 -        assert(lResult == ERROR_SUCCESS);
    3.96 -    }
    3.97 -}
    3.98 -
    3.99 -void GateKeeper::keep_updated()
   3.100 -{
   3.101 -
   3.102 -}
   3.103 -
   3.104  class CpEpCOMServerAdapterModule : public ATL::CAtlExeModuleT< CpEpCOMServerAdapterModule >
   3.105  {
   3.106  public:
   3.107 @@ -114,11 +23,11 @@
   3.108  	DECLARE_LIBID(LIBID_pEpCOMServerAdapterLib)
   3.109  	DECLARE_REGISTRY_APPID_RESOURCEID(IDR_PEPCOMSERVERADAPTER, "{B3480081-82C0-4EE4-9AA1-3F513C9D78DD}")
   3.110  
   3.111 +protected:
   3.112 +    static void gatekeeper(CpEpCOMServerAdapterModule * const self);
   3.113 +
   3.114  private:
   3.115      thread *gatekeeper_thread;
   3.116 -
   3.117 -protected:
   3.118 -    static void gatekeeper(CpEpCOMServerAdapterModule * const self);
   3.119  };
   3.120  
   3.121  void CpEpCOMServerAdapterModule::gatekeeper(CpEpCOMServerAdapterModule * const self)
     4.1 --- a/pEpCOMServerAdapter.vcxproj	Sun Jun 19 01:04:41 2016 +0200
     4.2 +++ b/pEpCOMServerAdapter.vcxproj	Sun Jun 19 07:59:43 2016 +0200
     4.3 @@ -85,7 +85,7 @@
     4.4        <SubSystem>Windows</SubSystem>
     4.5        <GenerateDebugInformation>true</GenerateDebugInformation>
     4.6        <RegisterOutput>false</RegisterOutput>
     4.7 -      <AdditionalDependencies>comsuppwd.lib;%(AdditionalDependencies)</AdditionalDependencies>
     4.8 +      <AdditionalDependencies>comsuppwd.lib;%(AdditionalDependencies);Wininet.lib</AdditionalDependencies>
     4.9        <PerUserRedirection>true</PerUserRedirection>
    4.10      </Link>
    4.11    </ItemDefinitionGroup>
    4.12 @@ -120,11 +120,12 @@
    4.13        <EnableCOMDATFolding>true</EnableCOMDATFolding>
    4.14        <OptimizeReferences>true</OptimizeReferences>
    4.15        <RegisterOutput>true</RegisterOutput>
    4.16 -      <AdditionalDependencies>comsuppw.lib;%(AdditionalDependencies)</AdditionalDependencies>
    4.17 +      <AdditionalDependencies>comsuppw.lib;%(AdditionalDependencies);Wininet.lib</AdditionalDependencies>
    4.18      </Link>
    4.19    </ItemDefinitionGroup>
    4.20    <ItemGroup>
    4.21      <ClCompile Include="CpEpEngine.cpp" />
    4.22 +    <ClCompile Include="GateKeeper.cpp" />
    4.23      <ClCompile Include="pEpCOMServerAdapter.cpp" />
    4.24      <ClCompile Include="pEpCOMServerAdapter_i.c">
    4.25        <CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</CompileAsManaged>
    4.26 @@ -151,6 +152,7 @@
    4.27    </ItemGroup>
    4.28    <ItemGroup>
    4.29      <ClInclude Include="CpEpEngine.h" />
    4.30 +    <ClInclude Include="GateKeeper.h" />
    4.31      <ClInclude Include="locked_queue.hh" />
    4.32      <ClInclude Include="pEpCOMServerAdapter_i.h" />
    4.33      <ClInclude Include="pEp_utility.h" />
     5.1 --- a/pEpCOMServerAdapter.vcxproj.filters	Sun Jun 19 01:04:41 2016 +0200
     5.2 +++ b/pEpCOMServerAdapter.vcxproj.filters	Sun Jun 19 07:59:43 2016 +0200
     5.3 @@ -40,6 +40,9 @@
     5.4      <ClCompile Include="pEp_utility.cpp">
     5.5        <Filter>Source Files</Filter>
     5.6      </ClCompile>
     5.7 +    <ClCompile Include="GateKeeper.cpp">
     5.8 +      <Filter>Source Files</Filter>
     5.9 +    </ClCompile>
    5.10    </ItemGroup>
    5.11    <ItemGroup>
    5.12      <ClInclude Include="stdafx.h">
    5.13 @@ -72,6 +75,9 @@
    5.14      <ClInclude Include="_IpEpEngineEvents_CP.H">
    5.15        <Filter>Generated Files</Filter>
    5.16      </ClInclude>
    5.17 +    <ClInclude Include="GateKeeper.h">
    5.18 +      <Filter>Header Files</Filter>
    5.19 +    </ClInclude>
    5.20    </ItemGroup>
    5.21    <ItemGroup>
    5.22      <ResourceCompile Include="pEpCOMServerAdapter.rc">
     6.1 --- a/stdafx.h	Sun Jun 19 01:04:41 2016 +0200
     6.2 +++ b/stdafx.h	Sun Jun 19 07:59:43 2016 +0200
     6.3 @@ -27,6 +27,8 @@
     6.4  
     6.5  #include <comutil.h>
     6.6  
     6.7 +#include <Wininet.h>
     6.8 +
     6.9  #include <vector>
    6.10  #include <sstream>
    6.11  #include <string>