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