1 /*
2  * DISTRHO Plugin Framework (DPF)
3  * Copyright (C) 2012-2016 Filipe Coelho <falktx@falktx.com>
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any purpose with
6  * or without fee is hereby granted, provided that the above copyright notice and this
7  * permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
10  * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
11  * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
13  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef DGL_APP_HPP_INCLUDED
18 #define DGL_APP_HPP_INCLUDED
19 
20 #include "Base.hpp"
21 
22 START_NAMESPACE_DGL
23 
24 // -----------------------------------------------------------------------
25 // Forward class names
26 
27 class Window;
28 
29 // -----------------------------------------------------------------------
30 
31 /**
32    Base DGL Application class.
33 
34    One application instance is required for creating a window.
35    There's no single/global application instance in DGL, and multiple
36    windows can share the same app instance.
37 
38    In standalone mode an application will automatically quit its
39    event-loop when all its windows are closed.
40  */
41 class Application
42 {
43 public:
44    /**
45       Constructor.
46     */
47     Application();
48 
49    /**
50       Destructor.
51     */
52     virtual ~Application();
53 
54    /**
55       Idle function.
56       This runs the application event-loop once.
57     */
58     void idle();
59 
60    /**
61       Run the application event-loop until all Windows are closed.
62       idle() is called at regular intervals.
63       @note This function is meant for standalones only, *never* call this from plugins.
64     */
65     void exec(int idleTime = 10);
66 
67    /**
68       Quit the application.
69       This stops the event-loop and closes all Windows.
70     */
71     void quit();
72 
73    /**
74       Check if the application is about to quit.
75       Returning true means there's no event-loop running at the moment (or it's just about to stop).
76     */
77     bool isQuiting() const noexcept;
78 
79 private:
80     struct PrivateData;
81     PrivateData* const pData;
82     friend class Window;
83 
84     DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Application)
85 };
86 
87 // -----------------------------------------------------------------------
88 
89 END_NAMESPACE_DGL
90 
91 #endif // DGL_APP_HPP_INCLUDED
92