summaryrefslogtreecommitdiffstats
path: root/K2LABI/IPC/K2LIPC.cpp
blob: 5d173595e9c88b0a60fdde83aff2638486a644fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "windows-adapter.h"
#include "K2LIPC.h"
#include "IPCFlowDecoder.h"
#include "Ipc.h"

IIpc* CIpcFactory::CreateIpc()
{
    return new CIpc();
}

//-----------------------------------------------------------------------------
void CIpcFactory::DestroyIpc(IIpc* pIpc)
{
    delete pIpc;
}

//-----------------------------------------------------------------------------
K2LABI_API IPC_HANDLE CreateIPC()
{
    CIpc* pIpc = new CIpc;
    return reinterpret_cast<IPC_HANDLE>(pIpc);
}

//-----------------------------------------------------------------------------
K2LABI_API void DestroyIPC(IPC_HANDLE hIpc)
{
    CIpc* pIpc = reinterpret_cast<CIpc*>(hIpc);
    delete pIpc;
}

//-----------------------------------------------------------------------------
K2LABI_API int IPCInit(IPC_HANDLE hIpc, FCT_OnMessageEvent callback, FCT_OnEvent error, FCT_OnEvent overflow)
{
    CIpc* pIpc = reinterpret_cast<CIpc*>(hIpc);
    if (!pIpc)
        return -1;

    IIPCListener* pListener = pIpc->CreateListener(callback, error, overflow);
    return pIpc->Init(pListener);
}

//-----------------------------------------------------------------------------
K2LABI_API int IPCDeinit(IPC_HANDLE hIpc)
{
    CIpc* pIpc = reinterpret_cast<CIpc*>(hIpc);
    if (!pIpc)
        return -1;
    
    pIpc->DestroyListener();
    return pIpc->Deinit();
}

//-----------------------------------------------------------------------------
K2LABI_API int IPCFormatRequest(IPC_HANDLE hIpc, BYTE channel, BYTE ifaceId, BYTE funId, DWORD dwSenderID, const BYTE *pReqData, DWORD dataLen, BYTE* pResult, int nResultLen, int* nNeededResultLen)
{
    CIpc* pIpc = reinterpret_cast<CIpc*>(hIpc);
    if (!pIpc)
        return -1;

    return pIpc->FormatRequest(channel, ifaceId, funId, dwSenderID, pReqData, dataLen, pResult, nResultLen, nNeededResultLen);
}

//-----------------------------------------------------------------------------
K2LABI_API void IPCDecode(IPC_HANDLE hIpc, BYTE* pData, int nDataLen)
{
    CIpc* pIpc = reinterpret_cast<CIpc*>(hIpc);

    if (pIpc)
        pIpc->Decode(pData, nDataLen);
}