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 "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(OUString const & os, OUString const & cpu)
66  {
67  return (os == StrOperatingSystem::get())
68  && (cpu == StrCPU::get());
69  }
70 
71  bool isPlatformSupported( OUString const & token )
72  {
73  bool ret = false;
74  if (token == PLATFORM_ALL)
75  ret = true;
76  else if (token == "windows_x86")
77  ret = checkOSandCPU("Windows", "x86");
78  else if (token == "windows_x86_64")
79  ret = checkOSandCPU("Windows", "X86_64");
80  else if (token == "solaris_sparc")
81  ret = checkOSandCPU("Solaris", "SPARC");
82  else if (token == "solaris_sparc64")
83  ret = checkOSandCPU("Solaris", "SPARC64");
84  else if (token == "solaris_x86")
85  ret = checkOSandCPU("Solaris", "x86");
86  else if (token == "aix_powerpc")
87  ret = checkOSandCPU("AIX", "PowerPC");
88  else if (token == "macosx_x86_64")
89  ret = checkOSandCPU("MacOSX", "X86_64");
90  else if (token == "linux_x86")
91  ret = checkOSandCPU("Linux", "x86");
92  else if (token == "linux_x86_64")
93  ret = checkOSandCPU("Linux", "X86_64");
94  else if (token == "linux_sparc")
95  ret = checkOSandCPU("Linux", "SPARC");
96  else if (token == "linux_sparc64")
97  ret = checkOSandCPU("Linux", "SPARC64");
98  else if (token == "linux_powerpc")
99  ret = checkOSandCPU("Linux", "PowerPC");
100  else if (token == "linux_powerpc64")
101  ret = checkOSandCPU("Linux", "PowerPC_64");
102  else if (token == "linux_powerpc64_le")
103  ret = checkOSandCPU("Linux", "PowerPC_64_LE");
104  else if (token == "linux_arm_eabi")
105  ret = checkOSandCPU("Linux", "ARM_EABI");
106  else if (token == "linux_arm_oabi")
107  ret = checkOSandCPU("Linux", "ARM_OABI");
108  else if (token == "linux_mips_el")
109  ret = checkOSandCPU("Linux", "MIPS_EL");
110  else if (token == "linux_mips64_el")
111  ret = checkOSandCPU("Linux", "MIPS64_EL");
112  else if (token == "linux_mips_eb")
113  ret = checkOSandCPU("Linux", "MIPS_EB");
114  else if (token == "linux_mips64_eb")
115  ret = checkOSandCPU("Linux", "MIPS64_EB");
116  else if (token == "linux_ia64")
117  ret = checkOSandCPU("Linux", "IA64");
118  else if (token == "linux_m68k")
119  ret = checkOSandCPU("Linux", "M68K");
120  else if (token == "linux_s390")
121  ret = checkOSandCPU("Linux", "S390");
122  else if (token == "linux_s390x")
123  ret = checkOSandCPU("Linux", "S390x");
124  else if (token == "linux_hppa")
125  ret = checkOSandCPU("Linux", "HPPA");
126  else if (token == "linux_alpha")
127  ret = checkOSandCPU("Linux", "ALPHA");
128  else if (token == "linux_aarch64")
129  ret = checkOSandCPU("Linux", "AARCH64");
130  else if (token == "freebsd_x86")
131  ret = checkOSandCPU("FreeBSD", "x86");
132  else if (token == "freebsd_x86_64")
133  ret = checkOSandCPU("FreeBSD", "X86_64");
134  else if (token == "freebsd_powerpc")
135  ret = checkOSandCPU("FreeBSD", "PowerPC");
136  else if (token == "kfreebsd_x86")
137  ret = checkOSandCPU("kFreeBSD", "x86");
138  else if (token == "kfreebsd_x86_64")
139  ret = checkOSandCPU("kFreeBSD", "X86_64");
140  else if (token == "netbsd_x86")
141  ret = checkOSandCPU("NetBSD", "x86");
142  else if (token == "netbsd_x86_64")
143  ret = checkOSandCPU("NetBSD", "X86_64");
144  else if (token == "openbsd_x86")
145  ret = checkOSandCPU("OpenBSD", "x86");
146  else if (token == "openbsd_x86_64")
147  ret = checkOSandCPU("OpenBSD", "X86_64");
148  else if (token == "dragonfly_x86")
149  ret = checkOSandCPU("DragonFly", "x86");
150  else if (token == "dragonfly_x86_64")
151  ret = checkOSandCPU("DragonFly", "X86_64");
152  else
153  {
154  OSL_FAIL("Extension Manager: The extension supports an unknown platform. "
155  "Check the platform in the description.xml");
156  ret = false;
157  }
158  return ret;
159  }
160 
161 } // anon namespace
162 
163 
164 OUString const & getPlatformString()
165 {
166  return StrPlatform::get();
167 }
168 
169 bool platform_fits( OUString const & platform_string )
170 {
171  sal_Int32 index = 0;
172  for (;;)
173  {
174  const OUString token(
175  platform_string.getToken( 0, ',', index ).trim() );
176  // check if this platform:
177  if (token.equalsIgnoreAsciiCase( StrPlatform::get() ) ||
178  (token.indexOf( '_' ) < 0 && /* check OS part only */
179  token.equalsIgnoreAsciiCase( StrOperatingSystem::get() )))
180  {
181  return true;
182  }
183  if (index < 0)
184  break;
185  }
186  return false;
187 }
188 
189 bool hasValidPlatform( css::uno::Sequence<OUString> const & platformStrings)
190 {
191  bool ret = false;
192  for (const OUString& s : platformStrings)
193  {
194  if ( isPlatformSupported( s ) )
195  {
196  ret = true;
197  break;
198  }
199  }
200  return ret;
201 }
202 
203 }
204 
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC OUString const & getPlatformString()
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool platform_fits(OUString const &platform_string)
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.