1 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
2 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
3 | *
|
---|
4 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
5 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
6 | * the License. You may obtain a copy of the License at
|
---|
7 | * http://www.mozilla.org/MPL/
|
---|
8 | *
|
---|
9 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
11 | * for the specific language governing rights and limitations under the
|
---|
12 | * License.
|
---|
13 | *
|
---|
14 | * The Original Code is Mozilla IPC.
|
---|
15 | *
|
---|
16 | * The Initial Developer of the Original Code is
|
---|
17 | * Netscape Communications Corporation.
|
---|
18 | * Portions created by the Initial Developer are Copyright (C) 2002
|
---|
19 | * the Initial Developer. All Rights Reserved.
|
---|
20 | *
|
---|
21 | * Contributor(s):
|
---|
22 | * Darin Fisher <[email protected]>
|
---|
23 | *
|
---|
24 | * Alternatively, the contents of this file may be used under the terms of
|
---|
25 | * either the GNU General Public License Version 2 or later (the "GPL"), or
|
---|
26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
27 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
28 | * of those above. If you wish to allow use of your version of this file only
|
---|
29 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
30 | * use your version of this file under the terms of the MPL, indicate your
|
---|
31 | * decision by deleting the provisions above and replace them with the notice
|
---|
32 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
33 | * the provisions above, a recipient may use your version of this file under
|
---|
34 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
35 | *
|
---|
36 | * ***** END LICENSE BLOCK ***** */
|
---|
37 |
|
---|
38 | #ifndef ipcModuleUtil_h__
|
---|
39 | #define ipcModuleUtil_h__
|
---|
40 |
|
---|
41 | #include "prlog.h"
|
---|
42 | #include "ipcModule.h"
|
---|
43 |
|
---|
44 | extern const ipcDaemonMethods *gIPCDaemonMethods;
|
---|
45 |
|
---|
46 | //-----------------------------------------------------------------------------
|
---|
47 | // inline wrapper functions
|
---|
48 | //
|
---|
49 | // these functions may only be called by a module that uses the
|
---|
50 | // IPC_IMPL_GETMODULES macro.
|
---|
51 | //-----------------------------------------------------------------------------
|
---|
52 |
|
---|
53 | inline PRStatus
|
---|
54 | IPC_DispatchMsg(ipcClientHandle client, const nsID &target, const void *data, PRUint32 dataLen)
|
---|
55 | {
|
---|
56 | PR_ASSERT(gIPCDaemonMethods);
|
---|
57 | return gIPCDaemonMethods->dispatchMsg(client, target, data, dataLen);
|
---|
58 | }
|
---|
59 |
|
---|
60 | inline PRStatus
|
---|
61 | IPC_SendMsg(ipcClientHandle client, const nsID &target, const void *data, PRUint32 dataLen)
|
---|
62 | {
|
---|
63 | PR_ASSERT(gIPCDaemonMethods);
|
---|
64 | return gIPCDaemonMethods->sendMsg(client, target, data, dataLen);
|
---|
65 | }
|
---|
66 |
|
---|
67 | inline ipcClientHandle
|
---|
68 | IPC_GetClientByID(PRUint32 id)
|
---|
69 | {
|
---|
70 | PR_ASSERT(gIPCDaemonMethods);
|
---|
71 | return gIPCDaemonMethods->getClientByID(id);
|
---|
72 | }
|
---|
73 |
|
---|
74 | inline ipcClientHandle
|
---|
75 | IPC_GetClientByName(const char *name)
|
---|
76 | {
|
---|
77 | PR_ASSERT(gIPCDaemonMethods);
|
---|
78 | return gIPCDaemonMethods->getClientByName(name);
|
---|
79 | }
|
---|
80 |
|
---|
81 | inline void
|
---|
82 | IPC_EnumClients(ipcClientEnumFunc func, void *closure)
|
---|
83 | {
|
---|
84 | PR_ASSERT(gIPCDaemonMethods);
|
---|
85 | gIPCDaemonMethods->enumClients(func, closure);
|
---|
86 | }
|
---|
87 |
|
---|
88 | inline PRUint32
|
---|
89 | IPC_GetClientID(ipcClientHandle client)
|
---|
90 | {
|
---|
91 | PR_ASSERT(gIPCDaemonMethods);
|
---|
92 | return gIPCDaemonMethods->getClientID(client);
|
---|
93 | }
|
---|
94 |
|
---|
95 | inline PRBool
|
---|
96 | IPC_ClientHasName(ipcClientHandle client, const char *name)
|
---|
97 | {
|
---|
98 | PR_ASSERT(gIPCDaemonMethods);
|
---|
99 | return gIPCDaemonMethods->clientHasName(client, name);
|
---|
100 | }
|
---|
101 |
|
---|
102 | inline PRBool
|
---|
103 | IPC_ClientHasTarget(ipcClientHandle client, const nsID &target)
|
---|
104 | {
|
---|
105 | PR_ASSERT(gIPCDaemonMethods);
|
---|
106 | return gIPCDaemonMethods->clientHasTarget(client, target);
|
---|
107 | }
|
---|
108 |
|
---|
109 | inline void
|
---|
110 | IPC_EnumClientNames(ipcClientHandle client, ipcClientNameEnumFunc func, void *closure)
|
---|
111 | {
|
---|
112 | PR_ASSERT(gIPCDaemonMethods);
|
---|
113 | gIPCDaemonMethods->enumClientNames(client, func, closure);
|
---|
114 | }
|
---|
115 |
|
---|
116 | inline void
|
---|
117 | IPC_EnumClientTargets(ipcClientHandle client, ipcClientTargetEnumFunc func, void *closure)
|
---|
118 | {
|
---|
119 | PR_ASSERT(gIPCDaemonMethods);
|
---|
120 | gIPCDaemonMethods->enumClientTargets(client, func, closure);
|
---|
121 | }
|
---|
122 |
|
---|
123 | //-----------------------------------------------------------------------------
|
---|
124 | // inline composite functions
|
---|
125 | //-----------------------------------------------------------------------------
|
---|
126 |
|
---|
127 | inline PRStatus
|
---|
128 | IPC_SendMsg(PRUint32 clientID, const nsID &target, const void *data, PRUint32 dataLen)
|
---|
129 | {
|
---|
130 | ipcClient *client = IPC_GetClientByID(clientID);
|
---|
131 | if (!client)
|
---|
132 | return PR_FAILURE;
|
---|
133 | return IPC_SendMsg(client, target, data, dataLen);
|
---|
134 | }
|
---|
135 |
|
---|
136 | //-----------------------------------------------------------------------------
|
---|
137 | // module factory macros
|
---|
138 | //-----------------------------------------------------------------------------
|
---|
139 |
|
---|
140 | #define IPC_IMPL_GETMODULES(_modName, _modEntries) \
|
---|
141 | const ipcDaemonMethods *gIPCDaemonMethods; \
|
---|
142 | IPC_EXPORT int \
|
---|
143 | IPC_GetModules(const ipcDaemonMethods *dmeths, \
|
---|
144 | const ipcModuleEntry **ents) { \
|
---|
145 | /* XXX do version checking */ \
|
---|
146 | gIPCDaemonMethods = dmeths; \
|
---|
147 | *ents = _modEntries; \
|
---|
148 | return sizeof(_modEntries) / sizeof(ipcModuleEntry); \
|
---|
149 | }
|
---|
150 |
|
---|
151 | #endif // !ipcModuleUtil_h__
|
---|