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: dp_misc.h,v $
10 * $Revision: 1.13.86.2 $
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 #if ! defined INCLUDED_DP_MISC_H
32 #define INCLUDED_DP_MISC_H
34 #include "rtl/ustrbuf.hxx"
35 #include "rtl/instance.hxx"
36 #include "osl/mutex.hxx"
37 #include "osl/process.h"
38 #include "com/sun/star/uno/XComponentContext.hpp"
39 #include "com/sun/star/lang/XComponent.hpp"
40 #include "com/sun/star/lang/DisposedException.hpp"
41 #include "com/sun/star/deployment/XPackageRegistry.hpp"
42 #include "com/sun/star/awt/XWindow.hpp"
43 #include "dp_misc_api.hxx"
45 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
46 #define ARLEN(x) (sizeof (x) / sizeof *(x))
50 const sal_Char CR
= 0x0d;
51 const sal_Char LF
= 0x0a;
53 //==============================================================================
56 mutable ::osl::Mutex m_mutex
;
58 inline ::osl::Mutex
& getMutex() const { return m_mutex
; }
61 //==============================================================================
62 inline void try_dispose( ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> const & x
)
64 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XComponent
> xComp( x
, ::com::sun::star::uno::UNO_QUERY
);
69 //##############################################################################
71 //==============================================================================
72 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
73 ::rtl::OUString
expandUnoRcTerm( ::rtl::OUString
const & term
);
75 //==============================================================================
76 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
77 ::rtl::OUString
expandUnoRcUrl( ::rtl::OUString
const & url
);
79 //==============================================================================
80 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC ::rtl::OUString
makeURL(
81 ::rtl::OUString
const & baseURL
, ::rtl::OUString
const & relPath
);
83 //==============================================================================
84 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC ::rtl::OUString
generateRandomPipeId();
87 //==============================================================================
88 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
89 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> resolveUnoURL(
90 ::rtl::OUString
const & connectString
,
91 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> const & xLocalContext
,
92 AbortChannel
* abortChannel
= 0 );
94 //==============================================================================
95 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
bool office_is_running();
97 //==============================================================================
98 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
99 oslProcess
raiseProcess( ::rtl::OUString
const & appURL
,
100 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> const & args
);
102 //==============================================================================
103 /** returns the default update URL (for the update information) which
104 is used when an extension does not provide its own URL.
106 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
107 ::rtl::OUString
getExtensionDefaultUpdateURL();
109 /** writes the argument string to the console.
110 On Linux/Unix/etc. it converts the UTF16 string to an ANSI string using
111 osl_getThreadTextEncoding() as target encoding. On Windows it uses WriteFile
112 with the standard out stream. unopkg.com reads the data and prints them out using
115 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
116 void writeConsole(::rtl::OUString
const & sText
);
118 /** writes the argument string to the console.
119 On Linux/Unix/etc. the string is passed into fprintf without any conversion.
120 On Windows the string is converted to UTF16 assuming the argument is UTF8
121 encoded. The UTF16 string is written to stdout with WriteFile. unopkg.com
122 reads the data and prints them out using WriteConsoleW.
124 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
125 void writeConsole(::rtl::OString
const & sText
);
127 /** writes the argument to the console using the error stream.
128 Otherwise the same as writeConsole.
130 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
131 void writeConsoleError(::rtl::OUString
const & sText
);
134 /** writes the argument to the console using the error stream.
135 Otherwise the same as writeConsole.
137 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
138 void writeConsoleError(::rtl::OString
const & sText
);
141 /** reads from the console.
142 On Linux/Unix/etc. it uses fgets to read char values and converts them to OUString
143 using osl_getThreadTextEncoding as target encoding. The returned string has a maximum
144 size of 1024 and does NOT include leading and trailing white space(applied OUString::trim())
146 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
147 ::rtl::OUString
readConsole();
149 /** print the text to the console in a debug build.
150 The argument is forwarded to writeConsole. The function does not add new line.
151 The code is only executed if OSL_DEBUG_LEVEL > 1
153 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
154 void TRACE(::rtl::OUString
const & sText
);
155 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
156 void TRACE(::rtl::OString
const & sText
);