1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
27 #include <basic/sberrors.hxx>
28 #include <basic/sbx.hxx>
29 #include <basic/sbxvar.hxx>
30 #include <rtl/ustring.hxx>
35 struct SbiDllMgr::Impl
{};
39 // Overcome the mess of Currency vs. custom types etc.
40 ErrCode
returnInt64InOutArg(SbxArray
*pArgs
, SbxVariable
&rRetVal
,
43 if (!rRetVal
.PutLong(1) && !rRetVal
.PutInteger(1))
44 return ERRCODE_BASIC_BAD_ARGUMENT
;
45 if (!pArgs
|| pArgs
->Count() != 2)
46 return ERRCODE_BASIC_BAD_ARGUMENT
;
47 SbxVariable
*pOut
= pArgs
->Get(1);
49 return ERRCODE_BASIC_BAD_ARGUMENT
;
50 if (pOut
->IsCurrency())
52 pOut
->PutCurrency(nValue
);
57 // FIXME: should we clone this and use pOut->PutObject ?
58 SbxObject
* pObj
= dynamic_cast<SbxObject
*>( pOut
->GetObject() );
60 return ERRCODE_BASIC_BAD_ARGUMENT
;
62 // We expect two Longs but other mappings could be possible too.
63 SbxArray
* pProps
= pObj
->GetProperties();
64 if (pProps
->Count32() != 2)
65 return ERRCODE_BASIC_BAD_ARGUMENT
;
66 SbxVariable
* pLow
= pProps
->Get32( 0 );
67 SbxVariable
* pHigh
= pProps
->Get32( 1 );
68 if (!pLow
|| !pLow
->IsLong() ||
69 !pHigh
|| !pHigh
->IsLong())
70 return ERRCODE_BASIC_BAD_ARGUMENT
;
71 pLow
->PutLong(nValue
& 0xffffffff);
72 pHigh
->PutLong(nValue
>> 32);
75 return ERRCODE_BASIC_BAD_ARGUMENT
;
78 ErrCode
builtin_kernel32(const OUString
&aFuncName
, SbxArray
*pArgs
,
81 sal_Int64 nNanoSecsPerSec
= 1000.0*1000*1000;
82 if (aFuncName
== "QueryPerformanceFrequency")
83 return returnInt64InOutArg(pArgs
, rRetVal
, nNanoSecsPerSec
);
85 else if (aFuncName
== "QueryPerformanceCounter")
88 osl_getSystemTime( &aNow
);
89 sal_Int64 nStamp
= aNow
.Nanosec
+ aNow
.Seconds
* nNanoSecsPerSec
;
90 return returnInt64InOutArg(pArgs
, rRetVal
, nStamp
);
92 return ERRCODE_BASIC_NOT_IMPLEMENTED
;
97 ErrCode
SbiDllMgr::Call(
98 const OUString
&aFuncName
, const OUString
&aDllName
,
99 SbxArray
*pArgs
, SbxVariable
&rRetVal
,
100 SAL_UNUSED_PARAMETER
bool /* bCDecl */)
102 if (aDllName
== "kernel32")
103 return builtin_kernel32(aFuncName
, pArgs
, rRetVal
);
105 return ERRCODE_BASIC_NOT_IMPLEMENTED
;
108 void SbiDllMgr::FreeDll(SAL_UNUSED_PARAMETER OUString
const &) {}
110 SbiDllMgr::SbiDllMgr(): impl_(new Impl
) {}
112 SbiDllMgr::~SbiDllMgr() {}
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */