libzypp 17.32.5
application.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8----------------------------------------------------------------------*/
9#include "application.h"
12
13namespace ztui {
14
15 namespace {
17 thread_local Application *app = nullptr;
18 return &app;
19 }
20 }
21
23 : _exitCode(ZTUI_EXIT_OK)
24 , _config( new Config() )
25 { init(); }
26
27 Application::Application(std::shared_ptr<Config> &&cfg)
28 : _exitCode(ZTUI_EXIT_OK)
29 , _config( std::move(cfg) )
30 { init(); }
31
33 {
34 // ALWAYS do this FIRST!
35 *getApplicationInstance() = this;
36 _out = std::make_shared<OutNormal>();
37 }
38
40 {
41 // set the thread local global to null again
42 *getApplicationInstance() = nullptr;
43 }
44
45 Application &Application::instance()
46 {
48 if ( !instPtr )
49 ZYPP_THROW( zypp::Exception("No ztui::Application intance registered, its required to create one manually before using ztui.") );
50 return *instPtr;
51 }
52
53 const Config &Application::config() const
54 {
55 return *_config;
56 }
57
58 Config &Application::mutableConfig()
59 {
60 return *_config;
61 }
62
63 Out &Application::out()
64 {
65 if ( not _out ) {
66 _out.reset(new OutNormal( Out::QUIET ));
67 }
68 return *_out;
69 }
70
71 void Application::setOutputWriter(Out *out)
72 {
73 if ( out == _out.get() )
74 return;
75 _out.reset ( out );
76 }
77
78 void Application::setExitCode(int exit) {
79 WAR << "setExitCode " << exit << std::endl;
80 _exitCode = exit;
81 }
82
83}
Base class for producing common (for now) zypper output.
Definition Out.h:430
Class representing an application (appdata.xml)
Definition Application.h:28
~Application() override
Dtor.
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:95
void reset()
Reset to default Ctor values.
Base class for Exception.
Definition Exception.h:147
Definition Arch.h:364
static constexpr int ZTUI_EXIT_OK
Definition application.h:24
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition Exception.h:429
#define WAR
Definition Logger.h:97