Browse Source

nicer

COM-121
Volker Birk 6 years ago
parent
commit
f15e9eea9a
6 changed files with 114 additions and 97 deletions
  1. +64
    -0
      GateKeeper.cpp
  2. +34
    -0
      GateKeeper.h
  3. +4
    -95
      pEpCOMServerAdapter.cpp
  4. +4
    -2
      pEpCOMServerAdapter.vcxproj
  5. +6
    -0
      pEpCOMServerAdapter.vcxproj.filters
  6. +2
    -0
      stdafx.h

+ 64
- 0
GateKeeper.cpp View File

@ -0,0 +1,64 @@
#include "stdafx.h"
#include "GateKeeper.h"
using namespace std;
const LPCTSTR GateKeeper::plugin_reg_path = _T("Software\\Microsoft\\Office\\Outlook\\Addins\\pEp");
const LPCTSTR GateKeeper::plugin_reg_value_name = _T("LoadBehavior");
const time_t GateKeeper::cycle = 7200; // 7200 sec is 2 h
const DWORD GateKeeper::waiting = 10000; // 10000 ms is 10 sec
time_t GateKeeper::time_diff()
{
try {
static random_device rd;
static mt19937 gen(rd());
uniform_int_distribution<time_t> dist(0, cycle);
return dist(gen);
}
catch (exception&) {
assert(0);
return 0;
}
}
void GateKeeper::keep()
{
while (1) {
keep_plugin();
now = time(NULL);
assert(now != -1);
if (now > next) {
next = now + GateKeeper::cycle;
keep_updated();
}
Sleep(waiting);
}
}
void GateKeeper::keep_plugin()
{
DWORD value;
DWORD size;
LONG lResult = RegGetValue(cu, plugin_reg_path, plugin_reg_value_name, RRF_RT_REG_DWORD, NULL, &value, &size);
if (lResult != ERROR_SUCCESS)
return;
if (value != 3) {
lResult = RegSetValue(cu, plugin_reg_path, RRF_RT_REG_DWORD, plugin_reg_value_name, 3);
assert(lResult == ERROR_SUCCESS);
}
}
void GateKeeper::keep_updated()
{
}

+ 34
- 0
GateKeeper.h View File

@ -0,0 +1,34 @@
class CpEpCOMServerAdapterModule;
class GateKeeper {
public:
GateKeeper(CpEpCOMServerAdapterModule * const self) : _self(self), now(time(NULL)), next(now + time_diff())
{
LONG lResult = RegOpenCurrentUser(KEY_READ, &cu);
assert(lResult == ERROR_SUCCESS);
}
~GateKeeper()
{
RegCloseKey(cu);
}
void keep();
protected:
static const LPCTSTR plugin_reg_path;
static const LPCTSTR plugin_reg_value_name;
static const time_t cycle;
static const DWORD waiting;
static time_t time_diff();
void keep_plugin();
void keep_updated();
private:
time_t now;
time_t next;
HKEY cu;
CpEpCOMServerAdapterModule * const _self;
};

+ 4
- 95
pEpCOMServerAdapter.cpp View File

