Line data Source code
1 : /* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #ifndef nsAppShellSingleton_h__
7 : #define nsAppShellSingleton_h__
8 :
9 : /**
10 : * This file is designed to be included into the file that provides the
11 : * nsIModule implementation for a particular widget toolkit.
12 : *
13 : * The following functions are defined:
14 : * nsAppShellInit
15 : * nsAppShellShutdown
16 : * nsAppShellConstructor
17 : *
18 : * The nsAppShellInit function is designed to be used as a module constructor.
19 : * If you already have a module constructor, then call nsAppShellInit from your
20 : * module constructor.
21 : *
22 : * The nsAppShellShutdown function is designed to be used as a module
23 : * destructor. If you already have a module destructor, then call
24 : * nsAppShellShutdown from your module destructor.
25 : *
26 : * The nsAppShellConstructor function is designed to be used as a factory
27 : * method for the nsAppShell class.
28 : */
29 :
30 : #include "nsXULAppAPI.h"
31 :
32 : static nsIAppShell *sAppShell;
33 :
34 : static nsresult
35 3 : nsAppShellInit()
36 : {
37 3 : NS_ASSERTION(!sAppShell, "already initialized");
38 :
39 3 : sAppShell = new nsAppShell();
40 3 : if (!sAppShell)
41 0 : return NS_ERROR_OUT_OF_MEMORY;
42 3 : NS_ADDREF(sAppShell);
43 :
44 : nsresult rv;
45 3 : rv = static_cast<nsAppShell*>(sAppShell)->Init();
46 3 : if (NS_FAILED(rv)) {
47 0 : NS_RELEASE(sAppShell);
48 0 : return rv;
49 : }
50 :
51 3 : return NS_OK;
52 : }
53 :
54 : static void
55 0 : nsAppShellShutdown()
56 : {
57 0 : NS_RELEASE(sAppShell);
58 0 : }
59 :
60 : static nsresult
61 3 : nsAppShellConstructor(nsISupports *outer, const nsIID &iid, void **result)
62 : {
63 3 : NS_ENSURE_TRUE(!outer, NS_ERROR_NO_AGGREGATION);
64 3 : NS_ENSURE_TRUE(sAppShell, NS_ERROR_NOT_INITIALIZED);
65 :
66 3 : return sAppShell->QueryInterface(iid, result);
67 : }
68 :
69 : #endif // nsAppShellSingleton_h__
|