1 | /* $Id: spy.cpp,v 1.10 2000-02-16 14:34:33 sandervl Exp $ */
|
---|
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 | */
|
---|
12 | #define INCL_DOSPROCESS
|
---|
13 | #define INCL_DOSQUEUES
|
---|
14 | #define INCL_DOSMEMMGR
|
---|
15 | #define INCL_WINMESSAGEMGR
|
---|
16 | #define INCL_DOSERRORS
|
---|
17 | #define INCL_DOSSEMAPHORES
|
---|
18 | #include <os2.h>
|
---|
19 | #include <os2wrap.h>
|
---|
20 |
|
---|
21 | #include <stdlib.h>
|
---|
22 | #include <stddef.h>
|
---|
23 | #include <string.h>
|
---|
24 | #include <misc.h>
|
---|
25 | #include <spy.h>
|
---|
26 |
|
---|
27 | #define DBG_LOCALLOG DBG_spy
|
---|
28 | #include "dbglocal.h"
|
---|
29 |
|
---|
30 | #define Q_BUFFER_SIZE 4096
|
---|
31 | #define MAX_MESSAGES (Q_BUFFER_SIZE/sizeof(Q_SPYMSG))
|
---|
32 |
|
---|
33 | PID pidServer = 0;
|
---|
34 | HQUEUE hqQueue = 0;
|
---|
35 | Q_SPYMSG *pvdQMemory = 0;
|
---|
36 | int msgIndex = 0;
|
---|
37 |
|
---|
38 | BOOL InitSpyQueue()
|
---|
39 | {
|
---|
40 | APIRET rc;
|
---|
41 |
|
---|
42 | if ((rc = DosOpenQueue(&pidServer, &hqQueue, "\\queues\\"Q_NAME)) != 0)
|
---|
43 | {
|
---|
44 | dprintf(("InitSpyQueue: couldn't open spy queue rc=%d!", rc));
|
---|
45 | return FALSE;
|
---|
46 | }
|
---|
47 | if ((rc = DosAllocSharedMem((VOID **)&pvdQMemory,
|
---|
48 | NULL,
|
---|
49 | Q_BUFFER_SIZE,
|
---|
50 | fALLOCSHR)) != 0)
|
---|
51 | {
|
---|
52 | dprintf(("InitSpyQueue: DosAllocSharedMem failed rc=%d", rc));
|
---|
53 | DosCloseQueue(hqQueue);
|
---|
54 | return FALSE;
|
---|
55 | }
|
---|
56 |
|
---|
57 | /* give memory to server */
|
---|
58 | if (DosGiveSharedMem(pvdQMemory, pidServer, PAG_READ | PAG_WRITE))
|
---|
59 | {
|
---|
60 | dprintf(("InitSpyQueue: DosGiveSharedMem failed"));
|
---|
61 | DosCloseQueue(hqQueue);
|
---|
62 | return FALSE;
|
---|
63 | }
|
---|
64 | return (TRUE);
|
---|
65 | }
|
---|
66 |
|
---|
67 | void CloseSpyQueue()
|
---|
68 | {
|
---|
69 | APIRET rc;
|
---|
70 |
|
---|
71 | dprintf(("CloseSpyQueue"));
|
---|
72 | if(hqQueue) {
|
---|
73 | if(pvdQMemory) {
|
---|
74 | rc = DosWriteQueue(hqQueue, Q_SPYMSG_KILLSERVER, 0, 0, 0);
|
---|
75 | if(rc) {
|
---|
76 | dprintf(("CloseSpyQueue: DosWriteQueue returned %d", rc));
|
---|
77 | }
|
---|
78 | }
|
---|
79 | DosCloseQueue(hqQueue);
|
---|
80 | }
|
---|
81 | if(pvdQMemory)
|
---|
82 | DosFreeMem(pvdQMemory);
|
---|
83 | }
|
---|
84 |
|
---|
85 | #ifdef DEBUG
|
---|
86 | BOOL PostSpyMessage(HWND hwnd, ULONG Msg, ULONG wParam, ULONG lParam)
|
---|
87 | {
|
---|
88 | APIRET rc;
|
---|
89 |
|
---|
90 | if (hqQueue == 0)
|
---|
91 | return FALSE;
|
---|
92 |
|
---|
93 | pvdQMemory[msgIndex].hwnd = hwnd;
|
---|
94 | pvdQMemory[msgIndex].Msg = Msg;
|
---|
95 | pvdQMemory[msgIndex].wParam = wParam;
|
---|
96 | pvdQMemory[msgIndex].lParam = lParam;
|
---|
97 |
|
---|
98 | if ((rc = DosWriteQueue(hqQueue,
|
---|
99 | Q_SPYMSG_WNDMSG,
|
---|
100 | sizeof(Q_SPYMSG),
|
---|
101 | &pvdQMemory[msgIndex],
|
---|
102 | 0)) != 0)
|
---|
103 | {
|
---|
104 | hqQueue = 0; //give up, server probably died
|
---|
105 | dprintf(("PostSpyMessage: DosWriteQueue returned %d", rc));
|
---|
106 | return FALSE;
|
---|
107 | }
|
---|
108 | if(++msgIndex >= MAX_MESSAGES)
|
---|
109 | {
|
---|
110 | msgIndex = 0;
|
---|
111 | }
|
---|
112 | return TRUE;
|
---|
113 | }
|
---|
114 |
|
---|
115 | #endif
|
---|