1*03b7fc75SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*03b7fc75SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*03b7fc75SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*03b7fc75SAndrew Rist * distributed with this work for additional information 6*03b7fc75SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*03b7fc75SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*03b7fc75SAndrew Rist * "License"); you may not use this file except in compliance 9*03b7fc75SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*03b7fc75SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*03b7fc75SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*03b7fc75SAndrew Rist * software distributed under the License is distributed on an 15*03b7fc75SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*03b7fc75SAndrew Rist * KIND, either express or implied. See the License for the 17*03b7fc75SAndrew Rist * specific language governing permissions and limitations 18*03b7fc75SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*03b7fc75SAndrew Rist *************************************************************/ 21*03b7fc75SAndrew Rist 22*03b7fc75SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #if ! defined INCLUDED_DP_MISC_H 25cdf0e10cSrcweir #define INCLUDED_DP_MISC_H 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "rtl/ustrbuf.hxx" 28cdf0e10cSrcweir #include "rtl/instance.hxx" 29cdf0e10cSrcweir #include "osl/mutex.hxx" 30cdf0e10cSrcweir #include "osl/process.h" 31cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp" 32cdf0e10cSrcweir #include "com/sun/star/lang/XComponent.hpp" 33cdf0e10cSrcweir #include "com/sun/star/lang/DisposedException.hpp" 34cdf0e10cSrcweir #include "com/sun/star/deployment/XPackageRegistry.hpp" 35cdf0e10cSrcweir #include "com/sun/star/ucb/XCommandEnvironment.hpp" 36cdf0e10cSrcweir #include "com/sun/star/awt/XWindow.hpp" 37cdf0e10cSrcweir #include "dp_misc_api.hxx" 38cdf0e10cSrcweir 39cdf0e10cSrcweir #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) ) 40cdf0e10cSrcweir #define ARLEN(x) (sizeof (x) / sizeof *(x)) 41cdf0e10cSrcweir 42cdf0e10cSrcweir namespace dp_misc { 43cdf0e10cSrcweir 44cdf0e10cSrcweir const sal_Char CR = 0x0d; 45cdf0e10cSrcweir const sal_Char LF = 0x0a; 46cdf0e10cSrcweir 47cdf0e10cSrcweir //============================================================================== 48cdf0e10cSrcweir class MutexHolder 49cdf0e10cSrcweir { 50cdf0e10cSrcweir mutable ::osl::Mutex m_mutex; 51cdf0e10cSrcweir protected: 52cdf0e10cSrcweir inline ::osl::Mutex & getMutex() const { return m_mutex; } 53cdf0e10cSrcweir }; 54cdf0e10cSrcweir 55cdf0e10cSrcweir //============================================================================== 56cdf0e10cSrcweir inline void try_dispose( ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> const & x ) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent> xComp( x, ::com::sun::star::uno::UNO_QUERY ); 59cdf0e10cSrcweir if (xComp.is()) 60cdf0e10cSrcweir xComp->dispose(); 61cdf0e10cSrcweir } 62cdf0e10cSrcweir 63cdf0e10cSrcweir //############################################################################## 64cdf0e10cSrcweir 65cdf0e10cSrcweir //============================================================================== 66cdf0e10cSrcweir DESKTOP_DEPLOYMENTMISC_DLLPUBLIC 67cdf0e10cSrcweir ::rtl::OUString expandUnoRcTerm( ::rtl::OUString const & term ); 68cdf0e10cSrcweir 69cdf0e10cSrcweir DESKTOP_DEPLOYMENTMISC_DLLPUBLIC 70cdf0e10cSrcweir ::rtl::OUString makeRcTerm( ::rtl::OUString const & url ); 71cdf0e10cSrcweir 72cdf0e10cSrcweir //============================================================================== 73cdf0e10cSrcweir DESKTOP_DEPLOYMENTMISC_DLLPUBLIC 74cdf0e10cSrcweir ::rtl::OUString expandUnoRcUrl( ::rtl::OUString const & url ); 75cdf0e10cSrcweir 76cdf0e10cSrcweir //============================================================================== 77cdf0e10cSrcweir 78cdf0e10cSrcweir /** appends a relative path to a url. 79cdf0e10cSrcweir 80cdf0e10cSrcweir The relative path must already be correctly encoded for use in an URL. 81cdf0e10cSrcweir If the URL starts with vnd.sun.star.expand then the relative path will 82cdf0e10cSrcweir be again encoded for use in an "expand" URL. 83cdf0e10cSrcweir */ 84cdf0e10cSrcweir DESKTOP_DEPLOYMENTMISC_DLLPUBLIC ::rtl::OUString makeURL( 85cdf0e10cSrcweir ::rtl::OUString const & baseURL, ::rtl::OUString const & relPath ); 86cdf0e10cSrcweir 87cdf0e10cSrcweir 88cdf0e10cSrcweir /** appends a relative path to a url. 89cdf0e10cSrcweir 90cdf0e10cSrcweir This is the same as makeURL, but the relative Path must me a segment 91cdf0e10cSrcweir of an system path. 92cdf0e10cSrcweir */ 93cdf0e10cSrcweir DESKTOP_DEPLOYMENTMISC_DLLPUBLIC ::rtl::OUString makeURLAppendSysPathSegment( 94cdf0e10cSrcweir ::rtl::OUString const & baseURL, ::rtl::OUString const & relPath ); 95cdf0e10cSrcweir 96cdf0e10cSrcweir //============================================================================== 97cdf0e10cSrcweir DESKTOP_DEPLOYMENTMISC_DLLPUBLIC ::rtl::OUString generateRandomPipeId(); 98cdf0e10cSrcweir 99cdf0e10cSrcweir class AbortChannel; 100cdf0e10cSrcweir //============================================================================== 101cdf0e10cSrcweir DESKTOP_DEPLOYMENTMISC_DLLPUBLIC 102cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> resolveUnoURL( 103cdf0e10cSrcweir ::rtl::OUString const & connectString, 104cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext> const & xLocalContext, 105cdf0e10cSrcweir AbortChannel * abortChannel = 0 ); 106cdf0e10cSrcweir 107cdf0e10cSrcweir //============================================================================== 108cdf0e10cSrcweir DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool office_is_running(); 109cdf0e10cSrcweir 110cdf0e10cSrcweir //============================================================================== 111cdf0e10cSrcweir DESKTOP_DEPLOYMENTMISC_DLLPUBLIC 112cdf0e10cSrcweir oslProcess raiseProcess( ::rtl::OUString const & appURL, 113cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > const & args ); 114cdf0e10cSrcweir 115cdf0e10cSrcweir //============================================================================== 116cdf0e10cSrcweir 117cdf0e10cSrcweir /** writes the argument string to the console. 118cdf0e10cSrcweir On Linux/Unix/etc. it converts the UTF16 string to an ANSI string using 119cdf0e10cSrcweir osl_getThreadTextEncoding() as target encoding. On Windows it uses WriteFile 120cdf0e10cSrcweir with the standard out stream. unopkg.com reads the data and prints them out using 121cdf0e10cSrcweir WriteConsoleW. 122cdf0e10cSrcweir */ 123cdf0e10cSrcweir DESKTOP_DEPLOYMENTMISC_DLLPUBLIC 124cdf0e10cSrcweir void writeConsole(::rtl::OUString const & sText); 125cdf0e10cSrcweir 126cdf0e10cSrcweir /** writes the argument string to the console. 127cdf0e10cSrcweir On Linux/Unix/etc. the string is passed into fprintf without any conversion. 128cdf0e10cSrcweir On Windows the string is converted to UTF16 assuming the argument is UTF8 129cdf0e10cSrcweir encoded. The UTF16 string is written to stdout with WriteFile. unopkg.com 130cdf0e10cSrcweir reads the data and prints them out using WriteConsoleW. 131cdf0e10cSrcweir */ 132cdf0e10cSrcweir DESKTOP_DEPLOYMENTMISC_DLLPUBLIC 133cdf0e10cSrcweir void writeConsole(::rtl::OString const & sText); 134cdf0e10cSrcweir 135cdf0e10cSrcweir /** writes the argument to the console using the error stream. 136cdf0e10cSrcweir Otherwise the same as writeConsole. 137cdf0e10cSrcweir */ 138cdf0e10cSrcweir DESKTOP_DEPLOYMENTMISC_DLLPUBLIC 139cdf0e10cSrcweir void writeConsoleError(::rtl::OUString const & sText); 140cdf0e10cSrcweir 141cdf0e10cSrcweir 142cdf0e10cSrcweir /** writes the argument to the console using the error stream. 143cdf0e10cSrcweir Otherwise the same as writeConsole. 144cdf0e10cSrcweir */ 145cdf0e10cSrcweir DESKTOP_DEPLOYMENTMISC_DLLPUBLIC 146cdf0e10cSrcweir void writeConsoleError(::rtl::OString const & sText); 147cdf0e10cSrcweir 148cdf0e10cSrcweir 149cdf0e10cSrcweir /** reads from the console. 150cdf0e10cSrcweir On Linux/Unix/etc. it uses fgets to read char values and converts them to OUString 151cdf0e10cSrcweir using osl_getThreadTextEncoding as target encoding. The returned string has a maximum 152cdf0e10cSrcweir size of 1024 and does NOT include leading and trailing white space(applied OUString::trim()) 153cdf0e10cSrcweir */ 154cdf0e10cSrcweir DESKTOP_DEPLOYMENTMISC_DLLPUBLIC 155cdf0e10cSrcweir ::rtl::OUString readConsole(); 156cdf0e10cSrcweir 157cdf0e10cSrcweir /** print the text to the console in a debug build. 158cdf0e10cSrcweir The argument is forwarded to writeConsole. The function does not add new line. 159cdf0e10cSrcweir The code is only executed if OSL_DEBUG_LEVEL > 1 160cdf0e10cSrcweir */ 161cdf0e10cSrcweir DESKTOP_DEPLOYMENTMISC_DLLPUBLIC 162cdf0e10cSrcweir void TRACE(::rtl::OUString const & sText); 163cdf0e10cSrcweir DESKTOP_DEPLOYMENTMISC_DLLPUBLIC 164cdf0e10cSrcweir void TRACE(::rtl::OString const & sText); 165cdf0e10cSrcweir 166cdf0e10cSrcweir /** registers or revokes shared or bundled extensions which have been 167cdf0e10cSrcweir recently added or removed. 168cdf0e10cSrcweir */ 169cdf0e10cSrcweir DESKTOP_DEPLOYMENTMISC_DLLPUBLIC 170cdf0e10cSrcweir void syncRepositories(::com::sun::star::uno::Reference< 171cdf0e10cSrcweir ::com::sun::star::ucb::XCommandEnvironment> const & xCmdEnv); 172cdf0e10cSrcweir 173cdf0e10cSrcweir } 174cdf0e10cSrcweir 175cdf0e10cSrcweir #endif 176