@ -6,102 +6,11 @@
#include "pEpCOMServerAdapter_i.h"
#include "xdlldata.h"
#include "GateKeeper.h"
using namespace ATL;
using namespace std;
class CpEpCOMServerAdapterModule;
static class GateKeeper {
public:
static const time_t cycle = 7200; // 7200 sec is 2 h
static const DWORD waiting = 10000; // 10000 ms is 10 sec
static time_t time_diff()
{
try {
static random_device rd;
static mt19937 gen(rd());
uniform_int_distribution<time_t> dist(0, cycle);
return dist(gen);
}
catch (exception& e) {
assert(0);
return 0;
}
}
GateKeeper(CpEpCOMServerAdapterModule * const self) : _self(self), now(time(NULL)), next(now + time_diff())
{
LONG lResult = RegOpenCurrentUser(KEY_READ, &cu);
assert(lResult == ERROR_SUCCESS);
}
~GateKeeper()
{
RegCloseKey(cu);
}
void keep();
void keep_plugin();
void keep_updated();
protected:
static const LPCTSTR plugin_reg_path;
static const LPCTSTR plugin_reg_value_name;
private:
time_t now;
time_t next;
HKEY cu;
CpEpCOMServerAdapterModule * const _self;
};
const LPCTSTR GateKeeper::plugin_reg_path = _T("Software\\Microsoft\\Office\\Outlook\\Addins\\pEp");
const LPCTSTR GateKeeper::plugin_reg_value_name = _T("LoadBehavior");
void GateKeeper::keep()
{
while (1) {
keep_plugin();
now = time(NULL);
assert(now != -1);
if (now > next) {
next = now + GateKeeper::cycle;
keep_updated();
}
Sleep(10000);
}
}
void GateKeeper::keep_plugin()
{
DWORD value;
DWORD size;
LONG lResult = RegGetValue(cu, plugin_reg_path, plugin_reg_value_name, RRF_RT_REG_DWORD, NULL, &value, &size);
assert(lResult == ERROR_SUCCESS);
if (lResult != ERROR_SUCCESS)
return;
if (value != 3) {
lResult = RegSetValue(cu, plugin_reg_path, RRF_RT_REG_DWORD, plugin_reg_value_name, 3);
assert(lResult == ERROR_SUCCESS);
}
}
void GateKeeper::keep_updated()
{
}
class CpEpCOMServerAdapterModule : public ATL::CAtlExeModuleT< CpEpCOMServerAdapterModule >
{
public:
@ -114,11 +23,11 @@ public:
DECLARE_LIBID(LIBID_pEpCOMServerAdapterLib)
DECLARE_REGISTRY_APPID_RESOURCEID(IDR_PEPCOMSERVERADAPTER, "{B3480081-82C0-4EE4-9AA1-3F513C9D78DD}")
private:
thread *gatekeeper_thread;
protected:
static void gatekeeper(CpEpCOMServerAdapterModule * const self);
private:
thread *gatekeeper_thread;
};
void CpEpCOMServerAdapterModule::gatekeeper(CpEpCOMServerAdapterModule * const self)


+ 4
- 2
pEpCOMServerAdapter.vcxproj View File

@ -85,7 +85,7 @@ echo "generating interop assembly $(TargetDir)pEpCOMServerAdapter.Interop.dll"
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<RegisterOutput>false</RegisterOutput>
<AdditionalDependencies>comsuppwd.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>comsuppwd.lib;%(AdditionalDependencies);Wininet.lib</AdditionalDependencies>
<PerUserRedirection>true</PerUserRedirection>
</Link>
</ItemDefinitionGroup>
@ -120,11 +120,12 @@ echo "generating interop assembly $(TargetDir)pEpCOMServerAdapter.Interop.dll"
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<RegisterOutput>true</RegisterOutput>
<AdditionalDependencies>comsuppw.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>comsuppw.lib;%(AdditionalDependencies);Wininet.lib</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="CpEpEngine.cpp" />
<ClCompile Include="GateKeeper.cpp" />
<ClCompile Include="pEpCOMServerAdapter.cpp" />
<ClCompile Include="pEpCOMServerAdapter_i.c">
<CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</CompileAsManaged>
@ -151,6 +152,7 @@ echo "generating interop assembly $(TargetDir)pEpCOMServerAdapter.Interop.dll"
</ItemGroup>
<ItemGroup>
<ClInclude Include="CpEpEngine.h" />
<ClInclude Include="GateKeeper.h" />
<ClInclude Include="locked_queue.hh" />
<ClInclude Include="pEpCOMServerAdapter_i.h" />
<ClInclude Include="pEp_utility.h" />


+ 6
- 0
pEpCOMServerAdapter.vcxproj.filters View File

@ -40,6 +40,9 @@
<ClCompile Include="pEp_utility.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GateKeeper.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
@ -72,6 +75,9 @@
<ClInclude Include="_IpEpEngineEvents_CP.H">
<Filter>Generated Files</Filter>
</ClInclude>
<ClInclude Include="GateKeeper.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="pEpCOMServerAdapter.rc">


+ 2
- 0
stdafx.h View File

@ -27,6 +27,8 @@
#include <comutil.h>
#include <Wininet.h>
#include <vector>
#include <sstream>
#include <string>


Loading…
Cancel
Save