Lumiera  0.pre.03
»edit your freedom«
sess-manager-impl.cpp
Go to the documentation of this file.
1 /*
2  SessManagerImpl - global session access and lifecycle
3 
4  Copyright (C) Lumiera.org
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
23 
41 #include "lib/error.hpp"
47 #include "steam/asset/timeline.hpp"
49 #include "common/query.hpp"
50 
51 #include <memory>
52 #include <exception>
53 
54 
55 
56 
57 namespace steam {
58 namespace mobject {
59 namespace session {
60 
61  LUMIERA_ERROR_DEFINE (CREATE_SESSION, "unable to create basic session");
62 
73  {
74  if (!pSess_)
75  try
76  { // create empty default configured session
77  this->reset();
78  }
79  catch (...)
80  {
81  ERROR (progress, "Unrecoverable Failure while creating the empty default session. System halted.");
82  std::terminate();
83  }
84 
85 
86  return pSess_.get();
87  }
88 
89 
90 
91 
92 
93 
94 
95  namespace { // defining details of the Session Lifecycle
96 
97  using SessionPImpl = std::unique_ptr<SessionImplAPI>;
98 
100  : public LifecycleAdvisor
101  {
102  SessionPImpl & session_;
103  bool shall_load_;
104 
105 
106 
110  void
112  {
113  INFO (session, "Initialising new Session....");
114  SessionPImpl tmpS (new SessionImplAPI);
115  session_.swap (tmpS);
116  }
117 
118 
119  void
120  injectSessionContent() override
121  {
122  if (shall_load_)
123  {
124  UNIMPLEMENTED ("loading session from persistent storage");
125  }
126  else
127  { // inject some default session content
128  REQUIRE (0 == session_->timelines.size(), "injecting default timeline, but session isn't pristine");
129 
130  // issue a default query to retrieve or create a Timeline and a default Sequence
131  asset::PTimeline initialTimeline = session_->defaults (lumiera::Query<asset::Timeline> (""));
132 
133  // these got registered automatically
134  ENSURE (1 == session_->timelines.size());
135  ENSURE (initialTimeline == session_->timelines[0]);
136  }
137  }
138 
139 
140  void
141  getSessionReady() override
142  {
144  INFO (session, "Session ready for use.");
145  }
146 
147 
148  void
149  openSessionInterface() override
150  {
152  }
153 
154 
155  void
156  closeSessionInterface() override
157  {
158  control::SteamDispatcher::instance().deactivate();
159  }
160 
161 
162  void
163  disconnectRenderProcesses() override
164  {
165  TODO ("halt rendering");
166  TODO ("possibly terminate builder");
167  }
168 
169 
173  void
175  {
176  control::SteamDispatcher::instance().awaitDeactivation();
177  INFO (command, " Session shutdown. Command processing stopped.");
178  }
179 
180 
181  void
182  deconfigure() override
183  {
184  session_->defaults.clear();
185  ConfigResolver::instance().reset(); // forget any configuration rules
186  AssetManager::instance().clear();
188  }
189 
190 
191 
192 
193  public:
194  SessionLifecycleDetails(SessionPImpl& currentSessionAccessPoint)
195  : session_(currentSessionAccessPoint)
196  , shall_load_(false)
197  { }
198  };
199 
200  }//(End) details of Session Lifecycle
201 
202 
203 
213  : pSess_{}
214  , lifecycle_{new SessionLifecycleDetails(pSess_)}
215  {
216  Session::initFlag = true;
217  }
218 
219 
220  SessManagerImpl::~SessManagerImpl ()
221  {
223  Session::initFlag = false;
224  }
225 
226 
227 
228  bool
230  {
231  Lock sync{this};
232  return bool(pSess_);
233  }
234 
238  void
240  {
241  Lock sync{this};
242  pSess_->clear();
243  }
244 
245 
251  void
253  {
254  Lock sync{this};
255  if (isUp())
256  lifecycle_->shutDown();
257  pSess_.reset();
258  }
259 
260 
266  void
268  {
269  Lock sync{this};
270  if (isUp())
271  lifecycle_->shutDown();
272  lifecycle_->pullUp();
273  }
274 
278  void
280  {
281  UNIMPLEMENTED ("load serialised session");
282  Lock sync{this};
283  if (isUp())
284  lifecycle_->shutDown();
285  lifecycle_->pullUp();
286  }
287 
288 
297  void
298  SessManagerImpl::save (string snapshotID)
299  {
300  UNIMPLEMENTED ("save session (serialised)");
302  }
303 
304 
305 
306 }}} // namespace steam::mobject::session
static lib::Depend< SteamDispatcher > instance
storage for Singleton access
Collection of configured implementation-level services to provide by the Session. ...
void deconfigure() override
This final stage of the session lifecycle terminates the operational state of all parts of the curren...
Basic and generic representation of an internal query.
Dispatch and execute mutation operations on the High-level model.
scoped guard to control the actual locking.
Definition: sync.hpp:234
Steam-Layer implementation namespace root.
Definition of the concrete frontend for rule based configuration within the session.
Namespace of Session and user visible high-level objects.
Definition: sequence.hpp:74
Management of defaults and default rules.
Skeleton of operations conducting the session lifecycle sequences.
static lib::Depend< ConfigResolver > instance
Singleton factory instance, configured with the actual implementation type.
Implementation facility for session management.
SessManagerImpl()
Starting up the session access and lifecycle management.
Implementation facility providing an operation skeleton of session lifecycle.
SessionServices< Types< SessionServiceFetch, SessionServiceMutate, SessionServiceExploreScope, SessionServiceMockIndex, SessionServiceDefaults >, SessManagerImpl, SessionImpl > SessionImplAPI
actual configuration of the session implementation compound: forming an inheritance chain of all inte...
virtual SessionImplAPI * operator->() noexcept override
Access to the "current session", which actually is an SessionImpl instance.
Lumiera error handling (C++ interface).
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:80
static bool initFlag
temporary fix for init problems
Definition: session.hpp:127
Primary Interface to the current Session.
virtual bool isUp() override
diagnostics: session interface opened?
virtual void close() override
Shut down the current session together with all associated services.
Generic interface to express a query for specifically typed result elements exposing some capabilitie...
Definition: query.hpp:279
Top level structural element within the session.
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.
Definition: error.h:80