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)
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
14 
32 #include "lib/error.hpp"
38 #include "steam/asset/timeline.hpp"
40 #include "common/query.hpp"
41 
42 #include <memory>
43 #include <exception>
44 
45 
46 
47 
48 namespace steam {
49 namespace mobject {
50 namespace session {
51 
52  LUMIERA_ERROR_DEFINE (CREATE_SESSION, "unable to create basic session");
53 
64  {
65  if (!pSess_)
66  try
67  { // create empty default configured session
68  this->reset();
69  }
70  catch (...)
71  {
72  ERROR (progress, "Unrecoverable Failure while creating the empty default session. System halted.");
73  std::terminate();
74  }
75 
76 
77  return pSess_.get();
78  }
79 
80 
81 
82 
83 
84 
85 
86  namespace { // defining details of the Session Lifecycle
87 
88  using SessionPImpl = std::unique_ptr<SessionImplAPI>;
89 
91  : public LifecycleAdvisor
92  {
93  SessionPImpl & session_;
94  bool shall_load_;
95 
96 
97 
101  void
103  {
104  INFO (session, "Initialising new Session....");
105  SessionPImpl tmpS (new SessionImplAPI);
106  session_.swap (tmpS);
107  }
108 
109 
110  void
111  injectSessionContent() override
112  {
113  if (shall_load_)
114  {
115  UNIMPLEMENTED ("loading session from persistent storage");
116  }
117  else
118  { // inject some default session content
119  REQUIRE (0 == session_->timelines.size(), "injecting default timeline, but session isn't pristine");
120 
121  // issue a default query to retrieve or create a Timeline and a default Sequence
122  asset::PTimeline initialTimeline = session_->defaults (lumiera::Query<asset::Timeline> (""));
123 
124  // these got registered automatically
125  ENSURE (1 == session_->timelines.size());
126  ENSURE (initialTimeline == session_->timelines[0]);
127  }
128  }
129 
130 
131  void
132  getSessionReady() override
133  {
135  INFO (session, "Session ready for use.");
136  }
137 
138 
139  void
140  openSessionInterface() override
141  {
143  }
144 
145 
146  void
147  closeSessionInterface() override
148  {
149  control::SteamDispatcher::instance().deactivate();
150  }
151 
152 
153  void
154  disconnectRenderProcesses() override
155  {
156  TODO ("halt rendering");
157  TODO ("possibly terminate builder");
158  }
159 
160 
164  void
166  {
167  control::SteamDispatcher::instance().awaitDeactivation();
168  INFO (command, " Session shutdown. Command processing stopped.");
169  }
170 
171 
172  void
173  deconfigure() override
174  {
175  session_->defaults.clear();
176  ConfigResolver::instance().reset(); // forget any configuration rules
177  AssetManager::instance().clear();
179  }
180 
181 
182 
183 
184  public:
185  SessionLifecycleDetails(SessionPImpl& currentSessionAccessPoint)
186  : session_(currentSessionAccessPoint)
187  , shall_load_(false)
188  { }
189  };
190 
191  }//(End) details of Session Lifecycle
192 
193 
194 
204  : pSess_{}
205  , lifecycle_{new SessionLifecycleDetails(pSess_)}
206  {
207  Session::initFlag = true;
208  }
209 
210 
211  SessManagerImpl::~SessManagerImpl ()
212  {
214  Session::initFlag = false;
215  }
216 
217 
218 
219  bool
221  {
222  Lock sync{this};
223  return bool(pSess_);
224  }
225 
229  void
231  {
232  Lock sync{this};
233  pSess_->clear();
234  }
235 
236 
242  void
244  {
245  Lock sync{this};
246  if (isUp())
247  lifecycle_->shutDown();
248  pSess_.reset();
249  }
250 
251 
257  void
259  {
260  Lock sync{this};
261  if (isUp())
262  lifecycle_->shutDown();
263  lifecycle_->pullUp();
264  }
265 
269  void
271  {
272  UNIMPLEMENTED ("load serialised session");
273  Lock sync{this};
274  if (isUp())
275  lifecycle_->shutDown();
276  lifecycle_->pullUp();
277  }
278 
279 
288  void
289  SessManagerImpl::save (string snapshotID)
290  {
291  UNIMPLEMENTED ("save session (serialised)");
293  }
294 
295 
296 
297 }}} // 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:226
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:65
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:71
static bool initFlag
temporary fix for init problems
Definition: session.hpp:118
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:270
Top level structural element within the session.
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.
Definition: error.h:71