Medical Imaging Interaction Toolkit  2018.4.99-07c45cb1
Medical Imaging Interaction Toolkit
mitkToFDeviceFactoryManager.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
14 
15 //Microservices
16 #include <usGetModuleContext.h>
17 
18 
19 namespace mitk
20 {
22  {
23  ModuleContext* context = GetModuleContext();
25  if (m_RegisteredFactoryRefs.empty())
26  {
27  MITK_ERROR << "No factories registered!";
28  }
29  }
30 
32  {
33  }
34 
36  {
37  ModuleContext* context = GetModuleContext();
38  // std::string filter("(" + mitk::ServiceConstants::OBJECTCLASS() + "=" + "org.mitk.services.IToFDeviceFactory)");
39  // std::list<ServiceReference> serviceRef = context->GetServiceReference<IToFDeviceFactory>(/*filter*/);
40  std::vector<us::ServiceReference<IToFDeviceFactory> > serviceRefs = context->GetServiceReferences<IToFDeviceFactory>(/*filter*/);
41  if (!serviceRefs.empty())
42  {
43  for(std::vector<us::ServiceReference<IToFDeviceFactory> >::iterator it = serviceRefs.begin(); it != serviceRefs.end(); ++it)
44  {
45  IToFDeviceFactory* service = context->GetService( *it );
46  if(service)
47  {
48  m_RegisteredFactoryNames.push_back(std::string(service->GetFactoryName()));
49  }
50  }
51  }
53  }
54 
56  {
57  us::ModuleContext* context = us::GetModuleContext();
58  std::vector<std::string> result;
59  std::vector<us::ServiceReference<ToFCameraDevice> > serviceRefs = context->GetServiceReferences<ToFCameraDevice>();
60  if (!serviceRefs.empty())
61  {
62  for(std::empty<us::ServiceReference<ToFCameraDevice> >::iterator it = serviceRefs.begin(); it != serviceRefs.end(); ++it)
63  {
64  ToFCameraDevice* service = context->GetService( *it );
65  if(service)
66  {
67  result.push_back(std::string(service->GetNameOfClass()));
68  }
69  }
70  }
71  if(result.size() == 0)
72  {
73  MITK_ERROR << "No devices connected!";
74  }
75  return result;
76  }
77 
79  {
80  us::ModuleContext* context = us::GetModuleContext();
81 
82  std::vector<us::ServiceReference<IToFDeviceFactory> > serviceRefs = context->GetServiceReferences<IToFDeviceFactory>(/*filter*/);
83  if (!serviceRefs.empty())
84  {
85  int i = 0;
86  for(std::vector<us::ServiceReference<IToFDeviceFactory> >::iterator it = serviceRefs.begin(); it != serviceRefs.end(); ++it)
87  {
88  IToFDeviceFactory* service = context->GetService( *it );
89  if(service && (i == index))
90  {
91  return dynamic_cast<mitk::AbstractToFDeviceFactory*>(service)->ConnectToFDevice();
92  }
93  i++;
94  }
95  }
96  MITK_ERROR << "No device generated!";
97  return nullptr;
98  }
99 }
std::vector< std::string > GetConnectedDevices()
ToFCameraDevice * GetInstanceOfDevice(int index)
#define MITK_ERROR
Definition: mitkLogMacros.h:20
Virtual interface and base class for all Time-of-Flight device factories. The basic interface is in t...
Virtual interface and base class for all Time-of-Flight devices.
DataCollection - Class to facilitate loading/accessing structured data.
virtual std::string GetFactoryName()=0
GetFactoryName Get the human readable name of the factory.
void * GetService(const ServiceReferenceBase &reference)
std::vector< us::ServiceReference< IToFDeviceFactory > > m_RegisteredFactoryRefs
std::vector< ServiceReferenceU > GetServiceReferences(const std::string &clazz, const std::string &filter=std::string())
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
This is the base of class for all ToFDeviceFactories.
std::vector< std::string > GetRegisteredDeviceFactories()
std::vector< std::string > m_RegisteredFactoryNames