LibreOffice Module desktop (master)  1
dp_platform.cxx
Go to the documentation of this file.
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 
31 
32 namespace dp_misc
33 {
34 namespace
35 {
36  struct StrOperatingSystem :
37  public rtl::StaticWithInit<OUString, StrOperatingSystem> {
38  OUString operator () () {
39  OUString os( "$_OS" );
40  ::rtl::Bootstrap::expandMacros( os );
41  return os;
42  }
43  };
44 
45  struct StrCPU :
46  public rtl::StaticWithInit<OUString, StrCPU> {
47  OUString operator () () {
48  OUString arch( "$_ARCH" );
49  ::rtl::Bootstrap::expandMacros( arch );
50  return arch;
51  }
52  };
53 
54 
55  struct StrPlatform : public rtl::StaticWithInit<
56  OUString, StrPlatform> {
57  OUString operator () () {
58  OUStringBuffer buf;
59  buf.append( StrOperatingSystem::get() );
60  buf.append( '_' );
61  buf.append( StrCPU::get() );
62  return buf.makeStringAndClear();
63  }
64  };
65 
66  bool checkOSandCPU(OUString const & os, OUString const & cpu)
67  {
68  return (os == StrOperatingSystem::get())
69  && (cpu == StrCPU::get());
70  }
71 
72  bool isPlatformSupported( OUString const & token )
73  {
74  bool ret = false;
75  if (token == PLATFORM_ALL)
76  ret = true;
77  else if (token == "windows_x86")
78  ret = checkOSandCPU("Windows", "x86");
79  else if (token == "windows_x86_64")
80  ret = checkOSandCPU("Windows", "X86_64");
81  else if (token == "solaris_sparc")
82  ret = checkOSandCPU("Solaris", "SPARC");
83  else if (token == "solaris_sparc64")
84  ret = checkOSandCPU("Solaris", "SPARC64");
85  else if (token == "solaris_x86")
86  ret = checkOSandCPU("Solaris", "x86");
87  else if (token == "aix_powerpc")
88  ret = checkOSandCPU("AIX", "PowerPC");
89  else if (token == "macosx_x86_64")
90  ret = checkOSandCPU("MacOSX", "X86_64");
91  else if (token == "linux_x86")
92  ret = checkOSandCPU("Linux", "x86");
93  else if (token == "linux_x86_64")
94  ret = checkOSandCPU("Linux", "X86_64");
95  else if (token == "linux_sparc")
96  ret = checkOSandCPU("Linux", "SPARC");
97  else if (token == "linux_sparc64")
98  ret = checkOSandCPU("Linux", "SPARC64");
99  else if (token == "linux_powerpc")
100  ret = checkOSandCPU("Linux", "PowerPC");
101  else if (token == "linux_powerpc64")
102  ret = checkOSandCPU("Linux", "PowerPC_64");
103  else if (token == "linux_powerpc64_le")
104  ret = checkOSandCPU("Linux", "PowerPC_64_LE");
105  else if (token == "linux_arm_eabi")
106  ret = checkOSandCPU("Linux", "ARM_EABI");
107  else if (token == "linux_arm_oabi")
108  ret = checkOSandCPU("Linux", "ARM_OABI");
109  else if (token == "linux_mips_el")
110  ret = checkOSandCPU("Linux", "MIPS_EL");
111  else if (token == "linux_mips64_el")
112  ret = checkOSandCPU("Linux", "MIPS64_EL");
113  else if (token == "linux_mips_eb")
114  ret = checkOSandCPU("Linux", "MIPS_EB");
115  else if (token == "linux_mips64_eb")
116  ret = checkOSandCPU("Linux", "MIPS64_EB");
117  else if (token == "linux_ia64")
118  ret = checkOSandCPU("Linux", "IA64");
119  else if (token == "linux_m68k")
120  ret = checkOSandCPU("Linux", "M68K");
121  else if (token == "linux_s390")
122  ret = checkOSandCPU("Linux", "S390");
123  else if (token == "linux_s390x")
124  ret = checkOSandCPU("Linux", "S390x");
125  else if (token == "linux_hppa")
126  ret = checkOSandCPU("Linux", "HPPA");
127  else if (token == "linux_alpha")
128  ret = checkOSandCPU("Linux", "ALPHA");
129  else if (token == "linux_aarch64")
130  ret = checkOSandCPU("Linux", "AARCH64");
131  else if (token == "freebsd_x86")
132  ret = checkOSandCPU("FreeBSD", "x86");
133  else if (token == "freebsd_x86_64")
134  ret = checkOSandCPU("FreeBSD", "X86_64");
135  else if (token == "freebsd_powerpc")
136  ret = checkOSandCPU("FreeBSD", "PowerPC");
137  else if (token == "kfreebsd_x86")
138  ret = checkOSandCPU("kFreeBSD", "x86");
139  else if (token == "kfreebsd_x86_64")
140  ret = checkOSandCPU("kFreeBSD", "X86_64");
141  else if (token == "netbsd_x86")
142  ret = checkOSandCPU("NetBSD", "x86");
143  else if (token == "netbsd_x86_64")
144  ret = checkOSandCPU("NetBSD", "X86_64");
145  else if (token == "openbsd_x86")
146  ret = checkOSandCPU("OpenBSD", "x86");
147  else if (token == "openbsd_x86_64")
148  ret = checkOSandCPU("OpenBSD", "X86_64");
149  else if (token == "dragonfly_x86")
150  ret = checkOSandCPU("DragonFly", "x86");
151  else if (token == "dragonfly_x86_64")
152  ret = checkOSandCPU("DragonFly", "X86_64");
153  else
154  {
155  OSL_FAIL("Extension Manager: The extension supports an unknown platform. "
156  "Check the platform in the description.xml");
157  ret = false;
158  }
159  return ret;
160  }
161 
162 } // anon namespace
163 
164 
165 OUString const & getPlatformString()
166 {
167  return StrPlatform::get();
168 }
169 
170 bool platform_fits( OUString const & platform_string )
171 {
172  sal_Int32 index = 0;
173  for (;;)
174  {
175  const OUString token(
176  platform_string.getToken( 0, ',', index ).trim() );
177  // check if this platform:
178  if (token.equalsIgnoreAsciiCase( StrPlatform::get() ) ||
179  (token.indexOf( '_' ) < 0 && /* check OS part only */
180  token.equalsIgnoreAsciiCase( StrOperatingSystem::get() )))
181  {
182  return true;
183  }
184  if (index < 0)
185  break;
186  }
187  return false;
188 }
189 
190 bool hasValidPlatform( css::uno::Sequence<OUString> const & platformStrings)
191 {
192  bool ret = false;
193  for (sal_Int32 i = 0; i < platformStrings.getLength(); i++)
194  {
195  if ( isPlatformSupported( platformStrings[i] ))
196  {
197  ret = true;
198  break;
199  }
200  }
201  return ret;
202 }
203 
204 }
205 
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC OUString const & getPlatformString()
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool platform_fits(OUString const &platform_string)
int i
tuple index
#define PLATFORM_ALL
Definition: dp_platform.cxx:29
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool hasValidPlatform(css::uno::Sequence< OUString > const &platformStrings)
determines if the current platform corresponds to one of the platform strings.