NorMIT-nav  2023.01.05-dev+develop.0da12
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),
26  mService(SessionStorageService::getNullObject())
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 }
cx::SessionStorageServiceProxy::create
static SessionStorageServicePtr create(ctkPluginContext *pluginContext)
Definition: cxSessionStorageServiceProxy.cpp:19
cx::SessionStorageServiceProxy::isNull
virtual bool isNull() const
Definition: cxSessionStorageServiceProxy.cpp:94
cx::SessionStorageServiceProxy::load
virtual void load(QString dir)
load session from dir, or create new session in this location if none exist
Definition: cxSessionStorageServiceProxy.cpp:69
cx::SessionStorageServiceProxy::SessionStorageServiceProxy
SessionStorageServiceProxy(ctkPluginContext *pluginContext)
Definition: cxSessionStorageServiceProxy.cpp:24
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::SessionStorageService::getNullObject
static SessionStorageServicePtr getNullObject()
Definition: cxSessionStorageService.cpp:42
cx::SessionStorageServiceProxy::clear
virtual void clear()
Definition: cxSessionStorageServiceProxy.cpp:79
cx::ServiceTrackerListener
Helper class for listening to services being added, modified and removed.
Definition: cxServiceTrackerListener.h:53
cx::SessionStorageServiceProxy::isValid
virtual bool isValid() const
Definition: cxSessionStorageServiceProxy.cpp:84
cx::SessionStorageService
Definition: cxSessionStorageService.h:42
cx::SessionStorageServicePtr
boost::shared_ptr< class SessionStorageService > SessionStorageServicePtr
Definition: cxLogicManager.h:30
cxNullDeleter.h
cxSessionStorageServiceProxy.h
cx::SessionStorageServiceProxy::save
virtual void save()
Save all application data to XML file.
Definition: cxSessionStorageServiceProxy.cpp:74
cx::SessionStorageService::isSaving
void isSaving(QDomElement &root)
xml storage is available
cx::SessionStorageServiceProxy::getRootFolder
virtual QString getRootFolder() const
Definition: cxSessionStorageServiceProxy.cpp:89
cx::SessionStorageService::isLoadingSecond
void isLoadingSecond(QDomElement &root)
Emitted after the isLoading signal, to allow for structures that must be loaded after core structures...
cx::SessionStorageService::isLoading
void isLoading(QDomElement &root)
emitted while loading a session. Xml storage is available, getRootFolder() is set to loaded value.
cx::SessionStorageService::sessionChanged
void sessionChanged()
emitted after change to a new session (new or loaded or cleared)
cx::SessionStorageService::cleared
void cleared()
emitted when session is cleared, before isLoading is called