12722ceddSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
32722ceddSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
42722ceddSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
52722ceddSAndrew Rist  * distributed with this work for additional information
62722ceddSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
72722ceddSAndrew Rist  * to you under the Apache License, Version 2.0 (the
82722ceddSAndrew Rist  * "License"); you may not use this file except in compliance
92722ceddSAndrew Rist  * with the License.  You may obtain a copy of the License at
102722ceddSAndrew Rist  *
112722ceddSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
122722ceddSAndrew Rist  *
132722ceddSAndrew Rist  * Unless required by applicable law or agreed to in writing,
142722ceddSAndrew Rist  * software distributed under the License is distributed on an
152722ceddSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162722ceddSAndrew Rist  * KIND, either express or implied.  See the License for the
172722ceddSAndrew Rist  * specific language governing permissions and limitations
182722ceddSAndrew Rist  * under the License.
192722ceddSAndrew Rist  *
202722ceddSAndrew Rist  *************************************************************/
212722ceddSAndrew Rist 
222722ceddSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_desktop.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "dp_misc.h"
28cdf0e10cSrcweir #include "dp_platform.hxx"
29cdf0e10cSrcweir #include "rtl/ustring.hxx"
30cdf0e10cSrcweir #include "rtl/ustrbuf.hxx"
31cdf0e10cSrcweir #include "rtl/instance.hxx"
32cdf0e10cSrcweir #include "rtl/bootstrap.hxx"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #define PLATFORM_ALL                "all"
35cdf0e10cSrcweir #define PLATFORM_WIN_X86            "windows_x86"
36cdf0e10cSrcweir #define PLATFORM_LINUX_X86          "linux_x86"
37cdf0e10cSrcweir #define PLATFORM_LINUX_X86_64       "linux_x86_64"
38cdf0e10cSrcweir #define PLATFORM_KFREEBSD_X86       "kfreebsd_x86"
39cdf0e10cSrcweir #define PLATFORM_KFREEBSD_X86_64    "kfreebsd_x86_64"
40cdf0e10cSrcweir #define PLATFORM_LINUX_SPARC        "linux_sparc"
41cdf0e10cSrcweir #define PLATFORM_LINUX_POWERPC      "linux_powerpc"
42cdf0e10cSrcweir #define PLATFORM_LINUX_POWERPC64    "linux_powerpc64"
43cdf0e10cSrcweir #define PLATFORM_LINUX_ARM_EABI     "linux_arm_eabi"
44cdf0e10cSrcweir #define PLATFORM_LINUX_ARM_OABI     "linux_arm_oabi"
45cdf0e10cSrcweir #define PLATFORM_LINUX_MIPS_EL      "linux_mips_el"
46cdf0e10cSrcweir #define PLATFORM_LINUX_MIPS_EB      "linux_mips_eb"
47cdf0e10cSrcweir #define PLATFORM_LINUX_IA64         "linux_ia64"
48cdf0e10cSrcweir #define PLATFORM_LINUX_M68K         "linux_m68k"
49cdf0e10cSrcweir #define PLATFORM_LINUX_S390         "linux_s390"
50cdf0e10cSrcweir #define PLATFORM_LINUX_S390x        "linux_s390x"
51cdf0e10cSrcweir #define PLATFORM_LINUX_HPPA         "linux_hppa"
52cdf0e10cSrcweir #define PLATFORM_LINUX_ALPHA        "linux_alpha"
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 
56cdf0e10cSrcweir #define PLATFORM_SOLARIS_SPARC      "solaris_sparc"
57cdf0e10cSrcweir #define PLATFORM_SOLARIS_SPARC64    "solaris_sparc64"
58cdf0e10cSrcweir #define PLATFORM_SOLARIS_X86        "solaris_x86"
59ceb6c444SPedro Giffuni #define PLATFORM_FREEBSD_POWERPC    "freebsd_powerpc"
60*e15a4534Spfg #define PLATFORM_FREEBSD_POWERPC64  "freebsd_powerpc64"
61cdf0e10cSrcweir #define PLATFORM_FREEBSD_X86        "freebsd_x86"
62cdf0e10cSrcweir #define PLATFORM_FREEBSD_X86_64     "freebsd_x86_64"
63cdf0e10cSrcweir #define PLATFORM_MACOSX_X86         "macosx_x86"
646d1ed1ddSHerbert Dürr #define PLATFORM_MACOSX_X86_64      "macosx_x86_64"
65cdf0e10cSrcweir #define PLATFORM_MACOSX_PPC         "macosx_powerpc"
66cdf0e10cSrcweir #define PLATFORM_OS2_X86            "os2_x86"
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 
76cdf0e10cSrcweir #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
77cdf0e10cSrcweir using ::rtl::OUString;
78cdf0e10cSrcweir namespace css = ::com::sun::star;
79cdf0e10cSrcweir 
80cdf0e10cSrcweir namespace dp_misc
81cdf0e10cSrcweir {
82cdf0e10cSrcweir namespace
83cdf0e10cSrcweir {
84cdf0e10cSrcweir     struct StrOperatingSystem :
85cdf0e10cSrcweir         public rtl::StaticWithInit<const OUString, StrOperatingSystem> {
86cdf0e10cSrcweir             const OUString operator () () {
87cdf0e10cSrcweir                 OUString os( RTL_CONSTASCII_USTRINGPARAM("$_OS") );
88cdf0e10cSrcweir                 ::rtl::Bootstrap::expandMacros( os );
89cdf0e10cSrcweir                 return os;
90cdf0e10cSrcweir             }
91cdf0e10cSrcweir     };
92cdf0e10cSrcweir 
93cdf0e10cSrcweir     struct StrCPU :
94cdf0e10cSrcweir         public rtl::StaticWithInit<const OUString, StrCPU> {
95cdf0e10cSrcweir             const OUString operator () () {
96cdf0e10cSrcweir                 OUString arch( RTL_CONSTASCII_USTRINGPARAM("$_ARCH") );
97cdf0e10cSrcweir                 ::rtl::Bootstrap::expandMacros( arch );
98cdf0e10cSrcweir                 return arch;
99cdf0e10cSrcweir             }
100cdf0e10cSrcweir     };
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     struct StrPlatform : public rtl::StaticWithInit<
104cdf0e10cSrcweir         const OUString, StrPlatform> {
105cdf0e10cSrcweir             const OUString operator () () {
106cdf0e10cSrcweir                 ::rtl::OUStringBuffer buf;
107cdf0e10cSrcweir                 buf.append( StrOperatingSystem::get() );
108cdf0e10cSrcweir                 buf.append( static_cast<sal_Unicode>('_') );
109cdf0e10cSrcweir                 OUString arch( RTL_CONSTASCII_USTRINGPARAM("$_ARCH") );
110cdf0e10cSrcweir                 ::rtl::Bootstrap::expandMacros( arch );
111cdf0e10cSrcweir                 buf.append( arch );
112cdf0e10cSrcweir                 return buf.makeStringAndClear();
113cdf0e10cSrcweir             }
114cdf0e10cSrcweir     };
115cdf0e10cSrcweir 
116cdf0e10cSrcweir     bool checkOSandCPU(OUString const & os, OUString const & cpu)
117cdf0e10cSrcweir     {
118cdf0e10cSrcweir         return os.equals(StrOperatingSystem::get())
119cdf0e10cSrcweir             && cpu.equals(StrCPU::get());
120cdf0e10cSrcweir     }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     bool isValidPlatform(OUString const &  token )
123cdf0e10cSrcweir     {
124cdf0e10cSrcweir         bool ret = false;
125cdf0e10cSrcweir         if (token.equals(OUSTR(PLATFORM_ALL)))
126cdf0e10cSrcweir             ret = true;
127cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_WIN_X86)))
128cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Windows"), OUSTR("x86"));
129cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_X86)))
130cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("x86"));
131cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_X86_64)))
132cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("X86_64"));
133cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_KFREEBSD_X86)))
134cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("kFreeBSD"), OUSTR("x86"));
135cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_KFREEBSD_X86_64)))
136cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("kFreeBSD"), OUSTR("X86_64"));
137cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_SPARC)))
138cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("SPARC"));
139*e15a4534Spfg         else if (token.equals(OUSTR(PLATFORM_FREEBSD_POWERPC)))
140*e15a4534Spfg             ret = checkOSandCPU(OUSTR("FreeBSD"), OUSTR("PowerPC"));
141*e15a4534Spfg         else if (token.equals(OUSTR(PLATFORM_FREEBSD_POWERPC64)))
142*e15a4534Spfg             ret = checkOSandCPU(OUSTR("FreeBSD"), OUSTR("PowerPC64"));
143cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_POWERPC)))
144cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("PowerPC"));
145cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_POWERPC64)))
146cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("PowerPC_64"));
147cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_ARM_EABI)))
148cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("ARM_EABI"));
149cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_ARM_OABI)))
150cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("ARM_OABI"));
151cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_MIPS_EL)))
152cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("MIPS_EL"));
153cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_MIPS_EB)))
154cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("MIPS_EB"));
155cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_IA64)))
156cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("IA64"));
157cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_M68K)))
158cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("M68K"));
159cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_S390)))
160cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("S390"));
161cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_S390x)))
162cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("S390x"));
163cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_HPPA)))
164cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("HPPA"));
165cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_ALPHA)))
166cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("ALPHA"));
167cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_SOLARIS_SPARC)))
168cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Solaris"), OUSTR("SPARC"));
169cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_SOLARIS_SPARC64)))
170cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Solaris"), OUSTR("SPARC64"));
171cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_SOLARIS_X86)))
172cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Solaris"), OUSTR("x86"));
173ceb6c444SPedro Giffuni         else if (token.equals(OUSTR(PLATFORM_FREEBSD_POWERPC)))
174ceb6c444SPedro Giffuni             ret = checkOSandCPU(OUSTR("FreeBSD"), OUSTR("PowerPC"));
175cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_FREEBSD_X86)))
176cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("FreeBSD"), OUSTR("x86"));
177cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_FREEBSD_X86_64)))
178cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("FreeBSD"), OUSTR("X86_64"));
179cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_MACOSX_X86)))
180cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("MacOSX"), OUSTR("x86"));
1816d1ed1ddSHerbert Dürr         else if (token.equals(OUSTR(PLATFORM_MACOSX_X86_64)))
18269910d95SAriel Constenla-Haile             ret = checkOSandCPU(OUSTR("MacOSX"), OUSTR("X86_64"));
183cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_MACOSX_PPC)))
184cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("MacOSX"), OUSTR("PowerPC"));
185cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_OS2_X86)))
186cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("OS2"), OUSTR("x86"));
187cdf0e10cSrcweir         else
188cdf0e10cSrcweir         {
189cdf0e10cSrcweir             OSL_ENSURE(0, "Extension Manager: The extension supports an unknown platform. "
190cdf0e10cSrcweir             "Check the platform element in the descripion.xml");
191cdf0e10cSrcweir             ret = false;
192cdf0e10cSrcweir         }
193cdf0e10cSrcweir         return ret;
194cdf0e10cSrcweir     }
195cdf0e10cSrcweir 
196cdf0e10cSrcweir } // anon namespace
197cdf0e10cSrcweir //=============================================================================
198cdf0e10cSrcweir 
199cdf0e10cSrcweir OUString const & getPlatformString()
200cdf0e10cSrcweir {
201cdf0e10cSrcweir     return StrPlatform::get();
202cdf0e10cSrcweir }
203cdf0e10cSrcweir 
204cdf0e10cSrcweir bool platform_fits( OUString const & platform_string )
205cdf0e10cSrcweir {
206cdf0e10cSrcweir     sal_Int32 index = 0;
207cdf0e10cSrcweir     for (;;)
208cdf0e10cSrcweir     {
209cdf0e10cSrcweir         const OUString token(
210cdf0e10cSrcweir             platform_string.getToken( 0, ',', index ).trim() );
211cdf0e10cSrcweir         // check if this platform:
212cdf0e10cSrcweir         if (token.equalsIgnoreAsciiCase( StrPlatform::get() ) ||
213cdf0e10cSrcweir             (token.indexOf( '_' ) < 0 && /* check OS part only */
214cdf0e10cSrcweir              token.equalsIgnoreAsciiCase( StrOperatingSystem::get() )))
215cdf0e10cSrcweir         {
216cdf0e10cSrcweir             return true;
217cdf0e10cSrcweir         }
218cdf0e10cSrcweir         if (index < 0)
219cdf0e10cSrcweir             break;
220cdf0e10cSrcweir     }
221cdf0e10cSrcweir     return false;
222cdf0e10cSrcweir }
223cdf0e10cSrcweir 
224cdf0e10cSrcweir bool hasValidPlatform( css::uno::Sequence<OUString> const & platformStrings)
225cdf0e10cSrcweir {
226cdf0e10cSrcweir     bool ret = false;
227cdf0e10cSrcweir     for (sal_Int32 i  = 0; i < platformStrings.getLength(); i++)
228cdf0e10cSrcweir     {
229cdf0e10cSrcweir         if (isValidPlatform(platformStrings[i]))
230cdf0e10cSrcweir         {
231cdf0e10cSrcweir             ret = true;
232cdf0e10cSrcweir             break;
233cdf0e10cSrcweir         }
234cdf0e10cSrcweir     }
235cdf0e10cSrcweir     return ret;
236cdf0e10cSrcweir }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir }
239cdf0e10cSrcweir 
240