diff --git a/Core/Code/IO/mitkLegacyFileWriterService.cpp b/Core/Code/IO/mitkLegacyFileWriterService.cpp index d44ff4c8be..fb9f21b692 100644 --- a/Core/Code/IO/mitkLegacyFileWriterService.cpp +++ b/Core/Code/IO/mitkLegacyFileWriterService.cpp @@ -1,61 +1,66 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include #include mitk::LegacyFileWriterService::LegacyFileWriterService(mitk::FileWriterWithInformation::Pointer legacyWriter, const std::string& basedataType, const std::string& extension, const std::string& description) : AbstractFileWriter(basedataType, extension, description) , m_LegacyWriter(legacyWriter) { if (extension.empty()) mitkThrow() << "LegacyFileWriterWrapper cannot be initialized without FileExtension." ; - RegisterService(); + m_ServiceRegistration = RegisterService(); +} + +mitk::LegacyFileWriterService::~LegacyFileWriterService() +{ + m_ServiceRegistration.Unregister(); } ////////////////////// Writing ///////////////////////// void mitk::LegacyFileWriterService::Write(const BaseData* data, const std::string& path) { if (m_LegacyWriter.IsNull()) mitkThrow() << "LegacyFileWriterService was incorrectly initialized: Has no LegacyFileWriter."; m_LegacyWriter->SetFileName(path.c_str()); m_LegacyWriter->DoWrite(mitk::BaseData::Pointer(const_cast(data))); } void mitk::LegacyFileWriterService::Write(const BaseData* data, std::ostream& stream) { mitk::AbstractFileWriter::Write(data, stream); } bool mitk::LegacyFileWriterService::CanWrite(const mitk::BaseData* data) const { return mitk::AbstractFileWriter::CanWrite(data) && m_LegacyWriter->CanWriteBaseDataType(mitk::BaseData::Pointer(const_cast(data))); } mitk::LegacyFileWriterService* mitk::LegacyFileWriterService::Clone() const { return new LegacyFileWriterService(*this); } diff --git a/Core/Code/IO/mitkLegacyFileWriterService.h b/Core/Code/IO/mitkLegacyFileWriterService.h index 4a58a364ab..03151f3a37 100644 --- a/Core/Code/IO/mitkLegacyFileWriterService.h +++ b/Core/Code/IO/mitkLegacyFileWriterService.h @@ -1,60 +1,63 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef LegacyFileWriterService_H_HEADER_INCLUDED_C1E7E521 #define LegacyFileWriterService_H_HEADER_INCLUDED_C1E7E521 // Macro #include // MITK #include #include namespace mitk { //##Documentation //## @brief //## @ingroup Process class LegacyFileWriterService : public mitk::AbstractFileWriter { public: LegacyFileWriterService(mitk::FileWriterWithInformation::Pointer legacyWriter, const std::string& basedataType, const std::string& extension, const std::string& description); + ~LegacyFileWriterService(); + using AbstractFileWriter::Write; virtual void Write(const BaseData* data, const std::string& path); virtual void Write(const BaseData* data, std::ostream& stream ); virtual bool CanWrite(const BaseData *data) const; protected: mitk::FileWriterWithInformation::Pointer m_LegacyWriter; private: LegacyFileWriterService* Clone() const; + us::ServiceRegistration m_ServiceRegistration; }; } // namespace mitk #endif /* LegacyFileWriterService_H_HEADER_INCLUDED_C1E7E521 */