LCOV - code coverage report
Current view: top level - basic/source/runtime - dllmgr-none.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 33 43 76.7 %
Date: 2014-11-03 Functions: 5 6 83.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10