1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tcommuni.cxx,v $
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>
45 #include "rcontrol.hxx"
46 #include "tcommuni.hxx"
47 #include <basic/testtool.hxx>
49 CommunicationManagerClientViaSocketTT::CommunicationManagerClientViaSocketTT()
50 : CommunicationManagerClientViaSocket( TRUE
)
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
)
69 aAppEnv
= (*pChildEnv
);
70 return StartCommunication();
74 BOOL
CommunicationManagerClientViaSocketTT::RetryConnect()
76 if ( !bApplicationStarted
)
78 // Die App ist wohl nicht da. Starten wir sie mal.
83 pProcess
= new Process();
84 pProcess
->SetImage( aAppPath
, aAppParams
, &aAppEnv
);
86 BOOL bSucc
= pProcess
->Start();
87 bApplicationStarted
= TRUE
;
91 aFirstRetryCall
= Time() + Time( 0, 1 ); // Max eine Minute Zeit
92 for ( int i
= 10 ; i
-- ; )
93 GetpApp()->Reschedule();
101 if ( aFirstRetryCall
> Time() )
104 aWait
.SetTimeout( 500 ); // Max 500 mSec
106 while ( aWait
.IsActive() )
115 BOOL
CommunicationManagerClientViaSocketTT::KillApplication()
118 return pProcess
->Terminate();
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()
135 for ( USHORT i
= 0 ; i
< Application::GetCommandLineParamCount() ; i
++ )
137 if ( Application::GetCommandLineParam( i
).Copy(0,6).CompareIgnoreCaseToAscii("-host=") == COMPARE_EQUAL
139 || Application::GetCommandLineParam( i
).Copy(0,6).CompareIgnoreCaseToAscii("/host=") == COMPARE_EQUAL
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()
158 for ( USHORT i
= 0 ; i
< Application::GetCommandLineParamCount() ; i
++ )
160 if ( Application::GetCommandLineParam( i
).Copy(0,6).CompareIgnoreCaseToAscii("-port=") == COMPARE_EQUAL
162 || Application::GetCommandLineParam( i
).Copy(0,6).CompareIgnoreCaseToAscii("/port=") == COMPARE_EQUAL
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()
184 for ( USHORT i
= 0 ; i
< Application::GetCommandLineParamCount() ; i
++ )
186 if ( Application::GetCommandLineParam( i
).Copy(0,9).CompareIgnoreCaseToAscii("-unoport=") == COMPARE_EQUAL
188 || Application::GetCommandLineParam( i
).Copy(0,9).CompareIgnoreCaseToAscii("/unoport=") == COMPARE_EQUAL
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();