@echo off
setlocal
rem ----------------------------------------------------------------------------- 
rem  Project :  PCO
rem  Modul   :  
rem ----------------------------------------------------------------------------- 
rem  Copyright 2004 Texas Instruments Deutschland GmbH 
rem                 All rights reserved. 
rem 
rem                 This file is confidential and a trade secret of Texas 
rem                 Instruments Berlin, AG 
rem                 The receipt of or possession of this file does not convey 
rem                 any rights to reproduce or disclose its contents or to 
rem                 manufacture, use, or sell anything it may describe, in 
rem                 whole, or in part, without the specific written consent of 
rem                 Texas Instruments Berlin, AG. 
rem ----------------------------------------------------------------------------- 
rem |  Purpose :  general depending application killer
rem ----------------------------------------------------------------------------- 

set PATH=%PATH%;..\tools\bin;..\..\tools\bin\debug;..\..\tools\bin


REM Trying to close depending applications
set one_closed=0
echo Trying to close pco controllers ...
closewin pco_ctrl 2>nul | grep sent 
if %? == 0 set one_closed=1
closewin pcoc 2>nul | grep sent
if %? == 0 set one_closed=1

echo Trying to close pco server ...
closewin pco_srv 2>nul | grep sent
if %? == 0 set one_closed=1
closewin pco_minisrv 2>nul | grep sent
if %? == 0 set one_closed=1
closewin pcod 2>nul | grep sent
if %? == 0 set one_closed=1

echo Trying to close pco viewers ...
closewin pco_view 2>nul | grep sent
if %? == 0 set one_closed=1
closewin pco_miniview 2>nul | grep sent
if %? == 0 set one_closed=1
closewin pco_demoview 2>nul | grep sent
if %? == 0 set one_closed=1

echo Trying to close testinterface ...
closewin tst 2>nul  | grep sent
if %? == 0 set one_closed=1

echo Trying to close cms.exe ...
closewin cms 2>nul | grep sent
if %? == 0 set one_closed=1

echo Trying to close xPanel ...
closewin xpanel 2>nul | grep sent
if %? == 0 set one_closed=1

echo Trying to close EMW ...
closewin emw 2>nul | grep sent
if %? == 0 set one_closed=1

echo Trying to close tcgen ...
closewin tcgen 2>nul | grep sent
if %? == 0 set one_closed=1

echo Trying to close TraceMultiplexer ...
closewin TraceMultiplexer 2>nul | grep sent
if %? == 0 set one_closed=1

if %one_closed% == 0 goto kill

REM give applications the chance to exit normally
echo.
echo Waiting for applications to shutdown normally ...
delay 5

:kill
echo.
REM trying to kill depending applications
echo Killing pco controllers ...
pkill pco_ctrl | grep Killed
pkill pcoc | grep Killed

echo Killing pco server ...
pkill pco_srv | grep Killed
pkill pco_minisrv | grep Killed
pkill pcod | grep Killed

echo Killing pco viewers ...
pkill pco_view | grep Killed
pkill pco_miniview | grep Killed

echo Killing testinterface ...
pkill tst | grep Killed

echo Killing cms.exe ...
pkill cms | grep Killed

echo Killing xPanel ...
pkill xpanel | grep Killed

echo Killing EMW ...
pkill emw | grep Killed

echo Killing tcgen ...
pkill tcgen | grep Killed

echo Killing TraceMultiplexer ...
pkill TraceMultiplexer | grep Killed

:end
endlocal
