Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / vcl / headless / headlessinst.cxx
blob7793d85f8ce2984739b4761215e6fb8d944384a7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * Version: MPL 1.1 / GPLv3+ / LGPLv3+
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License or as specified alternatively below. You may obtain a copy of
8 * the License at http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * Major Contributor(s):
16 * Copyright (C) 2012 Novell, Inc.
17 * Michael Meeks <michael.meeks@suse.com> (initial developer)
19 * All Rights Reserved.
21 * For minor contributions see the git repository.
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
25 * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
26 * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
27 * instead of those above.
29 #include <headless/svpinst.hxx>
30 #include <headless/svpdummies.hxx>
31 #include <generic/gendata.hxx>
33 class HeadlessSalInstance : public SvpSalInstance
35 public:
36 HeadlessSalInstance( SalYieldMutex *pMutex );
37 virtual ~HeadlessSalInstance();
39 virtual SalSystem* CreateSalSystem();
42 HeadlessSalInstance::HeadlessSalInstance( SalYieldMutex *pMutex ) :
43 SvpSalInstance( pMutex)
47 HeadlessSalInstance::~HeadlessSalInstance()
51 class HeadlessSalSystem : public SvpSalSystem {
52 public:
53 HeadlessSalSystem() : SvpSalSystem() {}
54 virtual ~HeadlessSalSystem() {}
55 virtual int ShowNativeDialog( const rtl::OUString& rTitle,
56 const rtl::OUString& rMessage,
57 const std::list< rtl::OUString >& rButtons,
58 int nDefButton )
60 (void)rButtons; (void)nDefButton;
61 ::fprintf(stdout, "LibreOffice - dialog '%s': '%s'",
62 rtl::OUStringToOString(rTitle, RTL_TEXTENCODING_ASCII_US).getStr(),
63 rtl::OUStringToOString(rMessage, RTL_TEXTENCODING_ASCII_US).getStr());
64 return 0;
68 SalSystem *HeadlessSalInstance::CreateSalSystem()
70 return new HeadlessSalSystem();
73 class HeadlessSalData : public SalGenericData
75 public:
76 HeadlessSalData( SalInstance *pInstance ) : SalGenericData( SAL_DATA_HEADLESS, pInstance ) {}
77 virtual void ErrorTrapPush() {}
78 virtual bool ErrorTrapPop( bool ) { return false; }
81 // All the interesting stuff is slaved from the AndroidSalInstance
82 void InitSalData() {}
83 void DeInitSalData() {}
84 void InitSalMain() {}
85 void DeInitSalMain() {}
87 void SalAbort( const rtl::OUString& rErrorText, bool bDumpCore )
89 rtl::OUString aError( rErrorText );
90 if( aError.isEmpty() )
91 aError = rtl::OUString::createFromAscii("Unknown application error");
92 ::fprintf( stderr, "%s\n", rtl::OUStringToOString(rErrorText, osl_getThreadTextEncoding()).getStr() );
94 ::fprintf( stderr, "SalAbort: '%s'",
95 rtl::OUStringToOString(aError, RTL_TEXTENCODING_ASCII_US).getStr());
96 if( bDumpCore )
97 abort();
98 else
99 _exit(1);
102 const OUString& SalGetDesktopEnvironment()
104 static rtl::OUString aEnv( RTL_CONSTASCII_USTRINGPARAM( "headless" ) );
105 return aEnv;
108 SalData::SalData() :
109 m_pInstance( 0 ),
110 m_pPlugin( 0 ),
111 m_pPIManager(0 )
115 SalData::~SalData()
119 // This is our main entry point:
120 SalInstance *CreateSalInstance()
122 HeadlessSalInstance* pInstance = new HeadlessSalInstance( new SalYieldMutex() );
123 new HeadlessSalData( pInstance );
124 pInstance->AcquireYieldMutex(1);
125 return pInstance;
128 void DestroySalInstance( SalInstance *pInst )
130 pInst->ReleaseYieldMutex();
131 delete pInst;
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */