NorMIT-nav  18.04
An IGT application
cxSessionStorageServiceProxy.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
13 #include "boost/bind.hpp"
14 #include "cxNullDeleter.h"
15 
16 namespace cx
17 {
18 
20 {
21  return SessionStorageServicePtr(new SessionStorageServiceProxy(pluginContext));
22 }
23 
25  mPluginContext(pluginContext),
27 {
28  this->initServiceListener();
29 }
30 
31 void SessionStorageServiceProxy::initServiceListener()
32 {
33  mServiceListener.reset(new ServiceTrackerListener<SessionStorageService>(
34  mPluginContext,
35  boost::bind(&SessionStorageServiceProxy::onServiceAdded, this, _1),
36  boost::function<void (SessionStorageService*)>(),
37  boost::bind(&SessionStorageServiceProxy::onServiceRemoved, this, _1)
38  ));
39  mServiceListener->open();
40 }
41 
42 void SessionStorageServiceProxy::onServiceAdded(SessionStorageService* service)
43 {
44  mService.reset(service, null_deleter());
45 
46  connect(mService.get(), &SessionStorageService::cleared, this, &SessionStorageService::cleared);
48  connect(mService.get(), &SessionStorageService::isSaving, this, &SessionStorageService::isSaving);
51 
52  emit sessionChanged();
53 }
54 
55 void SessionStorageServiceProxy::onServiceRemoved(SessionStorageService *service)
56 {
57  disconnect(mService.get(), &SessionStorageService::cleared, this, &SessionStorageService::cleared);
59  disconnect(mService.get(), &SessionStorageService::isSaving, this, &SessionStorageService::isSaving);
60  disconnect(mService.get(), &SessionStorageService::isLoading, this, &SessionStorageService::isLoading);
62 
64 
65  emit cleared();
66  emit sessionChanged();
67 }
68 
70 {
71  mService->load(dir);
72 }
73 
75 {
76  mService->save();
77 }
78 
80 {
81  mService->clear();
82 }
83 
85 {
86  return mService->isValid();
87 }
88 
90 {
91  return mService->getRootFolder();
92 }
93 
95 {
96  return false;
97 }
98 
99 }
void isLoading(QDomElement &root)
emitted while loading a session. Xml storage is available, getRootFolder() is set to loaded value...
virtual void load(QString dir)
load session from dir, or create new session in this location if none exist
void isLoadingSecond(QDomElement &root)
Emitted after the isLoading signal, to allow for structures that must be loaded after core structures...
static SessionStorageServicePtr create(ctkPluginContext *pluginContext)
SessionStorageServiceProxy(ctkPluginContext *pluginContext)
virtual void save()
Save all application data to XML file.
void sessionChanged()
emitted after change to a new session (new or loaded or cleared)
void cleared()
emitted when session is cleared, before isLoading is called
Helper class for listening to services being added, modified and removed.
static SessionStorageServicePtr getNullObject()
void isSaving(QDomElement &root)
xml storage is available
boost::shared_ptr< class SessionStorageService > SessionStorageServicePtr
Namespace for all CustusX production code.