Fraxinus  16.5.0-fx-rc5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
34 #include "boost/bind.hpp"
35 #include "cxNullDeleter.h"
36 
37 namespace cx
38 {
39 
41 {
42  return SessionStorageServicePtr(new SessionStorageServiceProxy(pluginContext));
43 }
44 
46  mPluginContext(pluginContext),
47  mService(SessionStorageService::getNullObject())
48 {
49  this->initServiceListener();
50 }
51 
52 void SessionStorageServiceProxy::initServiceListener()
53 {
54  mServiceListener.reset(new ServiceTrackerListener<SessionStorageService>(
55  mPluginContext,
56  boost::bind(&SessionStorageServiceProxy::onServiceAdded, this, _1),
57  boost::function<void (SessionStorageService*)>(),
58  boost::bind(&SessionStorageServiceProxy::onServiceRemoved, this, _1)
59  ));
60  mServiceListener->open();
61 }
62 
63 void SessionStorageServiceProxy::onServiceAdded(SessionStorageService* service)
64 {
65  mService.reset(service, null_deleter());
66 
67  connect(mService.get(), &SessionStorageService::cleared, this, &SessionStorageService::cleared);
69  connect(mService.get(), &SessionStorageService::isSaving, this, &SessionStorageService::isSaving);
72 
73  emit sessionChanged();
74 }
75 
76 void SessionStorageServiceProxy::onServiceRemoved(SessionStorageService *service)
77 {
78  disconnect(mService.get(), &SessionStorageService::cleared, this, &SessionStorageService::cleared);
80  disconnect(mService.get(), &SessionStorageService::isSaving, this, &SessionStorageService::isSaving);
81  disconnect(mService.get(), &SessionStorageService::isLoading, this, &SessionStorageService::isLoading);
83 
85 
86  emit cleared();
87  emit sessionChanged();
88 }
89 
91 {
92  mService->load(dir);
93 }
94 
96 {
97  mService->save();
98 }
99 
101 {
102  mService->clear();
103 }
104 
106 {
107  return mService->isValid();
108 }
109 
111 {
112  return mService->getRootFolder();
113 }
114 
116 {
117  return false;
118 }
119 
120 }
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