pEpCOMServerAdapter.cpp
author Volker Birk <vb@pep.foundation>
Thu, 02 Jul 2020 07:46:18 +0200
branchCOM-115
changeset 425 161a68f99058
parent 420 e984cace12a6
child 426 02815463ba92
permissions -rw-r--r--
first UI
vb@0
     1
// pEpCOMServerAdapter.cpp : Implementation of WinMain
vb@0
     2
vb@0
     3
vb@0
     4
#include "stdafx.h"
vb@0
     5
#include "resource.h"
vb@0
     6
#include "xdlldata.h"
vb@0
     7
vb@88
     8
#include "GateKeeper.h"
vb@110
     9
#include "pEpCOMServerAdapter.h"
vb@409
    10
#include "LocalJSONAdapter.h"
vb@425
    11
#include "CMainWindow.h"
vb@0
    12
vb@0
    13
using namespace ATL;
vb@86
    14
using namespace std;
vb@0
    15
vb@117
    16
void CpEpCOMServerAdapterModule::gatekeeper(CpEpCOMServerAdapterModule * self)
vb@86
    17
{
vb@96
    18
    pEp::GateKeeper keeper(self);
vb@86
    19
    keeper.keep();
vb@86
    20
}
vb@86
    21
vb@0
    22
CpEpCOMServerAdapterModule _AtlModule;
vb@411
    23
LocalJSONAdapter* ljs = nullptr;
vb@413
    24
pEp::PassphraseCache cache;
vb@425
    25
CMainWindow mainWindow;
vb@0
    26
vb@110
    27
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, 
vb@409
    28
                                LPTSTR lpCmdLine, int nShowCmd)
vb@0
    29
{
vb@110
    30
    _AtlModule.hModule(hInstance);
vb@110
    31
    _AtlModule.start_gatekeeper();
vb@110
    32
vb@409
    33
    PEP_SESSION first_session;
vb@409
    34
    PEP_STATUS status = ::init(&first_session, NULL, NULL);
vb@409
    35
vb@411
    36
    if (!boost::algorithm::iequals(lpCmdLine, "/regserver")) {
vb@411
    37
        ljs = &LocalJSONAdapter::createInstance();
vb@412
    38
        ljs->startup(pEp::CallbackDispatcher::messageToSend);
vb@418
    39
        pEp::callback_dispatcher.add(JsonAdapter::messageToSend, JsonAdapter::notifyHandshake);
vb@425
    40
        auto mw = mainWindow.Create(HWND_MESSAGE);
vb@425
    41
        assert(mw);
vb@411
    42
    }
vb@409
    43
vb@409
    44
    auto rv = _AtlModule.WinMain(nShowCmd);
vb@409
    45
vb@411
    46
    if (ljs) {
vb@425
    47
        BOOL r = true;
vb@425
    48
        mainWindow.OnDestroy(0, 0, 0, r);
vb@418
    49
        pEp::callback_dispatcher.remove(JsonAdapter::messageToSend);
vb@409
    50
        ljs->shutdown_now();
vb@411
    51
    }
vb@409
    52
vb@409
    53
    ::release(first_session);
vb@420
    54
    ExitProcess(rv);
vb@409
    55
    return rv;
vb@0
    56
}