| 168 | //////////// µS Registration & Properties ////////////// |
| 169 | |
| 170 | us::ServiceRegistration<IFileWriter> AbstractFileWriter::RegisterService(us::ModuleContext *context) |
| 171 | { |
| 172 | if (d->m_PrototypeFactory) |
| 173 | return us::ServiceRegistration<IFileWriter>(); |
| 174 | |
| 175 | if (context == nullptr) |
| 176 | { |
| 177 | context = us::GetModuleContext(); |
| 178 | } |
| 179 | |
| 180 | d->RegisterMimeType(context); |
| 181 | |
| 182 | if (this->GetMimeType()->GetName().empty()) |
| 183 | { |
| 184 | MITK_WARN << "Not registering writer due to empty MIME type."; |
| 185 | return us::ServiceRegistration<IFileWriter>(); |
| 186 | } |
| 187 | |
| 188 | struct PrototypeFactory : public us::PrototypeServiceFactory |
| 189 | { |
| 190 | AbstractFileWriter *const m_Prototype; |
| 191 | |
| 192 | PrototypeFactory(AbstractFileWriter *prototype) : m_Prototype(prototype) {} |
| 193 | us::InterfaceMap GetService(us::Module * /*module*/, |
| 194 | const us::ServiceRegistrationBase & /*registration*/) override |
| 195 | { |
| 196 | return us::MakeInterfaceMap<IFileWriter>(m_Prototype->Clone()); |
| 197 | } |
| 198 | |
| 199 | void UngetService(us::Module * /*module*/, |
| 200 | const us::ServiceRegistrationBase & /*registration*/, |
| 201 | const us::InterfaceMap &service) override |
| 202 | { |
| 203 | delete us::ExtractInterface<IFileWriter>(service); |
| 204 | } |
| 205 | }; |
| 206 | |
| 207 | d->m_PrototypeFactory = new PrototypeFactory(this); |
| 208 | us::ServiceProperties props = this->GetServiceProperties(); |
| 209 | d->m_Reg = context->RegisterService<IFileWriter>(d->m_PrototypeFactory, props); |
| 210 | return d->m_Reg; |
| 211 | } |
| 212 | |
| 213 | void AbstractFileWriter::UnregisterService() |
| 214 | { |
nothing calls this directly
no test coverage detected