1
|
1 |
/*
|
|
2 |
* Copyright 2000-2001 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*
|
|
23 |
*/
|
|
24 |
|
|
25 |
#include <stdio.h>
|
|
26 |
#include <string.h>
|
|
27 |
#include "dispatcher.hpp"
|
|
28 |
|
|
29 |
const char* CMD_ASCII = "ascii";
|
|
30 |
const char* CMD_UNICODE = "unicode";
|
|
31 |
const char* CMD_PROCLIST = "proclist";
|
|
32 |
const char* CMD_ATTACH = "attach";
|
|
33 |
const char* CMD_DETACH = "detach";
|
|
34 |
const char* CMD_LIBINFO = "libinfo";
|
|
35 |
const char* CMD_PEEK = "peek";
|
|
36 |
const char* CMD_POKE = "poke";
|
|
37 |
const char* CMD_THREADLIST = "threadlist";
|
|
38 |
const char* CMD_DUPHANDLE = "duphandle";
|
|
39 |
const char* CMD_CLOSEHANDLE = "closehandle";
|
|
40 |
const char* CMD_GETCONTEXT = "getcontext";
|
|
41 |
const char* CMD_SETCONTEXT = "setcontext";
|
|
42 |
const char* CMD_SELECTORENTRY = "selectorentry";
|
|
43 |
const char* CMD_SUSPEND = "suspend";
|
|
44 |
const char* CMD_RESUME = "resume";
|
|
45 |
const char* CMD_POLLEVENT = "pollevent";
|
|
46 |
const char* CMD_CONTINUEEVENT = "continueevent";
|
|
47 |
const char* CMD_EXIT = "exit";
|
|
48 |
|
|
49 |
// Uncomment the #define below to get messages on stderr
|
|
50 |
// #define DEBUGGING
|
|
51 |
|
|
52 |
void
|
|
53 |
Dispatcher::dispatch(char* cmd, Handler* handler) {
|
|
54 |
if (!strncmp(cmd, CMD_ASCII, strlen(CMD_ASCII))) {
|
|
55 |
handler->ascii(cmd + strlen(CMD_ASCII));
|
|
56 |
|
|
57 |
} else if (!strncmp(cmd, CMD_UNICODE, strlen(CMD_UNICODE))) {
|
|
58 |
handler->unicode(cmd + strlen(CMD_UNICODE));
|
|
59 |
|
|
60 |
} else if (!strncmp(cmd, CMD_PROCLIST, strlen(CMD_PROCLIST))) {
|
|
61 |
handler->procList(cmd + strlen(CMD_PROCLIST));
|
|
62 |
|
|
63 |
} else if (!strncmp(cmd, CMD_ATTACH, strlen(CMD_ATTACH))) {
|
|
64 |
handler->attach(cmd + strlen(CMD_ATTACH));
|
|
65 |
|
|
66 |
} else if (!strncmp(cmd, CMD_DETACH, strlen(CMD_DETACH))) {
|
|
67 |
handler->detach(cmd + strlen(CMD_DETACH));
|
|
68 |
|
|
69 |
} else if (!strncmp(cmd, CMD_LIBINFO, strlen(CMD_LIBINFO))) {
|
|
70 |
handler->libInfo(cmd + strlen(CMD_LIBINFO));
|
|
71 |
|
|
72 |
} else if (!strncmp(cmd, CMD_PEEK, strlen(CMD_PEEK))) {
|
|
73 |
handler->peek(cmd + strlen(CMD_PEEK));
|
|
74 |
|
|
75 |
} else if (!strncmp(cmd, CMD_POKE, strlen(CMD_POKE))) {
|
|
76 |
handler->poke(cmd + strlen(CMD_POKE));
|
|
77 |
|
|
78 |
} else if (!strncmp(cmd, CMD_THREADLIST, strlen(CMD_THREADLIST))) {
|
|
79 |
handler->threadList(cmd + strlen(CMD_THREADLIST));
|
|
80 |
|
|
81 |
} else if (!strncmp(cmd, CMD_DUPHANDLE, strlen(CMD_DUPHANDLE))) {
|
|
82 |
handler->dupHandle(cmd + strlen(CMD_DUPHANDLE));
|
|
83 |
|
|
84 |
} else if (!strncmp(cmd, CMD_CLOSEHANDLE, strlen(CMD_CLOSEHANDLE))) {
|
|
85 |
handler->closeHandle(cmd + strlen(CMD_CLOSEHANDLE));
|
|
86 |
|
|
87 |
} else if (!strncmp(cmd, CMD_GETCONTEXT, strlen(CMD_GETCONTEXT))) {
|
|
88 |
handler->getContext(cmd + strlen(CMD_GETCONTEXT));
|
|
89 |
|
|
90 |
} else if (!strncmp(cmd, CMD_SETCONTEXT, strlen(CMD_SETCONTEXT))) {
|
|
91 |
handler->setContext(cmd + strlen(CMD_SETCONTEXT));
|
|
92 |
|
|
93 |
} else if (!strncmp(cmd, CMD_SELECTORENTRY, strlen(CMD_SELECTORENTRY))) {
|
|
94 |
handler->selectorEntry(cmd + strlen(CMD_SELECTORENTRY));
|
|
95 |
|
|
96 |
} else if (!strncmp(cmd, CMD_SUSPEND, strlen(CMD_SUSPEND))) {
|
|
97 |
handler->suspend(cmd + strlen(CMD_SUSPEND));
|
|
98 |
|
|
99 |
} else if (!strncmp(cmd, CMD_RESUME, strlen(CMD_RESUME))) {
|
|
100 |
handler->resume(cmd + strlen(CMD_RESUME));
|
|
101 |
|
|
102 |
} else if (!strncmp(cmd, CMD_POLLEVENT, strlen(CMD_POLLEVENT))) {
|
|
103 |
handler->pollEvent(cmd + strlen(CMD_POLLEVENT));
|
|
104 |
|
|
105 |
} else if (!strncmp(cmd, CMD_CONTINUEEVENT, strlen(CMD_CONTINUEEVENT))) {
|
|
106 |
handler->continueEvent(cmd + strlen(CMD_CONTINUEEVENT));
|
|
107 |
|
|
108 |
} else if (!strcmp(cmd, CMD_EXIT)) {
|
|
109 |
handler->exit(cmd + strlen(CMD_EXIT));
|
|
110 |
}
|
|
111 |
|
|
112 |
#ifdef DEBUGGING
|
|
113 |
else fprintf(stderr, "Ignoring illegal command \"%s\"\n", cmd);
|
|
114 |
#endif
|
|
115 |
}
|