LibreOffice Module extensions (master) 1
olethread.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include "ole2uno.hxx"
21
23#include <osl/thread.hxx>
24#include <sal/log.hxx>
25
27{
28 static osl::ThreadData oleThreadData;
29
30 if (!bool(reinterpret_cast<sal_IntPtr>(oleThreadData.getData())))
31 {
32 HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
33 if (!SUCCEEDED(hr))
34 { // FIXME: is it a problem that this ends up in STA currently?
35 assert(RPC_E_CHANGED_MODE == hr);
36 // Let's find out explicitly what apartment mode we are in.
37 SAL_WARN("extensions.olebridge", "CoInitializeEx failed"
38 << (hr == RPC_E_CHANGED_MODE ? " (expectedly)" : "")
39 << ": " << WindowsErrorStringFromHRESULT(hr));
40 APTTYPE nAptType;
41 APTTYPEQUALIFIER nAptTypeQualifier;
42 if (SUCCEEDED(CoGetApartmentType(&nAptType, &nAptTypeQualifier)))
43 {
44 SAL_WARN("extensions.olebridge",
45 " Thread is in a "
46 << (nAptType == APTTYPE_STA ? OUString("single-threaded") :
47 (nAptType == APTTYPE_MTA ? OUString("multi-threaded") :
48 (nAptType == APTTYPE_NA ? OUString("neutral") :
49 (nAptType == APTTYPE_MAINSTA ? OUString("main single-threaded") :
50 ("unknown (") + OUString::number(nAptType) + ")"))))
51 << " apartment"
52 << (nAptTypeQualifier == APTTYPEQUALIFIER_NONE ? OUString() :
53 (nAptTypeQualifier == APTTYPEQUALIFIER_IMPLICIT_MTA ? OUString(" (implicit)") :
54 (nAptTypeQualifier == APTTYPEQUALIFIER_NA_ON_MTA ? OUString(" (on MTA)") :
55 (nAptTypeQualifier == APTTYPEQUALIFIER_NA_ON_STA ? OUString(" (on STA)") :
56 (nAptTypeQualifier == APTTYPEQUALIFIER_NA_ON_IMPLICIT_MTA ? OUString(" (on implicit MTA)") :
57 (nAptTypeQualifier == APTTYPEQUALIFIER_NA_ON_MAINSTA ? OUString(" (on main STA)") :
58 (" (with unknown qualifier (" + OUString::number(nAptTypeQualifier) + "))")))))))
59 << ".");
60 }
61 }
62 oleThreadData.setData(reinterpret_cast<void*>(true));
63 }
64}
65
66/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define SAL_WARN(area, stream)
void o2u_attachCurrentThread()
Definition: olethread.cxx:26
return hr
Definition: so_activex.cxx:446