LCOV - code coverage report
Current view: top level - basic/source/runtime - dllmgr-none.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 33 43 76.7 %
Date: 2015-06-13 12:38:46 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           5 : SbError returnInt64InOutArg(SbxArray *pArgs, SbxVariable &rRetVal,
      43             :                             sal_Int64 nValue)
      44             : {
      45           5 :     if (!rRetVal.PutLong(1) && !rRetVal.PutInteger(1))
      46           0 :         return ERRCODE_BASIC_BAD_ARGUMENT;
      47           5 :     if (!pArgs || pArgs->Count() != 2)
      48           0 :         return ERRCODE_BASIC_BAD_ARGUMENT;
      49           5 :     SbxVariable *pOut = pArgs->Get(1);
      50           5 :     if (!pOut)
      51           0 :         return ERRCODE_BASIC_BAD_ARGUMENT;
      52           5 :     if (pOut->IsCurrency())
      53             :     {
      54           3 :         pOut->PutCurrency(nValue);
      55           3 :         return ERRCODE_NONE;
      56             :     }
      57           2 :     if (pOut->IsObject())
      58             :     {
      59             :         // FIXME: should we clone this and use pOut->PutObject ?
      60           2 :         SbxObject* pObj = PTR_CAST(SbxObject,pOut->GetObject());
      61           2 :         if (!pObj)
      62           0 :             return ERRCODE_BASIC_BAD_ARGUMENT;
      63             : 
      64             :         // We expect two Longs but other mappings could be possible too.
      65           2 :         SbxArray* pProps = pObj->GetProperties();
      66           2 :         if (pProps->Count32() != 2)
      67           0 :             return ERRCODE_BASIC_BAD_ARGUMENT;
      68           2 :         SbxVariable* pLow = pProps->Get32( 0 );
      69           2 :         SbxVariable* pHigh = pProps->Get32( 1 );
      70           4 :         if (!pLow || !pLow->IsLong() ||
      71           4 :             !pHigh || !pHigh->IsLong())
      72           0 :             return ERRCODE_BASIC_BAD_ARGUMENT;
      73           2 :         pLow->PutLong(nValue & 0xffffffff);
      74           2 :         pHigh->PutLong(nValue >> 32);
      75           2 :         return ERRCODE_NONE;
      76             :     }
      77           0 :     return ERRCODE_BASIC_BAD_ARGUMENT;
      78             : }
      79             : 
      80           5 : SbError builtin_kernel32(const OUString &aFuncName, SbxArray *pArgs,
      81             :                          SbxVariable &rRetVal)
      82             : {
      83           5 :     sal_Int64 nNanoSecsPerSec = 1000.0*1000*1000;
      84           5 :     if (aFuncName == "QueryPerformanceFrequency")
      85           2 :         return returnInt64InOutArg(pArgs, rRetVal, nNanoSecsPerSec);
      86             : 
      87           3 :     else if (aFuncName == "QueryPerformanceCounter")
      88             :     {
      89             :         TimeValue aNow;
      90           3 :         osl_getSystemTime( &aNow );
      91           3 :         sal_Int64 nStamp = aNow.Nanosec + aNow.Seconds * nNanoSecsPerSec;
      92           3 :         return returnInt64InOutArg(pArgs, rRetVal, nStamp);
      93             :     }
      94           0 :     return ERRCODE_BASIC_NOT_IMPLEMENTED;
      95             : }
      96             : 
      97             : };
      98             : 
      99           5 : SbError SbiDllMgr::Call(
     100             :     const OUString &aFuncName, const OUString &aDllName,
     101             :     SbxArray *pArgs, SbxVariable &rRetVal,
     102             :     bool /* bCDecl */)
     103             : {
     104           5 :     if (aDllName == "kernel32")
     105           5 :         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           2 : SbiDllMgr::SbiDllMgr(): impl_(new Impl) {}
     113             : 
     114           2 : SbiDllMgr::~SbiDllMgr() {}
     115             : 
     116             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11