LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / basic / source / runtime / dllmgr-none.cxx
blob30070977d2155ec81ae8ae1afedd2eb709ed0925
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 <sal/config.h>
22 #if defined(_WIN32)
23 #include <prewin.h>
24 #include <postwin.h>
25 #endif
27 #include <basic/sberrors.hxx>
28 #include <basic/sbx.hxx>
29 #include <basic/sbxvar.hxx>
30 #include <rtl/ustring.hxx>
31 #include <osl/time.h>
33 #include "dllmgr.hxx"
35 namespace {
37 // Overcome the mess of Currency vs. custom types etc.
38 ErrCode returnInt64InOutArg(SbxArray *pArgs, SbxVariable &rRetVal,
39 sal_Int64 nValue)
41 if (!rRetVal.PutLong(1) && !rRetVal.PutInteger(1))
42 return ERRCODE_BASIC_BAD_ARGUMENT;
43 if (!pArgs || pArgs->Count() != 2)
44 return ERRCODE_BASIC_BAD_ARGUMENT;
45 SbxVariable* pOut = pArgs->Get(1);
46 if (!pOut)
47 return ERRCODE_BASIC_BAD_ARGUMENT;
48 if (pOut->IsCurrency())
50 pOut->PutCurrency(nValue);
51 return ERRCODE_NONE;
53 if (pOut->IsObject())
55 // FIXME: should we clone this and use pOut->PutObject ?
56 SbxObject* pObj = dynamic_cast<SbxObject*>( pOut->GetObject() );
57 if (!pObj)
58 return ERRCODE_BASIC_BAD_ARGUMENT;
60 // We expect two Longs but other mappings could be possible too.
61 SbxArray* pProps = pObj->GetProperties();
62 if (pProps->Count() != 2)
63 return ERRCODE_BASIC_BAD_ARGUMENT;
64 SbxVariable* pLow = pProps->Get(0);
65 SbxVariable* pHigh = pProps->Get(1);
66 if (!pLow || !pLow->IsLong() ||
67 !pHigh || !pHigh->IsLong())
68 return ERRCODE_BASIC_BAD_ARGUMENT;
69 pLow->PutLong(nValue & 0xffffffff);
70 pHigh->PutLong(nValue >> 32);
71 return ERRCODE_NONE;
73 return ERRCODE_BASIC_BAD_ARGUMENT;
76 ErrCode builtin_kernel32(std::u16string_view aFuncName, SbxArray *pArgs,
77 SbxVariable &rRetVal)
79 sal_Int64 nNanoSecsPerSec = 1000.0*1000*1000;
80 if (aFuncName == u"QueryPerformanceFrequency")
81 return returnInt64InOutArg(pArgs, rRetVal, nNanoSecsPerSec);
83 else if (aFuncName == u"QueryPerformanceCounter")
85 TimeValue aNow;
86 osl_getSystemTime( &aNow );
87 sal_Int64 nStamp = aNow.Nanosec + aNow.Seconds * nNanoSecsPerSec;
88 return returnInt64InOutArg(pArgs, rRetVal, nStamp);
90 return ERRCODE_BASIC_NOT_IMPLEMENTED;
95 ErrCode SbiDllMgr::Call(
96 std::u16string_view aFuncName, std::u16string_view aDllName,
97 SbxArray *pArgs, SbxVariable &rRetVal,
98 SAL_UNUSED_PARAMETER bool /* bCDecl */)
100 if (aDllName == u"kernel32")
101 return builtin_kernel32(aFuncName, pArgs, rRetVal);
102 else
103 return ERRCODE_BASIC_NOT_IMPLEMENTED;
106 void SbiDllMgr::FreeDll(SAL_UNUSED_PARAMETER OUString const &) {}
108 SbiDllMgr::SbiDllMgr() = default;
110 SbiDllMgr::~SbiDllMgr() = default;
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */