libzypp 17.37.17
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 {
16 Application **getApplicationInstance () {
17 thread_local Application *app = nullptr;
18 return &app;
19 }
20 }
21
26
27 Application::Application(std::shared_ptr<Config> &&cfg)
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
46 {
47 auto instPtr = *getApplicationInstance ();
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
54 {
55 return *_config;
56 }
57
59 {
60 return *_config;
61 }
62
64 {
65 if ( not _out ) {
66 _out.reset(new OutNormal( Out::QUIET ));
67 }
68 return *_out;
69 }
70
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}
virtual void setOutputWriter(Out *out)
std::shared_ptr< Out > _out
Definition application.h:54
std::shared_ptr< Config > _config
Definition application.h:53
static Application & instance()
virtual Out & out()
void setExitCode(int exit)
const Config & config() const
Config & mutableConfig()
Base class for producing common (for now) zypper output.
Definition Out.h:424
@ QUIET
Only important messages (no progress or status, only the result).
Definition Out.h:429
Class representing an application (appdata.xml)
Definition Application.h:28
~Application() override
Dtor.
Base class for Exception.
Definition Exception.h:153
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:459
#define WAR
Definition Logger.h:101