|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include <stdio.h> |
|
22 #include <rpc/rpc.h> |
|
23 #ifdef WIN32 |
|
24 #include <rpc/PMAP_CLN.H> |
|
25 #else |
|
26 #include <rpc/pmap_clnt.h> |
|
27 #endif |
|
28 #include "mobster.h" |
|
29 |
|
30 static void mobster_1(); |
|
31 |
|
32 int main( void ) |
|
33 { |
|
34 SVCXPRT *transp; |
|
35 |
|
36 #ifdef WIN32 |
|
37 rpc_nt_init(); |
|
38 #endif |
|
39 |
|
40 (void)pmap_unset(MOBSTER, MOBSTER_VERSION); |
|
41 |
|
42 transp = svcudp_create(RPC_ANYSOCK); |
|
43 if (transp == NULL) { |
|
44 (void)fprintf(stderr, "cannot create udp service.\n"); |
|
45 #ifdef WIN32 |
|
46 rpc_nt_exit(); |
|
47 #endif |
|
48 exit(1); |
|
49 } |
|
50 if (!svc_register(transp, MOBSTER, MOBSTER_VERSION, mobster_1, IPPROTO_UDP)) { |
|
51 (void)fprintf(stderr, "unable to register (MOBSTER, MOBSTER_VERSION, udp).\n"); |
|
52 #ifdef WIN32 |
|
53 rpc_nt_exit(); |
|
54 #endif |
|
55 exit(1); |
|
56 } |
|
57 |
|
58 transp = svctcp_create(RPC_ANYSOCK, 0, 0); |
|
59 if (transp == NULL) { |
|
60 (void)fprintf(stderr, "cannot create tcp service.\n"); |
|
61 #ifdef WIN32 |
|
62 rpc_nt_exit(); |
|
63 #endif |
|
64 exit(1); |
|
65 } |
|
66 if (!svc_register(transp, MOBSTER, MOBSTER_VERSION, mobster_1, IPPROTO_TCP)) { |
|
67 (void)fprintf(stderr, "unable to register (MOBSTER, MOBSTER_VERSION, tcp).\n"); |
|
68 #ifdef WIN32 |
|
69 rpc_nt_exit(); |
|
70 #endif |
|
71 exit(1); |
|
72 } |
|
73 svc_run(); |
|
74 (void)fprintf(stderr, "svc_run returned\n"); |
|
75 #ifdef WIN32 |
|
76 rpc_nt_exit(); |
|
77 #endif |
|
78 exit(1); |
|
79 } |
|
80 |
|
81 #ifdef MULTITHREAD |
|
82 struct call_params { |
|
83 struct svc_req *rqstp; |
|
84 SVCXPRT *transp; |
|
85 void *arg; |
|
86 char *(*local)(); |
|
87 bool_t (*xdr_argument)(), (*xdr_result)(); |
|
88 }; |
|
89 static void mobster_1_a (); |
|
90 #endif |
|
91 |
|
92 static void |
|
93 mobster_1(rqstp, transp) |
|
94 struct svc_req *rqstp; |
|
95 SVCXPRT *transp; |
|
96 { |
|
97 union { |
|
98 struct TChannelAddress ss_startuprpcservice_1_arg; |
|
99 int sc_shutdownrpcservice_1_arg; |
|
100 TDeviceDesc cstr_startdevice_1_arg; |
|
101 int dstr_removedevice_1_arg; |
|
102 int getdeviceinfo_1_arg; |
|
103 int getdevicelog_1_arg; |
|
104 int stopdevice_1_arg; |
|
105 struct TUUAddress setremoteuuaddress_1_arg; |
|
106 } argument; |
|
107 char *result; |
|
108 bool_t (*xdr_argument)(), (*xdr_result)(); |
|
109 char *(*local)(); |
|
110 |
|
111 |
|
112 #ifdef MULTITHREAD |
|
113 DWORD TID = 0; |
|
114 HANDLE threadHandle = NULL; |
|
115 struct call_params *params; |
|
116 #endif |
|
117 switch (rqstp->rq_proc) { |
|
118 case NULLPROC: |
|
119 (void)svc_sendreply(transp, (void*)xdr_void, (char *)NULL); |
|
120 return; |
|
121 |
|
122 case SS_STARTUPRPCSERVICE: |
|
123 xdr_argument = xdr_mobster_TChannelAddress; |
|
124 xdr_result = xdr_int; |
|
125 local = (char *(*)()) ss_startuprpcservice_1; |
|
126 break; |
|
127 |
|
128 case SC_SHUTDOWNRPCSERVICE: |
|
129 xdr_argument = xdr_int; |
|
130 xdr_result = xdr_int; |
|
131 local = (char *(*)()) sc_shutdownrpcservice_1; |
|
132 break; |
|
133 |
|
134 case LIST_DEVICES: |
|
135 xdr_argument = xdr_void; |
|
136 xdr_result = xdr_mobster_TComponentList; |
|
137 local = (char *(*)()) list_devices_1; |
|
138 break; |
|
139 |
|
140 case CSTR_STARTDEVICE: |
|
141 xdr_argument = xdr_mobster_TDeviceDesc; |
|
142 xdr_result = xdr_int; |
|
143 local = (char *(*)()) cstr_startdevice_1; |
|
144 break; |
|
145 |
|
146 case DSTR_REMOVEDEVICE: |
|
147 xdr_argument = xdr_int; |
|
148 xdr_result = xdr_int; |
|
149 local = (char *(*)()) dstr_removedevice_1; |
|
150 break; |
|
151 |
|
152 case GETDEVICEINFO: |
|
153 xdr_argument = xdr_int; |
|
154 xdr_result = xdr_mobster_TDeviceDesc; |
|
155 local = (char *(*)()) getdeviceinfo_1; |
|
156 break; |
|
157 |
|
158 case GETDEVICELOG: |
|
159 xdr_argument = xdr_int; |
|
160 xdr_result = xdr_mobster_TVarData; |
|
161 local = (char *(*)()) getdevicelog_1; |
|
162 break; |
|
163 |
|
164 case STOPDEVICE: |
|
165 xdr_argument = xdr_int; |
|
166 xdr_result = xdr_int; |
|
167 local = (char *(*)()) stopdevice_1; |
|
168 break; |
|
169 |
|
170 case SETREMOTEUUADDRESS: |
|
171 xdr_argument = xdr_mobster_TUUAddress; |
|
172 xdr_result = xdr_int; |
|
173 local = (char *(*)()) setremoteuuaddress_1; |
|
174 break; |
|
175 |
|
176 default: |
|
177 svcerr_noproc(transp); |
|
178 return; |
|
179 } |
|
180 bzero((char *)&argument, sizeof(argument)); |
|
181 if (!svc_getargs(transp, (void*)xdr_argument, (void*)&argument)) { |
|
182 svcerr_decode(transp); |
|
183 return; |
|
184 } |
|
185 |
|
186 #ifdef MULTITHREAD |
|
187 params = (struct call_params*) malloc (sizeof(struct call_params)); |
|
188 |
|
189 params->rqstp = (struct svc_req*) malloc (sizeof(struct svc_req)); |
|
190 bcopy(rqstp, params->rqstp, sizeof(struct svc_req)); |
|
191 |
|
192 params->transp = transp; |
|
193 |
|
194 params->arg = malloc (sizeof(argument)); |
|
195 bcopy(&argument, params->arg, sizeof(argument)); |
|
196 |
|
197 params->local = local; |
|
198 |
|
199 params->xdr_argument = xdr_argument; |
|
200 params->xdr_result = xdr_result; |
|
201 |
|
202 threadHandle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)mobster_1_a, params, 0, &TID); |
|
203 if (!threadHandle) |
|
204 mobster_1_a(¶ms); |
|
205 } |
|
206 |
|
207 static void |
|
208 mobster_1_a(params) |
|
209 struct call_params *params; |
|
210 { |
|
211 struct svc_req *rqstp; |
|
212 SVCXPRT *transp; |
|
213 void *argument; |
|
214 void (*destroy_proc)(); |
|
215 |
|
216 char *result; |
|
217 bool_t (*xdr_argument)(), (*xdr_result)(); |
|
218 char *(*local)(); |
|
219 |
|
220 |
|
221 argument = params->arg; |
|
222 rqstp = params->rqstp; |
|
223 transp = params->transp; |
|
224 xdr_argument = params->xdr_argument; |
|
225 xdr_result = params->xdr_result; |
|
226 local = params->local; |
|
227 destroy_proc = transp->xp_ops->xp_destroy; |
|
228 transp->xp_ops->xp_destroy = xprt_unregister; |
|
229 #endif |
|
230 |
|
231 result = (*local)(&argument, rqstp); |
|
232 if (result != NULL && !svc_sendreply(transp, (void*)xdr_result, result)) { |
|
233 svcerr_systemerr(transp); |
|
234 } |
|
235 #ifdef MULTITHREAD |
|
236 free(params->rqstp); |
|
237 free(params); |
|
238 #endif |
|
239 if (!svc_freeargs(transp, (void*)xdr_argument, (void*)&argument)) { |
|
240 (void)fprintf(stderr, "unable to free arguments\n"); |
|
241 #ifdef WIN32 |
|
242 rpc_nt_exit(); |
|
243 #endif |
|
244 exit(1); |
|
245 } |
|
246 #ifdef MULTITHREAD |
|
247 free(argument); |
|
248 transp->xp_ops->xp_destroy = destroy_proc; |
|
249 #endif |
|
250 } |
|
251 |