Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / extensions / source / ole / olethread.cxx
blob74d7346516c54b1d526b08626c0367ddff193083
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "ole2uno.hxx"
22 #include <comphelper/windowserrorstring.hxx>
23 #include <osl/thread.hxx>
24 #include <sal/log.hxx>
26 using namespace std;
28 void o2u_attachCurrentThread()
30 static osl::ThreadData oleThreadData;
32 if (!bool(reinterpret_cast<sal_IntPtr>(oleThreadData.getData())))
34 HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
35 if (!SUCCEEDED(hr))
36 { // FIXME: is it a problem that this ends up in STA currently?
37 assert(RPC_E_CHANGED_MODE == hr);
38 // Let's find out explicitly what apartment mode we are in.
39 SAL_WARN("extensions.olebridge", "CoInitializeEx failed"
40 << (hr == RPC_E_CHANGED_MODE ? " (expectedly)" : "")
41 << ": " << WindowsErrorStringFromHRESULT(hr));
42 APTTYPE nAptType;
43 APTTYPEQUALIFIER nAptTypeQualifier;
44 if (SUCCEEDED(CoGetApartmentType(&nAptType, &nAptTypeQualifier)))
46 SAL_WARN("extensions.olebridge",
47 " Thread is in a "
48 << (nAptType == APTTYPE_STA ? OUString("single-threaded") :
49 (nAptType == APTTYPE_MTA ? OUString("multi-threaded") :
50 (nAptType == APTTYPE_NA ? OUString("neutral") :
51 (nAptType == APTTYPE_MAINSTA ? OUString("main single-threaded") :
52 ("unknown (") + OUString::number(nAptType) + ")"))))
53 << " apartment"
54 << (nAptTypeQualifier == APTTYPEQUALIFIER_NONE ? OUString() :
55 (nAptTypeQualifier == APTTYPEQUALIFIER_IMPLICIT_MTA ? OUString(" (implicit)") :
56 (nAptTypeQualifier == APTTYPEQUALIFIER_NA_ON_MTA ? OUString(" (on MTA)") :
57 (nAptTypeQualifier == APTTYPEQUALIFIER_NA_ON_STA ? OUString(" (on STA)") :
58 (nAptTypeQualifier == APTTYPEQUALIFIER_NA_ON_IMPLICIT_MTA ? OUString(" (on implicit MTA)") :
59 (nAptTypeQualifier == APTTYPEQUALIFIER_NA_ON_MAINSTA ? OUString(" (on main STA)") :
60 (" (with unknown qualifier (" + OUString::number(nAptTypeQualifier) + "))")))))))
61 << ".");
64 oleThreadData.setData(reinterpret_cast<void*>(true));
68 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */