testexecmgmt/ucc/Source/pppcontroller/CSvcPppcontroller.cpp
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 * This file was autogenerated by rpcgen, but should be modified by the developer.
       
    16 * Make sure you don't use the -component_mod flag in future or this file will be overwritten.
       
    17 * Fri Oct 17 09:37:11 2003
       
    18 * System Includes
       
    19 *
       
    20 */
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 #include <stdio.h>
       
    26 #include <signal.h>
       
    27 
       
    28 
       
    29 /****************************************************************************************
       
    30  * 
       
    31  * Local Includes
       
    32  * 
       
    33  ***************************************************************************************/
       
    34 #include "CSvcPppcontroller.h"
       
    35 #include "pppcontroller.h"
       
    36 #include "../include/standard_unix.h"
       
    37 #include "../include/standard_service_manager.h"
       
    38 
       
    39 
       
    40 /****************************************************************************************
       
    41  * 
       
    42  * File-scope variables
       
    43  * 
       
    44  ***************************************************************************************/
       
    45 static CComponentManager<CSPppcontroller> *iComponentManager;
       
    46 static pid_t iServerProcess;
       
    47 
       
    48 
       
    49 /*******************************************************************************
       
    50  *
       
    51  * SIGNAL HANDLER - SIGTERM: We need pppd to start in our process group so that
       
    52  * we can send signals to it (to stop it). The problem is that when you try
       
    53  * and kill pppd it sends a term signal to everyone in it's process group. So,
       
    54  * we should just ignore SIGTERM and if anyone wants to kill us manually they
       
    55  * can use SIGINT (or SIGKILL in times of need). The problem with this is that
       
    56  * when we fork processes, but before we exec pppd, the child is also ignoring
       
    57  * SIGTERM and if we try and kill it before it is exec'd then it won't die 
       
    58  * and we wait on the pid forever. We could make wait more intelligent
       
    59  * (i.e. timeout and resend the signal) but that is not so nice as waitpid
       
    60  * doesn't have a timeout -- means we have to use WNOHANG and poll every
       
    61  * X seconds which isn't gret. Instead we record the pid of the main process
       
    62  * and check this in the signal handler. If it matches then the signal is
       
    63  * ignored -- otherwise the process is terminated.
       
    64  *
       
    65  ******************************************************************************/
       
    66 void handle_sigterm( int sig )
       
    67 {
       
    68   pid_t pid, ppid;
       
    69   pid = getpid();
       
    70   if( pid == iServerProcess ) {
       
    71     return;
       
    72   } 
       
    73   ppid = getppid();
       
    74   fprintf( stderr, "INFO: SIGTERM received before exec (pid = %d, ppid = %d).\n", pid, ppid );
       
    75   exit( -1 );
       
    76 }
       
    77 
       
    78 
       
    79 /****************************************************************************************
       
    80  * 
       
    81  * Implementation
       
    82  * 
       
    83  ***************************************************************************************/
       
    84 
       
    85 
       
    86 /****************************************************************************************
       
    87  * 
       
    88  * PUBLIC: GetInstanceKeyFromArgs
       
    89  * 
       
    90  ***************************************************************************************/
       
    91 int CSvcPppcontroller::GetInstanceKeyFromArgs( int aMethod, void *aArgs )
       
    92 {
       
    93 	int rv;
       
    94 	int *ik_integer;
       
    95 	switch( aMethod ) {
       
    96 
       
    97 	// integer instance keys
       
    98 	case DSTR_REMOVEPPPSESSION:
       
    99 	case KILLSESSION:
       
   100 	case STOPSESSION:
       
   101 	case GETSESSIONINFO:
       
   102 	case GETPPPLOG:
       
   103 		ik_integer = (int*)aArgs;
       
   104 		rv = *ik_integer;
       
   105 		break;
       
   106 
       
   107 	// error
       
   108 	default:
       
   109 		rv = ERR_INVALID_METHOD;
       
   110 		break;
       
   111 	}
       
   112 	return rv;
       
   113 }
       
   114 
       
   115 
       
   116 /****************************************************************************************
       
   117  * 
       
   118  * PUBLIC: SetError
       
   119  * 
       
   120  ***************************************************************************************/
       
   121 int CSvcPppcontroller::SetError( int aMethod, void *aArgs, int aError )
       
   122 {
       
   123 	int rv = ERR_NONE;
       
   124 	TResult *rv_result;
       
   125 	TComponentList *rv_component_list;
       
   126 	TPppSessionDesc *rv_session_desc;
       
   127 	TVarData *rv_var_data;
       
   128 
       
   129 	switch( aMethod ) {
       
   130 
       
   131 	// TComponentList
       
   132 	case LIST_DEVICES:
       
   133 		SET_LIST_ERROR_CODE( TComponentList, rv_component_list );
       
   134 		break;
       
   135 
       
   136 	// TPppSessionDesc
       
   137 	case GETSESSIONINFO:
       
   138 		SET_ERROR_CODE( TPppSessionDesc, iErrorCode, rv_session_desc );
       
   139 		break;
       
   140 
       
   141 	// TVarData
       
   142 	case GETPPPLOG:
       
   143 		SET_LIST_ERROR_CODE( TVarData, rv_var_data );
       
   144 		break;
       
   145 
       
   146 	// TResult return
       
   147 	case CSTR_STARTPPPSESSION:
       
   148 	case DSTR_REMOVEPPPSESSION:
       
   149 	case KILLSESSION:
       
   150 	case STOPSESSION:
       
   151 		SET_ERROR_CODE( TResult, iStandardResult, rv_result );
       
   152 		break;
       
   153 
       
   154 	// Error
       
   155 	default:
       
   156 		rv = ERR_INVALID_METHOD;
       
   157 		break;
       
   158 	}
       
   159 	return rv;
       
   160 }
       
   161 
       
   162 
       
   163 /****************************************************************************************
       
   164  * 
       
   165  * PUBLIC: GetError
       
   166  * 
       
   167  ***************************************************************************************/
       
   168 int CSvcPppcontroller::GetError( int aMethod, void *aArgs )
       
   169 {
       
   170   TResult *result;
       
   171   
       
   172   // check assumption
       
   173   assert( (aMethod == CSTR_STARTPPPSESSION) || (aMethod == DSTR_REMOVEPPPSESSION) );
       
   174   
       
   175   // return error code
       
   176   result = (TResult*)aArgs;
       
   177   return result->iStandardResult;
       
   178 }
       
   179 
       
   180 
       
   181 /****************************************************************************************
       
   182  * 
       
   183  * PUBLIC: StartRPCService
       
   184  * 
       
   185  ***************************************************************************************/
       
   186 int CSvcPppcontroller::StartRPCService( CComponentManager<CSPppcontroller> *aComponentManager, TStartupInfo *aArg )
       
   187 {	
       
   188 	sighandler_t oh;
       
   189 
       
   190 	// get the server process's ID for the signal handler
       
   191 	iServerProcess = getpid();
       
   192 
       
   193 	// register the sigterm handler
       
   194 	oh = signal( SIGTERM, handle_sigterm );
       
   195 	if( oh == SIG_ERR ) {
       
   196 		return ERR_SET_SIGNAL_ERROR;
       
   197 	}
       
   198 
       
   199 	// setup the component manager
       
   200 	assert( iComponentManager == NULL );
       
   201 	iComponentManager = aComponentManager;
       
   202 	return ERR_NONE;
       
   203 }
       
   204 
       
   205 
       
   206 /****************************************************************************************
       
   207  * 
       
   208  * PUBLIC: StopRPCService
       
   209  * 
       
   210  ***************************************************************************************/
       
   211 int CSvcPppcontroller::StopRPCService()
       
   212 {
       
   213 	iComponentManager = NULL;
       
   214 	return ERR_NONE;
       
   215 }