Debian Codegraph @

basic/source/runtime/dllmgr-none.cxx

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