LCOV - code coverage report
Current view: top level - desktop/source/deployment/misc - dp_platform.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 28 113 24.8 %
Date: 2015-06-13 12:38:46 Functions: 6 8 75.0 %
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             : 
      21             : #include "dp_misc.h"
      22             : #include "dp_platform.hxx"
      23             : #include <rtl/ustring.hxx>
      24             : #include <rtl/ustrbuf.hxx>
      25             : #include <rtl/instance.hxx>
      26             : #include <rtl/bootstrap.hxx>
      27             : #include <osl/diagnose.h>
      28             : 
      29             : #define PLATFORM_ALL                "all"
      30             : #define PLATFORM_WIN_X86            "windows_x86"
      31             : #define PLATFORM_WIN_X86_64         "windows_x86_64"
      32             : #define PLATFORM_LINUX_X86          "linux_x86"
      33             : #define PLATFORM_LINUX_X86_64       "linux_x86_64"
      34             : #define PLATFORM_KFREEBSD_X86       "kfreebsd_x86"
      35             : #define PLATFORM_KFREEBSD_X86_64    "kfreebsd_x86_64"
      36             : #define PLATFORM_LINUX_SPARC        "linux_sparc"
      37             : #define PLATFORM_LINUX_POWERPC      "linux_powerpc"
      38             : #define PLATFORM_LINUX_POWERPC64    "linux_powerpc64"
      39             : #define PLATFORM_LINUX_POWERPC64_LE "linux_powerpc64_le"
      40             : #define PLATFORM_LINUX_ARM_EABI     "linux_arm_eabi"
      41             : #define PLATFORM_LINUX_ARM_OABI     "linux_arm_oabi"
      42             : #define PLATFORM_LINUX_MIPS_EL      "linux_mips_el"
      43             : #define PLATFORM_LINUX_MIPS_EB      "linux_mips_eb"
      44             : #define PLATFORM_LINUX_IA64         "linux_ia64"
      45             : #define PLATFORM_LINUX_M68K         "linux_m68k"
      46             : #define PLATFORM_LINUX_S390         "linux_s390"
      47             : #define PLATFORM_LINUX_S390x        "linux_s390x"
      48             : #define PLATFORM_LINUX_HPPA         "linux_hppa"
      49             : #define PLATFORM_LINUX_ALPHA        "linux_alpha"
      50             : #define PLATFORM_LINUX_AARCH64      "linux_aarch64"
      51             : 
      52             : 
      53             : #define PLATFORM_SOLARIS_SPARC      "solaris_sparc"
      54             : #define PLATFORM_SOLARIS_SPARC64    "solaris_sparc64"
      55             : #define PLATFORM_SOLARIS_X86        "solaris_x86"
      56             : #define PLATFORM_FREEBSD_X86        "freebsd_x86"
      57             : #define PLATFORM_FREEBSD_X86_64     "freebsd_x86_64"
      58             : #define PLATFORM_NETBSD_X86         "netbsd_x86"
      59             : #define PLATFORM_NETBSD_X86_64      "netbsd_x86_64"
      60             : #define PLATFORM_MACOSX_X86         "macosx_x86"
      61             : #define PLATFORM_MACOSX_X86_64      "macosx_x86_64"
      62             : #define PLATFORM_OPENBSD_X86        "openbsd_x86"
      63             : #define PLATFORM_OPENBSD_X86_64     "openbsd_x86_64"
      64             : #define PLATFORM_DRAGONFLY_X86      "dragonfly_x86"
      65             : #define PLATFORM_DRAGONFLY_X86_64   "dragonfly_x86_64"
      66             : 
      67             : 
      68             : #define PLATFORM_AIX_POWERPC        "aix_powerpc"
      69             : 
      70             : 
      71             : namespace dp_misc
      72             : {
      73             : namespace
      74             : {
      75             :     struct StrOperatingSystem :
      76             :         public rtl::StaticWithInit<OUString, StrOperatingSystem> {
      77          95 :             const OUString operator () () {
      78          95 :                 OUString os( "$_OS" );
      79          95 :                 ::rtl::Bootstrap::expandMacros( os );
      80          95 :                 return os;
      81             :             }
      82             :     };
      83             : 
      84             :     struct StrCPU :
      85             :         public rtl::StaticWithInit<OUString, StrCPU> {
      86          95 :             const OUString operator () () {
      87          95 :                 OUString arch( "$_ARCH" );
      88          95 :                 ::rtl::Bootstrap::expandMacros( arch );
      89          95 :                 return arch;
      90             :             }
      91             :     };
      92             : 
      93             : 
      94             :     struct StrPlatform : public rtl::StaticWithInit<
      95             :         OUString, StrPlatform> {
      96          95 :             const OUString operator () () {
      97          95 :                 OUStringBuffer buf;
      98          95 :                 buf.append( StrOperatingSystem::get() );
      99          95 :                 buf.append( '_' );
     100          95 :                 buf.append( StrCPU::get() );
     101          95 :                 return buf.makeStringAndClear();
     102             :             }
     103             :     };
     104             : 
     105           0 :     bool checkOSandCPU(OUString const & os, OUString const & cpu)
     106             :     {
     107           0 :         return (os == StrOperatingSystem::get())
     108           0 :             && (cpu == StrCPU::get());
     109             :     }
     110             : 
     111           2 :     bool isValidPlatform(OUString const &  token )
     112             :     {
     113           2 :         bool ret = false;
     114           2 :         if (token == PLATFORM_ALL)
     115           2 :             ret = true;
     116           0 :         else if (token == PLATFORM_WIN_X86)
     117           0 :             ret = checkOSandCPU("Windows", "x86");
     118           0 :         else if (token == PLATFORM_WIN_X86_64)
     119           0 :             ret = checkOSandCPU("Windows", "x86_64");
     120           0 :         else if (token == PLATFORM_LINUX_X86)
     121           0 :             ret = checkOSandCPU("Linux", "x86");
     122           0 :         else if (token == PLATFORM_LINUX_X86_64)
     123           0 :             ret = checkOSandCPU("Linux", "X86_64");
     124           0 :         else if (token == PLATFORM_KFREEBSD_X86)
     125           0 :             ret = checkOSandCPU("kFreeBSD", "x86");
     126           0 :         else if (token == PLATFORM_KFREEBSD_X86_64)
     127           0 :             ret = checkOSandCPU("kFreeBSD", "X86_64");
     128           0 :         else if (token == PLATFORM_LINUX_SPARC)
     129           0 :             ret = checkOSandCPU("Linux", "SPARC");
     130           0 :         else if (token == PLATFORM_LINUX_POWERPC)
     131           0 :             ret = checkOSandCPU("Linux", "PowerPC");
     132           0 :         else if (token == PLATFORM_LINUX_POWERPC64)
     133           0 :             ret = checkOSandCPU("Linux", "PowerPC_64");
     134           0 :         else if (token == PLATFORM_LINUX_POWERPC64_LE)
     135           0 :             ret = checkOSandCPU("Linux", "PowerPC_64_LE");
     136           0 :         else if (token == PLATFORM_LINUX_ARM_EABI)
     137           0 :             ret = checkOSandCPU("Linux", "ARM_EABI");
     138           0 :         else if (token == PLATFORM_LINUX_ARM_OABI)
     139           0 :             ret = checkOSandCPU("Linux", "ARM_OABI");
     140           0 :         else if (token == PLATFORM_LINUX_MIPS_EL)
     141           0 :             ret = checkOSandCPU("Linux", "MIPS_EL");
     142           0 :         else if (token == PLATFORM_LINUX_MIPS_EB)
     143           0 :             ret = checkOSandCPU("Linux", "MIPS_EB");
     144           0 :         else if (token == PLATFORM_LINUX_IA64)
     145           0 :             ret = checkOSandCPU("Linux", "IA64");
     146           0 :         else if (token == PLATFORM_LINUX_M68K)
     147           0 :             ret = checkOSandCPU("Linux", "M68K");
     148           0 :         else if (token == PLATFORM_LINUX_S390)
     149           0 :             ret = checkOSandCPU("Linux", "S390");
     150           0 :         else if (token == PLATFORM_LINUX_S390x)
     151           0 :             ret = checkOSandCPU("Linux", "S390x");
     152           0 :         else if (token == PLATFORM_LINUX_HPPA)
     153           0 :             ret = checkOSandCPU("Linux", "HPPA");
     154           0 :         else if (token == PLATFORM_LINUX_ALPHA)
     155           0 :             ret = checkOSandCPU("Linux", "ALPHA");
     156           0 :         else if (token == PLATFORM_LINUX_AARCH64)
     157           0 :             ret = checkOSandCPU("Linux", "AARCH64");
     158           0 :         else if (token == PLATFORM_SOLARIS_SPARC)
     159           0 :             ret = checkOSandCPU("Solaris", "SPARC");
     160           0 :         else if (token == PLATFORM_SOLARIS_SPARC64)
     161           0 :             ret = checkOSandCPU("Solaris", "SPARC64");
     162           0 :         else if (token == PLATFORM_SOLARIS_X86)
     163           0 :             ret = checkOSandCPU("Solaris", "x86");
     164           0 :         else if (token == PLATFORM_FREEBSD_X86)
     165           0 :             ret = checkOSandCPU("FreeBSD", "x86");
     166           0 :         else if (token == PLATFORM_FREEBSD_X86_64)
     167           0 :             ret = checkOSandCPU("FreeBSD", "X86_64");
     168           0 :         else if (token == PLATFORM_NETBSD_X86)
     169           0 :             ret = checkOSandCPU("NetBSD", "x86");
     170           0 :         else if (token == PLATFORM_NETBSD_X86_64)
     171           0 :             ret = checkOSandCPU("NetBSD", "X86_64");
     172           0 :         else if (token == PLATFORM_MACOSX_X86)
     173           0 :             ret = checkOSandCPU("MacOSX", "x86");
     174           0 :         else if (token == PLATFORM_MACOSX_X86_64)
     175           0 :             ret = checkOSandCPU("MacOSX", "X86_64");
     176           0 :         else if (token == PLATFORM_AIX_POWERPC)
     177           0 :             ret = checkOSandCPU("AIX", "PowerPC");
     178           0 :         else if (token == PLATFORM_OPENBSD_X86)
     179           0 :             ret = checkOSandCPU("OpenBSD", "x86");
     180           0 :         else if (token == PLATFORM_OPENBSD_X86_64)
     181           0 :             ret = checkOSandCPU("OpenBSD", "X86_64");
     182           0 :         else if (token == PLATFORM_DRAGONFLY_X86)
     183           0 :             ret = checkOSandCPU("DragonFly", "x86");
     184           0 :         else if (token == PLATFORM_DRAGONFLY_X86_64)
     185           0 :             ret = checkOSandCPU("DragonFly", "X86_64");
     186             :         else
     187             :         {
     188             :             OSL_FAIL("Extension Manager: The extension supports an unknown platform. "
     189             :             "Check the platform element in the description.xml");
     190           0 :             ret = false;
     191             :         }
     192           2 :         return ret;
     193             :     }
     194             : 
     195             : } // anon namespace
     196             : 
     197             : 
     198         397 : OUString const & getPlatformString()
     199             : {
     200         397 :     return StrPlatform::get();
     201             : }
     202             : 
     203           0 : bool platform_fits( OUString const & platform_string )
     204             : {
     205           0 :     sal_Int32 index = 0;
     206             :     for (;;)
     207             :     {
     208             :         const OUString token(
     209           0 :             platform_string.getToken( 0, ',', index ).trim() );
     210             :         // check if this platform:
     211           0 :         if (token.equalsIgnoreAsciiCase( StrPlatform::get() ) ||
     212           0 :             (token.indexOf( '_' ) < 0 && /* check OS part only */
     213           0 :              token.equalsIgnoreAsciiCase( StrOperatingSystem::get() )))
     214             :         {
     215           0 :             return true;
     216             :         }
     217           0 :         if (index < 0)
     218           0 :             break;
     219           0 :     }
     220           0 :     return false;
     221             : }
     222             : 
     223           2 : bool hasValidPlatform( css::uno::Sequence<OUString> const & platformStrings)
     224             : {
     225           2 :     bool ret = false;
     226           2 :     for (sal_Int32 i  = 0; i < platformStrings.getLength(); i++)
     227             :     {
     228           2 :         if (isValidPlatform(platformStrings[i]))
     229             :         {
     230           2 :             ret = true;
     231           2 :             break;
     232             :         }
     233             :     }
     234           2 :     return ret;
     235             : }
     236             : 
     237             : }
     238             : 
     239             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11