[8888] | 1 | /* $Id: spy.cpp,v 1.12 2002-07-18 19:22:49 achimha Exp $ */
|
---|
[2469] | 2 |
|
---|
| 3 | /*
|
---|
| 4 | * Queue procedures to send messages to the spy server
|
---|
| 5 | *
|
---|
| 6 | * Copyright 1999 Sander van Leeuwen
|
---|
| 7 | *
|
---|
| 8 | *
|
---|
| 9 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
| 10 | *
|
---|
| 11 | */
|
---|
[8888] | 12 |
|
---|
| 13 | // AH TODO
|
---|
| 14 | // we might want to disable the spy queue for custom builds or at least
|
---|
| 15 | // supply a different queue name
|
---|
| 16 |
|
---|
[2469] | 17 | #define INCL_DOSPROCESS
|
---|
| 18 | #define INCL_DOSQUEUES
|
---|
| 19 | #define INCL_DOSMEMMGR
|
---|
| 20 | #define INCL_WINMESSAGEMGR
|
---|
| 21 | #define INCL_DOSERRORS
|
---|
| 22 | #define INCL_DOSSEMAPHORES
|
---|
| 23 | #include <os2wrap.h>
|
---|
| 24 |
|
---|
| 25 | #include <stdlib.h>
|
---|
| 26 | #include <stddef.h>
|
---|
| 27 | #include <string.h>
|
---|
| 28 | #include <misc.h>
|
---|
| 29 | #include <spy.h>
|
---|
| 30 |
|
---|
[2804] | 31 | #define DBG_LOCALLOG DBG_spy
|
---|
| 32 | #include "dbglocal.h"
|
---|
[2469] | 33 |
|
---|
| 34 | #define Q_BUFFER_SIZE 4096
|
---|
| 35 | #define MAX_MESSAGES (Q_BUFFER_SIZE/sizeof(Q_SPYMSG))
|
---|
| 36 |
|
---|
| 37 | PID pidServer = 0;
|
---|
| 38 | HQUEUE hqQueue = 0;
|
---|
| 39 | Q_SPYMSG *pvdQMemory = 0;
|
---|
| 40 | int msgIndex = 0;
|
---|
| 41 |
|
---|
| 42 | BOOL InitSpyQueue()
|
---|
| 43 | {
|
---|
| 44 | APIRET rc;
|
---|
| 45 |
|
---|
| 46 | if ((rc = DosOpenQueue(&pidServer, &hqQueue, "\\queues\\"Q_NAME)) != 0)
|
---|
| 47 | {
|
---|
| 48 | dprintf(("InitSpyQueue: couldn't open spy queue rc=%d!", rc));
|
---|
| 49 | return FALSE;
|
---|
| 50 | }
|
---|
| 51 | if ((rc = DosAllocSharedMem((VOID **)&pvdQMemory,
|
---|
| 52 | NULL,
|
---|
| 53 | Q_BUFFER_SIZE,
|
---|
| 54 | fALLOCSHR)) != 0)
|
---|
| 55 | {
|
---|
| 56 | dprintf(("InitSpyQueue: DosAllocSharedMem failed rc=%d", rc));
|
---|
| 57 | DosCloseQueue(hqQueue);
|
---|
| 58 | return FALSE;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | /* give memory to server */
|
---|
| 62 | if (DosGiveSharedMem(pvdQMemory, pidServer, PAG_READ | PAG_WRITE))
|
---|
| 63 | {
|
---|
| 64 | dprintf(("InitSpyQueue: DosGiveSharedMem failed"));
|
---|
| 65 | DosCloseQueue(hqQueue);
|
---|
| 66 | return FALSE;
|
---|
| 67 | }
|
---|
| 68 | return (TRUE);
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | void CloseSpyQueue()
|
---|
| 72 | {
|
---|
| 73 | APIRET rc;
|
---|
| 74 |
|
---|
| 75 | dprintf(("CloseSpyQueue"));
|
---|
| 76 | if(hqQueue) {
|
---|
| 77 | if(pvdQMemory) {
|
---|
| 78 | rc = DosWriteQueue(hqQueue, Q_SPYMSG_KILLSERVER, 0, 0, 0);
|
---|
| 79 | if(rc) {
|
---|
| 80 | dprintf(("CloseSpyQueue: DosWriteQueue returned %d", rc));
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 | DosCloseQueue(hqQueue);
|
---|
| 84 | }
|
---|
| 85 | if(pvdQMemory)
|
---|
| 86 | DosFreeMem(pvdQMemory);
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | #ifdef DEBUG
|
---|
| 90 | BOOL PostSpyMessage(HWND hwnd, ULONG Msg, ULONG wParam, ULONG lParam)
|
---|
| 91 | {
|
---|
| 92 | APIRET rc;
|
---|
| 93 |
|
---|
| 94 | if (hqQueue == 0)
|
---|
| 95 | return FALSE;
|
---|
| 96 |
|
---|
| 97 | pvdQMemory[msgIndex].hwnd = hwnd;
|
---|
| 98 | pvdQMemory[msgIndex].Msg = Msg;
|
---|
| 99 | pvdQMemory[msgIndex].wParam = wParam;
|
---|
| 100 | pvdQMemory[msgIndex].lParam = lParam;
|
---|
| 101 |
|
---|
| 102 | if ((rc = DosWriteQueue(hqQueue,
|
---|
| 103 | Q_SPYMSG_WNDMSG,
|
---|
| 104 | sizeof(Q_SPYMSG),
|
---|
| 105 | &pvdQMemory[msgIndex],
|
---|
| 106 | 0)) != 0)
|
---|
| 107 | {
|
---|
| 108 | hqQueue = 0; //give up, server probably died
|
---|
| 109 | dprintf(("PostSpyMessage: DosWriteQueue returned %d", rc));
|
---|
| 110 | return FALSE;
|
---|
| 111 | }
|
---|
| 112 | if(++msgIndex >= MAX_MESSAGES)
|
---|
| 113 | {
|
---|
| 114 | msgIndex = 0;
|
---|
| 115 | }
|
---|
| 116 | return TRUE;
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | #endif
|
---|