testexecmgmt/ucc/Source/HostExecuteSimple/hostexecute_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 "hostexecute.h"
       
    29 
       
    30 static void hostexecute_3();
       
    31 
       
    32 int main( void )
       
    33 {
       
    34 	SVCXPRT *transp;
       
    35 
       
    36 	(void)pmap_unset(HOSTEXECUTE, HOSTEXECUTE_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, HOSTEXECUTE, HOSTEXECUTE_VERSION, hostexecute_3, IPPROTO_UDP)) {
       
    44 		(void)fprintf(stderr, "unable to register (HOSTEXECUTE, HOSTEXECUTE_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, HOSTEXECUTE, HOSTEXECUTE_VERSION, hostexecute_3, IPPROTO_TCP)) {
       
    54 		(void)fprintf(stderr, "unable to register (HOSTEXECUTE, HOSTEXECUTE_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 hostexecute_3(rqstp, transp)
       
    64 	struct svc_req *rqstp;
       
    65 	SVCXPRT *transp;
       
    66 {
       
    67 	union {
       
    68 		TStartupInfo ss_startuprpcservice_3_arg;
       
    69 		int sc_shutdownrpcservice_3_arg;
       
    70 		TExecuteRequest st_executecommand_3_arg;
       
    71 	} argument;
       
    72 	char *result;
       
    73 	bool_t (*xdr_argument)(), (*xdr_result)();
       
    74 	char *(*local)();
       
    75 
       
    76 	switch (rqstp->rq_proc) {
       
    77 	case NULLPROC:
       
    78 		(void)svc_sendreply(transp, (void*)xdr_void, (char *)NULL);
       
    79 		return;
       
    80 
       
    81 	case SS_STARTUPRPCSERVICE:
       
    82 		xdr_argument = xdr_hostexecute_TStartupInfo;
       
    83 		xdr_result = xdr_int;
       
    84 		local = (char *(*)()) ss_startuprpcservice_3;
       
    85 		break;
       
    86 
       
    87 	case SC_SHUTDOWNRPCSERVICE:
       
    88 		xdr_argument = xdr_int;
       
    89 		xdr_result = xdr_int;
       
    90 		local = (char *(*)()) sc_shutdownrpcservice_3;
       
    91 		break;
       
    92 
       
    93 	case LIST_DEVICES:
       
    94 		xdr_argument = xdr_void;
       
    95 		xdr_result = xdr_hostexecute_TComponentList;
       
    96 		local = (char *(*)()) list_devices_3;
       
    97 		break;
       
    98 
       
    99 	case ST_EXECUTECOMMAND:
       
   100 		xdr_argument = xdr_hostexecute_TExecuteRequest;
       
   101 		xdr_result = xdr_hostexecute_TExecuteResult;
       
   102 		local = (char *(*)()) st_executecommand_3;
       
   103 		break;
       
   104 
       
   105 	default:
       
   106 		svcerr_noproc(transp);
       
   107 		return;
       
   108 	}
       
   109 	bzero((char *)&argument, sizeof(argument));
       
   110 	if (!svc_getargs(transp, (void*)xdr_argument, (void*)&argument)) {
       
   111 		svcerr_decode(transp);
       
   112 		return;
       
   113 	}
       
   114 	result = (*local)(&argument, rqstp);
       
   115 	if (result != NULL && !svc_sendreply(transp, (void*)xdr_result, result)) {
       
   116 		svcerr_systemerr(transp);
       
   117 	}
       
   118 	if (!svc_freeargs(transp, (void*)xdr_argument, (void*)&argument)) {
       
   119 		(void)fprintf(stderr, "unable to free arguments\n");
       
   120 		exit(1);
       
   121 	}
       
   122 }
       
   123