testexecmgmt/ucc/Source/HostExecuteAsync/hostexecuteasync_svc.c
changeset 0 3da2a79470a7
equal deleted inserted replaced
-1:000000000000 0:3da2a79470a7
       
     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 "hostexecuteasync.h"
       
    29 
       
    30 static void hostexecuteasync_9();
       
    31 
       
    32 int main( void )
       
    33 {
       
    34 	SVCXPRT *transp;
       
    35 
       
    36 	(void)pmap_unset(HOSTEXECUTEASYNC, HOSTEXECUTEASYNC_VERSION);
       
    37 
       
    38 	transp = svcudp_create(RPC_ANYSOCK);
       
    39 	if (transp == NULL) {
       
    40 		(void)fprintf(stderr, "cannot create udp service.\n");
       
    41 		exit(1);
       
    42 	}
       
    43 	if (!svc_register(transp, HOSTEXECUTEASYNC, HOSTEXECUTEASYNC_VERSION, hostexecuteasync_9, IPPROTO_UDP)) {
       
    44 		(void)fprintf(stderr, "unable to register (HOSTEXECUTEASYNC, HOSTEXECUTEASYNC_VERSION, udp).\n");
       
    45 		exit(1);
       
    46 	}
       
    47 
       
    48 	transp = svctcp_create(RPC_ANYSOCK, 0, 0);
       
    49 	if (transp == NULL) {
       
    50 		(void)fprintf(stderr, "cannot create tcp service.\n");
       
    51 		exit(1);
       
    52 	}
       
    53 	if (!svc_register(transp, HOSTEXECUTEASYNC, HOSTEXECUTEASYNC_VERSION, hostexecuteasync_9, IPPROTO_TCP)) {
       
    54 		(void)fprintf(stderr, "unable to register (HOSTEXECUTEASYNC, HOSTEXECUTEASYNC_VERSION, tcp).\n");
       
    55 		exit(1);
       
    56 	}
       
    57 	svc_run();
       
    58 	(void)fprintf(stderr, "svc_run returned\n");
       
    59 	exit(1);
       
    60 }
       
    61 
       
    62 static void
       
    63 hostexecuteasync_9(rqstp, transp)
       
    64 	struct svc_req *rqstp;
       
    65 	SVCXPRT *transp;
       
    66 {
       
    67 	union {
       
    68 		TStartupInfo ss_startuprpcservice_9_arg;
       
    69 		int sc_shutdownrpcservice_9_arg;
       
    70 		char *cstr_startprocess_9_arg;
       
    71 		int dstr_removeprocess_9_arg;
       
    72 		int killprocess_9_arg;
       
    73 		int stopprocess_9_arg;
       
    74 		int getprocessinfo_9_arg;
       
    75 		int getstandardoutput_9_arg;
       
    76 		int getstandarderror_9_arg;
       
    77 	} argument;
       
    78 	char *result;
       
    79 	bool_t (*xdr_argument)(), (*xdr_result)();
       
    80 	char *(*local)();
       
    81 
       
    82 	switch (rqstp->rq_proc) {
       
    83 	case NULLPROC:
       
    84 		(void)svc_sendreply(transp, (void*)xdr_void, (char *)NULL);
       
    85 		return;
       
    86 
       
    87 	case SS_STARTUPRPCSERVICE:
       
    88 		xdr_argument = xdr_hostexecuteasync_TStartupInfo;
       
    89 		xdr_result = xdr_int;
       
    90 		local = (char *(*)()) ss_startuprpcservice_9;
       
    91 		break;
       
    92 
       
    93 	case SC_SHUTDOWNRPCSERVICE:
       
    94 		xdr_argument = xdr_int;
       
    95 		xdr_result = xdr_int;
       
    96 		local = (char *(*)()) sc_shutdownrpcservice_9;
       
    97 		break;
       
    98 
       
    99 	case LIST_DEVICES:
       
   100 		xdr_argument = xdr_void;
       
   101 		xdr_result = xdr_hostexecuteasync_TComponentList;
       
   102 		local = (char *(*)()) list_devices_9;
       
   103 		break;
       
   104 
       
   105 	case CSTR_STARTPROCESS:
       
   106 		xdr_argument = xdr_wrapstring;
       
   107 		xdr_result = xdr_hostexecuteasync_TResult;
       
   108 		local = (char *(*)()) cstr_startprocess_9;
       
   109 		break;
       
   110 
       
   111 	case DSTR_REMOVEPROCESS:
       
   112 		xdr_argument = xdr_int;
       
   113 		xdr_result = xdr_hostexecuteasync_TResult;
       
   114 		local = (char *(*)()) dstr_removeprocess_9;
       
   115 		break;
       
   116 
       
   117 	case KILLPROCESS:
       
   118 		xdr_argument = xdr_int;
       
   119 		xdr_result = xdr_hostexecuteasync_TResult;
       
   120 		local = (char *(*)()) killprocess_9;
       
   121 		break;
       
   122 
       
   123 	case STOPPROCESS:
       
   124 		xdr_argument = xdr_int;
       
   125 		xdr_result = xdr_hostexecuteasync_TResult;
       
   126 		local = (char *(*)()) stopprocess_9;
       
   127 		break;
       
   128 
       
   129 	case GETPROCESSINFO:
       
   130 		xdr_argument = xdr_int;
       
   131 		xdr_result = xdr_hostexecuteasync_THostExecuteAsyncProcessInfo;
       
   132 		local = (char *(*)()) getprocessinfo_9;
       
   133 		break;
       
   134 
       
   135 	case GETSTANDARDOUTPUT:
       
   136 		xdr_argument = xdr_int;
       
   137 		xdr_result = xdr_hostexecuteasync_TVarData;
       
   138 		local = (char *(*)()) getstandardoutput_9;
       
   139 		break;
       
   140 
       
   141 	case GETSTANDARDERROR:
       
   142 		xdr_argument = xdr_int;
       
   143 		xdr_result = xdr_hostexecuteasync_TVarData;
       
   144 		local = (char *(*)()) getstandarderror_9;
       
   145 		break;
       
   146 
       
   147 	default:
       
   148 		svcerr_noproc(transp);
       
   149 		return;
       
   150 	}
       
   151 	bzero((char *)&argument, sizeof(argument));
       
   152 	if (!svc_getargs(transp, (void*)xdr_argument, (void*)&argument)) {
       
   153 		svcerr_decode(transp);
       
   154 		return;
       
   155 	}
       
   156 	result = (*local)(&argument, rqstp);
       
   157 	if (result != NULL && !svc_sendreply(transp, (void*)xdr_result, result)) {
       
   158 		svcerr_systemerr(transp);
       
   159 	}
       
   160 	if (!svc_freeargs(transp, (void*)xdr_argument, (void*)&argument)) {
       
   161 		(void)fprintf(stderr, "unable to free arguments\n");
       
   162 		exit(1);
       
   163 	}
       
   164 }
       
   165