update dev300-m58
[ooovba.git] / automation / source / testtool / tcommuni.cxx
blob931b917da648006aa190c36cfc49b82c01091aea
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tcommuni.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_automation.hxx"
35 #include <tools/config.hxx>
36 #include <vcl/svapp.hxx>
37 #include <tools/time.hxx>
38 #include <tools/debug.hxx>
39 #include <vcl/timer.hxx>
41 #ifndef _BASIC_TTRESHLP_HXX
42 #include <basic/ttstrhlp.hxx>
43 #endif
45 #include "rcontrol.hxx"
46 #include "tcommuni.hxx"
47 #include <basic/testtool.hxx>
49 CommunicationManagerClientViaSocketTT::CommunicationManagerClientViaSocketTT()
50 : CommunicationManagerClientViaSocket( TRUE )
51 , aAppPath()
52 , aAppParams()
53 , pProcess( NULL )
58 BOOL CommunicationManagerClientViaSocketTT::StartCommunication()
60 bApplicationStarted = FALSE;
61 return CommunicationManagerClientViaSocket::StartCommunication( ByteString( GetHostConfig(), RTL_TEXTENCODING_UTF8 ), GetTTPortConfig() );
65 BOOL CommunicationManagerClientViaSocketTT::StartCommunication( String aApp, String aParams, Environment *pChildEnv )
67 aAppPath = aApp;
68 aAppParams = aParams;
69 aAppEnv = (*pChildEnv);
70 return StartCommunication();
74 BOOL CommunicationManagerClientViaSocketTT::RetryConnect()
76 if ( !bApplicationStarted )
78 // Die App ist wohl nicht da. Starten wir sie mal.
79 if ( aAppPath.Len() )
81 delete pProcess;
83 pProcess = new Process();
84 pProcess->SetImage( aAppPath, aAppParams, &aAppEnv );
86 BOOL bSucc = pProcess->Start();
87 bApplicationStarted = TRUE;
89 if ( bSucc )
91 aFirstRetryCall = Time() + Time( 0, 1 ); // Max eine Minute Zeit
92 for ( int i = 10 ; i-- ; )
93 GetpApp()->Reschedule();
95 return bSucc;
97 return FALSE;
99 else
101 if ( aFirstRetryCall > Time() )
103 Timer aWait;
104 aWait.SetTimeout( 500 ); // Max 500 mSec
105 aWait.Start();
106 while ( aWait.IsActive() )
107 GetpApp()->Yield();
108 return TRUE;
110 else
111 return FALSE;
115 BOOL CommunicationManagerClientViaSocketTT::KillApplication()
117 if ( pProcess )
118 return pProcess->Terminate();
119 return TRUE;
122 #define GETSET(aVar, KeyName, Dafault) \
123 aVar = aConf.ReadKey(KeyName,"No Entry"); \
124 if ( aVar.CompareTo("No Entry") == COMPARE_EQUAL ) \
126 aVar = ByteString(Dafault); \
127 aConf.WriteKey(KeyName, aVar); \
131 String GetHostConfig()
133 String aHostToTalk;
135 for ( USHORT i = 0 ; i < Application::GetCommandLineParamCount() ; i++ )
137 if ( Application::GetCommandLineParam( i ).Copy(0,6).CompareIgnoreCaseToAscii("-host=") == COMPARE_EQUAL
138 #ifndef UNX
139 || Application::GetCommandLineParam( i ).Copy(0,6).CompareIgnoreCaseToAscii("/host=") == COMPARE_EQUAL
140 #endif
142 return Application::GetCommandLineParam( i ).Copy(6);
145 ByteString abHostToTalk;
146 Config aConf(Config::GetConfigName( Config::GetDefDirectory(), CUniString("testtool") ));
147 aConf.SetGroup("Communication");
149 GETSET( abHostToTalk, "Host", DEFAULT_HOST );
150 return UniString( abHostToTalk, RTL_TEXTENCODING_UTF8 );
154 ULONG GetTTPortConfig()
156 String aPortToTalk;
158 for ( USHORT i = 0 ; i < Application::GetCommandLineParamCount() ; i++ )
160 if ( Application::GetCommandLineParam( i ).Copy(0,6).CompareIgnoreCaseToAscii("-port=") == COMPARE_EQUAL
161 #ifndef UNX
162 || Application::GetCommandLineParam( i ).Copy(0,6).CompareIgnoreCaseToAscii("/port=") == COMPARE_EQUAL
163 #endif
166 aPortToTalk = Application::GetCommandLineParam( i ).Copy(6);
167 return (ULONG)aPortToTalk.ToInt64();
171 ByteString abPortToTalk;
172 Config aConf(Config::GetConfigName( Config::GetDefDirectory(), CUniString("testtool") ));
173 aConf.SetGroup("Communication");
175 GETSET( abPortToTalk, "TTPort", ByteString::CreateFromInt32( TESTTOOL_DEFAULT_PORT ) );
176 return (ULONG)abPortToTalk.ToInt64();
180 ULONG GetUnoPortConfig()
182 String aPortToTalk;
184 for ( USHORT i = 0 ; i < Application::GetCommandLineParamCount() ; i++ )
186 if ( Application::GetCommandLineParam( i ).Copy(0,9).CompareIgnoreCaseToAscii("-unoport=") == COMPARE_EQUAL
187 #ifndef UNX
188 || Application::GetCommandLineParam( i ).Copy(0,9).CompareIgnoreCaseToAscii("/unoport=") == COMPARE_EQUAL
189 #endif
192 aPortToTalk = Application::GetCommandLineParam( i ).Copy(6);
193 return (ULONG)aPortToTalk.ToInt64();
197 ByteString abPortToTalk;
198 Config aConf(Config::GetConfigName( Config::GetDefDirectory(), CUniString("testtool") ));
199 aConf.SetGroup("Communication");
201 GETSET( abPortToTalk, "UnoPort", ByteString::CreateFromInt32( UNO_DEFAULT_PORT ) );
202 return (ULONG)abPortToTalk.ToInt64();